[vlc-devel] commit: Use polling instead of msleep in v4l2 access_demux. ( Antoine Cellerier )

git version control git at videolan.org
Sat Jan 3 22:50:01 CET 2009


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Mon Oct 27 17:35:55 2008 -0700| [711c318b5e7cb7b2662109099fdc847695ed261f] | committer: Antoine Cellerier 

Use polling instead of msleep in v4l2 access_demux.

I'm not sure about the polltimeout. I'd settle for an infinite timeout but then VLC might behavior on exit might be messed up.

This also fixes the last compilation warning in v4l2.c.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=711c318b5e7cb7b2662109099fdc847695ed261f
---

 modules/access/v4l2/v4l2.c |   49 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/modules/access/v4l2/v4l2.c b/modules/access/v4l2/v4l2.c
index bbe8ccc..beed7b5 100644
--- a/modules/access/v4l2/v4l2.c
+++ b/modules/access/v4l2/v4l2.c
@@ -1383,24 +1383,53 @@ static int Demux( demux_t *p_demux )
     es_out_id_t *p_es = p_sys->p_es_audio;
     block_t *p_block = NULL;
 
-    /* Try grabbing audio frames first */
-    if( p_sys->i_fd_audio < 0 || !( p_block = GrabAudio( p_demux ) ) )
+    struct pollfd p_fd[2];
+    int i_fd = 0;
+    memset( p_fd, 0, 2 * sizeof( struct pollfd ) );
+    if( p_sys->i_fd_video )
+    {
+        p_fd[i_fd].fd = p_sys->i_fd_video;
+        p_fd[i_fd].events = POLLIN|POLLPRI;
+        i_fd ++;
+    }
+    if( p_sys->i_fd_audio )
+    {
+        p_fd[i_fd].fd = p_sys->i_fd_audio;
+        p_fd[i_fd].events = POLLIN|POLLPRI;
+        i_fd ++;
+    }
+
+    /* Wait for data */
+    if( poll( p_fd, i_fd, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
     {
-        /* Try grabbing video frame */
-        p_es = p_sys->p_es_video;
-        if( p_sys->i_fd_video > 0 ) p_block = GrabVideo( p_demux );
+        for( i_fd --; i_fd >= 0; i_fd -- )
+        {
+            if( p_fd[i_fd].revents & (POLLIN|POLLPRI) )
+            {
+                if( p_fd[i_fd].fd == p_sys->i_fd_video )
+                {
+                    p_block = GrabVideo( p_demux );
+                    p_es = p_sys->p_es_video;
+                }
+                else /* audio */
+                {
+                    p_block = GrabAudio( p_demux );
+                    p_es = p_sys->p_es_audio;
+                }
+                break;
+            }
+        }
     }
 
     if( !p_block )
     {
-        /* Sleep so we do not consume all the cpu, 10ms seems
-         * like a good value (100fps) */
-        /* Yeah, nevermind this was sleeping 10 microseconds! This is
-         * completely brain damaged anyway. Use poll() or mwait() FIXME. */
-        msleep(10000);
+        /* Looks like poll timed out ...
+         * ... or returned an error on one of the fds.
+         * TODO: process */
         return 1;
     }
 
+    assert( p_es );
     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
     es_out_Send( p_demux->out, p_es, p_block );
 




More information about the vlc-devel mailing list