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

{

    VideoData *s = s1->priv_data;

    AVStream *st;

    int width, height;

    int video_fd, frame_size;

    int ret, frame_rate, frame_rate_base;

    int desired_palette, desired_depth;

    struct video_tuner tuner;

    struct video_audio audio;

    struct video_picture pict;

    int j;

    int vformat_num = sizeof(video_formats) / sizeof(video_formats[0]);



    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {

        av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",

            ap->width, ap->height, ap->time_base.den);



        return -1;

    }



    width = ap->width;

    height = ap->height;

    frame_rate      = ap->time_base.den;

    frame_rate_base = ap->time_base.num;



    if((unsigned)width > 32767 || (unsigned)height > 32767) {

        av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",

            width, height);



        return -1;

    }



    st = av_new_stream(s1, 0);

    if (!st)

        return AVERROR(ENOMEM);

    av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */



    s->width = width;

    s->height = height;

    s->frame_rate      = frame_rate;

    s->frame_rate_base = frame_rate_base;



    video_fd = open(s1->filename, O_RDWR);

    if (video_fd < 0) {

        av_log(s1, AV_LOG_ERROR, "%s: %s\n", s1->filename, strerror(errno));

        goto fail;

    }



    if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {

        av_log(s1, AV_LOG_ERROR, "VIDIOCGCAP: %s\n", strerror(errno));

        goto fail;

    }



    if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {

        av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");

        goto fail;

    }



    desired_palette = -1;

    desired_depth = -1;

    for (j = 0; j < vformat_num; j++) {

        if (ap->pix_fmt == video_formats[j].pix_fmt) {

            desired_palette = video_formats[j].palette;

            desired_depth = video_formats[j].depth;

            break;

        }

    }



    /* set tv standard */

    if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {

        if (!strcasecmp(ap->standard, "pal"))

            tuner.mode = VIDEO_MODE_PAL;

        else if (!strcasecmp(ap->standard, "secam"))

            tuner.mode = VIDEO_MODE_SECAM;

        else

            tuner.mode = VIDEO_MODE_NTSC;

        ioctl(video_fd, VIDIOCSTUNER, &tuner);

    }



    /* unmute audio */

    audio.audio = 0;

    ioctl(video_fd, VIDIOCGAUDIO, &audio);

    memcpy(&s->audio_saved, &audio, sizeof(audio));

    audio.flags &= ~VIDEO_AUDIO_MUTE;

    ioctl(video_fd, VIDIOCSAUDIO, &audio);



    ioctl(video_fd, VIDIOCGPICT, &pict);

#if 0

    printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",

           pict.colour,

           pict.hue,

           pict.brightness,

           pict.contrast,

           pict.whiteness);

#endif

    /* try to choose a suitable video format */

    pict.palette = desired_palette;

    pict.depth= desired_depth;

    if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {

        for (j = 0; j < vformat_num; j++) {

            pict.palette = video_formats[j].palette;

            pict.depth = video_formats[j].depth;

            if (-1 != ioctl(video_fd, VIDIOCSPICT, &pict))

                break;

        }

        if (j >= vformat_num)

            goto fail1;

    }



    ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);

    if (ret < 0) {

        /* try to use read based access */

        struct video_window win;

        int val;



        win.x = 0;

        win.y = 0;

        win.width = width;

        win.height = height;

        win.chromakey = -1;

        win.flags = 0;



        ioctl(video_fd, VIDIOCSWIN, &win);



        s->frame_format = pict.palette;



        val = 1;

        ioctl(video_fd, VIDIOCCAPTURE, &val);



        s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;

        s->use_mmap = 0;

    } else {

        s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);

        if ((unsigned char*)-1 == s->video_buf) {

            s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0);

            if ((unsigned char*)-1 == s->video_buf) {

                av_log(s1, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));

                goto fail;

            }

        }

        s->gb_frame = 0;

        s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;



        /* start to grab the first frame */

        s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;

        s->gb_buf.height = height;

        s->gb_buf.width = width;

        s->gb_buf.format = pict.palette;



        ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);

        if (ret < 0) {

            if (errno != EAGAIN) {

            fail1:

                av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");

            } else {

                av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");

            }

            goto fail;

        }

        for (j = 1; j < s->gb_buffers.frames; j++) {

          s->gb_buf.frame = j;

          ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);

        }

        s->frame_format = s->gb_buf.format;

        s->use_mmap = 1;

    }



    for (j = 0; j < vformat_num; j++) {

        if (s->frame_format == video_formats[j].palette) {

            frame_size = width * height * video_formats[j].depth / 8;

            st->codec->pix_fmt = video_formats[j].pix_fmt;

            break;

        }

    }



    if (j >= vformat_num)

        goto fail;



    s->fd = video_fd;

    s->frame_size = frame_size;



    st->codec->codec_type = CODEC_TYPE_VIDEO;

    st->codec->codec_id = CODEC_ID_RAWVIDEO;

    st->codec->width = width;

    st->codec->height = height;

    st->codec->time_base.den      = frame_rate;

    st->codec->time_base.num = frame_rate_base;

    st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;



    return 0;

 fail:

    if (video_fd >= 0)

        close(video_fd);

    av_free(st);

    return AVERROR(EIO);

}

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

