int ff_mpv_common_frame_size_change(MpegEncContext *s)

{

    int i, err = 0;



    if (!s->context_initialized)

        return AVERROR(EINVAL);



    if (s->slice_context_count > 1) {

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

            free_duplicate_context(s->thread_context[i]);

        }

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

            av_freep(&s->thread_context[i]);

        }

    } else

        free_duplicate_context(s);



    free_context_frame(s);



    if (s->picture)

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

                s->picture[i].needs_realloc = 1;

        }



    s->last_picture_ptr         =

    s->next_picture_ptr         =

    s->current_picture_ptr      = NULL;



    // init

    if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)

        s->mb_height = (s->height + 31) / 32 * 2;

    else

        s->mb_height = (s->height + 15) / 16;



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

        (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)

        goto fail;



    if ((err = init_context_frame(s)))

        goto fail;



    s->thread_context[0]   = s;



    if (s->width && s->height) {

        int nb_slices = s->slice_context_count;

        if (nb_slices > 1) {

            for (i = 1; i < nb_slices; i++) {

                s->thread_context[i] = av_malloc(sizeof(MpegEncContext));

                memcpy(s->thread_context[i], s, sizeof(MpegEncContext));

            }



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

                if ((err = init_duplicate_context(s->thread_context[i])) < 0)

                    goto fail;

                    s->thread_context[i]->start_mb_y =

                        (s->mb_height * (i) + nb_slices / 2) / nb_slices;

                    s->thread_context[i]->end_mb_y   =

                        (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices;

            }

        } else {

            err = init_duplicate_context(s);

            if (err < 0)

                goto fail;

            s->start_mb_y = 0;

            s->end_mb_y   = s->mb_height;

        }

        s->slice_context_count = nb_slices;

    }



    return 0;

 fail:

    ff_mpv_common_end(s);

    return err;

}

int ff_mpv_common_frame_size_change(MpegEncContext *s)

{

    int i, err = 0;



    if (!s->context_initialized)

        return AVERROR(EINVAL);



    if (s->slice_context_count > 1) {

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

            free_duplicate_context(s->thread_context[i]);

        }

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

            av_freep(&s->thread_context[i]);

        }

    } else

        free_duplicate_context(s);



    free_context_frame(s);



    if (s->picture)

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

                s->picture[i].needs_realloc = 1;

        }



    s->last_picture_ptr         =

    s->next_picture_ptr         =

    s->current_picture_ptr      = NULL;



    

    if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)

        s->mb_height = (s->height + 31) / 32 * 2;

    else

        s->mb_height = (s->height + 15) / 16;



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

        (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)

        goto fail;



    if ((err = init_context_frame(s)))

        goto fail;



    s->thread_context[0]   = s;



    if (s->width && s->height) {

        int nb_slices = s->slice_context_count;

        if (nb_slices > 1) {

            for (i = 1; i < nb_slices; i++) {

                s->thread_context[i] = av_malloc(sizeof(MpegEncContext));

                memcpy(s->thread_context[i], s, sizeof(MpegEncContext));

            }



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

                if ((err = init_duplicate_context(s->thread_context[i])) < 0)

                    goto fail;

                    s->thread_context[i]->start_mb_y =

                        (s->mb_height * (i) + nb_slices / 2) / nb_slices;

                    s->thread_context[i]->end_mb_y   =

                        (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices;

            }

        } else {

            err = init_duplicate_context(s);

            if (err < 0)

                goto fail;

            s->start_mb_y = 0;

            s->end_mb_y   = s->mb_height;

        }

        s->slice_context_count = nb_slices;

    }



    return 0;

 fail:

    ff_mpv_common_end(s);

    return err;

}

int FUNC_0(MpegEncContext *VAR_0)

