add ffmpeg vaapi hw encode, colorpicker fix alpha, titler layout timecode, booby...
[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  *
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 "bcsignals.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "pluginserver.h"
26 #include "pluginvclient.h"
27 #include "vframe.h"
28
29 #include <string.h>
30
31 PluginVClient::PluginVClient(PluginServer *server)
32  : PluginClient(server)
33 {
34         video_in = 0;
35         video_out = 0;
36         temp = 0;
37         if(server &&
38                 server->edl &&
39                 server->edl->session)
40         {
41                 project_frame_rate = server->edl->session->frame_rate;
42                 frame_rate = project_frame_rate;
43         }
44         else
45         {
46                 project_frame_rate = 1.0;
47                 frame_rate = project_frame_rate;
48         }
49 }
50
51 PluginVClient::~PluginVClient()
52 {
53         if(temp) delete temp;
54 }
55
56 int PluginVClient::is_video()
57 {
58         return 1;
59 }
60
61 VFrame* PluginVClient::new_temp(int w, int h, int color_model)
62 {
63         if(temp &&
64                 (temp->get_w() != w ||
65                 temp->get_h() != h ||
66                 temp->get_color_model() != color_model))
67         {
68                 delete temp;
69                 temp = 0;
70         }
71
72         if(!temp)
73         {
74                 temp = new VFrame(w, h, color_model, 0);
75         }
76
77         return temp;
78 }
79
80 void PluginVClient::age_temp()
81 {
82         if(temp &&
83                 temp->get_w() > PLUGIN_MAX_W &&
84                 temp->get_h() > PLUGIN_MAX_H)
85         {
86                 delete temp;
87                 temp = 0;
88         }
89 }
90
91 VFrame* PluginVClient::get_temp()
92 {
93         return temp;
94 }
95
96 // Run before every realtime buffer is to be rendered.
97 int PluginVClient::get_render_ptrs()
98 {
99         int i, double_buffer, fragment_position;
100
101         for(i = 0; i < total_in_buffers; i++)
102         {
103                 double_buffer = double_buffer_in_render.values[i];
104                 fragment_position = offset_in_render.values[i];
105                 input_ptr_render[i] = &input_ptr_master.values[i][double_buffer][fragment_position];
106         }
107
108         for(i = 0; i < total_out_buffers; i++)
109         {
110                 double_buffer = double_buffer_out_render.values[i];
111                 fragment_position = offset_out_render.values[i];
112                 output_ptr_render[i] = &output_ptr_master.values[i][double_buffer][fragment_position];
113         }
114         return 0;
115 }
116
117 // Run after the non realtime plugin is run.
118 int PluginVClient::delete_nonrealtime_parameters()
119 {
120         int i, j;
121
122         for(i = 0; i < total_in_buffers; i++)
123         {
124                 for(j = 0; j < in_buffer_size; j++)
125                 {
126                         delete video_in[i][j];
127                 }
128         }
129
130         for(i = 0; i < total_out_buffers; i++)
131         {
132                 for(j = 0; j < out_buffer_size; j++)
133                 {
134                         delete video_out[i][j];
135                 }
136         }
137         video_in = 0;
138         video_out = 0;
139
140         return 0;
141 }
142
143 int PluginVClient::init_realtime_parameters()
144 {
145         project_frame_rate = server->edl->session->frame_rate;
146         project_color_model = server->edl->session->color_model;
147         aspect_w = server->edl->session->aspect_w;
148         aspect_h = server->edl->session->aspect_h;
149         return 0;
150 }
151
152 int PluginVClient::process_realtime(VFrame **input,
153         VFrame **output)
154 {
155         return 0;
156 }
157
158 int PluginVClient::process_realtime(VFrame *input,
159         VFrame *output)
160 {
161         return 0;
162 }
163
164 int PluginVClient::process_buffer(VFrame **frame,
165         int64_t start_position,
166         double frame_rate)
167 {
168 //PRINT_TRACE
169         for(int i = 0; i < PluginClient::total_in_buffers; i++)
170                 read_frame(frame[i], i, start_position, frame_rate, 0);
171         if(is_multichannel())
172                 process_realtime(frame, frame);
173         return 0;
174 }
175
176 int PluginVClient::process_buffer(VFrame *frame,
177         int64_t start_position,
178         double frame_rate)
179 {
180         read_frame(frame, 0, start_position, frame_rate, 0);
181         process_realtime(frame, frame);
182         return 0;
183 }
184
185
186 int PluginVClient::plugin_start_loop(int64_t start,
187         int64_t end,
188         int64_t buffer_size,
189         int total_buffers)
190 {
191         frame_rate = get_project_framerate();
192         return PluginClient::plugin_start_loop(start,
193                 end,
194                 buffer_size,
195                 total_buffers);
196 }
197
198 int PluginVClient::plugin_get_parameters()
199 {
200         frame_rate = get_project_framerate();
201         return PluginClient::plugin_get_parameters();
202 }
203
204 int64_t PluginVClient::local_to_edl(int64_t position)
205 {
206         if(position < 0) return position;
207         return (int64_t)Units::round(position *
208                 get_project_framerate() /
209                 frame_rate);
210         return 0;
211 }
212
213 int64_t PluginVClient::edl_to_local(int64_t position)
214 {
215         if(position < 0) return position;
216         return (int64_t)Units::round(position *
217                 frame_rate /
218                 get_project_framerate());
219 }
220
221 int PluginVClient::plugin_process_loop(VFrame **buffers, int64_t &write_length)
222 {
223         int result = 0;
224
225         if(is_multichannel())
226                 result = process_loop(buffers);
227         else
228                 result = process_loop(buffers[0]);
229
230
231         write_length = 1;
232
233         return result;
234 }
235
236
237 int PluginVClient::run_opengl()
238 {
239         server->run_opengl(this);
240         return 0;
241 }
242
243 int PluginVClient::handle_opengl()
244 {
245         return 0;
246 }
247
248 VFrame* PluginVClient::get_input(int channel)
249 {
250         return input[channel];
251 }
252
253 VFrame* PluginVClient::get_output(int channel)
254 {
255         return output[channel];
256 }
257
258 int PluginVClient::next_effect_is(const char *title)
259 {
260         return !strcmp(title, output[0]->get_next_effect());
261 }
262
263 int PluginVClient::prev_effect_is(const char *title)
264 {
265         return !strcmp(title, output[0]->get_prev_effect());
266 }
267
268
269
270 int PluginVClient::read_frame(VFrame *buffer,
271         int channel,
272         int64_t start_position)
273 {
274         return server->read_frame(buffer,
275                 channel,
276                 start_position);
277 }
278
279 int PluginVClient::read_frame(VFrame *buffer,
280         int64_t start_position)
281 {
282         return server->read_frame(buffer,
283                 0,
284                 start_position);
285 }
286
287 int PluginVClient::read_frame(VFrame *buffer,
288                 int channel,
289                 int64_t start_position,
290                 double frame_rate,
291                 int use_opengl)
292 {
293         return server->read_frame(buffer,
294                 channel,
295                 start_position,
296                 frame_rate,
297                 use_opengl);
298 }
299
300
301 double PluginVClient::get_project_framerate()
302 {
303         return project_frame_rate;
304 }
305
306 double PluginVClient::get_framerate()
307 {
308         return frame_rate;
309 }
310
311 ArrayList<BC_FontEntry*> *PluginVClient::get_fontlist()
312 {
313         return BC_Resources::fontlist;
314 }
315
316 BC_FontEntry *PluginVClient::find_fontentry(const char *displayname, int style,
317         int mask, int preferred_style)
318 {
319         return BC_Resources::find_fontentry(displayname, style, mask, preferred_style);
320 }
321
322 int PluginVClient::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
323 {
324         return BC_Resources::find_font_by_char(char_code, path_new, oldface);
325 }