1 #include "bcdisplayinfo.h"
4 #include "delayvideo.h"
20 REGISTER_PLUGIN(DelayVideo)
26 DelayVideoConfig::DelayVideoConfig()
31 int DelayVideoConfig::equivalent(DelayVideoConfig &that)
33 return EQUIV(length, that.length);
36 void DelayVideoConfig::copy_from(DelayVideoConfig &that)
41 void DelayVideoConfig::interpolate(DelayVideoConfig &prev,
42 DelayVideoConfig &next,
45 int64_t current_frame)
47 this->length = prev.length;
52 DelayVideoWindow::DelayVideoWindow(DelayVideo *plugin, int x, int y)
53 : BC_Window(plugin->gui_string,
64 this->plugin = plugin;
67 DelayVideoWindow::~DelayVideoWindow()
72 void DelayVideoWindow::create_objects()
76 add_subwindow(new BC_Title(x, y, _("Delay seconds:")));
78 add_subwindow(slider = new DelayVideoSlider(plugin, x, y));
84 WINDOW_CLOSE_EVENT(DelayVideoWindow)
86 void DelayVideoWindow::update_gui()
88 char string[BCTEXTLEN];
89 sprintf(string, "%.04f", plugin->config.length);
90 slider->update(string);
104 DelayVideoSlider::DelayVideoSlider(DelayVideo *plugin, int x, int y)
105 : BC_TextBox(x, y, 150, 1, plugin->config.length)
107 this->plugin = plugin;
110 int DelayVideoSlider::handle_event()
112 plugin->config.length = atof(get_text());
113 plugin->send_configure_change();
127 PLUGIN_THREAD_OBJECT(DelayVideo, DelayVideoThread, DelayVideoWindow)
135 DelayVideo::DelayVideo(PluginServer *server)
136 : PluginVClient(server)
142 DelayVideo::~DelayVideo()
144 PLUGIN_DESTRUCTOR_MACRO
148 //printf("DelayVideo::~DelayVideo 1\n");
149 for(int i = 0; i < allocation; i++)
151 //printf("DelayVideo::~DelayVideo 1\n");
154 //printf("DelayVideo::~DelayVideo 1\n");
158 void DelayVideo::reset()
162 need_reconfigure = 1;
167 void DelayVideo::reconfigure()
169 int new_allocation = 1 + (int)(config.length * PluginVClient::project_frame_rate);
170 VFrame **new_buffer = new VFrame*[new_allocation];
171 int reuse = MIN(new_allocation, allocation);
173 for(int i = 0; i < reuse; i++)
175 new_buffer[i] = buffer[i];
178 for(int i = reuse; i < new_allocation; i++)
180 new_buffer[i] = new VFrame(0,
183 PluginVClient::project_color_model);
186 for(int i = reuse; i < allocation; i++)
191 if(buffer) delete [] buffer;
195 allocation = new_allocation;
197 need_reconfigure = 0;
200 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
202 //printf("DelayVideo::process_realtime 1 %d\n", config.length);
203 this->input = input_ptr;
204 this->output = output_ptr;
205 need_reconfigure += load_configuration();
206 CLAMP(config.length, 0, 10);
208 //printf("DelayVideo::process_realtime 2 %d\n", config.length);
209 if(need_reconfigure) reconfigure();
210 //printf("DelayVideo::process_realtime 3 %d %d\n", config.length, allocation);
212 buffer[allocation - 1]->copy_from(input_ptr);
213 output_ptr->copy_from(buffer[0]);
215 VFrame *temp = buffer[0];
216 for(int i = 0; i < allocation - 1; i++)
218 buffer[i] = buffer[i + 1];
221 buffer[allocation - 1] = temp;
222 //printf("DelayVideo::process_realtime 4\n");
228 int DelayVideo::is_realtime()
233 char* DelayVideo::plugin_title() { return N_("Delay Video"); }
235 SET_STRING_MACRO(DelayVideo)
237 NEW_PICON_MACRO(DelayVideo)
239 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
241 SHOW_GUI_MACRO(DelayVideo, DelayVideoThread)
243 RAISE_WINDOW_MACRO(DelayVideo)
246 void DelayVideo::save_data(KeyFrame *keyframe)
249 output.set_shared_string(keyframe->data, MESSAGESIZE);
251 output.tag.set_title("DELAYVIDEO");
252 output.tag.set_property("LENGTH", (double)config.length);
254 output.append_newline();
255 output.terminate_string();
258 void DelayVideo::read_data(KeyFrame *keyframe)
261 input.set_shared_string(keyframe->data, strlen(keyframe->data));
266 result = input.read_tag();
270 if(input.tag.title_is("DELAYVIDEO"))
272 config.length = input.tag.get_property("LENGTH", (double)config.length);
278 void DelayVideo::update_gui()
282 load_configuration();
283 thread->window->lock_window();
284 thread->window->slider->update(config.length);
285 thread->window->unlock_window();
292 int DelayVideo::load_defaults()
294 char directory[BCTEXTLEN];
295 sprintf(directory, "%sdelayvideo.rc", BCASTDIR);
296 defaults = new BC_Hash(directory);
298 config.length = defaults->get("LENGTH", (double)1);
302 int DelayVideo::save_defaults()
304 defaults->update("LENGTH", config.length);