Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / cinelerra / playbackconfig.C
blob47dfdbb2811a2aa21198b720e5d2b484b80b90d7
1 #include "clip.h"
2 #include "bchash.h"
3 #include "playbackconfig.h"
4 #include "videodevice.inc"
5 #include <string.h>
7 AudioOutConfig::AudioOutConfig(int duplex)
9         this->duplex = duplex;
11         fragment_size = 16384;
12         driver = AUDIO_OSS;
14         audio_offset = 0.0;
16         oss_out_bits = 16;
17         for(int i = 0; i < MAXDEVICES; i++)
18         {
19                 oss_enable[i] = (i == 0);
20                 sprintf(oss_out_device[i], "/dev/dsp");
21         }
23         sprintf(esound_out_server, "");
24         esound_out_port = 0;
26         sprintf(alsa_out_device, "default");
27         alsa_out_bits = 16;
28         interrupt_workaround = 0;
30         firewire_channel = 63;
31         firewire_port = 0;
32         strcpy(firewire_path, "/dev/video1394");
33         firewire_syt = 30000;
35         dv1394_channel = 63;
36         dv1394_port = 0;
37         strcpy(dv1394_path, "/dev/dv1394");
38         dv1394_syt = 30000;
42 AudioOutConfig::~AudioOutConfig()
48 int AudioOutConfig::operator!=(AudioOutConfig &that)
50         return !(*this == that);
53 int AudioOutConfig::operator==(AudioOutConfig &that)
55         return 
56                 fragment_size == that.fragment_size &&
57                 driver == that.driver &&
58                 EQUIV(audio_offset, that.audio_offset) &&
61                 !strcmp(oss_out_device[0], that.oss_out_device[0]) && 
62                 (oss_out_bits == that.oss_out_bits) && 
66                 !strcmp(esound_out_server, that.esound_out_server) && 
67                 (esound_out_port == that.esound_out_port) && 
71                 !strcmp(alsa_out_device, that.alsa_out_device) &&
72                 (alsa_out_bits == that.alsa_out_bits) &&
73                 (interrupt_workaround == that.interrupt_workaround) &&
75                 firewire_channel == that.firewire_channel &&
76                 firewire_port == that.firewire_port &&
77                 firewire_syt == that.firewire_syt &&
78                 !strcmp(firewire_path, that.firewire_path) &&
80                 dv1394_channel == that.dv1394_channel &&
81                 dv1394_port == that.dv1394_port &&
82                 dv1394_syt == that.dv1394_syt &&
83                 !strcmp(dv1394_path, that.dv1394_path);
88 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
90         copy_from(&that);
91         return *this;
94 void AudioOutConfig::copy_from(AudioOutConfig *src)
96         fragment_size = src->fragment_size;
97         driver = src->driver;
98         audio_offset = src->audio_offset;
100         strcpy(esound_out_server, src->esound_out_server);
101         esound_out_port = src->esound_out_port;
102         for(int i = 0; i < MAXDEVICES; i++)
103         {
104                 oss_enable[i] = src->oss_enable[i];
105                 strcpy(oss_out_device[i], src->oss_out_device[i]);
106         }
107         oss_out_bits = src->oss_out_bits;
109         strcpy(alsa_out_device, src->alsa_out_device);
110         alsa_out_bits = src->alsa_out_bits;
111         interrupt_workaround = src->interrupt_workaround;
113         firewire_channel = src->firewire_channel;
114         firewire_port = src->firewire_port;
115         firewire_syt = src->firewire_syt;
116         strcpy(firewire_path, src->firewire_path);
118         dv1394_channel = src->dv1394_channel;
119         dv1394_port = src->dv1394_port;
120         dv1394_syt = src->dv1394_syt;
121         strcpy(dv1394_path, src->dv1394_path);
125 int AudioOutConfig::load_defaults(BC_Hash *defaults)
127         char string[BCTEXTLEN];
129         fragment_size = defaults->get("FRAGMENT_SIZE", fragment_size);
130         audio_offset = defaults->get("AUDIO_OFFSET", audio_offset);
131         sprintf(string, "AUDIO_OUT_DRIVER_%d", duplex);
132         driver = defaults->get(string, driver);
134         for(int i = 0; i < MAXDEVICES; i++)
135         {
136                 sprintf(string, "OSS_ENABLE_%d_%d", i, duplex);
137                 oss_enable[i] = defaults->get(string, oss_enable[i]);
138                 sprintf(string, "OSS_OUT_DEVICE_%d_%d", i, duplex);
139                 defaults->get(string, oss_out_device[i]);
140         }
141         sprintf(string, "OSS_OUT_BITS_%d", duplex);
142         oss_out_bits = defaults->get(string, oss_out_bits);
144         defaults->get("ALSA_OUT_DEVICE", alsa_out_device);
145         alsa_out_bits = defaults->get("ALSA_OUT_BITS", alsa_out_bits);
146         interrupt_workaround = defaults->get("ALSA_INTERRUPT_WORKAROUND", interrupt_workaround);
148         sprintf(string, "ESOUND_OUT_SERVER_%d", duplex);
149         defaults->get(string, esound_out_server);
150         sprintf(string, "ESOUND_OUT_PORT_%d", duplex);
151         esound_out_port =             defaults->get(string, esound_out_port);
153         sprintf(string, "AFIREWIRE_OUT_CHANNEL");
154         firewire_channel = defaults->get(string, firewire_channel);
155         sprintf(string, "AFIREWIRE_OUT_PORT");
156         firewire_port = defaults->get(string, firewire_port);
157         sprintf(string, "AFIREWIRE_OUT_PATH");
158         defaults->get(string, firewire_path);
159         sprintf(string, "AFIREWIRE_OUT_SYT");
160         firewire_syt = defaults->get(string, firewire_syt);
162         sprintf(string, "ADV1394_OUT_CHANNEL");
163         dv1394_channel = defaults->get(string, dv1394_channel);
164         sprintf(string, "ADV1394_OUT_PORT");
165         dv1394_port = defaults->get(string, dv1394_port);
166         sprintf(string, "ADV1394_OUT_PATH");
167         defaults->get(string, dv1394_path);
168         sprintf(string, "ADV1394_OUT_SYT");
169         dv1394_syt = defaults->get(string, dv1394_syt);
171         return 0;
174 int AudioOutConfig::save_defaults(BC_Hash *defaults)
176         char string[BCTEXTLEN];
178         defaults->update("FRAGMENT_SIZE", fragment_size);
179         defaults->update("AUDIO_OFFSET", audio_offset);
181         sprintf(string, "AUDIO_OUT_DRIVER_%d", duplex);
182         defaults->update(string, driver);
184         for(int i = 0; i < MAXDEVICES; i++)
185         {
186                 sprintf(string, "OSS_ENABLE_%d_%d", i, duplex);
187                 defaults->update(string, oss_enable[i]);
188                 sprintf(string, "OSS_OUT_DEVICE_%d_%d", i, duplex);
189                 defaults->update(string, oss_out_device[i]);
190         }
191         sprintf(string, "OSS_OUT_BITS_%d", duplex);
192         defaults->update(string, oss_out_bits);
195         defaults->update("ALSA_OUT_DEVICE", alsa_out_device);
196         defaults->update("ALSA_OUT_BITS", alsa_out_bits);
197         defaults->update("ALSA_INTERRUPT_WORKAROUND", interrupt_workaround);
199         sprintf(string, "ESOUND_OUT_SERVER_%d", duplex);
200         defaults->update(string, esound_out_server);
201         sprintf(string, "ESOUND_OUT_PORT_%d", duplex);
202         defaults->update(string, esound_out_port);
204         sprintf(string, "AFIREWIRE_OUT_CHANNEL");
205         defaults->update(string, firewire_channel);
206         sprintf(string, "AFIREWIRE_OUT_PORT");
207         defaults->update(string, firewire_port);
208         sprintf(string, "AFIREWIRE_OUT_PATH");
209         defaults->update(string, firewire_path);
210         sprintf(string, "AFIREWIRE_OUT_SYT");
211         defaults->update(string, firewire_syt);
214         sprintf(string, "ADV1394_OUT_CHANNEL");
215         defaults->update(string, dv1394_channel);
216         sprintf(string, "ADV1394_OUT_PORT");
217         defaults->update(string, dv1394_port);
218         sprintf(string, "ADV1394_OUT_PATH");
219         defaults->update(string, dv1394_path);
220         sprintf(string, "ADV1394_OUT_SYT");
221         defaults->update(string, dv1394_syt);
223         return 0;
235 VideoOutConfig::VideoOutConfig()
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         sprintf(x11_host, "");
243         x11_use_fields = USE_NO_FIELDS;
245         firewire_channel = 63;
246         firewire_port = 0;
247         strcpy(firewire_path, "/dev/video1394");
248         firewire_syt = 30000;
250         dv1394_channel = 63;
251         dv1394_port = 0;
252         strcpy(dv1394_path, "/dev/dv1394");
253         dv1394_syt = 30000;
255         brightness = 32768;
256         hue = 32768;
257         color = 32768;
258         contrast = 32768;
259         whiteness = 32768;
262 VideoOutConfig::~VideoOutConfig()
267 int VideoOutConfig::operator!=(VideoOutConfig &that)
269         return !(*this == that);
272 int VideoOutConfig::operator==(VideoOutConfig &that)
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) &&
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) &&
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);
303 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
305         copy_from(&that);
306         return *this;
309 void VideoOutConfig::copy_from(VideoOutConfig *src)
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;
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;
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;
330 char* VideoOutConfig::get_path()
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;
351 int VideoOutConfig::load_defaults(BC_Hash *defaults)
353         char string[BCTEXTLEN];
354         sprintf(string, "VIDEO_OUT_DRIVER");
355         driver = defaults->get(string, driver);
356         sprintf(string, "LML_OUT_DEVICE");
357         defaults->get(string, lml_out_device);
358         sprintf(string, "BUZ_OUT_DEVICE");
359         defaults->get(string, buz_out_device);
360         sprintf(string, "BUZ_OUT_CHANNEL");
361         buz_out_channel = defaults->get(string, buz_out_channel);
362         sprintf(string, "BUZ_SWAP_FIELDS");
363         buz_swap_fields = defaults->get(string, buz_swap_fields);
364         sprintf(string, "X11_OUT_DEVICE");
365         defaults->get(string, x11_host);
366         x11_use_fields = defaults->get("X11_USE_FIELDS", x11_use_fields);
370         sprintf(string, "VFIREWIRE_OUT_CHANNEL");
371         firewire_channel = defaults->get(string, firewire_channel);
372         sprintf(string, "VFIREWIRE_OUT_PORT");
373         firewire_port = defaults->get(string, firewire_port);
374         sprintf(string, "VFIREWIRE_OUT_PATH");
375         defaults->get(string, firewire_path);
376         sprintf(string, "VFIREWIRE_OUT_SYT");
377         firewire_syt = defaults->get(string, firewire_syt);
379         sprintf(string, "VDV1394_OUT_CHANNEL");
380         dv1394_channel = defaults->get(string, dv1394_channel);
381         sprintf(string, "VDV1394_OUT_PORT");
382         dv1394_port = defaults->get(string, dv1394_port);
383         sprintf(string, "VDV1394_OUT_PATH");
384         defaults->get(string, dv1394_path);
385         sprintf(string, "VDV1394_OUT_SYT");
386         dv1394_syt = defaults->get(string, dv1394_syt);
387         return 0;
390 int VideoOutConfig::save_defaults(BC_Hash *defaults)
392         char string[BCTEXTLEN];
393         sprintf(string, "VIDEO_OUT_DRIVER");
394         defaults->update(string, driver);
395         sprintf(string, "LML_OUT_DEVICE");
396         defaults->update(string, lml_out_device);
397         sprintf(string, "BUZ_OUT_DEVICE");
398         defaults->update(string, buz_out_device);
399         sprintf(string, "BUZ_OUT_CHANNEL");
400         defaults->update(string, buz_out_channel);
401         sprintf(string, "BUZ_SWAP_FIELDS");
402         defaults->update(string, buz_swap_fields);
403         sprintf(string, "X11_OUT_DEVICE");
404         defaults->update(string, x11_host);
405         defaults->update("X11_USE_FIELDS", x11_use_fields);
407         sprintf(string, "VFIREWIRE_OUT_CHANNEL");
408         defaults->update(string, firewire_channel);
409         sprintf(string, "VFIREWIRE_OUT_PORT");
410         defaults->update(string, firewire_port);
411         sprintf(string, "VFIREWIRE_OUT_PATH");
412         defaults->update(string, firewire_path);
413         sprintf(string, "VFIREWIRE_OUT_SYT");
414         defaults->update(string, firewire_syt);
416         sprintf(string, "VDV1394_OUT_CHANNEL");
417         defaults->update(string, dv1394_channel);
418         sprintf(string, "VDV1394_OUT_PORT");
419         defaults->update(string, dv1394_port);
420         sprintf(string, "VDV1394_OUT_PATH");
421         defaults->update(string, dv1394_path);
422         sprintf(string, "VDV1394_OUT_SYT");
423         defaults->update(string, dv1394_syt);
424         return 0;
435 PlaybackConfig::PlaybackConfig()
437         aconfig = new AudioOutConfig(0);
438         vconfig = new VideoOutConfig;
439         sprintf(hostname, "localhost");
440         port = 23456;
443 PlaybackConfig::~PlaybackConfig()
445         delete aconfig;
446         delete vconfig;
449 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
451         copy_from(&that);
452         return *this;
455 void PlaybackConfig::copy_from(PlaybackConfig *src)
457         aconfig->copy_from(src->aconfig);
458         vconfig->copy_from(src->vconfig);
459         strcpy(hostname, src->hostname);
460         port = src->port;
463 int PlaybackConfig::load_defaults(BC_Hash *defaults)
465         char string[1024];
466         sprintf(string, "PLAYBACK_HOSTNAME");
467         defaults->get(string, hostname);
468         sprintf(string, "PLAYBACK_PORT");
469         port = defaults->get(string, port);
470         aconfig->load_defaults(defaults);
471         vconfig->load_defaults(defaults);
472         return 0;
475 int PlaybackConfig::save_defaults(BC_Hash *defaults)
477         char string[1024];
478         sprintf(string, "PLAYBACK_HOSTNAME");
479         defaults->update(string, hostname);
480         sprintf(string, "PLAYBACK_PORT");
481         defaults->update(string, port);
482         aconfig->save_defaults(defaults);
483         vconfig->save_defaults(defaults);
484         return 0;