static av_cold int fbdev_write_header(AVFormatContext *h)

{

    FBDevContext *fbdev = h->priv_data;

    enum AVPixelFormat pix_fmt;

    AVStream *st = NULL;

    int ret, flags = O_RDWR;

    int i;



    for (i = 0; i < h->nb_streams; i++) {

        if (h->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

            if (!st) {

                fbdev->index = i;

                st = h->streams[i];

            } else {

                av_log(h, AV_LOG_WARNING, "More than one video stream found. First one is used.\n");

                break;

            }

        }

    }

    if (!st) {

        av_log(h, AV_LOG_ERROR, "No video stream found.\n");

        return AVERROR(EINVAL);

    }



    if ((fbdev->fd = avpriv_open(h->filename, flags)) == -1) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR,

               "Could not open framebuffer device '%s': %s\n",

               h->filename, av_err2str(ret));

        return ret;

    }



    if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "FBIOGET_VSCREENINFO: %s\n", av_err2str(ret));

        goto fail;

    }



    if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "FBIOGET_FSCREENINFO: %s\n", av_err2str(ret));

        goto fail;

    }



    pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);

    if (pix_fmt == AV_PIX_FMT_NONE) {

        ret = AVERROR(EINVAL);

        av_log(h, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n");

        goto fail;

    }



    fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_WRITE, MAP_SHARED, fbdev->fd, 0);

    if (fbdev->data == MAP_FAILED) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "Error in mmap(): %s\n", av_err2str(ret));

        goto fail;

    }



    return 0;

  fail:

    close(fbdev->fd);

    return ret;

}

static av_cold int fbdev_write_header(AVFormatContext *h)

{

    FBDevContext *fbdev = h->priv_data;

    enum AVPixelFormat pix_fmt;

    AVStream *st = NULL;

    int ret, flags = O_RDWR;

    int i;



    for (i = 0; i < h->nb_streams; i++) {

        if (h->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

            if (!st) {

                fbdev->index = i;

                st = h->streams[i];

            } else {

                av_log(h, AV_LOG_WARNING, "More than one video stream found. First one is used.\n");

                break;

            }

        }

    }

    if (!st) {

        av_log(h, AV_LOG_ERROR, "No video stream found.\n");

        return AVERROR(EINVAL);

    }



    if ((fbdev->fd = avpriv_open(h->filename, flags)) == -1) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR,

               "Could not open framebuffer device '%s': %s\n",

               h->filename, av_err2str(ret));

        return ret;

    }



    if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "FBIOGET_VSCREENINFO: %s\n", av_err2str(ret));

        goto fail;

    }



    if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "FBIOGET_FSCREENINFO: %s\n", av_err2str(ret));

        goto fail;

    }



    pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);

    if (pix_fmt == AV_PIX_FMT_NONE) {

        ret = AVERROR(EINVAL);

        av_log(h, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n");

        goto fail;

    }



    fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_WRITE, MAP_SHARED, fbdev->fd, 0);

    if (fbdev->data == MAP_FAILED) {

        ret = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "Error in mmap(): %s\n", av_err2str(ret));

        goto fail;

    }



    return 0;

  fail:

    close(fbdev->fd);

    return ret;

}

static av_cold int FUNC_0(AVFormatContext *h)

{

    FBDevContext *fbdev = h->priv_data;

    enum AVPixelFormat VAR_0;

    AVStream *st = NULL;

    int VAR_1, VAR_2 = O_RDWR;

    int VAR_3;



    for (VAR_3 = 0; VAR_3 < h->nb_streams; VAR_3++) {

        if (h->streams[VAR_3]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

            if (!st) {

                fbdev->index = VAR_3;

                st = h->streams[VAR_3];

            } else {

                av_log(h, AV_LOG_WARNING, "More than one video stream found. First one is used.\n");

                break;

            }

        }

    }

    if (!st) {

        av_log(h, AV_LOG_ERROR, "No video stream found.\n");

        return AVERROR(EINVAL);

    }



    if ((fbdev->fd = avpriv_open(h->filename, VAR_2)) == -1) {

        VAR_1 = AVERROR(errno);

        av_log(h, AV_LOG_ERROR,

               "Could not open framebuffer device '%s': %s\n",

               h->filename, av_err2str(VAR_1));

        return VAR_1;

    }



    if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) {

        VAR_1 = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "FBIOGET_VSCREENINFO: %s\n", av_err2str(VAR_1));

        goto fail;

    }



    if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) {

        VAR_1 = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "FBIOGET_FSCREENINFO: %s\n", av_err2str(VAR_1));

        goto fail;

    }



    VAR_0 = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);

    if (VAR_0 == AV_PIX_FMT_NONE) {

        VAR_1 = AVERROR(EINVAL);

        av_log(h, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n");

        goto fail;

    }



    fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_WRITE, MAP_SHARED, fbdev->fd, 0);

    if (fbdev->data == MAP_FAILED) {

        VAR_1 = AVERROR(errno);

        av_log(h, AV_LOG_ERROR, "Error in mmap(): %s\n", av_err2str(VAR_1));

        goto fail;

    }



    return 0;

  fail:

    close(fbdev->fd);

    return VAR_1;

}

static av_cold int FUNC_0(AVFormatContext *h)
{ FBDevContext *fbdev = h->priv_data; enum AVPixelFormat VAR_0; AVStream *st = NULL; int VAR_1, VAR_2 = O_RDWR; int VAR_3; for (VAR_3 = 0; VAR_3 < h->nb_streams; VAR_3++) { if (h->streams[VAR_3]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (!st) { fbdev->index = VAR_3; st = h->streams[VAR_3]; } else { av_log(h, AV_LOG_WARNING, "More than one video stream found. First one is used.\n"); break; } } } if (!st) { av_log(h, AV_LOG_ERROR, "No video stream found.\n"); return AVERROR(EINVAL); } if ((fbdev->fd = avpriv_open(h->filename, VAR_2)) == -1) { VAR_1 = AVERROR(errno); av_log(h, AV_LOG_ERROR,
"Could not open framebuffer device '%s': %s\n",
h->filename, av_err2str(VAR_1)); return VAR_1; } if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) { VAR_1 = AVERROR(errno); av_log(h, AV_LOG_ERROR, "FBIOGET_VSCREENINFO: %s\n", av_err2str(VAR_1)); goto fail; } if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) { VAR_1 = AVERROR(errno); av_log(h, AV_LOG_ERROR, "FBIOGET_FSCREENINFO: %s\n", av_err2str(VAR_1)); goto fail; } VAR_0 = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo); if (VAR_0 == AV_PIX_FMT_NONE) { VAR_1 = AVERROR(EINVAL); av_log(h, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n"); goto fail; } fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_WRITE, MAP_SHARED, fbdev->fd, 0); if (fbdev->data == MAP_FAILED) { VAR_1 = AVERROR(errno); av_log(h, AV_LOG_ERROR, "Error in mmap(): %s\n", av_err2str(VAR_1)); goto fail; } return 0; fail:
close(fbdev->fd); return VAR_1; }