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");
201 if(config.line_double)
203 output.tag.set_title("LINE_DOUBLE");
206 output.terminate_string();
207 // data is now in *text
210 void FreezeFrameMain::read_data(KeyFrame *keyframe)
214 input.set_shared_string(keyframe->data, strlen(keyframe->data));
218 config.line_double = 0;
222 result = input.read_tag();
226 if(input.tag.title_is("ENABLED"))
230 if(input.tag.title_is("LINE_DOUBLE"))
232 config.line_double = 1;
238 int FreezeFrameMain::load_defaults()
240 char directory[BCTEXTLEN], string[BCTEXTLEN];
241 // set the default directory
242 sprintf(directory, "%sfreezeframe.rc", BCASTDIR);
245 defaults = new BC_Hash(directory);
248 config.enabled = defaults->get("ENABLED", config.enabled);
249 config.line_double = defaults->get("LINE_DOUBLE", config.line_double);
253 int FreezeFrameMain::save_defaults()
255 defaults->update("ENABLED", config.enabled);
256 defaults->update("LINE_DOUBLE", config.line_double);
266 int FreezeFrameMain::process_buffer(VFrame *frame,
267 int64_t start_position,
270 int64_t previous_first_frame = first_frame_position;
271 load_configuration();
273 // Just entered frozen range
274 if(!first_frame && config.enabled)
277 first_frame = new VFrame(0,
280 frame->get_color_model());
281 printf("FreezeFrameMain::process_buffer 1 %lld\n", first_frame_position);
282 read_frame(first_frame,
284 first_frame_position,
287 if(get_use_opengl()) return run_opengl();
288 frame->copy_from(first_frame);
292 if(!first_frame && !config.enabled)
301 // Just left frozen range
302 if(first_frame && !config.enabled)
314 if(first_frame && config.enabled)
316 // Had a keyframe in frozen range. Load new first frame
317 if(previous_first_frame != first_frame_position)
319 read_frame(first_frame,
321 first_frame_position,
325 if(get_use_opengl()) return run_opengl();
326 frame->copy_from(first_frame);
330 // Line double to support interlacing
331 // if(config.line_double && config.enabled)
333 // for(int i = 0; i < frame->get_h() - 1; i += 2)
335 // memcpy(frame->get_rows()[i + 1],
336 // frame->get_rows()[i],
337 // frame->get_bytes_per_line());
346 int FreezeFrameMain::handle_opengl()
349 get_output()->enable_opengl();
350 get_output()->init_screen();
351 first_frame->to_texture();
352 first_frame->bind_texture(0);
353 first_frame->draw_texture();
354 get_output()->set_opengl_state(VFrame::SCREEN);