{

    VideoData *s = s1->priv_data;

    AVStream *st;

    int width, height;

    int video_fd, frame_size;

    int ret, frame_rate, frame_rate_base;

    int desired_palette, desired_depth;

    struct video_tuner tuner;

    struct video_audio audio;

    struct video_picture pict;

    int j;

    int vformat_num = sizeof(video_formats) / sizeof(video_formats[0]);



    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {

        av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",

            ap->width, ap->height, ap->time_base.den);



        return -1;

    }



    width = ap->width;

    height = ap->height;

    frame_rate      = ap->time_base.den;

    frame_rate_base = ap->time_base.num;



    if((unsigned)width > 32767 || (unsigned)height > 32767) {

        av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",

            width, height);



        return -1;

    }



    st = av_new_stream(s1, 0);

    if (!st)

        return AVERROR(ENOMEM);

    av_set_pts_info(st, 64, 1, 1000000); 



    s->width = width;

    s->height = height;

    s->frame_rate      = frame_rate;

    s->frame_rate_base = frame_rate_base;



    video_fd = open(s1->filename, O_RDWR);

    if (video_fd < 0) {

        av_log(s1, AV_LOG_ERROR, "%s: %s\n", s1->filename, strerror(errno));

        goto fail;

    }



    if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {

        av_log(s1, AV_LOG_ERROR, "VIDIOCGCAP: %s\n", strerror(errno));

        goto fail;

    }



    if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {

        av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");

        goto fail;

    }



    desired_palette = -1;

    desired_depth = -1;

    for (j = 0; j < vformat_num; j++) {

        if (ap->pix_fmt == video_formats[j].pix_fmt) {

            desired_palette = video_formats[j].palette;

            desired_depth = video_formats[j].depth;

            break;

        }

    }



    

    if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {

        if (!strcasecmp(ap->standard, "pal"))

            tuner.mode = VIDEO_MODE_PAL;

        else if (!strcasecmp(ap->standard, "secam"))

            tuner.mode = VIDEO_MODE_SECAM;

        else

            tuner.mode = VIDEO_MODE_NTSC;

        ioctl(video_fd, VIDIOCSTUNER, &tuner);

    }



    

    audio.audio = 0;

    ioctl(video_fd, VIDIOCGAUDIO, &audio);

    memcpy(&s->audio_saved, &audio, sizeof(audio));

    audio.flags &= ~VIDEO_AUDIO_MUTE;

    ioctl(video_fd, VIDIOCSAUDIO, &audio);



    ioctl(video_fd, VIDIOCGPICT, &pict);

#if 0

    printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",

           pict.colour,

           pict.hue,

           pict.brightness,

           pict.contrast,

           pict.whiteness);

