static int select_input_picture(MpegEncContext *s)

{

    int i, ret;



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

        s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];

    s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;



    /* set next picture type & ordering */

    if (!s->reordered_input_picture[0] && s->input_picture[0]) {

        if (/*s->picture_in_gop_number >= s->gop_size ||*/

            !s->next_picture_ptr || s->intra_only) {

            s->reordered_input_picture[0] = s->input_picture[0];

            s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;

            s->reordered_input_picture[0]->f->coded_picture_number =

                s->coded_picture_number++;

        } else {

            int b_frames;



            if (s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor) {

                if (s->picture_in_gop_number < s->gop_size &&

                    skip_check(s, s->input_picture[0], s->next_picture_ptr)) {

                    // FIXME check that te gop check above is +-1 correct

                    av_frame_unref(s->input_picture[0]->f);



                    emms_c();

                    ff_vbv_update(s, 0);



                    goto no_output_pic;

                }

            }



            if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {

                for (i = 0; i < s->max_b_frames + 1; i++) {

                    int pict_num = s->input_picture[0]->f->display_picture_number + i;



                    if (pict_num >= s->rc_context.num_entries)

                        break;

                    if (!s->input_picture[i]) {

                        s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P;

                        break;

                    }



                    s->input_picture[i]->f->pict_type =

                        s->rc_context.entry[pict_num].new_pict_type;

                }

            }



            if (s->avctx->b_frame_strategy == 0) {

                b_frames = s->max_b_frames;

                while (b_frames && !s->input_picture[b_frames])

                    b_frames--;

            } else if (s->avctx->b_frame_strategy == 1) {

                for (i = 1; i < s->max_b_frames + 1; i++) {

                    if (s->input_picture[i] &&

                        s->input_picture[i]->b_frame_score == 0) {

                        s->input_picture[i]->b_frame_score =

                            get_intra_count(s,

                                            s->input_picture[i    ]->f->data[0],

                                            s->input_picture[i - 1]->f->data[0],

                                            s->linesize) + 1;

                    }

                }

                for (i = 0; i < s->max_b_frames + 1; i++) {

                    if (!s->input_picture[i] ||

                        s->input_picture[i]->b_frame_score - 1 >

                            s->mb_num / s->avctx->b_sensitivity)

                        break;

                }



                b_frames = FFMAX(0, i - 1);



                /* reset scores */

                for (i = 0; i < b_frames + 1; i++) {

                    s->input_picture[i]->b_frame_score = 0;

                }

            } else if (s->avctx->b_frame_strategy == 2) {

                b_frames = estimate_best_b_count(s);

            } else {

                av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");

                b_frames = 0;

            }



            emms_c();



            for (i = b_frames - 1; i >= 0; i--) {

                int type = s->input_picture[i]->f->pict_type;

                if (type && type != AV_PICTURE_TYPE_B)

                    b_frames = i;

            }

            if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B &&

                b_frames == s->max_b_frames) {

                av_log(s->avctx, AV_LOG_ERROR,

                       "warning, too many b frames in a row\n");

            }



            if (s->picture_in_gop_number + b_frames >= s->gop_size) {

                if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&

                    s->gop_size > s->picture_in_gop_number) {

                    b_frames = s->gop_size - s->picture_in_gop_number - 1;

                } else {

                    if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)

                        b_frames = 0;

                    s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I;

                }

            }



            if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames &&

                s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I)

                b_frames--;



            s->reordered_input_picture[0] = s->input_picture[b_frames];

            if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)

                s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;

            s->reordered_input_picture[0]->f->coded_picture_number =

                s->coded_picture_number++;

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

                s->reordered_input_picture[i + 1] = s->input_picture[i];

                s->reordered_input_picture[i + 1]->f->pict_type =

                    AV_PICTURE_TYPE_B;

                s->reordered_input_picture[i + 1]->f->coded_picture_number =

                    s->coded_picture_number++;

            }

        }

    }

no_output_pic:

    ff_mpeg_unref_picture(s->avctx, &s->new_picture);



    if (s->reordered_input_picture[0]) {

        s->reordered_input_picture[0]->reference =

           s->reordered_input_picture[0]->f->pict_type !=

               AV_PICTURE_TYPE_B ? 3 : 0;



        if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture, s->reordered_input_picture[0])))

            return ret;



        if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {

            // input is a shared pix, so we can't modifiy it -> alloc a new

            // one & ensure that the shared one is reuseable



            Picture *pic;

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

            if (i < 0)

                return i;

            pic = &s->picture[i];



            pic->reference = s->reordered_input_picture[0]->reference;

            if (alloc_picture(s, pic, 0) < 0) {

                return -1;

            }



            ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f);

            if (ret < 0)

                return ret;



            /* mark us unused / free shared pic */

            av_frame_unref(s->reordered_input_picture[0]->f);

            s->reordered_input_picture[0]->shared = 0;



            s->current_picture_ptr = pic;

        } else {

            // input is not a shared pix -> reuse buffer for current_pix

            s->current_picture_ptr = s->reordered_input_picture[0];

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

                s->new_picture.f->data[i] += INPLACE_OFFSET;

            }

        }

        ff_mpeg_unref_picture(s->avctx, &s->current_picture);

        if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,

                                       s->current_picture_ptr)) < 0)

            return ret;



        s->picture_number = s->new_picture.f->display_picture_number;

    }

    return 0;

}

static int select_input_picture(MpegEncContext *s)

{

    int i, ret;



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

        s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];

    s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;



    

    if (!s->reordered_input_picture[0] && s->input_picture[0]) {

        if (

            !s->next_picture_ptr || s->intra_only) {

            s->reordered_input_picture[0] = s->input_picture[0];

            s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;

            s->reordered_input_picture[0]->f->coded_picture_number =

                s->coded_picture_number++;

        } else {

            int b_frames;



            if (s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor) {

                if (s->picture_in_gop_number < s->gop_size &&

                    skip_check(s, s->input_picture[0], s->next_picture_ptr)) {

                    

                    av_frame_unref(s->input_picture[0]->f);



                    emms_c();

                    ff_vbv_update(s, 0);



                    goto no_output_pic;

                }

            }



            if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {

                for (i = 0; i < s->max_b_frames + 1; i++) {

                    int pict_num = s->input_picture[0]->f->display_picture_number + i;



                    if (pict_num >= s->rc_context.num_entries)

                        break;

                    if (!s->input_picture[i]) {

                        s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P;

                        break;

                    }



                    s->input_picture[i]->f->pict_type =

                        s->rc_context.entry[pict_num].new_pict_type;

                }

            }



            if (s->avctx->b_frame_strategy == 0) {

                b_frames = s->max_b_frames;

                while (b_frames && !s->input_picture[b_frames])

                    b_frames--;

            } else if (s->avctx->b_frame_strategy == 1) {

                for (i = 1; i < s->max_b_frames + 1; i++) {

                    if (s->input_picture[i] &&

                        s->input_picture[i]->b_frame_score == 0) {

                        s->input_picture[i]->b_frame_score =

                            get_intra_count(s,

                                            s->input_picture[i    ]->f->data[0],

                                            s->input_picture[i - 1]->f->data[0],

                                            s->linesize) + 1;

                    }

                }

                for (i = 0; i < s->max_b_frames + 1; i++) {

                    if (!s->input_picture[i] ||

                        s->input_picture[i]->b_frame_score - 1 >

                            s->mb_num / s->avctx->b_sensitivity)

                        break;

                }



                b_frames = FFMAX(0, i - 1);



                

                for (i = 0; i < b_frames + 1; i++) {

                    s->input_picture[i]->b_frame_score = 0;

                }

            } else if (s->avctx->b_frame_strategy == 2) {

                b_frames = estimate_best_b_count(s);

            } else {

                av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");

                b_frames = 0;

            }



            emms_c();



            for (i = b_frames - 1; i >= 0; i--) {

                int type = s->input_picture[i]->f->pict_type;

                if (type && type != AV_PICTURE_TYPE_B)

                    b_frames = i;

            }

            if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B &&

                b_frames == s->max_b_frames) {

                av_log(s->avctx, AV_LOG_ERROR,

                       "warning, too many b frames in a row\n");

            }



            if (s->picture_in_gop_number + b_frames >= s->gop_size) {

                if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&

                    s->gop_size > s->picture_in_gop_number) {

                    b_frames = s->gop_size - s->picture_in_gop_number - 1;

                } else {

                    if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)

                        b_frames = 0;

                    s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I;

                }

            }



            if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames &&

                s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I)

                b_frames--;



            s->reordered_input_picture[0] = s->input_picture[b_frames];

            if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)

                s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;

            s->reordered_input_picture[0]->f->coded_picture_number =

                s->coded_picture_number++;

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

                s->reordered_input_picture[i + 1] = s->input_picture[i];

                s->reordered_input_picture[i + 1]->f->pict_type =

                    AV_PICTURE_TYPE_B;

                s->reordered_input_picture[i + 1]->f->coded_picture_number =

                    s->coded_picture_number++;

            }

        }

    }

