CHECKED_ALLOCZ(s->me_scratchpad,  s->width*2*16*3*sizeof(uint8_t))
CHECKED_ALLOCZ(s->me.scratchpad,  s->width*2*16*3*sizeof(uint8_t))
int MPV_common_init(MpegEncContext *s){    int y_size, c_size, yc_size, i;    dsputil_init(&s->dsp, s->avctx->dsp_mask);    DCT_common_init(s);    s->flags= s->avctx->flags;    s->mb_width  = (s->width  + 15) / 16;    s->mb_height = (s->height + 15) / 16;    /* set default edge pos, will be overriden in decode_header if needed */    s->h_edge_pos= s->mb_width*16;    s->v_edge_pos= s->mb_height*16;    s->mb_num = s->mb_width * s->mb_height;    y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);    c_size = (s->mb_width + 2) * (s->mb_height + 2);    yc_size = y_size + 2 * c_size;    /* convert fourcc to upper case */    s->avctx->fourcc=   toupper( s->avctx->fourcc     &0xFF)                               + (toupper((s->avctx->fourcc>>8 )&0xFF)<<8 )                     + (toupper((s->avctx->fourcc>>16)&0xFF)<<16)                      + (toupper((s->avctx->fourcc>>24)&0xFF)<<24);    CHECKED_ALLOCZ(s->edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance    s->avctx->coded_frame= (AVFrame*)&s->current_picture;    if (s->encoding) {        int mv_table_size= (s->mb_width+2)*(s->mb_height+2);        /* Allocate MV tables */        CHECKED_ALLOCZ(s->p_mv_table            , mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_forw_mv_table       , mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_back_mv_table       , mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_direct_forw_mv_table, mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_direct_back_mv_table, mv_table_size * 2 * sizeof(INT16))        CHECKED_ALLOCZ(s->b_direct_mv_table     , mv_table_size * 2 * sizeof(INT16))        //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer()        CHECKED_ALLOCZ(s->me_scratchpad,  s->width*2*16*3*sizeof(uint8_t))                 CHECKED_ALLOCZ(s->me_map      , ME_MAP_SIZE*sizeof(uint32_t))        CHECKED_ALLOCZ(s->me_score_map, ME_MAP_SIZE*sizeof(uint16_t))        if(s->codec_id==CODEC_ID_MPEG4){            CHECKED_ALLOCZ(s->tex_pb_buffer, PB_BUFFER_SIZE);            CHECKED_ALLOCZ(   s->pb2_buffer, PB_BUFFER_SIZE);        }                if(s->msmpeg4_version){            CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int));        }        CHECKED_ALLOCZ(s->avctx->stats_out, 256);    }            CHECKED_ALLOCZ(s->error_status_table, s->mb_num*sizeof(UINT8))        if (s->out_format == FMT_H263 || s->encoding) {        int size;        /* Allocate MB type table */        CHECKED_ALLOCZ(s->mb_type  , s->mb_num * sizeof(UINT8))        /* MV prediction */        size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);        CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(INT16));    }    if(s->codec_id==CODEC_ID_MPEG4){        /* interlaced direct mode decoding tables */        CHECKED_ALLOCZ(s->field_mv_table, s->mb_num*2*2 * sizeof(INT16))        CHECKED_ALLOCZ(s->field_select_table, s->mb_num*2* sizeof(INT8))    }    /* 4mv b frame decoding table */    //note this is needed for h263 without b frames too (segfault on damaged streams otherwise)    CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(UINT8))    if (s->out_format == FMT_H263) {        /* ac values */        CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(INT16) * 16);        s->ac_val[1] = s->ac_val[0] + y_size;        s->ac_val[2] = s->ac_val[1] + c_size;                /* cbp values */        CHECKED_ALLOCZ(s->coded_block, y_size);                /* divx501 bitstream reorder buffer */        CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE);        /* cbp, ac_pred, pred_dir */        CHECKED_ALLOCZ(s->cbp_table  , s->mb_num * sizeof(UINT8))        CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8))    }        if (s->h263_pred || s->h263_plus || !s->encoding) {        /* dc values */        //MN: we need these for error resilience of intra-frames        CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(INT16));        s->dc_val[1] = s->dc_val[0] + y_size;        s->dc_val[2] = s->dc_val[1] + c_size;        for(i=0;i<yc_size;i++)            s->dc_val[0][i] = 1024;    }    /* which mb is a intra block */    CHECKED_ALLOCZ(s->mbintra_table, s->mb_num);    memset(s->mbintra_table, 1, s->mb_num);        /* default structure is frame */    s->picture_structure = PICT_FRAME;        /* init macroblock skip table */    CHECKED_ALLOCZ(s->mbskip_table, s->mb_num+1);    //Note the +1 is for a quicker mpeg4 slice_end detection        s->block= s->blocks[0];    s->parse_context.state= -1;    s->context_initialized = 1;    return 0; fail:    MPV_common_end(s);    return -1;}