]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l.c
dshow: try to improve multithreading code for RAW sample grabbing
[vlc] / modules / access / v4l.c
index 7efc65f5a65e4d5dc704449236f7c4d88957fffb..d54bcd40e8e175c36dd8da9a3b17f27ae87c821f 100644 (file)
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_demux.h>
 #include <vlc_access.h>
@@ -42,6 +47,7 @@
 #include <sys/mman.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <arpa/inet.h>
 
 /* From GStreamer's v4l plugin:
  * Because of some really cool feature in video4linux1, also known as
@@ -136,55 +142,55 @@ static void Close( vlc_object_t * );
 #define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \
     "(-1 for autodetect)." )
 
-static int i_norm_list[] =
+static const int i_norm_list[] =
     { VIDEO_MODE_AUTO, VIDEO_MODE_SECAM, VIDEO_MODE_PAL, VIDEO_MODE_NTSC };
-static const char *psz_norm_list_text[] =
+static const char *const psz_norm_list_text[] =
     { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
 
 vlc_module_begin();
-    set_shortname( _("Video4Linux") );
-    set_description( _("Video4Linux input") );
+    set_shortname( N_("Video4Linux") );
+    set_description( N_("Video4Linux input") );
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_ACCESS );
 
     add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL,
-                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
+                 CACHING_TEXT, CACHING_LONGTEXT, true );
     add_string( "v4l-vdev", "/dev/video", 0, VDEV_TEXT, VDEV_LONGTEXT,
-                VLC_FALSE );
+                false );
     add_string( "v4l-adev", "/dev/dsp", 0, ADEV_TEXT, ADEV_LONGTEXT,
-                VLC_FALSE );
+                false );
     add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                VLC_TRUE );
-    add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
+                true );
+    add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, true );
     add_integer( "v4l-samplerate", 44100, NULL, SAMPLERATE_TEXT,
-                SAMPLERATE_LONGTEXT, VLC_TRUE );
+                SAMPLERATE_LONGTEXT, true );
     add_integer( "v4l-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,
-                VLC_TRUE );
-    add_integer( "v4l-tuner", -1, NULL, TUNER_TEXT, TUNER_LONGTEXT, VLC_TRUE );
+                true );
+    add_integer( "v4l-tuner", -1, NULL, TUNER_TEXT, TUNER_LONGTEXT, true );
     add_integer( "v4l-norm", VIDEO_MODE_AUTO, NULL, NORM_TEXT, NORM_LONGTEXT,
-                VLC_FALSE );
-        change_integer_list( i_norm_list, psz_norm_list_text, 0 );
+                false );
+        change_integer_list( i_norm_list, psz_norm_list_text, NULL );
     add_integer( "v4l-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
-                VLC_FALSE );
-    add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, VLC_TRUE );
-    add_bool( "v4l-stereo", VLC_TRUE, NULL, STEREO_TEXT, STEREO_LONGTEXT,
-            VLC_TRUE );
-    add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
+                false );
+    add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, true );
+    add_bool( "v4l-stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT,
+            true );
+    add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true );
     add_integer( "v4l-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
-                VLC_TRUE );
+                true );
     add_integer( "v4l-brightness", -1, NULL, BRIGHTNESS_TEXT,
-                BRIGHTNESS_LONGTEXT, VLC_TRUE );
+                BRIGHTNESS_LONGTEXT, true );
     add_integer( "v4l-colour", -1, NULL, COLOUR_TEXT, COLOUR_LONGTEXT,
-                VLC_TRUE );
-    add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, VLC_TRUE );
+                true );
+    add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, true );
     add_integer( "v4l-contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT,
-                VLC_TRUE );
-    add_bool( "v4l-mjpeg", VLC_FALSE, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,
-            VLC_TRUE );
+                true );
+    add_bool( "v4l-mjpeg", false, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,
+            true );
     add_integer( "v4l-decimation", 1, NULL, DECIMATION_TEXT,
-            DECIMATION_LONGTEXT, VLC_TRUE );
+            DECIMATION_LONGTEXT, true );
     add_integer( "v4l-quality", 100, NULL, QUALITY_TEXT, QUALITY_LONGTEXT,
-            VLC_TRUE );
+            true );
 
     add_shortcut( "v4l" );
     set_capability( "access_demux", 10 );
@@ -220,7 +226,7 @@ struct quicktime_mjpeg_app1
     uint32_t    i_data_offset;          /* following SOS marker data */
 };
 