no_output_pic:

    ff_mpeg_unref_picture(s->avctx, &s->new_picture);



    if (s->reordered_input_picture[0]) {

        s->reordered_input_picture[0]->reference =

           s->reordered_input_picture[0]->f->pict_type !=

               AV_PICTURE_TYPE_B ? 3 : 0;



        if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture, s->reordered_input_picture[0])))

            return ret;



        if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {

            

            



            Picture *pic;

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

            if (i < 0)

                return i;

            pic = &s->picture[i];



            pic->reference = s->reordered_input_picture[0]->reference;

            if (alloc_picture(s, pic, 0) < 0) {

                return -1;

            }



            ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f);

            if (ret < 0)

                return ret;



            

            av_frame_unref(s->reordered_input_picture[0]->f);

            s->reordered_input_picture[0]->shared = 0;



            s->current_picture_ptr = pic;

        } else {

            

            s->current_picture_ptr = s->reordered_input_picture[0];

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

                s->new_picture.f->data[i] += INPLACE_OFFSET;

            }

        }

        ff_mpeg_unref_picture(s->avctx, &s->current_picture);

        if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,

                                       s->current_picture_ptr)) < 0)

            return ret;



        s->picture_number = s->new_picture.f->display_picture_number;

    }

    return 0;

}

static int FUNC_0(MpegEncContext *VAR_0)

