static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){

    int y_size = s->b8_stride * (2 * s->mb_height + 1);

    int c_size = s->mb_stride * (s->mb_height + 1);

    int yc_size = y_size + 2 * c_size;

    int i;



    // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)

    FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance

    s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21;



     //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer()

    FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad,  (s->width+64)*4*16*2*sizeof(uint8_t), fail)

    s->me.temp=         s->me.scratchpad;

    s->rd_scratchpad=   s->me.scratchpad;

    s->b_scratchpad=    s->me.scratchpad;

    s->obmc_scratchpad= s->me.scratchpad + 16;

    if (s->encoding) {

        FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map      , ME_MAP_SIZE*sizeof(uint32_t), fail)

        FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)

        if(s->avctx->noise_reduction){

            FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail)

        }

    }

    FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail)

    s->block= s->blocks[0];



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

        s->pblocks[i] = &s->block[i];

    }



    if (s->out_format == FMT_H263) {

        /* ac values */

        FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);

        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;

        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;

        s->ac_val[2] = s->ac_val[1] + c_size;

    }



    return 0;

fail:

    return -1; //free() through MPV_common_end()

}

static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){

    int y_size = s->b8_stride * (2 * s->mb_height + 1);

    int c_size = s->mb_stride * (s->mb_height + 1);

    int yc_size = y_size + 2 * c_size;

    int i;



    

    FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); 

    s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21;



     

    FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad,  (s->width+64)*4*16*2*sizeof(uint8_t), fail)

    s->me.temp=         s->me.scratchpad;

    s->rd_scratchpad=   s->me.scratchpad;

    s->b_scratchpad=    s->me.scratchpad;

    s->obmc_scratchpad= s->me.scratchpad + 16;

    if (s->encoding) {

        FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map      , ME_MAP_SIZE*sizeof(uint32_t), fail)

        FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)

        if(s->avctx->noise_reduction){

            FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail)

        }

    }

    FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail)

    s->block= s->blocks[0];



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

        s->pblocks[i] = &s->block[i];

    }



    if (s->out_format == FMT_H263) {

        

        FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);

        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;

        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;

        s->ac_val[2] = s->ac_val[1] + c_size;

    }



    return 0;

fail:

    return -1; 

}

    s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21;
static int FUNC_0(MpegEncContext *VAR_0, MpegEncContext *VAR_1){

    int VAR_2 = VAR_0->b8_stride * (2 * VAR_0->mb_height + 1);

    int VAR_3 = VAR_0->mb_stride * (VAR_0->mb_height + 1);

    int VAR_4 = VAR_2 + 2 * VAR_3;

    int VAR_5;



    

    FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->allocated_edge_emu_buffer, (VAR_0->width+64)*2*21*2, fail); 

    VAR_0->edge_emu_buffer= VAR_0->allocated_edge_emu_buffer + (VAR_0->width+64)*2*21;



     

    FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->me.scratchpad,  (VAR_0->width+64)*4*16*2*sizeof(uint8_t), fail)

    VAR_0->me.temp=         VAR_0->me.scratchpad;

    VAR_0->rd_scratchpad=   VAR_0->me.scratchpad;

    VAR_0->b_scratchpad=    VAR_0->me.scratchpad;

    VAR_0->obmc_scratchpad= VAR_0->me.scratchpad + 16;

    if (VAR_0->encoding) {

        FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->me.map      , ME_MAP_SIZE*sizeof(uint32_t), fail)

        FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)

        if(VAR_0->avctx->noise_reduction){

            FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->dct_error_sum, 2 * 64 * sizeof(int), fail)

        }

    }

    FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->blocks, 64*12*2 * sizeof(DCTELEM), fail)

    VAR_0->block= VAR_0->blocks[0];



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

        VAR_0->pblocks[VAR_5] = &VAR_0->block[VAR_5];

    }



    if (VAR_0->out_format == FMT_H263) {

        

        FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->ac_val_base, VAR_4 * sizeof(int16_t) * 16, fail);

        VAR_0->ac_val[0] = VAR_0->ac_val_base + VAR_0->b8_stride + 1;

        VAR_0->ac_val[1] = VAR_0->ac_val_base + VAR_2 + VAR_0->mb_stride + 1;

        VAR_0->ac_val[2] = VAR_0->ac_val[1] + VAR_3;

    }



    return 0;

fail:

    return -1; 

}

static int FUNC_0(MpegEncContext *VAR_0, MpegEncContext *VAR_1){ int VAR_2 = VAR_0->b8_stride * (2 * VAR_0->mb_height + 1); int VAR_3 = VAR_0->mb_stride * (VAR_0->mb_height + 1); int VAR_4 = VAR_2 + 2 * VAR_3; int VAR_5; FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->allocated_edge_emu_buffer, (VAR_0->width+64)*2*21*2, fail); VAR_0->edge_emu_buffer= VAR_0->allocated_edge_emu_buffer + (VAR_0->width+64)*2*21; FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->me.scratchpad,  (VAR_0->width+64)*4*16*2*sizeof(uint8_t), fail)
VAR_0->me.temp=         VAR_0->me.scratchpad; VAR_0->rd_scratchpad=   VAR_0->me.scratchpad; VAR_0->b_scratchpad=    VAR_0->me.scratchpad; VAR_0->obmc_scratchpad= VAR_0->me.scratchpad + 16; if (VAR_0->encoding) { FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->me.map      , ME_MAP_SIZE*sizeof(uint32_t), fail)
FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)
if(VAR_0->avctx->noise_reduction){ FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->dct_error_sum, 2 * 64 * sizeof(int), fail)
} } FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->blocks, 64*12*2 * sizeof(DCTELEM), fail)
VAR_0->block= VAR_0->blocks[0]; for(VAR_5=0;VAR_5<12;VAR_5++){ VAR_0->pblocks[VAR_5] = &VAR_0->block[VAR_5]; } if (VAR_0->out_format == FMT_H263) { FF_ALLOCZ_OR_GOTO(VAR_0->avctx, VAR_0->ac_val_base, VAR_4 * sizeof(int16_t) * 16, fail); VAR_0->ac_val[0] = VAR_0->ac_val_base + VAR_0->b8_stride + 1; VAR_0->ac_val[1] = VAR_0->ac_val_base + VAR_2 + VAR_0->mb_stride + 1; VAR_0->ac_val[2] = VAR_0->ac_val[1] + VAR_3; } return 0; fail:
return -1; }