-static struct
+static const struct
 {
     int i_v4l;
     int i_fourcc;
@@ -278,7 +284,7 @@ struct demux_sys_t
     float f_fps;            /* <= 0.0 mean to grab at full rate */
     mtime_t i_video_pts;    /* only used when f_fps > 0 */
 
-    vlc_bool_t b_mjpeg;
+    bool b_mjpeg;
     int i_decimation;
     int i_quality;
 
@@ -298,7 +304,7 @@ struct demux_sys_t
     /* Audio properties */
     vlc_fourcc_t i_acodec_raw;
     int          i_sample_rate;
-    vlc_bool_t   b_stereo;
+    bool   b_stereo;
     int          i_audio_max_frame_size;
     block_t      *p_block_audio;
     es_out_id_t  *p_es_audio;
@@ -427,14 +433,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;
         }
@@ -455,7 +461,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" );;
         }
 
@@ -470,7 +476,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" );;
         }
 
@@ -498,12 +504,24 @@ static int Open( vlc_object_t *p_this )
         fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
 
         /* Setup rgb mask for RGB formats */
-        if( p_sys->i_fourcc == VLC_FOURCC('R','V','2','4') )
+        switch( p_sys->i_fourcc )
         {
-            /* This is in BGR format */
-            fmt.video.i_bmask = 0x00ff0000;
-            fmt.video.i_gmask = 0x0000ff00;
-            fmt.video.i_rmask = 0x000000ff;
+            case VLC_FOURCC('R','V','1','5'):
+                fmt.video.i_rmask = 0x001f;
+                fmt.video.i_gmask = 0x03e0;
+                fmt.video.i_bmask = 0x7c00;
+                break;
+            case VLC_FOURCC('R','V','1','6'):
+                fmt.video.i_rmask = 0x001f;
+                fmt.video.i_gmask = 0x07e0;
+                fmt.video.i_bmask = 0xf800;
+                break;
+            case VLC_FOURCC('R','V','2','4'):
+            case VLC_FOURCC('R','V','3','2'):
+                fmt.video.i_rmask = 0x00ff0000;
+                fmt.video.i_gmask = 0x0000ff00;
+                fmt.video.i_bmask = 0x000000ff;
+                break;
         }
 
         msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
@@ -544,9 +562,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 );
@@ -574,7 +592,7 @@ static void Close( vlc_object_t *p_this )
  *****************************************************************************/
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
-    vlc_bool_t *pb;
+    bool *pb;
     int64_t    *pi64;
 
     switch( i_query )
@@ -584,8 +602,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
         case DEMUX_CAN_SEEK:
         case DEMUX_SET_PAUSE_STATE:
         case DEMUX_CAN_CONTROL_PACE:
-            pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
-            *pb = VLC_FALSE;
+            pb = (bool*)va_arg( args, bool * );
+            *pb = false;
             return VLC_SUCCESS;
 
         case DEMUX_GET_PTS_DELAY:
@@ -808,19 +826,19 @@ static void ParseMRL( demux_t *p_demux )
             {
                 psz_parser += strlen( "stereo" );
 
-                p_sys->b_stereo = VLC_TRUE;
+                p_sys->b_stereo = true;
             }
             else if( !strncmp( psz_parser, "mono", strlen( "mono" ) ) )
             {
                 psz_parser += strlen( "mono" );
 
-                p_sys->b_stereo = VLC_FALSE;
+                p_sys->b_stereo = false;
             }
             else if( !strncmp( psz_parser, "mjpeg", strlen( "mjpeg" ) ) )
             {
                 psz_parser += strlen( "mjpeg" );
 
-                p_sys->b_mjpeg = VLC_TRUE;
+                p_sys->b_mjpeg = true;
             }
             else if( !strncmp( psz_parser, "decimation=",
                         strlen( "decimation=" ) ) )
@@ -862,7 +880,7 @@ static void ParseMRL( demux_t *p_demux )
     {
         p_sys->psz_device = strdup( psz_dup );
     }
-    if( psz_dup ) free( psz_dup );
+    free( psz_dup );
 }
 
 /*****************************************************************************
@@ -1411,7 +1429,7 @@ static block_t *GrabAudio( demux_t *p_demux )
     }
 
     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;
@@ -1435,7 +1453,7 @@ static uint8_t *GrabCapture( demux_t *p_demux )
             return NULL;
         }
 
-        if( p_demux->b_die )
+        if( !vlc_object_alive (p_demux) )
         {
             return NULL;
         }