On Tue, 27 Dec 2011 07:51:21 +0100, Luca Barbato <[email protected]> wrote:
> Check capabilities directly in the function, further simplify the code.
> ---
>  libavdevice/v4l2.c |   71 ++++++++++++++++++++++++---------------------------
>  1 files changed, 33 insertions(+), 38 deletions(-)
> 
> diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
> index ee43ed7..c1ba756 100644
> --- a/libavdevice/v4l2.c
> +++ b/libavdevice/v4l2.c
> @@ -101,7 +101,7 @@ static struct fmt_map fmt_conversion_table[] = {
>      { PIX_FMT_NONE,    CODEC_ID_MJPEG,    V4L2_PIX_FMT_JPEG    },
>  };
>  
> -static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
> +static int device_open(AVFormatContext *ctx)
>  {
>      struct v4l2_capability cap;
>      int fd;
> @@ -114,41 +114,43 @@ static int device_open(AVFormatContext *ctx, uint32_t 
> *capabilities)
>  
>      fd = open(ctx->filename, flags, 0);
>      if (fd < 0) {
> +        err = errno;
> +
>          av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
> -               ctx->filename, strerror(errno));
> +               ctx->filename, strerror(err));
>  
> -        return AVERROR(errno);
> +        return AVERROR(err);
>      }
>  
>      res = ioctl(fd, VIDIOC_QUERYCAP, &cap);
> -    // ENOIOCTLCMD definition only availble on __KERNEL__
> -    if (res < 0 && ((err = errno) == 515)) {
> -        av_log(ctx, AV_LOG_ERROR,
> -               "QUERYCAP not implemented, probably V4L device but "
> -               "not supporting V4L2\n");
> -        close(fd);
> -
> -        return AVERROR(515);
> -    }
> -
>      if (res < 0) {
> +        err = errno;
>          av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
> -                 strerror(errno));
> -        close(fd);
> +           strerror(err));
>  
> -        return AVERROR(err);
> +        goto fail;
>      }
>  
> -    if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
> -        av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n");
> -        close(fd);
> +    av_log(ctx, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n",
> +           fd, cap.capabilities);
> +
> +    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
> +        av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n");
> +        err = ENODEV;
>  
> -        return AVERROR(ENODEV);
> +        goto fail;
>      }
>  
> -    *capabilities = cap.capabilities;
> +    if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
> +        av_log(ctx, AV_LOG_ERROR, "Streaming I/O not supported.\n");

This error message is confusing, what you probably want to say is
"The device does not support streaming I/O."
But it could also mean that the device supports it, but _we_ don't.

> +        err = AVERROR(EIO);

Missing goto fail?


-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to