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;
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");
265 VideoOutConfig::~VideoOutConfig()
270 int VideoOutConfig::operator!=(VideoOutConfig &that)
272 return !(*this == that);
275 int VideoOutConfig::operator==(VideoOutConfig &that)
277 return (driver == that.driver) &&
278 !strcmp(x11_host, that.x11_host) &&
279 (x11_use_fields == that.x11_use_fields) &&
280 (use_direct_x11 == that.use_direct_x11) &&
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->x11_host, src->x11_host);
313 this->x11_use_fields = src->x11_use_fields;
314 this->use_direct_x11 = src->use_direct_x11;
316 firewire_channel = src->firewire_channel;
317 firewire_port = src->firewire_port;
318 strcpy(firewire_path, src->firewire_path);
319 firewire_syt = src->firewire_syt;
321 dv1394_channel = src->dv1394_channel;
322 dv1394_port = src->dv1394_port;
323 strcpy(dv1394_path, src->dv1394_path);
324 dv1394_syt = src->dv1394_syt;
327 const char *VideoOutConfig::get_path()
332 case PLAYBACK_X11_XV:
335 case PLAYBACK_DV1394:
338 case PLAYBACK_FIREWIRE:
339 return firewire_path;
342 return default_video_device;
345 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
347 char prefix[BCTEXTLEN];
348 sprintf(prefix, "%c_", 'A'+active_config);
350 driver = defaults->getf(driver, "%sVIDEO_OUT_DRIVER", prefix);
351 defaults->getf(x11_host, "%sX11_OUT_DEVICE", prefix);
352 x11_use_fields = defaults->getf(x11_use_fields, "%sX11_USE_FIELDS", prefix);
356 firewire_channel = defaults->getf(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
357 firewire_port = defaults->getf(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
358 defaults->getf(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
359 firewire_syt = defaults->getf(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
361 dv1394_channel = defaults->getf(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
362 dv1394_port = defaults->getf(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
363 defaults->getf(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
364 dv1394_syt = defaults->getf(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
368 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
370 char prefix[BCTEXTLEN];
371 sprintf(prefix, "%c_", 'A'+active_config);
373 defaults->updatef(driver, "%sVIDEO_OUT_DRIVER", prefix);
374 defaults->updatef(x11_host, "%sX11_OUT_DEVICE", prefix);
375 defaults->updatef(x11_use_fields, "%sX11_USE_FIELDS", prefix);
377 defaults->updatef(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
378 defaults->updatef(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
379 defaults->updatef(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
380 defaults->updatef(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
382 defaults->updatef(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
383 defaults->updatef(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
384 defaults->updatef(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
385 defaults->updatef(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
397 PlaybackConfig::PlaybackConfig()
399 aconfig = new AudioOutConfig;
400 vconfig = new VideoOutConfig;
401 sprintf(hostname, "localhost");
406 PlaybackConfig::~PlaybackConfig()
412 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
418 void PlaybackConfig::copy_from(PlaybackConfig *src)
420 active_config = src->active_config;
421 aconfig->copy_from(src->aconfig);
422 vconfig->copy_from(src->vconfig);
423 strncpy(hostname, src->hostname, sizeof(hostname));
427 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
429 active_config = load_config >= 0 ? load_config :
430 defaults->get("PLAYBACK_ACTIVE_CONFIG", active_config);
431 aconfig->load_defaults(defaults, active_config);
432 vconfig->load_defaults(defaults, active_config);
433 defaults->get("PLAYBACK_HOSTNAME", hostname);
434 port = defaults->get("PLAYBACK_PORT", port);
438 int PlaybackConfig::save_defaults(BC_Hash *defaults)
440 defaults->update("PLAYBACK_ACTIVE_CONFIG", active_config);
441 aconfig->save_defaults(defaults, active_config);
442 vconfig->save_defaults(defaults, active_config);
443 defaults->update("PLAYBACK_HOSTNAME", hostname);
444 defaults->update("PLAYBACK_PORT", port);