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);
238 const char *VideoOutConfig::default_video_device = "/dev/video0";
240 VideoOutConfig::VideoOutConfig()
242 driver = PLAYBACK_X11_XV;
244 x11_use_fields = USE_NO_FIELDS;
246 firewire_channel = 63;
248 strcpy(firewire_path, "/dev/video1394");
249 firewire_syt = 30000;
253 strcpy(dv1394_path, "/dev/dv1394");
264 VideoOutConfig::~VideoOutConfig()
269 int VideoOutConfig::operator!=(VideoOutConfig &that)
271 return !(*this == that);
274 int VideoOutConfig::operator==(VideoOutConfig &that)
276 return (driver == that.driver) &&
277 !strcmp(x11_host, that.x11_host) &&
278 (x11_use_fields == that.x11_use_fields) &&
279 (brightness == that.brightness) &&
281 (color == that.color) &&
282 (contrast == that.contrast) &&
283 (whiteness == that.whiteness) &&
285 (firewire_channel == that.firewire_channel) &&
286 (firewire_port == that.firewire_port) &&
287 !strcmp(firewire_path, that.firewire_path) &&
288 (firewire_syt == that.firewire_syt) &&
290 (dv1394_channel == that.dv1394_channel) &&
291 (dv1394_port == that.dv1394_port) &&
292 !strcmp(dv1394_path, that.dv1394_path) &&
293 (dv1394_syt == that.dv1394_syt);
301 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
307 void VideoOutConfig::copy_from(VideoOutConfig *src)
309 this->driver = src->driver;
310 strcpy(this->x11_host, src->x11_host);
311 this->x11_use_fields = src->x11_use_fields;
313 firewire_channel = src->firewire_channel;
314 firewire_port = src->firewire_port;
315 strcpy(firewire_path, src->firewire_path);
316 firewire_syt = src->firewire_syt;
318 dv1394_channel = src->dv1394_channel;
319 dv1394_port = src->dv1394_port;
320 strcpy(dv1394_path, src->dv1394_path);
321 dv1394_syt = src->dv1394_syt;
324 const char *VideoOutConfig::get_path()
329 case PLAYBACK_X11_XV:
332 case PLAYBACK_DV1394:
335 case PLAYBACK_FIREWIRE:
336 return firewire_path;
339 return default_video_device;
342 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
344 char prefix[BCTEXTLEN];
345 sprintf(prefix, "%c_", 'A'+active_config);
347 driver = defaults->getf(driver, "%sVIDEO_OUT_DRIVER", prefix);
348 defaults->getf(x11_host, "%sX11_OUT_DEVICE", prefix);
349 x11_use_fields = defaults->getf(x11_use_fields, "%sX11_USE_FIELDS", prefix);
353 firewire_channel = defaults->getf(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
354 firewire_port = defaults->getf(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
355 defaults->getf(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
356 firewire_syt = defaults->getf(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
358 dv1394_channel = defaults->getf(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
359 dv1394_port = defaults->getf(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
360 defaults->getf(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
361 dv1394_syt = defaults->getf(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
365 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
367 char prefix[BCTEXTLEN];
368 sprintf(prefix, "%c_", 'A'+active_config);
370 defaults->updatef(driver, "%sVIDEO_OUT_DRIVER", prefix);
371 defaults->updatef(x11_host, "%sX11_OUT_DEVICE", prefix);
372 defaults->updatef(x11_use_fields, "%sX11_USE_FIELDS", prefix);
374 defaults->updatef(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
375 defaults->updatef(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
376 defaults->updatef(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
377 defaults->updatef(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
379 defaults->updatef(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
380 defaults->updatef(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
381 defaults->updatef(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
382 defaults->updatef(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
394 PlaybackConfig::PlaybackConfig()
396 aconfig = new AudioOutConfig;
397 vconfig = new VideoOutConfig;
398 sprintf(hostname, "localhost");
403 PlaybackConfig::~PlaybackConfig()
409 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
415 void PlaybackConfig::copy_from(PlaybackConfig *src)
417 active_config = src->active_config;
418 aconfig->copy_from(src->aconfig);
419 vconfig->copy_from(src->vconfig);
420 strncpy(hostname, src->hostname, sizeof(hostname));
424 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
426 active_config = load_config >= 0 ? load_config :
427 defaults->get("PLAYBACK_ACTIVE_CONFIG", active_config);
428 aconfig->load_defaults(defaults, active_config);
429 vconfig->load_defaults(defaults, active_config);
430 defaults->get("PLAYBACK_HOSTNAME", hostname);
431 port = defaults->get("PLAYBACK_PORT", port);
435 int PlaybackConfig::save_defaults(BC_Hash *defaults)
437 defaults->update("PLAYBACK_ACTIVE_CONFIG", active_config);
438 aconfig->save_defaults(defaults, active_config);
439 vconfig->save_defaults(defaults, active_config);
440 defaults->update("PLAYBACK_HOSTNAME", hostname);
441 defaults->update("PLAYBACK_PORT", port);