static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)

{

    Picture *pic = NULL;

    int64_t pts;

    int i, display_picture_number = 0, ret;

    int encoding_delay = s->max_b_frames ? s->max_b_frames

                                         : (s->low_delay ? 0 : 1);

    int flush_offset = 1;

    int direct = 1;



    if (pic_arg) {

        pts = pic_arg->pts;

        display_picture_number = s->input_picture_number++;



        if (pts != AV_NOPTS_VALUE) {

            if (s->user_specified_pts != AV_NOPTS_VALUE) {

                int64_t last = s->user_specified_pts;



                if (pts <= last) {

                    av_log(s->avctx, AV_LOG_ERROR,

                           "Invalid pts (%"PRId64") <= last (%"PRId64")\n",

                           pts, last);

                    return AVERROR(EINVAL);

                }



                if (!s->low_delay && display_picture_number == 1)

                    s->dts_delta = pts - last;

            }

            s->user_specified_pts = pts;

        } else {

            if (s->user_specified_pts != AV_NOPTS_VALUE) {

                s->user_specified_pts =

                pts = s->user_specified_pts + 1;

                av_log(s->avctx, AV_LOG_INFO,

                       "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",

                       pts);

            } else {

                pts = display_picture_number;

            }

        }



        if (!pic_arg->buf[0] ||

            pic_arg->linesize[0] != s->linesize ||

            pic_arg->linesize[1] != s->uvlinesize ||

            pic_arg->linesize[2] != s->uvlinesize)

            direct = 0;

        if ((s->width & 15) || (s->height & 15))

            direct = 0;

        if (((intptr_t)(pic_arg->data[0])) & (STRIDE_ALIGN-1))

            direct = 0;

        if (s->linesize & (STRIDE_ALIGN-1))

            direct = 0;



        ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0],

                pic_arg->linesize[1], s->linesize, s->uvlinesize);



        i = ff_find_unused_picture(s->avctx, s->picture, direct);

        if (i < 0)

            return i;



        pic = &s->picture[i];

        pic->reference = 3;



        if (direct) {

            if ((ret = av_frame_ref(pic->f, pic_arg)) < 0)

                return ret;

        }

        ret = alloc_picture(s, pic, direct);

        if (ret < 0)

            return ret;



        if (!direct) {

            if (pic->f->data[0] + INPLACE_OFFSET == pic_arg->data[0] &&

                pic->f->data[1] + INPLACE_OFFSET == pic_arg->data[1] &&

                pic->f->data[2] + INPLACE_OFFSET == pic_arg->data[2]) {

                // empty

            } else {

                int h_chroma_shift, v_chroma_shift;

                av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,

                                                 &h_chroma_shift,

                                                 &v_chroma_shift);



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

                    int src_stride = pic_arg->linesize[i];

                    int dst_stride = i ? s->uvlinesize : s->linesize;

                    int h_shift = i ? h_chroma_shift : 0;

                    int v_shift = i ? v_chroma_shift : 0;

                    int w = s->width  >> h_shift;

                    int h = s->height >> v_shift;

                    uint8_t *src = pic_arg->data[i];

                    uint8_t *dst = pic->f->data[i];

                    int vpad = 16;



                    if (   s->codec_id == AV_CODEC_ID_MPEG2VIDEO

                        && !s->progressive_sequence

                        && FFALIGN(s->height, 32) - s->height > 16)

                        vpad = 32;



                    if (!s->avctx->rc_buffer_size)

                        dst += INPLACE_OFFSET;



                    if (src_stride == dst_stride)

                        memcpy(dst, src, src_stride * h);

                    else {

                        int h2 = h;

                        uint8_t *dst2 = dst;

                        while (h2--) {

                            memcpy(dst2, src, w);

                            dst2 += dst_stride;

                            src += src_stride;

                        }

                    }

                    if ((s->width & 15) || (s->height & (vpad-1))) {

                        s->mpvencdsp.draw_edges(dst, dst_stride,

                                                w, h,

                                                16 >> h_shift,

                                                vpad >> v_shift,

                                                EDGE_BOTTOM);

                    }

                }


            }

        }

        ret = av_frame_copy_props(pic->f, pic_arg);

        if (ret < 0)

            return ret;



        pic->f->display_picture_number = display_picture_number;

        pic->f->pts = pts; // we set this here to avoid modifying pic_arg

    } else {

        /* Flushing: When we have not received enough input frames,

         * ensure s->input_picture[0] contains the first picture */

        for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)

            if (s->input_picture[flush_offset])

                break;



        if (flush_offset <= 1)

            flush_offset = 1;

        else

            encoding_delay = encoding_delay - flush_offset + 1;

    }



    /* shift buffer entries */

    for (i = flush_offset; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++)

        s->input_picture[i - flush_offset] = s->input_picture[i];



    s->input_picture[encoding_delay] = (Picture*) pic;



    return 0;

}
static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)

