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");
206 if(config.line_double)
208 output.tag.set_title("LINE_DOUBLE");
211 output.terminate_string();
212 // data is now in *text
215 void FreezeFrameMain::read_data(KeyFrame *keyframe)
219 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
223 config.line_double = 0;
227 result = input.read_tag();
231 if(input.tag.title_is("ENABLED"))
235 if(input.tag.title_is("LINE_DOUBLE"))
237 config.line_double = 1;
249 int FreezeFrameMain::process_buffer(VFrame *frame,
250 int64_t start_position,
253 int64_t previous_first_frame = first_frame_position;
254 load_configuration();
256 // Just entered frozen range
257 if(!first_frame && config.enabled)
260 first_frame = new VFrame(0,
264 frame->get_color_model(),
266 //printf("FreezeFrameMain::process_buffer 1 " _LD "\n", first_frame_position);
267 read_frame(first_frame,
269 get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position,
272 if(get_use_opengl()) return run_opengl();
273 frame->copy_from(first_frame);
277 if(!first_frame && !config.enabled)
286 // Just left frozen range
287 if(first_frame && !config.enabled)
299 if(first_frame && config.enabled)
301 // Had a keyframe in frozen range. Load new first frame
302 if(previous_first_frame != first_frame_position)
304 read_frame(first_frame,
306 get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position,
310 if(get_use_opengl()) return run_opengl();
311 frame->copy_from(first_frame);
315 // Line double to support interlacing
316 // if(config.line_double && config.enabled)
318 // for(int i = 0; i < frame->get_h() - 1; i += 2)
320 // memcpy(frame->get_rows()[i + 1],
321 // frame->get_rows()[i],
322 // frame->get_bytes_per_line());
331 int FreezeFrameMain::handle_opengl()
334 get_output()->enable_opengl();
335 get_output()->init_screen();
336 first_frame->to_texture();
337 first_frame->bind_texture(0);
338 first_frame->draw_texture();
339 get_output()->set_opengl_state(VFrame::SCREEN);