[vlc-commits] Do not keep V4L2 input table in memory and fail on invalid input

Rémi Denis-Courmont git at videolan.org
Thu Sep 1 20:17:47 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Sep  1 20:18:23 2011 +0300| [eda97b3a1484403ea3a590559eae67eca8f28fb5] | committer: Rémi Denis-Courmont

Do not keep V4L2 input table in memory and fail on invalid input

The table is not needed. Furthermore, each input is now enumerated
once rather than twice.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eda97b3a1484403ea3a590559eae67eca8f28fb5
---

 modules/access/v4l2.c |   47 ++++++++---------------------------------------
 1 files changed, 8 insertions(+), 39 deletions(-)

diff --git a/modules/access/v4l2.c b/modules/access/v4l2.c
index bfa1b2b..3e87d6c 100644
--- a/modules/access/v4l2.c
+++ b/modules/access/v4l2.c
@@ -571,10 +571,7 @@ struct demux_sys_t
     /* Video */
     io_method io;
 
-    uint32_t i_input;
-    struct v4l2_input *p_inputs;
     unsigned i_selected_input;
-
     char *psz_standard;
 
     uint32_t i_audio;
@@ -836,7 +833,6 @@ static void CommonClose( vlc_object_t *p_this, demux_sys_t *p_sys )
     if( p_sys->i_fd >= 0 ) v4l2_close( p_sys->i_fd );
     free( p_sys->psz_device );
     free( p_sys->psz_standard );
-    free( p_sys->p_inputs );
     free( p_sys->p_tuners );
     free( p_sys->p_codecs );
     free( p_sys->psz_requested_chroma );
@@ -1632,12 +1628,6 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
 
     /* Select input */
 
-    if( p_sys->i_selected_input >= p_sys->i_input )
-    {
-        msg_Warn( p_obj, "invalid input: using default instead" );
-        p_sys->i_selected_input = 0;
-    }
-
     if( v4l2_ioctl( i_fd, VIDIOC_S_INPUT, &p_sys->i_selected_input ) < 0 )
     {
         msg_Err( p_obj, "cannot set input %u: %m", p_sys->i_selected_input );
@@ -2144,38 +2134,17 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
 
     if( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE )
     {
-        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 )
-        {
-            if( t_input.index != p_sys->i_input )
-                break;
-            p_sys->i_input++;
-            t_input.index = p_sys->i_input;
-        }
+        struct v4l2_input 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 error;
-
-        for( unsigned i_index = 0; i_index < p_sys->i_input; i_index++ )
+        input.index = 0;
+        while( v4l2_ioctl( i_fd, VIDIOC_ENUMINPUT, &input ) >= 0 )
         {
-            p_sys->p_inputs[i_index].index = i_index;
-
-            if( v4l2_ioctl( i_fd, VIDIOC_ENUMINPUT, &p_sys->p_inputs[i_index] ) )
-            {
-                msg_Err( p_obj, "cannot get video input characteristics: %m" );
-                goto error;
-            }
             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
-                                        == V4L2_INPUT_TYPE_TUNER ?
-                                        "Tuner adapter" :
-                                        "External analog input",
-                                i_index == p_sys->i_selected_input ? '*' : ' ' );
+                     input.index, input.name,
+                     input.type == V4L2_INPUT_TYPE_TUNER
+                         ? "Tuner adapter" : "External analog input",
+                     input.index == p_sys->i_selected_input ? '*' : ' ' );
+            input.index++;
         }
     }
 



More information about the vlc-commits mailing list