]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l.c
Cosmetic about i_zoom limitation (patch 3/3)
[vlc] / modules / access / v4l.c
index dc3c1409fc6b98d0aece7e9216d2590cb686d21d..042ca8f6883df380936b2fa4aec0b071a2d721ef 100644 (file)
 #include <vlc_demux.h>
 #include <vlc_access.h>
 #include <vlc_vout.h>
-#include <vlc_codecs.h>
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <unistd.h>
 #include <sys/mman.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <arpa/inet.h>
 
+#include <poll.h>
+
 /* From GStreamer's v4l plugin:
  * Because of some really cool feature in video4linux1, also known as
  * 'not including sys/types.h and sys/time.h', we had to include it
@@ -132,8 +129,8 @@ static void Close( vlc_object_t * );
 
 #define AUDIO_DEPRECATED_ERROR N_( \
     "Alsa or OSS audio capture in the v4l access is deprecated. " \
-    "please use 'v4l:/""/ --input-slave alsa:/""/' or " \
-    "'v4l:/""/ --input-slave oss:/""/' instead." )
+    "please use 'v4l:/""/ :input-slave=alsa:/""/' or " \
+    "'v4l:/""/ :input-slave=oss:/""/' instead." )
 
 static const int i_norm_list[] =
     { VIDEO_MODE_AUTO, VIDEO_MODE_SECAM, VIDEO_MODE_PAL, VIDEO_MODE_NTSC };
@@ -149,39 +146,39 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_INPUT_ACCESS )
 
     add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL,
-                 CACHING_TEXT, CACHING_LONGTEXT, true );
+                 CACHING_TEXT, CACHING_LONGTEXT, true )
     add_obsolete_string( "v4l-vdev" );
     add_obsolete_string( "v4l-adev" );
     add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                true );
+                true )
     add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, true )
     add_obsolete_integer( "v4l-samplerate" );
     add_integer( "v4l-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,
-                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,
-                false );
+                false )
         change_integer_list( i_norm_list, psz_norm_list_text, NULL );
     add_integer( "v4l-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
-                false );
+                false )
     add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, true )
     add_obsolete_bool( "v4l-stereo" );
     add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true )
     add_integer( "v4l-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
-                true );
+                true )
     add_integer( "v4l-brightness", -1, NULL, BRIGHTNESS_TEXT,
-                BRIGHTNESS_LONGTEXT, true );
+                BRIGHTNESS_LONGTEXT, true )
     add_integer( "v4l-colour", -1, NULL, COLOUR_TEXT, COLOUR_LONGTEXT,
-                true );
+                true )
     add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, true )
     add_integer( "v4l-contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT,
-                true );
+                true )
     add_bool( "v4l-mjpeg", false, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,
-            true );
+            true )
     add_integer( "v4l-decimation", 1, NULL, DECIMATION_TEXT,
-            DECIMATION_LONGTEXT, true );
+            DECIMATION_LONGTEXT, true )
     add_integer( "v4l-quality", 100, NULL, QUALITY_TEXT, QUALITY_LONGTEXT,
-            true );
+            true )
 
     add_shortcut( "v4l" )
     set_capability( "access_demux", 10 )
@@ -245,7 +242,7 @@ struct demux_sys_t
 {
     /* Devices */
     char *psz_device;         /* Main device from MRL */
-    int  fd_video;
+    int  i_fd;
 
     /* Video properties */
     picture_t pic;
@@ -378,15 +375,15 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_quality = val.i_int;
 
     p_sys->psz_device = NULL;
-    p_sys->fd_video = -1;
+    p_sys->i_fd = -1;
 
     p_sys->p_es = NULL;
 
     ParseMRL( p_demux );
 
     msg_Dbg( p_this, "opening device '%s'", p_sys->psz_device );
-    p_sys->fd_video = OpenVideoDev( p_demux, p_sys->psz_device );
-    if( p_sys->fd_video < 0 )
+    p_sys->i_fd = OpenVideoDev( p_demux, p_sys->psz_device );
+    if( p_sys->i_fd < 0 )
     {
         Close( p_this );
         return VLC_EGENERIC;
@@ -442,12 +439,12 @@ static void Close( vlc_object_t *p_this )
     demux_sys_t *p_sys   = p_demux->p_sys;
 
     free( p_sys->psz_device );
-    if( p_sys->fd_video >= 0 ) close( p_sys->fd_video );
+    if( p_sys->i_fd >= 0 ) close( p_sys->i_fd );
 
     if( p_sys->b_mjpeg )
     {
         int i_noframe = -1;
-        ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT, &i_noframe );
+        ioctl( p_sys->i_fd, MJPIOC_QBUF_CAPT, &i_noframe );
     }
 
     if( p_sys->p_video_mmap && p_sys->p_video_mmap != MAP_FAILED )
@@ -505,19 +502,26 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
-    block_t *p_block = GrabVideo( p_demux );
 
-    if( !p_block )
+    struct pollfd fd;
+    fd.fd = p_sys->i_fd;
+    fd.events = POLLIN|POLLPRI;
+    fd.revents = 0;
+
+    /* Wait for data */
+    if( poll( &fd, 1, 500 ) )
     {
-        /* Sleep so we do not consume all the cpu, 10ms seems
-         * like a good value (100fps) */
-        msleep( 10000 );
-        return 1;
+        if( fd.revents & (POLLIN|POLLPRI) )
+        {
+            block_t *p_block = GrabVideo( p_demux );
+            if( p_block )
+            {
+                es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
+                es_out_Send( p_demux->out, p_sys->p_es, p_block );
+            }
+        }
     }
 
-    es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
-    es_out_Send( p_demux->out, p_sys->p_es, p_block );
-
     return 1;
 }
 
@@ -1191,7 +1195,7 @@ static uint8_t *GrabCapture( demux_t *p_demux )
 
     p_sys->vid_mmap.frame = (p_sys->i_frame_pos + 1) % p_sys->vid_mbuf.frames;
 
-    while( ioctl( p_sys->fd_video, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
+    while( ioctl( p_sys->i_fd, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
     {
         if( errno != EAGAIN )
         {
@@ -1207,7 +1211,7 @@ static uint8_t *GrabCapture( demux_t *p_demux )
         msg_Dbg( p_demux, "grab failed, trying again" );
     }
 
-    while( ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
+    while( ioctl(p_sys->i_fd, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
     {
         if( errno != EAGAIN && errno != EINTR )
         {
@@ -1233,7 +1237,7 @@ static uint8_t *GrabMJPEG( demux_t *p_demux )
     /* re-queue the last frame we sync'd */
     if( p_sys->i_frame_pos != -1 )
     {
-        while( ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT,
+        while( ioctl( p_sys->i_fd, MJPIOC_QBUF_CAPT,
                                        &p_sys->i_frame_pos ) < 0 )
         {
             if( errno != EAGAIN && errno != EINTR )
@@ -1245,7 +1249,7 @@ static uint8_t *GrabMJPEG( demux_t *p_demux )
     }
 
     /* sync on the next frame */
-    while( ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
+    while( ioctl( p_sys->i_fd, MJPIOC_SYNC, &sync ) < 0 )
     {
         if( errno != EAGAIN && errno != EINTR )
         {