4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
28 #include "pluginvclient.h"
29 #include "transportque.h"
43 class LoopVideoFrames : public BC_TextBox
46 LoopVideoFrames(LoopVideo *plugin,
53 class LoopVideoWindow : public PluginClientWindow
56 LoopVideoWindow(LoopVideo *plugin);
58 void create_objects();
60 LoopVideoFrames *frames;
64 class LoopVideo : public PluginVClient
67 LoopVideo(PluginServer *server);
70 PLUGIN_CLASS_MEMBERS(LoopVideoConfig)
72 void save_data(KeyFrame *keyframe);
73 void read_data(KeyFrame *keyframe);
77 int process_buffer(VFrame *frame,
78 int64_t start_position,
88 REGISTER_PLUGIN(LoopVideo);
92 LoopVideoConfig::LoopVideoConfig()
101 LoopVideoWindow::LoopVideoWindow(LoopVideo *plugin)
102 : PluginClientWindow(plugin,
109 this->plugin = plugin;
112 LoopVideoWindow::~LoopVideoWindow()
116 void LoopVideoWindow::create_objects()
120 add_subwindow(new BC_Title(x, y, _("Frames to loop:")));
122 add_subwindow(frames = new LoopVideoFrames(plugin,
139 LoopVideoFrames::LoopVideoFrames(LoopVideo *plugin,
146 plugin->config.frames)
148 this->plugin = plugin;
151 int LoopVideoFrames::handle_event()
153 plugin->config.frames = atol(get_text());
154 plugin->config.frames = MAX(1, plugin->config.frames);
155 plugin->send_configure_change();
167 LoopVideo::LoopVideo(PluginServer *server)
168 : PluginVClient(server)
174 LoopVideo::~LoopVideo()
179 const char* LoopVideo::plugin_title() { return _("Loop video"); }
180 int LoopVideo::is_realtime() { return 1; }
181 int LoopVideo::is_synthesis() { return 1; }
184 NEW_WINDOW_MACRO(LoopVideo, LoopVideoWindow)
188 int LoopVideo::process_buffer(VFrame *frame,
189 int64_t start_position,
192 int64_t current_loop_position;
194 // Truncate to next keyframe
195 if(get_direction() == PLAY_FORWARD)
197 // Get start of current loop
198 KeyFrame *prev_keyframe = get_prev_keyframe(start_position);
199 int64_t prev_position = edl_to_local(prev_keyframe->position);
200 if(prev_position == 0)
201 prev_position = get_source_start();
202 read_data(prev_keyframe);
204 // Get start of fragment in current loop
205 current_loop_position = prev_position +
206 ((start_position - prev_position) %
208 while(current_loop_position < prev_position) current_loop_position += config.frames;
209 while(current_loop_position >= prev_position + config.frames) current_loop_position -= config.frames;
213 KeyFrame *prev_keyframe = get_next_keyframe(start_position);
214 int64_t prev_position = edl_to_local(prev_keyframe->position);
215 if(prev_position == 0)
216 prev_position = get_source_start() + get_total_len();
217 read_data(prev_keyframe);
219 current_loop_position = prev_position -
220 ((prev_position - start_position) %
222 while(current_loop_position <= prev_position - config.frames) current_loop_position += config.frames;
223 while(current_loop_position > prev_position) current_loop_position -= config.frames;
227 // printf("LoopVideo::process_buffer 100 %lld %lld %lld %d\n",
228 // current_position, current_loop_position, current_loop_end, fragment_size);
231 current_loop_position,
241 int LoopVideo::load_configuration()
243 KeyFrame *prev_keyframe;
244 int64_t old_frames = config.frames;
245 prev_keyframe = get_prev_keyframe(get_source_position());
246 read_data(prev_keyframe);
247 config.frames = MAX(config.frames, 1);
248 return old_frames != config.frames;
252 void LoopVideo::save_data(KeyFrame *keyframe)
256 // cause data to be stored directly in text
257 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
258 output.tag.set_title("LOOPVIDEO");
259 output.tag.set_property("FRAMES", config.frames);
261 output.terminate_string();
264 void LoopVideo::read_data(KeyFrame *keyframe)
268 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
270 while(!input.read_tag())
272 if(input.tag.title_is("LOOPVIDEO"))
274 config.frames = input.tag.get_property("FRAMES", config.frames);
279 void LoopVideo::update_gui()
283 load_configuration();
284 thread->window->lock_window();
285 ((LoopVideoWindow*)thread->window)->frames->update(config.frames);
286 thread->window->unlock_window();