#endif

    

    pict.palette = desired_palette;

    pict.depth= desired_depth;

    if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {

        for (j = 0; j < vformat_num; j++) {

            pict.palette = video_formats[j].palette;

            pict.depth = video_formats[j].depth;

            if (-1 != ioctl(video_fd, VIDIOCSPICT, &pict))

                break;

        }

        if (j >= vformat_num)

            goto fail1;

    }



    ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);

    if (ret < 0) {

        

        struct video_window win;

        int val;



        win.x = 0;

        win.y = 0;

        win.width = width;

        win.height = height;

        win.chromakey = -1;

        win.flags = 0;



        ioctl(video_fd, VIDIOCSWIN, &win);



        s->frame_format = pict.palette;



        val = 1;

        ioctl(video_fd, VIDIOCCAPTURE, &val);



        s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;

        s->use_mmap = 0;

    } else {

        s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);

        if ((unsigned char*)-1 == s->video_buf) {

            s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0);

            if ((unsigned char*)-1 == s->video_buf) {

                av_log(s1, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));

                goto fail;

            }

        }

        s->gb_frame = 0;

        s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;



        

        s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;

        s->gb_buf.height = height;

        s->gb_buf.width = width;

        s->gb_buf.format = pict.palette;



        ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);

        if (ret < 0) {

            if (errno != EAGAIN) {

            fail1:

                av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");

            } else {

                av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");

            }

            goto fail;

        }

        for (j = 1; j < s->gb_buffers.frames; j++) {

          s->gb_buf.frame = j;

          ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);

        }

        s->frame_format = s->gb_buf.format;

        s->use_mmap = 1;

    }



    for (j = 0; j < vformat_num; j++) {

        if (s->frame_format == video_formats[j].palette) {

            frame_size = width * height * video_formats[j].depth / 8;

            st->codec->pix_fmt = video_formats[j].pix_fmt;

            break;

        }

    }



    if (j >= vformat_num)

        goto fail;



    s->fd = video_fd;

    s->frame_size = frame_size;



    st->codec->codec_type = CODEC_TYPE_VIDEO;

    st->codec->codec_id = CODEC_ID_RAWVIDEO;

    st->codec->width = width;

    st->codec->height = height;

    st->codec->time_base.den      = frame_rate;

    st->codec->time_base.num = frame_rate_base;

    st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;



    return 0;

 fail:

    if (video_fd >= 0)

        close(video_fd);

    av_free(st);

    return AVERROR(EIO);

}

    av_free(st);
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)