{

    int VAR_5, VAR_2;



    for (VAR_5 = 1; VAR_5 < MAX_PICTURE_COUNT; VAR_5++)

        VAR_0->reordered_input_picture[VAR_5 - 1] = VAR_0->reordered_input_picture[VAR_5];

    VAR_0->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;



    

    if (!VAR_0->reordered_input_picture[0] && VAR_0->input_picture[0]) {

        if (

            !VAR_0->next_picture_ptr || VAR_0->intra_only) {

            VAR_0->reordered_input_picture[0] = VAR_0->input_picture[0];

            VAR_0->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;

            VAR_0->reordered_input_picture[0]->f->coded_picture_number =

                VAR_0->coded_picture_number++;

        } else {

            int VAR_3;



            if (VAR_0->avctx->frame_skip_threshold || VAR_0->avctx->frame_skip_factor) {

                if (VAR_0->picture_in_gop_number < VAR_0->gop_size &&

                    skip_check(VAR_0, VAR_0->input_picture[0], VAR_0->next_picture_ptr)) {

                    

                    av_frame_unref(VAR_0->input_picture[0]->f);



                    emms_c();

                    ff_vbv_update(VAR_0, 0);



                    goto no_output_pic;

                }

            }



            if (VAR_0->avctx->flags & AV_CODEC_FLAG_PASS2) {

                for (VAR_5 = 0; VAR_5 < VAR_0->max_b_frames + 1; VAR_5++) {

                    int pict_num = VAR_0->input_picture[0]->f->display_picture_number + VAR_5;



                    if (pict_num >= VAR_0->rc_context.num_entries)

                        break;

                    if (!VAR_0->input_picture[VAR_5]) {

                        VAR_0->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P;

                        break;

                    }



                    VAR_0->input_picture[VAR_5]->f->pict_type =

                        VAR_0->rc_context.entry[pict_num].new_pict_type;

                }

            }



            if (VAR_0->avctx->b_frame_strategy == 0) {

                VAR_3 = VAR_0->max_b_frames;

                while (VAR_3 && !VAR_0->input_picture[VAR_3])

                    VAR_3--;

            } else if (VAR_0->avctx->b_frame_strategy == 1) {

                for (VAR_5 = 1; VAR_5 < VAR_0->max_b_frames + 1; VAR_5++) {

                    if (VAR_0->input_picture[VAR_5] &&

                        VAR_0->input_picture[VAR_5]->b_frame_score == 0) {

                        VAR_0->input_picture[VAR_5]->b_frame_score =

                            get_intra_count(VAR_0,

                                            VAR_0->input_picture[VAR_5    ]->f->data[0],

                                            VAR_0->input_picture[VAR_5 - 1]->f->data[0],

                                            VAR_0->linesize) + 1;

                    }

                }

                for (VAR_5 = 0; VAR_5 < VAR_0->max_b_frames + 1; VAR_5++) {

                    if (!VAR_0->input_picture[VAR_5] ||

                        VAR_0->input_picture[VAR_5]->b_frame_score - 1 >

                            VAR_0->mb_num / VAR_0->avctx->b_sensitivity)

                        break;

                }



                VAR_3 = FFMAX(0, VAR_5 - 1);



                

                for (VAR_5 = 0; VAR_5 < VAR_3 + 1; VAR_5++) {

                    VAR_0->input_picture[VAR_5]->b_frame_score = 0;

                }

            } else if (VAR_0->avctx->b_frame_strategy == 2) {

                VAR_3 = estimate_best_b_count(VAR_0);

            } else {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");

                VAR_3 = 0;

            }



            emms_c();



            for (VAR_5 = VAR_3 - 1; VAR_5 >= 0; VAR_5--) {

                int VAR_4 = VAR_0->input_picture[VAR_5]->f->pict_type;

                if (VAR_4 && VAR_4 != AV_PICTURE_TYPE_B)

                    VAR_3 = VAR_5;

            }

            if (VAR_0->input_picture[VAR_3]->f->pict_type == AV_PICTURE_TYPE_B &&

                VAR_3 == VAR_0->max_b_frames) {

                av_log(VAR_0->avctx, AV_LOG_ERROR,

                       "warning, too many b frames in a row\n");

            }



            if (VAR_0->picture_in_gop_number + VAR_3 >= VAR_0->gop_size) {

                if ((VAR_0->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&

                    VAR_0->gop_size > VAR_0->picture_in_gop_number) {

                    VAR_3 = VAR_0->gop_size - VAR_0->picture_in_gop_number - 1;

                } else {

                    if (VAR_0->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)

                        VAR_3 = 0;

                    VAR_0->input_picture[VAR_3]->f->pict_type = AV_PICTURE_TYPE_I;

                }

            }



            if ((VAR_0->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && VAR_3 &&

                VAR_0->input_picture[VAR_3]->f->pict_type == AV_PICTURE_TYPE_I)

                VAR_3--;



            VAR_0->reordered_input_picture[0] = VAR_0->input_picture[VAR_3];

            if (VAR_0->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)

                VAR_0->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;

            VAR_0->reordered_input_picture[0]->f->coded_picture_number =

                VAR_0->coded_picture_number++;

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

                VAR_0->reordered_input_picture[VAR_5 + 1] = VAR_0->input_picture[VAR_5];

                VAR_0->reordered_input_picture[VAR_5 + 1]->f->pict_type =

                    AV_PICTURE_TYPE_B;

                VAR_0->reordered_input_picture[VAR_5 + 1]->f->coded_picture_number =

                    VAR_0->coded_picture_number++;

            }

        }

    }

no_output_pic:

    ff_mpeg_unref_picture(VAR_0->avctx, &VAR_0->new_picture);



    if (VAR_0->reordered_input_picture[0]) {

        VAR_0->reordered_input_picture[0]->reference =

           VAR_0->reordered_input_picture[0]->f->pict_type !=

               AV_PICTURE_TYPE_B ? 3 : 0;



        if ((VAR_2 = ff_mpeg_ref_picture(VAR_0->avctx, &VAR_0->new_picture, VAR_0->reordered_input_picture[0])))

            return VAR_2;



        if (VAR_0->reordered_input_picture[0]->shared || VAR_0->avctx->rc_buffer_size) {

            

            



            Picture *pic;

            int VAR_5 = ff_find_unused_picture(VAR_0->avctx, VAR_0->picture, 0);

            if (VAR_5 < 0)

                return VAR_5;

            pic = &VAR_0->picture[VAR_5];



            pic->reference = VAR_0->reordered_input_picture[0]->reference;

            if (alloc_picture(VAR_0, pic, 0) < 0) {

                return -1;

            }



            VAR_2 = av_frame_copy_props(pic->f, VAR_0->reordered_input_picture[0]->f);

            if (VAR_2 < 0)

                return VAR_2;



            

            av_frame_unref(VAR_0->reordered_input_picture[0]->f);

            VAR_0->reordered_input_picture[0]->shared = 0;



            VAR_0->current_picture_ptr = pic;

        } else {

            

            VAR_0->current_picture_ptr = VAR_0->reordered_input_picture[0];

            for (VAR_5 = 0; VAR_5 < 4; VAR_5++) {

                VAR_0->new_picture.f->data[VAR_5] += INPLACE_OFFSET;

            }

        }

        ff_mpeg_unref_picture(VAR_0->avctx, &VAR_0->current_picture);

        if ((VAR_2 = ff_mpeg_ref_picture(VAR_0->avctx, &VAR_0->current_picture,

                                       VAR_0->current_picture_ptr)) < 0)

            return VAR_2;



        VAR_0->picture_number = VAR_0->new_picture.f->display_picture_number;

    }

    return 0;

}

static int FUNC_0(MpegEncContext *VAR_0)
{ int VAR_5, VAR_2; for (VAR_5 = 1; VAR_5 < MAX_PICTURE_COUNT; VAR_5++) VAR_0->reordered_input_picture[VAR_5 - 1] = VAR_0->reordered_input_picture[VAR_5]; VAR_0->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; if (!VAR_0->reordered_input_picture[0] && VAR_0->input_picture[0]) { if (
!VAR_0->next_picture_ptr || VAR_0->intra_only) { VAR_0->reordered_input_picture[0] = VAR_0->input_picture[0]; VAR_0->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; VAR_0->reordered_input_picture[0]->f->coded_picture_number =
VAR_0->coded_picture_number++; } else { int VAR_3; if (VAR_0->avctx->frame_skip_threshold || VAR_0->avctx->frame_skip_factor) { if (VAR_0->picture_in_gop_number < VAR_0->gop_size &&
skip_check(VAR_0, VAR_0->input_picture[0], VAR_0->next_picture_ptr)) { av_frame_unref(VAR_0->input_picture[0]->f); emms_c(); ff_vbv_update(VAR_0, 0); goto no_output_pic; } } if (VAR_0->avctx->flags & AV_CODEC_FLAG_PASS2) { for (VAR_5 = 0; VAR_5 < VAR_0->max_b_frames + 1; VAR_5++) { int pict_num = VAR_0->input_picture[0]->f->display_picture_number + VAR_5; if (pict_num >= VAR_0->rc_context.num_entries)
break; if (!VAR_0->input_picture[VAR_5]) { VAR_0->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; break; } VAR_0->input_picture[VAR_5]->f->pict_type =
VAR_0->rc_context.entry[pict_num].new_pict_type; } } if (VAR_0->avctx->b_frame_strategy == 0) { VAR_3 = VAR_0->max_b_frames; while (VAR_3 && !VAR_0->input_picture[VAR_3])
VAR_3--; } else if (VAR_0->avctx->b_frame_strategy == 1) { for (VAR_5 = 1; VAR_5 < VAR_0->max_b_frames + 1; VAR_5++) { if (VAR_0->input_picture[VAR_5] &&
VAR_0->input_picture[VAR_5]->b_frame_score == 0) { VAR_0->input_picture[VAR_5]->b_frame_score =
get_intra_count(VAR_0,
VAR_0->input_picture[VAR_5    ]->f->data[0],
VAR_0->input_picture[VAR_5 - 1]->f->data[0],
VAR_0->linesize) + 1; } } for (VAR_5 = 0; VAR_5 < VAR_0->max_b_frames + 1; VAR_5++) { if (!VAR_0->input_picture[VAR_5] ||
VAR_0->input_picture[VAR_5]->b_frame_score - 1 >
VAR_0->mb_num / VAR_0->avctx->b_sensitivity)
break; } VAR_3 = FFMAX(0, VAR_5 - 1); for (VAR_5 = 0; VAR_5 < VAR_3 + 1; VAR_5++) { VAR_0->input_picture[VAR_5]->b_frame_score = 0; } } else if (VAR_0->avctx->b_frame_strategy == 2) { VAR_3 = estimate_best_b_count(VAR_0); } else { av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal b frame strategy\n"); VAR_3 = 0; } emms_c(); for (VAR_5 = VAR_3 - 1; VAR_5 >= 0; VAR_5--) { int VAR_4 = VAR_0->input_picture[VAR_5]->f->pict_type; if (VAR_4 && VAR_4 != AV_PICTURE_TYPE_B)
VAR_3 = VAR_5; } if (VAR_0->input_picture[VAR_3]->f->pict_type == AV_PICTURE_TYPE_B &&
VAR_3 == VAR_0->max_b_frames) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"warning, too many b frames in a row\n"); } if (VAR_0->picture_in_gop_number + VAR_3 >= VAR_0->gop_size) { if ((VAR_0->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
VAR_0->gop_size > VAR_0->picture_in_gop_number) { VAR_3 = VAR_0->gop_size - VAR_0->picture_in_gop_number - 1; } else { if (VAR_0->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
VAR_3 = 0; VAR_0->input_picture[VAR_3]->f->pict_type = AV_PICTURE_TYPE_I; } } if ((VAR_0->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && VAR_3 &&
VAR_0->input_picture[VAR_3]->f->pict_type == AV_PICTURE_TYPE_I)
VAR_3--; VAR_0->reordered_input_picture[0] = VAR_0->input_picture[VAR_3]; if (VAR_0->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)
VAR_0->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; VAR_0->reordered_input_picture[0]->f->coded_picture_number =
VAR_0->coded_picture_number++; for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5++) { VAR_0->reordered_input_picture[VAR_5 + 1] = VAR_0->input_picture[VAR_5]; VAR_0->reordered_input_picture[VAR_5 + 1]->f->pict_type =
AV_PICTURE_TYPE_B; VAR_0->reordered_input_picture[VAR_5 + 1]->f->coded_picture_number =
VAR_0->coded_picture_number++; } } } no_output_pic:
ff_mpeg_unref_picture(VAR_0->avctx, &VAR_0->new_picture); if (VAR_0->reordered_input_picture[0]) { VAR_0->reordered_input_picture[0]->reference =
VAR_0->reordered_input_picture[0]->f->pict_type !=
AV_PICTURE_TYPE_B ? 3 : 0; if ((VAR_2 = ff_mpeg_ref_picture(VAR_0->avctx, &VAR_0->new_picture, VAR_0->reordered_input_picture[0])))
return VAR_2; if (VAR_0->reordered_input_picture[0]->shared || VAR_0->avctx->rc_buffer_size) { Picture *pic; int VAR_5 = ff_find_unused_picture(VAR_0->avctx, VAR_0->picture, 0); if (VAR_5 < 0)
return VAR_5; pic = &VAR_0->picture[VAR_5]; pic->reference = VAR_0->reordered_input_picture[0]->reference; if (alloc_picture(VAR_0, pic, 0) < 0) { return -1; } VAR_2 = av_frame_copy_props(pic->f, VAR_0->reordered_input_picture[0]->f); if (VAR_2 < 0)
return VAR_2; av_frame_unref(VAR_0->reordered_input_picture[0]->f); VAR_0->reordered_input_picture[0]->shared = 0; VAR_0->current_picture_ptr = pic; } else { VAR_0->current_picture_ptr = VAR_0->reordered_input_picture[0]; for (VAR_5 = 0; VAR_5 < 4; VAR_5++) { VAR_0->new_picture.f->data[VAR_5] += INPLACE_OFFSET; } } ff_mpeg_unref_picture(VAR_0->avctx, &VAR_0->current_picture); if ((VAR_2 = ff_mpeg_ref_picture(VAR_0->avctx, &VAR_0->current_picture,
VAR_0->current_picture_ptr)) < 0)
return VAR_2; VAR_0->picture_number = VAR_0->new_picture.f->display_picture_number; } return 0; }