s->block= s->intra_block;
int MPV_common_init(MpegEncContext *s){    int c_size, i;    UINT8 *pict;    if (s->out_format == FMT_H263)         s->dct_unquantize = dct_unquantize_h263_c;    else        s->dct_unquantize = dct_unquantize_mpeg1_c;        #ifdef HAVE_MMX    MPV_common_init_mmx(s);#endif    s->mb_width = (s->width + 15) / 16;    s->mb_height = (s->height + 15) / 16;    s->mb_num = s->mb_width * s->mb_height;    s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH;    for(i=0;i<3;i++) {        int w, h, shift, pict_start;        w = s->linesize;        h = s->mb_height * 16 + 2 * EDGE_WIDTH;        shift = (i == 0) ? 0 : 1;        c_size = (w >> shift) * (h >> shift);        pict_start = (w >> shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift);        pict = av_mallocz(c_size);        if (pict == NULL)            goto fail;        s->last_picture_base[i] = pict;        s->last_picture[i] = pict + pict_start;            pict = av_mallocz(c_size);        if (pict == NULL)            goto fail;        s->next_picture_base[i] = pict;        s->next_picture[i] = pict + pict_start;        if (s->has_b_frames) {            pict = av_mallocz(c_size);            if (pict == NULL)                 goto fail;            s->aux_picture_base[i] = pict;            s->aux_picture[i] = pict + pict_start;        }    }        if (s->encoding) {        /* Allocate MB type table */        s->mb_type = av_mallocz(s->mb_num * sizeof(char));        if (s->mb_type == NULL) {            perror("malloc");            goto fail;        }                s->mb_var = av_mallocz(s->mb_num * sizeof(INT16));        if (s->mb_var == NULL) {            perror("malloc");            goto fail;        }        /* Allocate MV table */        /* By now we just have one MV per MB */        s->mv_table[0] = av_mallocz(s->mb_num * sizeof(INT16));        s->mv_table[1] = av_mallocz(s->mb_num * sizeof(INT16));        if (s->mv_table[1] == NULL || s->mv_table[0] == NULL) {            perror("malloc");            goto fail;        }    }        if (s->out_format == FMT_H263 || s->encoding) {        int size;        /* MV prediction */        size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);        s->motion_val = malloc(size * 2 * sizeof(INT16));        if (s->motion_val == NULL)            goto fail;        memset(s->motion_val, 0, size * 2 * sizeof(INT16));    }    if (s->h263_pred || s->h263_plus) {        int y_size, c_size, i, size;                /* dc values */        y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);        c_size = (s->mb_width + 2) * (s->mb_height + 2);        size = y_size + 2 * c_size;        s->dc_val[0] = malloc(size * sizeof(INT16));        if (s->dc_val[0] == NULL)            goto fail;        s->dc_val[1] = s->dc_val[0] + y_size;        s->dc_val[2] = s->dc_val[1] + c_size;        for(i=0;i<size;i++)            s->dc_val[0][i] = 1024;        /* ac values */        s->ac_val[0] = av_mallocz(size * sizeof(INT16) * 16);        if (s->ac_val[0] == NULL)            goto fail;        s->ac_val[1] = s->ac_val[0] + y_size;        s->ac_val[2] = s->ac_val[1] + c_size;                /* cbp values */        s->coded_block = av_mallocz(y_size);        if (!s->coded_block)            goto fail;        /* which mb is a intra block */        s->mbintra_table = av_mallocz(s->mb_num);        if (!s->mbintra_table)            goto fail;        memset(s->mbintra_table, 1, s->mb_num);    }    /* default structure is frame */    s->picture_structure = PICT_FRAME;    /* init macroblock skip table */    if (!s->encoding) {        s->mbskip_table = av_mallocz(s->mb_num);        if (!s->mbskip_table)            goto fail;    }    s->context_initialized = 1;    return 0; fail:    MPV_common_end(s);    return -1;}