{

    VideoData *s = VAR_0->priv_data;

    AVStream *st;

    int VAR_2, VAR_3;

    int VAR_4, VAR_5;

    int VAR_6, VAR_7, VAR_8;

    int VAR_9, VAR_10;

    struct video_tuner VAR_11;

    struct video_audio VAR_12;

    struct video_picture VAR_13;

    int VAR_14;

    int VAR_15 = sizeof(video_formats) / sizeof(video_formats[0]);



    if (VAR_1->VAR_2 <= 0 || VAR_1->VAR_3 <= 0 || VAR_1->time_base.den <= 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",

            VAR_1->VAR_2, VAR_1->VAR_3, VAR_1->time_base.den);



        return -1;

    }



    VAR_2 = VAR_1->VAR_2;

    VAR_3 = VAR_1->VAR_3;

    VAR_7      = VAR_1->time_base.den;

    VAR_8 = VAR_1->time_base.num;



    if((unsigned)VAR_2 > 32767 || (unsigned)VAR_3 > 32767) {

        av_log(VAR_0, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",

            VAR_2, VAR_3);



        return -1;

    }



    st = av_new_stream(VAR_0, 0);

    if (!st)

        return AVERROR(ENOMEM);

    av_set_pts_info(st, 64, 1, 1000000); 



    s->VAR_2 = VAR_2;

    s->VAR_3 = VAR_3;

    s->VAR_7      = VAR_7;

    s->VAR_8 = VAR_8;



    VAR_4 = open(VAR_0->filename, O_RDWR);

    if (VAR_4 < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "%s: %s\n", VAR_0->filename, strerror(errno));

        goto fail;

    }



    if (ioctl(VAR_4,VIDIOCGCAP, &s->video_cap) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "VIDIOCGCAP: %s\n", strerror(errno));

        goto fail;

    }



    if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {

        av_log(VAR_0, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");

        goto fail;

    }



    VAR_9 = -1;

    VAR_10 = -1;

    for (VAR_14 = 0; VAR_14 < VAR_15; VAR_14++) {

        if (VAR_1->pix_fmt == video_formats[VAR_14].pix_fmt) {

            VAR_9 = video_formats[VAR_14].palette;

            VAR_10 = video_formats[VAR_14].depth;

            break;

        }

    }



    

    if (VAR_1->standard && !ioctl(VAR_4, VIDIOCGTUNER, &VAR_11)) {

        if (!strcasecmp(VAR_1->standard, "pal"))

            VAR_11.mode = VIDEO_MODE_PAL;

        else if (!strcasecmp(VAR_1->standard, "secam"))

            VAR_11.mode = VIDEO_MODE_SECAM;

        else

            VAR_11.mode = VIDEO_MODE_NTSC;

        ioctl(VAR_4, VIDIOCSTUNER, &VAR_11);

    }



    

    VAR_12.VAR_12 = 0;

    ioctl(VAR_4, VIDIOCGAUDIO, &VAR_12);

    memcpy(&s->audio_saved, &VAR_12, sizeof(VAR_12));

    VAR_12.flags &= ~VIDEO_AUDIO_MUTE;

    ioctl(VAR_4, VIDIOCSAUDIO, &VAR_12);



    ioctl(VAR_4, VIDIOCGPICT, &VAR_13);

#if 0

    printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",

           VAR_13.colour,

           VAR_13.hue,

           VAR_13.brightness,

           VAR_13.contrast,

           VAR_13.whiteness);

#endif

    

    VAR_13.palette = VAR_9;

    VAR_13.depth= VAR_10;

    if (VAR_9 == -1 || (VAR_6 = ioctl(VAR_4, VIDIOCSPICT, &VAR_13)) < 0) {

        for (VAR_14 = 0; VAR_14 < VAR_15; VAR_14++) {

            VAR_13.palette = video_formats[VAR_14].palette;

            VAR_13.depth = video_formats[VAR_14].depth;

            if (-1 != ioctl(VAR_4, VIDIOCSPICT, &VAR_13))

                break;

        }

        if (VAR_14 >= VAR_15)

            goto fail1;

    }



    VAR_6 = ioctl(VAR_4,VIDIOCGMBUF,&s->gb_buffers);

    if (VAR_6 < 0) {

        

        struct video_window VAR_16;

        int VAR_17;



        VAR_16.x = 0;

        VAR_16.y = 0;

        VAR_16.VAR_2 = VAR_2;

        VAR_16.VAR_3 = VAR_3;

        VAR_16.chromakey = -1;

        VAR_16.flags = 0;



        ioctl(VAR_4, VIDIOCSWIN, &VAR_16);



        s->frame_format = VAR_13.palette;



        VAR_17 = 1;

        ioctl(VAR_4, VIDIOCCAPTURE, &VAR_17);



        s->time_frame = av_gettime() * s->VAR_7 / s->VAR_8;

        s->use_mmap = 0;

    } else {

        s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,VAR_4,0);

        if ((unsigned char*)-1 == s->video_buf) {

            s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,VAR_4,0);

            if ((unsigned char*)-1 == s->video_buf) {

                av_log(VAR_0, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));

                goto fail;

            }

        }

        s->gb_frame = 0;

        s->time_frame = av_gettime() * s->VAR_7 / s->VAR_8;



        

        s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;

        s->gb_buf.VAR_3 = VAR_3;

        s->gb_buf.VAR_2 = VAR_2;

        s->gb_buf.format = VAR_13.palette;



        VAR_6 = ioctl(VAR_4, VIDIOCMCAPTURE, &s->gb_buf);

        if (VAR_6 < 0) {

            if (errno != EAGAIN) {

            fail1:

                av_log(VAR_0, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");

            } else {

                av_log(VAR_0, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");

            }

            goto fail;

        }

        for (VAR_14 = 1; VAR_14 < s->gb_buffers.frames; VAR_14++) {

          s->gb_buf.frame = VAR_14;

          ioctl(VAR_4, VIDIOCMCAPTURE, &s->gb_buf);

        }

        s->frame_format = s->gb_buf.format;

        s->use_mmap = 1;

    }



    for (VAR_14 = 0; VAR_14 < VAR_15; VAR_14++) {

        if (s->frame_format == video_formats[VAR_14].palette) {

            VAR_5 = VAR_2 * VAR_3 * video_formats[VAR_14].depth / 8;

            st->codec->pix_fmt = video_formats[VAR_14].pix_fmt;

            break;

        }

    }



    if (VAR_14 >= VAR_15)

        goto fail;



    s->fd = VAR_4;

    s->VAR_5 = VAR_5;



    st->codec->codec_type = CODEC_TYPE_VIDEO;

    st->codec->codec_id = CODEC_ID_RAWVIDEO;

    st->codec->VAR_2 = VAR_2;

    st->codec->VAR_3 = VAR_3;

    st->codec->time_base.den      = VAR_7;

    st->codec->time_base.num = VAR_8;

    st->codec->bit_rate = VAR_5 * 1/av_q2d(st->codec->time_base) * 8;



    return 0;

 fail:

    if (VAR_4 >= 0)

        close(VAR_4);

    av_free(st);

    return AVERROR(EIO);

}

