00001 #include "bcdisplayinfo.h"
00002 #include "clip.h"
00003 #include "bchash.h"
00004 #include "delayvideo.h"
00005 #include "filexml.h"
00006 #include "language.h"
00007 #include "picon_png.h"
00008 #include "vframe.h"
00009
00010
00011
00012
00013 #include <string.h>
00014
00015
00016
00017
00018
00019
00020 REGISTER_PLUGIN(DelayVideo)
00021
00022
00023
00024
00025
00026 DelayVideoConfig::DelayVideoConfig()
00027 {
00028 length = 0;
00029 }
00030
00031 int DelayVideoConfig::equivalent(DelayVideoConfig &that)
00032 {
00033 return EQUIV(length, that.length);
00034 }
00035
00036 void DelayVideoConfig::copy_from(DelayVideoConfig &that)
00037 {
00038 length = that.length;
00039 }
00040
00041 void DelayVideoConfig::interpolate(DelayVideoConfig &prev,
00042 DelayVideoConfig &next,
00043 int64_t prev_frame,
00044 int64_t next_frame,
00045 int64_t current_frame)
00046 {
00047 this->length = prev.length;
00048 }
00049
00050
00051
00052 DelayVideoWindow::DelayVideoWindow(DelayVideo *plugin, int x, int y)
00053 : BC_Window(plugin->gui_string,
00054 x,
00055 y,
00056 210,
00057 120,
00058 210,
00059 120,
00060 0,
00061 0,
00062 1)
00063 {
00064 this->plugin = plugin;
00065 }
00066
00067 DelayVideoWindow::~DelayVideoWindow()
00068 {
00069 }
00070
00071
00072 void DelayVideoWindow::create_objects()
00073 {
00074 int x = 10, y = 10;
00075
00076 add_subwindow(new BC_Title(x, y, _("Delay seconds:")));
00077 y += 20;
00078 add_subwindow(slider = new DelayVideoSlider(plugin, x, y));
00079
00080 show_window();
00081 flush();
00082 }
00083
00084 WINDOW_CLOSE_EVENT(DelayVideoWindow)
00085
00086 void DelayVideoWindow::update_gui()
00087 {
00088 char string[BCTEXTLEN];
00089 sprintf(string, "%.04f", plugin->config.length);
00090 slider->update(string);
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 DelayVideoSlider::DelayVideoSlider(DelayVideo *plugin, int x, int y)
00105 : BC_TextBox(x, y, 150, 1, plugin->config.length)
00106 {
00107 this->plugin = plugin;
00108 }
00109
00110 int DelayVideoSlider::handle_event()
00111 {
00112 plugin->config.length = atof(get_text());
00113 plugin->send_configure_change();
00114 return 1;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 PLUGIN_THREAD_OBJECT(DelayVideo, DelayVideoThread, DelayVideoWindow)
00128
00129
00130
00131
00132
00133
00134
00135 DelayVideo::DelayVideo(PluginServer *server)
00136 : PluginVClient(server)
00137 {
00138 reset();
00139 load_defaults();
00140 }
00141
00142 DelayVideo::~DelayVideo()
00143 {
00144 PLUGIN_DESTRUCTOR_MACRO
00145
00146 if(buffer)
00147 {
00148
00149 for(int i = 0; i < allocation; i++)
00150 delete buffer[i];
00151
00152
00153 delete [] buffer;
00154
00155 }
00156 }
00157
00158 void DelayVideo::reset()
00159 {
00160 thread = 0;
00161 defaults = 0;
00162 need_reconfigure = 1;
00163 buffer = 0;
00164 allocation = 0;
00165 }
00166
00167 void DelayVideo::reconfigure()
00168 {
00169 int new_allocation = 1 + (int)(config.length * PluginVClient::project_frame_rate);
00170 VFrame **new_buffer = new VFrame*[new_allocation];
00171 int reuse = MIN(new_allocation, allocation);
00172
00173 for(int i = 0; i < reuse; i++)
00174 {
00175 new_buffer[i] = buffer[i];
00176 }
00177
00178 for(int i = reuse; i < new_allocation; i++)
00179 {
00180 new_buffer[i] = new VFrame(0,
00181 input->get_w(),
00182 input->get_h(),
00183 PluginVClient::project_color_model);
00184 }
00185
00186 for(int i = reuse; i < allocation; i++)
00187 {
00188 delete buffer[i];
00189 }
00190
00191 if(buffer) delete [] buffer;
00192
00193
00194 buffer = new_buffer;
00195 allocation = new_allocation;
00196
00197 need_reconfigure = 0;
00198 }
00199
00200 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
00201 {
00202
00203 this->input = input_ptr;
00204 this->output = output_ptr;
00205 need_reconfigure += load_configuration();
00206 CLAMP(config.length, 0, 10);
00207
00208
00209 if(need_reconfigure) reconfigure();
00210
00211
00212 buffer[allocation - 1]->copy_from(input_ptr);
00213 output_ptr->copy_from(buffer[0]);
00214
00215 VFrame *temp = buffer[0];
00216 for(int i = 0; i < allocation - 1; i++)
00217 {
00218 buffer[i] = buffer[i + 1];
00219 }
00220
00221 buffer[allocation - 1] = temp;
00222
00223
00224
00225 return 0;
00226 }
00227
00228 int DelayVideo::is_realtime()
00229 {
00230 return 1;
00231 }
00232
00233 char* DelayVideo::plugin_title() { return N_("Delay Video"); }
00234
00235 SET_STRING_MACRO(DelayVideo)
00236
00237 NEW_PICON_MACRO(DelayVideo)
00238
00239 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
00240
00241 SHOW_GUI_MACRO(DelayVideo, DelayVideoThread)
00242
00243 RAISE_WINDOW_MACRO(DelayVideo)
00244
00245
00246 void DelayVideo::save_data(KeyFrame *keyframe)
00247 {
00248 FileXML output;
00249 output.set_shared_string(keyframe->data, MESSAGESIZE);
00250
00251 output.tag.set_title("DELAYVIDEO");
00252 output.tag.set_property("LENGTH", (double)config.length);
00253 output.append_tag();
00254 output.tag.set_title("/DELAYVIDEO");
00255 output.append_tag();
00256 output.append_newline();
00257 output.terminate_string();
00258 }
00259
00260 void DelayVideo::read_data(KeyFrame *keyframe)
00261 {
00262 FileXML input;
00263 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00264
00265 int result = 0;
00266 while(!result)
00267 {
00268 result = input.read_tag();
00269
00270 if(!result)
00271 {
00272 if(input.tag.title_is("DELAYVIDEO"))
00273 {
00274 config.length = input.tag.get_property("LENGTH", (double)config.length);
00275 }
00276 }
00277 }
00278 }
00279
00280 void DelayVideo::update_gui()
00281 {
00282 if(thread)
00283 {
00284 load_configuration();
00285 thread->window->lock_window();
00286 thread->window->slider->update(config.length);
00287 thread->window->unlock_window();
00288 }
00289 }
00290
00291
00292
00293
00294 int DelayVideo::load_defaults()
00295 {
00296 char directory[BCTEXTLEN];
00297 sprintf(directory, "%sdelayvideo.rc", BCASTDIR);
00298 defaults = new BC_Hash(directory);
00299 defaults->load();
00300 config.length = defaults->get("LENGTH", (double)1);
00301 return 0;
00302 }
00303
00304 int DelayVideo::save_defaults()
00305 {
00306 defaults->update("LENGTH", config.length);
00307 defaults->save();
00308 return 0;
00309 }
00310
00311
00312