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"
25 #include "freezeframe.h"
27 #include "transportque.inc"
34 REGISTER_PLUGIN(FreezeFrameMain)
40 FreezeFrameConfig::FreezeFrameConfig()
46 void FreezeFrameConfig::copy_from(FreezeFrameConfig &that)
48 enabled = that.enabled;
49 line_double = that.line_double;
52 int FreezeFrameConfig::equivalent(FreezeFrameConfig &that)
54 return enabled == that.enabled &&
55 line_double == that.line_double;
58 void FreezeFrameConfig::interpolate(FreezeFrameConfig &prev,
59 FreezeFrameConfig &next,
64 this->enabled = prev.enabled;
65 this->line_double = prev.line_double;
77 FreezeFrameWindow::FreezeFrameWindow(FreezeFrameMain *client)
78 : PluginClientWindow(client, xS(160), yS(40), xS(160), yS(40), 0)
80 this->client = client;
83 FreezeFrameWindow::~FreezeFrameWindow()
87 void FreezeFrameWindow::create_objects()
89 int x = xS(10), y = yS(10);
90 add_tool(enabled = new FreezeFrameToggle(client,
91 &client->config.enabled,
95 // Try using extra effect for the line double since it doesn't
96 // change the overhead.
98 // add_tool(line_double = new FreezeFrameToggle(client,
99 // &client->config.line_double,
102 // _("Line double")));
112 FreezeFrameToggle::FreezeFrameToggle(FreezeFrameMain *client,
117 : BC_CheckBox(x, y, *value, text)
119 this->client = client;
122 FreezeFrameToggle::~FreezeFrameToggle()
125 int FreezeFrameToggle::handle_event()
127 *value = get_value();
128 client->send_configure_change();
143 FreezeFrameMain::FreezeFrameMain(PluginServer *server)
144 : PluginVClient(server)
148 first_frame_position = -1;
151 FreezeFrameMain::~FreezeFrameMain()
154 if(first_frame) delete first_frame;
157 const char* FreezeFrameMain::plugin_title() { return N_("Freeze Frame"); }
158 int FreezeFrameMain::is_synthesis() { return 1; }
159 int FreezeFrameMain::is_realtime() { return 1; }
162 NEW_WINDOW_MACRO(FreezeFrameMain, FreezeFrameWindow)
164 int FreezeFrameMain::load_configuration()
166 KeyFrame *prev_keyframe = get_prev_keyframe(get_source_position());
167 int64_t prev_position = edl_to_local(prev_keyframe->position);
168 if(prev_position < get_source_start()) prev_position = get_source_start();
169 read_data(prev_keyframe);
170 // Invalidate stored frame
171 if(config.enabled) first_frame_position = prev_position;
175 void FreezeFrameMain::update_gui()
179 load_configuration();
180 ((FreezeFrameWindow*)thread->window)->lock_window();
181 ((FreezeFrameWindow*)thread->window)->enabled->update(config.enabled);
182 // thread->window->line_double->update(config.line_double);
183 thread->window->unlock_window();
187 void FreezeFrameMain::save_data(KeyFrame *keyframe)
191 // cause data to be stored directly in text
192 output.set_shared_output(keyframe->xbuf);
193 output.tag.set_title("FREEZEFRAME");
197 output.tag.set_title("ENABLED");
199 output.tag.set_title("/ENABLED");
202 if(config.line_double)
204 output.tag.set_title("LINE_DOUBLE");
206 output.tag.set_title("/LINE_DOUBLE");
209 output.tag.set_title("/FREEZEFRAME");
211 output.append_newline();
212 output.terminate_string();
213 // data is now in *text
216 void FreezeFrameMain::read_data(KeyFrame *keyframe)
220 input.set_shared_input(keyframe->xbuf);
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;
250 int FreezeFrameMain::process_buffer(VFrame *frame,
251 int64_t start_position,
254 int64_t previous_first_frame = first_frame_position;
255 load_configuration();
257 // Just entered frozen range
258 if(!first_frame && config.enabled)
261 first_frame = new VFrame(frame->get_w(), frame->get_h(),
262 frame->get_color_model(), 0);
263 //printf("FreezeFrameMain::process_buffer 1 %jd\n", first_frame_position);
264 read_frame(first_frame,
266 get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position,
269 if(get_use_opengl()) return run_opengl();
270 frame->copy_from(first_frame);
274 if(!first_frame && !config.enabled)
283 // Just left frozen range
284 if(first_frame && !config.enabled)
296 if(first_frame && config.enabled)
298 // Had a keyframe in frozen range. Load new first frame
299 if(previous_first_frame != first_frame_position)
301 read_frame(first_frame,
303 get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position,
307 if(get_use_opengl()) return run_opengl();
308 frame->copy_from(first_frame);
312 // Line double to support interlacing
313 // if(config.line_double && config.enabled)
315 // for(int i = 0; i < frame->get_h() - 1; i += 2)
317 // memcpy(frame->get_rows()[i + 1],
318 // frame->get_rows()[i],
319 // frame->get_bytes_per_line());
328 int FreezeFrameMain::handle_opengl()
331 get_output()->enable_opengl();
332 get_output()->init_screen();
333 first_frame->to_texture();
334 first_frame->bind_texture(0);
335 first_frame->draw_texture();
336 get_output()->set_opengl_state(VFrame::SCREEN);