Commit fbc0d868 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Open V4L2 node and initialize libv4l2 only once

parent 58794a90
...@@ -446,8 +446,7 @@ static bool IsPixelFormatSupported( demux_t *p_demux, ...@@ -446,8 +446,7 @@ static bool IsPixelFormatSupported( demux_t *p_demux,
unsigned int i_pixelformat ); unsigned int i_pixelformat );
static int OpenVideoDev( vlc_object_t *, demux_sys_t *, bool ); static int OpenVideoDev( vlc_object_t *, demux_sys_t *, bool );
static bool ProbeVideoDev( vlc_object_t *, demux_sys_t *, static int ProbeVideoDev( vlc_object_t *, demux_sys_t *, int );
const char *psz_device );
static int ControlList( vlc_object_t *, int , bool, bool ); static int ControlList( vlc_object_t *, int , bool, bool );
static int Control( vlc_object_t *, int i_fd, static int Control( vlc_object_t *, int i_fd,
...@@ -624,13 +623,7 @@ static int FindMainDevice( vlc_object_t *p_this, demux_sys_t *p_sys, ...@@ -624,13 +623,7 @@ static int FindMainDevice( vlc_object_t *p_this, demux_sys_t *p_sys,
{ {
/* TODO: if using default device, loop through all /dev/video* until /* TODO: if using default device, loop through all /dev/video* until
* one works */ * one works */
msg_Dbg( p_this, "opening device '%s'", p_sys->psz_device ); p_sys->i_fd = OpenVideoDev( p_this, p_sys, b_demux );
if( ProbeVideoDev( p_this, p_sys, p_sys->psz_device ) )
{
msg_Dbg( p_this, "'%s' is a video device", p_sys->psz_device );
p_sys->i_fd = OpenVideoDev( p_this, p_sys, b_demux );
}
if( p_sys->i_fd < 0 ) return VLC_EGENERIC; if( p_sys->i_fd < 0 ) return VLC_EGENERIC;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1529,6 +1522,8 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) ...@@ -1529,6 +1522,8 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
const char *psz_device = p_sys->psz_device; const char *psz_device = p_sys->psz_device;
es_format_t es_fmt; es_format_t es_fmt;
msg_Dbg( p_obj, "opening device '%s'", psz_device );
int i_fd = vlc_open( psz_device, O_RDWR ); int i_fd = vlc_open( psz_device, O_RDWR );
if( i_fd == -1 ) if( i_fd == -1 )
{ {
...@@ -1552,6 +1547,9 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) ...@@ -1552,6 +1547,9 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
} }
#endif #endif
if( ProbeVideoDev( p_obj, p_sys, i_fd ) )
goto error;
/* Select input */ /* Select input */
if( v4l2_ioctl( i_fd, VIDIOC_S_INPUT, &p_sys->i_selected_input ) < 0 ) if( v4l2_ioctl( i_fd, VIDIOC_S_INPUT, &p_sys->i_selected_input ) < 0 )
{ {
...@@ -2054,39 +2052,15 @@ error: ...@@ -2054,39 +2052,15 @@ error:
/***************************************************************************** /*****************************************************************************
* ProbeVideoDev: probe video for capabilities * ProbeVideoDev: probe video for capabilities
*****************************************************************************/ *****************************************************************************/
static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, static int ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, int i_fd )
const char *psz_device )
{ {
int i_fd = vlc_open( psz_device, O_RDWR );
if( i_fd == -1 )
{
msg_Err( p_obj, "cannot open video device %s: %m", psz_device );
return -1;
}
#ifdef HAVE_LIBV4L2
/* Note the v4l2_xxx functions are designed so that if they get passed an
unknown fd, the will behave exactly as their regular xxx counterparts,
so if v4l2_fd_open fails, we continue as normal (missing the libv4l2
custom cam format to normal formats conversion). Chances are big we will
still fail then though, as normally v4l2_fd_open only fails if the
device is not a v4l2 device. */
if( p_sys->b_libv4l2 )
{
int libv4l2_fd;
libv4l2_fd = v4l2_fd_open( i_fd, 0 );
if( libv4l2_fd != -1 )
i_fd = libv4l2_fd;
}
#endif
/* Get device capabilites */ /* Get device capabilites */
struct v4l2_capability cap; struct v4l2_capability cap;
if( v4l2_ioctl( i_fd, VIDIOC_QUERYCAP, &cap ) < 0 ) if( v4l2_ioctl( i_fd, VIDIOC_QUERYCAP, &cap ) < 0 )
{ {
msg_Err( p_obj, "cannot get video capabilities: %m" ); msg_Err( p_obj, "cannot get video capabilities: %m" );
goto error; return -1;
} }
msg_Dbg( p_obj, "device %s using driver %s (version %u.%u.%u) on %s", msg_Dbg( p_obj, "device %s using driver %s (version %u.%u.%u) on %s",
...@@ -2111,7 +2085,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2111,7 +2085,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
else else
{ {
msg_Err( p_obj, "no supported I/O method" ); msg_Err( p_obj, "no supported I/O method" );
goto error; return -1;
} }
if( cap.capabilities & V4L2_CAP_RDS_CAPTURE ) if( cap.capabilities & V4L2_CAP_RDS_CAPTURE )
...@@ -2162,7 +2136,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2162,7 +2136,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
if( v4l2_ioctl( i_fd, VIDIOC_G_AUDIO, &p_sys->p_audios[ p_sys->i_audio] ) < 0 ) if( v4l2_ioctl( i_fd, VIDIOC_G_AUDIO, &p_sys->p_audios[ p_sys->i_audio] ) < 0 )
{ {
msg_Err( p_obj, "cannot get audio input characteristics: %m" ); msg_Err( p_obj, "cannot get audio input characteristics: %m" );
goto error; return -1;
} }
msg_Dbg( p_obj, "audio input %u (%s) is %s %s %c", msg_Dbg( p_obj, "audio input %u (%s) is %s %s %c",
...@@ -2197,7 +2171,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2197,7 +2171,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
free( p_sys->p_tuners ); free( p_sys->p_tuners );
p_sys->p_tuners = calloc( 1, p_sys->i_tuner * sizeof( struct v4l2_tuner ) ); p_sys->p_tuners = calloc( 1, p_sys->i_tuner * sizeof( struct v4l2_tuner ) );
if( !p_sys->p_tuners ) goto error; if( !p_sys->p_tuners ) return -1;
for( unsigned i_index = 0; i_index < p_sys->i_tuner; i_index++ ) for( unsigned i_index = 0; i_index < p_sys->i_tuner; i_index++ )
{ {
...@@ -2206,7 +2180,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2206,7 +2180,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
if( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &p_sys->p_tuners[i_index] ) ) if( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &p_sys->p_tuners[i_index] ) )
{ {
msg_Err( p_obj, "cannot get tuner characteristics: %m" ); msg_Err( p_obj, "cannot get tuner characteristics: %m" );
goto error; return -1;
} }
msg_Dbg( p_obj, "tuner %u (%s) has type: %s, " msg_Dbg( p_obj, "tuner %u (%s) has type: %s, "
"frequency range: %.1f %s -> %.1f %s", "frequency range: %.1f %s -> %.1f %s",
...@@ -2229,7 +2203,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2229,7 +2203,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
if( v4l2_ioctl( i_fd, VIDIOC_G_FREQUENCY, &frequency ) < 0 ) if( v4l2_ioctl( i_fd, VIDIOC_G_FREQUENCY, &frequency ) < 0 )
{ {
msg_Err( p_obj, "cannot get tuner frequency: %m" ); msg_Err( p_obj, "cannot get tuner frequency: %m" );
goto error; return -1;
} }
msg_Dbg( p_obj, "tuner %u (%s) frequency: %.1f %s", msg_Dbg( p_obj, "tuner %u (%s) frequency: %.1f %s",
i_index, i_index,
...@@ -2272,7 +2246,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2272,7 +2246,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &p_sys->p_codecs[i_index] ) < 0 ) if( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &p_sys->p_codecs[i_index] ) < 0 )
{ {
msg_Err( p_obj, "cannot get codec description: %m" ); msg_Err( p_obj, "cannot get codec description: %m" );
goto error; return -1;
} }
/* only print if vlc supports the format */ /* only print if vlc supports the format */
...@@ -2347,13 +2321,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, ...@@ -2347,13 +2321,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
} }
} }
} }
v4l2_close( i_fd ); return 0;
return true;
error:
v4l2_close( i_fd );
return false;
} }
static void name2var( unsigned char *name ) static void name2var( unsigned char *name )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment