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