static int fbdev_write_packet(AVFormatContext *h, AVPacket *pkt)

{

    FBDevContext *fbdev = h->priv_data;

    uint8_t *pin, *pout;

    enum AVPixelFormat fb_pix_fmt;

    int disp_height;

    int bytes_to_copy;

    AVCodecContext *codec_ctx = h->streams[fbdev->index]->codec;

    enum AVPixelFormat video_pix_fmt = codec_ctx->pix_fmt;

    int video_width = codec_ctx->width;

    int video_height = codec_ctx->height;

    int bytes_per_pixel = ((codec_ctx->bits_per_coded_sample + 7) >> 3);

    int src_line_size = video_width * bytes_per_pixel;

    int i;



    if (fbdev->index != pkt->stream_index)

        return 0;



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

        av_log(h, AV_LOG_WARNING,

               "Error refreshing variable info: %s\n", av_err2str(AVERROR(errno)));



    fb_pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);



    if (fb_pix_fmt != video_pix_fmt) {

        av_log(h, AV_LOG_ERROR, "Pixel format %s is not supported, use %s\n",

               av_get_pix_fmt_name(video_pix_fmt), av_get_pix_fmt_name(fb_pix_fmt));

        return AVERROR(EINVAL);

    }



    disp_height = FFMIN(fbdev->varinfo.yres, video_height);

    bytes_to_copy = FFMIN(fbdev->varinfo.xres, video_width) * bytes_per_pixel;



    pin  = pkt->data;

    pout = fbdev->data +

           bytes_per_pixel * fbdev->varinfo.xoffset +

           fbdev->varinfo.yoffset * fbdev->fixinfo.line_length;



    if (fbdev->xoffset) {

        if (fbdev->xoffset < 0) {

            if (-fbdev->xoffset >= video_width) //nothing to display

                return 0;

            bytes_to_copy += fbdev->xoffset * bytes_per_pixel;

            pin -= fbdev->xoffset * bytes_per_pixel;

        } else {

            int diff = (video_width + fbdev->xoffset) - fbdev->varinfo.xres;

            if (diff > 0) {

                if (diff >= video_width) //nothing to display

                    return 0;

                bytes_to_copy -= diff * bytes_per_pixel;

            }

            pout += bytes_per_pixel * fbdev->xoffset;

        }

    }



    if (fbdev->yoffset) {

        if (fbdev->yoffset < 0) {

            if (-fbdev->yoffset >= video_height) //nothing to display

                return 0;

            disp_height += fbdev->yoffset;

            pin -= fbdev->yoffset * src_line_size;

        } else {

            int diff = (video_height + fbdev->yoffset) - fbdev->varinfo.yres;

            if (diff > 0) {

                if (diff >= video_height) //nothing to display

                    return 0;

                disp_height -= diff;

            }

            pout += fbdev->yoffset * fbdev->fixinfo.line_length;

        }

    }



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

        memcpy(pout, pin, bytes_to_copy);

        pout += fbdev->fixinfo.line_length;

        pin  += src_line_size;

    }



    return 0;

}

static int fbdev_write_packet(AVFormatContext *h, AVPacket *pkt)

