4 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
26 #include "freezeframe.h"
28 #include "transportque.inc"
35 REGISTER_PLUGIN(FreezeFrameMain)
41 FreezeFrameConfig::FreezeFrameConfig()
47 void FreezeFrameConfig::copy_from(FreezeFrameConfig &that)
49 enabled = that.enabled;
50 line_double = that.line_double;
53 int FreezeFrameConfig::equivalent(FreezeFrameConfig &that)
55 return enabled == that.enabled &&
56 line_double == that.line_double;
59 void FreezeFrameConfig::interpolate(FreezeFrameConfig &prev,
60 FreezeFrameConfig &next,
65 this->enabled = prev.enabled;
66 this->line_double = prev.line_double;
78 FreezeFrameWindow::FreezeFrameWindow(FreezeFrameMain *client)
79 : PluginClientWindow(client,
86 this->client = client;
89 FreezeFrameWindow::~FreezeFrameWindow()
93 void FreezeFrameWindow::create_objects()
96 add_tool(enabled = new FreezeFrameToggle(client,
97 &client->config.enabled,
101 // Try using extra effect for the line double since it doesn't
102 // change the overhead.
104 // add_tool(line_double = new FreezeFrameToggle(client,
105 // &client->config.line_double,
108 // _("Line double")));
118 FreezeFrameToggle::FreezeFrameToggle(FreezeFrameMain *client,
123 : BC_CheckBox(x, y, *value, text)
125 this->client = client;
128 FreezeFrameToggle::~FreezeFrameToggle()
131 int FreezeFrameToggle::handle_event()
133 *value = get_value();
134 client->send_configure_change();
149 FreezeFrameMain::FreezeFrameMain(PluginServer *server)
150 : PluginVClient(server)
154 first_frame_position = -1;
157 FreezeFrameMain::~FreezeFrameMain()
160 if(first_frame) delete first_frame;
163 const char* FreezeFrameMain::plugin_title() { return _("Freeze Frame"); }
164 int FreezeFrameMain::is_synthesis() { return 1; }
165 int FreezeFrameMain::is_realtime() { return 1; }
168 NEW_WINDOW_MACRO(FreezeFrameMain, FreezeFrameWindow)
170 int FreezeFrameMain::load_configuration()
172 KeyFrame *prev_keyframe = get_prev_keyframe(get_source_position());
173 int64_t prev_position = edl_to_local(prev_keyframe->position);
174 if(prev_position < get_source_start()) prev_position = get_source_start();
175 read_data(prev_keyframe);
176 // Invalidate stored frame
177 if(config.enabled) first_frame_position = prev_position;
181 void FreezeFrameMain::update_gui()
185 load_configuration();
186 ((FreezeFrameWindow*)thread->window)->lock_window();
187 ((FreezeFrameWindow*)thread->window)->enabled->update(config.enabled);
188 // thread->window->line_double->update(config.line_double);
189 thread->window->unlock_window();
193 void FreezeFrameMain::save_data(KeyFrame *keyframe)
197 // cause data to be stored directly in text
198 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
199 output.tag.set_title("FREEZEFRAME");
203 output.tag.set_title("ENABLED");
205 output.tag.set_title("/ENABLED");
208 if(config.line_double)
210 output.tag.set_title("LINE_DOUBLE");
212 output.tag.set_title("/LINE_DOUBLE");
215 output.tag.set_title("/FREEZEFRAME");
217 output.append_newline();
218 output.terminate_string();
219 // data is now in *text
222 void FreezeFrameMain::read_data(KeyFrame *keyframe)
226 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
230 config.line_double = 0;
234 result = input.read_tag();
238 if(input.tag.title_is("ENABLED"))
242 if(input.tag.title_is("LINE_DOUBLE"))
244 config.line_double = 1;
256 int FreezeFrameMain::process_buffer(VFrame *frame,
257 int64_t start_position,
260 int64_t previous_first_frame = first_frame_position;
261 load_configuration();
263 // Just entered frozen range
264 if(!first_frame && config.enabled)
267 first_frame = new VFrame(0,
271 frame->get_color_model(),
273 //printf("FreezeFrameMain::process_buffer 1 %jd\n", first_frame_position);
274 read_frame(first_frame,
276 get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position,
279 if(get_use_opengl()) return run_opengl();
280 frame->copy_from(first_frame);
284 if(!first_frame && !config.enabled)
293 // Just left frozen range
294 if(first_frame && !config.enabled)
306 if(first_frame && config.enabled)
308 // Had a keyframe in frozen range. Load new first frame
309 if(previous_first_frame != first_frame_position)
311 read_frame(first_frame,
313 get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position,
317 if(get_use_opengl()) return run_opengl();
318 frame->copy_from(first_frame);
322 // Line double to support interlacing
323 // if(config.line_double && config.enabled)
325 // for(int i = 0; i < frame->get_h() - 1; i += 2)
327 // memcpy(frame->get_rows()[i + 1],
328 // frame->get_rows()[i],
329 // frame->get_bytes_per_line());
338 int FreezeFrameMain::handle_opengl()
341 get_output()->enable_opengl();
342 get_output()->init_screen();
343 first_frame->to_texture();
344 first_frame->bind_texture(0);
345 first_frame->draw_texture();
346 get_output()->set_opengl_state(VFrame::SCREEN);