]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l2/v4l2.c
Fix segfault on 64 bit archs. (0 != NULL)
[vlc] / modules / access / v4l2 / v4l2.c
index ad1dfb6c380c0ebf956ce6901ddb5e7bbd507429..f773353644a7abe5f7bd183052dc4e1853c3d587 100644 (file)
@@ -42,7 +42,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_access.h>
 #include <vlc_demux.h>
 #include <vlc_input.h>
@@ -85,7 +86,7 @@ static void AccessClose( vlc_object_t * );
 #define CHROMA_TEXT N_("Video input chroma format")
 #define CHROMA_LONGTEXT N_( \
     "Force the Video4Linux2 video device to use a specific chroma format " \
-    "(eg. I420 or I422 for raw images, MJPEG for M-JPEG compressed input) " \
+    "(eg. I420 or I422 for raw images, MJPG for M-JPEG compressed input) " \
     "(Complete list: GREY, I240, RV16, RV15, RV24, RV32, YUY2, YUYV, UYVY, " \
     "I41N, I422, I420, I411, I410, MJPG)")
 #define INPUT_TEXT N_( "Input" )
@@ -239,21 +240,21 @@ typedef enum {
     IO_METHOD_USERPTR,
 } io_method;
 
-static int i_standards_list[] =
+static const int i_standards_list[] =
     { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };
