static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)

{

    struct video_data *s = s1->priv_data;

    struct v4l2_input input;

    struct v4l2_standard standard;

    struct v4l2_streamparm streamparm = { 0 };

    struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;

    int i, ret;

    AVRational framerate_q;



    streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;



    if (s->framerate &&

        (ret = av_parse_video_rate(&framerate_q, s->framerate)) < 0) {

        av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n",

               s->framerate);

        return ret;

    }



    /* set tv video input */

    memset (&input, 0, sizeof (input));

    input.index = s->channel;

    if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {

        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");

        return AVERROR(EIO);

    }



    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",

            s->channel, input.name);

    if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {

        av_log(s1, AV_LOG_ERROR,

               "The V4L2 driver ioctl set input(%d) failed\n",

                s->channel);

        return AVERROR(EIO);

    }



    if (s->standard) {

        av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",

               s->standard);

        /* set tv standard */

        memset (&standard, 0, sizeof (standard));

        for(i=0;;i++) {

            standard.index = i;

            if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {

                av_log(s1, AV_LOG_ERROR,

                       "The V4L2 driver ioctl set standard(%s) failed\n",

                       s->standard);

                return AVERROR(EIO);

            }



            if (!av_strcasecmp(standard.name, s->standard)) {

                break;

            }

        }



        av_log(s1, AV_LOG_DEBUG,

               "The V4L2 driver set standard: %s, id: %"PRIu64"\n",

               s->standard, (uint64_t)standard.id);

        if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {

            av_log(s1, AV_LOG_ERROR,

                   "The V4L2 driver ioctl set standard(%s) failed\n",

                   s->standard);

            return AVERROR(EIO);

        }

    }



    if (framerate_q.num && framerate_q.den) {

        av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",

               framerate_q.den, framerate_q.num);

        tpf->numerator   = framerate_q.den;

        tpf->denominator = framerate_q.num;



        if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {

            av_log(s1, AV_LOG_ERROR,

                   "ioctl set time per frame(%d/%d) failed\n",

                   framerate_q.den, framerate_q.num);

            return AVERROR(EIO);

        }



        if (framerate_q.num != tpf->denominator ||

            framerate_q.den != tpf->numerator) {

            av_log(s1, AV_LOG_INFO,

                   "The driver changed the time per frame from "

                   "%d/%d to %d/%d\n",

                   framerate_q.den, framerate_q.num,

                   tpf->numerator, tpf->denominator);

        }

    } else {

        if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {

            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n",

                   strerror(errno));

            return AVERROR(errno);

        }

    }

    s1->streams[0]->codec->time_base.den = tpf->denominator;

    s1->streams[0]->codec->time_base.num = tpf->numerator;



    s->timeout = 100 +

        av_rescale_q(1, s1->streams[0]->codec->time_base,

                        (AVRational){1, 1000});



    return 0;

}

static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)

{

    struct video_data *s = s1->priv_data;

    struct v4l2_input input;

    struct v4l2_standard standard;

    struct v4l2_streamparm streamparm = { 0 };

    struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;

    int i, ret;

    AVRational framerate_q;



    streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;



    if (s->framerate &&

        (ret = av_parse_video_rate(&framerate_q, s->framerate)) < 0) {

        av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n",

               s->framerate);

        return ret;

    }



    

    memset (&input, 0, sizeof (input));

    input.index = s->channel;

    if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {

        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");

        return AVERROR(EIO);

    }



    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",

            s->channel, input.name);

    if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {

        av_log(s1, AV_LOG_ERROR,

               "The V4L2 driver ioctl set input(%d) failed\n",

                s->channel);

        return AVERROR(EIO);

    }



    if (s->standard) {

        av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",

               s->standard);

        

        memset (&standard, 0, sizeof (standard));

        for(i=0;;i++) {

            standard.index = i;

            if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {

                av_log(s1, AV_LOG_ERROR,

                       "The V4L2 driver ioctl set standard(%s) failed\n",

                       s->standard);

                return AVERROR(EIO);

            }



            if (!av_strcasecmp(standard.name, s->standard)) {

                break;

            }

        }



        av_log(s1, AV_LOG_DEBUG,

               "The V4L2 driver set standard: %s, id: %"PRIu64"\n",

               s->standard, (uint64_t)standard.id);

        if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {

            av_log(s1, AV_LOG_ERROR,

                   "The V4L2 driver ioctl set standard(%s) failed\n",

                   s->standard);

            return AVERROR(EIO);

        }

    }



    if (framerate_q.num && framerate_q.den) {

        av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",

               framerate_q.den, framerate_q.num);

        tpf->numerator   = framerate_q.den;

        tpf->denominator = framerate_q.num;



        if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {

            av_log(s1, AV_LOG_ERROR,

                   "ioctl set time per frame(%d/%d) failed\n",

                   framerate_q.den, framerate_q.num);

            return AVERROR(EIO);

        }



        if (framerate_q.num != tpf->denominator ||

            framerate_q.den != tpf->numerator) {

            av_log(s1, AV_LOG_INFO,

                   "The driver changed the time per frame from "

                   "%d/%d to %d/%d\n",

                   framerate_q.den, framerate_q.num,

                   tpf->numerator, tpf->denominator);

        }

    } else {

        if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {

            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n",

                   strerror(errno));

            return AVERROR(errno);

        }

    }

    s1->streams[0]->codec->time_base.den = tpf->denominator;

    s1->streams[0]->codec->time_base.num = tpf->numerator;



    s->timeout = 100 +

        av_rescale_q(1, s1->streams[0]->codec->time_base,

                        (AVRational){1, 1000});



    return 0;

}

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

