00001 #include "bcdisplayinfo.h"
00002 #include "bchash.h"
00003 #include "filexml.h"
00004 #include "guicast.h"
00005 #include "language.h"
00006 #include "pluginvclient.h"
00007 #include "transportque.h"
00008
00009 #include <string.h>
00010
00011 class ReverseVideo;
00012
00013 class ReverseVideoConfig
00014 {
00015 public:
00016 ReverseVideoConfig();
00017 int enabled;
00018 };
00019
00020
00021 class ReverseVideoEnabled : public BC_CheckBox
00022 {
00023 public:
00024 ReverseVideoEnabled(ReverseVideo *plugin,
00025 int x,
00026 int y);
00027 int handle_event();
00028 ReverseVideo *plugin;
00029 };
00030
00031 class ReverseVideoWindow : public BC_Window
00032 {
00033 public:
00034 ReverseVideoWindow(ReverseVideo *plugin, int x, int y);
00035 ~ReverseVideoWindow();
00036 void create_objects();
00037 int close_event();
00038 ReverseVideo *plugin;
00039 ReverseVideoEnabled *enabled;
00040 };
00041
00042 PLUGIN_THREAD_HEADER(ReverseVideo, ReverseVideoThread, ReverseVideoWindow)
00043
00044 class ReverseVideo : public PluginVClient
00045 {
00046 public:
00047 ReverseVideo(PluginServer *server);
00048 ~ReverseVideo();
00049
00050 PLUGIN_CLASS_MEMBERS(ReverseVideoConfig, ReverseVideoThread)
00051
00052 int load_defaults();
00053 int save_defaults();
00054 void save_data(KeyFrame *keyframe);
00055 void read_data(KeyFrame *keyframe);
00056 void update_gui();
00057 int is_realtime();
00058 int process_buffer(VFrame *frame,
00059 int64_t start_position,
00060 double frame_rate);
00061
00062 int64_t input_position;
00063 };
00064
00065
00066
00067
00068
00069
00070
00071 REGISTER_PLUGIN(ReverseVideo);
00072
00073
00074
00075 ReverseVideoConfig::ReverseVideoConfig()
00076 {
00077 enabled = 1;
00078 }
00079
00080
00081
00082
00083
00084 ReverseVideoWindow::ReverseVideoWindow(ReverseVideo *plugin, int x, int y)
00085 : BC_Window(plugin->gui_string,
00086 x,
00087 y,
00088 210,
00089 160,
00090 200,
00091 160,
00092 0,
00093 0,
00094 1)
00095 {
00096 this->plugin = plugin;
00097 }
00098
00099 ReverseVideoWindow::~ReverseVideoWindow()
00100 {
00101 }
00102
00103 void ReverseVideoWindow::create_objects()
00104 {
00105 int x = 10, y = 10;
00106
00107 add_subwindow(enabled = new ReverseVideoEnabled(plugin,
00108 x,
00109 y));
00110 show_window();
00111 flush();
00112 }
00113
00114 WINDOW_CLOSE_EVENT(ReverseVideoWindow)
00115
00116
00117 PLUGIN_THREAD_OBJECT(ReverseVideo, ReverseVideoThread, ReverseVideoWindow)
00118
00119
00120
00121
00122
00123
00124 ReverseVideoEnabled::ReverseVideoEnabled(ReverseVideo *plugin,
00125 int x,
00126 int y)
00127 : BC_CheckBox(x,
00128 y,
00129 plugin->config.enabled,
00130 _("Enabled"))
00131 {
00132 this->plugin = plugin;
00133 }
00134
00135 int ReverseVideoEnabled::handle_event()
00136 {
00137 plugin->config.enabled = get_value();
00138 plugin->send_configure_change();
00139 return 1;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 ReverseVideo::ReverseVideo(PluginServer *server)
00151 : PluginVClient(server)
00152 {
00153 PLUGIN_CONSTRUCTOR_MACRO
00154 }
00155
00156
00157 ReverseVideo::~ReverseVideo()
00158 {
00159 PLUGIN_DESTRUCTOR_MACRO
00160 }
00161
00162 char* ReverseVideo::plugin_title() { return N_("Reverse video"); }
00163 int ReverseVideo::is_realtime() { return 1; }
00164
00165 #include "picon_png.h"
00166 NEW_PICON_MACRO(ReverseVideo)
00167
00168 SHOW_GUI_MACRO(ReverseVideo, ReverseVideoThread)
00169
00170 RAISE_WINDOW_MACRO(ReverseVideo)
00171
00172 SET_STRING_MACRO(ReverseVideo);
00173
00174
00175 int ReverseVideo::process_buffer(VFrame *frame,
00176 int64_t start_position,
00177 double frame_rate)
00178 {
00179 load_configuration();
00180
00181 if(config.enabled)
00182 read_frame(frame,
00183 0,
00184 input_position,
00185 frame_rate);
00186 else
00187 read_frame(frame,
00188 0,
00189 start_position,
00190 frame_rate);
00191 return 0;
00192 }
00193
00194
00195
00196
00197 int ReverseVideo::load_configuration()
00198 {
00199 KeyFrame *prev_keyframe, *next_keyframe;
00200 next_keyframe = get_next_keyframe(get_source_position());
00201 prev_keyframe = get_prev_keyframe(get_source_position());
00202
00203 read_data(prev_keyframe);
00204
00205 int64_t prev_position = edl_to_local(prev_keyframe->position);
00206 int64_t next_position = edl_to_local(next_keyframe->position);
00207
00208 if(prev_position == 0 && next_position == 0)
00209 {
00210 next_position = prev_position = get_source_start();
00211 }
00212
00213
00214 int64_t range_start = prev_position;
00215 int64_t range_end = next_position;
00216
00217
00218 if(range_start == range_end)
00219 {
00220
00221 if(get_source_position() >= get_source_start() &&
00222 get_source_position() < range_start)
00223 {
00224 range_start = get_source_start();
00225 }
00226 else
00227
00228 if(get_source_position() >= range_start &&
00229 get_source_position() < get_source_start() + get_total_len())
00230 {
00231 range_end = get_source_start() + get_total_len();
00232 }
00233 else
00234 {
00235
00236 ;
00237 }
00238 }
00239
00240
00241
00242 if(get_direction() == PLAY_FORWARD)
00243 {
00244 input_position = get_source_position() - range_start;
00245 input_position = range_end - input_position - 1;
00246 }
00247 else
00248 {
00249 input_position = range_end - get_source_position();
00250 input_position = range_start + input_position + 1;
00251 }
00252
00253
00254
00255
00256
00257
00258 return 0;
00259 }
00260
00261 int ReverseVideo::load_defaults()
00262 {
00263 char directory[BCTEXTLEN];
00264
00265 sprintf(directory, "%sreversevideo.rc", BCASTDIR);
00266
00267
00268 defaults = new BC_Hash(directory);
00269 defaults->load();
00270
00271 config.enabled = defaults->get("ENABLED", config.enabled);
00272 return 0;
00273 }
00274
00275 int ReverseVideo::save_defaults()
00276 {
00277 defaults->update("ENABLED", config.enabled);
00278 defaults->save();
00279 return 0;
00280 }
00281
00282 void ReverseVideo::save_data(KeyFrame *keyframe)
00283 {
00284 FileXML output;
00285
00286
00287 output.set_shared_string(keyframe->data, MESSAGESIZE);
00288 output.tag.set_title("REVERSEVIDEO");
00289 output.tag.set_property("ENABLED", config.enabled);
00290 output.append_tag();
00291 output.tag.set_title("/REVERSEVIDEO");
00292 output.append_tag();
00293 output.terminate_string();
00294 }
00295
00296 void ReverseVideo::read_data(KeyFrame *keyframe)
00297 {
00298 FileXML input;
00299
00300 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00301
00302 int result = 0;
00303
00304 while(!input.read_tag())
00305 {
00306 if(input.tag.title_is("REVERSEVIDEO"))
00307 {
00308 config.enabled = input.tag.get_property("ENABLED", config.enabled);
00309 }
00310 }
00311 }
00312
00313 void ReverseVideo::update_gui()
00314 {
00315 if(thread)
00316 {
00317 load_configuration();
00318 thread->window->lock_window();
00319 thread->window->enabled->update(config.enabled);
00320 thread->window->unlock_window();
00321 }
00322 }
00323
00324
00325
00326
00327