int update_dimensions(VP8Context *s, int width, int height, int is_vp7)

{

    AVCodecContext *avctx = s->avctx;

    int i, ret;



    if (width  != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||

        height != s->avctx->height) {

        vp8_decode_flush_impl(s->avctx, 1);



        ret = ff_set_dimensions(s->avctx, width, height);

        if (ret < 0)

            return ret;

    }



    s->mb_width  = (s->avctx->coded_width  + 15) / 16;

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



    s->mb_layout = is_vp7 || avctx->active_thread_type == FF_THREAD_SLICE &&

                   FFMIN(s->num_coeff_partitions, avctx->thread_count) > 1;

    if (!s->mb_layout) { // Frame threading and one thread

        s->macroblocks_base       = av_mallocz((s->mb_width + s->mb_height * 2 + 1) *

                                               sizeof(*s->macroblocks));

        s->intra4x4_pred_mode_top = av_mallocz(s->mb_width * 4);

    } else // Sliced threading

        s->macroblocks_base = av_mallocz((s->mb_width + 2) * (s->mb_height + 2) *

                                         sizeof(*s->macroblocks));

    s->top_nnz     = av_mallocz(s->mb_width * sizeof(*s->top_nnz));

    s->top_border  = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));

    s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));



    if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||

        !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {

        free_buffers(s);

        return AVERROR(ENOMEM);

    }



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

        s->thread_data[i].filter_strength =

            av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));

        if (!s->thread_data[i].filter_strength) {

            free_buffers(s);

            return AVERROR(ENOMEM);

        }

#if HAVE_THREADS

        pthread_mutex_init(&s->thread_data[i].lock, NULL);

        pthread_cond_init(&s->thread_data[i].cond, NULL);

#endif

    }



    s->macroblocks = s->macroblocks_base + 1;



    return 0;

}

int update_dimensions(VP8Context *s, int width, int height, int is_vp7)

{

    AVCodecContext *avctx = s->avctx;

    int i, ret;



    if (width  != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||

        height != s->avctx->height) {

        vp8_decode_flush_impl(s->avctx, 1);



        ret = ff_set_dimensions(s->avctx, width, height);

        if (ret < 0)

            return ret;

    }



    s->mb_width  = (s->avctx->coded_width  + 15) / 16;

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



    s->mb_layout = is_vp7 || avctx->active_thread_type == FF_THREAD_SLICE &&

                   FFMIN(s->num_coeff_partitions, avctx->thread_count) > 1;

    if (!s->mb_layout) { 

        s->macroblocks_base       = av_mallocz((s->mb_width + s->mb_height * 2 + 1) *

                                               sizeof(*s->macroblocks));

        s->intra4x4_pred_mode_top = av_mallocz(s->mb_width * 4);

    } else 

        s->macroblocks_base = av_mallocz((s->mb_width + 2) * (s->mb_height + 2) *

                                         sizeof(*s->macroblocks));

    s->top_nnz     = av_mallocz(s->mb_width * sizeof(*s->top_nnz));

    s->top_border  = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));

    s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));



    if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||

        !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {

        free_buffers(s);

        return AVERROR(ENOMEM);

    }



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

        s->thread_data[i].filter_strength =

            av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));

        if (!s->thread_data[i].filter_strength) {

            free_buffers(s);

            return AVERROR(ENOMEM);

        }

#if HAVE_THREADS

        pthread_mutex_init(&s->thread_data[i].lock, NULL);

        pthread_cond_init(&s->thread_data[i].cond, NULL);

#endif

    }



    s->macroblocks = s->macroblocks_base + 1;



    return 0;

}

                   FFMIN(s->num_coeff_partitions, avctx->thread_count) > 1;
int FUNC_0(VP8Context *VAR_0, int VAR_1, int VAR_2, int VAR_3)

