4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "playbackconfig.h"
26 #include "videodevice.inc"
29 AudioOutConfig::AudioOutConfig()
31 fragment_size = 16384;
46 for(int i = 0; i < MAXDEVICES; i++)
48 oss_enable[i] = (i == 0);
49 sprintf(oss_out_device[i], "/dev/dsp");
52 esound_out_server[0] = 0;
55 pulse_out_server[0] = 0;
57 sprintf(alsa_out_device, "default");
59 interrupt_workaround = 0;
61 firewire_channel = 63;
63 strcpy(firewire_path, "/dev/video1394");
68 strcpy(dv1394_path, "/dev/dv1394");
72 AudioOutConfig::~AudioOutConfig()
78 int AudioOutConfig::operator!=(AudioOutConfig &that)
80 return !(*this == that);
83 int AudioOutConfig::operator==(AudioOutConfig &that)
86 fragment_size == that.fragment_size &&
87 driver == that.driver &&
88 EQUIV(audio_offset, that.audio_offset) &&
89 play_gain == that.play_gain &&
91 !strcmp(oss_out_device[0], that.oss_out_device[0]) &&
92 (oss_out_bits == that.oss_out_bits) &&
94 !strcmp(esound_out_server, that.esound_out_server) &&
95 (esound_out_port == that.esound_out_port) &&
97 !strcmp(pulse_out_server, that.pulse_out_server) &&
99 !strcmp(alsa_out_device, that.alsa_out_device) &&
100 (alsa_out_bits == that.alsa_out_bits) &&
101 (interrupt_workaround == that.interrupt_workaround) &&
103 firewire_channel == that.firewire_channel &&
104 firewire_port == that.firewire_port &&
105 firewire_syt == that.firewire_syt &&
106 !strcmp(firewire_path, that.firewire_path) &&
108 dv1394_channel == that.dv1394_channel &&
109 dv1394_port == that.dv1394_port &&
110 dv1394_syt == that.dv1394_syt &&
111 !strcmp(dv1394_path, that.dv1394_path);
116 AudioOutConfig& AudioOutConfig::operator=(AudioOutConfig &that)
122 void AudioOutConfig::copy_from(AudioOutConfig *src)
124 if( this == src ) return;
125 fragment_size = src->fragment_size;
126 driver = src->driver;
127 audio_offset = src->audio_offset;
128 map51_2 = src->map51_2;
129 play_gain = src->play_gain;
131 strcpy(esound_out_server, src->esound_out_server);
132 esound_out_port = src->esound_out_port;
134 strcpy(pulse_out_server, src->pulse_out_server);
136 for(int i = 0; i < MAXDEVICES; i++)
138 oss_enable[i] = src->oss_enable[i];
139 strcpy(oss_out_device[i], src->oss_out_device[i]);
141 oss_out_bits = src->oss_out_bits;
143 strcpy(alsa_out_device, src->alsa_out_device);
144 alsa_out_bits = src->alsa_out_bits;
145 interrupt_workaround = src->interrupt_workaround;
147 firewire_channel = src->firewire_channel;
148 firewire_port = src->firewire_port;
149 firewire_syt = src->firewire_syt;
150 strcpy(firewire_path, src->firewire_path);
152 dv1394_channel = src->dv1394_channel;
153 dv1394_port = src->dv1394_port;
154 dv1394_syt = src->dv1394_syt;
155 strcpy(dv1394_path, src->dv1394_path);
158 int AudioOutConfig::load_defaults(BC_Hash *defaults, int active_config)
160 char prefix[BCTEXTLEN];
161 sprintf(prefix, "%c_", 'A'+active_config);
163 fragment_size = defaults->getf(fragment_size, "%sFRAGMENT_SIZE", prefix);
164 audio_offset = defaults->getf(audio_offset, "%sAUDIO_OFFSET", prefix);
165 map51_2 = defaults->getf(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
166 play_gain = defaults->getf(play_gain, "%sAUDIO_OUT_GAIN", prefix);
167 driver = defaults->getf(driver, "%sAUDIO_OUT_DRIVER", prefix);
169 for(int i = 0; i < MAXDEVICES; i++)
171 oss_enable[i] = defaults->getf(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
172 defaults->getf(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
174 oss_out_bits = defaults->getf(oss_out_bits, "%sOSS_OUT_BITS", prefix);
176 defaults->getf(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
177 alsa_out_bits = defaults->getf(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
178 interrupt_workaround = defaults->getf(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
180 defaults->getf(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
181 defaults->getf(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
182 esound_out_port = defaults->getf(esound_out_port, "%sESOUND_OUT_PORT", prefix);
184 defaults->getf(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
186 firewire_channel = defaults->getf(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
187 firewire_port = defaults->getf(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
188 defaults->getf(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
189 firewire_syt = defaults->getf(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
191 dv1394_channel = defaults->getf(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
192 dv1394_port = defaults->getf(dv1394_port, "%sADV1394_OUT_PORT", prefix);
193 defaults->getf(dv1394_path, "%sADV1394_OUT_PATH", prefix);
194 dv1394_syt = defaults->getf(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
199 int AudioOutConfig::save_defaults(BC_Hash *defaults, int active_config)
201 char prefix[BCTEXTLEN];
202 sprintf(prefix, "%c_", 'A'+active_config);
204 defaults->updatef(fragment_size, "%sFRAGMENT_SIZE", prefix);
205 defaults->updatef(audio_offset, "%sAUDIO_OFFSET", prefix);
206 defaults->updatef(map51_2, "%sAUDIO_OUT_MAP51_2", prefix);
207 defaults->updatef(play_gain, "%sAUDIO_OUT_GAIN", prefix);
209 defaults->updatef(driver, "%sAUDIO_OUT_DRIVER", prefix);
211 for(int i = 0; i < MAXDEVICES; i++)
213 defaults->updatef(oss_enable[i], "%sOSS_ENABLE_%d", prefix, i);
214 defaults->updatef(oss_out_device[i], "%sOSS_OUT_DEVICE_%d", prefix, i);
216 defaults->updatef(oss_out_bits, "%sOSS_OUT_BITS", prefix);
219 defaults->updatef(alsa_out_device, "%sALSA_OUT_DEVICE", prefix);
220 defaults->updatef(alsa_out_bits, "%sALSA_OUT_BITS", prefix);
221 defaults->updatef(interrupt_workaround, "%sALSA_INTERRUPT_WORKAROUND", prefix);
223 defaults->updatef(esound_out_server, "%sESOUND_OUT_SERVER", prefix);
224 defaults->updatef(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
225 defaults->updatef(esound_out_port, "%sESOUND_OUT_PORT", prefix);
227 defaults->updatef(pulse_out_server, "%sPULSE_OUT_SERVER", prefix);
229 defaults->updatef(firewire_channel, "%sAFIREWIRE_OUT_CHANNEL", prefix);
230 defaults->updatef(firewire_port, "%sAFIREWIRE_OUT_PORT", prefix);
231 defaults->updatef(firewire_path, "%sAFIREWIRE_OUT_PATH", prefix);
232 defaults->updatef(firewire_syt, "%sAFIREWIRE_OUT_SYT", prefix);
235 defaults->updatef(dv1394_channel, "%sADV1394_OUT_CHANNEL", prefix);
236 defaults->updatef(dv1394_port, "%sADV1394_OUT_PORT", prefix);
237 defaults->updatef(dv1394_path, "%sADV1394_OUT_PATH", prefix);
238 defaults->updatef(dv1394_syt, "%sADV1394_OUT_SYT", prefix);
251 const char *VideoOutConfig::default_video_device = "/dev/video0";
253 VideoOutConfig::VideoOutConfig()
255 driver = PLAYBACK_X11;
257 x11_use_fields = USE_NO_FIELDS;
259 firewire_channel = 63;
261 strcpy(firewire_path, "/dev/video1394");
262 firewire_syt = 30000;
266 strcpy(dv1394_path, "/dev/dv1394");
278 VideoOutConfig::~VideoOutConfig()
283 int VideoOutConfig::operator!=(VideoOutConfig &that)
285 return !(*this == that);
288 int VideoOutConfig::operator==(VideoOutConfig &that)
290 return (driver == that.driver) &&
291 !strcmp(x11_host, that.x11_host) &&
292 (x11_use_fields == that.x11_use_fields) &&
293 (use_direct_x11 == that.use_direct_x11) &&
294 (brightness == that.brightness) &&
296 (color == that.color) &&
297 (contrast == that.contrast) &&
298 (whiteness == that.whiteness) &&
300 (firewire_channel == that.firewire_channel) &&
301 (firewire_port == that.firewire_port) &&
302 !strcmp(firewire_path, that.firewire_path) &&
303 (firewire_syt == that.firewire_syt) &&
305 (dv1394_channel == that.dv1394_channel) &&
306 (dv1394_port == that.dv1394_port) &&
307 !strcmp(dv1394_path, that.dv1394_path) &&
308 (dv1394_syt == that.dv1394_syt);
316 VideoOutConfig& VideoOutConfig::operator=(VideoOutConfig &that)
322 void VideoOutConfig::copy_from(VideoOutConfig *src)
324 this->driver = src->driver;
325 strcpy(this->x11_host, src->x11_host);
326 this->x11_use_fields = src->x11_use_fields;
327 this->use_direct_x11 = src->use_direct_x11;
329 firewire_channel = src->firewire_channel;
330 firewire_port = src->firewire_port;
331 strcpy(firewire_path, src->firewire_path);
332 firewire_syt = src->firewire_syt;
334 dv1394_channel = src->dv1394_channel;
335 dv1394_port = src->dv1394_port;
336 strcpy(dv1394_path, src->dv1394_path);
337 dv1394_syt = src->dv1394_syt;
340 const char *VideoOutConfig::get_path()
345 case PLAYBACK_X11_XV:
348 case PLAYBACK_DV1394:
351 case PLAYBACK_FIREWIRE:
352 return firewire_path;
355 return default_video_device;
358 int VideoOutConfig::load_defaults(BC_Hash *defaults, int active_config)
360 char prefix[BCTEXTLEN];
361 sprintf(prefix, "%c_", 'A'+active_config);
363 driver = defaults->getf(driver, "%sVIDEO_OUT_DRIVER", prefix);
364 defaults->getf(x11_host, "%sX11_OUT_DEVICE", prefix);
365 x11_use_fields = defaults->getf(x11_use_fields, "%sX11_USE_FIELDS", prefix);
369 firewire_channel = defaults->getf(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
370 firewire_port = defaults->getf(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
371 defaults->getf(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
372 firewire_syt = defaults->getf(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
374 dv1394_channel = defaults->getf(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
375 dv1394_port = defaults->getf(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
376 defaults->getf(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
377 dv1394_syt = defaults->getf(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
381 int VideoOutConfig::save_defaults(BC_Hash *defaults, int active_config)
383 char prefix[BCTEXTLEN];
384 sprintf(prefix, "%c_", 'A'+active_config);
386 defaults->updatef(driver, "%sVIDEO_OUT_DRIVER", prefix);
387 defaults->updatef(x11_host, "%sX11_OUT_DEVICE", prefix);
388 defaults->updatef(x11_use_fields, "%sX11_USE_FIELDS", prefix);
390 defaults->updatef(firewire_channel, "%sVFIREWIRE_OUT_CHANNEL", prefix);
391 defaults->updatef(firewire_port, "%sVFIREWIRE_OUT_PORT", prefix);
392 defaults->updatef(firewire_path, "%sVFIREWIRE_OUT_PATH", prefix);
393 defaults->updatef(firewire_syt, "%sVFIREWIRE_OUT_SYT", prefix);
395 defaults->updatef(dv1394_channel, "%sVDV1394_OUT_CHANNEL", prefix);
396 defaults->updatef(dv1394_port, "%sVDV1394_OUT_PORT", prefix);
397 defaults->updatef(dv1394_path, "%sVDV1394_OUT_PATH", prefix);
398 defaults->updatef(dv1394_syt, "%sVDV1394_OUT_SYT", prefix);
410 PlaybackConfig::PlaybackConfig()
412 aconfig = new AudioOutConfig;
413 vconfig = new VideoOutConfig;
414 sprintf(hostname, "localhost");
419 PlaybackConfig::~PlaybackConfig()
425 PlaybackConfig& PlaybackConfig::operator=(PlaybackConfig &that)
431 void PlaybackConfig::copy_from(PlaybackConfig *src)
433 active_config = src->active_config;
434 aconfig->copy_from(src->aconfig);
435 vconfig->copy_from(src->vconfig);
436 strncpy(hostname, src->hostname, sizeof(hostname));
440 int PlaybackConfig::load_defaults(BC_Hash *defaults, int load_config)
442 active_config = load_config >= 0 ? load_config :
443 defaults->get("PLAYBACK_ACTIVE_CONFIG", active_config);
444 aconfig->load_defaults(defaults, active_config);
445 vconfig->load_defaults(defaults, active_config);
446 defaults->get("PLAYBACK_HOSTNAME", hostname);
447 port = defaults->get("PLAYBACK_PORT", port);
451 int PlaybackConfig::save_defaults(BC_Hash *defaults)
453 defaults->update("PLAYBACK_ACTIVE_CONFIG", active_config);
454 aconfig->save_defaults(defaults, active_config);
455 vconfig->save_defaults(defaults, active_config);
456 defaults->update("PLAYBACK_HOSTNAME", hostname);
457 defaults->update("PLAYBACK_PORT", port);