{

    Picture *pic = NULL;

    int64_t pts;

    int i, display_picture_number = 0, ret;

    int encoding_delay = s->max_b_frames ? s->max_b_frames

                                         : (s->low_delay ? 0 : 1);

    int flush_offset = 1;

    int direct = 1;



    if (pic_arg) {

        pts = pic_arg->pts;

        display_picture_number = s->input_picture_number++;



        if (pts != AV_NOPTS_VALUE) {

            if (s->user_specified_pts != AV_NOPTS_VALUE) {

                int64_t last = s->user_specified_pts;



                if (pts <= last) {

                    av_log(s->avctx, AV_LOG_ERROR,

                           "Invalid pts (%"PRId64") <= last (%"PRId64")\n",

                           pts, last);

                    return AVERROR(EINVAL);

                }



                if (!s->low_delay && display_picture_number == 1)

                    s->dts_delta = pts - last;

            }

            s->user_specified_pts = pts;

        } else {

            if (s->user_specified_pts != AV_NOPTS_VALUE) {

                s->user_specified_pts =

                pts = s->user_specified_pts + 1;

                av_log(s->avctx, AV_LOG_INFO,

                       "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",

                       pts);

            } else {

                pts = display_picture_number;

            }

        }



        if (!pic_arg->buf[0] ||

            pic_arg->linesize[0] != s->linesize ||

            pic_arg->linesize[1] != s->uvlinesize ||

            pic_arg->linesize[2] != s->uvlinesize)

            direct = 0;

        if ((s->width & 15) || (s->height & 15))

            direct = 0;

        if (((intptr_t)(pic_arg->data[0])) & (STRIDE_ALIGN-1))

            direct = 0;

        if (s->linesize & (STRIDE_ALIGN-1))

            direct = 0;



        ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0],

                pic_arg->linesize[1], s->linesize, s->uvlinesize);



        i = ff_find_unused_picture(s->avctx, s->picture, direct);

        if (i < 0)

            return i;



        pic = &s->picture[i];

        pic->reference = 3;



        if (direct) {

            if ((ret = av_frame_ref(pic->f, pic_arg)) < 0)

                return ret;

        }

        ret = alloc_picture(s, pic, direct);

        if (ret < 0)

            return ret;



        if (!direct) {

            if (pic->f->data[0] + INPLACE_OFFSET == pic_arg->data[0] &&

                pic->f->data[1] + INPLACE_OFFSET == pic_arg->data[1] &&

                pic->f->data[2] + INPLACE_OFFSET == pic_arg->data[2]) {

                

            } else {

                int h_chroma_shift, v_chroma_shift;

                av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,

                                                 &h_chroma_shift,

                                                 &v_chroma_shift);



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

                    int src_stride = pic_arg->linesize[i];

                    int dst_stride = i ? s->uvlinesize : s->linesize;

                    int h_shift = i ? h_chroma_shift : 0;

                    int v_shift = i ? v_chroma_shift : 0;

                    int w = s->width  >> h_shift;

                    int h = s->height >> v_shift;

                    uint8_t *src = pic_arg->data[i];

                    uint8_t *dst = pic->f->data[i];

                    int vpad = 16;



                    if (   s->codec_id == AV_CODEC_ID_MPEG2VIDEO

                        && !s->progressive_sequence

                        && FFALIGN(s->height, 32) - s->height > 16)

                        vpad = 32;



                    if (!s->avctx->rc_buffer_size)

                        dst += INPLACE_OFFSET;



                    if (src_stride == dst_stride)

                        memcpy(dst, src, src_stride * h);

                    else {

                        int h2 = h;

                        uint8_t *dst2 = dst;

                        while (h2--) {

                            memcpy(dst2, src, w);

                            dst2 += dst_stride;

                            src += src_stride;

                        }

                    }

                    if ((s->width & 15) || (s->height & (vpad-1))) {

                        s->mpvencdsp.draw_edges(dst, dst_stride,

                                                w, h,

                                                16 >> h_shift,

                                                vpad >> v_shift,

                                                EDGE_BOTTOM);

                    }

                }


            }

        }

        ret = av_frame_copy_props(pic->f, pic_arg);

        if (ret < 0)

            return ret;



        pic->f->display_picture_number = display_picture_number;

        pic->f->pts = pts; 

    } else {

        



        for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)

            if (s->input_picture[flush_offset])

                break;



        if (flush_offset <= 1)

            flush_offset = 1;

        else

            encoding_delay = encoding_delay - flush_offset + 1;

    }



    

    for (i = flush_offset; i < MAX_PICTURE_COUNT ; i++)

        s->input_picture[i - flush_offset] = s->input_picture[i];



    s->input_picture[encoding_delay] = (Picture*) pic;



    return 0;

}
static int FUNC_0(MpegEncContext *VAR_0, const AVFrame *VAR_1)

