00001 #include "bcdisplayinfo.h"
00002 #include "bchash.h"
00003 #include "filexml.h"
00004 #include "freezeframe.h"
00005 #include "language.h"
00006 #include "picon_png.h"
00007
00008
00009
00010 #include <string.h>
00011
00012
00013 REGISTER_PLUGIN(FreezeFrameMain)
00014
00015
00016
00017
00018
00019 FreezeFrameConfig::FreezeFrameConfig()
00020 {
00021 enabled = 0;
00022 line_double = 0;
00023 }
00024
00025 void FreezeFrameConfig::copy_from(FreezeFrameConfig &that)
00026 {
00027 enabled = that.enabled;
00028 line_double = that.line_double;
00029 }
00030
00031 int FreezeFrameConfig::equivalent(FreezeFrameConfig &that)
00032 {
00033 return enabled == that.enabled &&
00034 line_double == that.line_double;
00035 }
00036
00037 void FreezeFrameConfig::interpolate(FreezeFrameConfig &prev,
00038 FreezeFrameConfig &next,
00039 long prev_frame,
00040 long next_frame,
00041 long current_frame)
00042 {
00043 this->enabled = prev.enabled;
00044 this->line_double = prev.line_double;
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 FreezeFrameWindow::FreezeFrameWindow(FreezeFrameMain *client, int x, int y)
00057 : BC_Window(client->get_gui_string(),
00058 x,
00059 y,
00060 200,
00061 100,
00062 200,
00063 100,
00064 0,
00065 0,
00066 1)
00067 {
00068 this->client = client;
00069 }
00070
00071 FreezeFrameWindow::~FreezeFrameWindow()
00072 {
00073 }
00074
00075 int FreezeFrameWindow::create_objects()
00076 {
00077 int x = 10, y = 10;
00078 add_tool(enabled = new FreezeFrameToggle(client,
00079 &client->config.enabled,
00080 x,
00081 y,
00082 _("Enabled")));
00083
00084
00085
00086
00087
00088
00089
00090
00091 show_window();
00092 flush();
00093 return 0;
00094 }
00095
00096 WINDOW_CLOSE_EVENT(FreezeFrameWindow)
00097
00098
00099
00100
00101 PLUGIN_THREAD_OBJECT(FreezeFrameMain, FreezeFrameThread, FreezeFrameWindow)
00102
00103
00104
00105
00106
00107 FreezeFrameToggle::FreezeFrameToggle(FreezeFrameMain *client,
00108 int *value,
00109 int x,
00110 int y,
00111 char *text)
00112 : BC_CheckBox(x, y, *value, text)
00113 {
00114 this->client = client;
00115 this->value = value;
00116 }
00117 FreezeFrameToggle::~FreezeFrameToggle()
00118 {
00119 }
00120 int FreezeFrameToggle::handle_event()
00121 {
00122 *value = get_value();
00123 client->send_configure_change();
00124 return 1;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 FreezeFrameMain::FreezeFrameMain(PluginServer *server)
00139 : PluginVClient(server)
00140 {
00141 PLUGIN_CONSTRUCTOR_MACRO
00142 first_frame = 0;
00143 first_frame_position = -1;
00144 }
00145
00146 FreezeFrameMain::~FreezeFrameMain()
00147 {
00148 PLUGIN_DESTRUCTOR_MACRO
00149 if(first_frame) delete first_frame;
00150 }
00151
00152 char* FreezeFrameMain::plugin_title() { return N_("Freeze Frame"); }
00153 int FreezeFrameMain::is_synthesis() { return 1; }
00154 int FreezeFrameMain::is_realtime() { return 1; }
00155
00156
00157 SHOW_GUI_MACRO(FreezeFrameMain, FreezeFrameThread)
00158
00159 RAISE_WINDOW_MACRO(FreezeFrameMain)
00160
00161 SET_STRING_MACRO(FreezeFrameMain)
00162
00163 NEW_PICON_MACRO(FreezeFrameMain)
00164
00165 int FreezeFrameMain::load_configuration()
00166 {
00167 KeyFrame *prev_keyframe = get_prev_keyframe(get_source_position());
00168 int64_t prev_position = edl_to_local(prev_keyframe->position);
00169 if(prev_position < get_source_start()) prev_position = get_source_start();
00170 read_data(prev_keyframe);
00171
00172 if(config.enabled) first_frame_position = prev_position;
00173 return 0;
00174 }
00175
00176 void FreezeFrameMain::update_gui()
00177 {
00178 if(thread)
00179 {
00180 load_configuration();
00181 thread->window->lock_window();
00182 thread->window->enabled->update(config.enabled);
00183
00184 thread->window->unlock_window();
00185 }
00186 }
00187
00188 void FreezeFrameMain::save_data(KeyFrame *keyframe)
00189 {
00190 FileXML output;
00191
00192
00193 output.set_shared_string(keyframe->data, MESSAGESIZE);
00194 output.tag.set_title("FREEZEFRAME");
00195 output.append_tag();
00196 if(config.enabled)
00197 {
00198 output.tag.set_title("ENABLED");
00199 output.append_tag();
00200 output.tag.set_title("/ENABLED");
00201 output.append_tag();
00202 }
00203 if(config.line_double)
00204 {
00205 output.tag.set_title("LINE_DOUBLE");
00206 output.append_tag();
00207 output.tag.set_title("/LINE_DOUBLE");
00208 output.append_tag();
00209 }
00210 output.tag.set_title("/FREEZEFRAME");
00211 output.append_tag();
00212 output.terminate_string();
00213
00214 }
00215
00216 void FreezeFrameMain::read_data(KeyFrame *keyframe)
00217 {
00218 FileXML input;
00219
00220 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00221
00222 int result = 0;
00223 config.enabled = 0;
00224 config.line_double = 0;
00225
00226 while(!result)
00227 {
00228 result = input.read_tag();
00229
00230 if(!result)
00231 {
00232 if(input.tag.title_is("ENABLED"))
00233 {
00234 config.enabled = 1;
00235 }
00236 if(input.tag.title_is("LINE_DOUBLE"))
00237 {
00238 config.line_double = 1;
00239 }
00240 }
00241 }
00242 }
00243
00244 int FreezeFrameMain::load_defaults()
00245 {
00246 char directory[BCTEXTLEN], string[BCTEXTLEN];
00247
00248 sprintf(directory, "%sfreezeframe.rc", BCASTDIR);
00249
00250
00251 defaults = new BC_Hash(directory);
00252 defaults->load();
00253
00254 config.enabled = defaults->get("ENABLED", config.enabled);
00255 config.line_double = defaults->get("LINE_DOUBLE", config.line_double);
00256 return 0;
00257 }
00258
00259 int FreezeFrameMain::save_defaults()
00260 {
00261 defaults->update("ENABLED", config.enabled);
00262 defaults->update("LINE_DOUBLE", config.line_double);
00263 defaults->save();
00264 return 0;
00265 }
00266
00267
00268
00269
00270
00271
00272 int FreezeFrameMain::process_buffer(VFrame *frame,
00273 int64_t start_position,
00274 double frame_rate)
00275 {
00276 int64_t previous_first_frame = first_frame_position;
00277 load_configuration();
00278
00279
00280 if(!first_frame && config.enabled)
00281 {
00282 if(!first_frame)
00283 first_frame = new VFrame(0,
00284 frame->get_w(),
00285 frame->get_h(),
00286 frame->get_color_model());
00287 printf("FreezeFrameMain::process_buffer 1 %lld\n", first_frame_position);
00288 read_frame(first_frame,
00289 0,
00290 first_frame_position,
00291 frame_rate,
00292 get_use_opengl());
00293 if(get_use_opengl()) return run_opengl();
00294 frame->copy_from(first_frame);
00295 }
00296 else
00297
00298 if(!first_frame && !config.enabled)
00299 {
00300 read_frame(frame,
00301 0,
00302 start_position,
00303 frame_rate,
00304 get_use_opengl());
00305 }
00306 else
00307
00308 if(first_frame && !config.enabled)
00309 {
00310 delete first_frame;
00311 first_frame = 0;
00312 read_frame(frame,
00313 0,
00314 start_position,
00315 frame_rate,
00316 get_use_opengl());
00317 }
00318 else
00319
00320 if(first_frame && config.enabled)
00321 {
00322
00323 if(previous_first_frame != first_frame_position)
00324 {
00325 read_frame(first_frame,
00326 0,
00327 first_frame_position,
00328 frame_rate,
00329 get_use_opengl());
00330 }
00331 if(get_use_opengl()) return run_opengl();
00332 frame->copy_from(first_frame);
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 return 0;
00350 }
00351
00352 int FreezeFrameMain::handle_opengl()
00353 {
00354 #ifdef HAVE_GL
00355 get_output()->enable_opengl();
00356 get_output()->init_screen();
00357 first_frame->to_texture();
00358 first_frame->bind_texture(0);
00359 first_frame->draw_texture();
00360 get_output()->set_opengl_state(VFrame::SCREEN);
00361 #endif
00362 return 0;
00363 }
00364
00365