Credit Andrew R for finding the direct copy mods for exr and ppm sequences
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / recordconfig.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "audiodevice.inc"
23 #include "bchash.h"
24 #include "playbackconfig.h"
25 #include "recordconfig.h"
26 #include "videodevice.inc"
27 #include <string.h>
28
29
30
31
32
33 AudioInConfig::AudioInConfig()
34 {
35 #ifdef HAVE_ALSA
36         driver = AUDIO_ALSA;
37 #else
38         driver = AUDIO_OSS;
39 #endif
40         for(int i = 0; i < MAXDEVICES; i++)
41         {
42                 oss_enable[i] = (i == 0);
43                 sprintf(oss_in_device[i], "/dev/dsp");
44         }
45         oss_in_bits = 16;
46         firewire_port = 0;
47         firewire_channel = 63;
48         strcpy(firewire_path, "/dev/raw1394");
49         esound_in_server[0] = 0;
50         esound_in_port = 0;
51         pulse_in_server[0] = 0;
52         sprintf(alsa_in_device, "default");
53         alsa_in_bits = 16;
54         in_samplerate = 48000;
55         strcpy(dvb_in_adapter,"/dev/dvb/adapter0");
56         dvb_in_device = 0;
57         dvb_in_bits = 16;
58         v4l2_in_bits = 16;
59         channels = 2;
60         follow_audio = 1;
61         map51_2 = 1;
62         rec_gain = 1.0;
63 }
64
65 AudioInConfig::~AudioInConfig()
66 {
67 }
68
69 int AudioInConfig::is_duplex(AudioInConfig *in, AudioOutConfig *out)
70 {
71         if(in->driver == out->driver)
72         {
73                 switch(in->driver)
74                 {
75                         case AUDIO_OSS:
76                         case AUDIO_OSS_ENVY24:
77                                 return (!strcmp(in->oss_in_device[0], out->oss_out_device[0]) &&
78                                         in->oss_in_bits == out->oss_out_bits);
79                                 break;
80
81 // ALSA always opens 2 devices
82                         case AUDIO_ALSA:
83                                 return 0;
84                                 break;
85                 }
86         }
87
88         return 0;
89 }
90
91
92 void AudioInConfig::copy_from(AudioInConfig *src)
93 {
94         driver = src->driver;
95
96         firewire_port = src->firewire_port;
97         firewire_channel = src->firewire_channel;
98         strcpy(firewire_path, src->firewire_path);
99
100         strcpy(esound_in_server, src->esound_in_server);
101         esound_in_port = src->esound_in_port;
102
103         strcpy(pulse_in_server, src->pulse_in_server);
104
105         for(int i = 0; i < MAXDEVICES; i++)
106         {
107                 oss_enable[i] = src->oss_enable[i];
108                 strcpy(oss_in_device[i], src->oss_in_device[i]);
109                 oss_in_bits = src->oss_in_bits;
110         }
111
112         strcpy(alsa_in_device, src->alsa_in_device);
113         alsa_in_bits = src->alsa_in_bits;
114         in_samplerate = src->in_samplerate;
115         strcpy(dvb_in_adapter, src->dvb_in_adapter);
116         dvb_in_device = src->dvb_in_device;
117         dvb_in_bits = src->dvb_in_bits;
118         v4l2_in_bits = src->v4l2_in_bits;
119         channels = src->channels;
120         follow_audio = src->follow_audio;
121         map51_2 = src->map51_2;
122         rec_gain = src->rec_gain;
123 }
124
125 AudioInConfig& AudioInConfig::operator=(AudioInConfig &that)
126 {
127         copy_from(&that);
128         return *this;
129 }
130
131 int AudioInConfig::load_defaults(BC_Hash *defaults)
132 {
133         driver = defaults->get("R_AUDIOINDRIVER", driver);
134         firewire_port = defaults->get("R_AFIREWIRE_IN_PORT", firewire_port);
135         firewire_channel = defaults->get("R_AFIREWIRE_IN_CHANNEL", firewire_channel);
136         defaults->get("R_AFIREWIRE_IN_PATH", firewire_path);
137         for(int i = 0; i < MAXDEVICES; i++)
138         {
139                 oss_enable[i] = defaults->getf(oss_enable[i], "R_OSS_ENABLE_%d", i);
140                 defaults->getf(oss_in_device[i], "R_OSS_IN_DEVICE_%d", i);
141         }
142         oss_in_bits = defaults->get("R_OSS_IN_BITS", oss_in_bits);
143         defaults->get("R_ESOUND_IN_SERVER", esound_in_server);
144         defaults->get("R_PULSE_IN_SERVER", pulse_in_server);
145         esound_in_port = defaults->get("R_ESOUND_IN_PORT", esound_in_port);
146         defaults->get("R_PULSE_IN_SERVER", pulse_in_server);
147         defaults->get("R_ALSA_IN_DEVICE", alsa_in_device);
148         alsa_in_bits = defaults->get("R_ALSA_IN_BITS", alsa_in_bits);
149         in_samplerate = defaults->get("R_IN_SAMPLERATE", in_samplerate);
150         defaults->get("R_AUDIO_DVB_IN_ADAPTER", dvb_in_adapter);
151         dvb_in_device = defaults->get("R_AUDIO_DVB_IN_DEVICE", dvb_in_device);
152         dvb_in_bits = defaults->get("R_DVB_IN_BITS", dvb_in_bits);
153         v4l2_in_bits = defaults->get("R_V4L2_IN_BITS", v4l2_in_bits);
154         channels = defaults->get("R_IN_CHANNELS", channels);
155         follow_audio = defaults->get("R_FOLLOW_AUDIO", follow_audio);
156         map51_2 = defaults->get("R_AUDIO_IN_MAP51_2", map51_2);
157         rec_gain = defaults->get("R_AUDIO_IN_GAIN", rec_gain);
158         return 0;
159 }
160
161 int AudioInConfig::save_defaults(BC_Hash *defaults)
162 {
163         defaults->update("R_AUDIOINDRIVER", driver);
164         defaults->update("R_AFIREWIRE_IN_PORT", firewire_port);
165         defaults->update("R_AFIREWIRE_IN_CHANNEL", firewire_channel);
166         defaults->update("R_AFIREWIRE_IN_PATH", firewire_path);
167
168         for(int i = 0; i < MAXDEVICES; i++)
169         {
170                 defaults->updatef(oss_enable[i], "R_OSS_ENABLE_%d", i);
171                 defaults->updatef(oss_in_device[i], "R_OSS_IN_DEVICE_%d", i);
172         }
173
174         defaults->update("R_OSS_IN_BITS", oss_in_bits);
175         defaults->update("R_ESOUND_IN_SERVER", esound_in_server);
176         defaults->update("R_PULSE_IN_SERVER", pulse_in_server);
177         defaults->update("R_ESOUND_IN_PORT", esound_in_port);
178         defaults->update("R_PULSE_IN_SERVER", pulse_in_server);
179         defaults->update("R_ALSA_IN_DEVICE", alsa_in_device);
180         defaults->update("R_ALSA_IN_BITS", alsa_in_bits);
181         defaults->update("R_IN_SAMPLERATE", in_samplerate);
182         defaults->update("R_AUDIO_DVB_IN_ADAPTER", dvb_in_adapter);
183         defaults->update("R_AUDIO_DVB_IN_DEVICE", dvb_in_device);
184         defaults->update("R_DVB_IN_BITS", dvb_in_bits);
185         defaults->update("R_V4L2_IN_BITS", v4l2_in_bits);
186         defaults->update("R_IN_CHANNELS", channels);
187         defaults->update("R_FOLLOW_AUDIO", follow_audio);
188         defaults->update("R_AUDIO_IN_MAP51_2", map51_2);
189         defaults->update("R_AUDIO_IN_GAIN", rec_gain);
190         return 0;
191 }
192
193
194
195
196
197
198 const char *VideoInConfig::default_video_device = "/dev/video0";
199
200 VideoInConfig::VideoInConfig()
201 {
202         driver = VIDEO4LINUX2;
203         sprintf(v4l2_in_device, "%s", "/dev/video0");
204         sprintf(v4l2jpeg_in_device, "%s", "/dev/video0");
205         v4l2jpeg_in_fields = 2;
206         sprintf(v4l2mpeg_in_device, "%s", "/dev/video0");
207         strcpy(dvb_in_adapter, "/dev/dvb/adapter0");
208         dvb_in_device = 0;
209         sprintf(screencapture_display, "%s", "");
210         firewire_port = 0;
211         firewire_channel = 63;
212         sprintf(firewire_path, "/dev/raw1394");
213 // number of frames to read from device during video recording.
214 //      capture_length = 15;
215         capture_length = 2;
216         w = 720;
217         h = 480;
218         in_framerate = 29.97;
219         follow_video = 1;
220 }
221
222 VideoInConfig::~VideoInConfig()
223 {
224 }
225
226 const char *VideoInConfig::get_path()
227 {
228         switch(driver) {
229         case CAPTURE_JPEG_WEBCAM:
230         case CAPTURE_YUYV_WEBCAM:
231         case VIDEO4LINUX2: return v4l2_in_device;
232         case VIDEO4LINUX2JPEG: return v4l2jpeg_in_device;
233         case VIDEO4LINUX2MPEG: return v4l2mpeg_in_device;
234         case CAPTURE_DVB: return dvb_in_adapter;
235         }
236         return default_video_device;
237 }
238
239 void VideoInConfig::copy_from(VideoInConfig *src)
240 {
241         driver = src->driver;
242         strcpy(v4l2_in_device, src->v4l2_in_device);
243         v4l2jpeg_in_fields = src->v4l2jpeg_in_fields;
244         strcpy(v4l2jpeg_in_device, src->v4l2jpeg_in_device);
245         strcpy(v4l2mpeg_in_device, src->v4l2mpeg_in_device);
246         strcpy(dvb_in_adapter, src->dvb_in_adapter);
247         dvb_in_device = src->dvb_in_device;
248         strcpy(screencapture_display, src->screencapture_display);
249         firewire_port = src->firewire_port;
250         firewire_channel = src->firewire_channel;
251         strcpy(firewire_path, src->firewire_path);
252         capture_length = src->capture_length;
253         w = src->w;
254         h = src->h;
255         in_framerate = src->in_framerate;
256         follow_video = src->follow_video;
257 }
258
259 VideoInConfig& VideoInConfig::operator=(VideoInConfig &that)
260 {
261         copy_from(&that);
262         return *this;
263 }
264
265 int VideoInConfig::load_defaults(BC_Hash *defaults)
266 {
267         driver = defaults->get("R_VIDEO_IN_DRIVER", driver);
268         defaults->get("R_V4L2_IN_DEVICE", v4l2_in_device);
269         defaults->get("R_V4L2JPEG_IN_DEVICE", v4l2jpeg_in_device);
270         v4l2jpeg_in_fields = defaults->get("R_V4L2JPEG_IN_FIELDS", v4l2jpeg_in_fields);
271         defaults->get("R_V4L2MPEG_IN_DEVICE", v4l2mpeg_in_device);
272         defaults->get("R_VIDEO_DVB_IN_ADAPTER", dvb_in_adapter);
273         dvb_in_device = defaults->get("R_VIDEO_DVB_IN_DEVICE", dvb_in_device);
274         defaults->get("R_SCREENCAPTURE_DISPLAY", screencapture_display);
275         firewire_port = defaults->get("R_VFIREWIRE_IN_PORT", firewire_port);
276         firewire_channel = defaults->get("R_VFIREWIRE_IN_CHANNEL", firewire_channel);
277         defaults->get("R_VFIREWIRE_IN_PATH", firewire_path);
278         capture_length = defaults->get("R_VIDEO_CAPTURE_LENGTH", capture_length);
279         w = defaults->get("RECORD_W", w);
280         h = defaults->get("RECORD_H", h);
281         in_framerate = defaults->get("R_IN_FRAMERATE", in_framerate);
282         follow_video = defaults->get("R_FOLLOW_VIDEO", follow_video);
283         return 0;
284 }
285
286 int VideoInConfig::save_defaults(BC_Hash *defaults)
287 {
288         defaults->update("R_VIDEO_IN_DRIVER", driver);
289         defaults->update("R_V4L2_IN_DEVICE", v4l2_in_device);
290         defaults->update("R_V4L2JPEG_IN_DEVICE", v4l2jpeg_in_device);
291         defaults->update("R_V4L2JPEG_IN_FIELDS", v4l2jpeg_in_fields);
292         defaults->update("R_V4L2MPEG_IN_DEVICE", v4l2mpeg_in_device);
293         defaults->update("R_VIDEO_DVB_IN_ADAPTER", dvb_in_adapter);
294         defaults->update("R_VIDEO_DVB_IN_DEVICE", dvb_in_device);
295         defaults->update("R_SCREENCAPTURE_DISPLAY", screencapture_display);
296         defaults->update("R_VFIREWIRE_IN_PORT", firewire_port);
297         defaults->update("R_VFIREWIRE_IN_CHANNEL", firewire_channel);
298         defaults->update("R_VFIREWIRE_IN_PATH", firewire_path);
299         defaults->update("R_VIDEO_CAPTURE_LENGTH", capture_length);
300         defaults->update("RECORD_W", w);
301         defaults->update("RECORD_H", h);
302         defaults->update("R_IN_FRAMERATE", in_framerate);
303         defaults->update("R_FOLLOW_VIDEO", follow_video);
304         return 0;
305 }
306