]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l.c
Another time "Remove useless test before a free".
[vlc] / modules / access / v4l.c
index fd0c88e3f348cc851d7b4f87c84c12ef760900c6..e6b9d23f0f4c571fb7f342f0e7aa59a6fbccf4c7 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdio.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_input.h>
@@ -428,14 +431,14 @@ static int Open( vlc_object_t *p_this )
             p_sys->fd_audio = OpenAudioDev( p_demux, p_sys->psz_device );
             if( p_sys->fd_audio >= 0 )
             {
-                if( p_sys->psz_adev ) free( p_sys->psz_adev );
+                free( p_sys->psz_adev );
                 p_sys->psz_adev = p_sys->psz_device;
                 p_sys->psz_device = NULL;
             }
         }
         else
         {
-            if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
+            free( p_sys->psz_vdev );
             p_sys->psz_vdev = p_sys->psz_device;
             p_sys->psz_device = NULL;
         }
@@ -456,7 +459,7 @@ static int Open( vlc_object_t *p_this )
     {
         if( !p_sys->psz_vdev || !*p_sys->psz_vdev )
         {
-            if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
+            free( p_sys->psz_vdev );
             p_sys->psz_vdev = var_CreateGetString( p_demux, "v4l-vdev" );;
         }
 
@@ -471,7 +474,7 @@ static int Open( vlc_object_t *p_this )
     {
         if( !p_sys->psz_adev || !*p_sys->psz_adev )
         {
-            if( p_sys->psz_adev ) free( p_sys->psz_adev );
+            free( p_sys->psz_adev );
             p_sys->psz_adev = var_CreateGetString( p_demux, "v4l-adev" );;
         }
 
@@ -545,9 +548,9 @@ static void Close( vlc_object_t *p_this )
     demux_t     *p_demux = (demux_t *)p_this;
     demux_sys_t *p_sys   = p_demux->p_sys;
 
-    if( p_sys->psz_device ) free( p_sys->psz_device );
-    if( p_sys->psz_vdev )   free( p_sys->psz_vdev );
-    if( p_sys->psz_adev )   free( p_sys->psz_adev );
+    free( p_sys->psz_device );
+    free( p_sys->psz_vdev );
+    free( p_sys->psz_adev );
     if( p_sys->fd_video >= 0 ) close( p_sys->fd_video );
     if( p_sys->fd_audio >= 0 ) close( p_sys->fd_audio );
     if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio );
@@ -582,6 +585,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     {
         /* Special for access_demux */
         case DEMUX_CAN_PAUSE:
+        case DEMUX_CAN_SEEK:
         case DEMUX_SET_PAUSE_STATE:
         case DEMUX_CAN_CONTROL_PACE:
             pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
@@ -766,7 +770,7 @@ static void ParseMRL( demux_t *p_demux )
             }
             else if( !strncmp( psz_parser, "hue=", strlen( "hue=" ) ) )
             {
-                p_sys->i_hue = strtol( psz_parser + strlen( "hue=" ), 
+                p_sys->i_hue = strtol( psz_parser + strlen( "hue=" ),
                                        &psz_parser, 0 );
             }
             else if( !strncmp( psz_parser, "contrast=", strlen( "contrast=" ) ) )
@@ -862,7 +866,7 @@ static void ParseMRL( demux_t *p_demux )
     {
         p_sys->psz_device = strdup( psz_dup );
     }
-    if( psz_dup ) free( psz_dup );
+    free( psz_dup );
 }
 
 /*****************************************************************************
@@ -879,13 +883,13 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
 
     if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
     {
-        msg_Err( p_demux, "cannot open device (%s)", strerror( errno ) );
+        msg_Err( p_demux, "cannot open device (%m)" );
         goto vdev_failed;
     }
 
     if( ioctl( i_fd, VIDIOCGCAP, &p_sys->vid_cap ) < 0 )
     {
-        msg_Err( p_demux, "cannot get capabilities (%s)", strerror( errno ) );
+        msg_Err( p_demux, "cannot get capabilities (%m)" );
         goto vdev_failed;
     }
 
@@ -930,8 +934,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
     vid_channel.channel = p_sys->i_channel;
     if( ioctl( i_fd, VIDIOCGCHAN, &vid_channel ) < 0 )
     {
-        msg_Err( p_demux, "cannot get channel infos (%s)",
-                          strerror( errno ) );
+        msg_Err( p_demux, "cannot get channel infos (%m)" );
         goto vdev_failed;
     }
     msg_Dbg( p_demux,
@@ -948,7 +951,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
     vid_channel.norm = p_sys->i_norm;
     if( ioctl( i_fd, VIDIOCSCHAN, &vid_channel ) < 0 )
     {
-        msg_Err( p_demux, "cannot set channel (%s)", strerror( errno ) );
+        msg_Err( p_demux, "cannot set channel (%m)" );
         goto vdev_failed;
     }
 
@@ -963,7 +966,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
             vid_tuner.tuner = p_sys->i_tuner;
             if( ioctl( i_fd, VIDIOCGTUNER, &vid_tuner ) < 0 )
             {
-                msg_Err( p_demux, "cannot get tuner (%s)", strerror( errno ) );
+                msg_Err( p_demux, "cannot get tuner (%m)" );
                 goto vdev_failed;
             }
             msg_Dbg( p_demux, "tuner %s low=%d high=%d, flags=0x%x "
@@ -978,7 +981,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
             //vid_tuner.mode = p_sys->i_norm;
             if( ioctl( i_fd, VIDIOCSTUNER, &vid_tuner ) < 0 )
             {
-                msg_Err( p_demux, "cannot set tuner (%s)", strerror( errno ) );
+                msg_Err( p_demux, "cannot set tuner (%m)" );
                 goto vdev_failed;
             }
         }
@@ -994,8 +997,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
             int driver_frequency = p_sys->i_frequency * 16 /1000;
             if( ioctl( i_fd, VIDIOCSFREQ, &driver_frequency ) < 0 )
             {
-                msg_Err( p_demux, "cannot set frequency (%s)",
-                                  strerror( errno ) );
+                msg_Err( p_demux, "cannot set frequency (%m)" );
                 goto vdev_failed;
             }
             msg_Dbg( p_demux, "frequency %d (%d)", p_sys->i_frequency,
@@ -1014,7 +1016,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
             vid_audio.audio = p_sys->i_audio;
             if( ioctl( i_fd, VIDIOCGAUDIO, &vid_audio ) < 0 )
             {
-                msg_Err( p_demux, "cannot get audio (%s)", strerror( errno ) );
+                msg_Err( p_demux, "cannot get audio (%m)" );
                 goto vdev_failed;
             }
 
@@ -1023,7 +1025,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
 
             if( ioctl( i_fd, VIDIOCSAUDIO, &vid_audio ) < 0 )
             {
-                msg_Err( p_demux, "cannot set audio (%s)", strerror( errno ) );
+                msg_Err( p_demux, "cannot set audio (%m)" );
                 goto vdev_failed;
             }
         }
@@ -1039,8 +1041,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
 
         if( ioctl( i_fd, MJPIOC_G_PARAMS, &mjpeg ) < 0 )
         {
-            msg_Err( p_demux, "cannot get mjpeg params (%s)",
-                              strerror( errno ) );
+            msg_Err( p_demux, "cannot get mjpeg params (%m)" );
             goto vdev_failed;
         }
         mjpeg.input = p_sys->i_channel;
@@ -1090,8 +1091,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
 
         if( ioctl( i_fd, MJPIOC_S_PARAMS, &mjpeg ) < 0 )
         {
-            msg_Err( p_demux, "cannot set mjpeg params (%s)",
-                              strerror( errno ) );
+            msg_Err( p_demux, "cannot set mjpeg params (%m)" );
             goto vdev_failed;
         }
 
@@ -1107,7 +1107,7 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device )
 
         if( ioctl( i_fd, VIDIOCGWIN, &vid_win ) < 0 )
         {
-            msg_Err( p_demux, "cannot get win (%s)", strerror( errno ) );
+            msg_Err( p_demux, "cannot get win (%m)" );
             goto vdev_failed;
         }
         p_sys->i_width  = vid_win.width;
@@ -1337,7 +1337,7 @@ static int OpenAudioDev( demux_t *p_demux, char *psz_device )
 
     if( (i_fd = open( psz_device, O_RDONLY | O_NONBLOCK )) < 0 )
     {
-        msg_Err( p_demux, "cannot open audio device (%s)", strerror( errno ) );
+        msg_Err( p_demux, "cannot open audio device (%m)" );
         goto adev_fail;
     }
 
@@ -1346,27 +1346,25 @@ static int OpenAudioDev( demux_t *p_demux, char *psz_device )
         || i_format != AFMT_S16_LE )
     {
         msg_Err( p_demux, "cannot set audio format (16b little endian) "
-                 "(%s)", strerror( errno ) );
+                 "(%m)" );
         goto adev_fail;
     }
 
     if( ioctl( i_fd, SNDCTL_DSP_STEREO,
                &p_sys->b_stereo ) < 0 )
     {
-        msg_Err( p_demux, "cannot set audio channels count (%s)",
-                 strerror( errno ) );
+        msg_Err( p_demux, "cannot set audio channels count (%m)" );
         goto adev_fail;
     }
 
     if( ioctl( i_fd, SNDCTL_DSP_SPEED,
                &p_sys->i_sample_rate ) < 0 )
     {
-        msg_Err( p_demux, "cannot set audio sample rate (%s)",
-                 strerror( errno ) );
+        msg_Err( p_demux, "cannot set audio sample rate (%m)" );
         goto adev_fail;
     }
 
-    msg_Dbg( p_demux, "openened adev=`%s' %s %dHz",
+    msg_Dbg( p_demux, "opened adev=`%s' %s %dHz",
              psz_device, p_sys->b_stereo ? "stereo" : "mono",
              p_sys->i_sample_rate );
 
@@ -1451,7 +1449,7 @@ static uint8_t *GrabCapture( demux_t *p_demux )
 
     while( ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
     {
-        if( errno != EAGAIN && errno != EINTR )    
+        if( errno != EAGAIN && errno != EINTR )
         {
             msg_Err( p_demux, "failed syncing new frame" );
             return NULL;
@@ -1489,7 +1487,7 @@ static uint8_t *GrabMJPEG( demux_t *p_demux )
     /* sync on the next frame */
     while( ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
     {
-        if( errno != EAGAIN && errno != EINTR )    
+        if( errno != EAGAIN && errno != EINTR )
         {
             msg_Err( p_demux, "failed syncing new frame" );
             return NULL;