static int AccessOpen ( vlc_object_t * );
static void AccessClose( vlc_object_t * );
+#define DEVICE_TEXT N_( "Device" )
+#define DEVICE_LONGTEXT N_( \
+ "Video device (Default: /dev/video0)." )
#define STANDARD_TEXT N_( "Standard" )
#define STANDARD_LONGTEXT N_( \
"Video standard (Default, SECAM, PAL, or NTSC)." )
static const char *const psz_iomethod_list_text[] =
{ N_("AUTO"), N_("READ"), N_("MMAP"), N_("USERPTR") };
-static const int i_tuner_audio_modes_list[] =
- { V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO,
+static const int i_tuner_audio_modes_list[] = {
+ -1, V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO,
V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2,
V4L2_TUNER_MODE_SAP, V4L2_TUNER_MODE_LANG1_LANG2 };
-static const char *const psz_tuner_audio_modes_list_text[] =
- { N_( "Mono" ),
+static const char *const psz_tuner_audio_modes_list_text[] = {
+ N_("Unspecified"),
+ N_( "Mono" ),
N_( "Stereo" ),
N_( "Primary language (Analog TV tuners only)" ),
N_( "Secondary language (Analog TV tuners only)" ),
set_subcategory( SUBCAT_INPUT_ACCESS )
set_section( N_( "Video input" ), NULL )
+ add_string( CFG_PREFIX "dev", "/dev/video0", DEVICE_TEXT, DEVICE_LONGTEXT,
+ false )
add_integer( CFG_PREFIX "standard", 0, STANDARD_TEXT,
STANDARD_LONGTEXT, false )
change_integer_list( i_standards_list, psz_standards_list_text )
add_string( CFG_PREFIX "set-ctrls", NULL, S_CTRLS_TEXT,
S_CTRLS_LONGTEXT, true )
- add_obsolete_string( CFG_PREFIX "dev" )
-
add_obsolete_string( CFG_PREFIX "adev" )
add_obsolete_integer( CFG_PREFIX "audio-method" )
add_obsolete_bool( CFG_PREFIX "stereo" )
struct v4l2_capability dev_cap;
- int i_input;
+ unsigned i_input;
struct v4l2_input *p_inputs;
- int i_selected_input;
+ unsigned i_selected_input;
- int i_standard;
+ unsigned i_standard;
struct v4l2_standard *p_standards;
v4l2_std_id i_selected_standard_id;
- int i_audio;
+ unsigned i_audio;
/* V4L2 devices cannot have more than 32 audio inputs */
struct v4l2_audio p_audios[32];
int i_selected_audio_input;
- int i_tuner;
+ unsigned i_tuner;
struct v4l2_tuner *p_tuners;
- int i_codec;
+ unsigned i_codec;
struct v4l2_fmtdesc *p_codecs;
struct buffer_t *p_buffers;
int i_height;
unsigned int i_aspect;
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;
/* Controls */
char *psz_set_ctrls;
-
#ifdef HAVE_LIBV4L2
/* */
int (*pf_open)(const char *, int, ...);
*****************************************************************************/
static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj )
{
- p_sys->i_video_pts = -1;
+ p_sys->psz_device = var_CreateGetNonEmptyString( p_obj, "v4l2-dev" );
p_sys->i_selected_standard_id =
- i_standards_list[var_CreateGetInteger( p_obj, "v4l2-standard" )];
-
+ var_CreateGetInteger( p_obj, "v4l2-standard" );
p_sys->i_selected_input = var_CreateGetInteger( p_obj, "v4l2-input" );
p_sys->i_selected_audio_input =
var_CreateGetInteger( p_obj, "v4l2-audio-input" );
}
free( psz_aspect );
- p_sys->psz_device = NULL;
p_sys->i_fd = -1;
p_sys->p_es = NULL;
/* Main device */
if( *psz_dup )
+ {
+ free( p_sys->psz_device );
p_sys->psz_device = strdup( psz_dup );
- else
+ }
+ else if( p_sys->psz_device == NULL )
p_sys->psz_device = strdup( V4L2_DEFAULT );
free( psz_dup );
}
fd.revents = 0;
/* Wait for data */
- if( poll( &fd, 1, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
- {
- if( fd.revents & (POLLIN|POLLPRI) )
- {
- return GrabVideo( VLC_OBJECT(p_access), p_sys );
- }
- }
+ if( poll( &fd, 1, 500 ) > 0 ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
+ return GrabVideo( VLC_OBJECT(p_access), p_sys );
return NULL;
}
if( i_ret < 0 )
{
- msg_Err( p_access, "Polling error (%m)." );
+ if( errno != EINTR )
+ msg_Err( p_access, "poll error" );
return -1;
}
fd.revents = 0;
/* Wait for data */
- if( poll( &fd, 1, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
- {
- if( fd.revents & (POLLIN|POLLPRI) )
+ /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
+ while( poll( &fd, 1, 500 ) == -1 )
+ if( errno != EINTR )
{
- block_t *p_block = GrabVideo( VLC_OBJECT(p_demux), p_sys );
- if( p_block )
- {
- es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
- es_out_Send( p_demux->out, p_sys->p_es, p_block );
- }
+ msg_Err( p_demux, "poll error: %m" );
+ return -1;
+ }
+
+ if( fd.revents )
+ {
+ block_t *p_block = GrabVideo( VLC_OBJECT(p_demux), p_sys );
+ if( p_block )
+ {
+ es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
+ es_out_Send( p_demux->out, p_sys->p_es, p_block );
}
}
struct v4l2_buffer buf;
ssize_t i_ret;
- if( p_sys->f_fps >= 0.1 && p_sys->i_video_pts > 0 )
- {
- 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 NULL;
- }
-
/* Grab Video Frame */
switch( p_sys->io )
{
}
/* Timestamp */
- p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate();
+ p_block->i_pts = p_block->i_dts = mdate();
p_block->i_flags |= p_sys->i_block_flags;
return p_block;
{
demux_sys_t *p_sys = p_demux->p_sys;
- for( int i_index = 0; i_index < p_sys->i_codec; i_index++ )
+ for( unsigned i_index = 0; i_index < p_sys->i_codec; i_index++ )
{
if( p_sys->p_codecs[i_index].pixelformat == i_pixelformat )
return true;
}
#endif
+ /* Select standard */
+
+ if( p_sys->i_selected_standard_id != V4L2_STD_UNKNOWN )
+ {
+ if( v4l2_ioctl( i_fd, VIDIOC_S_STD, &p_sys->i_selected_standard_id ) < 0 )
+ {
+ msg_Err( p_obj, "cannot set standard (%m)" );
+ goto open_failed;
+ }
+ 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"):", (int64_t)p_sys->i_selected_standard_id );
+ for(unsigned i_standard = 0; i_standard<p_sys->i_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 );
+ }
+ }
+ }
+
/* Tune the tuner */
if( p_sys->i_frequency >= 0 )
{
- if( p_sys->i_cur_tuner < 0 || p_sys->i_cur_tuner >= p_sys->i_tuner )
+ if( p_sys->i_cur_tuner < 0 || (unsigned)p_sys->i_cur_tuner >= p_sys->i_tuner )
{
msg_Err( p_obj, "invalid tuner %d.", p_sys->i_cur_tuner );
goto open_failed;
/* Set the tuner's audio mode */
if( p_sys->i_audio_mode >= 0 )
{
- if( p_sys->i_cur_tuner < 0 || p_sys->i_cur_tuner >= p_sys->i_tuner )
+ if( p_sys->i_cur_tuner < 0 || (unsigned)p_sys->i_cur_tuner >= p_sys->i_tuner )
{
msg_Err( p_obj, "invalid tuner %d.", p_sys->i_cur_tuner );
goto open_failed;
msg_Dbg( p_obj, "Tuner audio mode set" );
}
- /* Select standard */
-
- if( p_sys->i_selected_standard_id != V4L2_STD_UNKNOWN )
- {
- if( v4l2_ioctl( i_fd, VIDIOC_S_STD, &p_sys->i_selected_standard_id ) < 0 )
- {
- msg_Err( p_obj, "cannot set standard (%m)" );
- goto open_failed;
- }
- 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_standard<p_sys->i_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 */
if( p_sys->i_selected_input >= p_sys->i_input )
if( p_sys->i_audio > 0 )
{
if( p_sys->i_selected_audio_input < 0
- || p_sys->i_selected_audio_input >= p_sys->i_audio )
+ || (unsigned)p_sys->i_selected_audio_input >= p_sys->i_audio )
{
msg_Warn( p_obj, "invalid audio input. Using the default one" );
p_sys->i_selected_audio_input = 0;
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;
+ /* Framerate */
+ es_fmt.video.i_frame_rate = p_sys->f_fps * INT64_C(1000000);
+ es_fmt.video.i_frame_rate_base = INT64_C(1000000);
+
demux_t *p_demux = (demux_t *) p_obj;
msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
(char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
const char *psz_device )
{
- int i_index;
- int i_standard;
-
int i_fd;
if( ( i_fd = v4l2_open( psz_device, O_RDWR ) ) < 0 )
p_sys->i_input = 0;
while( v4l2_ioctl( i_fd, VIDIOC_ENUMINPUT, &t_input ) >= 0 )
{
+ if( t_input.index != p_sys->i_input )
+ break;
p_sys->i_input++;
t_input.index = p_sys->i_input;
}
p_sys->p_inputs = calloc( 1, p_sys->i_input * sizeof( struct v4l2_input ) );
if( !p_sys->p_inputs ) goto open_failed;
- for( i_index = 0; i_index < p_sys->i_input; i_index++ )
+ for( unsigned i_index = 0; i_index < p_sys->i_input; i_index++ )
{
p_sys->p_inputs[i_index].index = i_index;
msg_Err( p_obj, "cannot get video input characteristics (%m)" );
goto open_failed;
}
- msg_Dbg( p_obj, "video input %i (%s) has type: %s %c",
+ msg_Dbg( p_obj, "video input %u (%s) has type: %s %c",
i_index,
p_sys->p_inputs[i_index].name,
p_sys->p_inputs[i_index].type
p_sys->i_standard = 0;
while( v4l2_ioctl( i_fd, VIDIOC_ENUMSTD, &t_standards ) >=0 )
{
+ if( t_standards.index != p_sys->i_standard )
+ break;
p_sys->i_standard++;
t_standards.index = p_sys->i_standard;
}
p_sys->p_standards = calloc( 1, p_sys->i_standard * sizeof( struct v4l2_standard ) );
if( !p_sys->p_standards ) goto open_failed;
- for( i_standard = 0; i_standard < p_sys->i_standard; i_standard++ )
+ for( unsigned i_standard = 0; i_standard < p_sys->i_standard; i_standard++ )
{
p_sys->p_standards[i_standard].index = i_standard;
msg_Err( p_obj, "cannot get video input standards (%m)" );
goto open_failed;
}
- msg_Dbg( p_obj, "video standard %i is: %s %c",
+ msg_Dbg( p_obj, "video standard %u is: %s %c",
i_standard,
p_sys->p_standards[i_standard].name,
(p_sys->p_standards[i_standard].id & p_sys->i_selected_standard_id) ? '*' : ' ' );
}
/* initialize the structures for the ioctls */
- for( i_index = 0; i_index < 32; i_index++ )
+ for( unsigned i_index = 0; i_index < 32; i_index++ )
{
p_sys->p_audios[i_index].index = i_index;
}
goto open_failed;
}
- msg_Dbg( p_obj, "audio input %i (%s) is %s %s %c",
+ msg_Dbg( p_obj, "audio input %u (%s) is %s %s %c",
p_sys->i_audio,
p_sys->p_audios[p_sys->i_audio].name,
p_sys->p_audios[p_sys->i_audio].capability &
p_sys->p_audios[p_sys->i_audio].capability &
V4L2_AUDCAP_AVL ?
"(Automatic Volume Level supported)" : "",
- p_sys->i_audio == p_sys->i_selected_audio_input ? '*' : ' ' );
+ p_sys->i_audio == (unsigned)p_sys->i_selected_audio_input ? '*' : ' ' );
p_sys->i_audio++;
}
p_sys->i_tuner = 0;
while( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &tuner ) >= 0 )
{
+ if( tuner.index != p_sys->i_tuner )
+ break;
p_sys->i_tuner++;
memset( &tuner, 0, sizeof(tuner) );
tuner.index = p_sys->i_tuner;
p_sys->p_tuners = calloc( 1, p_sys->i_tuner * sizeof( struct v4l2_tuner ) );
if( !p_sys->p_tuners ) goto open_failed;
- for( i_index = 0; i_index < p_sys->i_tuner; i_index++ )
+ for( unsigned i_index = 0; i_index < p_sys->i_tuner; i_index++ )
{
p_sys->p_tuners[i_index].index = i_index;
msg_Err( p_obj, "cannot get tuner characteristics (%m)" );
goto open_failed;
}
- msg_Dbg( p_obj, "tuner %i (%s) has type: %s, "
+ msg_Dbg( p_obj, "tuner %u (%s) has type: %s, "
"frequency range: %.1f %s -> %.1f %s",
i_index,
p_sys->p_tuners[i_index].name,
msg_Err( p_obj, "cannot get tuner frequency (%m)" );
goto open_failed;
}
- msg_Dbg( p_obj, "tuner %i (%s) frequency: %.1f %s",
+ msg_Dbg( p_obj, "tuner %u (%s) frequency: %.1f %s",
i_index,
p_sys->p_tuners[i_index].name,
frequency.frequency * 62.5,
{
struct v4l2_fmtdesc codec;
- i_index = 0;
+ unsigned i_index = 0;
memset( &codec, 0, sizeof(codec) );
codec.index = i_index;
codec.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &codec ) >= 0 )
{
+ if( codec.index != i_index )
+ break;
i_index++;
codec.index = i_index;
}