4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
24 #include "playbackconfig.h"
25 #include "videodevice.inc"
28 AudioOutConfig::AudioOutConfig()
30 fragment_size = 16384;
38 for(int i = 0; i < MAXDEVICES; i++)
40 oss_enable[i] = (i == 0);
41 sprintf(oss_out_device[i], "/dev/dsp");
44 esound_out_server[0] = 0;
47 sprintf(alsa_out_device, "default");
49 interrupt_workaround = 0;
51 firewire_channel = 63;
53 strcpy(firewire_path, "/dev/video1394");
58 strcpy(dv1394_path, "/dev/dv1394");
62 AudioOutConfig::~AudioOutConfig()
68 int AudioOutConfig::operator!=(AudioOutConfig &that)
70 return !(*this == that);
73 int AudioOutConfig::operator==(AudioOutConfig &that)
76 fragment_size == that.fragment_size &&
77 driver == that.driver &&
78 EQUIV(audio_offset, that.audio_offset) &&
79 play_gain == that.play_gain &&
81 !strcmp(oss_out_device[0], that.oss_out_device[0]) &&
82 (oss_out_bits == that.oss_out_bits) &&
86 !strcmp(esound_out_server, that.esound_out_server) &&
87 (esound_out_port == that.esound_out_port) &&
91 !strcmp(alsa_out_device, that.alsa_out_device) &&
92 (alsa_out_bits == that.alsa_out_bits) &&
93 (interrupt_workaround == that.interrupt_workaround) &&
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) &&
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);
108 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
114 void AudioOutConfig::copy_from(AudioOutConfig *src)
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;
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++)
127 oss_enable[i] = src->oss_enable[i];
128 strcpy(oss_out_device[i], src->oss_out_device[i]);
130 oss_out_bits = src->oss_out_bits;
132 strcpy(alsa_out_device, src->alsa_out_device);
133 alsa_out_bits = src->alsa_out_bits;
134 interrupt_workaround = src->interrupt_workaround;
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);
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);
147 int AudioOutConfig::load_defaults(BC_Hash *defaults, int active_config)
149 char prefix[BCTEXTLEN];
150 sprintf(prefix, "%c_", 'A'+active_config);
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);
158 for(int i = 0; i < MAXDEVICES; i++)
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);
163 oss_out_bits = defaults->getf(oss_out_bits, "%sOSS_OUT_BITS", prefix);
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);
169 defaults->getf(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
170 esound_out_port = defaults->getf(esound_out_port, "%sESOUND_OUT_PORT", prefix);
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);
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);
185 int AudioOutConfig::save_defaults(BC_Hash *defaults, int active_config)
187 char prefix[BCTEXTLEN];
188 sprintf(prefix, "%c_", 'A'+active_config);
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);
195 defaults->updatef(driver, "%sAUDIO_OUT_DRIVER", prefix);
197 for(int i = 0; i < MAXDEVICES; i++)
199 defaults->updatef(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
200 defaults->updatef(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
202 defaults->updatef(oss_out_bits, "%sOSS_OUT_BITS", prefix);
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);
209 defaults->updatef(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
210 defaults->updatef(esound_out_port, "%sESOUND_OUT_PORT", prefix);
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);
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);
235 VideoOutConfig::VideoOutConfig()
237 sprintf(lml_out_device, "/dev/mvideo/stream");
238 sprintf(buz_out_device, "/dev/video0");
239 driver = PLAYBACK_X11_XV;
243 x11_use_fields = USE_NO_FIELDS;
245 firewire_channel = 63;
247 strcpy(firewire_path, "/dev/video1394");
248 firewire_syt = 30000;
252 strcpy(dv1394_path, "/dev/dv1394");
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) &&
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)
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()
335 return buz_out_device;
338 case PLAYBACK_X11_XV:
341 case PLAYBACK_DV1394:
344 case PLAYBACK_FIREWIRE:
345 return firewire_path;
348 return buz_out_device;
351 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
353 char prefix[BCTEXTLEN];
354 sprintf(prefix, "%c_", 'A'+active_config);
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);
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);
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);
378 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
380 char prefix[BCTEXTLEN];
381 sprintf(prefix, "%c_", 'A'+active_config);
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);
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);
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);
411 PlaybackConfig::PlaybackConfig()
413 aconfig = new AudioOutConfig;
414 vconfig = new VideoOutConfig;
415 sprintf(hostname, "localhost");
420 PlaybackConfig::~PlaybackConfig()
426 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
432 void PlaybackConfig::copy_from(PlaybackConfig *src)
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));
441 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
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);
452 int PlaybackConfig::save_defaults(BC_Hash *defaults)
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);