Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginvclient.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "bcsignals.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "pluginserver.h"
27 #include "pluginvclient.h"
28 #include "vframe.h"
29
30 #include <string.h>
31
32 PluginVClient::PluginVClient(PluginServer *server)
33  : PluginClient(server)
34 {
35         video_in = 0;
36         video_out = 0;
37         temp = 0;
38         if(server &&
39                 server->edl &&
40                 server->edl->session)
41         {
42                 project_frame_rate = server->edl->session->frame_rate;
43                 frame_rate = project_frame_rate;
44         }
45         else
46         {
47                 project_frame_rate = 1.0;
48                 frame_rate = project_frame_rate;
49         }
50 }
51
52 PluginVClient::~PluginVClient()
53 {
54         if(temp) delete temp;
55 }
56
57 int PluginVClient::is_video()
58 {
59         return 1;
60 }
61
62 VFrame* PluginVClient::new_temp(int w, int h, int color_model)
63 {
64         if(temp &&
65                 (temp->get_w() != w ||
66                 temp->get_h() != h ||
67                 temp->get_color_model() != color_model))
68         {
69                 delete temp;
70                 temp = 0;
71         }
72
73         if(!temp)
74         {
75                 temp = new VFrame(w, h, color_model, 0);
76         }
77
78         return temp;
79 }
80
81 void PluginVClient::age_temp()
82 {
83         if(temp &&
84                 temp->get_w() > PLUGIN_MAX_W &&
85                 temp->get_h() > PLUGIN_MAX_H)
86         {
87                 delete temp;
88                 temp = 0;
89         }
90 }
91
92 VFrame* PluginVClient::get_temp()
93 {
94         return temp;
95 }
96
97 // Run before every realtime buffer is to be rendered.
98 int PluginVClient::get_render_ptrs()
99 {
100         int i, double_buffer, fragment_position;
101
102         for(i = 0; i < total_in_buffers; i++)
103         {
104                 double_buffer = double_buffer_in_render.values[i];
105                 fragment_position = offset_in_render.values[i];
106                 input_ptr_render[i] = &input_ptr_master.values[i][double_buffer][fragment_position];
107         }
108
109         for(i = 0; i < total_out_buffers; i++)
110         {
111                 double_buffer = double_buffer_out_render.values[i];
112                 fragment_position = offset_out_render.values[i];
113                 output_ptr_render[i] = &output_ptr_master.values[i][double_buffer][fragment_position];
114         }
115         return 0;
116 }
117
118 // Run after the non realtime plugin is run.
119 int PluginVClient::delete_nonrealtime_parameters()
120 {
121         int i, j;
122
123         for(i = 0; i < total_in_buffers; i++)
124         {
125                 for(j = 0; j < in_buffer_size; j++)
126                 {
127                         delete video_in[i][j];
128                 }
129         }
130
131         for(i = 0; i < total_out_buffers; i++)
132         {
133                 for(j = 0; j < out_buffer_size; j++)
134                 {
135                         delete video_out[i][j];
136                 }
137         }
138         video_in = 0;
139         video_out = 0;
140
141         return 0;
142 }
143
144 int PluginVClient::init_realtime_parameters()
145 {
146         project_frame_rate = server->edl->session->frame_rate;
147         project_color_model = server->edl->session->color_model;
148         aspect_w = server->edl->session->aspect_w;
149         aspect_h = server->edl->session->aspect_h;
150         return 0;
151 }
152
153 int PluginVClient::process_realtime(VFrame **input,
154         VFrame **output)
155 {
156         return 0;
157 }
158
159 int PluginVClient::process_realtime(VFrame *input,
160         VFrame *output)
161 {
162         return 0;
163 }
164
165 int PluginVClient::process_buffer(VFrame **frame,
166         int64_t start_position,
167         double frame_rate)
168 {
169 //PRINT_TRACE
170         for(int i = 0; i < PluginClient::total_in_buffers; i++)
171                 read_frame(frame[i], i, start_position, frame_rate, 0);
172         if(is_multichannel())
173                 process_realtime(frame, frame);
174         return 0;
175 }
176
177 int PluginVClient::process_buffer(VFrame *frame,
178         int64_t start_position,
179         double frame_rate)
180 {
181         read_frame(frame, 0, start_position, frame_rate, 0);
182         process_realtime(frame, frame);
183         return 0;
184 }
185
186
187 int PluginVClient::plugin_start_loop(int64_t start,
188         int64_t end,
189         int64_t buffer_size,
190         int total_buffers)
191 {
192         frame_rate = get_project_framerate();
193         return PluginClient::plugin_start_loop(start,
194                 end,
195                 buffer_size,
196                 total_buffers);
197 }
198
199 int PluginVClient::plugin_get_parameters()
200 {
201         frame_rate = get_project_framerate();
202         return PluginClient::plugin_get_parameters();
203 }
204
205 int64_t PluginVClient::local_to_edl(int64_t position)
206 {
207         if(position < 0) return position;
208         return (int64_t)Units::round(position *
209                 get_project_framerate() /
210                 frame_rate);
211         return 0;
212 }
213
214 int64_t PluginVClient::edl_to_local(int64_t position)
215 {
216         if(position < 0) return position;
217         return (int64_t)Units::round(position *
218                 frame_rate /
219                 get_project_framerate());
220 }
221
222 int PluginVClient::plugin_process_loop(VFrame **buffers, int64_t &write_length)
223 {
224         int result = 0;
225
226         if(is_multichannel())
227                 result = process_loop(buffers);
228         else
229                 result = process_loop(buffers[0]);
230
231
232         write_length = 1;
233
234         return result;
235 }
236
237
238 int PluginVClient::run_opengl()
239 {
240         server->run_opengl(this);
241         return 0;
242 }
243
244 int PluginVClient::handle_opengl()
245 {
246         return 0;
247 }
248
249 VFrame* PluginVClient::get_input(int channel)
250 {
251         return input[channel];
252 }
253
254 VFrame* PluginVClient::get_output(int channel)
255 {
256         return output[channel];
257 }
258
259 int PluginVClient::next_effect_is(const char *title)
260 {
261         return !strcmp(title, output[0]->get_next_effect());
262 }
263
264 int PluginVClient::prev_effect_is(const char *title)
265 {
266         return !strcmp(title, output[0]->get_prev_effect());
267 }
268
269
270
271 int PluginVClient::read_frame(VFrame *buffer,
272         int channel,
273         int64_t start_position)
274 {
275         return server->read_frame(buffer,
276                 channel,
277                 start_position);
278 }
279
280 int PluginVClient::read_frame(VFrame *buffer,
281         int64_t start_position)
282 {
283         return server->read_frame(buffer,
284                 0,
285                 start_position);
286 }
287
288 int PluginVClient::read_frame(VFrame *buffer,
289                 int channel,
290                 int64_t start_position,
291                 double frame_rate,
292                 int use_opengl)
293 {
294         return server->read_frame(buffer,
295                 channel,
296                 start_position,
297                 frame_rate,
298                 use_opengl);
299 }
300
301
302 double PluginVClient::get_project_framerate()
303 {
304         return project_frame_rate;
305 }
306
307 double PluginVClient::get_framerate()
308 {
309         return frame_rate;
310 }
311
312 ArrayList<BC_FontEntry*> *PluginVClient::get_fontlist()
313 {
314         return BC_Resources::fontlist;
315 }
316
317 BC_FontEntry *PluginVClient::find_fontentry(const char *displayname, int style,
318         int mask, int preferred_style)
319 {
320         return BC_Resources::find_fontentry(displayname, style, mask, preferred_style);
321 }
322
323 int PluginVClient::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
324 {
325         return BC_Resources::find_font_by_char(char_code, path_new, oldface);
326 }
327
328 int64_t PluginVClient::get_startproject()
329 {
330         int64_t pos = server->get_startproject();
331         return  pos >= 0 ? pos : 0;
332 }
333
334 int64_t PluginVClient::get_endproject()
335 {
336         int64_t pos = server->get_endproject();
337         return  pos >= 0 ? pos : get_edl()->get_video_frames();
338 }
339