r1005: Increase the number of displayed digits for resample audio dialog box
[cinelerra_cv/mob.git] / cinelerra / pluginvclient.C
blobf8fbd6770b70e804d69a8db0e50d443d6c72208c
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "pluginserver.h"
4 #include "pluginvclient.h"
5 #include "vframe.h"
7 #include <string.h>
9 PluginVClient::PluginVClient(PluginServer *server)
10  : PluginClient(server)
12         video_in = 0;
13         video_out = 0;
14         temp = 0;
15         if(server &&
16                 server->edl &&
17                 server->edl->session)
18         {
19                 project_frame_rate = server->edl->session->frame_rate;
20                 frame_rate = project_frame_rate;
21         }
22         else
23         {
24                 project_frame_rate = 1.0;
25                 frame_rate = project_frame_rate;
26         }
29 PluginVClient::~PluginVClient()
31         if(temp) delete temp;
34 int PluginVClient::is_video()
36         return 1;
39 VFrame* PluginVClient::new_temp(int w, int h, int color_model)
41         if(temp && 
42                 (temp->get_w() != w ||
43                 temp->get_h() != h ||
44                 temp->get_color_model() != color_model))
45         {
46                 delete temp;
47                 temp = 0;
48         }
50         if(!temp)
51         {
52                 temp = new VFrame(0, w, h, color_model);
53         }
55         return temp;
58 void PluginVClient::age_temp()
60         if(temp &&
61                 temp->get_w() > PLUGIN_MAX_W &&
62                 temp->get_h() > PLUGIN_MAX_H)
63         {
64                 delete temp;
65                 temp = 0;
66         }
69 VFrame* PluginVClient::get_temp()
71         return temp;
74 // Run before every realtime buffer is to be rendered.
75 int PluginVClient::get_render_ptrs()
77         int i, j, double_buffer, fragment_position;
79         for(i = 0; i < total_in_buffers; i++)
80         {
81                 double_buffer = double_buffer_in_render.values[i];
82                 fragment_position = offset_in_render.values[i];
83                 input_ptr_render[i] = &input_ptr_master.values[i][double_buffer][fragment_position];
84         }
86         for(i = 0; i < total_out_buffers; i++)
87         {
88                 double_buffer = double_buffer_out_render.values[i];
89                 fragment_position = offset_out_render.values[i];
90                 output_ptr_render[i] = &output_ptr_master.values[i][double_buffer][fragment_position];
91         }
92         return 0;
95 // Run after the non realtime plugin is run.
96 int PluginVClient::delete_nonrealtime_parameters()
98         int i, j;
100         for(i = 0; i < total_in_buffers; i++)
101         {
102                 for(j = 0; j < in_buffer_size; j++)
103                 {
104                         delete video_in[i][j];
105                 }
106         }
108         for(i = 0; i < total_out_buffers; i++)
109         {
110                 for(j = 0; j < out_buffer_size; j++)
111                 {
112                         delete video_out[i][j];
113                 }
114         }
115         video_in = 0;
116         video_out = 0;
118         return 0;
121 int PluginVClient::init_realtime_parameters()
123         project_frame_rate = server->edl->session->frame_rate;
124         project_color_model = server->edl->session->color_model;
125         aspect_w = server->edl->session->aspect_w;
126         aspect_h = server->edl->session->aspect_h;
127         return 0;
130 int PluginVClient::process_realtime(VFrame **input, 
131         VFrame **output)
133         return 0; 
136 int PluginVClient::process_realtime(VFrame *input, 
137         VFrame *output) 
139         return 0; 
142 int PluginVClient::process_buffer(VFrame **frame,
143         int64_t start_position,
144         double frame_rate)
146         for(int i = 0; i < PluginClient::total_in_buffers; i++)
147                 read_frame(frame[i], i, start_position, frame_rate);
148         if(is_multichannel())
149                 process_realtime(frame, frame);
150         return 0;
153 int PluginVClient::process_buffer(VFrame *frame,
154         int64_t start_position,
155         double frame_rate)
157         read_frame(frame, 0, start_position, frame_rate);
158         process_realtime(frame, frame);
159         return 0;
163 // Replaced by pull method
164 // void PluginVClient::plugin_process_realtime(VFrame **input, 
165 //              VFrame **output, 
166 //              int64_t current_position,
167 //              int64_t total_len)
168 // {
169 //      this->source_position = current_position;
170 //      this->total_len = total_len;
171 // 
172 //      if(is_multichannel())
173 //              process_realtime(input, output);
174 //      else
175 //              process_realtime(input[0], output[0]);
176 // }
178 void PluginVClient::plugin_render_gui(void *data)
180         render_gui(data);
183 void PluginVClient::send_render_gui(void *data)
185         server->send_render_gui(data);
188 int PluginVClient::plugin_start_loop(int64_t start, 
189         int64_t end, 
190         int64_t buffer_size, 
191         int total_buffers)
193         frame_rate = get_project_framerate();
194         return PluginClient::plugin_start_loop(start, 
195                 end, 
196                 buffer_size, 
197                 total_buffers);
200 int PluginVClient::plugin_get_parameters()
202         frame_rate = get_project_framerate();
203         return PluginClient::plugin_get_parameters();
206 int64_t PluginVClient::local_to_edl(int64_t position)
208         if(position < 0) return position;
209         return (int64_t)Units::round(position * 
210                 get_project_framerate() /
211                 frame_rate);
212         return 0;
215 int64_t PluginVClient::edl_to_local(int64_t position)
217         if(position < 0) return position;
218         return (int64_t)Units::round(position * 
219                 frame_rate /
220                 get_project_framerate());
223 int PluginVClient::plugin_process_loop(VFrame **buffers, int64_t &write_length)
225         int result = 0;
227         if(is_multichannel())
228                 result = process_loop(buffers);
229         else
230                 result = process_loop(buffers[0]);
233         write_length = 1;
235         return result;
239 int PluginVClient::run_opengl()
241         server->run_opengl(this);
242         return 0;
245 int PluginVClient::handle_opengl()
247         return 0;
250 VFrame* PluginVClient::get_input(int channel)
252         return input[channel];
255 VFrame* PluginVClient::get_output(int channel)
257         return output[channel];
260 int PluginVClient::next_effect_is(char *title)
262         return !strcmp(title, output[0]->get_next_effect());
265 int PluginVClient::prev_effect_is(char *title)
267         return !strcmp(title, output[0]->get_prev_effect());
272 int PluginVClient::read_frame(VFrame *buffer, 
273         int channel, 
274         int64_t start_position)
276         return server->read_frame(buffer, 
277                 channel, 
278                 start_position);
281 int PluginVClient::read_frame(VFrame *buffer, 
282         int64_t start_position)
284         return server->read_frame(buffer, 
285                 0, 
286                 start_position);
289 int PluginVClient::read_frame(VFrame *buffer, 
290                 int channel, 
291                 int64_t start_position,
292                 double frame_rate,
293                 int use_opengl)
295         return server->read_frame(buffer,
296                 channel,
297                 start_position,
298                 frame_rate,
299                 use_opengl);
303 double PluginVClient::get_project_framerate()
305         return project_frame_rate;
308 double PluginVClient::get_framerate()
310         return frame_rate;