static int device_init(AVFormatContext *ctx, int *width, int *height,

                       uint32_t pix_fmt)

{

    struct video_data *s = ctx->priv_data;

    int fd = s->fd;

    struct v4l2_format fmt;

    struct v4l2_pix_format *pix = &fmt.fmt.pix;



    int res;



    memset(&fmt, 0, sizeof(struct v4l2_format));



    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    pix->width = *width;

    pix->height = *height;

    pix->pixelformat = pix_fmt;

    pix->field = V4L2_FIELD_ANY;



    res = ioctl(fd, VIDIOC_S_FMT, &fmt);



    if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {

        av_log(ctx, AV_LOG_INFO,

               "The V4L2 driver changed the video from %dx%d to %dx%d\n",

               *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);

        *width = fmt.fmt.pix.width;

        *height = fmt.fmt.pix.height;

    }



    if (pix_fmt != fmt.fmt.pix.pixelformat) {

        av_log(ctx, AV_LOG_DEBUG,

               "The V4L2 driver changed the pixel format "

               "from 0x%08X to 0x%08X\n",

               pix_fmt, fmt.fmt.pix.pixelformat);

        res = -1;

    }



    if (fmt.fmt.pix.field == V4L2_FIELD_INTERLACED) {

        av_log(ctx, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode");

        s->interlaced = 1;

    }



    return res;

}

static int device_init(AVFormatContext *ctx, int *width, int *height,

                       uint32_t pix_fmt)

{

    struct video_data *s = ctx->priv_data;

    int fd = s->fd;

    struct v4l2_format fmt;

    struct v4l2_pix_format *pix = &fmt.fmt.pix;



    int res;



    memset(&fmt, 0, sizeof(struct v4l2_format));



    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    pix->width = *width;

    pix->height = *height;

    pix->pixelformat = pix_fmt;

    pix->field = V4L2_FIELD_ANY;



    res = ioctl(fd, VIDIOC_S_FMT, &fmt);



    if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {

        av_log(ctx, AV_LOG_INFO,

               "The V4L2 driver changed the video from %dx%d to %dx%d\n",

               *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);

        *width = fmt.fmt.pix.width;

        *height = fmt.fmt.pix.height;

    }



    if (pix_fmt != fmt.fmt.pix.pixelformat) {

        av_log(ctx, AV_LOG_DEBUG,

               "The V4L2 driver changed the pixel format "

               "from 0x%08X to 0x%08X\n",

               pix_fmt, fmt.fmt.pix.pixelformat);

        res = -1;

    }



    if (fmt.fmt.pix.field == V4L2_FIELD_INTERLACED) {

        av_log(ctx, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode");

        s->interlaced = 1;

    }



    return res;

}

static int FUNC_0(AVFormatContext *VAR_0, int *VAR_1, int *VAR_2,

                       uint32_t VAR_3)

{

    struct video_data *VAR_4 = VAR_0->priv_data;

    int VAR_5 = VAR_4->VAR_5;

    struct v4l2_format VAR_6;

    struct v4l2_pix_format *VAR_7 = &VAR_6.VAR_6.VAR_7;



    int VAR_8;



    memset(&VAR_6, 0, sizeof(struct v4l2_format));



    VAR_6.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    VAR_7->VAR_1 = *VAR_1;

    VAR_7->VAR_2 = *VAR_2;

    VAR_7->pixelformat = VAR_3;

    VAR_7->field = V4L2_FIELD_ANY;



    VAR_8 = ioctl(VAR_5, VIDIOC_S_FMT, &VAR_6);



    if ((*VAR_1 != VAR_6.VAR_6.VAR_7.VAR_1) || (*VAR_2 != VAR_6.VAR_6.VAR_7.VAR_2)) {

        av_log(VAR_0, AV_LOG_INFO,

               "The V4L2 driver changed the video from %dx%d to %dx%d\n",

               *VAR_1, *VAR_2, VAR_6.VAR_6.VAR_7.VAR_1, VAR_6.VAR_6.VAR_7.VAR_2);

        *VAR_1 = VAR_6.VAR_6.VAR_7.VAR_1;

        *VAR_2 = VAR_6.VAR_6.VAR_7.VAR_2;

    }



    if (VAR_3 != VAR_6.VAR_6.VAR_7.pixelformat) {

        av_log(VAR_0, AV_LOG_DEBUG,

               "The V4L2 driver changed the pixel format "

               "from 0x%08X to 0x%08X\n",

               VAR_3, VAR_6.VAR_6.VAR_7.pixelformat);

        VAR_8 = -1;

    }



    if (VAR_6.VAR_6.VAR_7.field == V4L2_FIELD_INTERLACED) {

        av_log(VAR_0, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode");

        VAR_4->interlaced = 1;

    }



    return VAR_8;

}

static int FUNC_0(AVFormatContext *VAR_0, int *VAR_1, int *VAR_2,
uint32_t VAR_3)
{ struct video_data *VAR_4 = VAR_0->priv_data; int VAR_5 = VAR_4->VAR_5; struct v4l2_format VAR_6; struct v4l2_pix_format *VAR_7 = &VAR_6.VAR_6.VAR_7; int VAR_8; memset(&VAR_6, 0, sizeof(struct v4l2_format)); VAR_6.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; VAR_7->VAR_1 = *VAR_1; VAR_7->VAR_2 = *VAR_2; VAR_7->pixelformat = VAR_3; VAR_7->field = V4L2_FIELD_ANY; VAR_8 = ioctl(VAR_5, VIDIOC_S_FMT, &VAR_6); if ((*VAR_1 != VAR_6.VAR_6.VAR_7.VAR_1) || (*VAR_2 != VAR_6.VAR_6.VAR_7.VAR_2)) { av_log(VAR_0, AV_LOG_INFO,
"The V4L2 driver changed the video from %dx%d to %dx%d\n",
*VAR_1, *VAR_2, VAR_6.VAR_6.VAR_7.VAR_1, VAR_6.VAR_6.VAR_7.VAR_2); *VAR_1 = VAR_6.VAR_6.VAR_7.VAR_1; *VAR_2 = VAR_6.VAR_6.VAR_7.VAR_2; } if (VAR_3 != VAR_6.VAR_6.VAR_7.pixelformat) { av_log(VAR_0, AV_LOG_DEBUG,
"The V4L2 driver changed the pixel format "
"from 0x%08X to 0x%08X\n",
VAR_3, VAR_6.VAR_6.VAR_7.pixelformat); VAR_8 = -1; } if (VAR_6.VAR_6.VAR_7.field == V4L2_FIELD_INTERLACED) { av_log(VAR_0, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode"); VAR_4->interlaced = 1; } return VAR_8; }