1 /*****************************************************************************
2 * v4l2.c : Video4Linux2 input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Benjamin Pracht <bigben at videolan dot org>
8 * Richard Hosking <richard at hovis dot net>
9 * Antoine Cellerier <dionoea at videolan d.t org>
10 * Dennis Lou <dlou99 at yahoo dot com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
28 * Sections based on the reference V4L2 capture example at
29 * http://v4l2spec.bytesex.org/spec/capture-example.html
31 * ALSA support based on parts of
32 * http://www.equalarea.com/paul/alsa-audio.html
33 * and hints taken from alsa-utils (aplay/arecord)
34 * http://www.alsa-project.org
37 /*****************************************************************************
39 *****************************************************************************/
45 #include <vlc_common.h>
46 #include <vlc_plugin.h>
47 #include <vlc_access.h>
48 #include <vlc_demux.h>
49 #include <vlc_input.h>
55 #include <sys/ioctl.h>
58 #include <linux/videodev2.h>
60 #include <sys/soundcard.h>
63 # define ALSA_PCM_NEW_HW_PARAMS_API
64 # define ALSA_PCM_NEW_SW_PARAMS_API
65 # include <alsa/asoundlib.h>
70 /*****************************************************************************
72 *****************************************************************************/
74 static int DemuxOpen ( vlc_object_t * );
75 static void DemuxClose( vlc_object_t * );
76 static int AccessOpen ( vlc_object_t * );
77 static void AccessClose( vlc_object_t * );
79 #define DEV_TEXT N_("Device name")
80 #define DEV_LONGTEXT N_( \
81 "Name of the device to use. " \
82 "If you don't specify anything, /dev/video0 will be used.")
83 #define STANDARD_TEXT N_( "Standard" )
84 #define STANDARD_LONGTEXT N_( \
85 "Video standard (Default, SECAM, PAL, or NTSC)." )
86 #define CHROMA_TEXT N_("Video input chroma format")
87 #define CHROMA_LONGTEXT N_( \
88 "Force the Video4Linux2 video device to use a specific chroma format " \
89 "(eg. I420 or I422 for raw images, MJPG for M-JPEG compressed input) " \
90 "(Complete list: GREY, I240, RV16, RV15, RV24, RV32, YUY2, YUYV, UYVY, " \
91 "I41N, I422, I420, I411, I410, MJPG)")
92 #define INPUT_TEXT N_( "Input" )
93 #define INPUT_LONGTEXT N_( \
94 "Input of the card to use (see debug)." )
95 #define AUDIO_INPUT_TEXT N_( "Audio input" )
96 #define AUDIO_INPUT_LONGTEXT N_( \
97 "Audio input of the card to use (see debug)." )
98 #define IOMETHOD_TEXT N_( "IO Method" )
99 #define IOMETHOD_LONGTEXT N_( \
100 "IO Method (READ, MMAP, USERPTR)." )
101 #define WIDTH_TEXT N_( "Width" )
102 #define WIDTH_LONGTEXT N_( \
103 "Force width (-1 for autodetect)." )
104 #define HEIGHT_TEXT N_( "Height" )
105 #define HEIGHT_LONGTEXT N_( \
106 "Force height (-1 for autodetect)." )
107 #define FPS_TEXT N_( "Framerate" )
108 #define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \
109 "(-1 for autodetect)." )
111 #define CTRL_RESET_TEXT N_( "Reset v4l2 controls" )
112 #define CTRL_RESET_LONGTEXT N_( \
113 "Reset controls to defaults provided by the v4l2 driver." )
114 #define BRIGHTNESS_TEXT N_( "Brightness" )
115 #define BRIGHTNESS_LONGTEXT N_( \
116 "Brightness of the video input (if supported by the v4l2 driver)." )
117 #define CONTRAST_TEXT N_( "Contrast" )
118 #define CONTRAST_LONGTEXT N_( \
119 "Contrast of the video input (if supported by the v4l2 driver)." )
120 #define SATURATION_TEXT N_( "Saturation" )
121 #define SATURATION_LONGTEXT N_( \
122 "Saturation of the video input (if supported by the v4l2 driver)." )
123 #define HUE_TEXT N_( "Hue" )
124 #define HUE_LONGTEXT N_( \
125 "Hue of the video input (if supported by the v4l2 driver)." )
126 #define BLACKLEVEL_TEXT N_( "Black level" )
127 #define BLACKLEVEL_LONGTEXT N_( \
128 "Black level of the video input (if supported by the v4l2 driver)." )
129 #define AUTOWHITEBALANCE_TEXT N_( "Auto white balance" )
130 #define AUTOWHITEBALANCE_LONGTEXT N_( \
131 "Automatically set the white balance of the video input " \
132 "(if supported by the v4l2 driver)." )
133 #define DOWHITEBALANCE_TEXT N_( "Do white balance" )
134 #define DOWHITEBALANCE_LONGTEXT N_( \
135 "Trigger a white balancing action, useless if auto white balance is " \
136 "activated (if supported by the v4l2 driver)." )
137 #define REDBALANCE_TEXT N_( "Red balance" )
138 #define REDBALANCE_LONGTEXT N_( \
139 "Red balance of the video input (if supported by the v4l2 driver)." )
140 #define BLUEBALANCE_TEXT N_( "Blue balance" )
141 #define BLUEBALANCE_LONGTEXT N_( \
142 "Blue balance of the video input (if supported by the v4l2 driver)." )
143 #define GAMMA_TEXT N_( "Gamma" )
144 #define GAMMA_LONGTEXT N_( \
145 "Gamma of the video input (if supported by the v4l2 driver)." )
146 #define EXPOSURE_TEXT N_( "Exposure" )
147 #define EXPOSURE_LONGTEXT N_( \
148 "Exposure of the video input (if supported by the v4L2 driver)." )
149 #define AUTOGAIN_TEXT N_( "Auto gain" )
150 #define AUTOGAIN_LONGTEXT N_( \
151 "Automatically set the video input's gain (if supported by the " \
153 #define GAIN_TEXT N_( "Gain" )
154 #define GAIN_LONGTEXT N_( \
155 "Video input's gain (if supported by the v4l2 driver)." )
156 #define HFLIP_TEXT N_( "Horizontal flip" )
157 #define HFLIP_LONGTEXT N_( \
158 "Flip the video horizontally (if supported by the v4l2 driver)." )
159 #define VFLIP_TEXT N_( "Vertical flip" )
160 #define VFLIP_LONGTEXT N_( \
161 "Flip the video vertically (if supported by the v4l2 driver)." )
162 #define HCENTER_TEXT N_( "Horizontal centering" )
163 #define HCENTER_LONGTEXT N_( \
164 "Set the camera's horizontal centering (if supported by the v4l2 driver)." )
165 #define VCENTER_TEXT N_( "Vertical centering" )
166 #define VCENTER_LONGTEXT N_( \
167 "Set the camera's vertical centering (if supported by the v4l2 driver)." )
169 #define ADEV_TEXT N_("Audio device name")
171 #define ADEV_LONGTEXT N_( \
172 "Name of the audio device to use. " \
173 "If you don't specify anything, \"/dev/dsp\" will be used for OSS.")
175 #define ADEV_LONGTEXT N_( \
176 "Name of the audio device to use. " \
177 "If you don't specify anything, \"/dev/dsp\" will be used for OSS, " \
180 #define AUDIO_METHOD_TEXT N_( "Audio method" )
182 #define AUDIO_METHOD_LONGTEXT N_( \
183 "Audio method to use: 0 to disable audio, 1 for OSS." )
185 #define AUDIO_METHOD_LONGTEXT N_( \
186 "Audio method to use: 0 to disable audio, 1 for OSS, 2 for ALSA, " \
187 "3 for ALSA or OSS (ALSA is preferred)." )
189 #define AUDIO_VOLUME_TEXT N_( "Volume" )
190 #define AUDIO_VOLUME_LONGTEXT N_( \
191 "Volume of the audio input (if supported by the v4l2 driver)." )
192 #define AUDIO_BALANCE_TEXT N_( "Balance" )
193 #define AUDIO_BALANCE_LONGTEXT N_( \
194 "Balance of the audio input (if supported by the v4l2 driver)." )
195 #define AUDIO_MUTE_TEXT N_( "Mute" )
196 #define AUDIO_MUTE_LONGTEXT N_( \
197 "Mute audio input (if supported by the v4l2 driver)." )
198 #define AUDIO_BASS_TEXT N_( "Bass" )
199 #define AUDIO_BASS_LONGTEXT N_( \
200 "Bass level of the audio input (if supported by the v4l2 driver)." )
201 #define AUDIO_TREBLE_TEXT N_( "Treble" )
202 #define AUDIO_TREBLE_LONGTEXT N_( \
203 "Treble level of the audio input (if supported by the v4l2 driver)." )
204 #define AUDIO_LOUDNESS_TEXT N_( "Loudness" )
205 #define AUDIO_LOUDNESS_LONGTEXT N_( \
206 "Loudness of the audio input (if supported by the v4l2 driver)." )
208 #define STEREO_TEXT N_( "Stereo" )
209 #define STEREO_LONGTEXT N_( \
210 "Capture the audio stream in stereo." )
211 #define SAMPLERATE_TEXT N_( "Samplerate" )
212 #define SAMPLERATE_LONGTEXT N_( \
213 "Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100, 48000)" )
215 #define CACHING_TEXT N_("Caching value in ms")
216 #define CACHING_LONGTEXT N_( \
217 "Caching value for V4L2 captures. This " \
218 "value should be set in milliseconds." )
219 #define S_CTRLS_TEXT N_("v4l2 driver controls")
220 #define S_CTRLS_LONGTEXT N_( \
221 "Set the v4l2 driver controls to the values specified using a comma " \
222 "separated list optionally encapsulated by curly braces " \
223 "(e.g.: {video_bitrate=6000000,audio_crc=0,stream_type=3} ). " \
224 "To list available controls, increase verbosity (-vvv) " \
225 "or use the v4l2-ctl application." )
227 #define TUNER_TEXT N_("Tuner id")
228 #define TUNER_LONGTEXT N_( \
229 "Tuner id (see debug output)." )
230 #define FREQUENCY_TEXT N_("Frequency")
231 #define FREQUENCY_LONGTEXT N_( \
232 "Tuner frequency in Hz or kHz (see debug output)" )
233 #define TUNER_AUDIO_MODE_TEXT N_("Audio mode")
234 #define TUNER_AUDIO_MODE_LONGTEXT N_( \
235 "Tuner audio mono/stereo and track selection." )
243 static const int i_standards_list[] =
244 { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };
245 static const char *const psz_standards_list_text[] =
246 { N_("Default"), N_("SECAM"), N_("PAL"), N_("NTSC") };
248 static const int i_iomethod_list[] =
249 { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR };
250 static const char *const psz_iomethod_list_text[] =
251 { N_("READ"), N_("MMAP"), N_("USERPTR") };
253 static const int i_tuner_audio_modes_list[] =
254 { V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO,
255 V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2,
256 V4L2_TUNER_MODE_SAP, V4L2_TUNER_MODE_LANG1_LANG2 };
257 static const char *const psz_tuner_audio_modes_list_text[] =
260 N_( "Primary language (Analog TV tuners only)" ),
261 N_( "Secondary language (Analog TV tuners only)" ),
262 N_( "Second audio program (Analog TV tuners only)" ),
263 N_( "Primary language left, Secondary language right" ) };
268 #define AUDIO_METHOD_OSS 1
269 #define OSS_DEFAULT "/dev/dsp"
270 #define AUDIO_METHOD_ALSA 2
271 #define ALSA_DEFAULT "hw"
272 #define CFG_PREFIX "v4l2-"
275 set_shortname( N_("Video4Linux2") );
276 set_description( N_("Video4Linux2 input") );
277 set_category( CAT_INPUT );
278 set_subcategory( SUBCAT_INPUT_ACCESS );
280 set_section( N_( "Video input" ), NULL );
281 add_string( CFG_PREFIX "dev", "/dev/video0", 0, DEV_TEXT, DEV_LONGTEXT,
283 add_integer( CFG_PREFIX "standard", 0, NULL, STANDARD_TEXT,
284 STANDARD_LONGTEXT, false );
285 change_integer_list( i_standards_list, psz_standards_list_text, 0 );
286 add_string( CFG_PREFIX "chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
288 add_integer( CFG_PREFIX "input", 0, NULL, INPUT_TEXT, INPUT_LONGTEXT,
290 add_integer( CFG_PREFIX "audio-input", 0, NULL, AUDIO_INPUT_TEXT,
291 AUDIO_INPUT_LONGTEXT, true );
292 add_integer( CFG_PREFIX "io", IO_METHOD_MMAP, NULL, IOMETHOD_TEXT,
293 IOMETHOD_LONGTEXT, true );
294 change_integer_list( i_iomethod_list, psz_iomethod_list_text, 0 );
295 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
296 WIDTH_LONGTEXT, true );
297 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
298 HEIGHT_LONGTEXT, true );
299 add_float( CFG_PREFIX "fps", 0, NULL, FPS_TEXT, FPS_LONGTEXT, true );
301 set_section( N_( "Audio input" ), NULL );
302 add_string( CFG_PREFIX "adev", NULL, 0, ADEV_TEXT, ADEV_LONGTEXT,
304 add_integer( CFG_PREFIX "audio-method", AUDIO_METHOD_OSS|AUDIO_METHOD_ALSA,
305 NULL, AUDIO_METHOD_TEXT, AUDIO_METHOD_LONGTEXT, true );
306 add_bool( CFG_PREFIX "stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT,
308 add_integer( CFG_PREFIX "samplerate", 48000, NULL, SAMPLERATE_TEXT,
309 SAMPLERATE_LONGTEXT, true );
310 add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL,
311 CACHING_TEXT, CACHING_LONGTEXT, true );
313 set_section( N_( "Tuner" ), NULL );
314 add_integer( CFG_PREFIX "tuner", 0, NULL, TUNER_TEXT, TUNER_LONGTEXT,
316 add_integer( CFG_PREFIX "tuner-frequency", -1, NULL, FREQUENCY_TEXT,
317 FREQUENCY_LONGTEXT, true );
318 add_integer( CFG_PREFIX "tuner-audio-mode", -1, NULL, TUNER_AUDIO_MODE_TEXT,
319 TUNER_AUDIO_MODE_LONGTEXT, true );
320 change_integer_list( i_tuner_audio_modes_list,
321 psz_tuner_audio_modes_list_text, 0 );
323 set_section( N_( "Controls" ),
324 N_( "v4l2 driver controls, if supported by your v4l2 driver." ) );
325 add_bool( CFG_PREFIX "controls-reset", false, NULL, CTRL_RESET_TEXT,
326 CTRL_RESET_LONGTEXT, true );
327 add_integer( CFG_PREFIX "brightness", -1, NULL, BRIGHTNESS_TEXT,
328 BRIGHTNESS_LONGTEXT, true );
329 add_integer( CFG_PREFIX "contrast", -1, NULL, CONTRAST_TEXT,
330 CONTRAST_LONGTEXT, true );
331 add_integer( CFG_PREFIX "saturation", -1, NULL, SATURATION_TEXT,
332 SATURATION_LONGTEXT, true );
333 add_integer( CFG_PREFIX "hue", -1, NULL, HUE_TEXT,
334 HUE_LONGTEXT, true );
335 add_integer( CFG_PREFIX "black-level", -1, NULL, BLACKLEVEL_TEXT,
336 BLACKLEVEL_LONGTEXT, true );
337 add_integer( CFG_PREFIX "auto-white-balance", -1, NULL,
338 AUTOWHITEBALANCE_TEXT, AUTOWHITEBALANCE_LONGTEXT, true );
339 add_integer( CFG_PREFIX "do-white-balance", -1, NULL, DOWHITEBALANCE_TEXT,
340 DOWHITEBALANCE_LONGTEXT, true );
341 add_integer( CFG_PREFIX "red-balance", -1, NULL, REDBALANCE_TEXT,
342 REDBALANCE_LONGTEXT, true );
343 add_integer( CFG_PREFIX "blue-balance", -1, NULL, BLUEBALANCE_TEXT,
344 BLUEBALANCE_LONGTEXT, true );
345 add_integer( CFG_PREFIX "gamma", -1, NULL, GAMMA_TEXT,
346 GAMMA_LONGTEXT, true );
347 add_integer( CFG_PREFIX "exposure", -1, NULL, EXPOSURE_TEXT,
348 EXPOSURE_LONGTEXT, true );
349 add_integer( CFG_PREFIX "autogain", -1, NULL, AUTOGAIN_TEXT,
350 AUTOGAIN_LONGTEXT, true );
351 add_integer( CFG_PREFIX "gain", -1, NULL, GAIN_TEXT,
352 GAIN_LONGTEXT, true );
353 add_integer( CFG_PREFIX "hflip", -1, NULL, HFLIP_TEXT,
354 HFLIP_LONGTEXT, true );
355 add_integer( CFG_PREFIX "vflip", -1, NULL, VFLIP_TEXT,
356 VFLIP_LONGTEXT, true );
357 add_integer( CFG_PREFIX "hcenter", -1, NULL, HCENTER_TEXT,
358 HCENTER_LONGTEXT, true );
359 add_integer( CFG_PREFIX "vcenter", -1, NULL, VCENTER_TEXT,
360 VCENTER_LONGTEXT, true );
361 add_integer( CFG_PREFIX "audio-volume", -1, NULL, AUDIO_VOLUME_TEXT,
362 AUDIO_VOLUME_LONGTEXT, true );
363 add_integer( CFG_PREFIX "audio-balance", -1, NULL, AUDIO_BALANCE_TEXT,
364 AUDIO_BALANCE_LONGTEXT, true );
365 add_bool( CFG_PREFIX "audio-mute", false, NULL, AUDIO_MUTE_TEXT,
366 AUDIO_MUTE_LONGTEXT, true );
367 add_integer( CFG_PREFIX "audio-bass", -1, NULL, AUDIO_BASS_TEXT,
368 AUDIO_BASS_LONGTEXT, true );
369 add_integer( CFG_PREFIX "audio-treble", -1, NULL, AUDIO_TREBLE_TEXT,
370 AUDIO_TREBLE_LONGTEXT, true );
371 add_integer( CFG_PREFIX "audio-loudness", -1, NULL, AUDIO_LOUDNESS_TEXT,
372 AUDIO_LOUDNESS_LONGTEXT, true );
373 add_string( CFG_PREFIX "set-ctrls", NULL, NULL, S_CTRLS_TEXT,
374 S_CTRLS_LONGTEXT, true );
376 add_shortcut( "v4l2" );
377 set_capability( "access_demux", 10 );
378 set_callbacks( DemuxOpen, DemuxClose );
381 add_shortcut( "v4l2c" );
382 set_description( N_("Video4Linux2 Compressed A/V") );
383 set_capability( "access", 0 );
384 /* use these when open as access_demux fails; VLC will use another demux */
385 set_callbacks( AccessOpen, AccessClose );
389 /*****************************************************************************
390 * Access: local prototypes
391 *****************************************************************************/
393 static void CommonClose( vlc_object_t *, demux_sys_t * );
394 static void ParseMRL( demux_sys_t *, char *, vlc_object_t * );
395 static void GetV4L2Params( demux_sys_t *, vlc_object_t * );
396 static void SetAvailControlsByString( vlc_object_t *, demux_sys_t *, int );
398 static int DemuxControl( demux_t *, int, va_list );
399 static int AccessControl( access_t *, int, va_list );
401 static int Demux( demux_t * );
402 static ssize_t AccessRead( access_t *, uint8_t *, size_t );
404 static block_t* GrabVideo( demux_t *p_demux );
405 static block_t* ProcessVideoFrame( demux_t *p_demux, uint8_t *p_frame, size_t );
406 static block_t* GrabAudio( demux_t *p_demux );
408 static bool IsPixelFormatSupported( demux_t *p_demux,
409 unsigned int i_pixelformat );
412 static char* ResolveALSADeviceName( const char *psz_device );
414 static int OpenVideoDev( vlc_object_t *, demux_sys_t *, bool );
415 static int OpenAudioDev( vlc_object_t *, demux_sys_t *, bool );
416 static bool ProbeVideoDev( vlc_object_t *, demux_sys_t *,
418 static bool ProbeAudioDev( vlc_object_t *, demux_sys_t *,
421 static int ControlList( vlc_object_t *, int , bool, bool );
422 static int Control( vlc_object_t *, int i_fd,
423 const char *psz_name, int i_cid, int i_value );
425 static int DemuxControlCallback( vlc_object_t *p_this, const char *psz_var,
426 vlc_value_t oldval, vlc_value_t newval,
428 static int DemuxControlResetCallback( vlc_object_t *p_this, const char *psz_var,
429 vlc_value_t oldval, vlc_value_t newval,
431 static int AccessControlCallback( vlc_object_t *p_this, const char *psz_var,
432 vlc_value_t oldval, vlc_value_t newval,
434 static int AccessControlResetCallback( vlc_object_t *p_this,
435 const char *psz_var, vlc_value_t oldval,
436 vlc_value_t newval, void *p_data );
442 } v4l2chroma_to_fourcc[] =
445 { V4L2_PIX_FMT_GREY, VLC_FOURCC('G','R','E','Y') },
446 { V4L2_PIX_FMT_HI240, VLC_FOURCC('I','2','4','0') },
447 { V4L2_PIX_FMT_RGB565, VLC_FOURCC('R','V','1','6') },
448 { V4L2_PIX_FMT_RGB555, VLC_FOURCC('R','V','1','5') },
449 { V4L2_PIX_FMT_BGR24, VLC_FOURCC('R','V','2','4') },
450 { V4L2_PIX_FMT_BGR32, VLC_FOURCC('R','V','3','2') },
451 { V4L2_PIX_FMT_YUYV, VLC_FOURCC('Y','U','Y','2') },
452 { V4L2_PIX_FMT_YUYV, VLC_FOURCC('Y','U','Y','V') },
453 { V4L2_PIX_FMT_UYVY, VLC_FOURCC('U','Y','V','Y') },
454 { V4L2_PIX_FMT_Y41P, VLC_FOURCC('I','4','1','N') },
455 { V4L2_PIX_FMT_YUV422P, VLC_FOURCC('I','4','2','2') },
456 { V4L2_PIX_FMT_YVU420, VLC_FOURCC('Y','V','1','2') },
457 { V4L2_PIX_FMT_YUV411P, VLC_FOURCC('I','4','1','1') },
458 { V4L2_PIX_FMT_YUV410, VLC_FOURCC('I','4','1','0') },
460 /* Raw data types, not in V4L2 spec but still in videodev2.h and supported
462 { V4L2_PIX_FMT_YUV420, VLC_FOURCC('I','4','2','0') },
463 /* FIXME { V4L2_PIX_FMT_RGB444, VLC_FOURCC('R','V','3','2') }, */
465 /* Compressed data types */
466 { V4L2_PIX_FMT_MJPEG, VLC_FOURCC('M','J','P','G') },
468 { V4L2_PIX_FMT_JPEG, VLC_FOURCC('J','P','E','G') },
469 { V4L2_PIX_FMT_DV, VLC_FOURCC('?','?','?','?') },
470 { V4L2_PIX_FMT_MPEG, VLC_FOURCC('?','?','?','?') },
476 * List of V4L2 chromas were confident enough to use as fallbacks if the
477 * user hasn't provided a --v4l2-chroma value.
479 static const __u32 p_chroma_fallbacks[] =
480 { V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV422P,
481 V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_MJPEG };
485 const char *psz_name;
489 { "brightness", V4L2_CID_BRIGHTNESS },
490 { "contrast", V4L2_CID_CONTRAST },
491 { "saturation", V4L2_CID_SATURATION },
492 { "hue", V4L2_CID_HUE },
493 { "audio-volume", V4L2_CID_AUDIO_VOLUME },
494 { "audio-balance", V4L2_CID_AUDIO_BALANCE },
495 { "audio-bass", V4L2_CID_AUDIO_BASS },
496 { "audio-treble", V4L2_CID_AUDIO_TREBLE },
497 { "audio-mute", V4L2_CID_AUDIO_MUTE },
498 { "audio-loudness", V4L2_CID_AUDIO_LOUDNESS },
499 { "black-level", V4L2_CID_BLACK_LEVEL },
500 { "auto-white-balance", V4L2_CID_AUTO_WHITE_BALANCE },
501 { "do-white-balance", V4L2_CID_DO_WHITE_BALANCE },
502 { "red-balance", V4L2_CID_RED_BALANCE },
503 { "blue-balance", V4L2_CID_BLUE_BALANCE },
504 { "gamma", V4L2_CID_GAMMA },
505 { "exposure", V4L2_CID_EXPOSURE },
506 { "autogain", V4L2_CID_AUTOGAIN },
507 { "gain", V4L2_CID_GAIN },
508 { "hflip", V4L2_CID_HFLIP },
509 { "vflip", V4L2_CID_VFLIP },
510 { "hcenter", V4L2_CID_HCENTER },
511 { "vcenter", V4L2_CID_VCENTER },
523 char *psz_device; /* Main device from MRL, can be video or audio */
531 char *psz_requested_chroma;
538 struct v4l2_capability dev_cap;
541 struct v4l2_input *p_inputs;
542 int i_selected_input;
545 struct v4l2_standard *p_standards;
546 v4l2_std_id i_selected_standard_id;
549 /* V4L2 devices cannot have more than 32 audio inputs */
550 struct v4l2_audio p_audios[32];
551 int i_selected_audio_input;
554 struct v4l2_tuner *p_tuners;
557 struct v4l2_fmtdesc *p_codecs;
559 struct buffer_t *p_buffers;
560 unsigned int i_nbuffers;
564 float f_fps; /* <= 0.0 mean to grab at full rate */
565 mtime_t i_video_pts; /* only used when f_fps > 0 */
568 es_out_id_t *p_es_video;
571 unsigned int i_sample_rate;
573 size_t i_audio_max_frame_size;
574 block_t *p_block_audio;
575 es_out_id_t *p_es_audio;
581 snd_pcm_t *p_alsa_pcm;
582 size_t i_alsa_frame_size;
583 int i_alsa_chunk_size;
595 static int FindMainDevice( vlc_object_t *p_this, demux_sys_t *p_sys,
596 int i_flags, bool b_demux,
599 /* Find main device (video or audio) */
600 if( p_sys->psz_device && *p_sys->psz_device )
602 msg_Dbg( p_this, "main device='%s'", p_sys->psz_device );
604 bool b_maindevice_is_video = false;
606 /* Try to open as video device */
607 if( i_flags & FIND_VIDEO )
609 msg_Dbg( p_this, "trying device '%s' as video", p_sys->psz_device );
610 if( ProbeVideoDev( p_this, p_sys, p_sys->psz_device ) )
612 msg_Dbg( p_this, "'%s' is a video device", p_sys->psz_device );
613 /* Device was a video device */
614 free( p_sys->psz_vdev );
615 p_sys->psz_vdev = p_sys->psz_device;
616 p_sys->psz_device = NULL;
617 p_sys->i_fd_video = OpenVideoDev( p_this, p_sys, b_demux );
618 if( p_sys->i_fd_video < 0 )
620 b_maindevice_is_video = true;
621 /* If successful we carry on to try the audio if access is forced */
625 /* Try to open as audio device only if main device was not detected as video above */
626 if( i_flags & FIND_AUDIO && !b_maindevice_is_video )
628 msg_Dbg( p_this, "trying device '%s' as audio", p_sys->psz_device );
629 if( ProbeAudioDev( p_this, p_sys, p_sys->psz_device ) )
631 msg_Dbg( p_this, "'%s' is an audio device", p_sys->psz_device );
632 /* Device was an audio device */
633 free( p_sys->psz_adev );
634 p_sys->psz_adev = p_sys->psz_device;
635 p_sys->psz_device = NULL;
636 p_sys->i_fd_audio = OpenAudioDev( p_this, p_sys, b_demux );
637 if( p_sys->i_fd_audio < 0 )
639 /* If successful we carry on to try the video if access is forced */
644 /* If no device opened, only continue if the access was forced */
645 if( b_forced == false
646 && !( ( i_flags & FIND_VIDEO && p_sys->i_fd_video >= 0 )
647 || ( i_flags & FIND_AUDIO && p_sys->i_fd_audio >= 0 ) ) )
652 /* Find video device */
653 if( i_flags & FIND_VIDEO && p_sys->i_fd_video < 0 )
655 if( !p_sys->psz_vdev || !*p_sys->psz_vdev )
657 free( p_sys->psz_vdev );
658 p_sys->psz_vdev = var_CreateGetString( p_this, "v4l2-dev" );
661 msg_Dbg( p_this, "opening '%s' as video", p_sys->psz_vdev );
662 if( p_sys->psz_vdev && *p_sys->psz_vdev
663 && ProbeVideoDev( p_this, p_sys, p_sys->psz_vdev ) )
665 p_sys->i_fd_video = OpenVideoDev( p_this, p_sys, b_demux );
669 /* Find audio device */
670 if( i_flags & FIND_AUDIO && p_sys->i_fd_audio < 0 )
672 if( !p_sys->psz_adev )
674 p_sys->psz_adev = var_CreateGetNonEmptyString( p_this, "v4l2-adev" );
677 msg_Dbg( p_this, "opening '%s' as audio", p_sys->psz_adev );
678 if( ProbeAudioDev( p_this, p_sys, p_sys->psz_adev ) )
680 p_sys->i_fd_audio = OpenAudioDev( p_this, p_sys, b_demux );
684 if( !( ( i_flags & FIND_VIDEO && p_sys->i_fd_video >= 0 )
685 || ( i_flags & FIND_AUDIO && p_sys->i_fd_audio >= 0 ) ) )
692 /*****************************************************************************
693 * DemuxOpen: opens v4l2 device, access_demux callback
694 *****************************************************************************
696 * url: <video device>::::
698 *****************************************************************************/
699 static int DemuxOpen( vlc_object_t *p_this )
701 demux_t *p_demux = (demux_t*)p_this;
704 /* Only when selected */
705 if( *p_demux->psz_access == '\0' ) return VLC_EGENERIC;
708 p_demux->pf_control = DemuxControl;
709 p_demux->pf_demux = Demux;
710 p_demux->info.i_update = 0;
711 p_demux->info.i_title = 0;
712 p_demux->info.i_seekpoint = 0;
714 p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
715 if( p_sys == NULL ) return VLC_ENOMEM;
717 GetV4L2Params(p_sys, (vlc_object_t *) p_demux);
719 ParseMRL( p_sys, p_demux->psz_path, (vlc_object_t *) p_demux );
722 /* Alsa support available? */
723 msg_Dbg( p_demux, "ALSA input support available" );
726 if( FindMainDevice( p_this, p_sys, FIND_VIDEO|FIND_AUDIO,
727 true, !strncmp( p_demux->psz_access, "v4l2", 4 ) ) != VLC_SUCCESS )
729 DemuxClose( p_this );
736 /*****************************************************************************
737 * GetV4L2Params: fill in p_sys parameters (shared by DemuxOpen and AccessOpen)
738 *****************************************************************************/
739 static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj )
741 p_sys->i_video_pts = -1;
743 p_sys->i_selected_standard_id =
744 i_standards_list[var_CreateGetInteger( p_obj, "v4l2-standard" )];
746 p_sys->i_selected_input = var_CreateGetInteger( p_obj, "v4l2-input" );
747 p_sys->i_selected_audio_input =
748 var_CreateGetInteger( p_obj, "v4l2-audio-input" );
750 p_sys->io = var_CreateGetInteger( p_obj, "v4l2-io" );
752 p_sys->i_width = var_CreateGetInteger( p_obj, "v4l2-width" );
753 p_sys->i_height = var_CreateGetInteger( p_obj, "v4l2-height" );
755 var_CreateGetBool( p_obj, "v4l2-controls-reset" );
757 p_sys->f_fps = var_CreateGetFloat( p_obj, "v4l2-fps" );
758 p_sys->i_sample_rate = var_CreateGetInteger( p_obj, "v4l2-samplerate" );
759 p_sys->psz_requested_chroma = var_CreateGetString( p_obj, "v4l2-chroma" );
761 p_sys->i_audio_method = var_CreateGetInteger( p_obj, "v4l2-audio-method" );
763 p_sys->b_stereo = var_CreateGetBool( p_obj, "v4l2-stereo" );
765 p_sys->i_pts = var_CreateGetInteger( p_obj, "v4l2-caching" );
767 p_sys->i_cur_tuner = var_CreateGetInteger( p_obj, "v4l2-tuner" );
768 p_sys->i_frequency = var_CreateGetInteger( p_obj, "v4l2-tuner-frequency" );
769 p_sys->i_audio_mode = var_CreateGetInteger( p_obj, "v4l2-tuner-audio-mode" );
771 p_sys->psz_set_ctrls = var_CreateGetString( p_obj, "v4l2-set-ctrls" );
773 p_sys->psz_device = p_sys->psz_vdev = p_sys->psz_adev = NULL;
774 p_sys->i_fd_video = -1;
775 p_sys->i_fd_audio = -1;
777 p_sys->p_es_video = p_sys->p_es_audio = 0;
778 p_sys->p_block_audio = 0;
781 /*****************************************************************************
782 * ParseMRL: parse the options contained in the MRL
783 *****************************************************************************/
784 static void ParseMRL( demux_sys_t *p_sys, char *psz_path, vlc_object_t *p_obj )
786 char *psz_dup = strdup( psz_path );
787 char *psz_parser = psz_dup;
789 while( *psz_parser && *psz_parser != ':' )
794 if( *psz_parser == ':' )
799 *psz_parser++ = '\0';
801 if( !strncmp( psz_parser, "adev=", strlen( "adev=" ) ) )
805 psz_parser += strlen( "adev=" );
806 if( strchr( psz_parser, ':' ) )
808 i_len = strchr( psz_parser, ':' ) - psz_parser;
812 i_len = strlen( psz_parser );
815 p_sys->psz_adev = strndup( psz_parser, i_len );
816 if( !*p_sys->psz_adev )
818 free( p_sys->psz_adev );
819 p_sys->psz_adev = NULL;
824 else if( !strncmp( psz_parser, "standard=", strlen( "standard=" ) ) )
826 psz_parser += strlen( "standard=" );
827 if( !strncmp( psz_parser, "pal", strlen( "pal" ) ) )
829 p_sys->i_selected_standard_id = V4L2_STD_PAL;
830 psz_parser += strlen( "pal" );
832 else if( !strncmp( psz_parser, "ntsc", strlen( "ntsc" ) ) )
834 p_sys->i_selected_standard_id = V4L2_STD_NTSC;
835 psz_parser += strlen( "ntsc" );
837 else if( !strncmp( psz_parser, "secam", strlen( "secam" ) ) )
839 p_sys->i_selected_standard_id = V4L2_STD_SECAM;
840 psz_parser += strlen( "secam" );
842 else if( !strncmp( psz_parser, "default", strlen( "default" ) ) )
844 p_sys->i_selected_standard_id = V4L2_STD_UNKNOWN;
845 psz_parser += strlen( "default" );
849 p_sys->i_selected_standard_id = i_standards_list[strtol( psz_parser, &psz_parser, 0 )];
852 else if( !strncmp( psz_parser, "chroma=", strlen( "chroma=" ) ) )
856 psz_parser += strlen( "chroma=" );
857 if( strchr( psz_parser, ':' ) )
859 i_len = strchr( psz_parser, ':' ) - psz_parser;
863 i_len = strlen( psz_parser );
866 free( p_sys->psz_requested_chroma );
867 p_sys->psz_requested_chroma = strndup( psz_parser, i_len );
871 else if( !strncmp( psz_parser, "input=", strlen( "input=" ) ) )
873 p_sys->i_selected_input = strtol( psz_parser + strlen( "input=" ),
876 else if( !strncmp( psz_parser, "audio-input=", strlen( "audio-input=" ) ) )
878 p_sys->i_selected_audio_input = strtol( psz_parser + strlen( "audio-input=" ),
881 else if( !strncmp( psz_parser, "fps=", strlen( "fps=" ) ) )
883 p_sys->f_fps = strtof( psz_parser + strlen( "fps=" ),
886 else if( !strncmp( psz_parser, "io=", strlen( "io=" ) ) )
888 psz_parser += strlen( "io=" );
889 if( !strncmp( psz_parser, "read", strlen( "read" ) ) )
891 p_sys->io = IO_METHOD_READ;
892 psz_parser += strlen( "read" );
894 else if( !strncmp( psz_parser, "mmap", strlen( "mmap" ) ) )
896 p_sys->io = IO_METHOD_MMAP;
897 psz_parser += strlen( "mmap" );
899 else if( !strncmp( psz_parser, "userptr", strlen( "userptr" ) ) )
901 p_sys->io = IO_METHOD_USERPTR;
902 psz_parser += strlen( "userptr" );
906 p_sys->io = strtol( psz_parser, &psz_parser, 0 );
909 else if( !strncmp( psz_parser, "width=",
910 strlen( "width=" ) ) )
913 strtol( psz_parser + strlen( "width=" ),
916 else if( !strncmp( psz_parser, "height=",
917 strlen( "height=" ) ) )
920 strtol( psz_parser + strlen( "height=" ),
923 else if( !strncmp( psz_parser, "controls-reset",
924 strlen( "controls-reset" ) ) )
926 var_SetBool( p_obj, "v4l2-controls-reset", true );
927 psz_parser += strlen( "controls-reset" );
930 else if( !strncmp( psz_parser, "brightness=",
931 strlen( "brightness=" ) ) )
933 var_SetInteger( p_obj, "brightness",
934 strtol( psz_parser + strlen( "brightness=" ),
937 else if( !strncmp( psz_parser, "contrast=",
938 strlen( "contrast=" ) ) )
940 var_SetInteger( p_obj, "contrast",
941 strtol( psz_parser + strlen( "contrast=" ),
944 else if( !strncmp( psz_parser, "saturation=",
945 strlen( "saturation=" ) ) )
947 var_SetInteger( p_obj, "saturation",
948 strtol( psz_parser + strlen( "saturation=" ),
951 else if( !strncmp( psz_parser, "hue=",
954 var_SetInteger( p_obj, "hue",
955 strtol( psz_parser + strlen( "hue=" ),
958 else if( !strncmp( psz_parser, "gamma=",
959 strlen( "gamma=" ) ) )
961 var_SetInteger( p_obj, "gamma",
962 strtol( psz_parser + strlen( "gamma=" ),
966 else if( !strncmp( psz_parser, "samplerate=",
967 strlen( "samplerate=" ) ) )
969 p_sys->i_sample_rate =
970 strtol( psz_parser + strlen( "samplerate=" ),
973 else if( !strncmp( psz_parser, "audio-method", strlen( "audio-method" ) ) )
975 p_sys->i_audio_method =
976 strtol( psz_parser + strlen( "audio-method" ),
979 else if( !strncmp( psz_parser, "stereo", strlen( "stereo" ) ) )
981 psz_parser += strlen( "stereo" );
982 p_sys->b_stereo = true;
984 else if( !strncmp( psz_parser, "mono", strlen( "mono" ) ) )
986 psz_parser += strlen( "mono" );
987 p_sys->b_stereo = false;
989 else if( !strncmp( psz_parser, "caching=", strlen( "caching=" ) ) )
991 p_sys->i_pts = strtol( psz_parser + strlen( "caching=" ),
994 else if( !strncmp( psz_parser, "tuner=", strlen( "tuner=" ) ) )
996 p_sys->i_cur_tuner = strtol( psz_parser + strlen( "tuner=" ),
999 else if( !strncmp( psz_parser, "tuner-frequency=", strlen( "tuner-frequency=" ) ) )
1001 p_sys->i_frequency = strtol( psz_parser
1002 + strlen( "tuner-frequency=" ),
1005 else if( !strncmp( psz_parser, "tuner-audio-mode=", strlen( "tuner-audio-mode=" ) ) )
1007 p_sys->i_audio_mode = strtol( psz_parser
1008 + strlen( "tuner-audio-mode=" ),
1011 else if( !strncmp( psz_parser, "set-ctrls=", strlen( "set-ctrls=" )) )
1015 psz_parser += strlen( "set-ctrls=" );
1016 if( strchr( psz_parser, ':' ) )
1018 i_len = strchr( psz_parser, ':' ) - psz_parser;
1022 i_len = strlen( psz_parser );
1025 p_sys->psz_set_ctrls = strndup( psz_parser, i_len );
1027 psz_parser += i_len;
1031 char *psz_unk = strchr( psz_parser, ':' );
1033 psz_unk = strndup( psz_parser, psz_unk - psz_parser );
1035 psz_unk = strdup( psz_parser);
1036 msg_Warn( p_obj, "unknown option %s", psz_unk );
1040 while( *psz_parser && *psz_parser != ':' )
1045 if( *psz_parser == '\0' )
1055 p_sys->psz_device = strdup( psz_dup );
1060 /*****************************************************************************
1061 * Close: close device, free resources
1062 *****************************************************************************/
1063 static void AccessClose( vlc_object_t *p_this )
1065 access_t *p_access = (access_t *)p_this;
1066 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
1068 CommonClose( p_this, p_sys );
1071 static void DemuxClose( vlc_object_t *p_this )
1073 struct v4l2_buffer buf;
1074 enum v4l2_buf_type buf_type;
1077 demux_t *p_demux = (demux_t *)p_this;
1078 demux_sys_t *p_sys = p_demux->p_sys;
1080 /* Stop video capture */
1081 if( p_sys->i_fd_video >= 0 )
1085 case IO_METHOD_READ:
1089 case IO_METHOD_MMAP:
1090 case IO_METHOD_USERPTR:
1091 /* Some drivers 'hang' internally if this is not done before streamoff */
1092 for( unsigned int i = 0; i < p_sys->i_nbuffers; i++ )
1094 memset( &buf, 0, sizeof(buf) );
1095 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1096 buf.memory = ( p_sys->io == IO_METHOD_USERPTR ) ?
1097 V4L2_MEMORY_USERPTR : V4L2_MEMORY_MMAP;
1098 ioctl( p_sys->i_fd_video, VIDIOC_DQBUF, &buf ); /* ignore result */
1101 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1102 if( ioctl( p_sys->i_fd_video, VIDIOC_STREAMOFF, &buf_type ) < 0 ) {
1103 msg_Err( p_this, "VIDIOC_STREAMOFF failed" );
1110 /* Free Video Buffers */
1111 if( p_sys->p_buffers ) {
1114 case IO_METHOD_READ:
1115 free( p_sys->p_buffers[0].start );
1118 case IO_METHOD_MMAP:
1119 for( i = 0; i < p_sys->i_nbuffers; ++i )
1121 if( munmap( p_sys->p_buffers[i].start, p_sys->p_buffers[i].length ) )
1123 msg_Err( p_this, "munmap failed" );
1128 case IO_METHOD_USERPTR:
1129 for( i = 0; i < p_sys->i_nbuffers; ++i )
1131 free( p_sys->p_buffers[i].start );
1135 free( p_sys->p_buffers );
1138 CommonClose( p_this, p_sys );
1141 static void CommonClose( vlc_object_t *p_this, demux_sys_t *p_sys )
1144 if( p_sys->i_fd_video >= 0 ) close( p_sys->i_fd_video );
1146 if( p_sys->p_alsa_pcm )
1148 snd_pcm_close( p_sys->p_alsa_pcm );
1149 p_sys->i_fd_audio = -1;
1152 if( p_sys->i_fd_audio >= 0 ) close( p_sys->i_fd_audio );
1154 if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio );
1155 free( p_sys->psz_device );
1156 free( p_sys->psz_vdev );
1157 free( p_sys->psz_adev );
1158 free( p_sys->p_standards );
1159 free( p_sys->p_inputs );
1160 free( p_sys->p_tuners );
1161 free( p_sys->p_codecs );
1162 free( p_sys->psz_requested_chroma );
1163 free( p_sys->psz_set_ctrls );
1168 /*****************************************************************************
1169 * AccessOpen: opens v4l2 device, access callback
1170 *****************************************************************************
1172 * url: <video device>::::
1174 *****************************************************************************/
1175 static int AccessOpen( vlc_object_t * p_this )
1177 access_t *p_access = (access_t*) p_this;
1178 demux_sys_t * p_sys;
1180 /* Only when selected */
1181 if( *p_access->psz_access == '\0' ) return VLC_EGENERIC;
1183 p_access->pf_read = AccessRead;
1184 p_access->pf_block = NULL;
1185 p_access->pf_seek = NULL;
1186 p_access->pf_control = AccessControl;
1187 p_access->info.i_update = 0;
1188 p_access->info.i_size = 0;
1189 p_access->info.i_pos = 0;
1190 p_access->info.b_eof = false;
1191 p_access->info.i_title = 0;
1192 p_access->info.i_seekpoint = 0;
1194 p_sys = calloc( 1, sizeof( demux_sys_t ) );
1195 p_access->p_sys = (access_sys_t *) p_sys;
1196 if( p_sys == NULL ) return VLC_ENOMEM;
1198 GetV4L2Params( p_sys, (vlc_object_t *) p_access );
1200 ParseMRL( p_sys, p_access->psz_path, (vlc_object_t *) p_access );
1202 if( FindMainDevice( p_this, p_sys, FIND_VIDEO,
1203 false, !strncmp( p_access->psz_access, "v4l2", 4 ) ) != VLC_SUCCESS )
1205 AccessClose( p_this );
1206 return VLC_EGENERIC;
1212 /*****************************************************************************
1214 *****************************************************************************/
1215 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
1217 demux_sys_t *p_sys = p_demux->p_sys;
1223 /* Special for access_demux */
1224 case DEMUX_CAN_PAUSE:
1225 case DEMUX_CAN_SEEK:
1226 case DEMUX_SET_PAUSE_STATE:
1227 case DEMUX_CAN_CONTROL_PACE:
1228 pb = (bool*)va_arg( args, bool * );
1232 case DEMUX_GET_PTS_DELAY:
1233 pi64 = (int64_t*)va_arg( args, int64_t * );
1234 *pi64 = (int64_t)p_sys->i_pts * 1000;
1237 case DEMUX_GET_TIME:
1238 pi64 = (int64_t*)va_arg( args, int64_t * );
1242 /* TODO implement others */
1244 return VLC_EGENERIC;
1247 return VLC_EGENERIC;
1250 /*****************************************************************************
1251 * AccessControl: access callback
1252 *****************************************************************************/
1253 static int AccessControl( access_t *p_access, int i_query, va_list args )
1258 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
1263 case ACCESS_CAN_SEEK:
1264 case ACCESS_CAN_FASTSEEK:
1265 pb_bool = (bool*)va_arg( args, bool* );
1268 case ACCESS_CAN_PAUSE:
1269 pb_bool = (bool*)va_arg( args, bool* );
1272 case ACCESS_CAN_CONTROL_PACE:
1273 pb_bool = (bool*)va_arg( args, bool* );
1278 case ACCESS_GET_MTU:
1279 pi_int = (int*)va_arg( args, int * );
1283 case ACCESS_GET_PTS_DELAY:
1284 pi_64 = (int64_t*)va_arg( args, int64_t * );
1285 *pi_64 = (int64_t) p_sys->i_pts * 1000;
1289 case ACCESS_SET_PAUSE_STATE:
1293 case ACCESS_GET_TITLE_INFO:
1294 case ACCESS_SET_TITLE:
1295 case ACCESS_SET_SEEKPOINT:
1296 case ACCESS_SET_PRIVATE_ID_STATE:
1297 case ACCESS_GET_CONTENT_TYPE:
1298 case ACCESS_GET_META:
1299 return VLC_EGENERIC;
1302 msg_Warn( p_access, "Unimplemented query in control(%d).", i_query);
1303 return VLC_EGENERIC;
1309 /*****************************************************************************
1310 * AccessRead: access callback
1311 ******************************************************************************/
1312 static ssize_t AccessRead( access_t * p_access, uint8_t * p_buffer, size_t i_len )
1314 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
1318 ufd.fd = p_sys->i_fd_video;
1319 ufd.events = POLLIN;
1321 if( p_access->info.b_eof )
1326 if( !vlc_object_alive (p_access) )
1331 while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );
1335 msg_Err( p_access, "Polling error (%m)." );
1339 i_ret = read( p_sys->i_fd_video, p_buffer, i_len );
1342 p_access->info.b_eof = true;
1344 else if( i_ret > 0 )
1346 p_access->info.i_pos += i_ret;
1352 /*****************************************************************************
1353 * Demux: Processes the audio or video frame
1354 *****************************************************************************/
1355 static int Demux( demux_t *p_demux )
1357 demux_sys_t *p_sys = p_demux->p_sys;
1358 es_out_id_t *p_es = p_sys->p_es_audio;
1359 block_t *p_block = NULL;
1361 /* Try grabbing audio frames first */
1362 if( p_sys->i_fd_audio < 0 || !( p_block = GrabAudio( p_demux ) ) )
1364 /* Try grabbing video frame */
1365 p_es = p_sys->p_es_video;
1366 if( p_sys->i_fd_video > 0 ) p_block = GrabVideo( p_demux );
1371 /* Sleep so we do not consume all the cpu, 10ms seems
1372 * like a good value (100fps) */
1377 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
1378 es_out_Send( p_demux->out, p_es, p_block );
1383 /*****************************************************************************
1384 * GrabVideo: Grab a video frame
1385 *****************************************************************************/
1386 static block_t* GrabVideo( demux_t *p_demux )
1388 demux_sys_t *p_sys = p_demux->p_sys;
1390 block_t *p_block = NULL;
1391 struct v4l2_buffer buf;
1394 if( p_sys->f_fps >= 0.1 && p_sys->i_video_pts > 0 )
1396 mtime_t i_dur = (mtime_t)((double)1000000 / (double)p_sys->f_fps);
1398 /* Did we wait long enough ? (frame rate reduction) */
1399 if( p_sys->i_video_pts + i_dur > mdate() ) return 0;
1402 /* Grab Video Frame */
1405 case IO_METHOD_READ:
1406 i_ret = read( p_sys->i_fd_video, p_sys->p_buffers[0].start, p_sys->p_buffers[0].length );
1414 /* Could ignore EIO, see spec. */
1417 msg_Err( p_demux, "Failed to read frame" );
1422 p_block = ProcessVideoFrame( p_demux, (uint8_t*)p_sys->p_buffers[0].start, i_ret );
1423 if( !p_block ) return 0;
1427 case IO_METHOD_MMAP:
1428 memset( &buf, 0, sizeof(buf) );
1429 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1430 buf.memory = V4L2_MEMORY_MMAP;
1432 /* Wait for next frame */
1433 if (ioctl( p_sys->i_fd_video, VIDIOC_DQBUF, &buf ) < 0 )
1440 /* Could ignore EIO, see spec. */
1443 msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" );
1448 if( buf.index >= p_sys->i_nbuffers ) {
1449 msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" );
1453 p_block = ProcessVideoFrame( p_demux, p_sys->p_buffers[buf.index].start, buf.bytesused );
1454 if( !p_block ) return 0;
1457 if( ioctl( p_sys->i_fd_video, VIDIOC_QBUF, &buf ) < 0 )
1459 msg_Err (p_demux, "Failed to unlock (VIDIOC_QBUF)");
1465 case IO_METHOD_USERPTR:
1466 memset( &buf, 0, sizeof(buf) );
1467 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1468 buf.memory = V4L2_MEMORY_USERPTR;
1470 /* Wait for next frame */
1471 if (ioctl( p_sys->i_fd_video, VIDIOC_DQBUF, &buf ) < 0 )
1478 /* Could ignore EIO, see spec. */
1481 msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" );
1488 for( i = 0; i < p_sys->i_nbuffers; i++ )
1490 if( buf.m.userptr == (unsigned long)p_sys->p_buffers[i].start &&
1491 buf.length == p_sys->p_buffers[i].length ) break;
1494 if( i >= p_sys->i_nbuffers )
1496 msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" );
1500 p_block = ProcessVideoFrame( p_demux, (uint8_t*)buf.m.userptr, buf.bytesused );
1501 if( !p_block ) return 0;
1504 if( ioctl( p_sys->i_fd_video, VIDIOC_QBUF, &buf ) < 0 )
1506 msg_Err (p_demux, "Failed to unlock (VIDIOC_QBUF)");
1515 p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate();
1520 /*****************************************************************************
1521 * ProcessVideoFrame: Helper function to take a buffer and copy it into
1523 *****************************************************************************/
1524 static block_t* ProcessVideoFrame( demux_t *p_demux, uint8_t *p_frame, size_t i_size )
1528 if( !p_frame ) return 0;
1531 if( !( p_block = block_New( p_demux, i_size ) ) )
1533 msg_Warn( p_demux, "Cannot get new block" );
1538 memcpy( p_block->p_buffer, p_frame, i_size );
1543 /*****************************************************************************
1544 * GrabAudio: Grab an audio frame
1545 *****************************************************************************/
1546 static block_t* GrabAudio( demux_t *p_demux )
1548 demux_sys_t *p_sys = p_demux->p_sys;
1549 struct audio_buf_info buf_info;
1550 int i_read = 0, i_correct;
1553 if( p_sys->p_block_audio ) p_block = p_sys->p_block_audio;
1554 else p_block = block_New( p_demux, p_sys->i_audio_max_frame_size );
1558 msg_Warn( p_demux, "cannot get block" );
1562 p_sys->p_block_audio = p_block;
1565 if( p_sys->i_audio_method & AUDIO_METHOD_ALSA )
1568 i_read = snd_pcm_readi( p_sys->p_alsa_pcm, p_block->p_buffer, p_sys->i_alsa_chunk_size );
1578 snd_pcm_prepare( p_sys->p_alsa_pcm );
1582 i_resume = snd_pcm_resume( p_sys->p_alsa_pcm );
1583 if( i_resume < 0 && i_resume != -EAGAIN ) snd_pcm_prepare( p_sys->p_alsa_pcm );
1586 msg_Err( p_demux, "Failed to read alsa frame (%s)", snd_strerror( i_read ) );
1592 /* convert from frames to bytes */
1593 i_read *= p_sys->i_alsa_frame_size;
1598 if( p_sys->i_audio_method & AUDIO_METHOD_OSS )
1601 i_read = read( p_sys->i_fd_audio, p_block->p_buffer,
1602 p_sys->i_audio_max_frame_size );
1605 if( i_read <= 0 ) return 0;
1607 p_block->i_buffer = i_read;
1608 p_sys->p_block_audio = 0;
1610 /* Correct the date because of kernel buffering */
1612 if( p_sys->i_audio_method & AUDIO_METHOD_OSS )
1615 if( ioctl( p_sys->i_fd_audio, SNDCTL_DSP_GETISPACE, &buf_info ) == 0 )
1617 i_correct += buf_info.bytes;
1621 else if( p_sys->i_audio_method & AUDIO_METHOD_ALSA )
1625 snd_pcm_sframes_t delay = 0;
1626 if( ( i_err = snd_pcm_delay( p_sys->p_alsa_pcm, &delay ) ) >= 0 )
1628 size_t i_correction_delta = delay * p_sys->i_alsa_frame_size;
1629 /* Test for overrun */
1630 if( i_correction_delta > p_sys->i_audio_max_frame_size )
1632 msg_Warn( p_demux, "ALSA read overrun (%zu > %zu)",
1633 i_correction_delta, p_sys->i_audio_max_frame_size );
1634 i_correction_delta = p_sys->i_audio_max_frame_size;
1635 snd_pcm_prepare( p_sys->p_alsa_pcm );
1637 i_correct += i_correction_delta;
1641 /* delay failed so reset */
1642 msg_Warn( p_demux, "ALSA snd_pcm_delay failed (%s)", snd_strerror( i_err ) );
1643 snd_pcm_prepare( p_sys->p_alsa_pcm );
1649 p_block->i_pts = p_block->i_dts =
1650 mdate() - INT64_C(1000000) * (mtime_t)i_correct /
1651 2 / ( p_sys->b_stereo ? 2 : 1) / p_sys->i_sample_rate;
1656 /*****************************************************************************
1657 * Helper function to initalise video IO using the Read method
1658 *****************************************************************************/
1659 static int InitRead( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
1661 demux_sys_t *p_sys = p_demux->p_sys;
1663 p_sys->p_buffers = calloc( 1, sizeof( *p_sys->p_buffers ) );
1664 if( !p_sys->p_buffers )
1667 p_sys->p_buffers[0].length = i_buffer_size;
1668 p_sys->p_buffers[0].start = malloc( i_buffer_size );
1669 if( !p_sys->p_buffers[0].start )
1675 return VLC_EGENERIC;
1679 /*****************************************************************************
1680 * Helper function to initalise video IO using the mmap method
1681 *****************************************************************************/
1682 static int InitMmap( demux_t *p_demux, int i_fd )
1684 demux_sys_t *p_sys = p_demux->p_sys;
1685 struct v4l2_requestbuffers req;
1687 memset( &req, 0, sizeof(req) );
1689 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1690 req.memory = V4L2_MEMORY_MMAP;
1692 if( ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
1694 msg_Err( p_demux, "device does not support mmap i/o" );
1700 msg_Err( p_demux, "Insufficient buffer memory" );
1704 p_sys->p_buffers = calloc( req.count, sizeof( *p_sys->p_buffers ) );
1705 if( !p_sys->p_buffers )
1707 msg_Err( p_demux, "Out of memory" );
1711 for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < req.count; ++p_sys->i_nbuffers )
1713 struct v4l2_buffer buf;
1715 memset( &buf, 0, sizeof(buf) );
1716 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1717 buf.memory = V4L2_MEMORY_MMAP;
1718 buf.index = p_sys->i_nbuffers;
1720 if( ioctl( i_fd, VIDIOC_QUERYBUF, &buf ) < 0 )
1722 msg_Err( p_demux, "VIDIOC_QUERYBUF" );
1726 p_sys->p_buffers[p_sys->i_nbuffers].length = buf.length;
1727 p_sys->p_buffers[p_sys->i_nbuffers].start =
1728 mmap( NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, buf.m.offset );
1730 if( p_sys->p_buffers[p_sys->i_nbuffers].start == MAP_FAILED )
1732 msg_Err( p_demux, "mmap failed (%m)" );
1740 return VLC_EGENERIC;
1744 /*****************************************************************************
1745 * Helper function to initalise video IO using the userbuf method
1746 *****************************************************************************/
1747 static int InitUserP( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
1749 demux_sys_t *p_sys = p_demux->p_sys;
1750 struct v4l2_requestbuffers req;
1751 unsigned int i_page_size;
1753 i_page_size = sysconf(_SC_PAGESIZE);
1754 i_buffer_size = ( i_buffer_size + i_page_size - 1 ) & ~( i_page_size - 1);
1756 memset( &req, 0, sizeof(req) );
1758 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1759 req.memory = V4L2_MEMORY_USERPTR;
1761 if( ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
1763 msg_Err( p_demux, "device does not support user pointer i/o" );
1767 p_sys->p_buffers = calloc( 4, sizeof( *p_sys->p_buffers ) );
1768 if( !p_sys->p_buffers )
1770 msg_Err( p_demux, "Out of memory" );
1774 for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < 4; ++p_sys->i_nbuffers )
1776 p_sys->p_buffers[p_sys->i_nbuffers].length = i_buffer_size;
1777 posix_memalign( &p_sys->p_buffers[p_sys->i_nbuffers].start,
1778 /* boundary */ i_page_size, i_buffer_size );
1780 if( !p_sys->p_buffers[p_sys->i_nbuffers].start )
1782 msg_Err( p_demux, "out of memory" );
1790 return VLC_EGENERIC;
1794 /*****************************************************************************
1795 * IsPixelFormatSupported: returns true if the specified V4L2 pixel format is
1796 * in the array of supported formats returned by the driver
1797 *****************************************************************************/
1798 static bool IsPixelFormatSupported( demux_t *p_demux, unsigned int i_pixelformat )
1800 demux_sys_t *p_sys = p_demux->p_sys;
1802 for( int i_index = 0; i_index < p_sys->i_codec; i_index++ )
1804 if( p_sys->p_codecs[i_index].pixelformat == i_pixelformat )
1811 /*****************************************************************************
1812 * OpenVideoDev: open and set up the video device and probe for capabilities
1813 *****************************************************************************/
1814 static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
1817 struct v4l2_cropcap cropcap;
1818 struct v4l2_crop crop;
1819 struct v4l2_format fmt;
1821 enum v4l2_buf_type buf_type;
1822 char *psz_device = p_sys->psz_vdev;
1824 if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
1826 msg_Err( p_obj, "cannot open device (%m)" );
1830 /* Tune the tuner */
1831 if( p_sys->i_frequency >= 0 )
1833 if( p_sys->i_cur_tuner < 0 || p_sys->i_cur_tuner >= p_sys->i_tuner )
1835 msg_Err( p_obj, "invalid tuner %d.", p_sys->i_cur_tuner );
1838 struct v4l2_frequency frequency;
1839 memset( &frequency, 0, sizeof( frequency ) );
1840 frequency.tuner = p_sys->i_cur_tuner;
1841 frequency.type = p_sys->p_tuners[p_sys->i_cur_tuner].type;
1842 frequency.frequency = p_sys->i_frequency / 62.5;
1843 if( ioctl( i_fd, VIDIOC_S_FREQUENCY, &frequency ) < 0 )
1845 msg_Err( p_obj, "cannot set tuner frequency (%m)" );
1848 msg_Dbg( p_obj, "Tuner frequency set" );
1851 /* Set the tuner's audio mode */
1852 if( p_sys->i_audio_mode >= 0 )
1854 if( p_sys->i_cur_tuner < 0 || p_sys->i_cur_tuner >= p_sys->i_tuner )
1856 msg_Err( p_obj, "invalid tuner %d.", p_sys->i_cur_tuner );
1859 struct v4l2_tuner tuner;
1860 memset( &tuner, 0, sizeof( tuner ) );
1861 tuner.index = p_sys->i_cur_tuner;
1862 tuner.audmode = p_sys->i_audio_mode;
1863 if( ioctl( i_fd, VIDIOC_S_TUNER, &tuner ) < 0 )
1865 msg_Err( p_obj, "cannot set tuner audio mode (%m)" );
1868 msg_Dbg( p_obj, "Tuner audio mode set" );
1871 /* Select standard */
1873 if( p_sys->i_selected_standard_id != V4L2_STD_UNKNOWN )
1875 if( ioctl( i_fd, VIDIOC_S_STD, &p_sys->i_selected_standard_id ) < 0 )
1877 msg_Err( p_obj, "cannot set standard (%m)" );
1880 msg_Dbg( p_obj, "Set standard" );
1885 if( p_sys->i_selected_input >= p_sys->i_input )
1887 msg_Warn( p_obj, "invalid input. Using the default one" );
1888 p_sys->i_selected_input = 0;
1891 if( ioctl( i_fd, VIDIOC_S_INPUT, &p_sys->i_selected_input ) < 0 )
1893 msg_Err( p_obj, "cannot set input (%m)" );
1897 /* Set audio input */
1899 if( p_sys->i_audio > 0 )
1901 if( p_sys->i_selected_audio_input < 0
1902 || p_sys->i_selected_audio_input >= p_sys->i_audio )
1904 msg_Warn( p_obj, "invalid audio input. Using the default one" );
1905 p_sys->i_selected_audio_input = 0;
1908 if( ioctl( i_fd, VIDIOC_S_AUDIO, &p_sys->p_audios[p_sys->i_selected_audio_input] ) < 0 )
1910 msg_Err( p_obj, "cannot set audio input (%m)" );
1913 msg_Dbg( p_obj, "Audio input set to %d", p_sys->i_selected_audio_input );
1917 /* TODO: Move the resolution stuff up here */
1918 /* if MPEG encoder card, no need to do anything else after this */
1919 ControlList( p_obj, i_fd,
1920 var_GetBool( p_obj, "v4l2-controls-reset" ), b_demux );
1921 SetAvailControlsByString( p_obj, p_sys, i_fd );
1922 if( false == b_demux)
1927 demux_t *p_demux = (demux_t *) p_obj;
1929 /* Verify device support for the various IO methods */
1932 case IO_METHOD_READ:
1933 if( !(p_sys->dev_cap.capabilities & V4L2_CAP_READWRITE) )
1935 msg_Err( p_demux, "device does not support read i/o" );
1940 case IO_METHOD_MMAP:
1941 case IO_METHOD_USERPTR:
1942 if( !(p_sys->dev_cap.capabilities & V4L2_CAP_STREAMING) )
1944 msg_Err( p_demux, "device does not support streaming i/o" );
1950 msg_Err( p_demux, "io method not supported" );
1954 /* Reset Cropping */
1955 memset( &cropcap, 0, sizeof(cropcap) );
1956 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1957 if( ioctl( i_fd, VIDIOC_CROPCAP, &cropcap ) >= 0 )
1959 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1960 crop.c = cropcap.defrect; /* reset to default */
1961 if( ioctl( i_fd, VIDIOC_S_CROP, &crop ) < 0 )
1966 /* Cropping not supported. */
1969 /* Errors ignored. */
1975 /* Try and find default resolution if not specified */
1976 memset( &fmt, 0, sizeof(fmt) );
1977 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1979 if( p_sys->i_width <= 0 || p_sys->i_height <= 0 )
1981 if( ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 )
1983 msg_Err( p_demux, "Cannot get default width and height." );
1987 p_sys->i_width = fmt.fmt.pix.width;
1988 p_sys->i_height = fmt.fmt.pix.height;
1990 if( fmt.fmt.pix.field == V4L2_FIELD_ALTERNATE )
1992 p_sys->i_height = p_sys->i_height * 2;
1997 msg_Dbg( p_demux, "trying specified size %dx%d", p_sys->i_width, p_sys->i_height );
2000 fmt.fmt.pix.width = p_sys->i_width;
2001 fmt.fmt.pix.height = p_sys->i_height;
2002 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
2004 /* Test and set Chroma */
2005 fmt.fmt.pix.pixelformat = 0;
2006 if( p_sys->psz_requested_chroma && strlen( p_sys->psz_requested_chroma ) > 0 )
2008 /* User specified chroma */
2009 if( strlen( p_sys->psz_requested_chroma ) >= 4 )
2011 int i_requested_fourcc = VLC_FOURCC(
2012 p_sys->psz_requested_chroma[0], p_sys->psz_requested_chroma[1],
2013 p_sys->psz_requested_chroma[2], p_sys->psz_requested_chroma[3] );
2014 for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
2016 if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
2018 fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2;
2023 /* Try and set user chroma */
2024 if( !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) || ( fmt.fmt.pix.pixelformat && ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) )
2026 msg_Warn( p_demux, "Driver is unable to use specified chroma %s. Trying defaults.", p_sys->psz_requested_chroma );
2027 fmt.fmt.pix.pixelformat = 0;
2031 /* If no user specified chroma, find best */
2032 /* This also decides if MPEG encoder card or not */
2033 if( !fmt.fmt.pix.pixelformat )
2036 for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
2038 fmt.fmt.pix.pixelformat = p_chroma_fallbacks[i];
2039 if( IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat )
2040 && ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
2043 if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
2045 msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
2050 /* Reassign width, height and chroma incase driver override */
2051 p_sys->i_width = fmt.fmt.pix.width;
2052 p_sys->i_height = fmt.fmt.pix.height;
2054 /* Look up final fourcc */
2055 p_sys->i_fourcc = 0;
2056 for( int i = 0; v4l2chroma_to_fourcc[i].i_fourcc != 0; i++ )
2058 if( v4l2chroma_to_fourcc[i].i_v4l2 == fmt.fmt.pix.pixelformat )
2060 p_sys->i_fourcc = v4l2chroma_to_fourcc[i].i_fourcc;
2065 /* Buggy driver paranoia */
2066 i_min = fmt.fmt.pix.width * 2;
2067 if( fmt.fmt.pix.bytesperline < i_min )
2068 fmt.fmt.pix.bytesperline = i_min;
2069 i_min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
2070 if( fmt.fmt.pix.sizeimage < i_min )
2071 fmt.fmt.pix.sizeimage = i_min;
2073 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
2074 /* This is new in Linux 2.6.19 */
2075 /* List supported frame rates */
2076 struct v4l2_frmivalenum frmival;
2078 frmival.pixel_format = fmt.fmt.pix.pixelformat;
2079 frmival.width = p_sys->i_width;
2080 frmival.height = p_sys->i_height;
2081 if( ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 )
2084 memset( &psz_fourcc, 0, sizeof( psz_fourcc ) );
2085 vlc_fourcc_to_char( p_sys->i_fourcc, &psz_fourcc );
2086 msg_Dbg( p_demux, "supported frame intervals for %4s, %dx%d:",
2087 psz_fourcc, frmival.width, frmival.height );
2088 switch( frmival.type )
2090 case V4L2_FRMIVAL_TYPE_DISCRETE:
2093 msg_Dbg( p_demux, " supported frame interval: %d/%d",
2094 frmival.discrete.numerator,
2095 frmival.discrete.denominator );
2097 } while( ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 );
2099 case V4L2_FRMIVAL_TYPE_STEPWISE:
2100 msg_Dbg( p_demux, " supported frame intervals: %d/%d to "
2101 "%d/%d using %d/%d increments",
2102 frmival.stepwise.min.numerator,
2103 frmival.stepwise.min.denominator,
2104 frmival.stepwise.max.numerator,
2105 frmival.stepwise.max.denominator,
2106 frmival.stepwise.step.numerator,
2107 frmival.stepwise.step.denominator );
2109 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
2110 msg_Dbg( p_demux, " supported frame intervals: %d/%d to %d/%d",
2111 frmival.stepwise.min.numerator,
2112 frmival.stepwise.min.denominator,
2113 frmival.stepwise.max.numerator,
2114 frmival.stepwise.max.denominator );
2120 /* Init IO method */
2123 case IO_METHOD_READ:
2124 if( InitRead( p_demux, i_fd, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
2127 case IO_METHOD_MMAP:
2128 if( InitMmap( p_demux, i_fd ) != VLC_SUCCESS ) goto open_failed;
2131 case IO_METHOD_USERPTR:
2132 if( InitUserP( p_demux, i_fd, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
2139 es_format_Init( &es_fmt, VIDEO_ES, p_sys->i_fourcc );
2140 es_fmt.video.i_width = p_sys->i_width;
2141 es_fmt.video.i_height = p_sys->i_height;
2142 es_fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
2144 /* Setup rgb mask for RGB formats */
2145 if( p_sys->i_fourcc == VLC_FOURCC( 'R','V','2','4' ) )
2147 /* This is in BGR format */
2148 es_fmt.video.i_bmask = 0x00ff0000;
2149 es_fmt.video.i_gmask = 0x0000ff00;
2150 es_fmt.video.i_rmask = 0x000000ff;
2153 msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
2154 (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
2155 p_sys->p_es_video = es_out_Add( p_demux->out, &es_fmt );
2161 case IO_METHOD_READ:
2165 case IO_METHOD_MMAP:
2166 for (unsigned int i = 0; i < p_sys->i_nbuffers; ++i)
2168 struct v4l2_buffer buf;
2170 memset( &buf, 0, sizeof(buf) );
2171 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2172 buf.memory = V4L2_MEMORY_MMAP;
2175 if( ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
2177 msg_Err( p_demux, "VIDIOC_QBUF failed" );
2182 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2183 if( ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
2185 msg_Err( p_demux, "VIDIOC_STREAMON failed" );
2191 case IO_METHOD_USERPTR:
2192 for( unsigned int i = 0; i < p_sys->i_nbuffers; ++i )
2194 struct v4l2_buffer buf;
2196 memset( &buf, 0, sizeof(buf) );
2197 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2198 buf.memory = V4L2_MEMORY_USERPTR;
2200 buf.m.userptr = (unsigned long)p_sys->p_buffers[i].start;
2201 buf.length = p_sys->p_buffers[i].length;
2203 if( ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
2205 msg_Err( p_demux, "VIDIOC_QBUF failed" );
2210 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2211 if( ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
2213 msg_Err( p_demux, "VIDIOC_STREAMON failed" );
2221 if( p_sys->f_fps >= 0.1 )
2223 msg_Dbg( p_demux, "User set fps=%f", p_sys->f_fps );
2229 if( i_fd >= 0 ) close( i_fd );
2235 /*****************************************************************************
2236 * ResolveALSADeviceName: Change any . to : in the ALSA device name
2237 *****************************************************************************/
2238 static char *ResolveALSADeviceName( const char *psz_device )
2240 char* psz_alsa_name = strdup( psz_device );
2241 for( unsigned int i = 0; i < strlen( psz_device ); i++ )
2243 if( psz_alsa_name[i] == '.' ) psz_alsa_name[i] = ':';
2245 return psz_alsa_name;
2249 /*****************************************************************************
2250 * OpenAudioDev: open and set up the audio device and probe for capabilities
2251 *****************************************************************************/
2253 static int OpenAudioDevAlsa( vlc_object_t *p_this, demux_sys_t *p_sys,
2256 char *psz_device = p_sys->psz_adev;
2257 p_sys->p_alsa_pcm = NULL;
2258 char* psz_alsa_device_name = NULL;
2259 snd_pcm_hw_params_t *p_hw_params = NULL;
2260 snd_pcm_uframes_t buffer_size;
2261 snd_pcm_uframes_t chunk_size;
2265 psz_alsa_device_name =
2266 ResolveALSADeviceName( psz_device?: ALSA_DEFAULT );
2268 if( ( i_err = snd_pcm_open( &p_sys->p_alsa_pcm, psz_alsa_device_name,
2269 SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK ) ) < 0)
2271 msg_Err( p_this, "Cannot open ALSA audio device %s (%s)",
2272 psz_alsa_device_name, snd_strerror( i_err ) );
2276 if( ( i_err = snd_pcm_nonblock( p_sys->p_alsa_pcm, 1 ) ) < 0)
2278 msg_Err( p_this, "Cannot set ALSA nonblock (%s)",
2279 snd_strerror( i_err ) );
2283 /* Begin setting hardware parameters */
2285 if( ( i_err = snd_pcm_hw_params_malloc( &p_hw_params ) ) < 0 )
2288 "ALSA: cannot allocate hardware parameter structure (%s)",
2289 snd_strerror( i_err ) );
2293 if( ( i_err = snd_pcm_hw_params_any( p_sys->p_alsa_pcm, p_hw_params ) ) < 0 )
2296 "ALSA: cannot initialize hardware parameter structure (%s)",
2297 snd_strerror( i_err ) );
2301 /* Set Interleaved access */
2302 if( ( i_err = snd_pcm_hw_params_set_access( p_sys->p_alsa_pcm, p_hw_params, SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 )
2304 msg_Err( p_this, "ALSA: cannot set access type (%s)",
2305 snd_strerror( i_err ) );
2309 /* Set 16 bit little endian */
2310 if( ( i_err = snd_pcm_hw_params_set_format( p_sys->p_alsa_pcm, p_hw_params, SND_PCM_FORMAT_S16_LE ) ) < 0 )
2312 msg_Err( p_this, "ALSA: cannot set sample format (%s)",
2313 snd_strerror( i_err ) );
2317 /* Set sample rate */
2318 #ifdef HAVE_ALSA_NEW_API
2319 i_err = snd_pcm_hw_params_set_rate_near( p_sys->p_alsa_pcm, p_hw_params, &p_sys->i_sample_rate, NULL );
2321 i_err = snd_pcm_hw_params_set_rate_near( p_sys->p_alsa_pcm, p_hw_params, p_sys->i_sample_rate, NULL );
2325 msg_Err( p_this, "ALSA: cannot set sample rate (%s)",
2326 snd_strerror( i_err ) );
2331 unsigned int channels = p_sys->b_stereo ? 2 : 1;
2332 if( ( i_err = snd_pcm_hw_params_set_channels( p_sys->p_alsa_pcm, p_hw_params, channels ) ) < 0 )
2334 channels = ( channels==1 ) ? 2 : 1;
2335 msg_Warn( p_this, "ALSA: cannot set channel count (%s). "
2336 "Trying with channels=%d",
2337 snd_strerror( i_err ),
2339 if( ( i_err = snd_pcm_hw_params_set_channels( p_sys->p_alsa_pcm, p_hw_params, channels ) ) < 0 )
2341 msg_Err( p_this, "ALSA: cannot set channel count (%s)",
2342 snd_strerror( i_err ) );
2345 p_sys->b_stereo = ( channels == 2 );
2348 /* Set metrics for buffer calculations later */
2349 unsigned int buffer_time;
2350 if( ( i_err = snd_pcm_hw_params_get_buffer_time_max(p_hw_params, &buffer_time, 0) ) < 0 )
2352 msg_Err( p_this, "ALSA: cannot get buffer time max (%s)",
2353 snd_strerror( i_err ) );
2356 if (buffer_time > 500000) buffer_time = 500000;
2358 /* Set period time */
2359 unsigned int period_time = buffer_time / 4;
2360 #ifdef HAVE_ALSA_NEW_API
2361 i_err = snd_pcm_hw_params_set_period_time_near( p_sys->p_alsa_pcm, p_hw_params, &period_time, 0 );
2363 i_err = snd_pcm_hw_params_set_period_time_near( p_sys->p_alsa_pcm, p_hw_params, period_time, 0 );
2367 msg_Err( p_this, "ALSA: cannot set period time (%s)",
2368 snd_strerror( i_err ) );
2372 /* Set buffer time */
2373 #ifdef HAVE_ALSA_NEW_API
2374 i_err = snd_pcm_hw_params_set_buffer_time_near( p_sys->p_alsa_pcm, p_hw_params, &buffer_time, 0 );
2376 i_err = snd_pcm_hw_params_set_buffer_time_near( p_sys->p_alsa_pcm, p_hw_params, buffer_time, 0 );
2380 msg_Err( p_this, "ALSA: cannot set buffer time (%s)",
2381 snd_strerror( i_err ) );
2385 /* Apply new hardware parameters */
2386 if( ( i_err = snd_pcm_hw_params( p_sys->p_alsa_pcm, p_hw_params ) ) < 0 )
2388 msg_Err( p_this, "ALSA: cannot set hw parameters (%s)",
2389 snd_strerror( i_err ) );
2393 /* Get various buffer metrics */
2394 snd_pcm_hw_params_get_period_size( p_hw_params, &chunk_size, 0 );
2395 snd_pcm_hw_params_get_buffer_size( p_hw_params, &buffer_size );
2396 if( chunk_size == buffer_size )
2399 "ALSA: period cannot equal buffer size (%lu == %lu)",
2400 chunk_size, buffer_size);
2404 int bits_per_sample = snd_pcm_format_physical_width(SND_PCM_FORMAT_S16_LE);
2405 int bits_per_frame = bits_per_sample * channels;
2407 p_sys->i_alsa_chunk_size = chunk_size;
2408 p_sys->i_alsa_frame_size = bits_per_frame / 8;
2409 p_sys->i_audio_max_frame_size = chunk_size * bits_per_frame / 8;
2411 snd_pcm_hw_params_free( p_hw_params );
2415 if( ( i_err = snd_pcm_prepare( p_sys->p_alsa_pcm ) ) < 0 )
2418 "ALSA: cannot prepare audio interface for use (%s)",
2419 snd_strerror( i_err ) );
2423 free( psz_alsa_device_name );
2425 if( !p_sys->psz_adev )
2426 p_sys->psz_adev = strdup( ALSA_DEFAULT );
2428 /* Return a fake handle so other tests work */
2433 if( p_hw_params ) snd_pcm_hw_params_free( p_hw_params );
2434 if( p_sys->p_alsa_pcm ) snd_pcm_close( p_sys->p_alsa_pcm );
2435 free( psz_alsa_device_name );
2442 static int OpenAudioDevOss( vlc_object_t *p_this, demux_sys_t *p_sys,
2448 char* psz_oss_device_name = strdup( p_sys->psz_adev ? p_sys->psz_adev : OSS_DEFAULT );
2450 if( (i_fd = open( psz_oss_device_name, O_RDONLY | O_NONBLOCK )) < 0 )
2452 msg_Err( p_this, "cannot open OSS audio device (%m)" );
2456 i_format = AFMT_S16_LE;
2457 if( ioctl( i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
2458 || i_format != AFMT_S16_LE )
2461 "cannot set audio format (16b little endian) (%m)" );
2465 if( ioctl( i_fd, SNDCTL_DSP_STEREO,
2466 &p_sys->b_stereo ) < 0 )
2468 msg_Err( p_this, "cannot set audio channels count (%m)" );
2472 if( ioctl( i_fd, SNDCTL_DSP_SPEED,
2473 &p_sys->i_sample_rate ) < 0 )
2475 msg_Err( p_this, "cannot set audio sample rate (%m)" );
2479 p_sys->i_audio_max_frame_size = 6 * 1024;
2481 if( !p_sys->psz_adev )
2482 p_sys->psz_adev = strdup( OSS_DEFAULT );
2483 free( psz_oss_device_name );
2488 free( psz_oss_device_name );
2489 if( i_fd >= 0 ) close( i_fd );
2494 static int OpenAudioDev( vlc_object_t *p_this, demux_sys_t *p_sys,
2501 if( ( p_sys->i_audio_method & AUDIO_METHOD_ALSA ) && i_fd < 0 )
2502 i_fd = OpenAudioDevAlsa( p_this, p_sys, b_demux );
2505 if( ( p_sys->i_audio_method & AUDIO_METHOD_OSS ) && i_fd < 0 )
2506 i_fd = OpenAudioDevOss( p_this, p_sys, b_demux );
2511 psz_device = p_sys->psz_adev;
2513 msg_Dbg( p_this, "opened adev=`%s' %s %dHz",
2514 psz_device, p_sys->b_stereo ? "stereo" : "mono",
2515 p_sys->i_sample_rate );
2518 es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('a','r','a','w') );
2520 fmt.audio.i_channels = p_sys->b_stereo ? 2 : 1;
2521 fmt.audio.i_rate = p_sys->i_sample_rate;
2522 fmt.audio.i_bitspersample = 16;
2523 fmt.audio.i_blockalign = fmt.audio.i_channels * fmt.audio.i_bitspersample / 8;
2524 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate * fmt.audio.i_bitspersample;
2526 msg_Dbg( p_this, "new audio es %d channels %dHz",
2527 fmt.audio.i_channels, fmt.audio.i_rate );
2531 demux_t *p_demux = (demux_t *)p_this;
2532 p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt );
2538 /*****************************************************************************
2539 * ProbeVideoDev: probe video for capabilities
2540 *****************************************************************************/
2541 static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
2549 if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
2551 msg_Err( p_obj, "cannot open video device (%m)" );
2555 /* Get device capabilites */
2557 if( ioctl( i_fd, VIDIOC_QUERYCAP, &p_sys->dev_cap ) < 0 )
2559 msg_Err( p_obj, "cannot get video capabilities (%m)" );
2563 msg_Dbg( p_obj, "V4L2 device: %s using driver: %s (version: %u.%u.%u) on %s",
2564 p_sys->dev_cap.card,
2565 p_sys->dev_cap.driver,
2566 (p_sys->dev_cap.version >> 16) & 0xFF,
2567 (p_sys->dev_cap.version >> 8) & 0xFF,
2568 p_sys->dev_cap.version & 0xFF,
2569 p_sys->dev_cap.bus_info );
2571 msg_Dbg( p_obj, "the device has the capabilities: (%c) Video Capure, "
2574 ( p_sys->dev_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE ? 'X':' '),
2575 ( p_sys->dev_cap.capabilities & V4L2_CAP_AUDIO ? 'X':' '),
2576 ( p_sys->dev_cap.capabilities & V4L2_CAP_TUNER ? 'X':' ') );
2578 msg_Dbg( p_obj, "supported I/O methods are: (%c) Read/Write, "
2580 "(%c) Asynchronous",
2581 ( p_sys->dev_cap.capabilities & V4L2_CAP_READWRITE ? 'X':' ' ),
2582 ( p_sys->dev_cap.capabilities & V4L2_CAP_STREAMING ? 'X':' ' ),
2583 ( p_sys->dev_cap.capabilities & V4L2_CAP_ASYNCIO ? 'X':' ' ) );
2585 /* Now, enumerate all the video inputs. This is useless at the moment
2586 since we have no way to present that info to the user except with
2589 if( p_sys->dev_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
2591 struct v4l2_input t_input;
2593 while( ioctl( i_fd, VIDIOC_ENUMINPUT, &t_input ) >= 0 )
2596 t_input.index = p_sys->i_input;
2599 p_sys->p_inputs = calloc( 1, p_sys->i_input * sizeof( struct v4l2_input ) );
2600 if( !p_sys->p_inputs ) goto open_failed;
2602 for( i_index = 0; i_index < p_sys->i_input; i_index++ )
2604 p_sys->p_inputs[i_index].index = i_index;
2606 if( ioctl( i_fd, VIDIOC_ENUMINPUT, &p_sys->p_inputs[i_index] ) )
2608 msg_Err( p_obj, "cannot get video input characteristics (%m)" );
2611 msg_Dbg( p_obj, "video input %i (%s) has type: %s %c",
2613 p_sys->p_inputs[i_index].name,
2614 p_sys->p_inputs[i_index].type
2615 == V4L2_INPUT_TYPE_TUNER ?
2617 "External analog input",
2618 i_index == p_sys->i_selected_input ? '*' : ' ' );
2622 /* Probe video standards */
2623 if( p_sys->dev_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
2625 struct v4l2_standard t_standards;
2626 t_standards.index = 0;
2627 while( ioctl( i_fd, VIDIOC_ENUMSTD, &t_standards ) >=0 )
2629 p_sys->i_standard++;
2630 t_standards.index = p_sys->i_standard;
2633 p_sys->p_standards = calloc( 1, p_sys->i_standard * sizeof( struct v4l2_standard ) );
2634 if( !p_sys->p_standards ) goto open_failed;
2636 for( i_standard = 0; i_standard < p_sys->i_standard; i_standard++ )
2638 p_sys->p_standards[i_standard].index = i_standard;
2640 if( ioctl( i_fd, VIDIOC_ENUMSTD, &p_sys->p_standards[i_standard] ) )
2642 msg_Err( p_obj, "cannot get video input standards (%m)" );
2645 msg_Dbg( p_obj, "video standard %i is: %s %c",
2647 p_sys->p_standards[i_standard].name,
2648 (unsigned)i_standard == p_sys->i_selected_standard_id ? '*' : ' ' );
2652 /* initialize the structures for the ioctls */
2653 for( i_index = 0; i_index < 32; i_index++ )
2655 p_sys->p_audios[i_index].index = i_index;
2658 /* Probe audio inputs */
2659 if( p_sys->dev_cap.capabilities & V4L2_CAP_AUDIO )
2661 while( p_sys->i_audio < 32 &&
2662 ioctl( i_fd, VIDIOC_S_AUDIO, &p_sys->p_audios[p_sys->i_audio] ) >= 0 )
2664 if( ioctl( i_fd, VIDIOC_G_AUDIO, &p_sys->p_audios[ p_sys->i_audio] ) < 0 )
2666 msg_Err( p_obj, "cannot get audio input characteristics (%m)" );
2670 msg_Dbg( p_obj, "audio input %i (%s) is %s %s %c",
2672 p_sys->p_audios[p_sys->i_audio].name,
2673 p_sys->p_audios[p_sys->i_audio].capability &
2674 V4L2_AUDCAP_STEREO ?
2676 p_sys->p_audios[p_sys->i_audio].capability &
2678 "(Automatic Volume Level supported)" : "",
2679 p_sys->i_audio == p_sys->i_selected_audio_input ? '*' : ' ' );
2685 /* List tuner caps */
2686 if( p_sys->dev_cap.capabilities & V4L2_CAP_TUNER )
2688 struct v4l2_tuner tuner;
2689 memset( &tuner, 0, sizeof(tuner) );
2690 while( ioctl( i_fd, VIDIOC_G_TUNER, &tuner ) >= 0 )
2693 memset( &tuner, 0, sizeof(tuner) );
2694 tuner.index = p_sys->i_tuner;
2697 p_sys->p_tuners = calloc( 1, p_sys->i_tuner * sizeof( struct v4l2_tuner ) );
2698 if( !p_sys->p_tuners ) goto open_failed;
2700 for( i_index = 0; i_index < p_sys->i_tuner; i_index++ )
2702 p_sys->p_tuners[i_index].index = i_index;
2704 if( ioctl( i_fd, VIDIOC_G_TUNER, &p_sys->p_tuners[i_index] ) )
2706 msg_Err( p_obj, "cannot get tuner characteristics (%m)" );
2709 msg_Dbg( p_obj, "tuner %i (%s) has type: %s, "
2710 "frequency range: %.1f %s -> %.1f %s",
2712 p_sys->p_tuners[i_index].name,
2713 p_sys->p_tuners[i_index].type
2714 == V4L2_TUNER_RADIO ?
2715 "Radio" : "Analog TV",
2716 p_sys->p_tuners[i_index].rangelow * 62.5,
2717 p_sys->p_tuners[i_index].capability &
2718 V4L2_TUNER_CAP_LOW ?
2720 p_sys->p_tuners[i_index].rangehigh * 62.5,
2721 p_sys->p_tuners[i_index].capability &
2722 V4L2_TUNER_CAP_LOW ?
2725 struct v4l2_frequency frequency;
2726 memset( &frequency, 0, sizeof( frequency ) );
2727 if( ioctl( i_fd, VIDIOC_G_FREQUENCY, &frequency ) < 0 )
2729 msg_Err( p_obj, "cannot get tuner frequency (%m)" );
2732 msg_Dbg( p_obj, "tuner %i (%s) frequency: %.1f %s",
2734 p_sys->p_tuners[i_index].name,
2735 frequency.frequency * 62.5,
2736 p_sys->p_tuners[i_index].capability &
2737 V4L2_TUNER_CAP_LOW ?
2742 /* Probe for available chromas */
2743 if( p_sys->dev_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
2745 struct v4l2_fmtdesc codec;
2748 memset( &codec, 0, sizeof(codec) );
2749 codec.index = i_index;
2750 codec.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2752 while( ioctl( i_fd, VIDIOC_ENUM_FMT, &codec ) >= 0 )
2755 codec.index = i_index;
2758 p_sys->i_codec = i_index;
2760 p_sys->p_codecs = calloc( 1, p_sys->i_codec * sizeof( struct v4l2_fmtdesc ) );
2762 for( i_index = 0; i_index < p_sys->i_codec; i_index++ )
2764 p_sys->p_codecs[i_index].index = i_index;
2765 p_sys->p_codecs[i_index].type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2767 if( ioctl( i_fd, VIDIOC_ENUM_FMT, &p_sys->p_codecs[i_index] ) < 0 )
2769 msg_Err( p_obj, "cannot get codec description (%m)" );
2773 /* only print if vlc supports the format */
2774 char psz_fourcc_v4l2[5];
2775 memset( &psz_fourcc_v4l2, 0, sizeof( psz_fourcc_v4l2 ) );
2776 vlc_fourcc_to_char( p_sys->p_codecs[i_index].pixelformat,
2778 bool b_codec_supported = false;
2779 for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
2781 if( v4l2chroma_to_fourcc[i].i_v4l2 == p_sys->p_codecs[i_index].pixelformat )
2783 b_codec_supported = true;
2786 memset( &psz_fourcc, 0, sizeof( psz_fourcc ) );
2787 vlc_fourcc_to_char( v4l2chroma_to_fourcc[i].i_fourcc,
2789 msg_Dbg( p_obj, "device supports chroma %4s [%s, %s]",
2791 p_sys->p_codecs[i_index].description,
2794 #ifdef VIDIOC_ENUM_FRAMESIZES
2795 /* This is new in Linux 2.6.19 */
2796 /* List valid frame sizes for this format */
2797 struct v4l2_frmsizeenum frmsize;
2799 frmsize.pixel_format = p_sys->p_codecs[i_index].pixelformat;
2800 if( ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) < 0 )
2802 /* Not all devices support this ioctl */
2803 msg_Warn( p_obj, "Unable to query for frame sizes" );
2807 switch( frmsize.type )
2809 case V4L2_FRMSIZE_TYPE_DISCRETE:
2813 " device supports size %dx%d",
2814 frmsize.discrete.width, frmsize.discrete.height );
2816 } while( ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) >= 0 );
2818 case V4L2_FRMSIZE_TYPE_STEPWISE:
2820 " device supports sizes %dx%d to %dx%d using %dx%d increments",
2821 frmsize.stepwise.min_width, frmsize.stepwise.min_height,
2822 frmsize.stepwise.max_width, frmsize.stepwise.max_height,
2823 frmsize.stepwise.step_width, frmsize.stepwise.step_height );
2825 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
2827 " device supports all sizes %dx%d to %dx%d",
2828 frmsize.stepwise.min_width, frmsize.stepwise.min_height,
2829 frmsize.stepwise.max_width, frmsize.stepwise.max_height );
2836 if( !b_codec_supported )
2839 "device codec %4s (%s) not supported as access_demux",
2841 p_sys->p_codecs[i_index].description );
2848 if( i_fd >= 0 ) close( i_fd );
2853 if( i_fd >= 0 ) close( i_fd );
2858 /*****************************************************************************
2859 * ProbeAudioDev: probe audio for capabilities
2860 *****************************************************************************/
2862 static bool ProbeAudioDevAlsa( vlc_object_t *p_this, demux_sys_t *p_sys,
2866 snd_pcm_t *p_alsa_pcm;
2867 char* psz_alsa_device_name = ResolveALSADeviceName( psz_device ?: ALSA_DEFAULT );
2869 if( ( i_err = snd_pcm_open( &p_alsa_pcm, psz_alsa_device_name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK ) ) < 0 )
2871 msg_Err( p_this, "cannot open device %s for ALSA audio (%s)", psz_alsa_device_name, snd_strerror( i_err ) );
2872 free( psz_alsa_device_name );
2876 snd_pcm_close( p_alsa_pcm );
2877 free( psz_alsa_device_name );
2883 static bool ProbeAudioDevOss( vlc_object_t *p_this, demux_sys_t *p_sys,
2888 char* psz_oss_device_name = strdup( psz_device ? psz_device : OSS_DEFAULT );
2890 if( ( i_fd = open( psz_oss_device_name, O_RDONLY | O_NONBLOCK ) ) < 0 )
2892 msg_Err( p_this, "cannot open device %s for OSS audio (%m)", psz_oss_device_name );
2896 /* this will fail if the device is video */
2897 if( ioctl( i_fd, SNDCTL_DSP_GETCAPS, &i_caps ) < 0 )
2899 msg_Err( p_this, "cannot get audio caps (%m)" );
2903 free( psz_oss_device_name );
2904 if( i_fd >= 0 ) close( i_fd );
2909 free( psz_oss_device_name );
2910 if( i_fd >= 0 ) close( i_fd );
2914 static bool ProbeAudioDev( vlc_object_t *p_this, demux_sys_t *p_sys,
2918 if( ( p_sys->i_audio_method & AUDIO_METHOD_ALSA )
2919 && ProbeAudioDevAlsa( p_this, p_sys, psz_device ) )
2921 p_sys->i_audio_method = AUDIO_METHOD_ALSA;
2926 if( ( p_sys->i_audio_method & AUDIO_METHOD_OSS )
2927 && ProbeAudioDevOss( p_this, p_sys, psz_device ) )
2929 p_sys->i_audio_method = AUDIO_METHOD_OSS;
2933 p_sys->i_audio_method = 0;
2937 static void name2var( unsigned char *name )
2939 for( ; *name; name++ )
2940 *name = (*name == ' ') ? '_' : tolower( *name );
2943 /*****************************************************************************
2944 * Print a user-class v4l2 control's details, create the relevant variable,
2945 * change the value if needed.
2946 *****************************************************************************/
2947 static void ControlListPrint( vlc_object_t *p_obj, int i_fd,
2948 struct v4l2_queryctrl queryctrl,
2949 bool b_reset, bool b_demux )
2951 struct v4l2_querymenu querymenu;
2958 vlc_value_t val, val2;
2960 if( queryctrl.flags & V4L2_CTRL_FLAG_GRABBED )
2961 msg_Dbg( p_obj, " control is busy" );
2962 if( queryctrl.flags & V4L2_CTRL_FLAG_READ_ONLY )
2963 msg_Dbg( p_obj, " control is read-only" );
2965 for( i = 0; controls[i].psz_name != NULL; i++ )
2966 if( controls[i].i_cid == queryctrl.id ) break;
2968 if( controls[i].psz_name )
2970 psz_name = strdup( controls[i].psz_name );
2971 char psz_cfg_name[40];
2972 sprintf( psz_cfg_name, CFG_PREFIX "%s", psz_name );
2973 i_val = var_CreateGetInteger( p_obj, psz_cfg_name );
2974 var_Destroy( p_obj, psz_cfg_name );
2978 psz_name = strdup( (const char *)queryctrl.name );
2979 name2var( (unsigned char *)psz_name );
2983 switch( queryctrl.type )
2985 case V4L2_CTRL_TYPE_INTEGER:
2986 msg_Dbg( p_obj, " integer control" );
2988 " valid values: %d to %d by steps of %d",
2989 queryctrl.minimum, queryctrl.maximum,
2992 var_Create( p_obj, psz_name,
2993 VLC_VAR_INTEGER | VLC_VAR_HASMIN | VLC_VAR_HASMAX
2994 | VLC_VAR_HASSTEP | VLC_VAR_ISCOMMAND );
2995 val.i_int = queryctrl.minimum;
2996 var_Change( p_obj, psz_name, VLC_VAR_SETMIN, &val, NULL );
2997 val.i_int = queryctrl.maximum;
2998 var_Change( p_obj, psz_name, VLC_VAR_SETMAX, &val, NULL );
2999 val.i_int = queryctrl.step;
3000 var_Change( p_obj, psz_name, VLC_VAR_SETSTEP, &val, NULL );
3002 case V4L2_CTRL_TYPE_BOOLEAN:
3003 msg_Dbg( p_obj, " boolean control" );
3004 var_Create( p_obj, psz_name,
3005 VLC_VAR_BOOL | VLC_VAR_ISCOMMAND );
3007 case V4L2_CTRL_TYPE_MENU:
3008 msg_Dbg( p_obj, " menu control" );
3009 var_Create( p_obj, psz_name,
3010 VLC_VAR_INTEGER | VLC_VAR_HASCHOICE
3011 | VLC_VAR_ISCOMMAND );
3012 memset( &querymenu, 0, sizeof( querymenu ) );
3013 for( i_mid = queryctrl.minimum;
3014 i_mid <= (unsigned)queryctrl.maximum;
3017 querymenu.index = i_mid;
3018 querymenu.id = queryctrl.id;
3019 if( ioctl( i_fd, VIDIOC_QUERYMENU, &querymenu ) >= 0 )
3021 msg_Dbg( p_obj, " %d: %s",
3022 querymenu.index, querymenu.name );
3023 val.i_int = querymenu.index;
3024 val2.psz_string = (char *)querymenu.name;
3025 var_Change( p_obj, psz_name,
3026 VLC_VAR_ADDCHOICE, &val, &val2 );
3030 case V4L2_CTRL_TYPE_BUTTON:
3031 msg_Dbg( p_obj, " button control" );
3032 var_Create( p_obj, psz_name,
3033 VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
3035 case V4L2_CTRL_TYPE_CTRL_CLASS:
3036 msg_Dbg( p_obj, " control class" );
3037 var_Create( p_obj, psz_name, VLC_VAR_VOID );
3040 msg_Dbg( p_obj, " unknown control type (FIXME)" );
3045 switch( queryctrl.type )
3047 case V4L2_CTRL_TYPE_INTEGER:
3048 case V4L2_CTRL_TYPE_BOOLEAN:
3049 case V4L2_CTRL_TYPE_MENU:
3051 struct v4l2_control control;
3052 msg_Dbg( p_obj, " default value: %d",
3053 queryctrl.default_value );
3054 memset( &control, 0, sizeof( control ) );
3055 control.id = queryctrl.id;
3056 if( ioctl( i_fd, VIDIOC_G_CTRL, &control ) >= 0 )
3058 msg_Dbg( p_obj, " current value: %d", control.value );
3062 i_val = control.value;
3063 if( b_reset && queryctrl.default_value != control.value )
3065 msg_Dbg( p_obj, " reset value to default" );
3066 Control( p_obj, i_fd, psz_name,
3067 queryctrl.id, queryctrl.default_value );
3072 Control( p_obj, i_fd, psz_name,
3073 queryctrl.id, i_val );
3081 val.psz_string = (char *)queryctrl.name;
3082 var_Change( p_obj, psz_name, VLC_VAR_SETTEXT, &val, NULL );
3083 val.i_int = queryctrl.id;
3084 val2.psz_string = (char *)psz_name;
3085 var_Change( p_obj, "allcontrols", VLC_VAR_ADDCHOICE, &val, &val2 );
3086 /* bad things happen changing MPEG mid-stream
3087 * so don't add to Ext Settings GUI */
3088 if( V4L2_CTRL_ID2CLASS( queryctrl.id ) != V4L2_CTRL_CLASS_MPEG )
3089 var_Change( p_obj, "controls", VLC_VAR_ADDCHOICE, &val, &val2 );
3091 switch( var_Type( p_obj, psz_name ) & VLC_VAR_TYPE )
3094 var_SetBool( p_obj, psz_name, i_val );
3096 case VLC_VAR_INTEGER:
3097 var_SetInteger( p_obj, psz_name, i_val );
3102 msg_Warn( p_obj, "FIXME: %s %s %d", __FILE__, __func__,
3108 var_AddCallback( p_obj, psz_name,
3109 DemuxControlCallback, (void*)queryctrl.id );
3111 var_AddCallback( p_obj, psz_name,
3112 AccessControlCallback, (void*)queryctrl.id );
3117 /*****************************************************************************
3118 * List all user-class v4l2 controls, set them to the user specified
3119 * value and create the relevant variables to enable runtime changes
3120 *****************************************************************************/
3121 static int ControlList( vlc_object_t *p_obj, int i_fd,
3122 bool b_reset, bool b_demux )
3124 struct v4l2_queryctrl queryctrl;
3127 memset( &queryctrl, 0, sizeof( queryctrl ) );
3129 /* A list of available controls (aka the variable name) will be
3130 * stored as choices in the "allcontrols" variable. We'll thus be able
3131 * to use those to create an appropriate interface
3132 * A list of available controls that can be changed mid-stream will
3133 * be stored in the "controls" variable */
3134 var_Create( p_obj, "controls", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
3135 var_Create( p_obj, "allcontrols", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
3137 var_Create( p_obj, "controls-update", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
3139 /* Add a control to reset all controls to their default values */
3140 vlc_value_t val, val2;
3141 var_Create( p_obj, "controls-reset", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
3142 val.psz_string = _( "Reset controls to default" );
3143 var_Change( p_obj, "controls-reset", VLC_VAR_SETTEXT, &val, NULL );
3145 val2.psz_string = (char *)"controls-reset";
3146 var_Change( p_obj, "controls", VLC_VAR_ADDCHOICE, &val, &val2 );
3148 var_AddCallback( p_obj, "controls-reset", DemuxControlResetCallback, NULL );
3150 var_AddCallback( p_obj, "controls-reset", AccessControlResetCallback, NULL );
3152 queryctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
3153 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3155 msg_Dbg( p_obj, "Extended control API supported by v4l2 driver" );
3157 /* List extended controls */
3158 queryctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
3159 while( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3161 if( queryctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS )
3163 msg_Dbg( p_obj, "%s", queryctrl.name );
3164 queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
3167 switch( V4L2_CTRL_ID2CLASS( queryctrl.id ) )
3169 case V4L2_CTRL_CLASS_USER:
3170 msg_Dbg( p_obj, "Available control: %s (%x)",
3171 queryctrl.name, queryctrl.id );
3173 case V4L2_CTRL_CLASS_MPEG:
3174 name2var( queryctrl.name );
3175 msg_Dbg( p_obj, "Available MPEG control: %s (%x)",
3176 queryctrl.name, queryctrl.id );
3179 msg_Dbg( p_obj, "Available private control: %s (%x)",
3180 queryctrl.name, queryctrl.id );
3183 ControlListPrint( p_obj, i_fd, queryctrl, b_reset, b_demux );
3184 queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
3189 msg_Dbg( p_obj, "Extended control API not supported by v4l2 driver" );
3191 /* List public controls */
3192 for( i_cid = V4L2_CID_BASE;
3193 i_cid < V4L2_CID_LASTP1;
3196 queryctrl.id = i_cid;
3197 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3199 if( queryctrl.flags & V4L2_CTRL_FLAG_DISABLED )
3201 msg_Dbg( p_obj, "Available control: %s (%x)",
3202 queryctrl.name, queryctrl.id );
3203 ControlListPrint( p_obj, i_fd, queryctrl, b_reset, b_demux );
3207 /* List private controls */
3208 for( i_cid = V4L2_CID_PRIVATE_BASE;
3212 queryctrl.id = i_cid;
3213 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3215 if( queryctrl.flags & V4L2_CTRL_FLAG_DISABLED )
3217 msg_Dbg( p_obj, "Available private control: %s (%x)",
3218 queryctrl.name, queryctrl.id );
3219 ControlListPrint( p_obj, i_fd, queryctrl, b_reset, b_demux );
3229 static void SetAvailControlsByString( vlc_object_t *p_obj, demux_sys_t *p_sys,
3232 char *psz_parser = p_sys->psz_set_ctrls;
3233 vlc_value_t val, text, name;
3235 if( psz_parser == NULL )
3238 if( *psz_parser == '{' )
3241 int i_ret = var_Change( p_obj, "allcontrols", VLC_VAR_GETCHOICES,
3245 msg_Err( p_obj, "Oops, can't find 'allcontrols' variable." );
3249 while( *psz_parser && *psz_parser != '}' )
3251 char *psz_delim, *psz_assign;
3253 while( *psz_parser == ',' || *psz_parser == ' ' )
3256 psz_delim = strchr( psz_parser, ',' );
3257 if( psz_delim == NULL )
3258 psz_delim = strchr( psz_parser, '}' );
3259 if( psz_delim == NULL )
3260 psz_delim = psz_parser + strlen( psz_parser );
3262 psz_assign = memchr( psz_parser, '=', psz_delim - psz_parser );
3263 if( psz_assign == NULL )
3265 char *psz_name = strndup( psz_parser, psz_delim - psz_parser );
3266 msg_Err( p_obj, "%s missing '='", psz_name );
3268 psz_parser = psz_delim + 1;
3273 i < val.p_list->i_count ;//&& psz_parser < psz_assign;
3276 const char *psz_var = text.p_list->p_values[i].psz_string;
3277 int i_cid = val.p_list->p_values[i].i_int;
3278 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
3279 const char *psz_name = name.psz_string;
3281 int i_availstrlen = strlen( psz_name );
3282 int i_parsestrlen = psz_assign - psz_parser;
3283 int i_maxstrlen = __MAX( i_availstrlen, i_parsestrlen);
3285 if( !strncasecmp( psz_name, psz_parser, i_maxstrlen ) )
3287 Control( p_obj, i_fd, psz_name, i_cid,
3288 strtol( ++psz_assign, &psz_parser, 0) );
3292 if( psz_parser < psz_assign )
3294 char *psz_name = strndup( psz_parser, psz_assign - psz_parser );
3295 msg_Err( p_obj, "Control %s not available", psz_name );
3297 psz_parser = ( *psz_delim ) ? ( psz_delim + 1 ) : psz_delim;
3302 /*****************************************************************************
3303 * Reset all user-class v4l2 controls to their default value
3304 *****************************************************************************/
3305 static int ControlReset( vlc_object_t *p_obj, int i_fd )
3307 struct v4l2_queryctrl queryctrl;
3309 memset( &queryctrl, 0, sizeof( queryctrl ) );
3311 queryctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
3312 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3314 /* Extended control API supported */
3315 queryctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
3316 while( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3318 if( queryctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS
3319 || V4L2_CTRL_ID2CLASS( queryctrl.id ) == V4L2_CTRL_CLASS_MPEG )
3321 queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
3324 struct v4l2_control control;
3325 memset( &control, 0, sizeof( control ) );
3326 control.id = queryctrl.id;
3327 if( ioctl( i_fd, VIDIOC_G_CTRL, &control ) >= 0
3328 && queryctrl.default_value != control.value )
3331 for( i = 0; controls[i].psz_name != NULL; i++ )
3332 if( controls[i].i_cid == queryctrl.id ) break;
3333 name2var( queryctrl.name );
3334 Control( p_obj, i_fd,
3335 controls[i].psz_name ? : (const char *)queryctrl.name,
3336 queryctrl.id, queryctrl.default_value );
3338 queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
3344 /* public controls */
3345 for( i_cid = V4L2_CID_BASE;
3346 i_cid < V4L2_CID_LASTP1;
3349 queryctrl.id = i_cid;
3350 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3352 struct v4l2_control control;
3353 if( queryctrl.flags & V4L2_CTRL_FLAG_DISABLED )
3355 memset( &control, 0, sizeof( control ) );
3356 control.id = queryctrl.id;
3357 if( ioctl( i_fd, VIDIOC_G_CTRL, &control ) >= 0
3358 && queryctrl.default_value != control.value )
3361 for( i = 0; controls[i].psz_name != NULL; i++ )
3362 if( controls[i].i_cid == queryctrl.id ) break;
3363 name2var( queryctrl.name );
3364 Control( p_obj, i_fd,
3365 controls[i].psz_name ? : (const char *)queryctrl.name,
3366 queryctrl.id, queryctrl.default_value );
3371 /* private controls */
3372 for( i_cid = V4L2_CID_PRIVATE_BASE;
3376 queryctrl.id = i_cid;
3377 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 )
3379 struct v4l2_control control;
3380 if( queryctrl.flags & V4L2_CTRL_FLAG_DISABLED )
3382 memset( &control, 0, sizeof( control ) );
3383 control.id = queryctrl.id;
3384 if( ioctl( i_fd, VIDIOC_G_CTRL, &control ) >= 0
3385 && queryctrl.default_value != control.value )
3387 name2var( queryctrl.name );
3388 Control( p_obj, i_fd, (const char *)queryctrl.name,
3389 queryctrl.id, queryctrl.default_value );
3399 /*****************************************************************************
3400 * Issue user-class v4l2 controls
3401 *****************************************************************************/
3402 static int Control( vlc_object_t *p_obj, int i_fd,
3403 const char *psz_name, int i_cid, int i_value )
3405 struct v4l2_queryctrl queryctrl;
3406 struct v4l2_control control;
3407 struct v4l2_ext_control ext_control;
3408 struct v4l2_ext_controls ext_controls;
3413 memset( &queryctrl, 0, sizeof( queryctrl ) );
3415 queryctrl.id = i_cid;
3417 if( ioctl( i_fd, VIDIOC_QUERYCTRL, &queryctrl ) < 0
3418 || queryctrl.flags & V4L2_CTRL_FLAG_DISABLED )
3420 msg_Dbg( p_obj, "%s (%x) control is not supported.", psz_name, i_cid );
3421 return VLC_EGENERIC;
3424 memset( &control, 0, sizeof( control ) );
3425 memset( &ext_control, 0, sizeof( ext_control ) );
3426 memset( &ext_controls, 0, sizeof( ext_controls ) );
3428 ext_control.id = i_cid;
3429 ext_controls.ctrl_class = V4L2_CTRL_ID2CLASS( i_cid );
3430 ext_controls.count = 1;
3431 ext_controls.controls = &ext_control;
3437 ext_control.value = i_value;
3438 if( ioctl( i_fd, VIDIOC_S_EXT_CTRLS, &ext_controls ) < 0 )
3440 control.value = i_value;
3441 if( ioctl( i_fd, VIDIOC_S_CTRL, &control ) < 0 )
3443 msg_Err( p_obj, "unable to set %s (%x) to %d (%m)",
3444 psz_name, i_cid, i_value );
3445 return VLC_EGENERIC;
3447 i_ret = ioctl( i_fd, VIDIOC_G_CTRL, &control );
3451 i_ret = ioctl( i_fd, VIDIOC_G_EXT_CTRLS, &ext_controls );
3452 control.value = ext_control.value;
3459 msg_Dbg( p_obj, "video %s: %d", psz_name, control.value );
3460 switch( var_Type( p_obj, psz_name ) & VLC_VAR_TYPE )
3463 val.b_bool = control.value;
3464 var_Change( p_obj, psz_name, VLC_VAR_SETVALUE, &val, NULL );
3465 var_SetVoid( p_obj, "controls-update" );
3467 case VLC_VAR_INTEGER:
3468 val.i_int = control.value;
3469 var_Change( p_obj, psz_name, VLC_VAR_SETVALUE, &val, NULL );
3470 var_SetVoid( p_obj, "controls-update" );
3477 /*****************************************************************************
3478 * On the fly change settings callback
3479 *****************************************************************************/
3480 static int DemuxControlCallback( vlc_object_t *p_this,
3481 const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
3484 demux_t *p_demux = (demux_t*)p_this;
3485 demux_sys_t *p_sys = p_demux->p_sys;
3486 int i_cid = (int)p_data;
3488 int i_fd = p_sys->i_fd_video;
3491 return VLC_EGENERIC;
3493 Control( p_this, i_fd, psz_var, i_cid, newval.i_int );
3495 return VLC_EGENERIC;
3498 static int DemuxControlResetCallback( vlc_object_t *p_this,
3499 const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
3502 demux_t *p_demux = (demux_t*)p_this;
3503 demux_sys_t *p_sys = p_demux->p_sys;
3505 int i_fd = p_sys->i_fd_video;
3508 return VLC_EGENERIC;
3510 ControlReset( p_this, i_fd );
3512 return VLC_EGENERIC;
3515 static int AccessControlCallback( vlc_object_t *p_this,
3516 const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
3519 access_t *p_access = (access_t *)p_this;
3520 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
3521 int i_cid = (int)p_data;
3523 int i_fd = p_sys->i_fd_video;
3526 return VLC_EGENERIC;
3528 Control( p_this, i_fd, psz_var, i_cid, newval.i_int );
3530 return VLC_EGENERIC;
3533 static int AccessControlResetCallback( vlc_object_t *p_this,
3534 const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
3537 access_t *p_access = (access_t *)p_this;
3538 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
3540 int i_fd = p_sys->i_fd_video;
3543 return VLC_EGENERIC;
3545 ControlReset( p_this, i_fd );
3547 return VLC_EGENERIC;