r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / playbackconfig.C
blob3360dd0a83b33c3ce3e95335acfe2cffaa92f313
1 #include "defaults.h"
2 #include "playbackconfig.h"
3 #include "videodevice.inc"
4 #include <string.h>
6 AudioOutConfig::AudioOutConfig(int playback_strategy, int engine_number, int duplex)
8         this->duplex = duplex;
9         this->playback_strategy = playback_strategy;
10         this->engine_number = engine_number;
11         driver = AUDIO_OSS;
13         oss_out_bits = 16;
14         for(int i = 0; i < MAXDEVICES; i++)
15         {
16                 oss_enable[i] = (i == 0);
17                 sprintf(oss_out_device[i], "/dev/dsp");
18                 oss_out_channels[i] = 2;
19         }
21         sprintf(esound_out_server, "");
22         esound_out_port = 0;
24         sprintf(alsa_out_device, "");
25         alsa_out_channels = 2;
26         alsa_out_bits = 16;
28         firewire_channels = 2;
29         firewire_channel = 63;
30         firewire_port = 0;
31         strcpy(firewire_path, "/dev/video1394");
32         firewire_syt = 30000;
34         dv1394_channels = 2;
35         dv1394_channel = 63;
36         dv1394_port = 0;
37         strcpy(dv1394_path, "/dev/dv1394");
38         dv1394_syt = 30000;
40         bzero(do_channel, sizeof(int) * MAX_CHANNELS);
43 AudioOutConfig::~AudioOutConfig()
49 int AudioOutConfig::operator!=(AudioOutConfig &that)
51         return !(*this == that);
54 int AudioOutConfig::operator==(AudioOutConfig &that)
56         return 
57                 (driver == that.driver) &&
58                 !strcmp(oss_out_device[0], that.oss_out_device[0]) && 
59                 (oss_out_channels[0] == that.oss_out_channels[0]) && 
60                 (oss_out_bits == that.oss_out_bits) && 
61                 !strcmp(esound_out_server, that.esound_out_server) && 
62                 (esound_out_port == that.esound_out_port) && 
63                 !strcmp(alsa_out_device, that.alsa_out_device) &&
64                 (alsa_out_channels == that.alsa_out_channels) &&
65                 (alsa_out_bits == that.alsa_out_bits) &&
67                 firewire_channels == that.firewire_channels &&
68                 firewire_channel == that.firewire_channel &&
69                 firewire_port == that.firewire_port &&
70                 firewire_syt == that.firewire_syt &&
71                 !strcmp(firewire_path, that.firewire_path) &&
73                 dv1394_channels == that.dv1394_channels &&
74                 dv1394_channel == that.dv1394_channel &&
75                 dv1394_port == that.dv1394_port &&
76                 dv1394_syt == that.dv1394_syt &&
77                 !strcmp(dv1394_path, that.dv1394_path);
82 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
84         driver = that.driver;
85         strcpy(esound_out_server, that.esound_out_server);
86         esound_out_port = that.esound_out_port;
87         for(int i = 0; i < MAXDEVICES; i++)
88         {
89                 oss_enable[i] = that.oss_enable[i];
90                 strcpy(oss_out_device[i], that.oss_out_device[i]);
91                 oss_out_channels[i] = that.oss_out_channels[i];
92         }
93         oss_out_bits = that.oss_out_bits;
95         strcpy(alsa_out_device, that.alsa_out_device);
96         alsa_out_channels = that.alsa_out_channels;
97         alsa_out_bits = that.alsa_out_bits;
99         firewire_channels = that.firewire_channels;
100         firewire_channel = that.firewire_channel;
101         firewire_port = that.firewire_port;
102         firewire_syt = that.firewire_syt;
103         strcpy(firewire_path, that.firewire_path);
105         dv1394_channels = that.dv1394_channels;
106         dv1394_channel = that.dv1394_channel;
107         dv1394_port = that.dv1394_port;
108         dv1394_syt = that.dv1394_syt;
109         strcpy(dv1394_path, that.dv1394_path);
111         for(int i = 0; i < MAXCHANNELS; i++)
112                 do_channel[i] = that.do_channel[i];
113 // printf("AudioOutConfig::operator= ");
114 // for(int i = 0; i < MAXCHANNELS; i++)
115 // printf("%d", do_channel[i]);
116 // printf("\n");
117         return *this;
120 int AudioOutConfig::load_defaults(Defaults *defaults)
122         char string[BCTEXTLEN];
124         sprintf(string, "AUDIO_OUT_DRIVER_%d_%d_%d", playback_strategy, engine_number, duplex);
125         driver =                              defaults->get(string, driver);
126 //      sprintf(string, "OSS_OUT_DEVICE_%d_%d_%d", playback_strategy, engine_number, duplex);
127 //      defaults->get(string, oss_out_device);
128 //      sprintf(string, "OSS_OUT_CHANNELS_%d_%d_%d", playback_strategy, engine_number, duplex);
129 //      oss_out_channels =                defaults->get(string, oss_out_channels);
130 //      sprintf(string, "OSS_OUT_BITS_%d_%d_%d", playback_strategy, engine_number, duplex);
131 //      oss_out_bits =                defaults->get(string, oss_out_bits);
133         for(int i = 0; i < MAXDEVICES; i++)
134         {
135                 sprintf(string, "OSS_ENABLE_%d_%d", i, duplex);
136                 oss_enable[i] = defaults->get(string, oss_enable[i]);
137                 sprintf(string, "OSS_OUT_DEVICE_%d_%d", i, duplex);
138                 defaults->get(string, oss_out_device[i]);
139                 sprintf(string, "OSS_OUT_CHANNELS_%d_%d", i, duplex);
140                 oss_out_channels[i] = defaults->get(string, oss_out_channels[i]);
141         }
142         sprintf(string, "OSS_OUT_BITS_%d", duplex);
143         oss_out_bits = defaults->get(string, oss_out_bits);
145         defaults->get("ALSA_OUT_DEVICE", alsa_out_device);
146         alsa_out_channels = defaults->get("ALSA_OUT_CHANNELS", alsa_out_channels);
147         alsa_out_bits = defaults->get("ALSA_OUT_BITS", alsa_out_bits);
149         sprintf(string, "ESOUND_OUT_SERVER_%d_%d_%d", playback_strategy, engine_number, duplex);
150         defaults->get(string, esound_out_server);
151         sprintf(string, "ESOUND_OUT_PORT_%d_%d_%d", playback_strategy, engine_number, duplex);
152         esound_out_port =             defaults->get(string, esound_out_port);
154         sprintf(string, "AFIREWIRE_OUT_CHANNELS_%d_%d", playback_strategy, engine_number);
155         firewire_channels = defaults->get(string, firewire_channels);
156         sprintf(string, "AFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
157         firewire_channel = defaults->get(string, firewire_channel);
158         sprintf(string, "AFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
159         firewire_port = defaults->get(string, firewire_port);
160         sprintf(string, "AFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
161         defaults->get(string, firewire_path);
162         sprintf(string, "AFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
163         firewire_syt = defaults->get(string, firewire_syt);
165         sprintf(string, "ADV1394_OUT_CHANNELS_%d_%d", playback_strategy, engine_number);
166         dv1394_channels = defaults->get(string, dv1394_channels);
167         sprintf(string, "ADV1394_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
168         dv1394_channel = defaults->get(string, dv1394_channel);
169         sprintf(string, "ADV1394_OUT_PORT_%d_%d", playback_strategy, engine_number);
170         dv1394_port = defaults->get(string, dv1394_port);
171         sprintf(string, "ADV1394_OUT_PATH_%d_%d", playback_strategy, engine_number);
172         defaults->get(string, dv1394_path);
173         sprintf(string, "ADV1394_OUT_SYT_%d_%d", playback_strategy, engine_number);
174         dv1394_syt = defaults->get(string, dv1394_syt);
176         return 0;
179 int AudioOutConfig::save_defaults(Defaults *defaults)
181         char string[BCTEXTLEN];
183         sprintf(string, "AUDIO_OUT_DRIVER_%d_%d_%d", playback_strategy, engine_number, duplex);
184         defaults->update(string, driver);
185 //      sprintf(string, "OSS_OUT_DEVICE_%d_%d_%d", playback_strategy, engine_number, duplex);
186 //      defaults->update(string, oss_out_device);
187 //      sprintf(string, "OSS_OUT_CHANNELS_%d_%d_%d", playback_strategy, engine_number, duplex);
188 //      defaults->update(string, oss_out_channels);
189 //      sprintf(string, "OSS_OUT_BITS_%d_%d_%d", playback_strategy, engine_number, duplex);
190 //      defaults->update(string, oss_out_bits);
192         for(int i = 0; i < MAXDEVICES; i++)
193         {
194                 sprintf(string, "OSS_ENABLE_%d_%d", i, duplex);
195                 defaults->update(string, oss_enable[i]);
196                 sprintf(string, "OSS_OUT_DEVICE_%d_%d", i, duplex);
197                 defaults->update(string, oss_out_device[i]);
198                 sprintf(string, "OSS_OUT_CHANNELS_%d_%d", i, duplex);
199                 defaults->update(string, oss_out_channels[i]);
200         }
201         sprintf(string, "OSS_OUT_BITS_%d", duplex);
202         defaults->update(string, oss_out_bits);
205         defaults->update("ALSA_OUT_DEVICE", alsa_out_device);
206         defaults->update("ALSA_OUT_CHANNELS", alsa_out_channels);
207         defaults->update("ALSA_OUT_BITS", alsa_out_bits);
209         sprintf(string, "ESOUND_OUT_SERVER_%d_%d_%d", playback_strategy, engine_number, duplex);
210         defaults->update(string, esound_out_server);
211         sprintf(string, "ESOUND_OUT_PORT_%d_%d_%d", playback_strategy, engine_number, duplex);
212         defaults->update(string, esound_out_port);
214         sprintf(string, "AFIREWIRE_OUT_CHANNELS_%d_%d", playback_strategy, engine_number);
215         defaults->update(string, firewire_channels);
216         sprintf(string, "AFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
217         defaults->update(string, firewire_channel);
218         sprintf(string, "AFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
219         defaults->update(string, firewire_port);
220         sprintf(string, "AFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
221         defaults->update(string, firewire_path);
222         sprintf(string, "AFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
223         defaults->update(string, firewire_syt);
226         sprintf(string, "ADV1394_OUT_CHANNELS_%d_%d", playback_strategy, engine_number);
227         defaults->update(string, dv1394_channels);
228         sprintf(string, "ADV1394_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
229         defaults->update(string, dv1394_channel);
230         sprintf(string, "ADV1394_OUT_PORT_%d_%d", playback_strategy, engine_number);
231         defaults->update(string, dv1394_port);
232         sprintf(string, "ADV1394_OUT_PATH_%d_%d", playback_strategy, engine_number);
233         defaults->update(string, dv1394_path);
234         sprintf(string, "ADV1394_OUT_SYT_%d_%d", playback_strategy, engine_number);
235         defaults->update(string, dv1394_syt);
237         return 0;
240 int AudioOutConfig::total_output_channels()
242         switch(driver)
243         {
244                 case AUDIO_OSS:
245                 case AUDIO_OSS_ENVY24:
246                 {
247                         int total = 0;
248                         for(int i = 0; i < MAXDEVICES; i++)
249                         {
250                                 if(oss_enable[i]) total += oss_out_channels[i];
251                         }
252                         return total;
253                         break;
254                 }
256                 case AUDIO_ALSA:
257                         return alsa_out_channels;
258                         break;
261                 case AUDIO_1394:
262                         return firewire_channels;
263                         break;
265                 case AUDIO_DV1394:
266                         return dv1394_channels;
267                         break;
269                 case AUDIO_ESOUND:
270                         return 2;
271                         break;
273                 default:
274                         return 0;
275                         break;
276         }
277         return 0;
280 int AudioOutConfig::total_playable_channels()
282         int result = 0;
283         for(int i = 0; i < MAXCHANNELS; i++)
284                 if(do_channel[i]) result++;
285         return result;
288 int AudioOutConfig::playable_channel_number(int number)
290         for(int i = 0; i < MAXCHANNELS; i++)
291         {
292                 if(do_channel[i])
293                 {
294                         number--;
295                         if(number < 0) return i;
296                 }
297         }
298         return 0;
309 VideoOutConfig::VideoOutConfig(int playback_strategy, int engine_number)
311         sprintf(lml_out_device, "/dev/mvideo/stream");
312         sprintf(buz_out_device, "/dev/video0");
313         this->playback_strategy = playback_strategy;
314         this->engine_number = engine_number;
315         driver = PLAYBACK_X11_XV;
316         for(int i = 0; i < MAX_CHANNELS; i++) do_channel[i] = 0;
317         buz_out_channel = 0;
318         buz_swap_fields = 0;
319         sprintf(x11_host, "");
320         x11_use_fields = USE_NO_FIELDS;
322         firewire_channel = 63;
323         firewire_port = 0;
324         strcpy(firewire_path, "/dev/video1394");
325         firewire_syt = 30000;
327         dv1394_channel = 63;
328         dv1394_port = 0;
329         strcpy(dv1394_path, "/dev/dv1394");
330         dv1394_syt = 30000;
333 VideoOutConfig::~VideoOutConfig()
338 int VideoOutConfig::operator!=(VideoOutConfig &that)
340         return !(*this == that);
343 int VideoOutConfig::operator==(VideoOutConfig &that)
345         return (driver == that.driver) &&
346                 !strcmp(lml_out_device, that.lml_out_device) && 
347                 !strcmp(buz_out_device, that.buz_out_device) && 
348                 (buz_out_channel == that.buz_out_channel) && 
349                 (buz_swap_fields == that.buz_swap_fields) &&
350                 !strcmp(x11_host, that.x11_host) && 
351                 (x11_use_fields == that.x11_use_fields) &&
352                 (brightness == that.brightness) && 
353                 (hue == that.hue) && 
354                 (color == that.color) && 
355                 (contrast == that.contrast) && 
356                 (whiteness == that.whiteness) &&
358                 (firewire_channel == that.firewire_channel) &&
359                 (firewire_port == that.firewire_port) &&
360                 !strcmp(firewire_path, that.firewire_path) &&
361                 (firewire_syt == that.firewire_syt) &&
363                 (dv1394_channel == that.dv1394_channel) &&
364                 (dv1394_port == that.dv1394_port) &&
365                 !strcmp(dv1394_path, that.dv1394_path) &&
366                 (dv1394_syt == that.dv1394_syt);
374 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
376         this->driver = that.driver;
377         strcpy(this->lml_out_device, that.lml_out_device);
378         strcpy(this->buz_out_device, that.buz_out_device);
379         this->buz_out_channel = that.buz_out_channel;
380         this->buz_swap_fields = that.buz_swap_fields;
381         strcpy(this->x11_host, that.x11_host);
382         this->x11_use_fields = that.x11_use_fields;
383         for(int i = 0; i < MAX_CHANNELS; i++) 
384                 this->do_channel[i] = that.do_channel[i];
386         firewire_channel = that.firewire_channel;
387         firewire_port = that.firewire_port;
388         strcpy(firewire_path, that.firewire_path);
389         firewire_syt = that.firewire_syt;
391         dv1394_channel = that.dv1394_channel;
392         dv1394_port = that.dv1394_port;
393         strcpy(dv1394_path, that.dv1394_path);
394         dv1394_syt = that.dv1394_syt;
396         return *this;
399 char* VideoOutConfig::get_path()
401         switch(driver)
402         {
403                 case PLAYBACK_BUZ:
404                         return buz_out_device;
405                         break;
406                 case PLAYBACK_X11:
407                 case PLAYBACK_X11_XV:
408                         return x11_host;
409                         break;
410                 case PLAYBACK_DV1394:
411                         return dv1394_path;
412                         break;
413                 case PLAYBACK_FIREWIRE:
414                         return firewire_path;
415                         break;
416         };
417         return buz_out_device;
420 int VideoOutConfig::load_defaults(Defaults *defaults)
422         char string[BCTEXTLEN];
423         sprintf(string, "VIDEO_OUT_DRIVER_%d_%d", playback_strategy, engine_number);
424         driver = defaults->get(string, driver);
425         sprintf(string, "LML_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
426         defaults->get(string, lml_out_device);
427         sprintf(string, "BUZ_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
428         defaults->get(string, buz_out_device);
429         sprintf(string, "BUZ_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
430         buz_out_channel = defaults->get(string, buz_out_channel);
431         sprintf(string, "BUZ_SWAP_FIELDS_%d_%d", playback_strategy, engine_number);
432         buz_swap_fields = defaults->get(string, buz_swap_fields);
433         sprintf(string, "X11_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
434         defaults->get(string, x11_host);
435         x11_use_fields = defaults->get("X11_USE_FIELDS", x11_use_fields);
439         sprintf(string, "VFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
440         firewire_channel = defaults->get(string, firewire_channel);
441         sprintf(string, "VFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
442         firewire_port = defaults->get(string, firewire_port);
443         sprintf(string, "VFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
444         defaults->get(string, firewire_path);
445         sprintf(string, "VFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
446         firewire_syt = defaults->get(string, firewire_syt);
448         sprintf(string, "VDV1394_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
449         dv1394_channel = defaults->get(string, dv1394_channel);
450         sprintf(string, "VDV1394_OUT_PORT_%d_%d", playback_strategy, engine_number);
451         dv1394_port = defaults->get(string, dv1394_port);
452         sprintf(string, "VDV1394_OUT_PATH_%d_%d", playback_strategy, engine_number);
453         defaults->get(string, dv1394_path);
454         sprintf(string, "VDV1394_OUT_SYT_%d_%d", playback_strategy, engine_number);
455         dv1394_syt = defaults->get(string, dv1394_syt);
456         return 0;
459 int VideoOutConfig::save_defaults(Defaults *defaults)
461         char string[BCTEXTLEN];
462         sprintf(string, "VIDEO_OUT_DRIVER_%d_%d", playback_strategy, engine_number);
463         defaults->update(string, driver);
464         sprintf(string, "LML_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
465         defaults->update(string, lml_out_device);
466         sprintf(string, "BUZ_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
467         defaults->update(string, buz_out_device);
468         sprintf(string, "BUZ_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
469         defaults->update(string, buz_out_channel);
470         sprintf(string, "BUZ_SWAP_FIELDS_%d_%d", playback_strategy, engine_number);
471         defaults->update(string, buz_swap_fields);
472         sprintf(string, "X11_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
473         defaults->update(string, x11_host);
474         defaults->update("X11_USE_FIELDS", x11_use_fields);
476         sprintf(string, "VFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
477         defaults->update(string, firewire_channel);
478         sprintf(string, "VFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
479         defaults->update(string, firewire_port);
480         sprintf(string, "VFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
481         defaults->update(string, firewire_path);
482         sprintf(string, "VFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
483         defaults->update(string, firewire_syt);
485         sprintf(string, "VDV1394_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
486         defaults->update(string, dv1394_channel);
487         sprintf(string, "VDV1394_OUT_PORT_%d_%d", playback_strategy, engine_number);
488         defaults->update(string, dv1394_port);
489         sprintf(string, "VDV1394_OUT_PATH_%d_%d", playback_strategy, engine_number);
490         defaults->update(string, dv1394_path);
491         sprintf(string, "VDV1394_OUT_SYT_%d_%d", playback_strategy, engine_number);
492         defaults->update(string, dv1394_syt);
493         return 0;
496 int VideoOutConfig::total_playable_channels()
498         int result = 0;
499         for(int i = 0; i < MAXCHANNELS; i++)
500                 if(do_channel[i]) result++;
501         return result;
512 PlaybackConfig::PlaybackConfig(int playback_strategy, int engine_number)
514         aconfig = new AudioOutConfig(playback_strategy, engine_number, 0);
515         vconfig = new VideoOutConfig(playback_strategy, engine_number);
516         this->playback_strategy = playback_strategy;
517         this->engine_number = engine_number;
518         sprintf(hostname, "localhost");
519         port = 23456;
522 PlaybackConfig::~PlaybackConfig()
524         delete aconfig;
525         delete vconfig;
528 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
530         *aconfig = *that.aconfig;
531         *vconfig = *that.vconfig;
532         strcpy(hostname, that.hostname);
533         port = that.port;
534         return *this;
537 int PlaybackConfig::load_defaults(Defaults *defaults)
539         char string[1024];
540         sprintf(string, "PLAYBACK_HOSTNAME_%d_%d", playback_strategy, engine_number);
541         defaults->get(string, hostname);
542         sprintf(string, "PLAYBACK_PORT_%d_%d", playback_strategy, engine_number);
543         port = defaults->get(string, port);
544         aconfig->load_defaults(defaults);
545         vconfig->load_defaults(defaults);
546         return 0;
549 int PlaybackConfig::save_defaults(Defaults *defaults)
551         char string[1024];
552         sprintf(string, "PLAYBACK_HOSTNAME_%d_%d", playback_strategy, engine_number);
553         defaults->update(string, hostname);
554         sprintf(string, "PLAYBACK_PORT_%d_%d", playback_strategy, engine_number);
555         defaults->update(string, port);
556         aconfig->save_defaults(defaults);
557         vconfig->save_defaults(defaults);
558         return 0;