{

    AVCodecContext *avctx = VAR_0->avctx;

    int VAR_4, VAR_5;



    if (VAR_1  != VAR_0->avctx->VAR_1 || ((VAR_1+15)/16 != VAR_0->mb_width || (VAR_2+15)/16 != VAR_0->mb_height) && VAR_0->macroblocks_base ||

        VAR_2 != VAR_0->avctx->VAR_2) {

        vp8_decode_flush_impl(VAR_0->avctx, 1);



        VAR_5 = ff_set_dimensions(VAR_0->avctx, VAR_1, VAR_2);

        if (VAR_5 < 0)

            return VAR_5;

    }



    VAR_0->mb_width  = (VAR_0->avctx->coded_width  + 15) / 16;

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



    VAR_0->mb_layout = VAR_3 || avctx->active_thread_type == FF_THREAD_SLICE &&

                   FFMIN(VAR_0->num_coeff_partitions, avctx->thread_count) > 1;

    if (!VAR_0->mb_layout) { 

        VAR_0->macroblocks_base       = av_mallocz((VAR_0->mb_width + VAR_0->mb_height * 2 + 1) *

                                               sizeof(*VAR_0->macroblocks));

        VAR_0->intra4x4_pred_mode_top = av_mallocz(VAR_0->mb_width * 4);

    } else 

        VAR_0->macroblocks_base = av_mallocz((VAR_0->mb_width + 2) * (VAR_0->mb_height + 2) *

                                         sizeof(*VAR_0->macroblocks));

    VAR_0->top_nnz     = av_mallocz(VAR_0->mb_width * sizeof(*VAR_0->top_nnz));

    VAR_0->top_border  = av_mallocz((VAR_0->mb_width + 1) * sizeof(*VAR_0->top_border));

    VAR_0->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));



    if (!VAR_0->macroblocks_base || !VAR_0->top_nnz || !VAR_0->top_border ||

        !VAR_0->thread_data || (!VAR_0->intra4x4_pred_mode_top && !VAR_0->mb_layout)) {

        free_buffers(VAR_0);

        return AVERROR(ENOMEM);

    }



    for (VAR_4 = 0; VAR_4 < MAX_THREADS; VAR_4++) {

        VAR_0->thread_data[VAR_4].filter_strength =

            av_mallocz(VAR_0->mb_width * sizeof(*VAR_0->thread_data[0].filter_strength));

        if (!VAR_0->thread_data[VAR_4].filter_strength) {

            free_buffers(VAR_0);

            return AVERROR(ENOMEM);

        }

#if HAVE_THREADS

        pthread_mutex_init(&VAR_0->thread_data[VAR_4].lock, NULL);

        pthread_cond_init(&VAR_0->thread_data[VAR_4].cond, NULL);

#endif

    }



    VAR_0->macroblocks = VAR_0->macroblocks_base + 1;



    return 0;

}

int FUNC_0(VP8Context *VAR_0, int VAR_1, int VAR_2, int VAR_3)
{ AVCodecContext *avctx = VAR_0->avctx; int VAR_4, VAR_5; if (VAR_1  != VAR_0->avctx->VAR_1 || ((VAR_1+15)/16 != VAR_0->mb_width || (VAR_2+15)/16 != VAR_0->mb_height) && VAR_0->macroblocks_base ||
VAR_2 != VAR_0->avctx->VAR_2) { vp8_decode_flush_impl(VAR_0->avctx, 1); VAR_5 = ff_set_dimensions(VAR_0->avctx, VAR_1, VAR_2); if (VAR_5 < 0)
return VAR_5; } VAR_0->mb_width  = (VAR_0->avctx->coded_width  + 15) / 16; VAR_0->mb_height = (VAR_0->avctx->coded_height + 15) / 16; VAR_0->mb_layout = VAR_3 || avctx->active_thread_type == FF_THREAD_SLICE &&
FFMIN(VAR_0->num_coeff_partitions, avctx->thread_count) > 1; if (!VAR_0->mb_layout) { VAR_0->macroblocks_base       = av_mallocz((VAR_0->mb_width + VAR_0->mb_height * 2 + 1) *
sizeof(*VAR_0->macroblocks)); VAR_0->intra4x4_pred_mode_top = av_mallocz(VAR_0->mb_width * 4); } else VAR_0->macroblocks_base = av_mallocz((VAR_0->mb_width + 2) * (VAR_0->mb_height + 2) *
sizeof(*VAR_0->macroblocks)); VAR_0->top_nnz     = av_mallocz(VAR_0->mb_width * sizeof(*VAR_0->top_nnz)); VAR_0->top_border  = av_mallocz((VAR_0->mb_width + 1) * sizeof(*VAR_0->top_border)); VAR_0->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData)); if (!VAR_0->macroblocks_base || !VAR_0->top_nnz || !VAR_0->top_border ||
!VAR_0->thread_data || (!VAR_0->intra4x4_pred_mode_top && !VAR_0->mb_layout)) { free_buffers(VAR_0); return AVERROR(ENOMEM); } for (VAR_4 = 0; VAR_4 < MAX_THREADS; VAR_4++) { VAR_0->thread_data[VAR_4].filter_strength =
av_mallocz(VAR_0->mb_width * sizeof(*VAR_0->thread_data[0].filter_strength)); if (!VAR_0->thread_data[VAR_4].filter_strength) { free_buffers(VAR_0); return AVERROR(ENOMEM); } #if HAVE_THREADS
pthread_mutex_init(&VAR_0->thread_data[VAR_4].lock, NULL); pthread_cond_init(&VAR_0->thread_data[VAR_4].cond, NULL); #endif
} VAR_0->macroblocks = VAR_0->macroblocks_base + 1; return 0; }