static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{ VideoData *s = VAR_0->priv_data; AVStream *st; int VAR_2, VAR_3; int VAR_4, VAR_5; int VAR_6, VAR_7, VAR_8; int VAR_9, VAR_10; struct video_tuner VAR_11; struct video_audio VAR_12; struct video_picture VAR_13; int VAR_14; int VAR_15 = sizeof(video_formats) / sizeof(video_formats[0]); if (VAR_1->VAR_2 <= 0 || VAR_1->VAR_3 <= 0 || VAR_1->time_base.den <= 0) { av_log(VAR_0, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",
VAR_1->VAR_2, VAR_1->VAR_3, VAR_1->time_base.den); return -1; } VAR_2 = VAR_1->VAR_2; VAR_3 = VAR_1->VAR_3; VAR_7      = VAR_1->time_base.den; VAR_8 = VAR_1->time_base.num; if((unsigned)VAR_2 > 32767 || (unsigned)VAR_3 > 32767) { av_log(VAR_0, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
VAR_2, VAR_3); return -1; } st = av_new_stream(VAR_0, 0); if (!st)
return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, 1000000); s->VAR_2 = VAR_2; s->VAR_3 = VAR_3; s->VAR_7      = VAR_7; s->VAR_8 = VAR_8; VAR_4 = open(VAR_0->filename, O_RDWR); if (VAR_4 < 0) { av_log(VAR_0, AV_LOG_ERROR, "%s: %s\n", VAR_0->filename, strerror(errno)); goto fail; } if (ioctl(VAR_4,VIDIOCGCAP, &s->video_cap) < 0) { av_log(VAR_0, AV_LOG_ERROR, "VIDIOCGCAP: %s\n", strerror(errno)); goto fail; } if (!(s->video_cap.type & VID_TYPE_CAPTURE)) { av_log(VAR_0, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n"); goto fail; } VAR_9 = -1; VAR_10 = -1; for (VAR_14 = 0; VAR_14 < VAR_15; VAR_14++) { if (VAR_1->pix_fmt == video_formats[VAR_14].pix_fmt) { VAR_9 = video_formats[VAR_14].palette; VAR_10 = video_formats[VAR_14].depth; break; } } if (VAR_1->standard && !ioctl(VAR_4, VIDIOCGTUNER, &VAR_11)) { if (!strcasecmp(VAR_1->standard, "pal"))
VAR_11.mode = VIDEO_MODE_PAL; else if (!strcasecmp(VAR_1->standard, "secam"))
VAR_11.mode = VIDEO_MODE_SECAM; else
VAR_11.mode = VIDEO_MODE_NTSC; ioctl(VAR_4, VIDIOCSTUNER, &VAR_11); } VAR_12.VAR_12 = 0; ioctl(VAR_4, VIDIOCGAUDIO, &VAR_12); memcpy(&s->audio_saved, &VAR_12, sizeof(VAR_12)); VAR_12.flags &= ~VIDEO_AUDIO_MUTE; ioctl(VAR_4, VIDIOCSAUDIO, &VAR_12); ioctl(VAR_4, VIDIOCGPICT, &VAR_13); #if 0
printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
VAR_13.colour,
VAR_13.hue,
VAR_13.brightness,
VAR_13.contrast,
VAR_13.whiteness); #endif
VAR_13.palette = VAR_9; VAR_13.depth= VAR_10; if (VAR_9 == -1 || (VAR_6 = ioctl(VAR_4, VIDIOCSPICT, &VAR_13)) < 0) { for (VAR_14 = 0; VAR_14 < VAR_15; VAR_14++) { VAR_13.palette = video_formats[VAR_14].palette; VAR_13.depth = video_formats[VAR_14].depth; if (-1 != ioctl(VAR_4, VIDIOCSPICT, &VAR_13))
break; } if (VAR_14 >= VAR_15)
goto fail1; } VAR_6 = ioctl(VAR_4,VIDIOCGMBUF,&s->gb_buffers); if (VAR_6 < 0) { struct video_window VAR_16; int VAR_17; VAR_16.x = 0; VAR_16.y = 0; VAR_16.VAR_2 = VAR_2; VAR_16.VAR_3 = VAR_3; VAR_16.chromakey = -1; VAR_16.flags = 0; ioctl(VAR_4, VIDIOCSWIN, &VAR_16); s->frame_format = VAR_13.palette; VAR_17 = 1; ioctl(VAR_4, VIDIOCCAPTURE, &VAR_17); s->time_frame = av_gettime() * s->VAR_7 / s->VAR_8; s->use_mmap = 0; } else { s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,VAR_4,0); if ((unsigned char*)-1 == s->video_buf) { s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,VAR_4,0); if ((unsigned char*)-1 == s->video_buf) { av_log(VAR_0, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); goto fail; } } s->gb_frame = 0; s->time_frame = av_gettime() * s->VAR_7 / s->VAR_8; s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames; s->gb_buf.VAR_3 = VAR_3; s->gb_buf.VAR_2 = VAR_2; s->gb_buf.format = VAR_13.palette; VAR_6 = ioctl(VAR_4, VIDIOCMCAPTURE, &s->gb_buf); if (VAR_6 < 0) { if (errno != EAGAIN) { fail1:
av_log(VAR_0, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n"); } else { av_log(VAR_0, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n"); } goto fail; } for (VAR_14 = 1; VAR_14 < s->gb_buffers.frames; VAR_14++) { s->gb_buf.frame = VAR_14; ioctl(VAR_4, VIDIOCMCAPTURE, &s->gb_buf); } s->frame_format = s->gb_buf.format; s->use_mmap = 1; } for (VAR_14 = 0; VAR_14 < VAR_15; VAR_14++) { if (s->frame_format == video_formats[VAR_14].palette) { VAR_5 = VAR_2 * VAR_3 * video_formats[VAR_14].depth / 8; st->codec->pix_fmt = video_formats[VAR_14].pix_fmt; break; } } if (VAR_14 >= VAR_15)
goto fail; s->fd = VAR_4; s->VAR_5 = VAR_5; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; st->codec->VAR_2 = VAR_2; st->codec->VAR_3 = VAR_3; st->codec->time_base.den      = VAR_7; st->codec->time_base.num = VAR_8; st->codec->bit_rate = VAR_5 * 1/av_q2d(st->codec->time_base) * 8; return 0; fail:
if (VAR_4 >= 0)
close(VAR_4); av_free(st); return AVERROR(EIO); }