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