1 #include "bcdisplayinfo.h"
4 #include "freezeframe.h"
13 REGISTER_PLUGIN(FreezeFrameMain)
19 FreezeFrameConfig::FreezeFrameConfig()
25 void FreezeFrameConfig::copy_from(FreezeFrameConfig &that)
27 enabled = that.enabled;
28 line_double = that.line_double;
31 int FreezeFrameConfig::equivalent(FreezeFrameConfig &that)
33 return enabled == that.enabled &&
34 line_double == that.line_double;
37 void FreezeFrameConfig::interpolate(FreezeFrameConfig &prev,
38 FreezeFrameConfig &next,
43 this->enabled = prev.enabled;
44 this->line_double = prev.line_double;
56 FreezeFrameWindow::FreezeFrameWindow(FreezeFrameMain *client, int x, int y)
57 : BC_Window(client->get_gui_string(),
68 this->client = client;
71 FreezeFrameWindow::~FreezeFrameWindow()
75 int FreezeFrameWindow::create_objects()
78 add_tool(enabled = new FreezeFrameToggle(client,
79 &client->config.enabled,
83 // Try using extra effect for the line double since it doesn't
84 // change the overhead.
86 // add_tool(line_double = new FreezeFrameToggle(client,
87 // &client->config.line_double,
90 // _("Line double")));
96 WINDOW_CLOSE_EVENT(FreezeFrameWindow)
101 PLUGIN_THREAD_OBJECT(FreezeFrameMain, FreezeFrameThread, FreezeFrameWindow)
107 FreezeFrameToggle::FreezeFrameToggle(FreezeFrameMain *client,
112 : BC_CheckBox(x, y, *value, text)
114 this->client = client;
117 FreezeFrameToggle::~FreezeFrameToggle()
120 int FreezeFrameToggle::handle_event()
122 *value = get_value();
123 client->send_configure_change();
138 FreezeFrameMain::FreezeFrameMain(PluginServer *server)
139 : PluginVClient(server)
141 PLUGIN_CONSTRUCTOR_MACRO
143 first_frame_position = -1;
146 FreezeFrameMain::~FreezeFrameMain()
148 PLUGIN_DESTRUCTOR_MACRO
149 if(first_frame) delete first_frame;
152 char* FreezeFrameMain::plugin_title() { return N_("Freeze Frame"); }
153 int FreezeFrameMain::is_synthesis() { return 1; }
154 int FreezeFrameMain::is_realtime() { return 1; }
157 SHOW_GUI_MACRO(FreezeFrameMain, FreezeFrameThread)
159 RAISE_WINDOW_MACRO(FreezeFrameMain)
161 SET_STRING_MACRO(FreezeFrameMain)
163 NEW_PICON_MACRO(FreezeFrameMain)
165 int FreezeFrameMain::load_configuration()
167 KeyFrame *prev_keyframe = get_prev_keyframe(get_source_position());
168 int64_t prev_position = edl_to_local(prev_keyframe->position);
169 if(prev_position < get_source_start()) prev_position = get_source_start();
170 read_data(prev_keyframe);
171 // Invalidate stored frame
172 if(config.enabled) first_frame_position = prev_position;
176 void FreezeFrameMain::update_gui()
180 load_configuration();
181 thread->window->lock_window();
182 thread->window->enabled->update(config.enabled);
183 // thread->window->line_double->update(config.line_double);
184 thread->window->unlock_window();
188 void FreezeFrameMain::save_data(KeyFrame *keyframe)
192 // cause data to be stored directly in text
193 output.set_shared_string(keyframe->data, MESSAGESIZE);
194 output.tag.set_title("FREEZEFRAME");
198 output.tag.set_title("ENABLED");
200 output.tag.set_title("/ENABLED");
203 if(config.line_double)
205 output.tag.set_title("LINE_DOUBLE");
207 output.tag.set_title("/LINE_DOUBLE");
210 output.tag.set_title("/FREEZEFRAME");
212 output.terminate_string();
213 // data is now in *text
216 void FreezeFrameMain::read_data(KeyFrame *keyframe)
220 input.set_shared_string(keyframe->data, strlen(keyframe->data));
224 config.line_double = 0;
228 result = input.read_tag();
232 if(input.tag.title_is("ENABLED"))
236 if(input.tag.title_is("LINE_DOUBLE"))
238 config.line_double = 1;
244 int FreezeFrameMain::load_defaults()
246 char directory[BCTEXTLEN], string[BCTEXTLEN];
247 // set the default directory
248 sprintf(directory, "%sfreezeframe.rc", BCASTDIR);
251 defaults = new BC_Hash(directory);
254 config.enabled = defaults->get("ENABLED", config.enabled);
255 config.line_double = defaults->get("LINE_DOUBLE", config.line_double);
259 int FreezeFrameMain::save_defaults()
261 defaults->update("ENABLED", config.enabled);
262 defaults->update("LINE_DOUBLE", config.line_double);
272 int FreezeFrameMain::process_buffer(VFrame *frame,
273 int64_t start_position,
276 int64_t previous_first_frame = first_frame_position;
277 load_configuration();
279 // Just entered frozen range
280 if(!first_frame && config.enabled)
283 first_frame = new VFrame(0,
286 frame->get_color_model());
287 printf("FreezeFrameMain::process_buffer 1 %lld\n", first_frame_position);
288 read_frame(first_frame,
290 first_frame_position,
293 if(get_use_opengl()) return run_opengl();
294 frame->copy_from(first_frame);
298 if(!first_frame && !config.enabled)
307 // Just left frozen range
308 if(first_frame && !config.enabled)
320 if(first_frame && config.enabled)
322 // Had a keyframe in frozen range. Load new first frame
323 if(previous_first_frame != first_frame_position)
325 read_frame(first_frame,
327 first_frame_position,
331 if(get_use_opengl()) return run_opengl();
332 frame->copy_from(first_frame);
336 // Line double to support interlacing
337 // if(config.line_double && config.enabled)
339 // for(int i = 0; i < frame->get_h() - 1; i += 2)
341 // memcpy(frame->get_rows()[i + 1],
342 // frame->get_rows()[i],
343 // frame->get_bytes_per_line());
352 int FreezeFrameMain::handle_opengl()
355 get_output()->enable_opengl();
356 get_output()->init_screen();
357 first_frame->to_texture();
358 first_frame->bind_texture(0);
359 first_frame->draw_texture();
360 get_output()->set_opengl_state(VFrame::SCREEN);