{

    struct video_data *VAR_2 = VAR_0->priv_data;

    struct v4l2_input VAR_3;

    struct v4l2_standard VAR_4;

    struct v4l2_streamparm VAR_5 = { 0 };

    struct v4l2_fract *VAR_6 = &VAR_5.parm.capture.timeperframe;

    int VAR_7, VAR_8;

    AVRational framerate_q;



    VAR_5.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;



    if (VAR_2->framerate &&

        (VAR_8 = av_parse_video_rate(&framerate_q, VAR_2->framerate)) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Could not parse framerate '%VAR_2'.\n",

               VAR_2->framerate);

        return VAR_8;

    }



    

    memset (&VAR_3, 0, sizeof (VAR_3));

    VAR_3.index = VAR_2->channel;

    if (ioctl(VAR_2->fd, VIDIOC_ENUMINPUT, &VAR_3) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "The V4L2 driver ioctl enum VAR_3 failed:\n");

        return AVERROR(EIO);

    }



    av_log(VAR_0, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, VAR_3: %VAR_2\n",

            VAR_2->channel, VAR_3.name);

    if (ioctl(VAR_2->fd, VIDIOC_S_INPUT, &VAR_3.index) < 0) {

        av_log(VAR_0, AV_LOG_ERROR,

               "The V4L2 driver ioctl set VAR_3(%d) failed\n",

                VAR_2->channel);

        return AVERROR(EIO);

    }



    if (VAR_2->VAR_4) {

        av_log(VAR_0, AV_LOG_DEBUG, "The V4L2 driver set VAR_4: %VAR_2\n",

               VAR_2->VAR_4);

        

        memset (&VAR_4, 0, sizeof (VAR_4));

        for(VAR_7=0;;VAR_7++) {

            VAR_4.index = VAR_7;

            if (ioctl(VAR_2->fd, VIDIOC_ENUMSTD, &VAR_4) < 0) {

                av_log(VAR_0, AV_LOG_ERROR,

                       "The V4L2 driver ioctl set VAR_4(%VAR_2) failed\n",

                       VAR_2->VAR_4);

                return AVERROR(EIO);

            }



            if (!av_strcasecmp(VAR_4.name, VAR_2->VAR_4)) {

                break;

            }

        }



        av_log(VAR_0, AV_LOG_DEBUG,

               "The V4L2 driver set VAR_4: %VAR_2, id: %"PRIu64"\n",

               VAR_2->VAR_4, (uint64_t)VAR_4.id);

        if (ioctl(VAR_2->fd, VIDIOC_S_STD, &VAR_4.id) < 0) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "The V4L2 driver ioctl set VAR_4(%VAR_2) failed\n",

                   VAR_2->VAR_4);

            return AVERROR(EIO);

        }

    }



    if (framerate_q.num && framerate_q.den) {

        av_log(VAR_0, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",

               framerate_q.den, framerate_q.num);

        VAR_6->numerator   = framerate_q.den;

        VAR_6->denominator = framerate_q.num;



        if (ioctl(VAR_2->fd, VIDIOC_S_PARM, &VAR_5) != 0) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "ioctl set time per frame(%d/%d) failed\n",

                   framerate_q.den, framerate_q.num);

            return AVERROR(EIO);

        }



        if (framerate_q.num != VAR_6->denominator ||

            framerate_q.den != VAR_6->numerator) {

            av_log(VAR_0, AV_LOG_INFO,

                   "The driver changed the time per frame from "

                   "%d/%d to %d/%d\n",

                   framerate_q.den, framerate_q.num,

                   VAR_6->numerator, VAR_6->denominator);

        }

    } else {

        if (ioctl(VAR_2->fd, VIDIOC_G_PARM, &VAR_5) != 0) {

            av_log(VAR_0, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %VAR_2\n",

                   strerror(errno));

            return AVERROR(errno);

        }

    }

    VAR_0->streams[0]->codec->time_base.den = VAR_6->denominator;

    VAR_0->streams[0]->codec->time_base.num = VAR_6->numerator;



    VAR_2->timeout = 100 +

        av_rescale_q(1, VAR_0->streams[0]->codec->time_base,

                        (AVRational){1, 1000});



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{ struct video_data *VAR_2 = VAR_0->priv_data; struct v4l2_input VAR_3; struct v4l2_standard VAR_4; struct v4l2_streamparm VAR_5 = { 0 }; struct v4l2_fract *VAR_6 = &VAR_5.parm.capture.timeperframe; int VAR_7, VAR_8; AVRational framerate_q; VAR_5.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (VAR_2->framerate &&
(VAR_8 = av_parse_video_rate(&framerate_q, VAR_2->framerate)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Could not parse framerate '%VAR_2'.\n",
VAR_2->framerate); return VAR_8; } memset (&VAR_3, 0, sizeof (VAR_3)); VAR_3.index = VAR_2->channel; if (ioctl(VAR_2->fd, VIDIOC_ENUMINPUT, &VAR_3) < 0) { av_log(VAR_0, AV_LOG_ERROR, "The V4L2 driver ioctl enum VAR_3 failed:\n"); return AVERROR(EIO); } av_log(VAR_0, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, VAR_3: %VAR_2\n",
VAR_2->channel, VAR_3.name); if (ioctl(VAR_2->fd, VIDIOC_S_INPUT, &VAR_3.index) < 0) { av_log(VAR_0, AV_LOG_ERROR,
"The V4L2 driver ioctl set VAR_3(%d) failed\n",
VAR_2->channel); return AVERROR(EIO); } if (VAR_2->VAR_4) { av_log(VAR_0, AV_LOG_DEBUG, "The V4L2 driver set VAR_4: %VAR_2\n",
VAR_2->VAR_4); memset (&VAR_4, 0, sizeof (VAR_4)); for(VAR_7=0;;VAR_7++) { VAR_4.index = VAR_7; if (ioctl(VAR_2->fd, VIDIOC_ENUMSTD, &VAR_4) < 0) { av_log(VAR_0, AV_LOG_ERROR,
"The V4L2 driver ioctl set VAR_4(%VAR_2) failed\n",
VAR_2->VAR_4); return AVERROR(EIO); } if (!av_strcasecmp(VAR_4.name, VAR_2->VAR_4)) { break; } } av_log(VAR_0, AV_LOG_DEBUG,
"The V4L2 driver set VAR_4: %VAR_2, id: %"PRIu64"\n",
VAR_2->VAR_4, (uint64_t)VAR_4.id); if (ioctl(VAR_2->fd, VIDIOC_S_STD, &VAR_4.id) < 0) { av_log(VAR_0, AV_LOG_ERROR,
"The V4L2 driver ioctl set VAR_4(%VAR_2) failed\n",
VAR_2->VAR_4); return AVERROR(EIO); } } if (framerate_q.num && framerate_q.den) { av_log(VAR_0, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
framerate_q.den, framerate_q.num); VAR_6->numerator   = framerate_q.den; VAR_6->denominator = framerate_q.num; if (ioctl(VAR_2->fd, VIDIOC_S_PARM, &VAR_5) != 0) { av_log(VAR_0, AV_LOG_ERROR,
"ioctl set time per frame(%d/%d) failed\n",
framerate_q.den, framerate_q.num); return AVERROR(EIO); } if (framerate_q.num != VAR_6->denominator ||
framerate_q.den != VAR_6->numerator) { av_log(VAR_0, AV_LOG_INFO,
"The driver changed the time per frame from "
"%d/%d to %d/%d\n",
framerate_q.den, framerate_q.num,
VAR_6->numerator, VAR_6->denominator); } } else { if (ioctl(VAR_2->fd, VIDIOC_G_PARM, &VAR_5) != 0) { av_log(VAR_0, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %VAR_2\n",
strerror(errno)); return AVERROR(errno); } } VAR_0->streams[0]->codec->time_base.den = VAR_6->denominator; VAR_0->streams[0]->codec->time_base.num = VAR_6->numerator; VAR_2->timeout = 100 +
av_rescale_q(1, VAR_0->streams[0]->codec->time_base,
(AVRational){1, 1000}); return 0; }