add bluray dv, misc fixes
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginaclient.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 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 "edl.h"
23 #include "edlsession.h"
24 #include "pluginaclient.h"
25 #include "pluginserver.h"
26 #include "samples.h"
27
28 #include <string.h>
29
30
31 PluginAClient::PluginAClient(PluginServer *server)
32  : PluginClient(server)
33 {
34         sample_rate = 0;
35         if(server &&
36                 server->edl &&
37                 server->edl->session)
38         {
39                 project_sample_rate = server->edl->session->sample_rate;
40                 sample_rate = project_sample_rate;
41         }
42         else
43         {
44                 project_sample_rate = 1;
45                 sample_rate = 1;
46         }
47 }
48
49 PluginAClient::~PluginAClient()
50 {
51 }
52
53 int PluginAClient::is_audio()
54 {
55         return 1;
56 }
57
58
59 int PluginAClient::get_render_ptrs()
60 {
61         int i, double_buffer, fragment_position;
62
63         for(i = 0; i < total_in_buffers; i++)
64         {
65                 double_buffer = double_buffer_in_render.values[i];
66                 fragment_position = offset_in_render.values[i];
67                 input_ptr_render[i] = &input_ptr_master.values[i][double_buffer][fragment_position];
68 //printf("PluginAClient::get_render_ptrs %x\n", input_ptr_master.values[i][double_buffer]);
69         }
70
71         for(i = 0; i < total_out_buffers; i++)
72         {
73                 double_buffer = double_buffer_out_render.values[i];
74                 fragment_position = offset_out_render.values[i];
75                 output_ptr_render[i] = &output_ptr_master.values[i][double_buffer][fragment_position];
76         }
77 //printf("PluginAClient::get_render_ptrs %x %x\n", input_ptr_render[0], output_ptr_render[0]);
78         return 0;
79 }
80
81 int PluginAClient::init_realtime_parameters()
82 {
83         project_sample_rate = server->edl->session->sample_rate;
84         return 0;
85 }
86
87 int PluginAClient::process_realtime(int64_t size,
88         Samples **input_ptr,
89         Samples **output_ptr)
90 {
91         return 0;
92 }
93
94 int PluginAClient::process_realtime(int64_t size,
95         Samples *input_ptr,
96         Samples *output_ptr)
97 {
98         return 0;
99 }
100
101 int PluginAClient::process_buffer(int64_t size,
102         Samples **buffer,
103         int64_t start_position,
104         int sample_rate)
105 {
106         for(int i = 0; i < PluginClient::total_in_buffers; i++)
107                 read_samples(buffer[i],
108                         i,
109                         sample_rate,
110                         source_position,
111                         size);
112         process_realtime(size, buffer, buffer);
113         return 0;
114 }
115
116 int PluginAClient::process_buffer(int64_t size,
117         Samples *buffer,
118         int64_t start_position,
119         int sample_rate)
120 {
121         read_samples(buffer,
122                 0,
123                 sample_rate,
124                 source_position,
125                 size);
126         process_realtime(size, buffer, buffer);
127         return 0;
128 }
129
130
131
132
133 int PluginAClient::plugin_start_loop(int64_t start,
134         int64_t end,
135         int64_t buffer_size,
136         int total_buffers)
137 {
138         sample_rate = get_project_samplerate();
139         return PluginClient::plugin_start_loop(start,
140                 end,
141                 buffer_size,
142                 total_buffers);
143 }
144
145 int PluginAClient::plugin_get_parameters()
146 {
147         sample_rate = get_project_samplerate();
148         return PluginClient::plugin_get_parameters();
149 }
150
151
152 int64_t PluginAClient::local_to_edl(int64_t position)
153 {
154         if(position < 0) return position;
155         return (int64_t)(position *
156                 get_project_samplerate() /
157                 sample_rate);
158         return 0;
159 }
160
161 int64_t PluginAClient::edl_to_local(int64_t position)
162 {
163         if(position < 0) return position;
164         return (int64_t)(position *
165                 sample_rate /
166                 get_project_samplerate());
167 }
168
169
170 int PluginAClient::plugin_process_loop(Samples **buffers, int64_t &write_length)
171 {
172         write_length = 0;
173
174         if(is_multichannel())
175                 return process_loop(buffers, write_length);
176         else
177                 return process_loop(buffers[0], write_length);
178 }
179
180 int PluginAClient::read_samples(Samples *buffer,
181         int channel,
182         int64_t start_position,
183         int64_t total_samples)
184 {
185         return server->read_samples(buffer,
186                 channel,
187                 start_position,
188                 total_samples);
189 }
190
191 int PluginAClient::read_samples(Samples *buffer,
192         int64_t start_position,
193         int64_t total_samples)
194 {
195         return server->read_samples(buffer,
196                 0,
197                 start_position,
198                 total_samples);
199 }
200
201 int PluginAClient::read_samples(Samples *buffer,
202                 int channel,
203                 int sample_rate,
204                 int64_t start_position,
205                 int64_t len)
206 {
207         return server->read_samples(buffer,
208                 channel,
209                 sample_rate,
210                 start_position,
211                 len);
212 }
213
214
215
216
217 int PluginAClient::get_project_samplerate()
218 {
219         return project_sample_rate;
220 }
221
222 int PluginAClient::get_samplerate()
223 {
224         return sample_rate;
225 }
226
227
228
229
230
231