]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l2.c
BDA: work-around weird linking issue
[vlc] / modules / access / v4l2.c
index a97aa53a2cc6b5ed9756e6736a3e12d3d54cfeb9..0654e4ab3a75c19a2fd8f206a998a4fbe6aa4905 100644 (file)
@@ -567,7 +567,6 @@ struct demux_sys_t
     int i_height;
     unsigned int i_aspect;
     float f_fps;            /* <= 0.0 mean to grab at full rate */
-    mtime_t i_video_pts;    /* only used when f_fps > 0 */
     int i_fourcc;
     uint32_t i_block_flags;
 
@@ -581,7 +580,6 @@ struct demux_sys_t
     /* Controls */
     char *psz_set_ctrls;
 
-
 #ifdef HAVE_LIBV4L2
     /* */
     int (*pf_open)(const char *, int, ...);
@@ -707,8 +705,6 @@ static int DemuxOpen( vlc_object_t *p_this )
  *****************************************************************************/
 static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj )
 {
-    p_sys->i_video_pts = -1;
-
     p_sys->i_selected_standard_id =
         i_standards_list[var_CreateGetInteger( p_obj, "v4l2-standard" )];
 
@@ -1263,13 +1259,8 @@ static block_t *AccessRead( access_t * p_access )
     fd.revents = 0;
 
     /* Wait for data */
-    if( poll( &fd, 1, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
-    {
-        if( fd.revents & (POLLIN|POLLPRI) )
-        {
-            return GrabVideo( VLC_OBJECT(p_access), p_sys );
-        }
-    }
+    if( poll( &fd, 1, 500 ) > 0 ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
+        return GrabVideo( VLC_OBJECT(p_access), p_sys );
 
     return NULL;
 }
@@ -1297,7 +1288,8 @@ static ssize_t AccessReadStream( access_t * p_access, uint8_t * p_buffer, size_t
 
     if( i_ret < 0 )
     {
-        msg_Err( p_access, "Polling error (%m)." );
+        if( errno != EINTR )
+            msg_Err( p_access, "poll error" );
         return -1;
     }
 
@@ -1327,16 +1319,21 @@ static int Demux( demux_t *p_demux )
     fd.revents = 0;
 
     /* Wait for data */
-    if( poll( &fd, 1, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
-    {
-        if( fd.revents & (POLLIN|POLLPRI) )
+    /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
+    while( poll( &fd, 1, 500 ) == -1 )
+        if( errno != EINTR )
         {
-            block_t *p_block = GrabVideo( VLC_OBJECT(p_demux), p_sys );
-            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 );
-            }
+            msg_Err( p_demux, "poll error: %m" );
+            return -1;
+        }
+
+    if( fd.revents )
+    {
+         block_t *p_block = GrabVideo( VLC_OBJECT(p_demux), p_sys );
+         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 );
         }
     }
 
@@ -1352,15 +1349,6 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys )
     struct v4l2_buffer buf;
     ssize_t i_ret;
 
-    if( p_sys->f_fps >= 0.1 && p_sys->i_video_pts > 0 )
-    {
-        mtime_t i_dur = (mtime_t)((double)1000000 / (double)p_sys->f_fps);
-
-        /* Did we wait long enough ? (frame rate reduction) */
-        if( p_sys->i_video_pts + i_dur > mdate() )
-            return NULL;
-    }
-
     /* Grab Video Frame */
     switch( p_sys->io )
     {
@@ -1481,7 +1469,7 @@ static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys )
     }
 
     /* Timestamp */
-    p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate();
+    p_block->i_pts = p_block->i_dts = mdate();
     p_block->i_flags |= p_sys->i_block_flags;
 
     return p_block;
@@ -2305,6 +2293,10 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
         es_fmt.video.i_sar_num = p_sys->i_aspect    * es_fmt.video.i_height;
         es_fmt.video.i_sar_den = VOUT_ASPECT_FACTOR * es_fmt.video.i_width;
 
+        /* Framerate */
+        es_fmt.video.i_frame_rate = p_sys->f_fps * INT64_C(1000000);
+        es_fmt.video.i_frame_rate_base = INT64_C(1000000);
+
         demux_t *p_demux = (demux_t *) p_obj;
         msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
             (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
@@ -2491,6 +2483,8 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
         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;
         }
@@ -2527,6 +2521,8 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
         p_sys->i_standard = 0;
         while( v4l2_ioctl( i_fd, VIDIOC_ENUMSTD, &t_standards ) >=0 )
         {
+            if( t_standards.index != p_sys->i_standard )
+                break;
             p_sys->i_standard++;
             t_standards.index = p_sys->i_standard;
         }
@@ -2592,6 +2588,8 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
         p_sys->i_tuner = 0;
         while( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &tuner ) >= 0 )
         {
+            if( tuner.index != p_sys->i_tuner )
+                break;
             p_sys->i_tuner++;
             memset( &tuner, 0, sizeof(tuner) );
             tuner.index = p_sys->i_tuner;
@@ -2655,6 +2653,8 @@ static bool ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys,
 
         while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FMT, &codec ) >= 0 )
         {
+            if( codec.index != i_index )
+                break;
             i_index++;
             codec.index = i_index;
         }