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