{

    FBDevContext *fbdev = h->priv_data;

    uint8_t *pin, *pout;

    enum AVPixelFormat fb_pix_fmt;

    int disp_height;

    int bytes_to_copy;

    AVCodecContext *codec_ctx = h->streams[fbdev->index]->codec;

    enum AVPixelFormat video_pix_fmt = codec_ctx->pix_fmt;

    int video_width = codec_ctx->width;

    int video_height = codec_ctx->height;

    int bytes_per_pixel = ((codec_ctx->bits_per_coded_sample + 7) >> 3);

    int src_line_size = video_width * bytes_per_pixel;

    int i;



    if (fbdev->index != pkt->stream_index)

        return 0;



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

        av_log(h, AV_LOG_WARNING,

               "Error refreshing variable info: %s\n", av_err2str(AVERROR(errno)));



    fb_pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);



    if (fb_pix_fmt != video_pix_fmt) {

        av_log(h, AV_LOG_ERROR, "Pixel format %s is not supported, use %s\n",

               av_get_pix_fmt_name(video_pix_fmt), av_get_pix_fmt_name(fb_pix_fmt));

        return AVERROR(EINVAL);

    }



    disp_height = FFMIN(fbdev->varinfo.yres, video_height);

    bytes_to_copy = FFMIN(fbdev->varinfo.xres, video_width) * bytes_per_pixel;



    pin  = pkt->data;

    pout = fbdev->data +

           bytes_per_pixel * fbdev->varinfo.xoffset +

           fbdev->varinfo.yoffset * fbdev->fixinfo.line_length;



    if (fbdev->xoffset) {

        if (fbdev->xoffset < 0) {

            if (-fbdev->xoffset >= video_width) 

                return 0;

            bytes_to_copy += fbdev->xoffset * bytes_per_pixel;

            pin -= fbdev->xoffset * bytes_per_pixel;

        } else {

            int diff = (video_width + fbdev->xoffset) - fbdev->varinfo.xres;

            if (diff > 0) {

                if (diff >= video_width) 

                    return 0;

                bytes_to_copy -= diff * bytes_per_pixel;

            }

            pout += bytes_per_pixel * fbdev->xoffset;

        }

    }



    if (fbdev->yoffset) {

        if (fbdev->yoffset < 0) {

            if (-fbdev->yoffset >= video_height) 

                return 0;

            disp_height += fbdev->yoffset;

            pin -= fbdev->yoffset * src_line_size;

        } else {

            int diff = (video_height + fbdev->yoffset) - fbdev->varinfo.yres;

            if (diff > 0) {

                if (diff >= video_height) 

                    return 0;

                disp_height -= diff;

            }

            pout += fbdev->yoffset * fbdev->fixinfo.line_length;

        }

    }



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

        memcpy(pout, pin, bytes_to_copy);

        pout += fbdev->fixinfo.line_length;

        pin  += src_line_size;

    }



    return 0;

}

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

