r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / playbackconfig.C
blobbe65b57b262b79f30cc309994ecd4f67410f574e
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;
33         firewire_use_dv1394 = 0;
35         bzero(do_channel, sizeof(int) * MAX_CHANNELS);
38 AudioOutConfig::~AudioOutConfig()
44 int AudioOutConfig::operator!=(AudioOutConfig &that)
46         return !(*this == that);
49 int AudioOutConfig::operator==(AudioOutConfig &that)
51         return 
52                 (driver == that.driver) &&
53                 !strcmp(oss_out_device[0], that.oss_out_device[0]) && 
54                 (oss_out_channels[0] == that.oss_out_channels[0]) && 
55                 (oss_out_bits == that.oss_out_bits) && 
56                 !strcmp(esound_out_server, that.esound_out_server) && 
57                 (esound_out_port == that.esound_out_port) && 
58                 !strcmp(alsa_out_device, that.alsa_out_device) &&
59                 (alsa_out_channels == that.alsa_out_channels) &&
60                 (alsa_out_bits == that.alsa_out_bits) &&
61                 firewire_channels == that.firewire_channels &&
62                 firewire_channel == that.firewire_channel &&
63                 firewire_port == that.firewire_port &&
64                 firewire_syt == that.firewire_syt &&
65                 !strcmp(firewire_path, that.firewire_path) &&
66                 firewire_use_dv1394 == that.firewire_use_dv1394;
71 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
73         driver = that.driver;
74         strcpy(esound_out_server, that.esound_out_server);
75         esound_out_port = that.esound_out_port;
76         for(int i = 0; i < MAXDEVICES; i++)
77         {
78                 oss_enable[i] = that.oss_enable[i];
79                 strcpy(oss_out_device[i], that.oss_out_device[i]);
80                 oss_out_channels[i] = that.oss_out_channels[i];
81         }
82         oss_out_bits = that.oss_out_bits;
84         strcpy(alsa_out_device, that.alsa_out_device);
85         alsa_out_channels = that.alsa_out_channels;
86         alsa_out_bits = that.alsa_out_bits;
88         firewire_channels = that.firewire_channels;
89         firewire_channel = that.firewire_channel;
90         firewire_port = that.firewire_port;
91         firewire_syt = that.firewire_syt;
92         strcpy(firewire_path, that.firewire_path);
93         firewire_use_dv1394 = that.firewire_use_dv1394;
95         for(int i = 0; i < MAXCHANNELS; i++)
96                 do_channel[i] = that.do_channel[i];
97 // printf("AudioOutConfig::operator= ");
98 // for(int i = 0; i < MAXCHANNELS; i++)
99 // printf("%d", do_channel[i]);
100 // printf("\n");
101         return *this;
104 int AudioOutConfig::load_defaults(Defaults *defaults)
106         char string[BCTEXTLEN];
108         sprintf(string, "AUDIO_OUT_DRIVER_%d_%d_%d", playback_strategy, engine_number, duplex);
109         driver =                              defaults->get(string, driver);
110 //      sprintf(string, "OSS_OUT_DEVICE_%d_%d_%d", playback_strategy, engine_number, duplex);
111 //      defaults->get(string, oss_out_device);
112 //      sprintf(string, "OSS_OUT_CHANNELS_%d_%d_%d", playback_strategy, engine_number, duplex);
113 //      oss_out_channels =                defaults->get(string, oss_out_channels);
114 //      sprintf(string, "OSS_OUT_BITS_%d_%d_%d", playback_strategy, engine_number, duplex);
115 //      oss_out_bits =                defaults->get(string, oss_out_bits);
117         for(int i = 0; i < MAXDEVICES; i++)
118         {
119                 sprintf(string, "OSS_ENABLE_%d_%d", i, duplex);
120                 oss_enable[i] = defaults->get(string, oss_enable[i]);
121                 sprintf(string, "OSS_OUT_DEVICE_%d_%d", i, duplex);
122                 defaults->get(string, oss_out_device[i]);
123                 sprintf(string, "OSS_OUT_CHANNELS_%d_%d", i, duplex);
124                 oss_out_channels[i] = defaults->get(string, oss_out_channels[i]);
125         }
126         sprintf(string, "OSS_OUT_BITS_%d", duplex);
127         oss_out_bits = defaults->get(string, oss_out_bits);
129         defaults->get("ALSA_OUT_DEVICE", alsa_out_device);
130         alsa_out_channels = defaults->get("ALSA_OUT_CHANNELS", alsa_out_channels);
131         alsa_out_bits = defaults->get("ALSA_OUT_BITS", alsa_out_bits);
133         sprintf(string, "ESOUND_OUT_SERVER_%d_%d_%d", playback_strategy, engine_number, duplex);
134         defaults->get(string, esound_out_server);
135         sprintf(string, "ESOUND_OUT_PORT_%d_%d_%d", playback_strategy, engine_number, duplex);
136         esound_out_port =             defaults->get(string, esound_out_port);
138         sprintf(string, "AFIREWIRE_OUT_CHANNELS_%d_%d", playback_strategy, engine_number);
139         firewire_channels = defaults->get(string, firewire_channels);
140         sprintf(string, "AFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
141         firewire_channel = defaults->get(string, firewire_channel);
142         sprintf(string, "AFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
143         firewire_port = defaults->get(string, firewire_port);
144         sprintf(string, "AFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
145         defaults->get(string, firewire_path);
146         sprintf(string, "AFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
147         firewire_syt = defaults->get(string, firewire_syt);
148         sprintf(string, "AFIREWIRE_OUT_USE_DV1394_%d_%d", playback_strategy, engine_number);
149         firewire_use_dv1394 = defaults->get(string, firewire_use_dv1394);
151         return 0;
154 int AudioOutConfig::save_defaults(Defaults *defaults)
156         char string[BCTEXTLEN];
158         sprintf(string, "AUDIO_OUT_DRIVER_%d_%d_%d", playback_strategy, engine_number, duplex);
159         defaults->update(string, driver);
160 //      sprintf(string, "OSS_OUT_DEVICE_%d_%d_%d", playback_strategy, engine_number, duplex);
161 //      defaults->update(string, oss_out_device);
162 //      sprintf(string, "OSS_OUT_CHANNELS_%d_%d_%d", playback_strategy, engine_number, duplex);
163 //      defaults->update(string, oss_out_channels);
164 //      sprintf(string, "OSS_OUT_BITS_%d_%d_%d", playback_strategy, engine_number, duplex);
165 //      defaults->update(string, oss_out_bits);
167         for(int i = 0; i < MAXDEVICES; i++)
168         {
169                 sprintf(string, "OSS_ENABLE_%d_%d", i, duplex);
170                 defaults->update(string, oss_enable[i]);
171                 sprintf(string, "OSS_OUT_DEVICE_%d_%d", i, duplex);
172                 defaults->update(string, oss_out_device[i]);
173                 sprintf(string, "OSS_OUT_CHANNELS_%d_%d", i, duplex);
174                 defaults->update(string, oss_out_channels[i]);
175         }
176         sprintf(string, "OSS_OUT_BITS_%d", duplex);
177         defaults->update(string, oss_out_bits);
180         defaults->update("ALSA_OUT_DEVICE", alsa_out_device);
181         defaults->update("ALSA_OUT_CHANNELS", alsa_out_channels);
182         defaults->update("ALSA_OUT_BITS", alsa_out_bits);
184         sprintf(string, "ESOUND_OUT_SERVER_%d_%d_%d", playback_strategy, engine_number, duplex);
185         defaults->update(string, esound_out_server);
186         sprintf(string, "ESOUND_OUT_PORT_%d_%d_%d", playback_strategy, engine_number, duplex);
187         defaults->update(string, esound_out_port);
189         sprintf(string, "AFIREWIRE_OUT_CHANNELS_%d_%d", playback_strategy, engine_number);
190         defaults->update(string, firewire_channels);
191         sprintf(string, "AFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
192         defaults->update(string, firewire_channel);
193         sprintf(string, "AFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
194         defaults->update(string, firewire_port);
195         sprintf(string, "AFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
196         defaults->update(string, firewire_path);
197         sprintf(string, "AFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
198         defaults->update(string, firewire_syt);
199         sprintf(string, "AFIREWIRE_OUT_USE_DV1394_%d_%d", playback_strategy, engine_number);
200         defaults->update(string, firewire_use_dv1394);
201         return 0;
204 int AudioOutConfig::total_output_channels()
206         switch(driver)
207         {
208                 case AUDIO_OSS:
209                 case AUDIO_OSS_ENVY24:
210                 {
211                         int total = 0;
212                         for(int i = 0; i < MAXDEVICES; i++)
213                         {
214                                 if(oss_enable[i]) total += oss_out_channels[i];
215                         }
216                         return total;
217                         break;
218                 }
220                 case AUDIO_ALSA:
221                         return alsa_out_channels;
222                         break;
225                 case AUDIO_1394:
226                         return firewire_channels;
227                         break;
229                 default:
230                         return 0;
231                         break;
232         }
233         return 0;
236 int AudioOutConfig::total_playable_channels()
238         int result = 0;
239         for(int i = 0; i < MAXCHANNELS; i++)
240                 if(do_channel[i]) result++;
241         return result;
244 int AudioOutConfig::playable_channel_number(int number)
246         for(int i = 0; i < MAXCHANNELS; i++)
247         {
248                 if(do_channel[i])
249                 {
250                         number--;
251                         if(number < 0) return i;
252                 }
253         }
254         return 0;
265 VideoOutConfig::VideoOutConfig(int playback_strategy, int engine_number)
267         sprintf(lml_out_device, "/dev/mvideo/stream");
268         sprintf(buz_out_device, "/dev/video0");
269         this->playback_strategy = playback_strategy;
270         this->engine_number = engine_number;
271         driver = PLAYBACK_X11_XV;
272         for(int i = 0; i < MAX_CHANNELS; i++) do_channel[i] = 0;
273         buz_out_channel = 0;
274         buz_swap_fields = 0;
275         sprintf(x11_host, "");
276         x11_use_fields = USE_NO_FIELDS;
277         firewire_channel = 63;
278         firewire_port = 0;
279         strcpy(firewire_path, "/dev/video1394");
280         firewire_syt = 30000;
281         firewire_use_dv1394 = 0;
284 VideoOutConfig::~VideoOutConfig()
289 int VideoOutConfig::operator!=(VideoOutConfig &that)
291         return !(*this == that);
294 int VideoOutConfig::operator==(VideoOutConfig &that)
296         return (driver == that.driver) &&
297                 !strcmp(lml_out_device, that.lml_out_device) && 
298                 !strcmp(buz_out_device, that.buz_out_device) && 
299                 (buz_out_channel == that.buz_out_channel) && 
300                 (buz_swap_fields == that.buz_swap_fields) &&
301                 !strcmp(x11_host, that.x11_host) && 
302                 (x11_use_fields == that.x11_use_fields) &&
303                 (brightness == that.brightness) && 
304                 (hue == that.hue) && 
305                 (color == that.color) && 
306                 (contrast == that.contrast) && 
307                 (whiteness == that.whiteness) &&
308                 (firewire_channel == that.firewire_channel) &&
309                 (firewire_port == that.firewire_port) &&
310                 !strcmp(firewire_path, that.firewire_path) &&
311                 (firewire_syt == that.firewire_syt) &&
312                 (firewire_use_dv1394 == that.firewire_use_dv1394);
320 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
322         this->driver = that.driver;
323         strcpy(this->lml_out_device, that.lml_out_device);
324         strcpy(this->buz_out_device, that.buz_out_device);
325         this->buz_out_channel = that.buz_out_channel;
326         this->buz_swap_fields = that.buz_swap_fields;
327         strcpy(this->x11_host, that.x11_host);
328         this->x11_use_fields = that.x11_use_fields;
329         for(int i = 0; i < MAX_CHANNELS; i++) 
330                 this->do_channel[i] = that.do_channel[i];
331         firewire_channel = that.firewire_channel;
332         firewire_port = that.firewire_port;
333         strcpy(firewire_path, that.firewire_path);
334         firewire_syt = that.firewire_syt;
335         firewire_use_dv1394 = that.firewire_use_dv1394;
336         return *this;
339 char* VideoOutConfig::get_path()
341         switch(driver)
342         {
343                 case PLAYBACK_BUZ:
344                         return buz_out_device;
345                         break;
346                 case PLAYBACK_X11:
347                 case PLAYBACK_X11_XV:
348                         return x11_host;
349                         break;
350                 case PLAYBACK_FIREWIRE:
351                         return firewire_path;
352                         break;
353         };
354         return buz_out_device;
357 int VideoOutConfig::load_defaults(Defaults *defaults)
359         char string[BCTEXTLEN];
360         sprintf(string, "VIDEO_OUT_DRIVER_%d_%d", playback_strategy, engine_number);
361         driver = defaults->get(string, driver);
362         sprintf(string, "LML_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
363         defaults->get(string, lml_out_device);
364         sprintf(string, "BUZ_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
365         defaults->get(string, buz_out_device);
366         sprintf(string, "BUZ_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
367         buz_out_channel = defaults->get(string, buz_out_channel);
368         sprintf(string, "BUZ_SWAP_FIELDS_%d_%d", playback_strategy, engine_number);
369         buz_swap_fields = defaults->get(string, buz_swap_fields);
370         sprintf(string, "X11_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
371         defaults->get(string, x11_host);
372         x11_use_fields = defaults->get("X11_USE_FIELDS", x11_use_fields);
373         sprintf(string, "VFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
374         firewire_channel = defaults->get(string, firewire_channel);
375         sprintf(string, "VFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
376         firewire_port = defaults->get(string, firewire_port);
377         sprintf(string, "VFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
378         defaults->get(string, firewire_path);
379         sprintf(string, "VFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
380         firewire_syt = defaults->get(string, firewire_syt);
381         sprintf(string, "VFIREWIRE_OUT_USE_DV1394_%d_%d", playback_strategy, engine_number);
382         firewire_use_dv1394 = defaults->get(string, firewire_use_dv1394);
383         return 0;
386 int VideoOutConfig::save_defaults(Defaults *defaults)
388         char string[BCTEXTLEN];
389         sprintf(string, "VIDEO_OUT_DRIVER_%d_%d", playback_strategy, engine_number);
390         defaults->update(string, driver);
391         sprintf(string, "LML_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
392         defaults->update(string, lml_out_device);
393         sprintf(string, "BUZ_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
394         defaults->update(string, buz_out_device);
395         sprintf(string, "BUZ_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
396         defaults->update(string, buz_out_channel);
397         sprintf(string, "BUZ_SWAP_FIELDS_%d_%d", playback_strategy, engine_number);
398         defaults->update(string, buz_swap_fields);
399         sprintf(string, "X11_OUT_DEVICE_%d_%d", playback_strategy, engine_number);
400         defaults->update(string, x11_host);
401         defaults->update("X11_USE_FIELDS", x11_use_fields);
402         sprintf(string, "VFIREWIRE_OUT_CHANNEL_%d_%d", playback_strategy, engine_number);
403         defaults->update(string, firewire_channel);
404         sprintf(string, "VFIREWIRE_OUT_PORT_%d_%d", playback_strategy, engine_number);
405         defaults->update(string, firewire_port);
406         sprintf(string, "VFIREWIRE_OUT_PATH_%d_%d", playback_strategy, engine_number);
407         defaults->update(string, firewire_path);
408         sprintf(string, "VFIREWIRE_OUT_SYT_%d_%d", playback_strategy, engine_number);
409         defaults->update(string, firewire_syt);
410    sprintf(string, "VFIREWIRE_OUT_USE_DV1394_%d_%d", playback_strategy, engine_number);
411    defaults->update(string, firewire_use_dv1394);
412         return 0;
415 int VideoOutConfig::total_playable_channels()
417         int result = 0;
418         for(int i = 0; i < MAXCHANNELS; i++)
419                 if(do_channel[i]) result++;
420         return result;
431 PlaybackConfig::PlaybackConfig(int playback_strategy, int engine_number)
433         aconfig = new AudioOutConfig(playback_strategy, engine_number, 0);
434         vconfig = new VideoOutConfig(playback_strategy, engine_number);
435         this->playback_strategy = playback_strategy;
436         this->engine_number = engine_number;
437         sprintf(hostname, "localhost");
438         port = 23456;
441 PlaybackConfig::~PlaybackConfig()
443         delete aconfig;
444         delete vconfig;
447 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
449         *aconfig = *that.aconfig;
450         *vconfig = *that.vconfig;
451         strcpy(hostname, that.hostname);
452         port = that.port;
453         return *this;
456 int PlaybackConfig::load_defaults(Defaults *defaults)
458         char string[1024];
459         sprintf(string, "PLAYBACK_HOSTNAME_%d_%d", playback_strategy, engine_number);
460         defaults->get(string, hostname);
461         sprintf(string, "PLAYBACK_PORT_%d_%d", playback_strategy, engine_number);
462         port = defaults->get(string, port);
463         aconfig->load_defaults(defaults);
464         vconfig->load_defaults(defaults);
465         return 0;
468 int PlaybackConfig::save_defaults(Defaults *defaults)
470         char string[1024];
471         sprintf(string, "PLAYBACK_HOSTNAME_%d_%d", playback_strategy, engine_number);
472         defaults->update(string, hostname);
473         sprintf(string, "PLAYBACK_PORT_%d_%d", playback_strategy, engine_number);
474         defaults->update(string, port);
475         aconfig->save_defaults(defaults);
476         vconfig->save_defaults(defaults);
477         return 0;