Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / playbackconfig.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 "clip.h"
24 #include "bchash.h"
25 #include "playbackconfig.h"
26 #include "videodevice.inc"
27 #include <string.h>
28
29 AudioOutConfig::AudioOutConfig()
30 {
31         fragment_size = 16384;
32 #ifdef HAVE_ALSA
33         driver = AUDIO_ALSA;
34 #else
35 #ifdef HAVE_PULSE
36         driver = AUDIO_PULSE;
37 #else
38         driver = AUDIO_OSS;
39 #endif
40 #endif
41         audio_offset = 0.0;
42         map51_2 = 0;
43         play_gain = 1.0;
44
45         oss_out_bits = 16;
46         for(int i = 0; i < MAXDEVICES; i++)
47         {
48                 oss_enable[i] = (i == 0);
49                 sprintf(oss_out_device[i], "/dev/dsp");
50         }
51
52         esound_out_server[0] = 0;
53         esound_out_port = 0;
54
55         pulse_out_server[0] = 0;
56
57         sprintf(alsa_out_device, "default");
58         alsa_out_bits = 16;
59         interrupt_workaround = 0;
60
61         firewire_channel = 63;
62         firewire_port = 0;
63         strcpy(firewire_path, "/dev/video1394");
64         firewire_syt = 30000;
65
66         dv1394_channel = 63;
67         dv1394_port = 0;
68         strcpy(dv1394_path, "/dev/dv1394");
69         dv1394_syt = 30000;
70 }
71
72 AudioOutConfig::~AudioOutConfig()
73 {
74 }
75
76
77
78 int AudioOutConfig::operator!=(AudioOutConfig &that)
79 {
80         return !(*this == that);
81 }
82
83 int AudioOutConfig::operator==(AudioOutConfig &that)
84 {
85         return
86                 fragment_size == that.fragment_size &&
87                 driver == that.driver &&
88                 EQUIV(audio_offset, that.audio_offset) &&
89                 play_gain == that.play_gain &&
90
91                 !strcmp(oss_out_device[0], that.oss_out_device[0]) &&
92                 (oss_out_bits == that.oss_out_bits) &&
93
94                 !strcmp(esound_out_server, that.esound_out_server) &&
95                 (esound_out_port == that.esound_out_port) &&
96
97                 !strcmp(pulse_out_server, that.pulse_out_server) &&
98
99                 !strcmp(alsa_out_device, that.alsa_out_device) &&
100                 (alsa_out_bits == that.alsa_out_bits) &&
101                 (interrupt_workaround == that.interrupt_workaround) &&
102
103                 firewire_channel == that.firewire_channel &&
104                 firewire_port == that.firewire_port &&
105                 firewire_syt == that.firewire_syt &&
106                 !strcmp(firewire_path, that.firewire_path) &&
107
108                 dv1394_channel == that.dv1394_channel &&
109                 dv1394_port == that.dv1394_port &&
110                 dv1394_syt == that.dv1394_syt &&
111                 !strcmp(dv1394_path, that.dv1394_path);
112 }
113
114
115
116 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
117 {
118         copy_from(&that);
119         return *this;
120 }
121
122 void AudioOutConfig::copy_from(AudioOutConfig *src)
123 {
124         if( this == src ) return;
125         fragment_size = src->fragment_size;
126         driver = src->driver;
127         audio_offset = src->audio_offset;
128         map51_2 = src->map51_2;
129         play_gain = src->play_gain;
130
131         strcpy(esound_out_server, src->esound_out_server);
132         esound_out_port = src->esound_out_port;
133
134         strcpy(pulse_out_server, src->pulse_out_server);
135
136         for(int i = 0; i < MAXDEVICES; i++)
137         {
138                 oss_enable[i] = src->oss_enable[i];
139                 strcpy(oss_out_device[i], src->oss_out_device[i]);
140         }
141         oss_out_bits = src->oss_out_bits;
142
143         strcpy(alsa_out_device, src->alsa_out_device);
144         alsa_out_bits = src->alsa_out_bits;
145         interrupt_workaround = src->interrupt_workaround;
146
147         firewire_channel = src->firewire_channel;
148         firewire_port = src->firewire_port;
149         firewire_syt = src->firewire_syt;
150         strcpy(firewire_path, src->firewire_path);
151
152         dv1394_channel = src->dv1394_channel;
153         dv1394_port = src->dv1394_port;
154         dv1394_syt = src->dv1394_syt;
155         strcpy(dv1394_path, src->dv1394_path);
156 }
157
158 int AudioOutConfig::load_defaults(BC_Hash *defaults, int active_config)
159 {
160         char prefix[BCTEXTLEN];
161         sprintf(prefix, "%c_", 'A'+active_config);
162
163         fragment_size = defaults->getf(fragment_size, "%sFRAGMENT_SIZE", prefix);
164         audio_offset = defaults->getf(audio_offset, "%sAUDIO_OFFSET", prefix);
165         map51_2 = defaults->getf(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
166         play_gain = defaults->getf(play_gain, "%sAUDIO_OUT_GAIN", prefix);
167         driver = defaults->getf(driver, "%sAUDIO_OUT_DRIVER", prefix);
168
169         for(int i = 0; i < MAXDEVICES; i++)
170         {
171                 oss_enable[i] = defaults->getf(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
172                 defaults->getf(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
173         }
174         oss_out_bits = defaults->getf(oss_out_bits, "%sOSS_OUT_BITS", prefix);
175
176         defaults->getf(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
177         alsa_out_bits = defaults->getf(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
178         interrupt_workaround = defaults->getf(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
179
180         defaults->getf(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
181         defaults->getf(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
182         esound_out_port = defaults->getf(esound_out_port, "%sESOUND_OUT_PORT", prefix);
183
184         defaults->getf(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
185
186         firewire_channel = defaults->getf(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
187         firewire_port = defaults->getf(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
188         defaults->getf(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
189         firewire_syt = defaults->getf(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
190
191         dv1394_channel = defaults->getf(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
192         dv1394_port = defaults->getf(dv1394_port, "%sADV1394_OUT_PORT", prefix);
193         defaults->getf(dv1394_path, "%sADV1394_OUT_PATH", prefix);
194         dv1394_syt = defaults->getf(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
195
196         return 0;
197 }
198
199 int AudioOutConfig::save_defaults(BC_Hash *defaults, int active_config)
200 {
201         char prefix[BCTEXTLEN];
202         sprintf(prefix, "%c_", 'A'+active_config);
203
204         defaults->updatef(fragment_size, "%sFRAGMENT_SIZE", prefix);
205         defaults->updatef(audio_offset, "%sAUDIO_OFFSET", prefix);
206         defaults->updatef(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
207         defaults->updatef(play_gain, "%sAUDIO_OUT_GAIN", prefix);
208
209         defaults->updatef(driver, "%sAUDIO_OUT_DRIVER", prefix);
210
211         for(int i = 0; i < MAXDEVICES; i++)
212         {
213                 defaults->updatef(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
214                 defaults->updatef(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
215         }
216         defaults->updatef(oss_out_bits, "%sOSS_OUT_BITS", prefix);
217
218
219         defaults->updatef(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
220         defaults->updatef(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
221         defaults->updatef(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
222
223         defaults->updatef(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
224         defaults->updatef(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
225         defaults->updatef(esound_out_port, "%sESOUND_OUT_PORT", prefix);
226
227         defaults->updatef(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
228
229         defaults->updatef(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
230         defaults->updatef(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
231         defaults->updatef(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
232         defaults->updatef(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
233
234
235         defaults->updatef(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
236         defaults->updatef(dv1394_port, "%sADV1394_OUT_PORT", prefix);
237         defaults->updatef(dv1394_path, "%sADV1394_OUT_PATH", prefix);
238         defaults->updatef(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
239
240         return 0;
241 }
242
243
244
245
246
247
248
249
250
251 const char *VideoOutConfig::default_video_device = "/dev/video0";
252
253 VideoOutConfig::VideoOutConfig()
254 {
255         driver = PLAYBACK_X11;
256         x11_host[0] = 0;
257         x11_use_fields = USE_NO_FIELDS;
258
259         firewire_channel = 63;
260         firewire_port = 0;
261         strcpy(firewire_path, "/dev/video1394");
262         firewire_syt = 30000;
263
264         dv1394_channel = 63;
265         dv1394_port = 0;
266         strcpy(dv1394_path, "/dev/dv1394");
267         dv1394_syt = 30000;
268
269         brightness = 32768;
270         hue = 32768;
271         color = 32768;
272         contrast = 32768;
273         whiteness = 32768;
274         out_channel = -1;
275         use_direct_x11 = 1;
276 }
277
278 VideoOutConfig::~VideoOutConfig()
279 {
280 }
281
282
283 int VideoOutConfig::operator!=(VideoOutConfig &that)
284 {
285         return !(*this == that);
286 }
287
288 int VideoOutConfig::operator==(VideoOutConfig &that)
289 {
290         return (driver == that.driver) &&
291                 !strcmp(x11_host, that.x11_host) &&
292                 (x11_use_fields == that.x11_use_fields) &&
293                 (use_direct_x11 == that.use_direct_x11) &&
294                 (brightness == that.brightness) &&
295                 (hue == that.hue) &&
296                 (color == that.color) &&
297                 (contrast == that.contrast) &&
298                 (whiteness == that.whiteness) &&
299
300                 (firewire_channel == that.firewire_channel) &&
301                 (firewire_port == that.firewire_port) &&
302                 !strcmp(firewire_path, that.firewire_path) &&
303                 (firewire_syt == that.firewire_syt) &&
304
305                 (dv1394_channel == that.dv1394_channel) &&
306                 (dv1394_port == that.dv1394_port) &&
307                 !strcmp(dv1394_path, that.dv1394_path) &&
308                 (dv1394_syt == that.dv1394_syt);
309 }
310
311
312
313
314
315
316 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
317 {
318         copy_from(&that);
319         return *this;
320 }
321
322 void VideoOutConfig::copy_from(VideoOutConfig *src)
323 {
324         this->driver = src->driver;
325         strcpy(this->x11_host, src->x11_host);
326         this->x11_use_fields = src->x11_use_fields;
327         this->use_direct_x11 = src->use_direct_x11;
328
329         firewire_channel = src->firewire_channel;
330         firewire_port = src->firewire_port;
331         strcpy(firewire_path, src->firewire_path);
332         firewire_syt = src->firewire_syt;
333
334         dv1394_channel = src->dv1394_channel;
335         dv1394_port = src->dv1394_port;
336         strcpy(dv1394_path, src->dv1394_path);
337         dv1394_syt = src->dv1394_syt;
338 }
339
340 const char *VideoOutConfig::get_path()
341 {
342         switch(driver)
343         {
344                 case PLAYBACK_X11:
345                 case PLAYBACK_X11_XV:
346                         return x11_host;
347                         break;
348                 case PLAYBACK_DV1394:
349                         return dv1394_path;
350                         break;
351                 case PLAYBACK_FIREWIRE:
352                         return firewire_path;
353                         break;
354         };
355         return default_video_device;
356 }
357
358 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
359 {
360         char prefix[BCTEXTLEN];
361         sprintf(prefix, "%c_", 'A'+active_config);
362
363         driver = defaults->getf(driver, "%sVIDEO_OUT_DRIVER", prefix);
364         defaults->getf(x11_host, "%sX11_OUT_DEVICE", prefix);
365         x11_use_fields = defaults->getf(x11_use_fields, "%sX11_USE_FIELDS", prefix);
366
367
368
369         firewire_channel = defaults->getf(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
370         firewire_port = defaults->getf(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
371         defaults->getf(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
372         firewire_syt = defaults->getf(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
373
374         dv1394_channel = defaults->getf(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
375         dv1394_port = defaults->getf(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
376         defaults->getf(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
377         dv1394_syt = defaults->getf(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
378         return 0;
379 }
380
381 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
382 {
383         char prefix[BCTEXTLEN];
384         sprintf(prefix, "%c_", 'A'+active_config);
385
386         defaults->updatef(driver, "%sVIDEO_OUT_DRIVER", prefix);
387         defaults->updatef(x11_host, "%sX11_OUT_DEVICE", prefix);
388         defaults->updatef(x11_use_fields, "%sX11_USE_FIELDS", prefix);
389
390         defaults->updatef(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
391         defaults->updatef(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
392         defaults->updatef(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
393         defaults->updatef(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
394
395         defaults->updatef(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
396         defaults->updatef(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
397         defaults->updatef(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
398         defaults->updatef(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
399         return 0;
400 }
401
402
403
404
405
406
407
408
409
410 PlaybackConfig::PlaybackConfig()
411 {
412         aconfig = new AudioOutConfig;
413         vconfig = new VideoOutConfig;
414         sprintf(hostname, "localhost");
415         active_config = 0;
416         port = 23456;
417 }
418
419 PlaybackConfig::~PlaybackConfig()
420 {
421         delete aconfig;
422         delete vconfig;
423 }
424
425 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
426 {
427         copy_from(&that);
428         return *this;
429 }
430
431 void PlaybackConfig::copy_from(PlaybackConfig *src)
432 {
433         active_config = src->active_config;
434         aconfig->copy_from(src->aconfig);
435         vconfig->copy_from(src->vconfig);
436         strncpy(hostname, src->hostname, sizeof(hostname));
437         port = src->port;
438 }
439
440 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
441 {
442         active_config = load_config >= 0 ? load_config :
443                 defaults->get("PLAYBACK_ACTIVE_CONFIG", active_config);
444         aconfig->load_defaults(defaults, active_config);
445         vconfig->load_defaults(defaults, active_config);
446         defaults->get("PLAYBACK_HOSTNAME", hostname);
447         port = defaults->get("PLAYBACK_PORT", port);
448         return 0;
449 }
450
451 int PlaybackConfig::save_defaults(BC_Hash *defaults)
452 {
453         defaults->update("PLAYBACK_ACTIVE_CONFIG", active_config);
454         aconfig->save_defaults(defaults, active_config);
455         vconfig->save_defaults(defaults, active_config);
456         defaults->update("PLAYBACK_HOSTNAME", hostname);
457         defaults->update("PLAYBACK_PORT", port);
458         return 0;
459 }
460
461