X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fv4l2.c;h=a20b79dc9f82b8089c8a03bf581a2ba412d21387;hb=71b6846925c287d3107a82e13658ba4e45ce1d5a;hp=515d5cd8225a6e831ff6f3b15a478edcdfd7a7d3;hpb=9cf37a2cb106b4453bc9bae3048208ff4cab0316;p=vlc diff --git a/modules/access/v4l2.c b/modules/access/v4l2.c index 515d5cd822..a20b79dc9f 100644 --- a/modules/access/v4l2.c +++ b/modules/access/v4l2.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,13 @@ #include #include -#include +#if defined(HAVE_LINUX_VIDEODEV2_H) +# include +#elif defined(HAVE_SYS_VIDEOIO_H) +# include +#else +# error "No Video4Linux2 headers found." +#endif #include @@ -216,9 +223,26 @@ typedef enum { } io_method; static const int i_standards_list[] = - { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC }; + { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC, + V4L2_STD_PAL_B, V4L2_STD_PAL_B1, V4L2_STD_PAL_G, V4L2_STD_PAL_H, + V4L2_STD_PAL_I, V4L2_STD_PAL_D, V4L2_STD_PAL_D1, V4L2_STD_PAL_K, + V4L2_STD_PAL_M, V4L2_STD_PAL_N, V4L2_STD_PAL_Nc, V4L2_STD_PAL_60, + V4L2_STD_NTSC_M, V4L2_STD_NTSC_M_JP, V4L2_STD_NTSC_443, + V4L2_STD_NTSC_M_KR, + V4L2_STD_SECAM_B, V4L2_STD_SECAM_D, V4L2_STD_SECAM_G, + V4L2_STD_SECAM_H, V4L2_STD_SECAM_K, V4L2_STD_SECAM_K1, + V4L2_STD_SECAM_L, V4L2_STD_SECAM_LC, + V4L2_STD_ATSC_8_VSB, V4L2_STD_ATSC_16_VSB, + }; static const char *const psz_standards_list_text[] = - { N_("Default"), N_("SECAM"), N_("PAL"), N_("NTSC") }; + { N_("Default"), "SECAM", "PAL", "NTSC", + "PAL_B", "PAL_B1", "PAL_G", "PAL_H", "PAL_I", "PAL_D", + "PAL_D1", "PAL_K", "PAL_M", "PAL_N", "PAL_Nc", "PAL_60", + "NTSC_M", "NTSC_M_JP", "NTSC_443", "NTSC_M_KR", + "SECAM_B", "SECAM_D", "SECAM_G", "SECAM_H", "SECAM_K", + "SECAM_K1", "SECAM_L", "SECAM_LC", + "ATSC_8_VSB", "ATSC_16_VSB" + }; static const int i_iomethod_list[] = { IO_METHOD_AUTO, IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR }; @@ -240,6 +264,16 @@ static const char *const psz_tuner_audio_modes_list_text[] = #define V4L2_DEFAULT "/dev/video0" #define CFG_PREFIX "v4l2-" +#ifdef HAVE_MAEMO +# define DEFAULT_WIDTH 640 +# define DEFAULT_HEIGHT 492 +#endif + +#ifndef DEFAULT_WIDTH +# define DEFAULT_WIDTH (-1) +# define DEFAULT_HEIGHT (-1) +#endif + vlc_module_begin () set_shortname( N_("Video4Linux2") ) set_description( N_("Video4Linux2 input") ) @@ -259,14 +293,14 @@ vlc_module_begin () add_integer( CFG_PREFIX "io", IO_METHOD_AUTO, NULL, IOMETHOD_TEXT, IOMETHOD_LONGTEXT, true ) change_integer_list( i_iomethod_list, psz_iomethod_list_text, NULL ) - add_integer( CFG_PREFIX "width", -1, NULL, WIDTH_TEXT, + add_integer( CFG_PREFIX "width", DEFAULT_WIDTH, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true ) - add_integer( CFG_PREFIX "height", -1, NULL, HEIGHT_TEXT, + add_integer( CFG_PREFIX "height", DEFAULT_HEIGHT, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true ) add_string( CFG_PREFIX "aspect-ratio", "4:3", NULL, ASPECT_TEXT, ASPECT_LONGTEXT, true ) add_float( CFG_PREFIX "fps", 0, NULL, FPS_TEXT, FPS_LONGTEXT, true ) - add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL, + add_integer( CFG_PREFIX "caching", 50 /* ms */, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ) #ifdef HAVE_LIBV4L2 add_bool( CFG_PREFIX "use-libv4l2", false, NULL, LIBV4L2_TEXT, LIBV4L2_LONGTEXT, true ); @@ -347,8 +381,7 @@ vlc_module_begin () set_callbacks( DemuxOpen, DemuxClose ) add_submodule () - add_shortcut( "v4l2" ) - add_shortcut( "v4l2c" ) + add_shortcut( "v4l2", "v4l2c" ) set_description( N_("Video4Linux2 Compressed A/V") ) set_capability( "access", 0 ) /* use these when open as access_demux fails; VLC will use another demux */ @@ -451,7 +484,7 @@ static const struct * * Try YUV chromas first, then RGB little endian and MJPEG as last resort. */ -static const __u32 p_chroma_fallbacks[] = +static const uint32_t p_chroma_fallbacks[] = { V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV422P, V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_BGR24, V4L2_PIX_FMT_BGR32, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_JPEG }; @@ -536,6 +569,7 @@ struct demux_sys_t float f_fps; /* <= 0.0 mean to grab at full rate */ mtime_t i_video_pts; /* only used when f_fps > 0 */ int i_fourcc; + uint32_t i_block_flags; es_out_id_t *p_es; @@ -550,6 +584,7 @@ struct demux_sys_t #ifdef HAVE_LIBV4L2 /* */ + int (*pf_open)(const char *, int, ...); int (*pf_close)( int ); int (*pf_dup)( int ); int (*pf_ioctl)( int, unsigned long int, ... ); @@ -563,6 +598,7 @@ struct demux_sys_t #ifdef HAVE_LIBV4L2 static void use_kernel_v4l2( demux_sys_t *p_sys ) { + p_sys->pf_open = vlc_open; p_sys->pf_close = close; p_sys->pf_dup = dup; p_sys->pf_ioctl = ioctl; @@ -574,6 +610,7 @@ static void use_kernel_v4l2( demux_sys_t *p_sys ) static void use_libv4l2( demux_sys_t *p_sys ) { + p_sys->pf_open = v4l2_open; p_sys->pf_close = v4l2_close; p_sys->pf_dup = v4l2_dup; p_sys->pf_ioctl = v4l2_ioctl; @@ -583,6 +620,7 @@ static void use_libv4l2( demux_sys_t *p_sys ) p_sys->b_libv4l2 = true; } +# define v4l2_open (p_sys->pf_open) # define v4l2_close (p_sys->pf_close) # define v4l2_dup (p_sys->pf_dup) # define v4l2_ioctl (p_sys->pf_ioctl) @@ -590,6 +628,7 @@ static void use_libv4l2( demux_sys_t *p_sys ) # define v4l2_mmap (p_sys->pf_mmap) # define v4l2_munmap (p_sys->pf_munmap) #else +# define v4l2_open vlc_open # define v4l2_close close # define v4l2_dup dup # define v4l2_ioctl ioctl @@ -642,10 +681,10 @@ static int DemuxOpen( vlc_object_t *p_this ) GetV4L2Params(p_sys, (vlc_object_t *) p_demux); - ParseMRL( p_sys, p_demux->psz_path, (vlc_object_t *) p_demux ); + ParseMRL( p_sys, p_demux->psz_location, (vlc_object_t *) p_demux ); #ifdef HAVE_LIBV4L2 - if( !config_GetInt( p_this, CFG_PREFIX "use-libv4l2" ) ) + if( !var_InheritBool( p_this, CFG_PREFIX "use-libv4l2" ) ) { msg_Dbg( p_this, "Trying direct kernel v4l2" ); use_kernel_v4l2( p_sys ); @@ -696,9 +735,9 @@ static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj ) p_sys->psz_set_ctrls = var_CreateGetString( p_obj, "v4l2-set-ctrls" ); char *psz_aspect = var_CreateGetString( p_obj, "v4l2-aspect-ratio" ); - if( psz_aspect && *psz_aspect && strchr( psz_aspect, ':' ) ) + char *psz_delim = !EMPTY_STR(psz_aspect) ? strchr( psz_aspect, ':' ) : NULL; + if( psz_delim ) { - char *psz_delim = strchr( psz_aspect, ':' ); p_sys->i_aspect = atoi( psz_aspect ) * VOUT_ASPECT_FACTOR / atoi( psz_delim + 1 ); } else @@ -737,30 +776,22 @@ static void ParseMRL( demux_sys_t *p_sys, char *psz_path, vlc_object_t *p_obj ) if( !strncmp( psz_parser, "standard=", strlen( "standard=" ) ) ) { psz_parser += strlen( "standard=" ); - if( !strncmp( psz_parser, "pal", strlen( "pal" ) ) ) - { - p_sys->i_selected_standard_id = V4L2_STD_PAL; - psz_parser += strlen( "pal" ); - } - else if( !strncmp( psz_parser, "ntsc", strlen( "ntsc" ) ) ) - { - p_sys->i_selected_standard_id = V4L2_STD_NTSC; - psz_parser += strlen( "ntsc" ); - } - else if( !strncmp( psz_parser, "secam", strlen( "secam" ) ) ) - { - p_sys->i_selected_standard_id = V4L2_STD_SECAM; - psz_parser += strlen( "secam" ); - } - else if( !strncmp( psz_parser, "default", strlen( "default" ) ) ) + size_t i; + for( i = 0; i < ARRAY_SIZE(psz_standards_list_text); i++ ) { - p_sys->i_selected_standard_id = V4L2_STD_UNKNOWN; - psz_parser += strlen( "default" ); + const char *psz_value = psz_standards_list_text[i]; + size_t i_len = strlen( psz_value ); + if( !strncasecmp( psz_parser, psz_value, i_len ) && + ( psz_parser[i_len] == ':' || psz_parser[i_len] == 0 ) ) + { + p_sys->i_selected_standard_id = i_standards_list[i]; + psz_parser += i_len; + break; + } } - else - { + + if( i == ARRAY_SIZE(psz_standards_list_text) ) p_sys->i_selected_standard_id = i_standards_list[strtol( psz_parser, &psz_parser, 0 )]; - } } else if( !strncmp( psz_parser, "chroma=", strlen( "chroma=" ) ) ) { @@ -1105,19 +1136,23 @@ static int AccessOpen( vlc_object_t * p_this ) GetV4L2Params( p_sys, (vlc_object_t *) p_access ); - ParseMRL( p_sys, p_access->psz_path, (vlc_object_t *) p_access ); + ParseMRL( p_sys, p_access->psz_location, (vlc_object_t *) p_access ); #ifdef HAVE_LIBV4L2 - if( !config_GetInt( p_this, CFG_PREFIX "use-libv4l2" ) ) + if( !var_InheritBool( p_this, CFG_PREFIX "use-libv4l2" ) ) { msg_Dbg( p_this, "Trying direct kernel v4l2" ); use_kernel_v4l2( p_sys ); if( FindMainDevice( p_this, p_sys, false ) == VLC_SUCCESS) { if( p_sys->io == IO_METHOD_READ ) + { ACCESS_SET_CALLBACKS( AccessReadStream, NULL, AccessControl, NULL ); + } else + { ACCESS_SET_CALLBACKS( NULL, AccessRead, AccessControl, NULL ); + } return VLC_SUCCESS; } } @@ -1128,9 +1163,13 @@ static int AccessOpen( vlc_object_t * p_this ) if( FindMainDevice( p_this, p_sys, false ) == VLC_SUCCESS ) { if( p_sys->io == IO_METHOD_READ ) + { ACCESS_SET_CALLBACKS( AccessReadStream, NULL, AccessControl, NULL ); + } else + { ACCESS_SET_CALLBACKS( NULL, AccessRead, AccessControl, NULL ); + } return VLC_SUCCESS; } @@ -1318,7 +1357,8 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) mtime_t i_dur = (mtime_t)((double)1000000 / (double)p_sys->f_fps); /* Did we wait long enough ? (frame rate reduction) */ - if( p_sys->i_video_pts + i_dur > mdate() ) return 0; + if( p_sys->i_video_pts + i_dur > mdate() ) + return NULL; } /* Grab Video Frame */ @@ -1331,7 +1371,7 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) switch( errno ) { case EAGAIN: - return 0; + return NULL; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ @@ -1342,7 +1382,8 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) } p_block = ProcessVideoFrame( p_demux, (uint8_t*)p_sys->p_buffers[0].start, i_ret ); - if( !p_block ) return 0; + if( !p_block ) + return NULL; break; @@ -1357,30 +1398,31 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) switch( errno ) { case EAGAIN: - return 0; + return NULL; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ default: msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" ); - return 0; + return NULL; } } if( buf.index >= p_sys->i_nbuffers ) { msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" ); - return 0; + return NULL; } p_block = ProcessVideoFrame( p_demux, p_sys->p_buffers[buf.index].start, buf.bytesused ); - if( !p_block ) return 0; + if( !p_block ) + return NULL; /* Unlock */ if( v4l2_ioctl( p_sys->i_fd, VIDIOC_QBUF, &buf ) < 0 ) { msg_Err( p_demux, "Failed to unlock (VIDIOC_QBUF)" ); block_Release( p_block ); - return 0; + return NULL; } break; @@ -1396,13 +1438,13 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) switch( errno ) { case EAGAIN: - return 0; + return NULL; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ default: msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" ); - return 0; + return NULL; } } @@ -1417,18 +1459,19 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) if( i >= p_sys->i_nbuffers ) { msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" ); - return 0; + return NULL; } p_block = ProcessVideoFrame( p_demux, (uint8_t*)buf.m.userptr, buf.bytesused ); - if( !p_block ) return 0; + if( !p_block ) + return NULL; /* Unlock */ if( v4l2_ioctl( p_sys->i_fd, VIDIOC_QBUF, &buf ) < 0 ) { msg_Err( p_demux, "Failed to unlock (VIDIOC_QBUF)" ); block_Release( p_block ); - return 0; + return NULL; } break; @@ -1439,6 +1482,7 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys ) /* Timestamp */ p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate(); + p_block->i_flags |= p_sys->i_block_flags; return p_block; } @@ -1451,13 +1495,13 @@ static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size { block_t *p_block; - if( !p_frame ) return 0; + if( !p_frame ) return NULL; /* New block */ if( !( p_block = block_New( p_demux, i_size ) ) ) { msg_Warn( p_demux, "Cannot get new block" ); - return 0; + return NULL; } /* Copy frame */ @@ -1797,7 +1841,7 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) const char *psz_device = p_sys->psz_device; es_format_t es_fmt; - if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 ) + if( ( i_fd = v4l2_open( psz_device, O_RDWR ) ) < 0 ) { msg_Err( p_obj, "cannot open device (%m)" ); goto open_failed; @@ -1869,7 +1913,21 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) msg_Err( p_obj, "cannot set standard (%m)" ); goto open_failed; } - msg_Dbg( p_obj, "Set standard" ); + if( v4l2_ioctl( i_fd, VIDIOC_G_STD, &p_sys->i_selected_standard_id ) < 0 ) + { + msg_Err( p_obj, "cannot get standard (%m). This should never happen!" ); + goto open_failed; + } + msg_Dbg( p_obj, "Set standard to (0x%"PRIx64"):", p_sys->i_selected_standard_id ); + int i_standard; + for( i_standard = 0; i_standardi_standard; i_standard++) + { + if( p_sys->p_standards[i_standard].id & p_sys->i_selected_standard_id ) + { + msg_Dbg( p_obj, " %s", + p_sys->p_standards[i_standard].name ); + } + } } /* Select input */ @@ -1970,7 +2028,7 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) memset( &fmt, 0, sizeof(fmt) ); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if( p_sys->i_width == 0 || p_sys->i_height == 0 ) + if( p_sys->i_width <= 0 || p_sys->i_height <= 0 ) { /* Use current width and height settings */ if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 ) @@ -1979,26 +2037,22 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) goto open_failed; } - p_sys->i_width = fmt.fmt.pix.width; - p_sys->i_height = fmt.fmt.pix.height; + msg_Dbg( p_obj, "found default width and height of %ux%u", + fmt.fmt.pix.width, fmt.fmt.pix.height ); - if( fmt.fmt.pix.field == V4L2_FIELD_ALTERNATE ) + if( p_sys->i_width < 0 || p_sys->i_height < 0 ) { - p_sys->i_height = p_sys->i_height * 2; + msg_Dbg( p_obj, "will try to find optimal width and height." ); } } - else if( p_sys->i_width < 0 || p_sys->i_height < 0 ) - { - msg_Dbg( p_obj, "will try to find optimal width and height." ); - } else { /* Use user specified width and height */ msg_Dbg( p_obj, "trying specified size %dx%d", p_sys->i_width, p_sys->i_height ); + fmt.fmt.pix.width = p_sys->i_width; + fmt.fmt.pix.height = p_sys->i_height; } - fmt.fmt.pix.width = p_sys->i_width; - fmt.fmt.pix.height = p_sys->i_height; fmt.fmt.pix.field = V4L2_FIELD_NONE; if (b_demux) @@ -2081,23 +2135,28 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) &i_width, &i_height ); if( i_width || i_height ) { - msg_Dbg( p_demux, "Found optimal dimensions for framerate %f of %dx%d", - p_sys->f_fps, i_width, i_height ); + msg_Dbg( p_demux, "Found optimal dimensions for framerate %f " + "of %ux%u", p_sys->f_fps, i_width, i_height ); fmt.fmt.pix.width = i_width; fmt.fmt.pix.height = i_height; - if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) {;} + if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) + { + msg_Err( p_obj, "Cannot set size to optimal dimensions " + "%ux%u", i_width, i_height ); + goto open_failed; + } } else { - msg_Warn( p_obj, "Could not find optimal width and height." ); + msg_Warn( p_obj, "Could not find optimal width and height, " + "falling back to driver default." ); } } - - /* Reassign width, height and chroma incase driver override */ - p_sys->i_width = fmt.fmt.pix.width; - p_sys->i_height = fmt.fmt.pix.height; } + p_sys->i_width = fmt.fmt.pix.width; + p_sys->i_height = fmt.fmt.pix.height; + if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 ) {;} /* Print extra info */ msg_Dbg( p_obj, "Driver requires at most %d bytes to store a complete image", fmt.fmt.pix.sizeimage ); @@ -2115,29 +2174,34 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) break; case V4L2_FIELD_INTERLACED: msg_Dbg( p_obj, "Interlacing setting: interleaved (bottom top if M/NTSC, top bottom otherwise)" ); + if( p_sys->i_selected_standard_id == V4L2_STD_NTSC ) + p_sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST; + else + p_sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST; break; case V4L2_FIELD_SEQ_TB: - msg_Dbg( p_obj, "Interlacing setting: sequential top bottom" ); + msg_Dbg( p_obj, "Interlacing setting: sequential top bottom (TODO)" ); break; case V4L2_FIELD_SEQ_BT: - msg_Dbg( p_obj, "Interlacing setting: sequential bottom top" ); + msg_Dbg( p_obj, "Interlacing setting: sequential bottom top (TODO)" ); break; case V4L2_FIELD_ALTERNATE: - msg_Dbg( p_obj, "Interlacing setting: alternate fields" ); + msg_Dbg( p_obj, "Interlacing setting: alternate fields (TODO)" ); + p_sys->i_height = p_sys->i_height * 2; break; case V4L2_FIELD_INTERLACED_TB: msg_Dbg( p_obj, "Interlacing setting: interleaved top bottom" ); + p_sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST; break; case V4L2_FIELD_INTERLACED_BT: msg_Dbg( p_obj, "Interlacing setting: interleaved bottom top" ); + p_sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST; break; default: msg_Warn( p_obj, "Interlacing setting: unknown type (%d)", fmt.fmt.pix.field ); break; } - if( fmt.fmt.pix.field != V4L2_FIELD_NONE ) - msg_Warn( p_obj, "Interlaced inputs haven't been tested. Please report any issue." ); /* Look up final fourcc */ p_sys->i_fourcc = 0; @@ -2175,7 +2239,7 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) char psz_fourcc[5]; memset( &psz_fourcc, 0, sizeof( psz_fourcc ) ); vlc_fourcc_to_char( p_sys->i_fourcc, &psz_fourcc ); - msg_Dbg( p_obj, "supported frame intervals for %4s, %dx%d:", + msg_Dbg( p_obj, "supported frame intervals for %4.4s, %dx%d:", psz_fourcc, frmival.width, frmival.height ); switch( frmival.type ) { @@ -2238,7 +2302,8 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) es_fmt.video.i_height = p_sys->i_height; /* Get aspect-ratio */ - es_fmt.video.i_aspect = p_sys->i_aspect; + es_fmt.video.i_sar_num = p_sys->i_aspect * es_fmt.video.i_height; + es_fmt.video.i_sar_den = VOUT_ASPECT_FACTOR * es_fmt.video.i_width; demux_t *p_demux = (demux_t *) p_obj; msg_Dbg( p_demux, "added new video es %4.4s %dx%d", @@ -2338,7 +2403,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, int i_fd; - if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 ) + if( ( i_fd = v4l2_open( psz_device, O_RDWR ) ) < 0 ) { msg_Err( p_obj, "cannot open video device '%s' (%m)", psz_device ); goto open_failed; @@ -2376,7 +2441,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, p_sys->dev_cap.version & 0xFF, p_sys->dev_cap.bus_info ); - msg_Dbg( p_obj, "the device has the capabilities: (%c) Video Capure, " + msg_Dbg( p_obj, "the device has the capabilities: (%c) Video Capture, " "(%c) Audio, " "(%c) Tuner, " "(%c) Radio", @@ -2395,19 +2460,26 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, if( p_sys->io == IO_METHOD_AUTO ) { if( p_sys->dev_cap.capabilities & V4L2_CAP_STREAMING ) - { - msg_Err(p_obj, "Set p_sys->io to MMAP" ); p_sys->io = IO_METHOD_MMAP; - } else if( p_sys->dev_cap.capabilities & V4L2_CAP_READWRITE ) - { - msg_Err(p_obj, "Set p_sys->io to READ" ); p_sys->io = IO_METHOD_READ; - } else msg_Err( p_obj, "No known I/O method supported" ); } + if( p_sys->dev_cap.capabilities & V4L2_CAP_RDS_CAPTURE ) + msg_Dbg( p_obj, "device supports RDS" ); + +#ifdef V4L2_CAP_HW_FREQ_SEEK + if( p_sys->dev_cap.capabilities & V4L2_CAP_HW_FREQ_SEEK ) + msg_Dbg( p_obj, "device supports hardware frequency seeking" ); +#endif + if( p_sys->dev_cap.capabilities & V4L2_CAP_VBI_CAPTURE ) + msg_Dbg( p_obj, "device supports raw VBI capture" ); + + if( p_sys->dev_cap.capabilities & V4L2_CAP_SLICED_VBI_CAPTURE ) + msg_Dbg( p_obj, "device supports sliced VBI capture" ); + /* Now, enumerate all the video inputs. This is useless at the moment since we have no way to present that info to the user except with debug messages */ @@ -2416,12 +2488,14 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, { struct v4l2_input t_input; memset( &t_input, 0, sizeof(t_input) ); + p_sys->i_input = 0; while( v4l2_ioctl( i_fd, VIDIOC_ENUMINPUT, &t_input ) >= 0 ) { p_sys->i_input++; t_input.index = p_sys->i_input; } + free( p_sys->p_inputs ); p_sys->p_inputs = calloc( 1, p_sys->i_input * sizeof( struct v4l2_input ) ); if( !p_sys->p_inputs ) goto open_failed; @@ -2457,6 +2531,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, t_standards.index = p_sys->i_standard; } + free( p_sys->p_standards ); p_sys->p_standards = calloc( 1, p_sys->i_standard * sizeof( struct v4l2_standard ) ); if( !p_sys->p_standards ) goto open_failed; @@ -2472,7 +2547,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, msg_Dbg( p_obj, "video standard %i is: %s %c", i_standard, p_sys->p_standards[i_standard].name, - (unsigned)i_standard == p_sys->i_selected_standard_id ? '*' : ' ' ); + (p_sys->p_standards[i_standard].id & p_sys->i_selected_standard_id) ? '*' : ' ' ); } } @@ -2522,6 +2597,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, tuner.index = p_sys->i_tuner; } + free( p_sys->p_tuners ); p_sys->p_tuners = calloc( 1, p_sys->i_tuner * sizeof( struct v4l2_tuner ) ); if( !p_sys->p_tuners ) goto open_failed; @@ -2585,6 +2661,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, p_sys->i_codec = i_index; + free( p_sys->p_codecs ); p_sys->p_codecs = calloc( 1, p_sys->i_codec * sizeof( struct v4l2_fmtdesc ) ); for( i_index = 0; i_index < p_sys->i_codec; i_index++ ) @@ -2614,7 +2691,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, memset( &psz_fourcc, 0, sizeof( psz_fourcc ) ); vlc_fourcc_to_char( v4l2chroma_to_fourcc[i].i_fourcc, &psz_fourcc ); - msg_Dbg( p_obj, "device supports chroma %4s [%s, %s]", + msg_Dbg( p_obj, "device supports chroma %4.4s [%s, %s]", psz_fourcc, p_sys->p_codecs[i_index].description, psz_fourcc_v4l2 ); @@ -2664,7 +2741,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, if( !b_codec_supported ) { msg_Dbg( p_obj, - "device codec %4s (%s) not supported", + "device codec %4.4s (%s) not supported", psz_fourcc_v4l2, p_sys->p_codecs[i_index].description ); }