{

    FBDevContext *fbdev = VAR_0->priv_data;

    uint8_t *pin, *pout;

    enum AVPixelFormat VAR_2;

    int VAR_3;

    int VAR_4;

    AVCodecContext *codec_ctx = VAR_0->streams[fbdev->index]->codec;

    enum AVPixelFormat VAR_5 = codec_ctx->pix_fmt;

    int VAR_6 = codec_ctx->width;

    int VAR_7 = codec_ctx->height;

    int VAR_8 = ((codec_ctx->bits_per_coded_sample + 7) >> 3);

    int VAR_9 = VAR_6 * VAR_8;

    int VAR_10;



    if (fbdev->index != VAR_1->stream_index)

        return 0;



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

        av_log(VAR_0, AV_LOG_WARNING,

               "Error refreshing variable info: %s\n", av_err2str(AVERROR(errno)));



    VAR_2 = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);



    if (VAR_2 != VAR_5) {

        av_log(VAR_0, AV_LOG_ERROR, "Pixel format %s is not supported, use %s\n",

               av_get_pix_fmt_name(VAR_5), av_get_pix_fmt_name(VAR_2));

        return AVERROR(EINVAL);

    }



    VAR_3 = FFMIN(fbdev->varinfo.yres, VAR_7);

    VAR_4 = FFMIN(fbdev->varinfo.xres, VAR_6) * VAR_8;



    pin  = VAR_1->data;

    pout = fbdev->data +

           VAR_8 * fbdev->varinfo.xoffset +

           fbdev->varinfo.yoffset * fbdev->fixinfo.line_length;



    if (fbdev->xoffset) {

        if (fbdev->xoffset < 0) {

            if (-fbdev->xoffset >= VAR_6) 

                return 0;

            VAR_4 += fbdev->xoffset * VAR_8;

            pin -= fbdev->xoffset * VAR_8;

        } else {

            int VAR_12 = (VAR_6 + fbdev->xoffset) - fbdev->varinfo.xres;

            if (VAR_12 > 0) {

                if (VAR_12 >= VAR_6) 

                    return 0;

                VAR_4 -= VAR_12 * VAR_8;

            }

            pout += VAR_8 * fbdev->xoffset;

        }

    }



    if (fbdev->yoffset) {

        if (fbdev->yoffset < 0) {

            if (-fbdev->yoffset >= VAR_7) 

                return 0;

            VAR_3 += fbdev->yoffset;

            pin -= fbdev->yoffset * VAR_9;

        } else {

            int VAR_12 = (VAR_7 + fbdev->yoffset) - fbdev->varinfo.yres;

            if (VAR_12 > 0) {

                if (VAR_12 >= VAR_7) 

                    return 0;

                VAR_3 -= VAR_12;

            }

            pout += fbdev->yoffset * fbdev->fixinfo.line_length;

        }

    }



    for (VAR_10 = 0; VAR_10 < VAR_3; VAR_10++) {

        memcpy(pout, pin, VAR_4);

        pout += fbdev->fixinfo.line_length;

        pin  += VAR_9;

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ FBDevContext *fbdev = VAR_0->priv_data; uint8_t *pin, *pout; enum AVPixelFormat VAR_2; int VAR_3; int VAR_4; AVCodecContext *codec_ctx = VAR_0->streams[fbdev->index]->codec; enum AVPixelFormat VAR_5 = codec_ctx->pix_fmt; int VAR_6 = codec_ctx->width; int VAR_7 = codec_ctx->height; int VAR_8 = ((codec_ctx->bits_per_coded_sample + 7) >> 3); int VAR_9 = VAR_6 * VAR_8; int VAR_10; if (fbdev->index != VAR_1->stream_index)
return 0; if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0)
av_log(VAR_0, AV_LOG_WARNING,
"Error refreshing variable info: %s\n", av_err2str(AVERROR(errno))); VAR_2 = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo); if (VAR_2 != VAR_5) { av_log(VAR_0, AV_LOG_ERROR, "Pixel format %s is not supported, use %s\n",
av_get_pix_fmt_name(VAR_5), av_get_pix_fmt_name(VAR_2)); return AVERROR(EINVAL); } VAR_3 = FFMIN(fbdev->varinfo.yres, VAR_7); VAR_4 = FFMIN(fbdev->varinfo.xres, VAR_6) * VAR_8; pin  = VAR_1->data; pout = fbdev->data +
VAR_8 * fbdev->varinfo.xoffset +
fbdev->varinfo.yoffset * fbdev->fixinfo.line_length; if (fbdev->xoffset) { if (fbdev->xoffset < 0) { if (-fbdev->xoffset >= VAR_6)
return 0; VAR_4 += fbdev->xoffset * VAR_8; pin -= fbdev->xoffset * VAR_8; } else { int VAR_12 = (VAR_6 + fbdev->xoffset) - fbdev->varinfo.xres; if (VAR_12 > 0) { if (VAR_12 >= VAR_6)
return 0; VAR_4 -= VAR_12 * VAR_8; } pout += VAR_8 * fbdev->xoffset; } } if (fbdev->yoffset) { if (fbdev->yoffset < 0) { if (-fbdev->yoffset >= VAR_7)
return 0; VAR_3 += fbdev->yoffset; pin -= fbdev->yoffset * VAR_9; } else { int VAR_12 = (VAR_7 + fbdev->yoffset) - fbdev->varinfo.yres; if (VAR_12 > 0) { if (VAR_12 >= VAR_7)
return 0; VAR_3 -= VAR_12; } pout += fbdev->yoffset * fbdev->fixinfo.line_length; } } for (VAR_10 = 0; VAR_10 < VAR_3; VAR_10++) { memcpy(pout, pin, VAR_4); pout += fbdev->fixinfo.line_length; pin  += VAR_9; } return 0; }