static int device_open(AVFormatContext *ctx)

{

    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 = v4l2_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(err));



        return AVERROR(err);

    }

#if CONFIG_LIBV4L2

    fd_libv4l = v4l2_fd_open(fd, 0);

    if (fd < 0) {

        err = AVERROR(errno);

        av_log(ctx, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",

               ctx->filename, strerror(errno));

        return err;

    }

    fd = fd_libv4l;

#endif



    res = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap);

    if (res < 0) {

        err = errno;

        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",

               strerror(err));



        goto fail;

    }



    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;



        goto fail;

    }



    if (!(cap.capabilities & V4L2_CAP_STREAMING)) {

        av_log(ctx, AV_LOG_ERROR,

               "The device does not support the streaming I/O method.\n");

        err = ENOSYS;



        goto fail;

    }



    return fd;



fail:

    v4l2_close(fd);

    return AVERROR(err);

}

static int device_open(AVFormatContext *ctx)

{

    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 = v4l2_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(err));



        return AVERROR(err);

    }

#if CONFIG_LIBV4L2

    fd_libv4l = v4l2_fd_open(fd, 0);

    if (fd < 0) {

        err = AVERROR(errno);

        av_log(ctx, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",

               ctx->filename, strerror(errno));

        return err;

    }

    fd = fd_libv4l;

#endif



    res = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap);

    if (res < 0) {

        err = errno;

        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",

               strerror(err));



        goto fail;

    }



    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;



        goto fail;

    }



    if (!(cap.capabilities & V4L2_CAP_STREAMING)) {

        av_log(ctx, AV_LOG_ERROR,

               "The device does not support the streaming I/O method.\n");

        err = ENOSYS;



        goto fail;

    }



    return fd;



fail:

    v4l2_close(fd);

    return AVERROR(err);

}

#if CONFIG_LIBV4L2     int fd_libv4l; #endif #if CONFIG_LIBV4L2     fd_libv4l = v4l2_fd_open(fd, 0);     if (fd < 0) {         err = AVERROR(errno);         av_log(ctx, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",                ctx->filename, strerror(errno));         return err;     fd = fd_libv4l; #endif
static int FUNC_0(AVFormatContext *VAR_0)

{

    struct v4l2_capability VAR_1;

    int VAR_2;

#if CONFIG_LIBV4L2

    int fd_libv4l;

#endif

    int VAR_3, VAR_4;

    int VAR_5 = O_RDWR;



    if (VAR_0->VAR_5 & AVFMT_FLAG_NONBLOCK) {

        VAR_5 |= O_NONBLOCK;

    }



    VAR_2 = v4l2_open(VAR_0->filename, VAR_5, 0);

    if (VAR_2 < 0) {

        VAR_4 = errno;



        av_log(VAR_0, AV_LOG_ERROR, "Cannot open video device %s : %s\n",

               VAR_0->filename, strerror(VAR_4));



        return AVERROR(VAR_4);

    }

#if CONFIG_LIBV4L2

    fd_libv4l = v4l2_fd_open(VAR_2, 0);

    if (VAR_2 < 0) {

        VAR_4 = AVERROR(errno);

        av_log(VAR_0, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",

               VAR_0->filename, strerror(errno));

        return VAR_4;

    }

    VAR_2 = fd_libv4l;

#endif



    VAR_3 = v4l2_ioctl(VAR_2, VIDIOC_QUERYCAP, &VAR_1);

    if (VAR_3 < 0) {

        VAR_4 = errno;

        av_log(VAR_0, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",

               strerror(VAR_4));



        goto fail;

    }



    av_log(VAR_0, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n",

           VAR_2, VAR_1.capabilities);



    if (!(VAR_1.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {

        av_log(VAR_0, AV_LOG_ERROR, "Not a video capture device.\n");

        VAR_4 = ENODEV;



        goto fail;

    }



    if (!(VAR_1.capabilities & V4L2_CAP_STREAMING)) {

        av_log(VAR_0, AV_LOG_ERROR,

               "The device does not support the streaming I/O method.\n");

        VAR_4 = ENOSYS;



        goto fail;

    }



    return VAR_2;



fail:

    v4l2_close(VAR_2);

    return AVERROR(VAR_4);

}

static int FUNC_0(AVFormatContext *VAR_0)
{ struct v4l2_capability VAR_1; int VAR_2; #if CONFIG_LIBV4L2
int fd_libv4l; #endif
int VAR_3, VAR_4; int VAR_5 = O_RDWR; if (VAR_0->VAR_5 & AVFMT_FLAG_NONBLOCK) { VAR_5 |= O_NONBLOCK; } VAR_2 = v4l2_open(VAR_0->filename, VAR_5, 0); if (VAR_2 < 0) { VAR_4 = errno; av_log(VAR_0, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
VAR_0->filename, strerror(VAR_4)); return AVERROR(VAR_4); } #if CONFIG_LIBV4L2
fd_libv4l = v4l2_fd_open(VAR_2, 0); if (VAR_2 < 0) { VAR_4 = AVERROR(errno); av_log(VAR_0, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",
VAR_0->filename, strerror(errno)); return VAR_4; } VAR_2 = fd_libv4l; #endif
VAR_3 = v4l2_ioctl(VAR_2, VIDIOC_QUERYCAP, &VAR_1); if (VAR_3 < 0) { VAR_4 = errno; av_log(VAR_0, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
strerror(VAR_4)); goto fail; } av_log(VAR_0, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n",
VAR_2, VAR_1.capabilities); if (!(VAR_1.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { av_log(VAR_0, AV_LOG_ERROR, "Not a video capture device.\n"); VAR_4 = ENODEV; goto fail; } if (!(VAR_1.capabilities & V4L2_CAP_STREAMING)) { av_log(VAR_0, AV_LOG_ERROR,
"The device does not support the streaming I/O method.\n"); VAR_4 = ENOSYS; goto fail; } return VAR_2; fail:
v4l2_close(VAR_2); return AVERROR(VAR_4); }