{

    int VAR_1, VAR_2 = 0;



    if (!VAR_0->context_initialized)

        return AVERROR(EINVAL);



    if (VAR_0->slice_context_count > 1) {

        for (VAR_1 = 0; VAR_1 < VAR_0->slice_context_count; VAR_1++) {

            free_duplicate_context(VAR_0->thread_context[VAR_1]);

        }

        for (VAR_1 = 1; VAR_1 < VAR_0->slice_context_count; VAR_1++) {

            av_freep(&VAR_0->thread_context[VAR_1]);

        }

    } else

        free_duplicate_context(VAR_0);



    free_context_frame(VAR_0);



    if (VAR_0->picture)

        for (VAR_1 = 0; VAR_1 < MAX_PICTURE_COUNT; VAR_1++) {

                VAR_0->picture[VAR_1].needs_realloc = 1;

        }



    VAR_0->last_picture_ptr         =

    VAR_0->next_picture_ptr         =

    VAR_0->current_picture_ptr      = NULL;



    

    if (VAR_0->codec_id == AV_CODEC_ID_MPEG2VIDEO && !VAR_0->progressive_sequence)

        VAR_0->mb_height = (VAR_0->height + 31) / 32 * 2;

    else

        VAR_0->mb_height = (VAR_0->height + 15) / 16;



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

        (VAR_2 = av_image_check_size(VAR_0->width, VAR_0->height, 0, VAR_0->avctx)) < 0)

        goto fail;



    if ((VAR_2 = init_context_frame(VAR_0)))

        goto fail;



    VAR_0->thread_context[0]   = VAR_0;



    if (VAR_0->width && VAR_0->height) {

        int VAR_3 = VAR_0->slice_context_count;

        if (VAR_3 > 1) {

            for (VAR_1 = 1; VAR_1 < VAR_3; VAR_1++) {

                VAR_0->thread_context[VAR_1] = av_malloc(sizeof(MpegEncContext));

                memcpy(VAR_0->thread_context[VAR_1], VAR_0, sizeof(MpegEncContext));

            }



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

                if ((VAR_2 = init_duplicate_context(VAR_0->thread_context[VAR_1])) < 0)

                    goto fail;

                    VAR_0->thread_context[VAR_1]->start_mb_y =

                        (VAR_0->mb_height * (VAR_1) + VAR_3 / 2) / VAR_3;

                    VAR_0->thread_context[VAR_1]->end_mb_y   =

                        (VAR_0->mb_height * (VAR_1 + 1) + VAR_3 / 2) / VAR_3;

            }

        } else {

            VAR_2 = init_duplicate_context(VAR_0);

            if (VAR_2 < 0)

                goto fail;

            VAR_0->start_mb_y = 0;

            VAR_0->end_mb_y   = VAR_0->mb_height;

        }

        VAR_0->slice_context_count = VAR_3;

    }



    return 0;

 fail:

    ff_mpv_common_end(VAR_0);

    return VAR_2;

}

int FUNC_0(MpegEncContext *VAR_0)
{ int VAR_1, VAR_2 = 0; if (!VAR_0->context_initialized)
return AVERROR(EINVAL); if (VAR_0->slice_context_count > 1) { for (VAR_1 = 0; VAR_1 < VAR_0->slice_context_count; VAR_1++) { free_duplicate_context(VAR_0->thread_context[VAR_1]); } for (VAR_1 = 1; VAR_1 < VAR_0->slice_context_count; VAR_1++) { av_freep(&VAR_0->thread_context[VAR_1]); } } else free_duplicate_context(VAR_0); free_context_frame(VAR_0); if (VAR_0->picture)
for (VAR_1 = 0; VAR_1 < MAX_PICTURE_COUNT; VAR_1++) { VAR_0->picture[VAR_1].needs_realloc = 1; } VAR_0->last_picture_ptr         =
VAR_0->next_picture_ptr         =
VAR_0->current_picture_ptr      = NULL; if (VAR_0->codec_id == AV_CODEC_ID_MPEG2VIDEO && !VAR_0->progressive_sequence)
VAR_0->mb_height = (VAR_0->height + 31) / 32 * 2; else
VAR_0->mb_height = (VAR_0->height + 15) / 16; if ((VAR_0->width || VAR_0->height) &&
(VAR_2 = av_image_check_size(VAR_0->width, VAR_0->height, 0, VAR_0->avctx)) < 0)
goto fail; if ((VAR_2 = init_context_frame(VAR_0)))
goto fail; VAR_0->thread_context[0]   = VAR_0; if (VAR_0->width && VAR_0->height) { int VAR_3 = VAR_0->slice_context_count; if (VAR_3 > 1) { for (VAR_1 = 1; VAR_1 < VAR_3; VAR_1++) { VAR_0->thread_context[VAR_1] = av_malloc(sizeof(MpegEncContext)); memcpy(VAR_0->thread_context[VAR_1], VAR_0, sizeof(MpegEncContext)); } for (VAR_1 = 0; VAR_1 < VAR_3; VAR_1++) { if ((VAR_2 = init_duplicate_context(VAR_0->thread_context[VAR_1])) < 0)
goto fail; VAR_0->thread_context[VAR_1]->start_mb_y =
(VAR_0->mb_height * (VAR_1) + VAR_3 / 2) / VAR_3; VAR_0->thread_context[VAR_1]->end_mb_y   =
(VAR_0->mb_height * (VAR_1 + 1) + VAR_3 / 2) / VAR_3; } } else { VAR_2 = init_duplicate_context(VAR_0); if (VAR_2 < 0)
goto fail; VAR_0->start_mb_y = 0; VAR_0->end_mb_y   = VAR_0->mb_height; } VAR_0->slice_context_count = VAR_3; } return 0; fail:
ff_mpv_common_end(VAR_0); return VAR_2; }