edl plugin names eng, fix segv for opengl brender, renderfarm rework strategy, perf...
[goodguy/history.git] / cinelerra-5.1 / plugins / delayvideo / delayvideo.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "bchash.h"
25 #include "delayvideo.h"
26 #include "filexml.h"
27 #include "language.h"
28 #include "vframe.h"
29
30
31
32
33 #include <string.h>
34
35
36
37
38
39
40 REGISTER_PLUGIN(DelayVideo)
41
42
43
44
45
46 DelayVideoConfig::DelayVideoConfig()
47 {
48         length = 0;
49 }
50
51 int DelayVideoConfig::equivalent(DelayVideoConfig &that)
52 {
53         return EQUIV(length, that.length);
54 }
55
56 void DelayVideoConfig::copy_from(DelayVideoConfig &that)
57 {
58         length = that.length;
59 }
60
61 void DelayVideoConfig::interpolate(DelayVideoConfig &prev,
62                 DelayVideoConfig &next,
63                 int64_t prev_frame,
64                 int64_t next_frame,
65                 int64_t current_frame)
66 {
67         this->length = prev.length;
68 }
69
70
71
72 DelayVideoWindow::DelayVideoWindow(DelayVideo *plugin)
73  : PluginClientWindow(plugin,
74         210,
75         120,
76         210,
77         120,
78         0)
79 {
80         this->plugin = plugin;
81 }
82
83 DelayVideoWindow::~DelayVideoWindow()
84 {
85 }
86
87
88 void DelayVideoWindow::create_objects()
89 {
90         int x = 10, y = 10;
91
92         add_subwindow(new BC_Title(x, y, _("Delay seconds:")));
93         y += 20;
94         slider = new DelayVideoSlider(this, plugin, x, y);
95         slider->create_objects();
96         show_window();
97 }
98
99
100 void DelayVideoWindow::update_gui()
101 {
102         char string[BCTEXTLEN];
103         sprintf(string, "%.04f", plugin->config.length);
104         slider->update(string);
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118 DelayVideoSlider::DelayVideoSlider(DelayVideoWindow *window,
119         DelayVideo *plugin,
120         int x,
121         int y)
122  : BC_TumbleTextBox(window,
123         (float)plugin->config.length,
124         (float)0,
125         (float)10,
126         x,
127         y,
128         150)
129 {
130         this->plugin = plugin;
131         set_increment(0.1);
132 }
133
134 int DelayVideoSlider::handle_event()
135 {
136         plugin->config.length = atof(get_text());
137         plugin->send_configure_change();
138         return 1;
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 DelayVideo::DelayVideo(PluginServer *server)
158  : PluginVClient(server)
159 {
160         reset();
161 }
162
163 DelayVideo::~DelayVideo()
164 {
165         if(buffer)
166         {
167 //printf("DelayVideo::~DelayVideo 1\n");
168                 for(int i = 0; i < allocation; i++)
169                         delete buffer[i];
170 //printf("DelayVideo::~DelayVideo 1\n");
171
172                 delete [] buffer;
173 //printf("DelayVideo::~DelayVideo 1\n");
174         }
175 }
176
177 void DelayVideo::reset()
178 {
179         thread = 0;
180         need_reconfigure = 1;
181         buffer = 0;
182         allocation = 0;
183 }
184
185 void DelayVideo::reconfigure()
186 {
187         int new_allocation = 1 + (int)(config.length * PluginVClient::project_frame_rate);
188         VFrame **new_buffer = new VFrame*[new_allocation];
189         int reuse = MIN(new_allocation, allocation);
190
191         for(int i = 0; i < reuse; i++)
192         {
193                 new_buffer[i] = buffer[i];
194         }
195
196         for(int i = reuse; i < new_allocation; i++)
197         {
198                 new_buffer[i] = new VFrame(input->get_w(), input->get_h(),
199                         PluginVClient::project_color_model, 0);
200         }
201
202         for(int i = reuse; i < allocation; i++)
203         {
204                 delete buffer[i];
205         }
206
207         if(buffer) delete [] buffer;
208
209
210         buffer = new_buffer;
211         allocation = new_allocation;
212
213         need_reconfigure = 0;
214 }
215
216 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
217 {
218 //printf("DelayVideo::process_realtime 1 %d\n", config.length);
219         this->input = input_ptr;
220         this->output = output_ptr;
221         need_reconfigure += load_configuration();
222         CLAMP(config.length, 0, 10);
223
224 //printf("DelayVideo::process_realtime 2 %d\n", config.length);
225         if(need_reconfigure) reconfigure();
226 //printf("DelayVideo::process_realtime 3 %d %d\n", config.length, allocation);
227
228         buffer[allocation - 1]->copy_from(input_ptr);
229         output_ptr->copy_from(buffer[0]);
230
231         VFrame *temp = buffer[0];
232         for(int i = 0; i < allocation - 1; i++)
233         {
234                 buffer[i] = buffer[i + 1];
235         }
236
237         buffer[allocation - 1] = temp;
238 //printf("DelayVideo::process_realtime 4\n");
239
240
241         return 0;
242 }
243
244 int DelayVideo::is_realtime()
245 {
246         return 1;
247 }
248
249 const char* DelayVideo::plugin_title() { return N_("Delay Video"); }
250
251 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
252 NEW_WINDOW_MACRO(DelayVideo, DelayVideoWindow)
253
254
255 void DelayVideo::save_data(KeyFrame *keyframe)
256 {
257         FileXML output;
258         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
259
260         output.tag.set_title("DELAYVIDEO");
261         output.tag.set_property("LENGTH", (double)config.length);
262         output.append_tag();
263         output.tag.set_title("/DELAYVIDEO");
264         output.append_tag();
265         output.append_newline();
266         output.terminate_string();
267 }
268
269 void DelayVideo::read_data(KeyFrame *keyframe)
270 {
271         FileXML input;
272         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
273
274         int result = 0;
275         while(!result)
276         {
277                 result = input.read_tag();
278
279                 if(!result)
280                 {
281                         if(input.tag.title_is("DELAYVIDEO"))
282                         {
283                                 config.length = input.tag.get_property("LENGTH", (double)config.length);
284                         }
285                 }
286         }
287 }
288
289 void DelayVideo::update_gui()
290 {
291         if(thread)
292         {
293                 load_configuration();
294                 ((DelayVideoWindow*)thread->window)->lock_window();
295                 ((DelayVideoWindow*)thread->window)->slider->update(config.length);
296                 ((DelayVideoWindow*)thread->window)->unlock_window();
297         }
298 }
299
300
301
302
303
304
305