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