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;
42 for(int i = 0; i < MAXDEVICES; i++)
44 oss_enable[i] = (i == 0);
45 sprintf(oss_out_device[i], "/dev/dsp");
48 esound_out_server[0] = 0;
51 sprintf(alsa_out_device, "default");
53 interrupt_workaround = 0;
55 firewire_channel = 63;
57 strcpy(firewire_path, "/dev/video1394");
62 strcpy(dv1394_path, "/dev/dv1394");
66 AudioOutConfig::~AudioOutConfig()
72 int AudioOutConfig::operator!=(AudioOutConfig &that)
74 return !(*this == that);
77 int AudioOutConfig::operator==(AudioOutConfig &that)
80 fragment_size == that.fragment_size &&
81 driver == that.driver &&
82 EQUIV(audio_offset, that.audio_offset) &&
83 play_gain == that.play_gain &&
85 !strcmp(oss_out_device[0], that.oss_out_device[0]) &&
86 (oss_out_bits == that.oss_out_bits) &&
90 !strcmp(esound_out_server, that.esound_out_server) &&
91 (esound_out_port == that.esound_out_port) &&
95 !strcmp(alsa_out_device, that.alsa_out_device) &&
96 (alsa_out_bits == that.alsa_out_bits) &&
97 (interrupt_workaround == that.interrupt_workaround) &&
99 firewire_channel == that.firewire_channel &&
100 firewire_port == that.firewire_port &&
101 firewire_syt == that.firewire_syt &&
102 !strcmp(firewire_path, that.firewire_path) &&
104 dv1394_channel == that.dv1394_channel &&
105 dv1394_port == that.dv1394_port &&
106 dv1394_syt == that.dv1394_syt &&
107 !strcmp(dv1394_path, that.dv1394_path);
112 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
118 void AudioOutConfig::copy_from(AudioOutConfig *src)
120 if( this == src ) return;
121 fragment_size = src->fragment_size;
122 driver = src->driver;
123 audio_offset = src->audio_offset;
124 map51_2 = src->map51_2;
125 play_gain = src->play_gain;
127 strcpy(esound_out_server, src->esound_out_server);
128 esound_out_port = src->esound_out_port;
129 for(int i = 0; i < MAXDEVICES; i++)
131 oss_enable[i] = src->oss_enable[i];
132 strcpy(oss_out_device[i], src->oss_out_device[i]);
134 oss_out_bits = src->oss_out_bits;
136 strcpy(alsa_out_device, src->alsa_out_device);
137 alsa_out_bits = src->alsa_out_bits;
138 interrupt_workaround = src->interrupt_workaround;
140 firewire_channel = src->firewire_channel;
141 firewire_port = src->firewire_port;
142 firewire_syt = src->firewire_syt;
143 strcpy(firewire_path, src->firewire_path);
145 dv1394_channel = src->dv1394_channel;
146 dv1394_port = src->dv1394_port;
147 dv1394_syt = src->dv1394_syt;
148 strcpy(dv1394_path, src->dv1394_path);
151 int AudioOutConfig::load_defaults(BC_Hash *defaults, int active_config)
153 char prefix[BCTEXTLEN];
154 sprintf(prefix, "%c_", 'A'+active_config);
156 fragment_size = defaults->getf(fragment_size, "%sFRAGMENT_SIZE", prefix);
157 audio_offset = defaults->getf(audio_offset, "%sAUDIO_OFFSET", prefix);
158 map51_2 = defaults->getf(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
159 play_gain = defaults->getf(play_gain, "%sAUDIO_OUT_GAIN", prefix);
160 driver = defaults->getf(driver, "%sAUDIO_OUT_DRIVER", prefix);
162 for(int i = 0; i < MAXDEVICES; i++)
164 oss_enable[i] = defaults->getf(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
165 defaults->getf(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
167 oss_out_bits = defaults->getf(oss_out_bits, "%sOSS_OUT_BITS", prefix);
169 defaults->getf(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
170 alsa_out_bits = defaults->getf(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
171 interrupt_workaround = defaults->getf(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
173 defaults->getf(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
174 esound_out_port = defaults->getf(esound_out_port, "%sESOUND_OUT_PORT", prefix);
176 firewire_channel = defaults->getf(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
177 firewire_port = defaults->getf(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
178 defaults->getf(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
179 firewire_syt = defaults->getf(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
181 dv1394_channel = defaults->getf(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
182 dv1394_port = defaults->getf(dv1394_port, "%sADV1394_OUT_PORT", prefix);
183 defaults->getf(dv1394_path, "%sADV1394_OUT_PATH", prefix);
184 dv1394_syt = defaults->getf(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
189 int AudioOutConfig::save_defaults(BC_Hash *defaults, int active_config)
191 char prefix[BCTEXTLEN];
192 sprintf(prefix, "%c_", 'A'+active_config);
194 defaults->updatef(fragment_size, "%sFRAGMENT_SIZE", prefix);
195 defaults->updatef(audio_offset, "%sAUDIO_OFFSET", prefix);
196 defaults->updatef(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
197 defaults->updatef(play_gain, "%sAUDIO_OUT_GAIN", prefix);
199 defaults->updatef(driver, "%sAUDIO_OUT_DRIVER", prefix);
201 for(int i = 0; i < MAXDEVICES; i++)
203 defaults->updatef(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
204 defaults->updatef(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
206 defaults->updatef(oss_out_bits, "%sOSS_OUT_BITS", prefix);
209 defaults->updatef(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
210 defaults->updatef(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
211 defaults->updatef(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
213 defaults->updatef(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
214 defaults->updatef(esound_out_port, "%sESOUND_OUT_PORT", prefix);
216 defaults->updatef(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
217 defaults->updatef(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
218 defaults->updatef(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
219 defaults->updatef(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
222 defaults->updatef(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
223 defaults->updatef(dv1394_port, "%sADV1394_OUT_PORT", prefix);
224 defaults->updatef(dv1394_path, "%sADV1394_OUT_PATH", prefix);
225 defaults->updatef(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
239 VideoOutConfig::VideoOutConfig()
241 sprintf(lml_out_device, "/dev/mvideo/stream");
242 sprintf(buz_out_device, "/dev/video0");
243 driver = PLAYBACK_X11_XV;
247 x11_use_fields = USE_NO_FIELDS;
249 firewire_channel = 63;
251 strcpy(firewire_path, "/dev/video1394");
252 firewire_syt = 30000;
256 strcpy(dv1394_path, "/dev/dv1394");
266 VideoOutConfig::~VideoOutConfig()
271 int VideoOutConfig::operator!=(VideoOutConfig &that)
273 return !(*this == that);
276 int VideoOutConfig::operator==(VideoOutConfig &that)
278 return (driver == that.driver) &&
279 !strcmp(lml_out_device, that.lml_out_device) &&
280 !strcmp(buz_out_device, that.buz_out_device) &&
281 (buz_out_channel == that.buz_out_channel) &&
282 (buz_swap_fields == that.buz_swap_fields) &&
283 !strcmp(x11_host, that.x11_host) &&
284 (x11_use_fields == that.x11_use_fields) &&
285 (brightness == that.brightness) &&
287 (color == that.color) &&
288 (contrast == that.contrast) &&
289 (whiteness == that.whiteness) &&
291 (firewire_channel == that.firewire_channel) &&
292 (firewire_port == that.firewire_port) &&
293 !strcmp(firewire_path, that.firewire_path) &&
294 (firewire_syt == that.firewire_syt) &&
296 (dv1394_channel == that.dv1394_channel) &&
297 (dv1394_port == that.dv1394_port) &&
298 !strcmp(dv1394_path, that.dv1394_path) &&
299 (dv1394_syt == that.dv1394_syt);
307 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
313 void VideoOutConfig::copy_from(VideoOutConfig *src)
315 this->driver = src->driver;
316 strcpy(this->lml_out_device, src->lml_out_device);
317 strcpy(this->buz_out_device, src->buz_out_device);
318 this->buz_out_channel = src->buz_out_channel;
319 this->buz_swap_fields = src->buz_swap_fields;
320 strcpy(this->x11_host, src->x11_host);
321 this->x11_use_fields = src->x11_use_fields;
323 firewire_channel = src->firewire_channel;
324 firewire_port = src->firewire_port;
325 strcpy(firewire_path, src->firewire_path);
326 firewire_syt = src->firewire_syt;
328 dv1394_channel = src->dv1394_channel;
329 dv1394_port = src->dv1394_port;
330 strcpy(dv1394_path, src->dv1394_path);
331 dv1394_syt = src->dv1394_syt;
334 char* VideoOutConfig::get_path()
339 return buz_out_device;
342 case PLAYBACK_X11_XV:
345 case PLAYBACK_DV1394:
348 case PLAYBACK_FIREWIRE:
349 return firewire_path;
352 return buz_out_device;
355 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
357 char prefix[BCTEXTLEN];
358 sprintf(prefix, "%c_", 'A'+active_config);
360 driver = defaults->getf(driver, "%sVIDEO_OUT_DRIVER", prefix);
361 defaults->getf(lml_out_device, "%sLML_OUT_DEVICE", prefix);
362 defaults->getf(buz_out_device, "%sBUZ_OUT_DEVICE", prefix);
363 buz_out_channel = defaults->getf(buz_out_channel, "%sBUZ_OUT_CHANNEL", prefix);
364 buz_swap_fields = defaults->getf(buz_swap_fields, "%sBUZ_SWAP_FIELDS", prefix);
365 defaults->getf(x11_host, "%sX11_OUT_DEVICE", prefix);
366 x11_use_fields = defaults->getf(x11_use_fields, "%sX11_USE_FIELDS", prefix);
370 firewire_channel = defaults->getf(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
371 firewire_port = defaults->getf(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
372 defaults->getf(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
373 firewire_syt = defaults->getf(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
375 dv1394_channel = defaults->getf(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
376 dv1394_port = defaults->getf(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
377 defaults->getf(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
378 dv1394_syt = defaults->getf(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
382 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
384 char prefix[BCTEXTLEN];
385 sprintf(prefix, "%c_", 'A'+active_config);
387 defaults->updatef(driver, "%sVIDEO_OUT_DRIVER", prefix);
388 defaults->updatef(lml_out_device, "%sLML_OUT_DEVICE", prefix);
389 defaults->updatef(buz_out_device, "%sBUZ_OUT_DEVICE", prefix);
390 defaults->updatef(buz_out_channel, "%sBUZ_OUT_CHANNEL", prefix);
391 defaults->updatef(buz_swap_fields, "%sBUZ_SWAP_FIELDS", prefix);
392 defaults->updatef(x11_host, "%sX11_OUT_DEVICE", prefix);
393 defaults->updatef(x11_use_fields, "%sX11_USE_FIELDS", prefix);
395 defaults->updatef(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
396 defaults->updatef(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
397 defaults->updatef(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
398 defaults->updatef(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
400 defaults->updatef(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
401 defaults->updatef(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
402 defaults->updatef(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
403 defaults->updatef(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
415 PlaybackConfig::PlaybackConfig()
417 aconfig = new AudioOutConfig;
418 vconfig = new VideoOutConfig;
419 sprintf(hostname, "localhost");
424 PlaybackConfig::~PlaybackConfig()
430 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
436 void PlaybackConfig::copy_from(PlaybackConfig *src)
438 active_config = src->active_config;
439 aconfig->copy_from(src->aconfig);
440 vconfig->copy_from(src->vconfig);
441 strncpy(hostname, src->hostname, sizeof(hostname));
445 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
447 active_config = load_config >= 0 ? load_config :
448 defaults->get("PLAYBACK_ACTIVE_CONFIG", active_config);
449 aconfig->load_defaults(defaults, active_config);
450 vconfig->load_defaults(defaults, active_config);
451 defaults->get("PLAYBACK_HOSTNAME", hostname);
452 port = defaults->get("PLAYBACK_PORT", port);
456 int PlaybackConfig::save_defaults(BC_Hash *defaults)
458 defaults->update("PLAYBACK_ACTIVE_CONFIG", active_config);
459 aconfig->save_defaults(defaults, active_config);
460 vconfig->save_defaults(defaults, active_config);
461 defaults->update("PLAYBACK_HOSTNAME", hostname);
462 defaults->update("PLAYBACK_PORT", port);