{

    Picture *pic = NULL;

    int64_t pts;

    int VAR_2, VAR_3 = 0, VAR_4;

    int VAR_5 = VAR_0->max_b_frames ? VAR_0->max_b_frames

                                         : (VAR_0->low_delay ? 0 : 1);

    int VAR_6 = 1;

    int VAR_7 = 1;



    if (VAR_1) {

        pts = VAR_1->pts;

        VAR_3 = VAR_0->input_picture_number++;



        if (pts != AV_NOPTS_VALUE) {

            if (VAR_0->user_specified_pts != AV_NOPTS_VALUE) {

                int64_t last = VAR_0->user_specified_pts;



                if (pts <= last) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR,

                           "Invalid pts (%"PRId64") <= last (%"PRId64")\n",

                           pts, last);

                    return AVERROR(EINVAL);

                }



                if (!VAR_0->low_delay && VAR_3 == 1)

                    VAR_0->dts_delta = pts - last;

            }

            VAR_0->user_specified_pts = pts;

        } else {

            if (VAR_0->user_specified_pts != AV_NOPTS_VALUE) {

                VAR_0->user_specified_pts =

                pts = VAR_0->user_specified_pts + 1;

                av_log(VAR_0->avctx, AV_LOG_INFO,

                       "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",

                       pts);

            } else {

                pts = VAR_3;

            }

        }



        if (!VAR_1->buf[0] ||

            VAR_1->linesize[0] != VAR_0->linesize ||

            VAR_1->linesize[1] != VAR_0->uvlinesize ||

            VAR_1->linesize[2] != VAR_0->uvlinesize)

            VAR_7 = 0;

        if ((VAR_0->width & 15) || (VAR_0->height & 15))

            VAR_7 = 0;

        if (((intptr_t)(VAR_1->data[0])) & (STRIDE_ALIGN-1))

            VAR_7 = 0;

        if (VAR_0->linesize & (STRIDE_ALIGN-1))

            VAR_7 = 0;



        ff_dlog(VAR_0->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", VAR_1->linesize[0],

                VAR_1->linesize[1], VAR_0->linesize, VAR_0->uvlinesize);



        VAR_2 = ff_find_unused_picture(VAR_0->avctx, VAR_0->picture, VAR_7);

        if (VAR_2 < 0)

            return VAR_2;



        pic = &VAR_0->picture[VAR_2];

        pic->reference = 3;



        if (VAR_7) {

            if ((VAR_4 = av_frame_ref(pic->f, VAR_1)) < 0)

                return VAR_4;

        }

        VAR_4 = alloc_picture(VAR_0, pic, VAR_7);

        if (VAR_4 < 0)

            return VAR_4;



        if (!VAR_7) {

            if (pic->f->data[0] + INPLACE_OFFSET == VAR_1->data[0] &&

                pic->f->data[1] + INPLACE_OFFSET == VAR_1->data[1] &&

                pic->f->data[2] + INPLACE_OFFSET == VAR_1->data[2]) {

                

            } else {

                int VAR_8, VAR_9;

                av_pix_fmt_get_chroma_sub_sample(VAR_0->avctx->pix_fmt,

                                                 &VAR_8,

                                                 &VAR_9);



                for (VAR_2 = 0; VAR_2 < 3; VAR_2++) {

                    int VAR_10 = VAR_1->linesize[VAR_2];

                    int VAR_11 = VAR_2 ? VAR_0->uvlinesize : VAR_0->linesize;

                    int VAR_12 = VAR_2 ? VAR_8 : 0;

                    int VAR_13 = VAR_2 ? VAR_9 : 0;

                    int VAR_14 = VAR_0->width  >> VAR_12;

                    int VAR_15 = VAR_0->height >> VAR_13;

                    uint8_t *src = VAR_1->data[VAR_2];

                    uint8_t *dst = pic->f->data[VAR_2];

                    int VAR_16 = 16;



                    if (   VAR_0->codec_id == AV_CODEC_ID_MPEG2VIDEO

                        && !VAR_0->progressive_sequence

                        && FFALIGN(VAR_0->height, 32) - VAR_0->height > 16)

                        VAR_16 = 32;



                    if (!VAR_0->avctx->rc_buffer_size)

                        dst += INPLACE_OFFSET;



                    if (VAR_10 == VAR_11)

                        memcpy(dst, src, VAR_10 * VAR_15);

                    else {

                        int VAR_17 = VAR_15;

                        uint8_t *dst2 = dst;

                        while (VAR_17--) {

                            memcpy(dst2, src, VAR_14);

                            dst2 += VAR_11;

                            src += VAR_10;

                        }

                    }

                    if ((VAR_0->width & 15) || (VAR_0->height & (VAR_16-1))) {

                        VAR_0->mpvencdsp.draw_edges(dst, VAR_11,

                                                VAR_14, VAR_15,

                                                16 >> VAR_12,

                                                VAR_16 >> VAR_13,

                                                EDGE_BOTTOM);

                    }

                }


            }

        }

        VAR_4 = av_frame_copy_props(pic->f, VAR_1);

        if (VAR_4 < 0)

            return VAR_4;



        pic->f->VAR_3 = VAR_3;

        pic->f->pts = pts; 

    } else {

        



        for (VAR_6 = 0; VAR_6 < VAR_5 + 1; VAR_6++)

            if (VAR_0->input_picture[VAR_6])

                break;



        if (VAR_6 <= 1)

            VAR_6 = 1;

        else

            VAR_5 = VAR_5 - VAR_6 + 1;

    }



    

    for (VAR_2 = VAR_6; VAR_2 < MAX_PICTURE_COUNT ; VAR_2++)

        VAR_0->input_picture[VAR_2 - VAR_6] = VAR_0->input_picture[VAR_2];



    VAR_0->input_picture[VAR_5] = (Picture*) pic;



    return 0;

}
static int FUNC_0(MpegEncContext *VAR_0, const AVFrame *VAR_1)
{ Picture *pic = NULL; int64_t pts; int VAR_2, VAR_3 = 0, VAR_4; int VAR_5 = VAR_0->max_b_frames ? VAR_0->max_b_frames
: (VAR_0->low_delay ? 0 : 1); int VAR_6 = 1; int VAR_7 = 1; if (VAR_1) { pts = VAR_1->pts; VAR_3 = VAR_0->input_picture_number++; if (pts != AV_NOPTS_VALUE) { if (VAR_0->user_specified_pts != AV_NOPTS_VALUE) { int64_t last = VAR_0->user_specified_pts; if (pts <= last) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Invalid pts (%"PRId64") <= last (%"PRId64")\n",
pts, last); return AVERROR(EINVAL); } if (!VAR_0->low_delay && VAR_3 == 1)
VAR_0->dts_delta = pts - last; } VAR_0->user_specified_pts = pts; } else { if (VAR_0->user_specified_pts != AV_NOPTS_VALUE) { VAR_0->user_specified_pts =
pts = VAR_0->user_specified_pts + 1; av_log(VAR_0->avctx, AV_LOG_INFO,
"Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",
pts); } else { pts = VAR_3; } } if (!VAR_1->buf[0] ||
VAR_1->linesize[0] != VAR_0->linesize ||
VAR_1->linesize[1] != VAR_0->uvlinesize ||
VAR_1->linesize[2] != VAR_0->uvlinesize)
VAR_7 = 0; if ((VAR_0->width & 15) || (VAR_0->height & 15))
VAR_7 = 0; if (((intptr_t)(VAR_1->data[0])) & (STRIDE_ALIGN-1))
VAR_7 = 0; if (VAR_0->linesize & (STRIDE_ALIGN-1))
VAR_7 = 0; ff_dlog(VAR_0->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", VAR_1->linesize[0],
VAR_1->linesize[1], VAR_0->linesize, VAR_0->uvlinesize); VAR_2 = ff_find_unused_picture(VAR_0->avctx, VAR_0->picture, VAR_7); if (VAR_2 < 0)
return VAR_2; pic = &VAR_0->picture[VAR_2]; pic->reference = 3; if (VAR_7) { if ((VAR_4 = av_frame_ref(pic->f, VAR_1)) < 0)
return VAR_4; } VAR_4 = alloc_picture(VAR_0, pic, VAR_7); if (VAR_4 < 0)
return VAR_4; if (!VAR_7) { if (pic->f->data[0] + INPLACE_OFFSET == VAR_1->data[0] &&
pic->f->data[1] + INPLACE_OFFSET == VAR_1->data[1] &&
pic->f->data[2] + INPLACE_OFFSET == VAR_1->data[2]) { } else { int VAR_8, VAR_9; av_pix_fmt_get_chroma_sub_sample(VAR_0->avctx->pix_fmt,
&VAR_8,
&VAR_9); for (VAR_2 = 0; VAR_2 < 3; VAR_2++) { int VAR_10 = VAR_1->linesize[VAR_2]; int VAR_11 = VAR_2 ? VAR_0->uvlinesize : VAR_0->linesize; int VAR_12 = VAR_2 ? VAR_8 : 0; int VAR_13 = VAR_2 ? VAR_9 : 0; int VAR_14 = VAR_0->width  >> VAR_12; int VAR_15 = VAR_0->height >> VAR_13; uint8_t *src = VAR_1->data[VAR_2]; uint8_t *dst = pic->f->data[VAR_2]; int VAR_16 = 16; if (   VAR_0->codec_id == AV_CODEC_ID_MPEG2VIDEO
&& !VAR_0->progressive_sequence
&& FFALIGN(VAR_0->height, 32) - VAR_0->height > 16)
VAR_16 = 32; if (!VAR_0->avctx->rc_buffer_size)
dst += INPLACE_OFFSET; if (VAR_10 == VAR_11)
memcpy(dst, src, VAR_10 * VAR_15); else { int VAR_17 = VAR_15; uint8_t *dst2 = dst; while (VAR_17--) { memcpy(dst2, src, VAR_14); dst2 += VAR_11; src += VAR_10; } } if ((VAR_0->width & 15) || (VAR_0->height & (VAR_16-1))) { VAR_0->mpvencdsp.draw_edges(dst, VAR_11,
VAR_14, VAR_15,
16 >> VAR_12,
VAR_16 >> VAR_13,
EDGE_BOTTOM); } } } } VAR_4 = av_frame_copy_props(pic->f, VAR_1); if (VAR_4 < 0)
return VAR_4; pic->f->VAR_3 = VAR_3; pic->f->pts = pts; } else { for (VAR_6 = 0; VAR_6 < VAR_5 + 1; VAR_6++) if (VAR_0->input_picture[VAR_6])
break; if (VAR_6 <= 1)
VAR_6 = 1; else
VAR_5 = VAR_5 - VAR_6 + 1; } for (VAR_2 = VAR_6; VAR_2 < MAX_PICTURE_COUNT ; VAR_2++) VAR_0->input_picture[VAR_2 - VAR_6] = VAR_0->input_picture[VAR_2]; VAR_0->input_picture[VAR_5] = (Picture*) pic; return 0; }