[FFmpeg-devel] [PATCH] v4l2: add libv4l2 support.

Clément Bœsch ubitux at gmail.com
Sun Oct 30 13:11:54 CET 2011


On Sun, Oct 30, 2011 at 12:59:06PM +0100, Stefano Sabatini wrote:
> On date Sunday 2011-10-30 03:57:41 +0100, Clément Bœsch encoded:
> > ---
> > Here is a patch to support old webcams with exotic colorspaces or insane
> > drivers using userland libv4l2 (see for instance
> > http://hansdegoede.livejournal.com/3636.html).
> > 
> > It seems to work with my personnal crazy webcam, but more tests are welcome.
> > 
> > I wanted to make the support optional at runtime, but it raises at least one
> > issue: the context has to be transmitted to all subfunctions, which is not
> > easily possible in some cases such as mmap_release_buffer() callback. So ATM,
> > if you build FFmpeg with --enable-libv4l2, then deal with it, you have to use
> > it...
> > 
> 
> > Also, I noticed the gpl dependency is not strict by default: I needed to add
> > the "die_license..." stuff to force --enable-gpl. Is it a wanted behaviour?
> > What is the "gpl" dependency for in that case?
> 
> If you have dependencies on a given symbol, if one of the dependency
> symbol is not enabled the symbol is silently not enabled as well. If
> you want to force a fail in this case, you need to rely on the ad-hoc
> die_licence() mechanism.
> 
> See also:
> http://thread.gmane.org/gmane.comp.video.libav.devel/586
> 

Ah, ok thanks!

> > ---
> >  configure          |    6 ++++
> >  libavdevice/v4l2.c |   78 ++++++++++++++++++++++++++++++++++------------------
> >  2 files changed, 57 insertions(+), 27 deletions(-)
> > 
> > diff --git a/configure b/configure
> > index a1106a1..700cc97 100755
> > --- a/configure
> > +++ b/configure
> > @@ -186,6 +186,7 @@ External library support:
> >    --enable-libstagefright-h264  enable H.264 decoding via libstagefright [no]
> >    --enable-libtheora       enable Theora encoding via libtheora [no]
> >    --enable-libutvideo      enable Ut Video decoding via libutvideo [no]
> > +  --enable-libv4l2         enable libv4l2/v4l-utils [no]
> >    --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
> >    --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
> >    --enable-libvorbis       enable Vorbis encoding via libvorbis,
> > @@ -1021,6 +1022,7 @@ CONFIG_LIST="
> >      libstagefright_h264
> >      libtheora
> >      libutvideo
> > +    libv4l2
> >      libvo_aacenc
> >      libvo_amrwbenc
> >      libvorbis
> > @@ -1564,6 +1566,7 @@ jack_indev_deps="jack_jack_h sem_timedwait"
> >  lavfi_indev_deps="avfilter"
> >  libcdio_indev_deps="libcdio"
> >  libdc1394_indev_deps="libdc1394"
> > +libv4l2_indev_deps="libv4l2 gpl"
> >  openal_indev_deps="openal"
> >  oss_indev_deps_any="soundcard_h sys_soundcard_h"
> >  oss_outdev_deps_any="soundcard_h sys_soundcard_h"
> > @@ -2697,6 +2700,7 @@ die_license_disabled gpl libx264
> >  die_license_disabled gpl libxavs
> >  die_license_disabled gpl libxvid
> >  die_license_disabled gpl x11grab
> > +die_license_disabled gpl libv4l2
> 
> Why GPL? The libvl2 library itself is LGPL, or are you GPL-ing the code of
> *this* patch? In this case I think it should be done differently
> (like adding a symbol --enable-libvl2-v4l2 and setting:
> libv4l2_v4l2_deps="libv4l2 gpl"
> ) but I'd consider this overkill and I'd rather try to keep it LGPL.
>   

Ah! I missed the library was LGPL, I just relied on the COPYING file, but
didn't see the COPYING.LIB, my bad. I'll fix that ASAP.

> >  die_license_disabled nonfree libaacplus
> >  die_license_disabled nonfree libfaac
> > @@ -3042,6 +3046,7 @@ enabled libstagefright_h264  && require_cpp libstagefright_h264 "binder/ProcessS
> >      media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder
> >  enabled libtheora  && require  libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
> >  enabled libutvideo    && require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++
> > +enabled libv4l2    && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
> >  enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
> >  enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
> >  enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
> > @@ -3370,6 +3375,7 @@ echo "libspeex enabled          ${libspeex-no}"
> >  echo "libstagefright-h264 enabled    ${libstagefright_h264-no}"
> >  echo "libtheora enabled         ${libtheora-no}"
> >  echo "libutvideo enabled        ${libutvideo-no}"
> > +echo "libv4l2 enabled           ${libv4l2-no}"
> >  echo "libvo-aacenc support      ${libvo_aacenc-no}"
> >  echo "libvo-amrwbenc support    ${libvo_amrwbenc-no}"
> >  echo "libvorbis enabled         ${libvorbis-no}"
> > diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
> > index 9e26b2d..e1631ba 100644
> > --- a/libavdevice/v4l2.c
> > +++ b/libavdevice/v4l2.c
> > @@ -52,6 +52,18 @@
> >  #include "libavutil/parseutils.h"
> >  #include "libavutil/pixdesc.h"
> >  
> > +#if CONFIG_LIBV4L2
> > +#include <libv4l2.h>
> > +#else
> > +#define v4l2_open   open
> > +#define v4l2_close  close
> > +#define v4l2_dup    dup
> > +#define v4l2_ioctl  ioctl
> > +#define v4l2_read   read
> > +#define v4l2_mmap   mmap
> > +#define v4l2_munmap munmap
> > +#endif
> > +
> >  static const int desired_video_buffers = 256;
> >  
> >  enum io_method {
> > @@ -113,36 +125,48 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
> >  {
> >      struct v4l2_capability cap;
> >      int fd;
> > +#if CONFIG_LIBV4L2
> > +    int fd_libv4l;
> > +#endif
> >      int res, err;
> >      int flags = O_RDWR;
> >  
> >      if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
> >          flags |= O_NONBLOCK;
> >      }
> > -    fd = open(ctx->filename, flags, 0);
> > +    fd = v4l2_open(ctx->filename, flags, 0);
> >      if (fd < 0) {
> >          av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
> >                   ctx->filename, strerror(errno));
> >          return AVERROR(errno);
> >      }
> > +#if CONFIG_LIBV4L2
> > +    fd_libv4l = v4l2_fd_open(fd, 0);
> 
> > +    if (fd < 0) {
> > +        av_log(ctx, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",
> > +               ctx->filename, strerror(errno));
> > +        return AVERROR(errno);
> 
> err = AVERROR(errno);
> av_log(...)
> return err;
> 
> is safer, as av_log() may change the value of errno.
> 
> > +    }
> > +    fd = fd_libv4l;
> > +#endif
> 
> Also av_strerror() should be preferred, or this has a slight
> chance the get bogus data in multi-threaded apps.
> 

OK, will resend a patch soon, thanks for the review.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111030/0b1d7f63/attachment.asc>


More information about the ffmpeg-devel mailing list