]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l2.c
Move MODULE_* predefined constants from vlc-config to Makefile
[vlc] / modules / access / v4l2.c
index 5a5c888ee8d3b01e804727d93731cef2bfcd74d1..98bd116b86195018f2a96c23dff0b54a9400733e 100644 (file)
@@ -74,6 +74,9 @@ static void DemuxClose( vlc_object_t * );
 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)." )
@@ -249,12 +252,13 @@ static const int i_iomethod_list[] =
 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)" ),
@@ -281,6 +285,8 @@ vlc_module_begin ()
     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 )
@@ -369,8 +375,6 @@ vlc_module_begin ()
     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" )
@@ -541,23 +545,23 @@ struct demux_sys_t
 
     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;
@@ -705,9 +709,10 @@ static int DemuxOpen( vlc_object_t *p_this )
  *****************************************************************************/
 static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj )
 {
-    p_sys->i_selected_standard_id =
-        i_standards_list[var_CreateGetInteger( p_obj, "v4l2-standard" )];
+    p_sys->psz_device = var_CreateGetNonEmptyString( p_obj, "v4l2-dev" );
 
+    p_sys->i_selected_standard_id =
+        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" );
@@ -743,7 +748,6 @@ static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj )
     }
     free( psz_aspect );
 
-    p_sys->psz_device = NULL;
     p_sys->i_fd = -1;
 
     p_sys->p_es = NULL;
@@ -1001,8 +1005,11 @@ static void ParseMRL( demux_sys_t *p_sys, char *psz_path, vlc_object_t *p_obj )
 
     /* 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 );
 }
@@ -1288,7 +1295,8 @@ static ssize_t AccessReadStream( access_t * p_access, uint8_t * p_buffer, size_t
 
     if( i_ret < 0 )
     {
-        msg_Err( p_access, "Polling error (%m)." );
+        if( errno != EINTR )
+            msg_Err( p_access, "poll error" );
         return -1;
     }
 
@@ -1627,7 +1635,7 @@ static bool IsPixelFormatSupported( demux_t *p_demux, unsigned int i_pixelformat
 {
     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;
@@ -1850,10 +1858,35 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
     }
 #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;
@@ -1874,7 +1907,7 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
     /* 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;
@@ -1891,32 +1924,6 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
         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 )
@@ -1936,7 +1943,7 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
     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;
@@ -2389,9 +2396,6 @@ open_failed:
 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 )
@@ -2492,7 +2496,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
         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;
 
@@ -2501,7 +2505,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
                 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
@@ -2530,7 +2534,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
         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;
 
@@ -2539,7 +2543,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
                 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) ? '*' : ' ' );
@@ -2547,7 +2551,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
     }
 
     /* 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;
     }
@@ -2564,7 +2568,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
                 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 &
@@ -2573,7 +2577,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
                                 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++;
         }
@@ -2598,7 +2602,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
         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;
 
@@ -2607,7 +2611,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
                 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,
@@ -2630,7 +2634,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
                 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,
@@ -2645,7 +2649,7 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
     {
         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;