4 * Copyright (C) 2008 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"
27 #include "pluginvclient.h"
28 #include "transportque.h"
34 class ReverseVideoConfig
42 class ReverseVideoEnabled : public BC_CheckBox
45 ReverseVideoEnabled(ReverseVideo *plugin,
52 class ReverseVideoWindow : public PluginClientWindow
55 ReverseVideoWindow(ReverseVideo *plugin);
56 ~ReverseVideoWindow();
57 void create_objects();
60 ReverseVideoEnabled *enabled;
64 class ReverseVideo : public PluginVClient
67 ReverseVideo(PluginServer *server);
70 PLUGIN_CLASS_MEMBERS(ReverseVideoConfig)
72 void save_data(KeyFrame *keyframe);
73 void read_data(KeyFrame *keyframe);
76 int process_buffer(VFrame *frame,
77 int64_t start_position,
80 int64_t input_position;
89 REGISTER_PLUGIN(ReverseVideo);
93 ReverseVideoConfig::ReverseVideoConfig()
102 ReverseVideoWindow::ReverseVideoWindow(ReverseVideo *plugin)
103 : PluginClientWindow(plugin,
110 this->plugin = plugin;
113 ReverseVideoWindow::~ReverseVideoWindow()
117 void ReverseVideoWindow::create_objects()
121 add_subwindow(enabled = new ReverseVideoEnabled(plugin,
139 ReverseVideoEnabled::ReverseVideoEnabled(ReverseVideo *plugin,
144 plugin->config.enabled,
147 this->plugin = plugin;
150 int ReverseVideoEnabled::handle_event()
152 plugin->config.enabled = get_value();
153 plugin->send_configure_change();
165 ReverseVideo::ReverseVideo(PluginServer *server)
166 : PluginVClient(server)
172 ReverseVideo::~ReverseVideo()
177 const char* ReverseVideo::plugin_title() { return N_("Reverse video"); }
178 int ReverseVideo::is_realtime() { return 1; }
181 NEW_WINDOW_MACRO(ReverseVideo, ReverseVideoWindow)
184 int ReverseVideo::process_buffer(VFrame *frame,
185 int64_t start_position,
188 load_configuration();
206 int ReverseVideo::load_configuration()
208 KeyFrame *prev_keyframe, *next_keyframe;
209 next_keyframe = get_next_keyframe(get_source_position());
210 prev_keyframe = get_prev_keyframe(get_source_position());
211 // Previous keyframe stays in config object.
212 read_data(prev_keyframe);
214 int64_t prev_position = edl_to_local(prev_keyframe->position);
215 int64_t next_position = edl_to_local(next_keyframe->position);
217 if(prev_position == 0 && next_position == 0)
219 next_position = prev_position = get_source_start();
222 // Get range to flip in requested rate
223 int64_t range_start = prev_position;
224 int64_t range_end = next_position;
226 // Between keyframe and edge of range or no keyframes
227 if(range_start == range_end)
229 // Between first keyframe and start of effect
230 if(get_source_position() >= get_source_start() &&
231 get_source_position() < range_start)
233 range_start = get_source_start();
236 // Between last keyframe and end of effect
237 if(get_source_position() >= range_start &&
238 get_source_position() < get_source_start() + get_total_len())
240 range_end = get_source_start() + get_total_len();
244 // Should never get here
250 // Convert start position to new direction
251 if(get_direction() == PLAY_FORWARD)
253 input_position = get_source_position() - range_start;
254 input_position = range_end - input_position - 1;
258 input_position = range_end - get_source_position();
259 input_position = range_start + input_position + 1;
261 // printf("ReverseVideo::load_configuration 2 start=%lld end=%lld current=%lld input=%lld\n",
264 // get_source_position(),
271 void ReverseVideo::save_data(KeyFrame *keyframe)
275 // cause data to be stored directly in text
276 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
277 output.tag.set_title("REVERSEVIDEO");
278 output.tag.set_property("ENABLED", config.enabled);
280 output.terminate_string();
283 void ReverseVideo::read_data(KeyFrame *keyframe)
287 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
289 while(!input.read_tag())
291 if(input.tag.title_is("REVERSEVIDEO"))
293 config.enabled = input.tag.get_property("ENABLED", config.enabled);
298 void ReverseVideo::update_gui()
302 load_configuration();
303 thread->window->lock_window();
304 ((ReverseVideoWindow*)thread->window)->enabled->update(config.enabled);
305 thread->window->unlock_window();