static int device_open(AVFormatContext *ctx, uint32_t *capabilities)

{

    struct v4l2_capability cap;

    int fd;

    int res, err;

    int flags = O_RDWR;



    if (ctx->flags & AVFMT_FLAG_NONBLOCK) {

        flags |= O_NONBLOCK;

    }



    fd = 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);

    }



    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) {

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

                 strerror(errno));

        close(fd);



        return AVERROR(err);

    }



    if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {

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

        close(fd);



        return AVERROR(ENODEV);

    }



    *capabilities = cap.capabilities;



    return fd;

}

static int device_open(AVFormatContext *ctx, uint32_t *capabilities)

{

    struct v4l2_capability cap;

    int fd;

    int res, err;

    int flags = O_RDWR;



    if (ctx->flags & AVFMT_FLAG_NONBLOCK) {

        flags |= O_NONBLOCK;

    }



    fd = 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);

    }



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

    

    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) {

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

                 strerror(errno));

        close(fd);



        return AVERROR(err);

    }



    if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {

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

        close(fd);



        return AVERROR(ENODEV);

    }



    *capabilities = cap.capabilities;



    return fd;

}

static int FUNC_0(AVFormatContext *VAR_0, uint32_t *VAR_1)

{

    struct v4l2_capability VAR_2;

    int VAR_3;

    int VAR_4, VAR_5;

    int VAR_6 = O_RDWR;



    if (VAR_0->VAR_6 & AVFMT_FLAG_NONBLOCK) {

        VAR_6 |= O_NONBLOCK;

    }



    VAR_3 = open(VAR_0->filename, VAR_6, 0);

    if (VAR_3 < 0) {

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

               VAR_0->filename, strerror(errno));



        return AVERROR(errno);

    }



    VAR_4 = ioctl(VAR_3, VIDIOC_QUERYCAP, &VAR_2);

    

    if (VAR_4 < 0 && ((VAR_5 = errno) == 515)) {

        av_log(VAR_0, AV_LOG_ERROR,

               "QUERYCAP not implemented, probably V4L device but "

               "not supporting V4L2\n");

        close(VAR_3);



        return AVERROR(515);

    }



    if (VAR_4 < 0) {

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

                 strerror(errno));

        close(VAR_3);



        return AVERROR(VAR_5);

    }



    if ((VAR_2.VAR_1 & V4L2_CAP_VIDEO_CAPTURE) == 0) {

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

        close(VAR_3);



        return AVERROR(ENODEV);

    }



    *VAR_1 = VAR_2.VAR_1;



    return VAR_3;

}

static int FUNC_0(AVFormatContext *VAR_0, uint32_t *VAR_1)
{ struct v4l2_capability VAR_2; int VAR_3; int VAR_4, VAR_5; int VAR_6 = O_RDWR; if (VAR_0->VAR_6 & AVFMT_FLAG_NONBLOCK) { VAR_6 |= O_NONBLOCK; } VAR_3 = open(VAR_0->filename, VAR_6, 0); if (VAR_3 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
VAR_0->filename, strerror(errno)); return AVERROR(errno); } VAR_4 = ioctl(VAR_3, VIDIOC_QUERYCAP, &VAR_2); if (VAR_4 < 0 && ((VAR_5 = errno) == 515)) { av_log(VAR_0, AV_LOG_ERROR,
"QUERYCAP not implemented, probably V4L device but "
"not supporting V4L2\n"); close(VAR_3); return AVERROR(515); } if (VAR_4 < 0) { av_log(VAR_0, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
strerror(errno)); close(VAR_3); return AVERROR(VAR_5); } if ((VAR_2.VAR_1 & V4L2_CAP_VIDEO_CAPTURE) == 0) { av_log(VAR_0, AV_LOG_ERROR, "Not a video capture device\n"); close(VAR_3); return AVERROR(ENODEV); } *VAR_1 = VAR_2.VAR_1; return VAR_3; }