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;
45 for(int i = 0; i < MAXDEVICES; i++)
47 oss_enable[i] = (i == 0);
48 sprintf(oss_out_device[i], "/dev/dsp");
51 esound_out_server[0] = 0;
54 pulse_out_server[0] = 0;
56 sprintf(alsa_out_device, "default");
58 interrupt_workaround = 0;
60 firewire_channel = 63;
62 strcpy(firewire_path, "/dev/video1394");
67 strcpy(dv1394_path, "/dev/dv1394");
71 AudioOutConfig::~AudioOutConfig()
77 int AudioOutConfig::operator!=(AudioOutConfig &that)
79 return !(*this == that);
82 int AudioOutConfig::operator==(AudioOutConfig &that)
85 fragment_size == that.fragment_size &&
86 driver == that.driver &&
87 EQUIV(audio_offset, that.audio_offset) &&
88 play_gain == that.play_gain &&
90 !strcmp(oss_out_device[0], that.oss_out_device[0]) &&
91 (oss_out_bits == that.oss_out_bits) &&
93 !strcmp(esound_out_server, that.esound_out_server) &&
94 (esound_out_port == that.esound_out_port) &&
96 !strcmp(pulse_out_server, that.pulse_out_server) &&
98 !strcmp(alsa_out_device, that.alsa_out_device) &&
99 (alsa_out_bits == that.alsa_out_bits) &&
100 (interrupt_workaround == that.interrupt_workaround) &&
102 firewire_channel == that.firewire_channel &&
103 firewire_port == that.firewire_port &&
104 firewire_syt == that.firewire_syt &&
105 !strcmp(firewire_path, that.firewire_path) &&
107 dv1394_channel == that.dv1394_channel &&
108 dv1394_port == that.dv1394_port &&
109 dv1394_syt == that.dv1394_syt &&
110 !strcmp(dv1394_path, that.dv1394_path);
115 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
121 void AudioOutConfig::copy_from(AudioOutConfig *src)
123 if( this == src ) return;
124 fragment_size = src->fragment_size;
125 driver = src->driver;
126 audio_offset = src->audio_offset;
127 map51_2 = src->map51_2;
128 play_gain = src->play_gain;
130 strcpy(esound_out_server, src->esound_out_server);
131 esound_out_port = src->esound_out_port;
133 strcpy(pulse_out_server, src->pulse_out_server);
135 for(int i = 0; i < MAXDEVICES; i++)
137 oss_enable[i] = src->oss_enable[i];
138 strcpy(oss_out_device[i], src->oss_out_device[i]);
140 oss_out_bits = src->oss_out_bits;
142 strcpy(alsa_out_device, src->alsa_out_device);
143 alsa_out_bits = src->alsa_out_bits;
144 interrupt_workaround = src->interrupt_workaround;
146 firewire_channel = src->firewire_channel;
147 firewire_port = src->firewire_port;
148 firewire_syt = src->firewire_syt;
149 strcpy(firewire_path, src->firewire_path);
151 dv1394_channel = src->dv1394_channel;
152 dv1394_port = src->dv1394_port;
153 dv1394_syt = src->dv1394_syt;
154 strcpy(dv1394_path, src->dv1394_path);
157 int AudioOutConfig::load_defaults(BC_Hash *defaults, int active_config)
159 char prefix[BCTEXTLEN];
160 sprintf(prefix, "%c_", 'A'+active_config);
162 fragment_size = defaults->getf(fragment_size, "%sFRAGMENT_SIZE", prefix);
163 audio_offset = defaults->getf(audio_offset, "%sAUDIO_OFFSET", prefix);
164 map51_2 = defaults->getf(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
165 play_gain = defaults->getf(play_gain, "%sAUDIO_OUT_GAIN", prefix);
166 driver = defaults->getf(driver, "%sAUDIO_OUT_DRIVER", prefix);
168 for(int i = 0; i < MAXDEVICES; i++)
170 oss_enable[i] = defaults->getf(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
171 defaults->getf(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
173 oss_out_bits = defaults->getf(oss_out_bits, "%sOSS_OUT_BITS", prefix);
175 defaults->getf(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
176 alsa_out_bits = defaults->getf(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
177 interrupt_workaround = defaults->getf(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
179 defaults->getf(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
180 defaults->getf(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
181 esound_out_port = defaults->getf(esound_out_port, "%sESOUND_OUT_PORT", prefix);
183 defaults->getf(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
185 firewire_channel = defaults->getf(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
186 firewire_port = defaults->getf(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
187 defaults->getf(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
188 firewire_syt = defaults->getf(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
190 dv1394_channel = defaults->getf(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
191 dv1394_port = defaults->getf(dv1394_port, "%sADV1394_OUT_PORT", prefix);
192 defaults->getf(dv1394_path, "%sADV1394_OUT_PATH", prefix);
193 dv1394_syt = defaults->getf(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
198 int AudioOutConfig::save_defaults(BC_Hash *defaults, int active_config)
200 char prefix[BCTEXTLEN];
201 sprintf(prefix, "%c_", 'A'+active_config);
203 defaults->updatef(fragment_size, "%sFRAGMENT_SIZE", prefix);
204 defaults->updatef(audio_offset, "%sAUDIO_OFFSET", prefix);
205 defaults->updatef(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
206 defaults->updatef(play_gain, "%sAUDIO_OUT_GAIN", prefix);
208 defaults->updatef(driver, "%sAUDIO_OUT_DRIVER", prefix);
210 for(int i = 0; i < MAXDEVICES; i++)
212 defaults->updatef(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
213 defaults->updatef(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
215 defaults->updatef(oss_out_bits, "%sOSS_OUT_BITS", prefix);
218 defaults->updatef(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
219 defaults->updatef(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
220 defaults->updatef(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
222 defaults->updatef(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
223 defaults->updatef(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
224 defaults->updatef(esound_out_port, "%sESOUND_OUT_PORT", prefix);
226 defaults->updatef(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
228 defaults->updatef(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
229 defaults->updatef(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
230 defaults->updatef(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
231 defaults->updatef(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
234 defaults->updatef(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
235 defaults->updatef(dv1394_port, "%sADV1394_OUT_PORT", prefix);
236 defaults->updatef(dv1394_path, "%sADV1394_OUT_PATH", prefix);
237 defaults->updatef(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
250 const char *VideoOutConfig::default_video_device = "/dev/video0";
252 VideoOutConfig::VideoOutConfig()
254 driver = PLAYBACK_X11;
256 x11_use_fields = USE_NO_FIELDS;
258 firewire_channel = 63;
260 strcpy(firewire_path, "/dev/video1394");
261 firewire_syt = 30000;
265 strcpy(dv1394_path, "/dev/dv1394");
277 VideoOutConfig::~VideoOutConfig()
282 int VideoOutConfig::operator!=(VideoOutConfig &that)
284 return !(*this == that);
287 int VideoOutConfig::operator==(VideoOutConfig &that)
289 return (driver == that.driver) &&
290 !strcmp(x11_host, that.x11_host) &&
291 (x11_use_fields == that.x11_use_fields) &&
292 (use_direct_x11 == that.use_direct_x11) &&
293 (brightness == that.brightness) &&
295 (color == that.color) &&
296 (contrast == that.contrast) &&
297 (whiteness == that.whiteness) &&
299 (firewire_channel == that.firewire_channel) &&
300 (firewire_port == that.firewire_port) &&
301 !strcmp(firewire_path, that.firewire_path) &&
302 (firewire_syt == that.firewire_syt) &&
304 (dv1394_channel == that.dv1394_channel) &&
305 (dv1394_port == that.dv1394_port) &&
306 !strcmp(dv1394_path, that.dv1394_path) &&
307 (dv1394_syt == that.dv1394_syt);
315 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
321 void VideoOutConfig::copy_from(VideoOutConfig *src)
323 this->driver = src->driver;
324 strcpy(this->x11_host, src->x11_host);
325 this->x11_use_fields = src->x11_use_fields;
326 this->use_direct_x11 = src->use_direct_x11;
328 firewire_channel = src->firewire_channel;
329 firewire_port = src->firewire_port;
330 strcpy(firewire_path, src->firewire_path);
331 firewire_syt = src->firewire_syt;
333 dv1394_channel = src->dv1394_channel;
334 dv1394_port = src->dv1394_port;
335 strcpy(dv1394_path, src->dv1394_path);
336 dv1394_syt = src->dv1394_syt;
339 const char *VideoOutConfig::get_path()
344 case PLAYBACK_X11_XV:
347 case PLAYBACK_DV1394:
350 case PLAYBACK_FIREWIRE:
351 return firewire_path;
354 return default_video_device;
357 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
359 char prefix[BCTEXTLEN];
360 sprintf(prefix, "%c_", 'A'+active_config);
362 driver = defaults->getf(driver, "%sVIDEO_OUT_DRIVER", prefix);
363 defaults->getf(x11_host, "%sX11_OUT_DEVICE", prefix);
364 x11_use_fields = defaults->getf(x11_use_fields, "%sX11_USE_FIELDS", prefix);
368 firewire_channel = defaults->getf(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
369 firewire_port = defaults->getf(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
370 defaults->getf(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
371 firewire_syt = defaults->getf(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
373 dv1394_channel = defaults->getf(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
374 dv1394_port = defaults->getf(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
375 defaults->getf(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
376 dv1394_syt = defaults->getf(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
380 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
382 char prefix[BCTEXTLEN];
383 sprintf(prefix, "%c_", 'A'+active_config);
385 defaults->updatef(driver, "%sVIDEO_OUT_DRIVER", prefix);
386 defaults->updatef(x11_host, "%sX11_OUT_DEVICE", prefix);
387 defaults->updatef(x11_use_fields, "%sX11_USE_FIELDS", prefix);
389 defaults->updatef(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
390 defaults->updatef(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
391 defaults->updatef(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
392 defaults->updatef(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
394 defaults->updatef(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
395 defaults->updatef(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
396 defaults->updatef(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
397 defaults->updatef(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
409 PlaybackConfig::PlaybackConfig()
411 aconfig = new AudioOutConfig;
412 vconfig = new VideoOutConfig;
413 sprintf(hostname, "localhost");
418 PlaybackConfig::~PlaybackConfig()
424 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
430 void PlaybackConfig::copy_from(PlaybackConfig *src)
432 active_config = src->active_config;
433 aconfig->copy_from(src->aconfig);
434 vconfig->copy_from(src->vconfig);
435 strncpy(hostname, src->hostname, sizeof(hostname));
439 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
441 active_config = load_config >= 0 ? load_config :
442 defaults->get("PLAYBACK_ACTIVE_CONFIG", active_config);
443 aconfig->load_defaults(defaults, active_config);
444 vconfig->load_defaults(defaults, active_config);
445 defaults->get("PLAYBACK_HOSTNAME", hostname);
446 port = defaults->get("PLAYBACK_PORT", port);
450 int PlaybackConfig::save_defaults(BC_Hash *defaults)
452 defaults->update("PLAYBACK_ACTIVE_CONFIG", active_config);
453 aconfig->save_defaults(defaults, active_config);
454 vconfig->save_defaults(defaults, active_config);
455 defaults->update("PLAYBACK_HOSTNAME", hostname);
456 defaults->update("PLAYBACK_PORT", port);