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 char *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 *, const char *path, 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 char *path = ParseMRL( p_this, p_demux->psz_location );
511 path = var_CreateGetNonEmptyString( p_this, CFG_PREFIX"dev" );
515 if( !var_InheritBool( p_this, CFG_PREFIX "use-libv4l2" ) )
517 p_sys->b_libv4l2 = false;
519 msg_Dbg( p_this, "Trying direct kernel v4l2" );
520 p_sys->i_fd = OpenVideoDev( p_this, path, p_sys, true );
524 if( p_sys->i_fd == -1 )
526 p_sys->b_libv4l2 = true;
527 msg_Dbg( p_this, "Trying libv4l2 wrapper" );
528 p_sys->i_fd = OpenVideoDev( p_this, path, p_sys, true );
532 if( p_sys->i_fd == -1 )
542 * \return device node path (use free()) or NULL if not specified
544 static char *ParseMRL( vlc_object_t *obj, const char *mrl )
546 const char *p = strchr( mrl, ':' );
550 var_LocationParse( obj, p + 1, CFG_PREFIX );
552 return strndup( mrl, p - mrl );
557 return strdup( mrl );
562 /*****************************************************************************
563 * Close: close device, free resources
564 *****************************************************************************/
565 static void AccessClose( vlc_object_t *p_this )
567 access_t *p_access = (access_t *)p_this;
568 demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
570 CommonClose( p_this, p_sys );
573 static void DemuxClose( vlc_object_t *p_this )
575 struct v4l2_buffer buf;
576 enum v4l2_buf_type buf_type;
579 demux_t *p_demux = (demux_t *)p_this;
580 demux_sys_t *p_sys = p_demux->p_sys;
582 /* Stop video capture */
583 if( p_sys->i_fd >= 0 )
592 case IO_METHOD_USERPTR:
593 /* Some drivers 'hang' internally if this is not done before streamoff */
594 for( unsigned int i = 0; i < p_sys->i_nbuffers; i++ )
596 memset( &buf, 0, sizeof(buf) );
597 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
598 buf.memory = ( p_sys->io == IO_METHOD_USERPTR ) ?
599 V4L2_MEMORY_USERPTR : V4L2_MEMORY_MMAP;
600 v4l2_ioctl( p_sys->i_fd, VIDIOC_DQBUF, &buf ); /* ignore result */
603 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
604 if( v4l2_ioctl( p_sys->i_fd, VIDIOC_STREAMOFF, &buf_type ) < 0 ) {
605 msg_Err( p_this, "VIDIOC_STREAMOFF failed" );
612 /* Free Video Buffers */
613 if( p_sys->p_buffers ) {
617 free( p_sys->p_buffers[0].start );
621 for( i = 0; i < p_sys->i_nbuffers; ++i )
623 if( v4l2_munmap( p_sys->p_buffers[i].start, p_sys->p_buffers[i].length ) )
625 msg_Err( p_this, "munmap failed" );
630 case IO_METHOD_USERPTR:
631 for( i = 0; i < p_sys->i_nbuffers; ++i )
633 free( p_sys->p_buffers[i].start );
637 free( p_sys->p_buffers );
640 CommonClose( p_this, p_sys );
643 static void CommonClose( vlc_object_t *p_this, demux_sys_t *p_sys )
647 if( p_sys->i_fd >= 0 ) v4l2_close( p_sys->i_fd );
651 /*****************************************************************************
652 * AccessOpen: opens v4l2 device, access callback
653 *****************************************************************************
655 * url: <video device>::::
657 *****************************************************************************/
658 static int AccessOpen( vlc_object_t * p_this )
660 access_t *p_access = (access_t*) p_this;
663 /* Only when selected */
664 if( *p_access->psz_access == '\0' ) return VLC_EGENERIC;
666 access_InitFields( p_access );
667 p_sys = calloc( 1, sizeof( demux_sys_t ));
668 if( !p_sys ) return VLC_ENOMEM;
669 p_access->p_sys = (access_sys_t*)p_sys;
671 char *path = ParseMRL( p_this, p_access->psz_location );
673 path = var_InheritString( p_this, CFG_PREFIX"dev" );
677 if( !var_InheritBool( p_this, CFG_PREFIX "use-libv4l2" ) )
679 p_sys->b_libv4l2 = false;
681 msg_Dbg( p_this, "Trying direct kernel v4l2" );
682 p_sys->i_fd = OpenVideoDev( p_this, path, p_sys, false );
685 if( p_sys->i_fd == -1 )
687 p_sys->b_libv4l2 = true;
688 msg_Dbg( p_this, "Trying libv4l2 wrapper" );
689 p_sys->i_fd = OpenVideoDev( p_this, path, 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, const char *path,
1320 demux_sys_t *p_sys, bool b_demux )
1322 struct v4l2_cropcap cropcap;
1323 struct v4l2_crop crop;
1324 struct v4l2_format fmt;
1326 enum v4l2_buf_type buf_type;
1328 struct v4l2_fmtdesc *codecs = NULL;
1330 msg_Dbg( p_obj, "opening device '%s'", path );
1332 int i_fd = vlc_open( path, O_RDWR );
1335 msg_Err( p_obj, "cannot open device %s: %m", path );
1340 /* Note the v4l2_xxx functions are designed so that if they get passed an
1341 unknown fd, the will behave exactly as their regular xxx counterparts,
1342 so if v4l2_fd_open fails, we continue as normal (missing the libv4l2
1343 custom cam format to normal formats conversion). Chances are big we will
1344 still fail then though, as normally v4l2_fd_open only fails if the
1345 device is not a v4l2 device. */
1346 if( p_sys->b_libv4l2 )
1349 libv4l2_fd = v4l2_fd_open( i_fd, 0 );
1350 if( libv4l2_fd != -1 )
1355 /* Get device capabilites */
1356 struct v4l2_capability cap;
1357 if( v4l2_ioctl( i_fd, VIDIOC_QUERYCAP, &cap ) < 0 )
1359 msg_Err( p_obj, "cannot get video capabilities: %m" );
1363 msg_Dbg( p_obj, "device %s using driver %s (version %u.%u.%u) on %s",
1364 cap.card, cap.driver, (cap.version >> 16) & 0xFF,
1365 (cap.version >> 8) & 0xFF, cap.version & 0xFF, cap.bus_info );
1366 msg_Dbg( p_obj, "the device has the capabilities: 0x%08X",
1368 msg_Dbg( p_obj, " (%c) Video Capture, (%c) Audio, (%c) Tuner, (%c) Radio",
1369 ( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE ? 'X':' '),
1370 ( cap.capabilities & V4L2_CAP_AUDIO ? 'X':' '),
1371 ( cap.capabilities & V4L2_CAP_TUNER ? 'X':' '),
1372 ( cap.capabilities & V4L2_CAP_RADIO ? 'X':' ') );
1373 msg_Dbg( p_obj, " (%c) Read/Write, (%c) Streaming, (%c) Asynchronous",
1374 ( cap.capabilities & V4L2_CAP_READWRITE ? 'X':' ' ),
1375 ( cap.capabilities & V4L2_CAP_STREAMING ? 'X':' ' ),
1376 ( cap.capabilities & V4L2_CAP_ASYNCIO ? 'X':' ' ) );
1378 if( cap.capabilities & V4L2_CAP_STREAMING )
1379 p_sys->io = IO_METHOD_MMAP;
1380 else if( cap.capabilities & V4L2_CAP_READWRITE )
1381 p_sys->io = IO_METHOD_READ;
1384 msg_Err( p_obj, "no supported I/O method" );
1388 /* Now, enumerate all the video inputs. This is useless at the moment
1389 since we have no way to present that info to the user except with
1391 if( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
1393 struct v4l2_input input;
1394 unsigned index = var_InheritInteger( p_obj, CFG_PREFIX"input" );
1397 while( v4l2_ioctl( i_fd, VIDIOC_ENUMINPUT, &input ) >= 0 )
1399 msg_Dbg( p_obj, "video input %u (%s) has type: %s %c",
1400 input.index, input.name,
1401 input.type == V4L2_INPUT_TYPE_TUNER
1402 ? "Tuner adapter" : "External analog input",
1403 input.index == index ? '*' : ' ' );
1408 if( v4l2_ioctl( i_fd, VIDIOC_S_INPUT, &index ) < 0 )
1410 msg_Err( p_obj, "cannot set input %u: %m", index );
1413 msg_Dbg( p_obj, "input set to %u", index );
1416 /* Select standard */
1418 const char *stdname = var_InheritString( p_obj, CFG_PREFIX"standard" );
1419 if( stdname != NULL )
1421 v4l2_std_id std = strtoull( stdname, NULL, 0 );
1424 const size_t n = sizeof(standards_vlc) / sizeof(*standards_vlc);
1425 assert( n == sizeof(standards_v4l2) / sizeof(*standards_v4l2) );
1426 assert( n == sizeof(standards_user) / sizeof(*standards_user) );
1427 for( size_t i = 0; i < n; i++ )
1428 if( strcasecmp( stdname, standards_vlc[i] ) == 0 )
1430 std = standards_v4l2[i];
1435 if( v4l2_ioctl( i_fd, VIDIOC_S_STD, &std ) < 0
1436 || v4l2_ioctl( i_fd, VIDIOC_G_STD, &std ) < 0 )
1438 msg_Err( p_obj, "cannot set standard 0x%"PRIx64": %m", std );
1441 msg_Dbg( p_obj, "standard set to 0x%"PRIx64":", std );
1442 bottom_first = std == V4L2_STD_NTSC;
1445 bottom_first = false;
1447 /* Set audio input */
1448 if( cap.capabilities & V4L2_CAP_AUDIO )
1450 struct v4l2_audio audio = { .index = 0 };
1451 uint32_t idx = var_InheritInteger( p_obj, CFG_PREFIX"audio-input" );
1453 /* Probe audio inputs */
1454 while( v4l2_ioctl( i_fd, VIDIOC_ENUMAUDIO, &audio ) >= 0 )
1456 msg_Dbg( p_obj, "audio input %u (%s) is %s%s %c", audio.index,
1458 audio.capability & V4L2_AUDCAP_STEREO ? "Stereo" : "Mono",
1459 audio.capability & V4L2_AUDCAP_AVL
1460 ? " (Automatic Volume Level supported)" : "",
1461 audio.index == idx );
1465 if( idx != (uint32_t)-1 )
1467 memset( &audio, 0, sizeof(audio) );
1469 /* TODO: AVL support (audio.mode) */
1471 if( v4l2_ioctl( i_fd, VIDIOC_S_AUDIO, &audio ) < 0 )
1473 msg_Err( p_obj, "cannot set audio input %"PRIu32": %m", idx );
1476 msg_Dbg( p_obj, "audio input set to %"PRIu32, idx );
1480 /* List tuner caps */
1481 if( cap.capabilities & V4L2_CAP_TUNER )
1483 struct v4l2_tuner tuner;
1484 uint32_t idx = var_CreateGetInteger( p_obj, CFG_PREFIX"tuner" );
1485 enum v4l2_tuner_type type = V4L2_TUNER_RADIO;
1488 while( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &tuner ) >= 0 )
1490 if( tuner.index == idx )
1494 (tuner.capability & V4L2_TUNER_CAP_LOW) ? "Hz" : "kHz";
1495 msg_Dbg( p_obj, "tuner %u (%s) has type: %s, "
1496 "frequency range: %.1f %s -> %.1f %s", tuner.index,
1498 tuner.type == V4L2_TUNER_RADIO ? "Radio" : "Analog TV",
1499 tuner.rangelow * 62.5, unit,
1500 tuner.rangehigh * 62.5, unit );
1502 struct v4l2_frequency frequency = { .tuner = tuner.index };
1503 if( v4l2_ioctl( i_fd, VIDIOC_G_FREQUENCY, &frequency ) < 0 )
1505 msg_Err( p_obj, "cannot get tuner frequency: %m" );
1508 msg_Dbg( p_obj, "tuner %u (%s) frequency: %.1f %s", tuner.index,
1509 tuner.name, frequency.frequency * 62.5, unit );
1513 /* Tune the tuner */
1514 uint32_t freq = var_InheritInteger( p_obj,
1515 CFG_PREFIX"tuner-frequency" );
1516 if( freq != (uint32_t)-1 )
1518 struct v4l2_frequency frequency = {
1521 .frequency = freq / 62.5,
1524 if( v4l2_ioctl( i_fd, VIDIOC_S_FREQUENCY, &frequency ) < 0 )
1526 msg_Err( p_obj, "cannot set tuner frequency: %m" );
1529 msg_Dbg( p_obj, "tuner frequency set" );
1532 /* Set the tuner audio mode */
1533 int32_t audmode = var_InheritInteger( p_obj,
1534 CFG_PREFIX"tuner-audio-mode" );
1537 struct v4l2_tuner tuner = {
1542 if( v4l2_ioctl( i_fd, VIDIOC_S_TUNER, &tuner ) < 0 )
1544 msg_Err( p_obj, "cannot set tuner audio mode: %m" );
1547 msg_Dbg( p_obj, "tuner audio mode set" );
1551 /* Probe for available chromas */
1552 uint_fast32_t ncodec = 0;
1553 if( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
1555 struct v4l2_fmtdesc codec = {
1557 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1560 while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &codec ) >= 0 )
1561 codec.index = ++ncodec;
1563 codecs = malloc( ncodec * sizeof( *codecs ) );
1564 if( unlikely(codecs == NULL) )
1567 for( uint_fast32_t i = 0; i < ncodec; i++ )
1569 codecs[i].index = i;
1570 codecs[i].type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1572 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &codecs[i] ) < 0 )
1574 msg_Err( p_obj, "cannot get codec description: %m" );
1578 /* only print if vlc supports the format */
1579 char fourcc_v4l2[5];
1580 memset( fourcc_v4l2, 0, sizeof( fourcc_v4l2 ) );
1581 vlc_fourcc_to_char( codecs[i].pixelformat, fourcc_v4l2 );
1583 bool b_codec_supported = false;
1584 for( unsigned j = 0; v4l2chroma_to_fourcc[j].i_v4l2 != 0; j++ )
1586 if( v4l2chroma_to_fourcc[j].i_v4l2 == codecs[i].pixelformat )
1589 memset( fourcc, 0, sizeof( fourcc ) );
1590 vlc_fourcc_to_char( v4l2chroma_to_fourcc[j].i_fourcc,
1592 msg_Dbg( p_obj, "device supports chroma %4.4s [%s, %s]",
1593 fourcc, codecs[i].description, fourcc_v4l2 );
1594 b_codec_supported = true;
1596 #ifdef VIDIOC_ENUM_FRAMESIZES
1597 /* This is new in Linux 2.6.19 */
1598 /* List valid frame sizes for this format */
1599 struct v4l2_frmsizeenum frmsize;
1600 memset( &frmsize, 0, sizeof(frmsize) );
1601 frmsize.pixel_format = codecs[i].pixelformat;
1602 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) < 0 )
1604 /* Not all devices support this ioctl */
1605 msg_Warn( p_obj, "Unable to query for frame sizes" );
1609 switch( frmsize.type )
1611 case V4L2_FRMSIZE_TYPE_DISCRETE:
1615 " device supports size %dx%d",
1616 frmsize.discrete.width, frmsize.discrete.height );
1618 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) >= 0 );
1620 case V4L2_FRMSIZE_TYPE_STEPWISE:
1622 " device supports sizes %dx%d to %dx%d using %dx%d increments",
1623 frmsize.stepwise.min_width, frmsize.stepwise.min_height,
1624 frmsize.stepwise.max_width, frmsize.stepwise.max_height,
1625 frmsize.stepwise.step_width, frmsize.stepwise.step_height );
1627 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1629 " device supports all sizes %dx%d to %dx%d",
1630 frmsize.stepwise.min_width, frmsize.stepwise.min_height,
1631 frmsize.stepwise.max_width, frmsize.stepwise.max_height );
1638 if( !b_codec_supported )
1640 msg_Dbg( p_obj, "device codec %4.4s (%s) not supported",
1641 fourcc_v4l2, codecs[i].description );
1646 /* TODO: Move the resolution stuff up here */
1647 /* if MPEG encoder card, no need to do anything else after this */
1648 ControlList( p_obj, i_fd, b_demux );
1650 /* Reset Cropping */
1651 memset( &cropcap, 0, sizeof(cropcap) );
1652 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1653 if( v4l2_ioctl( i_fd, VIDIOC_CROPCAP, &cropcap ) >= 0 )
1655 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1656 crop.c = cropcap.defrect; /* reset to default */
1657 if( crop.c.width > 0 && crop.c.height > 0 ) /* Fix for fm tuners */
1659 if( v4l2_ioctl( i_fd, VIDIOC_S_CROP, &crop ) < 0 )
1664 /* Cropping not supported. */
1667 /* Errors ignored. */
1674 /* Try and find default resolution if not specified */
1675 int width = var_InheritInteger( p_obj, CFG_PREFIX"width" );
1676 int height = var_InheritInteger( p_obj, CFG_PREFIX"height" );
1678 memset( &fmt, 0, sizeof(fmt) );
1679 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1681 if( width <= 0 || height <= 0 )
1683 /* Use current width and height settings */
1684 if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 )
1686 msg_Err( p_obj, "cannot get default width and height: %m" );
1690 msg_Dbg( p_obj, "found default width and height of %ux%u",
1691 fmt.fmt.pix.width, fmt.fmt.pix.height );
1693 if( width < 0 || height < 0 )
1695 msg_Dbg( p_obj, "will try to find optimal width and height" );
1700 /* Use user specified width and height */
1701 msg_Dbg( p_obj, "trying specified size %dx%d", width, height );
1702 fmt.fmt.pix.width = width;
1703 fmt.fmt.pix.height = height;
1706 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1711 demux_t *p_demux = (demux_t *) p_obj;
1712 char *reqchroma = var_InheritString( p_obj, CFG_PREFIX"chroma" );
1714 /* Test and set Chroma */
1715 fmt.fmt.pix.pixelformat = 0;
1716 if( reqchroma != NULL )
1718 /* User specified chroma */
1719 const vlc_fourcc_t i_requested_fourcc =
1720 vlc_fourcc_GetCodecFromString( VIDEO_ES, reqchroma );
1722 for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
1724 if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
1726 fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2;
1730 /* Try and set user chroma */
1731 bool b_error = !IsPixelFormatSupported( codecs, ncodec,
1732 fmt.fmt.pix.pixelformat );
1733 if( !b_error && fmt.fmt.pix.pixelformat )
1735 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1737 fmt.fmt.pix.field = V4L2_FIELD_ANY;
1738 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1740 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1747 msg_Warn( p_obj, "requested chroma %s not supported. "
1748 " Trying default.", reqchroma );
1749 fmt.fmt.pix.pixelformat = 0;
1754 /* If no user specified chroma, find best */
1755 /* This also decides if MPEG encoder card or not */
1756 if( !fmt.fmt.pix.pixelformat )
1759 for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
1761 fmt.fmt.pix.pixelformat = p_chroma_fallbacks[i];
1762 if( IsPixelFormatSupported( codecs, ncodec,
1763 fmt.fmt.pix.pixelformat ) )
1765 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1767 fmt.fmt.pix.field = V4L2_FIELD_ANY;
1768 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1770 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1773 if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
1775 msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
1780 if( width < 0 || height < 0 )
1782 f_fps = var_InheritFloat( p_obj, CFG_PREFIX"fps" );
1785 f_fps = GetAbsoluteMaxFrameRate( p_demux, i_fd,
1786 fmt.fmt.pix.pixelformat );
1787 msg_Dbg( p_demux, "Found maximum framerate of %f", f_fps );
1789 uint32_t i_width, i_height;
1790 GetMaxDimensions( p_demux, i_fd,
1791 fmt.fmt.pix.pixelformat, f_fps,
1792 &i_width, &i_height );
1793 if( i_width || i_height )
1795 msg_Dbg( p_demux, "Found optimal dimensions for framerate %f "
1796 "of %ux%u", f_fps, i_width, i_height );
1797 fmt.fmt.pix.width = i_width;
1798 fmt.fmt.pix.height = i_height;
1799 if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1801 msg_Err( p_obj, "Cannot set size to optimal dimensions "
1802 "%ux%u", i_width, i_height );
1808 msg_Warn( p_obj, "Could not find optimal width and height, "
1809 "falling back to driver default." );
1814 width = fmt.fmt.pix.width;
1815 height = fmt.fmt.pix.height;
1817 if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 ) {;}
1818 /* Print extra info */
1819 msg_Dbg( p_obj, "Driver requires at most %d bytes to store a complete image", fmt.fmt.pix.sizeimage );
1820 /* Check interlacing */
1821 switch( fmt.fmt.pix.field )
1823 case V4L2_FIELD_NONE:
1824 msg_Dbg( p_obj, "Interlacing setting: progressive" );
1826 case V4L2_FIELD_TOP:
1827 msg_Dbg( p_obj, "Interlacing setting: top field only" );
1829 case V4L2_FIELD_BOTTOM:
1830 msg_Dbg( p_obj, "Interlacing setting: bottom field only" );
1832 case V4L2_FIELD_INTERLACED:
1833 msg_Dbg( p_obj, "Interlacing setting: interleaved (bottom top if M/NTSC, top bottom otherwise)" );
1835 p_sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST;
1837 p_sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST;
1839 case V4L2_FIELD_SEQ_TB:
1840 msg_Dbg( p_obj, "Interlacing setting: sequential top bottom (TODO)" );
1842 case V4L2_FIELD_SEQ_BT:
1843 msg_Dbg( p_obj, "Interlacing setting: sequential bottom top (TODO)" );
1845 case V4L2_FIELD_ALTERNATE:
1846 msg_Dbg( p_obj, "Interlacing setting: alternate fields (TODO)" );
1849 case V4L2_FIELD_INTERLACED_TB:
1850 msg_Dbg( p_obj, "Interlacing setting: interleaved top bottom" );
1851 p_sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST;
1853 case V4L2_FIELD_INTERLACED_BT:
1854 msg_Dbg( p_obj, "Interlacing setting: interleaved bottom top" );
1855 p_sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST;
1858 msg_Warn( p_obj, "Interlacing setting: unknown type (%d)",
1859 fmt.fmt.pix.field );
1863 /* Look up final fourcc */
1864 p_sys->i_fourcc = 0;
1865 for( int i = 0; v4l2chroma_to_fourcc[i].i_fourcc != 0; i++ )
1867 if( v4l2chroma_to_fourcc[i].i_v4l2 == fmt.fmt.pix.pixelformat )
1869 p_sys->i_fourcc = v4l2chroma_to_fourcc[i].i_fourcc;
1870 es_format_Init( &es_fmt, VIDEO_ES, p_sys->i_fourcc );
1871 es_fmt.video.i_rmask = v4l2chroma_to_fourcc[i].i_rmask;
1872 es_fmt.video.i_gmask = v4l2chroma_to_fourcc[i].i_gmask;
1873 es_fmt.video.i_bmask = v4l2chroma_to_fourcc[i].i_bmask;
1878 /* Buggy driver paranoia */
1879 i_min = fmt.fmt.pix.width * 2;
1880 if( fmt.fmt.pix.bytesperline < i_min )
1881 fmt.fmt.pix.bytesperline = i_min;
1882 i_min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
1883 if( fmt.fmt.pix.sizeimage < i_min )
1884 fmt.fmt.pix.sizeimage = i_min;
1886 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
1887 /* This is new in Linux 2.6.19 */
1888 /* List supported frame rates */
1889 struct v4l2_frmivalenum frmival;
1890 memset( &frmival, 0, sizeof(frmival) );
1891 frmival.pixel_format = fmt.fmt.pix.pixelformat;
1892 frmival.width = width;
1893 frmival.height = height;
1894 if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 )
1897 memset( &psz_fourcc, 0, sizeof( psz_fourcc ) );
1898 vlc_fourcc_to_char( p_sys->i_fourcc, &psz_fourcc );
1899 msg_Dbg( p_obj, "supported frame intervals for %4.4s, %dx%d:",
1900 psz_fourcc, frmival.width, frmival.height );
1901 switch( frmival.type )
1903 case V4L2_FRMIVAL_TYPE_DISCRETE:
1906 msg_Dbg( p_obj, " supported frame interval: %d/%d",
1907 frmival.discrete.numerator,
1908 frmival.discrete.denominator );
1910 } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 );
1912 case V4L2_FRMIVAL_TYPE_STEPWISE:
1913 msg_Dbg( p_obj, " supported frame intervals: %d/%d to "
1914 "%d/%d using %d/%d increments",
1915 frmival.stepwise.min.numerator,
1916 frmival.stepwise.min.denominator,
1917 frmival.stepwise.max.numerator,
1918 frmival.stepwise.max.denominator,
1919 frmival.stepwise.step.numerator,
1920 frmival.stepwise.step.denominator );
1922 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1923 msg_Dbg( p_obj, " supported frame intervals: %d/%d to %d/%d",
1924 frmival.stepwise.min.numerator,
1925 frmival.stepwise.min.denominator,
1926 frmival.stepwise.max.numerator,
1927 frmival.stepwise.max.denominator );
1934 /* Init I/O method */
1937 case IO_METHOD_READ:
1938 if( b_demux && InitRead( p_obj, p_sys, fmt.fmt.pix.sizeimage ) )
1942 case IO_METHOD_MMAP:
1943 if( InitMmap( p_obj, p_sys, i_fd ) )
1945 for (unsigned int i = 0; i < p_sys->i_nbuffers; ++i)
1947 struct v4l2_buffer buf;
1949 memset( &buf, 0, sizeof(buf) );
1950 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1951 buf.memory = V4L2_MEMORY_MMAP;
1954 if( v4l2_ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
1956 msg_Err( p_obj, "VIDIOC_QBUF failed" );
1961 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1962 if( v4l2_ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
1964 msg_Err( p_obj, "VIDIOC_STREAMON failed" );
1969 case IO_METHOD_USERPTR:
1970 if( InitUserP( p_obj, p_sys, i_fd, fmt.fmt.pix.sizeimage ) )
1972 for( unsigned int i = 0; i < p_sys->i_nbuffers; ++i )
1974 struct v4l2_buffer buf;
1976 memset( &buf, 0, sizeof(buf) );
1977 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1978 buf.memory = V4L2_MEMORY_USERPTR;
1980 buf.m.userptr = (unsigned long)p_sys->p_buffers[i].start;
1981 buf.length = p_sys->p_buffers[i].length;
1983 if( v4l2_ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
1985 msg_Err( p_obj, "VIDIOC_QBUF failed" );
1990 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1991 if( v4l2_ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
1993 msg_Err( p_obj, "VIDIOC_STREAMON failed" );
2003 int ar = 4 * VOUT_ASPECT_FACTOR / 3;
2004 char *str = var_InheritString( p_obj, CFG_PREFIX"aspect-ratio" );
2005 if( likely(str != NULL) )
2007 const char *delim = strchr( str, ':' );
2009 ar = atoi( str ) * VOUT_ASPECT_FACTOR / atoi( delim + 1 );
2014 es_fmt.video.i_width = width;
2015 es_fmt.video.i_height = height;
2017 /* Get aspect-ratio */
2018 es_fmt.video.i_sar_num = ar * es_fmt.video.i_height;
2019 es_fmt.video.i_sar_den = VOUT_ASPECT_FACTOR * es_fmt.video.i_width;
2022 es_fmt.video.i_frame_rate = lround(f_fps * 1000000.);
2023 es_fmt.video.i_frame_rate_base = 1000000;
2025 demux_t *p_demux = (demux_t *) p_obj;
2026 msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
2027 (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
2028 msg_Dbg( p_obj, " frame rate: %f", f_fps );
2030 p_sys->p_es = es_out_Add( p_demux->out, &es_fmt );