1 /*****************************************************************************
2 * v4l2.c : Video4Linux2 input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2009 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
32 /*****************************************************************************
34 *****************************************************************************/
41 #include <vlc_plugin.h>
42 #include <vlc_access.h>
44 #include <vlc_demux.h>
50 #include <sys/ioctl.h>
54 /*****************************************************************************
56 *****************************************************************************/
58 static int DemuxOpen ( vlc_object_t * );
59 static void DemuxClose( vlc_object_t * );
60 static int AccessOpen ( vlc_object_t * );
61 static void AccessClose( vlc_object_t * );
63 #define DEVICE_TEXT N_( "Device" )
64 #define DEVICE_LONGTEXT N_( \
65 "Video device (Default: /dev/video0)." )
66 #define STANDARD_TEXT N_( "Standard" )
67 #define STANDARD_LONGTEXT N_( \
68 "Video standard (Default, SECAM, PAL, or NTSC)." )
69 #define CHROMA_TEXT N_("Video input chroma format")
70 #define CHROMA_LONGTEXT N_( \
71 "Force the Video4Linux2 video device to use a specific chroma format " \
72 "(eg. I420 or I422 for raw images, MJPG for M-JPEG compressed input) " \
73 "(Complete list: GREY, I240, RV16, RV15, RV24, RV32, YUY2, YUYV, UYVY, " \
74 "I41N, I422, I420, I411, I410, MJPG)")
75 #define INPUT_TEXT N_( "Input" )
76 #define INPUT_LONGTEXT N_( \
77 "Input of the card to use (see debug)." )
78 #define AUDIO_INPUT_TEXT N_( "Audio input" )
79 #define AUDIO_INPUT_LONGTEXT N_( \
80 "Audio input of the card to use (see debug)." )
81 #define WIDTH_TEXT N_( "Width" )
82 #define WIDTH_LONGTEXT N_( \
83 "Force width (-1 for autodetect, 0 for driver default)." )
84 #define HEIGHT_TEXT N_( "Height" )
85 #define HEIGHT_LONGTEXT N_( \
86 "Force height (-1 for autodetect, 0 for driver default)." )
87 #define FPS_TEXT N_( "Framerate" )
88 #define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \
89 "(0 for autodetect)." )
92 #define LIBV4L2_TEXT N_( "Use libv4l2" )
93 #define LIBV4L2_LONGTEXT N_( \
94 "Force usage of the libv4l2 wrapper." )
97 #define CTRL_RESET_TEXT N_( "Reset v4l2 controls" )
98 #define CTRL_RESET_LONGTEXT N_( \
99 "Reset controls to defaults provided by the v4l2 driver." )
100 #define BRIGHTNESS_TEXT N_( "Brightness" )
101 #define BRIGHTNESS_LONGTEXT N_( \
102 "Brightness of the video input (if supported by the v4l2 driver)." )
103 #define CONTRAST_TEXT N_( "Contrast" )
104 #define CONTRAST_LONGTEXT N_( \
105 "Contrast of the video input (if supported by the v4l2 driver)." )
106 #define SATURATION_TEXT N_( "Saturation" )
107 #define SATURATION_LONGTEXT N_( \
108 "Saturation of the video input (if supported by the v4l2 driver)." )
109 #define HUE_TEXT N_( "Hue" )
110 #define HUE_LONGTEXT N_( \
111 "Hue of the video input (if supported by the v4l2 driver)." )
112 #define BLACKLEVEL_TEXT N_( "Black level" )
113 #define BLACKLEVEL_LONGTEXT N_( \
114 "Black level of the video input (if supported by the v4l2 driver)." )
115 #define AUTOWHITEBALANCE_TEXT N_( "Auto white balance" )
116 #define AUTOWHITEBALANCE_LONGTEXT N_( \
117 "Automatically set the white balance of the video input " \
118 "(if supported by the v4l2 driver)." )
119 #define DOWHITEBALANCE_TEXT N_( "Do white balance" )
120 #define DOWHITEBALANCE_LONGTEXT N_( \
121 "Trigger a white balancing action, useless if auto white balance is " \
122 "activated (if supported by the v4l2 driver)." )
123 #define REDBALANCE_TEXT N_( "Red balance" )
124 #define REDBALANCE_LONGTEXT N_( \
125 "Red balance of the video input (if supported by the v4l2 driver)." )
126 #define BLUEBALANCE_TEXT N_( "Blue balance" )
127 #define BLUEBALANCE_LONGTEXT N_( \
128 "Blue balance of the video input (if supported by the v4l2 driver)." )
129 #define GAMMA_TEXT N_( "Gamma" )
130 #define GAMMA_LONGTEXT N_( \
131 "Gamma of the video input (if supported by the v4l2 driver)." )
132 #define EXPOSURE_TEXT N_( "Exposure" )
133 #define EXPOSURE_LONGTEXT N_( \
134 "Exposure of the video input (if supported by the v4L2 driver)." )
135 #define AUTOGAIN_TEXT N_( "Auto gain" )
136 #define AUTOGAIN_LONGTEXT N_( \
137 "Automatically set the video input's gain (if supported by the " \
139 #define GAIN_TEXT N_( "Gain" )
140 #define GAIN_LONGTEXT N_( \
141 "Video input's gain (if supported by the v4l2 driver)." )
142 #define HFLIP_TEXT N_( "Horizontal flip" )
143 #define HFLIP_LONGTEXT N_( \
144 "Flip the video horizontally (if supported by the v4l2 driver)." )
145 #define VFLIP_TEXT N_( "Vertical flip" )
146 #define VFLIP_LONGTEXT N_( \
147 "Flip the video vertically (if supported by the v4l2 driver)." )
148 #define HCENTER_TEXT N_( "Horizontal centering" )
149 #define HCENTER_LONGTEXT N_( \
150 "Set the camera's horizontal centering (if supported by the v4l2 driver)." )
151 #define VCENTER_TEXT N_( "Vertical centering" )
152 #define VCENTER_LONGTEXT N_( \
153 "Set the camera's vertical centering (if supported by the v4l2 driver)." )
155 #define AUDIO_VOLUME_TEXT N_( "Volume" )
156 #define AUDIO_VOLUME_LONGTEXT N_( \
157 "Volume of the audio input (if supported by the v4l2 driver)." )
158 #define AUDIO_BALANCE_TEXT N_( "Balance" )
159 #define AUDIO_BALANCE_LONGTEXT N_( \
160 "Balance of the audio input (if supported by the v4l2 driver)." )
161 #define AUDIO_MUTE_TEXT N_( "Mute" )
162 #define AUDIO_MUTE_LONGTEXT N_( \
163 "Mute audio input (if supported by the v4l2 driver)." )
164 #define AUDIO_BASS_TEXT N_( "Bass" )
165 #define AUDIO_BASS_LONGTEXT N_( \
166 "Bass level of the audio input (if supported by the v4l2 driver)." )
167 #define AUDIO_TREBLE_TEXT N_( "Treble" )
168 #define AUDIO_TREBLE_LONGTEXT N_( \
169 "Treble level of the audio input (if supported by the v4l2 driver)." )
170 #define AUDIO_LOUDNESS_TEXT N_( "Loudness" )
171 #define AUDIO_LOUDNESS_LONGTEXT N_( \
172 "Loudness of the audio input (if supported by the v4l2 driver)." )
174 #define S_CTRLS_TEXT N_("v4l2 driver controls")
175 #define S_CTRLS_LONGTEXT N_( \
176 "Set the v4l2 driver controls to the values specified using a comma " \
177 "separated list optionally encapsulated by curly braces " \
178 "(e.g.: {video_bitrate=6000000,audio_crc=0,stream_type=3} ). " \
179 "To list available controls, increase verbosity (-vvv) " \
180 "or use the v4l2-ctl application." )
182 #define TUNER_TEXT N_("Tuner id")
183 #define TUNER_LONGTEXT N_( \
184 "Tuner id (see debug output)." )
185 #define FREQUENCY_TEXT N_("Frequency")
186 #define FREQUENCY_LONGTEXT N_( \
187 "Tuner frequency in Hz or kHz (see debug output)" )
188 #define TUNER_AUDIO_MODE_TEXT N_("Audio mode")
189 #define TUNER_AUDIO_MODE_LONGTEXT N_( \
190 "Tuner audio mono/stereo and track selection." )
192 #define ASPECT_TEXT N_("Picture aspect-ratio n:m")
193 #define ASPECT_LONGTEXT N_("Define input picture aspect-ratio to use. Default is 4:3" )
195 static const v4l2_std_id standards_v4l2[] = { V4L2_STD_UNKNOWN, V4L2_STD_ALL,
196 V4L2_STD_PAL, V4L2_STD_PAL_BG, V4L2_STD_PAL_DK,
198 V4L2_STD_SECAM, V4L2_STD_SECAM_DK,
199 V4L2_STD_525_60, V4L2_STD_625_50,
202 V4L2_STD_MN, V4L2_STD_B, V4L2_STD_GH, V4L2_STD_DK,
204 V4L2_STD_PAL_B, V4L2_STD_PAL_B1, V4L2_STD_PAL_G, V4L2_STD_PAL_H,
205 V4L2_STD_PAL_I, V4L2_STD_PAL_D, V4L2_STD_PAL_D1, V4L2_STD_PAL_K,
206 V4L2_STD_PAL_M, V4L2_STD_PAL_N, V4L2_STD_PAL_Nc, V4L2_STD_PAL_60,
207 V4L2_STD_NTSC_M, V4L2_STD_NTSC_M_JP,V4L2_STD_NTSC_443, V4L2_STD_NTSC_M_KR,
208 V4L2_STD_SECAM_B, V4L2_STD_SECAM_D, V4L2_STD_SECAM_G, V4L2_STD_SECAM_H,
209 V4L2_STD_SECAM_K, V4L2_STD_SECAM_K1, V4L2_STD_SECAM_L, V4L2_STD_SECAM_LC,
210 V4L2_STD_ATSC_8_VSB, V4L2_STD_ATSC_16_VSB,
212 static const char *const standards_vlc[] = { "", "ALL",
213 /* Pseudo standards */
214 "PAL", "PAL_BG", "PAL_DK",
220 /* Areas (PAL/NTSC or PAL/SECAM) */
221 "MN", "B", "GH", "DK",
223 /* Individual standards */
224 "PAL_B", "PAL_B1", "PAL_G", "PAL_H",
225 "PAL_I", "PAL_D", "PAL_D1", "PAL_K",
226 "PAL_M", "PAL_N", "PAL_Nc", "PAL_60",
227 "NTSC_M", "NTSC_M_JP", "NTSC_443", "NTSC_M_KR",
228 "SECAM_B", "SECAM_D", "SECAM_G", "SECAM_H",
229 "SECAM_K", "SECAM_K1", "SECAM_L", "SECAM_LC",
230 "ATSC_8_VSB", "ATSC_16_VSB",
232 static const char *const standards_user[] = { N_("Undefined"), N_("All"),
233 "PAL", "PAL B/G", "PAL D/K",
235 "SECAM", "SECAM D/K",
236 N_("525 lines / 60 Hz"), N_("625 lines / 50 Hz"),
240 "PAL/SECAM B", "PAL/SECAM G/H", "PAL/SECAM D/K",
242 "PAL B", "PAL B1", "PAL G", "PAL H",
243 "PAL I", "PAL D", "PAL D1", "PAL K",
244 "PAL M", "PAL N", N_("PAL N Argentina"), "PAL 60",
245 "NTSC M", N_("NTSC M Japan"), "NTSC 443", N_("NTSC M South Korea"),
246 "SECAM B", "SECAM D", "SECAM G", "SECAM H",
247 "SECAM K", "SECAM K1", "SECAM L", "SECAM L/C",
248 "ATSC 8-VSB", "ATSC 16-VSB",
251 static const int i_tuner_audio_modes_list[] = {
252 -1, V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO,
253 V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2,
254 V4L2_TUNER_MODE_SAP, V4L2_TUNER_MODE_LANG1_LANG2 };
255 static const char *const psz_tuner_audio_modes_list_text[] = {
259 N_( "Primary language (Analog TV tuners only)" ),
260 N_( "Secondary language (Analog TV tuners only)" ),
261 N_( "Second audio program (Analog TV tuners only)" ),
262 N_( "Primary language left, Secondary language right" ) };
264 #define V4L2_DEFAULT "/dev/video0"
267 # define DEFAULT_WIDTH 640
268 # define DEFAULT_HEIGHT 492
271 #ifndef DEFAULT_WIDTH
272 # define DEFAULT_WIDTH (-1)
273 # define DEFAULT_HEIGHT (-1)
277 set_shortname( N_("Video4Linux2") )
278 set_description( N_("Video4Linux2 input") )
279 set_category( CAT_INPUT )
280 set_subcategory( SUBCAT_INPUT_ACCESS )
282 set_section( N_( "Video input" ), NULL )
283 add_string( CFG_PREFIX "dev", "/dev/video0", DEVICE_TEXT, DEVICE_LONGTEXT,
286 add_string( CFG_PREFIX "standard", "",
287 STANDARD_TEXT, STANDARD_LONGTEXT, false )
288 change_string_list( standards_vlc, standards_user, NULL )
290 add_string( CFG_PREFIX "chroma", NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
293 add_integer( CFG_PREFIX "input", 0, INPUT_TEXT, INPUT_LONGTEXT,
295 change_integer_range( 0, 0xFFFFFFFE )
297 add_integer( CFG_PREFIX "audio-input", -1, AUDIO_INPUT_TEXT,
298 AUDIO_INPUT_LONGTEXT, true )
299 change_integer_range( -1, 0xFFFFFFFE )
301 add_obsolete_integer( CFG_PREFIX "io" ) /* since 1.2.0 */
302 add_integer( CFG_PREFIX "width", DEFAULT_WIDTH, WIDTH_TEXT,
303 WIDTH_LONGTEXT, true )
305 add_integer( CFG_PREFIX "height", DEFAULT_HEIGHT, HEIGHT_TEXT,
306 HEIGHT_LONGTEXT, true )
308 add_string( CFG_PREFIX "aspect-ratio", "4:3", ASPECT_TEXT,
309 ASPECT_LONGTEXT, true )
311 add_float( CFG_PREFIX "fps", 0, FPS_TEXT, FPS_LONGTEXT, true )
314 add_bool( CFG_PREFIX "use-libv4l2", false, LIBV4L2_TEXT, LIBV4L2_LONGTEXT, true );
317 set_section( N_( "Tuner" ), NULL )
318 add_integer( CFG_PREFIX "tuner", 0, TUNER_TEXT, TUNER_LONGTEXT,
320 change_integer_range( 0, 0xFFFFFFFE )
322 add_integer( CFG_PREFIX "tuner-frequency", -1, FREQUENCY_TEXT,
323 FREQUENCY_LONGTEXT, true )
324 change_integer_range( -1, 0xFFFFFFFE )
326 add_integer( CFG_PREFIX "tuner-audio-mode", -1, TUNER_AUDIO_MODE_TEXT,
327 TUNER_AUDIO_MODE_LONGTEXT, true )
328 change_integer_list( i_tuner_audio_modes_list,
329 psz_tuner_audio_modes_list_text )
332 set_section( N_( "Controls" ),
333 N_( "v4l2 driver controls, if supported by your v4l2 driver." ) )
334 add_bool( CFG_PREFIX "controls-reset", false, CTRL_RESET_TEXT,
335 CTRL_RESET_LONGTEXT, true )
337 add_integer( CFG_PREFIX "brightness", -1, BRIGHTNESS_TEXT,
338 BRIGHTNESS_LONGTEXT, true )
339 add_integer( CFG_PREFIX "contrast", -1, CONTRAST_TEXT,
340 CONTRAST_LONGTEXT, true )
341 add_integer( CFG_PREFIX "saturation", -1, SATURATION_TEXT,
342 SATURATION_LONGTEXT, true )
343 add_integer( CFG_PREFIX "hue", -1, HUE_TEXT,
345 add_integer( CFG_PREFIX "black-level", -1, BLACKLEVEL_TEXT,
346 BLACKLEVEL_LONGTEXT, true )
347 add_integer( CFG_PREFIX "auto-white-balance", -1,
348 AUTOWHITEBALANCE_TEXT, AUTOWHITEBALANCE_LONGTEXT, true )
349 add_integer( CFG_PREFIX "do-white-balance", -1, DOWHITEBALANCE_TEXT,
350 DOWHITEBALANCE_LONGTEXT, true )
351 add_integer( CFG_PREFIX "red-balance", -1, REDBALANCE_TEXT,
352 REDBALANCE_LONGTEXT, true )
353 add_integer( CFG_PREFIX "blue-balance", -1, BLUEBALANCE_TEXT,
354 BLUEBALANCE_LONGTEXT, true )
355 add_integer( CFG_PREFIX "gamma", -1, GAMMA_TEXT,
356 GAMMA_LONGTEXT, true )
357 add_integer( CFG_PREFIX "exposure", -1, EXPOSURE_TEXT,
358 EXPOSURE_LONGTEXT, true )
359 add_integer( CFG_PREFIX "autogain", -1, AUTOGAIN_TEXT,
360 AUTOGAIN_LONGTEXT, true )
361 add_integer( CFG_PREFIX "gain", -1, GAIN_TEXT,
362 GAIN_LONGTEXT, true )
363 add_integer( CFG_PREFIX "hflip", -1, HFLIP_TEXT,
364 HFLIP_LONGTEXT, true )
365 add_integer( CFG_PREFIX "vflip", -1, VFLIP_TEXT,
366 VFLIP_LONGTEXT, true )
367 add_integer( CFG_PREFIX "hcenter", -1, HCENTER_TEXT,
368 HCENTER_LONGTEXT, true )
369 add_integer( CFG_PREFIX "vcenter", -1, VCENTER_TEXT,
370 VCENTER_LONGTEXT, true )
371 add_integer( CFG_PREFIX "audio-volume", -1, AUDIO_VOLUME_TEXT,
372 AUDIO_VOLUME_LONGTEXT, true )
373 add_integer( CFG_PREFIX "audio-balance", -1, AUDIO_BALANCE_TEXT,
374 AUDIO_BALANCE_LONGTEXT, true )
375 add_bool( CFG_PREFIX "audio-mute", false, AUDIO_MUTE_TEXT,
376 AUDIO_MUTE_LONGTEXT, true )
377 add_integer( CFG_PREFIX "audio-bass", -1, AUDIO_BASS_TEXT,
378 AUDIO_BASS_LONGTEXT, true )
379 add_integer( CFG_PREFIX "audio-treble", -1, AUDIO_TREBLE_TEXT,
380 AUDIO_TREBLE_LONGTEXT, true )
381 add_integer( CFG_PREFIX "audio-loudness", -1, AUDIO_LOUDNESS_TEXT,
382 AUDIO_LOUDNESS_LONGTEXT, true )
383 add_string( CFG_PREFIX "set-ctrls", NULL, S_CTRLS_TEXT,
384 S_CTRLS_LONGTEXT, true )
387 add_obsolete_string( CFG_PREFIX "adev" )
388 add_obsolete_integer( CFG_PREFIX "audio-method" )
389 add_obsolete_bool( CFG_PREFIX "stereo" )
390 add_obsolete_integer( CFG_PREFIX "samplerate" )
392 add_shortcut( "v4l2" )
393 set_capability( "access_demux", 0 )
394 set_callbacks( DemuxOpen, DemuxClose )
397 add_shortcut( "v4l2", "v4l2c" )
398 set_description( N_("Video4Linux2 Compressed A/V") )
399 set_capability( "access", 0 )
400 /* use these when open as access_demux fails; VLC will use another demux */
401 set_callbacks( AccessOpen, AccessClose )
405 /*****************************************************************************
406 * Access: local prototypes
407 *****************************************************************************/
409 static void CommonClose( vlc_object_t *, demux_sys_t * );
410 static void ParseMRL( vlc_object_t *, const char * );
412 static int DemuxControl( demux_t *, int, va_list );
413 static int AccessControl( access_t *, int, va_list );
415 static int Demux( demux_t * );
416 static block_t *AccessRead( access_t * );
417 static ssize_t AccessReadStream( access_t * p_access, uint8_t * p_buffer, size_t i_len );
419 static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys );
420 static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size_t );
422 static int OpenVideoDev( vlc_object_t *, demux_sys_t *, bool );
427 vlc_fourcc_t i_fourcc;
431 } v4l2chroma_to_fourcc[] =
434 { V4L2_PIX_FMT_GREY, VLC_CODEC_GREY, 0, 0, 0 },
435 { V4L2_PIX_FMT_HI240, VLC_FOURCC('I','2','4','0'), 0, 0, 0 },
436 { V4L2_PIX_FMT_RGB555, VLC_CODEC_RGB15, 0x001f,0x03e0,0x7c00 },
437 { V4L2_PIX_FMT_RGB565, VLC_CODEC_RGB16, 0x001f,0x07e0,0xf800 },
438 /* Won't work since we don't know how to handle such gmask values
440 { V4L2_PIX_FMT_RGB555X, VLC_CODEC_RGB15, 0x007c,0xe003,0x1f00 },
441 { V4L2_PIX_FMT_RGB565X, VLC_CODEC_RGB16, 0x00f8,0xe007,0x1f00 },
443 { V4L2_PIX_FMT_BGR24, VLC_CODEC_RGB24, 0xff0000,0xff00,0xff },
444 { V4L2_PIX_FMT_RGB24, VLC_CODEC_RGB24, 0xff,0xff00,0xff0000 },
445 { V4L2_PIX_FMT_BGR32, VLC_CODEC_RGB32, 0xff0000,0xff00,0xff },
446 { V4L2_PIX_FMT_RGB32, VLC_CODEC_RGB32, 0xff,0xff00,0xff0000 },
447 { V4L2_PIX_FMT_YUYV, VLC_CODEC_YUYV, 0, 0, 0 },
448 { V4L2_PIX_FMT_UYVY, VLC_CODEC_UYVY, 0, 0, 0 },
449 { V4L2_PIX_FMT_Y41P, VLC_FOURCC('I','4','1','N'), 0, 0, 0 },
450 { V4L2_PIX_FMT_YUV422P, VLC_CODEC_I422, 0, 0, 0 },
451 { V4L2_PIX_FMT_YVU420, VLC_CODEC_YV12, 0, 0, 0 },
452 { V4L2_PIX_FMT_YUV411P, VLC_CODEC_I411, 0, 0, 0 },
453 { V4L2_PIX_FMT_YUV410, VLC_CODEC_I410, 0, 0, 0 },
455 /* Raw data types, not in V4L2 spec but still in videodev2.h and supported
457 { V4L2_PIX_FMT_YUV420, VLC_CODEC_I420, 0, 0, 0 },
458 /* FIXME { V4L2_PIX_FMT_RGB444, VLC_CODEC_RGB32 }, */
460 /* Compressed data types */
461 { V4L2_PIX_FMT_MJPEG, VLC_CODEC_MJPG, 0, 0, 0 },
462 { V4L2_PIX_FMT_JPEG, VLC_CODEC_JPEG, 0, 0, 0 },
464 { V4L2_PIX_FMT_DV, VLC_FOURCC('?','?','?','?') },
465 { V4L2_PIX_FMT_MPEG, VLC_FOURCC('?','?','?','?') },
471 * List of V4L2 chromas were confident enough to use as fallbacks if the
472 * user hasn't provided a --v4l2-chroma value.
474 * Try YUV chromas first, then RGB little endian and MJPEG as last resort.
476 static const uint32_t p_chroma_fallbacks[] =
477 { V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV422P,
478 V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_BGR24,
479 V4L2_PIX_FMT_BGR32, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_JPEG };
487 /*****************************************************************************
488 * DemuxOpen: opens v4l2 device, access_demux callback
489 *****************************************************************************
491 * url: <video device>::::
493 *****************************************************************************/
494 static int DemuxOpen( vlc_object_t *p_this )
496 demux_t *p_demux = (demux_t*)p_this;
500 p_demux->pf_control = DemuxControl;
501 p_demux->pf_demux = Demux;
502 p_demux->info.i_update = 0;
503 p_demux->info.i_title = 0;
504 p_demux->info.i_seekpoint = 0;
506 p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
507 if( p_sys == NULL ) return VLC_ENOMEM;
509 ParseMRL( p_this, p_demux->psz_location );
513 if( !var_InheritBool( p_this, CFG_PREFIX "use-libv4l2" ) )
515 p_sys->b_libv4l2 = false;
517 msg_Dbg( p_this, "Trying direct kernel v4l2" );
518 p_sys->i_fd = OpenVideoDev( p_this, p_sys, true );
522 if( p_sys->i_fd == -1 )
524 p_sys->b_libv4l2 = true;
525 msg_Dbg( p_this, "Trying libv4l2 wrapper" );
526 p_sys->i_fd = OpenVideoDev( p_this, p_sys, true );
529 if( p_sys->i_fd == -1 )
538 * Parses a V4L2 MRL into VLC object variables.
540 static void ParseMRL( vlc_object_t *obj, const char *mrl )
542 const char *p = strchr( mrl, ':' );
547 var_LocationParse( obj, p + 1, CFG_PREFIX );
549 dev = strndup( mrl, p - mrl );
559 var_Create( obj, CFG_PREFIX"dev", VLC_VAR_STRING );
560 var_SetString( obj, CFG_PREFIX"dev", dev );
565 /*****************************************************************************
566 * Close: close device, free resources
567 *****************************************************************************/
568 static void AccessClose( vlc_object_t *p_this )
570 access_t *p_access = (access_t *)p_this;
571 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
573 CommonClose( p_this, p_sys );
576 static void DemuxClose( vlc_object_t *p_this )
578 struct v4l2_buffer buf;
579 enum v4l2_buf_type buf_type;
582 demux_t *p_demux = (demux_t *)p_this;
583 demux_sys_t *p_sys = p_demux->p_sys;
585 /* Stop video capture */
586 if( p_sys->i_fd >= 0 )
595 case IO_METHOD_USERPTR:
596 /* Some drivers 'hang' internally if this is not done before streamoff */
597 for( unsigned int i = 0; i < p_sys->i_nbuffers; i++ )
599 memset( &buf, 0, sizeof(buf) );
600 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
601 buf.memory = ( p_sys->io == IO_METHOD_USERPTR ) ?
602 V4L2_MEMORY_USERPTR : V4L2_MEMORY_MMAP;
603 v4l2_ioctl( p_sys->i_fd, VIDIOC_DQBUF, &buf ); /* ignore result */
606 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
607 if( v4l2_ioctl( p_sys->i_fd, VIDIOC_STREAMOFF, &buf_type ) < 0 ) {
608 msg_Err( p_this, "VIDIOC_STREAMOFF failed" );
615 /* Free Video Buffers */
616 if( p_sys->p_buffers ) {
620 free( p_sys->p_buffers[0].start );
624 for( i = 0; i < p_sys->i_nbuffers; ++i )
626 if( v4l2_munmap( p_sys->p_buffers[i].start, p_sys->p_buffers[i].length ) )
628 msg_Err( p_this, "munmap failed" );
633 case IO_METHOD_USERPTR:
634 for( i = 0; i < p_sys->i_nbuffers; ++i )
636 free( p_sys->p_buffers[i].start );
640 free( p_sys->p_buffers );
643 CommonClose( p_this, p_sys );
646 static void CommonClose( vlc_object_t *p_this, demux_sys_t *p_sys )
650 if( p_sys->i_fd >= 0 ) v4l2_close( p_sys->i_fd );
654 /*****************************************************************************
655 * AccessOpen: opens v4l2 device, access callback
656 *****************************************************************************
658 * url: <video device>::::
660 *****************************************************************************/
661 static int AccessOpen( vlc_object_t * p_this )
663 access_t *p_access = (access_t*) p_this;
666 /* Only when selected */
667 if( *p_access->psz_access == '\0' ) return VLC_EGENERIC;
669 access_InitFields( p_access );
670 p_sys = calloc( 1, sizeof( demux_sys_t ));
671 if( !p_sys ) return VLC_ENOMEM;
672 p_access->p_sys = (access_sys_t*)p_sys;
674 ParseMRL( p_this, p_access->psz_location );
678 if( !var_InheritBool( p_this, CFG_PREFIX "use-libv4l2" ) )
680 p_sys->b_libv4l2 = false;
682 msg_Dbg( p_this, "Trying direct kernel v4l2" );
683 p_sys->i_fd = OpenVideoDev( p_this, p_sys, false );
686 if( p_sys->i_fd == -1 )
688 p_sys->b_libv4l2 = true;
689 msg_Dbg( p_this, "Trying libv4l2 wrapper" );
690 p_sys->i_fd = OpenVideoDev( p_this, p_sys, false );
693 if( p_sys->i_fd == -1 )
699 if( p_sys->io == IO_METHOD_READ )
700 ACCESS_SET_CALLBACKS( AccessReadStream, NULL, AccessControl, NULL );
702 ACCESS_SET_CALLBACKS( NULL, AccessRead, AccessControl, NULL );
706 /*****************************************************************************
708 *****************************************************************************/
709 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
713 /* Special for access_demux */
714 case DEMUX_CAN_PAUSE:
716 case DEMUX_CAN_CONTROL_PACE:
717 *va_arg( args, bool * ) = false;
720 case DEMUX_GET_PTS_DELAY:
721 *va_arg(args,int64_t *) = INT64_C(1000)
722 * var_InheritInteger( p_demux, "live-caching" );
726 *va_arg( args, int64_t * ) = mdate();
729 /* TODO implement others */
737 /*****************************************************************************
738 * AccessControl: access callback
739 *****************************************************************************/
740 static int AccessControl( access_t *p_access, int i_query, va_list args )
745 case ACCESS_CAN_SEEK:
746 case ACCESS_CAN_FASTSEEK:
747 case ACCESS_CAN_PAUSE:
748 case ACCESS_CAN_CONTROL_PACE:
749 *va_arg( args, bool* ) = false;
753 case ACCESS_GET_PTS_DELAY:
754 *va_arg(args,int64_t *) = INT64_C(1000)
755 * var_InheritInteger( p_access, "live-caching" );
759 case ACCESS_SET_PAUSE_STATE:
763 case ACCESS_GET_TITLE_INFO:
764 case ACCESS_SET_TITLE:
765 case ACCESS_SET_SEEKPOINT:
766 case ACCESS_SET_PRIVATE_ID_STATE:
767 case ACCESS_GET_CONTENT_TYPE:
768 case ACCESS_GET_META:
772 msg_Warn( p_access, "Unimplemented query in control(%d).", i_query);
779 /*****************************************************************************
780 * AccessRead: access callback
781 ******************************************************************************/
782 static block_t *AccessRead( access_t * p_access )
784 demux_sys_t *p_sys = (demux_sys_t *)p_access->p_sys;
788 fd.events = POLLIN|POLLPRI;
792 if( poll( &fd, 1, 500 ) > 0 ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
793 return GrabVideo( VLC_OBJECT(p_access), p_sys );
798 static ssize_t AccessReadStream( access_t * p_access, uint8_t * p_buffer, size_t i_len )
800 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
804 ufd.fd = p_sys->i_fd;
807 if( p_access->info.b_eof )
812 if( !vlc_object_alive (p_access) )
817 while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );
822 msg_Err( p_access, "poll error" );
826 i_ret = v4l2_read( p_sys->i_fd, p_buffer, i_len );
829 p_access->info.b_eof = true;
833 p_access->info.i_pos += i_ret;
839 /*****************************************************************************
840 * Demux: Processes the audio or video frame
841 *****************************************************************************/
842 static int Demux( demux_t *p_demux )
844 demux_sys_t *p_sys = p_demux->p_sys;
848 fd.events = POLLIN|POLLPRI;
852 /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
853 while( poll( &fd, 1, 500 ) == -1 )
856 msg_Err( p_demux, "poll error: %m" );
862 block_t *p_block = GrabVideo( VLC_OBJECT(p_demux), p_sys );
865 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
866 es_out_Send( p_demux->out, p_sys->p_es, p_block );
873 /*****************************************************************************
874 * GrabVideo: Grab a video frame
875 *****************************************************************************/
876 static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys )
879 struct v4l2_buffer buf;
882 /* Grab Video Frame */
886 i_ret = v4l2_read( p_sys->i_fd, p_sys->p_buffers[0].start, p_sys->p_buffers[0].length );
894 /* Could ignore EIO, see spec. */
897 msg_Err( p_demux, "Failed to read frame" );
902 p_block = ProcessVideoFrame( p_demux, (uint8_t*)p_sys->p_buffers[0].start, i_ret );
909 memset( &buf, 0, sizeof(buf) );
910 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
911 buf.memory = V4L2_MEMORY_MMAP;
913 /* Wait for next frame */
914 if (v4l2_ioctl( p_sys->i_fd, VIDIOC_DQBUF, &buf ) < 0 )
921 /* Could ignore EIO, see spec. */
924 msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" );
929 if( buf.index >= p_sys->i_nbuffers ) {
930 msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" );
934 p_block = ProcessVideoFrame( p_demux, p_sys->p_buffers[buf.index].start, buf.bytesused );
939 if( v4l2_ioctl( p_sys->i_fd, VIDIOC_QBUF, &buf ) < 0 )
941 msg_Err( p_demux, "Failed to unlock (VIDIOC_QBUF)" );
942 block_Release( p_block );
948 case IO_METHOD_USERPTR:
949 memset( &buf, 0, sizeof(buf) );
950 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
951 buf.memory = V4L2_MEMORY_USERPTR;
953 /* Wait for next frame */
954 if (v4l2_ioctl( p_sys->i_fd, VIDIOC_DQBUF, &buf ) < 0 )
961 /* Could ignore EIO, see spec. */
964 msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" );
971 for( i = 0; i < p_sys->i_nbuffers; i++ )
973 if( buf.m.userptr == (unsigned long)p_sys->p_buffers[i].start &&
974 buf.length == p_sys->p_buffers[i].length ) break;
977 if( i >= p_sys->i_nbuffers )
979 msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" );
983 p_block = ProcessVideoFrame( p_demux, (uint8_t*)buf.m.userptr, buf.bytesused );
988 if( v4l2_ioctl( p_sys->i_fd, VIDIOC_QBUF, &buf ) < 0 )
990 msg_Err( p_demux, "Failed to unlock (VIDIOC_QBUF)" );
991 block_Release( p_block );
999 p_block->i_pts = p_block->i_dts = mdate();
1000 p_block->i_flags |= p_sys->i_block_flags;
1005 /*****************************************************************************
1006 * ProcessVideoFrame: Helper function to take a buffer and copy it into
1008 *****************************************************************************/
1009 static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size_t i_size )
1013 if( !p_frame ) return NULL;
1016 if( !( p_block = block_New( p_demux, i_size ) ) )
1018 msg_Warn( p_demux, "Cannot get new block" );
1023 memcpy( p_block->p_buffer, p_frame, i_size );
1028 /*****************************************************************************
1029 * Helper function to initalise video IO using the Read method
1030 *****************************************************************************/
1031 static int InitRead( vlc_object_t *p_demux, demux_sys_t *p_sys, unsigned int i_buffer_size )
1035 p_sys->p_buffers = calloc( 1, sizeof( *p_sys->p_buffers ) );
1036 if( unlikely(p_sys->p_buffers == NULL) )
1039 p_sys->p_buffers[0].length = i_buffer_size;
1040 p_sys->p_buffers[0].start = malloc( i_buffer_size );
1041 if( !p_sys->p_buffers[0].start )
1047 /*****************************************************************************
1048 * Helper function to initalise video IO using the mmap method
1049 *****************************************************************************/
1050 static int InitMmap( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd )
1052 struct v4l2_requestbuffers req;
1054 memset( &req, 0, sizeof(req) );
1056 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1057 req.memory = V4L2_MEMORY_MMAP;
1059 if( v4l2_ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
1061 msg_Err( p_demux, "device does not support mmap I/O" );
1067 msg_Err( p_demux, "insufficient buffers" );
1071 p_sys->p_buffers = calloc( req.count, sizeof( *p_sys->p_buffers ) );
1072 if( unlikely(!p_sys->p_buffers) )
1075 for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < req.count; ++p_sys->i_nbuffers )
1077 struct v4l2_buffer buf;
1079 memset( &buf, 0, sizeof(buf) );
1080 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1081 buf.memory = V4L2_MEMORY_MMAP;
1082 buf.index = p_sys->i_nbuffers;
1084 if( v4l2_ioctl( i_fd, VIDIOC_QUERYBUF, &buf ) < 0 )
1086 msg_Err( p_demux, "VIDIOC_QUERYBUF: %m" );
1090 p_sys->p_buffers[p_sys->i_nbuffers].length = buf.length;
1091 p_sys->p_buffers[p_sys->i_nbuffers].start =
1092 v4l2_mmap( NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, buf.m.offset );
1094 if( p_sys->p_buffers[p_sys->i_nbuffers].start == MAP_FAILED )
1096 msg_Err( p_demux, "mmap failed: %m" );
1104 /*****************************************************************************
1105 * Helper function to initalise video IO using the userbuf method
1106 *****************************************************************************/
1107 static int InitUserP( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd, unsigned int i_buffer_size )
1109 struct v4l2_requestbuffers req;
1110 unsigned int i_page_size;
1112 i_page_size = sysconf(_SC_PAGESIZE);
1113 i_buffer_size = ( i_buffer_size + i_page_size - 1 ) & ~( i_page_size - 1);
1115 memset( &req, 0, sizeof(req) );
1117 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1118 req.memory = V4L2_MEMORY_USERPTR;
1120 if( v4l2_ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
1122 msg_Err( p_demux, "device does not support user pointer i/o" );
1126 p_sys->p_buffers = calloc( 4, sizeof( *p_sys->p_buffers ) );
1127 if( !p_sys->p_buffers )
1130 for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < 4; ++p_sys->i_nbuffers )
1132 p_sys->p_buffers[p_sys->i_nbuffers].length = i_buffer_size;
1133 if( posix_memalign( &p_sys->p_buffers[p_sys->i_nbuffers].start,
1134 /* boundary */ i_page_size, i_buffer_size ) )
1142 * \return true if the specified V4L2 pixel format is
1143 * in the array of supported formats returned by the driver
1145 static bool IsPixelFormatSupported( struct v4l2_fmtdesc *codecs, size_t n,
1146 unsigned int i_pixelformat )
1148 for( size_t i = 0; i < n; i++ )
1149 if( codecs[i].pixelformat == i_pixelformat )
1154 static float GetMaxFrameRate( int i_fd, uint32_t i_pixel_format,
1155 uint32_t i_width, uint32_t i_height )
1157 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
1158 /* This is new in Linux 2.6.19 */
1159 struct v4l2_frmivalenum frmival;
1160 memset( &frmival, 0, sizeof(frmival) );
1161 frmival.pixel_format = i_pixel_format;
1162 frmival.width = i_width;
1163 frmival.height = i_height;
1164 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 )
1166 switch( frmival.type )
1168 case V4L2_FRMIVAL_TYPE_DISCRETE:
1170 float f_fps_max = -1;
1173 float f_fps = (float)frmival.discrete.denominator
1174 / (float)frmival.discrete.numerator;
1175 if( f_fps > f_fps_max ) f_fps_max = f_fps;
1177 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS,
1181 case V4L2_FRMSIZE_TYPE_STEPWISE:
1182 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1183 return __MAX( (float)frmival.stepwise.max.denominator
1184 / (float)frmival.stepwise.max.numerator,
1185 (float)frmival.stepwise.min.denominator
1186 / (float)frmival.stepwise.min.numerator );
1193 static float GetAbsoluteMaxFrameRate( demux_t *p_demux, int i_fd,
1194 uint32_t i_pixel_format )
1196 float f_fps_max = -1.;
1197 #ifdef VIDIOC_ENUM_FRAMESIZES
1198 /* This is new in Linux 2.6.19 */
1199 struct v4l2_frmsizeenum frmsize;
1200 memset( &frmsize, 0, sizeof(frmsize) );
1201 frmsize.pixel_format = i_pixel_format;
1202 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) >= 0 )
1204 switch( frmsize.type )
1206 case V4L2_FRMSIZE_TYPE_DISCRETE:
1210 float f_fps = GetMaxFrameRate( i_fd, i_pixel_format,
1211 frmsize.discrete.width,
1212 frmsize.discrete.height );
1213 if( f_fps > f_fps_max ) f_fps_max = f_fps;
1214 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES,
1217 case V4L2_FRMSIZE_TYPE_STEPWISE:
1219 uint32_t i_width = frmsize.stepwise.min_width;
1220 uint32_t i_height = frmsize.stepwise.min_height;
1222 i_width <= frmsize.stepwise.max_width &&
1223 i_height <= frmsize.stepwise.max_width;
1224 i_width += frmsize.stepwise.step_width,
1225 i_height += frmsize.stepwise.step_height )
1227 float f_fps = GetMaxFrameRate( i_fd, i_pixel_format,
1228 i_width, i_height );
1229 if( f_fps > f_fps_max ) f_fps_max = f_fps;
1233 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1235 msg_Err( p_demux, "GetAbsoluteMaxFrameRate implementation for V4L2_FRMSIZE_TYPE_CONTINUOUS isn't correct" );
1236 f_fps_max = GetMaxFrameRate( i_fd, i_pixel_format,
1237 frmsize.stepwise.max_width,
1238 frmsize.stepwise.max_height );
1246 static void GetMaxDimensions( demux_t *p_demux, int i_fd,
1247 uint32_t i_pixel_format, float f_fps_min,
1248 uint32_t *pi_width, uint32_t *pi_height )
1252 #ifdef VIDIOC_ENUM_FRAMESIZES
1253 /* This is new in Linux 2.6.19 */
1254 struct v4l2_frmsizeenum frmsize;
1255 memset( &frmsize, 0, sizeof(frmsize) );
1256 frmsize.pixel_format = i_pixel_format;
1257 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) >= 0 )
1259 switch( frmsize.type )
1261 case V4L2_FRMSIZE_TYPE_DISCRETE:
1265 float f_fps = GetMaxFrameRate( i_fd, i_pixel_format,
1266 frmsize.discrete.width,
1267 frmsize.discrete.height );
1268 if( f_fps >= f_fps_min &&
1269 frmsize.discrete.width > *pi_width )
1271 *pi_width = frmsize.discrete.width;
1272 *pi_height = frmsize.discrete.height;
1274 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES,
1277 case V4L2_FRMSIZE_TYPE_STEPWISE:
1279 uint32_t i_width = frmsize.stepwise.min_width;
1280 uint32_t i_height = frmsize.stepwise.min_height;
1282 i_width <= frmsize.stepwise.max_width &&
1283 i_height <= frmsize.stepwise.max_width;
1284 i_width += frmsize.stepwise.step_width,
1285 i_height += frmsize.stepwise.step_height )
1287 float f_fps = GetMaxFrameRate( i_fd, i_pixel_format,
1288 i_width, i_height );
1289 if( f_fps >= f_fps_min && i_width > *pi_width )
1291 *pi_width = i_width;
1292 *pi_height = i_height;
1297 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1299 msg_Err( p_demux, "GetMaxDimension implementation for V4L2_FRMSIZE_TYPE_CONTINUOUS isn't correct" );
1300 float f_fps = GetMaxFrameRate( i_fd, i_pixel_format,
1301 frmsize.stepwise.max_width,
1302 frmsize.stepwise.max_height );
1303 if( f_fps >= f_fps_min &&
1304 frmsize.stepwise.max_width > *pi_width )
1306 *pi_width = frmsize.stepwise.max_width;
1307 *pi_height = frmsize.stepwise.max_height;
1316 * Opens and sets up a video device
1317 * \return file descriptor or -1 on error
1319 static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
1321 struct v4l2_cropcap cropcap;
1322 struct v4l2_crop crop;
1323 struct v4l2_format fmt;
1325 enum v4l2_buf_type buf_type;
1327 struct v4l2_fmtdesc *codecs = NULL;
1329 char *path = var_InheritString( p_obj, CFG_PREFIX"dev" );
1330 if( unlikely(path == NULL) )
1331 return -1; /* probably OOM */
1333 msg_Dbg( p_obj, "opening device '%s'", path );
1335 int i_fd = vlc_open( path, O_RDWR );
1338 msg_Err( p_obj, "cannot open device '%s': %m", path );
1345 /* Note the v4l2_xxx functions are designed so that if they get passed an
1346 unknown fd, the will behave exactly as their regular xxx counterparts,
1347 so if v4l2_fd_open fails, we continue as normal (missing the libv4l2
1348 custom cam format to normal formats conversion). Chances are big we will
1349 still fail then though, as normally v4l2_fd_open only fails if the
1350 device is not a v4l2 device. */
1351 if( p_sys->b_libv4l2 )
1354 libv4l2_fd = v4l2_fd_open( i_fd, 0 );
1355 if( libv4l2_fd != -1 )
1360 /* Get device capabilites */
1361 struct v4l2_capability cap;
1362 if( v4l2_ioctl( i_fd, VIDIOC_QUERYCAP, &cap ) < 0 )
1364 msg_Err( p_obj, "cannot get video capabilities: %m" );
1368 msg_Dbg( p_obj, "device %s using driver %s (version %u.%u.%u) on %s",
1369 cap.card, cap.driver, (cap.version >> 16) & 0xFF,
1370 (cap.version >> 8) & 0xFF, cap.version & 0xFF, cap.bus_info );
1371 msg_Dbg( p_obj, "the device has the capabilities: 0x%08X",
1373 msg_Dbg( p_obj, " (%c) Video Capture, (%c) Audio, (%c) Tuner, (%c) Radio",
1374 ( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE ? 'X':' '),
1375 ( cap.capabilities & V4L2_CAP_AUDIO ? 'X':' '),
1376 ( cap.capabilities & V4L2_CAP_TUNER ? 'X':' '),
1377 ( cap.capabilities & V4L2_CAP_RADIO ? 'X':' ') );
1378 msg_Dbg( p_obj, " (%c) Read/Write, (%c) Streaming, (%c) Asynchronous",
1379 ( cap.capabilities & V4L2_CAP_READWRITE ? 'X':' ' ),
1380 ( cap.capabilities & V4L2_CAP_STREAMING ? 'X':' ' ),
1381 ( cap.capabilities & V4L2_CAP_ASYNCIO ? 'X':' ' ) );
1383 if( cap.capabilities & V4L2_CAP_STREAMING )
1384 p_sys->io = IO_METHOD_MMAP;
1385 else if( cap.capabilities & V4L2_CAP_READWRITE )
1386 p_sys->io = IO_METHOD_READ;
1389 msg_Err( p_obj, "no supported I/O method" );
1393 /* Now, enumerate all the video inputs. This is useless at the moment
1394 since we have no way to present that info to the user except with
1396 if( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
1398 struct v4l2_input input;
1399 unsigned index = var_InheritInteger( p_obj, CFG_PREFIX"input" );
1402 while( v4l2_ioctl( i_fd, VIDIOC_ENUMINPUT, &input ) >= 0 )
1404 msg_Dbg( p_obj, "video input %u (%s) has type: %s %c",
1405 input.index, input.name,
1406 input.type == V4L2_INPUT_TYPE_TUNER
1407 ? "Tuner adapter" : "External analog input",
1408 input.index == index ? '*' : ' ' );
1413 if( v4l2_ioctl( i_fd, VIDIOC_S_INPUT, &index ) < 0 )
1415 msg_Err( p_obj, "cannot set input %u: %m", index );
1418 msg_Dbg( p_obj, "input set to %u", index );
1421 /* Select standard */
1423 const char *stdname = var_InheritString( p_obj, CFG_PREFIX"standard" );
1424 if( stdname != NULL )
1426 v4l2_std_id std = strtoull( stdname, NULL, 0 );
1429 const size_t n = sizeof(standards_vlc) / sizeof(*standards_vlc);
1430 assert( n == sizeof(standards_v4l2) / sizeof(*standards_v4l2) );
1431 assert( n == sizeof(standards_user) / sizeof(*standards_user) );
1432 for( size_t i = 0; i < n; i++ )
1433 if( strcasecmp( stdname, standards_vlc[i] ) == 0 )
1435 std = standards_v4l2[i];
1440 if( v4l2_ioctl( i_fd, VIDIOC_S_STD, &std ) < 0
1441 || v4l2_ioctl( i_fd, VIDIOC_G_STD, &std ) < 0 )
1443 msg_Err( p_obj, "cannot set standard 0x%"PRIx64": %m", std );
1446 msg_Dbg( p_obj, "standard set to 0x%"PRIx64":", std );
1447 bottom_first = std == V4L2_STD_NTSC;
1450 bottom_first = false;
1452 /* Set audio input */
1453 if( cap.capabilities & V4L2_CAP_AUDIO )
1455 struct v4l2_audio audio = { .index = 0 };
1456 uint32_t idx = var_InheritInteger( p_obj, CFG_PREFIX"audio-input" );
1458 /* Probe audio inputs */
1459 while( v4l2_ioctl( i_fd, VIDIOC_ENUMAUDIO, &audio ) >= 0 )
1461 msg_Dbg( p_obj, "audio input %u (%s) is %s%s %c", audio.index,
1463 audio.capability & V4L2_AUDCAP_STEREO ? "Stereo" : "Mono",
1464 audio.capability & V4L2_AUDCAP_AVL
1465 ? " (Automatic Volume Level supported)" : "",
1466 audio.index == idx );
1470 if( idx != (uint32_t)-1 )
1472 memset( &audio, 0, sizeof(audio) );
1474 /* TODO: AVL support (audio.mode) */
1476 if( v4l2_ioctl( i_fd, VIDIOC_S_AUDIO, &audio ) < 0 )
1478 msg_Err( p_obj, "cannot set audio input %"PRIu32": %m", idx );
1481 msg_Dbg( p_obj, "audio input set to %"PRIu32, idx );
1485 /* List tuner caps */
1486 if( cap.capabilities & V4L2_CAP_TUNER )
1488 struct v4l2_tuner tuner;
1489 uint32_t idx = var_CreateGetInteger( p_obj, CFG_PREFIX"tuner" );
1490 enum v4l2_tuner_type type = V4L2_TUNER_RADIO;
1493 while( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &tuner ) >= 0 )
1495 if( tuner.index == idx )
1499 (tuner.capability & V4L2_TUNER_CAP_LOW) ? "Hz" : "kHz";
1500 msg_Dbg( p_obj, "tuner %u (%s) has type: %s, "
1501 "frequency range: %.1f %s -> %.1f %s", tuner.index,
1503 tuner.type == V4L2_TUNER_RADIO ? "Radio" : "Analog TV",
1504 tuner.rangelow * 62.5, unit,
1505 tuner.rangehigh * 62.5, unit );
1507 struct v4l2_frequency frequency = { .tuner = tuner.index };
1508 if( v4l2_ioctl( i_fd, VIDIOC_G_FREQUENCY, &frequency ) < 0 )
1510 msg_Err( p_obj, "cannot get tuner frequency: %m" );
1513 msg_Dbg( p_obj, "tuner %u (%s) frequency: %.1f %s", tuner.index,
1514 tuner.name, frequency.frequency * 62.5, unit );
1518 /* Tune the tuner */
1519 uint32_t freq = var_InheritInteger( p_obj,
1520 CFG_PREFIX"tuner-frequency" );
1521 if( freq != (uint32_t)-1 )
1523 struct v4l2_frequency frequency = {
1526 .frequency = freq / 62.5,
1529 if( v4l2_ioctl( i_fd, VIDIOC_S_FREQUENCY, &frequency ) < 0 )
1531 msg_Err( p_obj, "cannot set tuner frequency: %m" );
1534 msg_Dbg( p_obj, "tuner frequency set" );
1537 /* Set the tuner audio mode */
1538 int32_t audmode = var_InheritInteger( p_obj,
1539 CFG_PREFIX"tuner-audio-mode" );
1542 struct v4l2_tuner tuner = {
1547 if( v4l2_ioctl( i_fd, VIDIOC_S_TUNER, &tuner ) < 0 )
1549 msg_Err( p_obj, "cannot set tuner audio mode: %m" );
1552 msg_Dbg( p_obj, "tuner audio mode set" );
1556 /* Probe for available chromas */
1557 uint_fast32_t ncodec = 0;
1558 if( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
1560 struct v4l2_fmtdesc codec = {
1562 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1565 while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &codec ) >= 0 )
1566 codec.index = ++ncodec;
1568 codecs = malloc( ncodec * sizeof( *codecs ) );
1569 if( unlikely(codecs == NULL) )
1572 for( uint_fast32_t i = 0; i < ncodec; i++ )
1574 codecs[i].index = i;
1575 codecs[i].type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1577 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &codecs[i] ) < 0 )
1579 msg_Err( p_obj, "cannot get codec description: %m" );
1583 /* only print if vlc supports the format */
1584 char fourcc_v4l2[5];
1585 memset( fourcc_v4l2, 0, sizeof( fourcc_v4l2 ) );
1586 vlc_fourcc_to_char( codecs[i].pixelformat, fourcc_v4l2 );
1588 bool b_codec_supported = false;
1589 for( unsigned j = 0; v4l2chroma_to_fourcc[j].i_v4l2 != 0; j++ )
1591 if( v4l2chroma_to_fourcc[j].i_v4l2 == codecs[i].pixelformat )
1594 memset( fourcc, 0, sizeof( fourcc ) );
1595 vlc_fourcc_to_char( v4l2chroma_to_fourcc[j].i_fourcc,
1597 msg_Dbg( p_obj, "device supports chroma %4.4s [%s, %s]",
1598 fourcc, codecs[i].description, fourcc_v4l2 );
1599 b_codec_supported = true;
1601 #ifdef VIDIOC_ENUM_FRAMESIZES
1602 /* This is new in Linux 2.6.19 */
1603 /* List valid frame sizes for this format */
1604 struct v4l2_frmsizeenum frmsize;
1605 memset( &frmsize, 0, sizeof(frmsize) );
1606 frmsize.pixel_format = codecs[i].pixelformat;
1607 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) < 0 )
1609 /* Not all devices support this ioctl */
1610 msg_Warn( p_obj, "Unable to query for frame sizes" );
1614 switch( frmsize.type )
1616 case V4L2_FRMSIZE_TYPE_DISCRETE:
1620 " device supports size %dx%d",
1621 frmsize.discrete.width, frmsize.discrete.height );
1623 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) >= 0 );
1625 case V4L2_FRMSIZE_TYPE_STEPWISE:
1627 " device supports sizes %dx%d to %dx%d using %dx%d increments",
1628 frmsize.stepwise.min_width, frmsize.stepwise.min_height,
1629 frmsize.stepwise.max_width, frmsize.stepwise.max_height,
1630 frmsize.stepwise.step_width, frmsize.stepwise.step_height );
1632 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1634 " device supports all sizes %dx%d to %dx%d",
1635 frmsize.stepwise.min_width, frmsize.stepwise.min_height,
1636 frmsize.stepwise.max_width, frmsize.stepwise.max_height );
1643 if( !b_codec_supported )
1645 msg_Dbg( p_obj, "device codec %4.4s (%s) not supported",
1646 fourcc_v4l2, codecs[i].description );
1651 /* TODO: Move the resolution stuff up here */
1652 /* if MPEG encoder card, no need to do anything else after this */
1653 ControlList( p_obj, i_fd, b_demux );
1655 /* Reset Cropping */
1656 memset( &cropcap, 0, sizeof(cropcap) );
1657 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1658 if( v4l2_ioctl( i_fd, VIDIOC_CROPCAP, &cropcap ) >= 0 )
1660 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1661 crop.c = cropcap.defrect; /* reset to default */
1662 if( crop.c.width > 0 && crop.c.height > 0 ) /* Fix for fm tuners */
1664 if( v4l2_ioctl( i_fd, VIDIOC_S_CROP, &crop ) < 0 )
1669 /* Cropping not supported. */
1672 /* Errors ignored. */
1679 /* Try and find default resolution if not specified */
1680 int width = var_InheritInteger( p_obj, CFG_PREFIX"width" );
1681 int height = var_InheritInteger( p_obj, CFG_PREFIX"height" );
1683 memset( &fmt, 0, sizeof(fmt) );
1684 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1686 if( width <= 0 || height <= 0 )
1688 /* Use current width and height settings */
1689 if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 )
1691 msg_Err( p_obj, "cannot get default width and height: %m" );
1695 msg_Dbg( p_obj, "found default width and height of %ux%u",
1696 fmt.fmt.pix.width, fmt.fmt.pix.height );
1698 if( width < 0 || height < 0 )
1700 msg_Dbg( p_obj, "will try to find optimal width and height" );
1705 /* Use user specified width and height */
1706 msg_Dbg( p_obj, "trying specified size %dx%d", width, height );
1707 fmt.fmt.pix.width = width;
1708 fmt.fmt.pix.height = height;
1711 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1716 demux_t *p_demux = (demux_t *) p_obj;
1717 char *reqchroma = var_InheritString( p_obj, CFG_PREFIX"chroma" );
1719 /* Test and set Chroma */
1720 fmt.fmt.pix.pixelformat = 0;
1721 if( reqchroma != NULL )
1723 /* User specified chroma */
1724 const vlc_fourcc_t i_requested_fourcc =
1725 vlc_fourcc_GetCodecFromString( VIDEO_ES, reqchroma );
1727 for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
1729 if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
1731 fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2;
1735 /* Try and set user chroma */
1736 bool b_error = !IsPixelFormatSupported( codecs, ncodec,
1737 fmt.fmt.pix.pixelformat );
1738 if( !b_error && fmt.fmt.pix.pixelformat )
1740 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1742 fmt.fmt.pix.field = V4L2_FIELD_ANY;
1743 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1745 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1752 msg_Warn( p_obj, "requested chroma %s not supported. "
1753 " Trying default.", reqchroma );
1754 fmt.fmt.pix.pixelformat = 0;
1759 /* If no user specified chroma, find best */
1760 /* This also decides if MPEG encoder card or not */
1761 if( !fmt.fmt.pix.pixelformat )
1764 for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
1766 fmt.fmt.pix.pixelformat = p_chroma_fallbacks[i];
1767 if( IsPixelFormatSupported( codecs, ncodec,
1768 fmt.fmt.pix.pixelformat ) )
1770 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1772 fmt.fmt.pix.field = V4L2_FIELD_ANY;
1773 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1775 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1778 if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
1780 msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
1785 if( width < 0 || height < 0 )
1787 f_fps = var_InheritFloat( p_obj, CFG_PREFIX"fps" );
1790 f_fps = GetAbsoluteMaxFrameRate( p_demux, i_fd,
1791 fmt.fmt.pix.pixelformat );
1792 msg_Dbg( p_demux, "Found maximum framerate of %f", f_fps );
1794 uint32_t i_width, i_height;
1795 GetMaxDimensions( p_demux, i_fd,
1796 fmt.fmt.pix.pixelformat, f_fps,
1797 &i_width, &i_height );
1798 if( i_width || i_height )
1800 msg_Dbg( p_demux, "Found optimal dimensions for framerate %f "
1801 "of %ux%u", f_fps, i_width, i_height );
1802 fmt.fmt.pix.width = i_width;
1803 fmt.fmt.pix.height = i_height;
1804 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1806 msg_Err( p_obj, "Cannot set size to optimal dimensions "
1807 "%ux%u", i_width, i_height );
1813 msg_Warn( p_obj, "Could not find optimal width and height, "
1814 "falling back to driver default." );
1819 width = fmt.fmt.pix.width;
1820 height = fmt.fmt.pix.height;
1822 if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 ) {;}
1823 /* Print extra info */
1824 msg_Dbg( p_obj, "Driver requires at most %d bytes to store a complete image", fmt.fmt.pix.sizeimage );
1825 /* Check interlacing */
1826 switch( fmt.fmt.pix.field )
1828 case V4L2_FIELD_NONE:
1829 msg_Dbg( p_obj, "Interlacing setting: progressive" );
1831 case V4L2_FIELD_TOP:
1832 msg_Dbg( p_obj, "Interlacing setting: top field only" );
1834 case V4L2_FIELD_BOTTOM:
1835 msg_Dbg( p_obj, "Interlacing setting: bottom field only" );
1837 case V4L2_FIELD_INTERLACED:
1838 msg_Dbg( p_obj, "Interlacing setting: interleaved (bottom top if M/NTSC, top bottom otherwise)" );
1840 p_sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST;
1842 p_sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST;
1844 case V4L2_FIELD_SEQ_TB:
1845 msg_Dbg( p_obj, "Interlacing setting: sequential top bottom (TODO)" );
1847 case V4L2_FIELD_SEQ_BT:
1848 msg_Dbg( p_obj, "Interlacing setting: sequential bottom top (TODO)" );
1850 case V4L2_FIELD_ALTERNATE:
1851 msg_Dbg( p_obj, "Interlacing setting: alternate fields (TODO)" );
1854 case V4L2_FIELD_INTERLACED_TB:
1855 msg_Dbg( p_obj, "Interlacing setting: interleaved top bottom" );
1856 p_sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST;
1858 case V4L2_FIELD_INTERLACED_BT:
1859 msg_Dbg( p_obj, "Interlacing setting: interleaved bottom top" );
1860 p_sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST;
1863 msg_Warn( p_obj, "Interlacing setting: unknown type (%d)",
1864 fmt.fmt.pix.field );
1868 /* Look up final fourcc */
1869 p_sys->i_fourcc = 0;
1870 for( int i = 0; v4l2chroma_to_fourcc[i].i_fourcc != 0; i++ )
1872 if( v4l2chroma_to_fourcc[i].i_v4l2 == fmt.fmt.pix.pixelformat )
1874 p_sys->i_fourcc = v4l2chroma_to_fourcc[i].i_fourcc;
1875 es_format_Init( &es_fmt, VIDEO_ES, p_sys->i_fourcc );
1876 es_fmt.video.i_rmask = v4l2chroma_to_fourcc[i].i_rmask;
1877 es_fmt.video.i_gmask = v4l2chroma_to_fourcc[i].i_gmask;
1878 es_fmt.video.i_bmask = v4l2chroma_to_fourcc[i].i_bmask;
1883 /* Buggy driver paranoia */
1884 i_min = fmt.fmt.pix.width * 2;
1885 if( fmt.fmt.pix.bytesperline < i_min )
1886 fmt.fmt.pix.bytesperline = i_min;
1887 i_min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
1888 if( fmt.fmt.pix.sizeimage < i_min )
1889 fmt.fmt.pix.sizeimage = i_min;
1891 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
1892 /* This is new in Linux 2.6.19 */
1893 /* List supported frame rates */
1894 struct v4l2_frmivalenum frmival;
1895 memset( &frmival, 0, sizeof(frmival) );
1896 frmival.pixel_format = fmt.fmt.pix.pixelformat;
1897 frmival.width = width;
1898 frmival.height = height;
1899 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 )
1902 memset( &psz_fourcc, 0, sizeof( psz_fourcc ) );
1903 vlc_fourcc_to_char( p_sys->i_fourcc, &psz_fourcc );
1904 msg_Dbg( p_obj, "supported frame intervals for %4.4s, %dx%d:",
1905 psz_fourcc, frmival.width, frmival.height );
1906 switch( frmival.type )
1908 case V4L2_FRMIVAL_TYPE_DISCRETE:
1911 msg_Dbg( p_obj, " supported frame interval: %d/%d",
1912 frmival.discrete.numerator,
1913 frmival.discrete.denominator );
1915 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 );
1917 case V4L2_FRMIVAL_TYPE_STEPWISE:
1918 msg_Dbg( p_obj, " supported frame intervals: %d/%d to "
1919 "%d/%d using %d/%d increments",
1920 frmival.stepwise.min.numerator,
1921 frmival.stepwise.min.denominator,
1922 frmival.stepwise.max.numerator,
1923 frmival.stepwise.max.denominator,
1924 frmival.stepwise.step.numerator,
1925 frmival.stepwise.step.denominator );
1927 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1928 msg_Dbg( p_obj, " supported frame intervals: %d/%d to %d/%d",
1929 frmival.stepwise.min.numerator,
1930 frmival.stepwise.min.denominator,
1931 frmival.stepwise.max.numerator,
1932 frmival.stepwise.max.denominator );
1939 /* Init I/O method */
1942 case IO_METHOD_READ:
1943 if( b_demux && InitRead( p_obj, p_sys, fmt.fmt.pix.sizeimage ) )
1947 case IO_METHOD_MMAP:
1948 if( InitMmap( p_obj, p_sys, i_fd ) )
1950 for (unsigned int i = 0; i < p_sys->i_nbuffers; ++i)
1952 struct v4l2_buffer buf;
1954 memset( &buf, 0, sizeof(buf) );
1955 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1956 buf.memory = V4L2_MEMORY_MMAP;
1959 if( v4l2_ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
1961 msg_Err( p_obj, "VIDIOC_QBUF failed" );
1966 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1967 if( v4l2_ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
1969 msg_Err( p_obj, "VIDIOC_STREAMON failed" );
1974 case IO_METHOD_USERPTR:
1975 if( InitUserP( p_obj, p_sys, i_fd, fmt.fmt.pix.sizeimage ) )
1977 for( unsigned int i = 0; i < p_sys->i_nbuffers; ++i )
1979 struct v4l2_buffer buf;
1981 memset( &buf, 0, sizeof(buf) );
1982 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1983 buf.memory = V4L2_MEMORY_USERPTR;
1985 buf.m.userptr = (unsigned long)p_sys->p_buffers[i].start;
1986 buf.length = p_sys->p_buffers[i].length;
1988 if( v4l2_ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
1990 msg_Err( p_obj, "VIDIOC_QBUF failed" );
1995 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1996 if( v4l2_ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
1998 msg_Err( p_obj, "VIDIOC_STREAMON failed" );
2008 int ar = 4 * VOUT_ASPECT_FACTOR / 3;
2009 char *str = var_InheritString( p_obj, CFG_PREFIX"aspect-ratio" );
2010 if( likely(str != NULL) )
2012 const char *delim = strchr( str, ':' );
2014 ar = atoi( str ) * VOUT_ASPECT_FACTOR / atoi( delim + 1 );
2019 es_fmt.video.i_width = width;
2020 es_fmt.video.i_height = height;
2022 /* Get aspect-ratio */
2023 es_fmt.video.i_sar_num = ar * es_fmt.video.i_height;
2024 es_fmt.video.i_sar_den = VOUT_ASPECT_FACTOR * es_fmt.video.i_width;
2027 es_fmt.video.i_frame_rate = lround(f_fps * 1000000.);
2028 es_fmt.video.i_frame_rate_base = 1000000;
2030 demux_t *p_demux = (demux_t *) p_obj;
2031 msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
2032 (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
2033 msg_Dbg( p_obj, " frame rate: %f", f_fps );
2035 p_sys->p_es = es_out_Add( p_demux->out, &es_fmt );