-static const char *psz_standards_list_text[] =
+static const char *const psz_standards_list_text[] =
     { N_("Default"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
 
-static int i_iomethod_list[] =
+static const int i_iomethod_list[] =
     { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR };
-static const char *psz_iomethod_list_text[] =
+static const char *const psz_iomethod_list_text[] =
     { N_("READ"), N_("MMAP"),  N_("USERPTR") };
 
-static int i_tuner_audio_modes_list[] =
+static const int i_tuner_audio_modes_list[] =
     { 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 *psz_tuner_audio_modes_list_text[] =
+static const char *const psz_tuner_audio_modes_list_text[] =
     { N_( "Mono" ),
       N_( "Stereo" ),
       N_( "Primary language (Analog TV tuners only)" ),
@@ -271,8 +272,8 @@ static const char *psz_tuner_audio_modes_list_text[] =
 #define CFG_PREFIX "v4l2-"
 
 vlc_module_begin();
-    set_shortname( _("Video4Linux2") );
-    set_description( _("Video4Linux2 input") );
+    set_shortname( N_("Video4Linux2") );
+    set_description( N_("Video4Linux2 input") );
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_ACCESS );
 
@@ -281,7 +282,7 @@ vlc_module_begin();
                 false );
     add_integer( CFG_PREFIX "standard", 0, NULL, STANDARD_TEXT,
                  STANDARD_LONGTEXT, false );
-        change_integer_list( i_standards_list, psz_standards_list_text, 0 );
+        change_integer_list( i_standards_list, psz_standards_list_text, NULL );
     add_string( CFG_PREFIX "chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
                 true );
     add_integer( CFG_PREFIX "input", 0, NULL, INPUT_TEXT, INPUT_LONGTEXT,
@@ -290,7 +291,7 @@ vlc_module_begin();
                  AUDIO_INPUT_LONGTEXT, true );
     add_integer( CFG_PREFIX "io", IO_METHOD_MMAP, NULL, IOMETHOD_TEXT,
                  IOMETHOD_LONGTEXT, true );
-        change_integer_list( i_iomethod_list, psz_iomethod_list_text, 0 );
+        change_integer_list( i_iomethod_list, psz_iomethod_list_text, NULL );
     add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
                 WIDTH_LONGTEXT, true );
     add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
@@ -378,7 +379,7 @@ vlc_module_begin();
 
     add_submodule();
     add_shortcut( "v4l2c" );
-    set_description( _("Video4Linux2 Compressed A/V") );
+    set_description( N_("Video4Linux2 Compressed A/V") );
     set_capability( "access", 0 );
     /* use these when open as access_demux fails; VLC will use another demux */
     set_callbacks( AccessOpen, AccessClose );
@@ -434,7 +435,7 @@ static int AccessControlResetCallback( vlc_object_t *p_this,
                                        const char *psz_var, vlc_value_t oldval,
                                        vlc_value_t newval, void *p_data );
 
-static struct
+static const struct
 {
     unsigned int i_v4l2;
     int i_fourcc;
@@ -477,9 +478,9 @@ static struct
  */
 static const __u32 p_chroma_fallbacks[] =
 { V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV422P,
-  V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_MJPEG };
+  V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_MJPEG };
 
-static struct
+static const struct
 {
     const char *psz_name;
     unsigned int i_cid;
@@ -1139,6 +1140,7 @@ static void DemuxClose( vlc_object_t *p_this )
 
 static void CommonClose( vlc_object_t *p_this, demux_sys_t *p_sys )
 {
+    (void)p_this;
     /* Close */
     if( p_sys->i_fd_video >= 0 ) close( p_sys->i_fd_video );
 #ifdef HAVE_ALSA
@@ -1322,7 +1324,7 @@ static ssize_t AccessRead( access_t * p_access, uint8_t * p_buffer, size_t i_len
 
     do
     {
-        if( p_access->b_die )
+        if( !vlc_object_alive (p_access) )
             return 0;
 
         ufd.revents = 0;
@@ -1628,7 +1630,7 @@ static block_t* GrabAudio( demux_t *p_demux )
             /* Test for overrun */
             if( i_correction_delta > p_sys->i_audio_max_frame_size )
             {
-                msg_Warn( p_demux, "ALSA read overrun (%d > %d)",
+                msg_Warn( p_demux, "ALSA read overrun (%zu > %zu)",
                           i_correction_delta, p_sys->i_audio_max_frame_size );
                 i_correction_delta = p_sys->i_audio_max_frame_size;
                 snd_pcm_prepare( p_sys->p_alsa_pcm );
@@ -1646,7 +1648,7 @@ static block_t* GrabAudio( demux_t *p_demux )
 
     /* Timestamp */
     p_block->i_pts = p_block->i_dts =
-        mdate() - I64C(1000000) * (mtime_t)i_correct /
+        mdate() - INT64_C(1000000) * (mtime_t)i_correct /
         2 / ( p_sys->b_stereo ? 2 : 1) / p_sys->i_sample_rate;
 
     return p_block;
@@ -1661,18 +1663,12 @@ static int InitRead( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
 
     p_sys->p_buffers = calloc( 1, sizeof( *p_sys->p_buffers ) );
     if( !p_sys->p_buffers )
-    {
-        msg_Err( p_demux, "Out of memory" );
         goto open_failed;
-    }
 
     p_sys->p_buffers[0].length = i_buffer_size;
     p_sys->p_buffers[0].start = malloc( i_buffer_size );
     if( !p_sys->p_buffers[0].start )
-    {
-        msg_Err( p_demux, "Out of memory" );
         goto open_failed;
-    }
 
     return VLC_SUCCESS;
 
@@ -1766,32 +1762,25 @@ static int InitUserP( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
     if( ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
     {
         msg_Err( p_demux, "device does not support user pointer i/o" );
-        goto open_failed;
+        return VLC_EGENERIC;
     }
 
     p_sys->p_buffers = calloc( 4, sizeof( *p_sys->p_buffers ) );
     if( !p_sys->p_buffers )
-    {
-        msg_Err( p_demux, "Out of memory" );
         goto open_failed;
-    }
 
     for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < 4; ++p_sys->i_nbuffers )
     {
         p_sys->p_buffers[p_sys->i_nbuffers].length = i_buffer_size;
-        posix_memalign( &p_sys->p_buffers[p_sys->i_nbuffers].start,
-                /* boundary */ i_page_size, i_buffer_size );
-
-        if( !p_sys->p_buffers[p_sys->i_nbuffers].start )
-        {
-            msg_Err( p_demux, "out of memory" );
+        if( posix_memalign( &p_sys->p_buffers[p_sys->i_nbuffers].start,
+                /* boundary */ i_page_size, i_buffer_size ) )
             goto open_failed;
-        }
     }
 
     return VLC_SUCCESS;
 
 open_failed:
+    free( p_sys->p_buffers );
     return VLC_EGENERIC;
 
 }
@@ -2259,7 +2248,6 @@ static int OpenAudioDevAlsa( vlc_object_t *p_this, demux_sys_t *p_sys,
                              bool b_demux )
 {
     char *psz_device = p_sys->psz_adev;
-    int i_fd = 0;
     p_sys->p_alsa_pcm = NULL;
     char* psz_alsa_device_name = NULL;
     snd_pcm_hw_params_t *p_hw_params = NULL;
@@ -2426,18 +2414,15 @@ static int OpenAudioDevAlsa( vlc_object_t *p_this, demux_sys_t *p_sys,
         goto adev_fail;
     }
 
-    /* Return a fake handle so other tests work */
-    i_fd = 1;
-
     free( psz_alsa_device_name );
 
     if( !p_sys->psz_adev )
         p_sys->psz_adev = strdup( ALSA_DEFAULT );
-    return i_fd;
 
- adev_fail:
+    /* Return a fake handle so other tests work */
+    return 1;
 
-    if( i_fd >= 0 ) close( i_fd );
+ adev_fail:
 
     if( p_hw_params ) snd_pcm_hw_params_free( p_hw_params );
     if( p_sys->p_alsa_pcm ) snd_pcm_close( p_sys->p_alsa_pcm );
@@ -3115,10 +3100,10 @@ static void ControlListPrint( vlc_object_t *p_obj, int i_fd,
 
     if( b_demux )
         var_AddCallback( p_obj, psz_name,
-                        DemuxControlCallback, (void*)queryctrl.id );
+                        DemuxControlCallback, (void*)(intptr_t)queryctrl.id );
     else
         var_AddCallback( p_obj, psz_name,
-                        AccessControlCallback, (void*)queryctrl.id );
+                        AccessControlCallback, (void*)(intptr_t)queryctrl.id );
 
     free( psz_name );
 }
@@ -3490,6 +3475,7 @@ static int DemuxControlCallback( vlc_object_t *p_this,
     const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
     void *p_data )
 {
+    (void)oldval;
     demux_t *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys = p_demux->p_sys;
     int i_cid = (int)p_data;
@@ -3505,9 +3491,9 @@ static int DemuxControlCallback( vlc_object_t *p_this,
 }
 
 static int DemuxControlResetCallback( vlc_object_t *p_this,
-    const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
-    void *p_data )
+    const char *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
+    (void)psz_var;    (void)oldval;    (void)newval;    (void)p_data;
     demux_t *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys = p_demux->p_sys;
 
@@ -3525,6 +3511,7 @@ static int AccessControlCallback( vlc_object_t *p_this,
     const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
     void *p_data )
 {
+    (void)oldval;
     access_t *p_access = (access_t *)p_this;
     demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
     int i_cid = (int)p_data;
@@ -3540,9 +3527,9 @@ static int AccessControlCallback( vlc_object_t *p_this,
 }
 
 static int AccessControlResetCallback( vlc_object_t *p_this,
-    const char *psz_var, vlc_value_t oldval, vlc_value_t newval,
-    void *p_data )
+    const char *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
+    (void)psz_var;     (void)oldval;     (void)newval;     (void)p_data;
     access_t *p_access = (access_t *)p_this;
     demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;