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

Rémi Denis-Courmont remi at remlab.net
Thu Aug 1 13:28:42 CEST 2013


Le mercredi 31 juillet 2013 16:11:26 Rafaël Carré a écrit :
> ---
>  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;

I suspect that this is too broad and checking errno is required.

> +
>      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);
> +}

This will not work, or rather it will work but incorrectly. The input thread 
does not handle non-blocking pf_demux callbacks correctly. If you are in luck, 
it will merely increase ticks. If you are in no such luck, the thread will go 
into a live loop.

Basically, if it were that easy, it would already have been implemented.

-- 
Rémi Denis-Courmont
http://www.remlab.net/




More information about the vlc-devel mailing list