[vlc-devel] [PATCH] v4l2 mmap: returns EOF on webcam unplug

Rafaël Carré funman at videolan.org
Wed Jul 31 16:11:26 CEST 2013


---
 modules/access/v4l2/access.c |  4 +++-
 modules/access/v4l2/demux.c  | 16 +++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/modules/access/v4l2/access.c b/modules/access/v4l2/access.c
index 5615743..410cf25 100644
--- a/modules/access/v4l2/access.c
+++ b/modules/access/v4l2/access.c
@@ -230,7 +230,9 @@ static block_t *MMapBlock (access_t *access)
     {
         block->i_pts = block->i_dts = mdate();
         block->i_flags |= sys->block_flags;
-    }
+    } else
+        access->info.b_eof = true;
+
     return block;
 }
 
diff --git a/modules/access/v4l2/demux.c b/modules/access/v4l2/demux.c
index 73af8ce..3e87989 100644
--- a/modules/access/v4l2/demux.c
+++ b/modules/access/v4l2/demux.c
@@ -39,6 +39,7 @@
 
 #include <vlc_common.h>
 #include <vlc_demux.h>
+#include <vlc_atomic.h>
 
 #include "v4l2.h"
 
@@ -62,6 +63,8 @@ struct demux_sys_t
 #ifdef ZVBI_COMPILED
     vlc_v4l2_vbi_t *vbi;
 #endif
+
+    vlc_atomic_t eof;
 };
 
 static void *UserPtrThread (void *);
@@ -70,6 +73,12 @@ static void *ReadThread (void *);
 static int DemuxControl( demux_t *, int, va_list );
 static int InitVideo (demux_t *, int fd, uint32_t caps);
 
+static int Demux(demux_t *demux)
+{
+    demux_sys_t *sys = demux->p_sys;
+    return vlc_atomic_get(&sys->eof);
+}
+
 int DemuxOpen( vlc_object_t *obj )
 {
     demux_t *demux = (demux_t *)obj;
@@ -78,6 +87,7 @@ int DemuxOpen( vlc_object_t *obj )
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
     demux->p_sys = sys;
+    vlc_atomic_set(&sys->eof, 1);
 #ifdef ZVBI_COMPILED
     sys->vbi = NULL;
 #endif
@@ -103,7 +113,7 @@ int DemuxOpen( vlc_object_t *obj )
 
     sys->controls = ControlsInit (VLC_OBJECT(demux), fd);
     sys->start = mdate ();
-    demux->pf_demux = NULL;
+    demux->pf_demux = Demux;
     demux->pf_control = DemuxControl;
     demux->info.i_update = 0;
     demux->info.i_title = 0;
@@ -621,6 +631,10 @@ static void *MmapThread (void *data)
                 es_out_Send (demux->out, sys->es, block);
             }
             vlc_restorecancel (canc);
+            if (!block) {
+                vlc_atomic_set(&sys->eof, 0);
+                return NULL;
+            }
         }
 #ifdef ZVBI_COMPILED
         if (sys->vbi != NULL && ufd[1].revents)
-- 
1.8.1.2



More information about the vlc-devel mailing list