static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){
    MpegEncContext * const s = &h->s;
    const int mb_x= s->mb_x;
    const int mb_y= s->mb_y;
    const int mb_xy= mb_x + mb_y*s->mb_stride;
    const int mb_type= s->current_picture.mb_type[mb_xy];
    uint8_t  *dest_y, *dest_cb, *dest_cr;
    int linesize, uvlinesize  ;
    int i;
    int *block_offset = &h->block_offset[0];
    const unsigned int bottom = mb_y & 1;
    const int transform_bypass = (s->qscale == 0 && h->sps.transform_bypass), is_h264 = (simple || s->codec_id == CODEC_ID_H264);
    void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);
    void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
    dest_y  = s->current_picture.data[0] + (mb_y * 16* s->linesize  ) + mb_x * 16;
    dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
    dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
    s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + 64, s->linesize, 4);
    s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + 64, dest_cr - dest_cb, 2);
    if (!simple && MB_FIELD) {
        linesize   = h->mb_linesize   = s->linesize * 2;
        uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;
        block_offset = &h->block_offset[24];
        if(mb_y&1){
            dest_y -= s->linesize*15;
            dest_cb-= s->uvlinesize*7;
            dest_cr-= s->uvlinesize*7;
        }
        if(FRAME_MBAFF) {
            int list;
            for(list=0; list<h->list_count; list++){
                if(!USES_LIST(mb_type, list))
                    continue;
                if(IS_16X16(mb_type)){
                    int8_t *ref = &h->ref_cache[list][scan8[0]];
                    fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1);
                }else{
                    for(i=0; i<16; i+=4){
                        int ref = h->ref_cache[list][scan8[i]];
                        if(ref >= 0)
                            fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1);
                    }
                }
            }
        }
    } else {
        linesize   = h->mb_linesize   = s->linesize;
        uvlinesize = h->mb_uvlinesize = s->uvlinesize;
    }
    if(transform_bypass){
        idct_dc_add =
        idct_add = IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4;
    }else if(IS_8x8DCT(mb_type)){
        idct_dc_add = s->dsp.h264_idct8_dc_add;
        idct_add = s->dsp.h264_idct8_add;
    }else{
        idct_dc_add = s->dsp.h264_idct_dc_add;
        idct_add = s->dsp.h264_idct_add;
    }
    if(!simple && FRAME_MBAFF && h->deblocking_filter && IS_INTRA(mb_type)
       && (!bottom || !IS_INTRA(s->current_picture.mb_type[mb_xy-s->mb_stride]))){
        int mbt_y = mb_y&~1;
        uint8_t *top_y  = s->current_picture.data[0] + (mbt_y * 16* s->linesize  ) + mb_x * 16;
        uint8_t *top_cb = s->current_picture.data[1] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;
        uint8_t *top_cr = s->current_picture.data[2] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;
        xchg_pair_border(h, top_y, top_cb, top_cr, s->linesize, s->uvlinesize, 1);
    }
    if (!simple && IS_INTRA_PCM(mb_type)) {
        unsigned int x, y;
        for(i=0; i<16; i++) {
            for (y=0; y<4; y++) {
                for (x=0; x<4; x++) {
                    *(dest_y + block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x];
                }
            }
        }
        for(i=16; i<16+4; i++) {
            for (y=0; y<4; y++) {
                for (x=0; x<4; x++) {
                    *(dest_cb + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
                }
            }
        }
        for(i=20; i<20+4; i++) {
            for (y=0; y<4; y++) {
                for (x=0; x<4; x++) {
                    *(dest_cr + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
                }
            }
        }
    } else {
        if(IS_INTRA(mb_type)){
            if(h->deblocking_filter && (simple || !FRAME_MBAFF))
                xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple);
            if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);
                h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);
            }
            if(IS_INTRA4x4(mb_type)){
                if(simple || !s->encoding){
                    if(IS_8x8DCT(mb_type)){
                        for(i=0; i<16; i+=4){
                            uint8_t * const ptr= dest_y + block_offset[i];
                            const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
                            const int nnz = h->non_zero_count_cache[ scan8[i] ];
                            h->hpc.pred8x8l[ dir ](ptr, (h->topleft_samples_available<<i)&0x8000,
                                                   (h->topright_samples_available<<i)&0x4000, linesize);
                            if(nnz){
                                if(nnz == 1 && h->mb[i*16])
                                    idct_dc_add(ptr, h->mb + i*16, linesize);
                                else
                                    idct_add(ptr, h->mb + i*16, linesize);
                            }
                        }
                    }else
                    for(i=0; i<16; i++){
                        uint8_t * const ptr= dest_y + block_offset[i];
                        uint8_t *topright;
                        const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
                        int nnz, tr;
                        if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){
                            const int topright_avail= (h->topright_samples_available<<i)&0x8000;
                            assert(mb_y || linesize <= block_offset[i]);
                            if(!topright_avail){
                                tr= ptr[3 - linesize]*0x01010101;
                                topright= (uint8_t*) &tr;
                            }else
                                topright= ptr + 4 - linesize;
                        }else
                            topright= NULL;
                        h->hpc.pred4x4[ dir ](ptr, topright, linesize);
                        nnz = h->non_zero_count_cache[ scan8[i] ];
                        if(nnz){
                            if(is_h264){
                                if(nnz == 1 && h->mb[i*16])
                                    idct_dc_add(ptr, h->mb + i*16, linesize);
                                else
                                    idct_add(ptr, h->mb + i*16, linesize);
                            }else
                                svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0);
                        }
                    }
                }
            }else{
                h->hpc.pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize);
                if(is_h264){
                    if(!transform_bypass)
                        h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[0][s->qscale][0]);
                }else
                    svq3_luma_dc_dequant_idct_c(h->mb, s->qscale);
            }
            if(h->deblocking_filter && (simple || !FRAME_MBAFF))
                xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple);
        }else if(is_h264){
            hl_motion(h, dest_y, dest_cb, dest_cr,
                      s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
                      s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
                      s->dsp.weight_h264_pixels_tab, s->dsp.biweight_h264_pixels_tab);
        }
        if(!IS_INTRA4x4(mb_type)){
            if(is_h264){
                if(IS_INTRA16x16(mb_type)){
                    for(i=0; i<16; i++){
                        if(h->non_zero_count_cache[ scan8[i] ])
                            idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);
                        else if(h->mb[i*16])
                            idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);
                    }
                }else{
                    const int di = IS_8x8DCT(mb_type) ? 4 : 1;
                    for(i=0; i<16; i+=di){
                        int nnz = h->non_zero_count_cache[ scan8[i] ];
                        if(nnz){
                            if(nnz==1 && h->mb[i*16])
                                idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);
                            else
                                idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);
                        }
                    }
                }
            }else{
                for(i=0; i<16; i++){
                    if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
                        uint8_t * const ptr= dest_y + block_offset[i];
                        svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0);
                    }
                }
            }
        }
        if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
            uint8_t *dest[2] = {dest_cb, dest_cr};
            if(transform_bypass){
                idct_add = idct_dc_add = s->dsp.add_pixels4;
            }else{
                idct_add = s->dsp.h264_idct_add;
                idct_dc_add = s->dsp.h264_idct_dc_add;
                chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);
                chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);
            }
            if(is_h264){
                for(i=16; i<16+8; i++){
                    if(h->non_zero_count_cache[ scan8[i] ])
                        idct_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize);
                    else if(h->mb[i*16])
                        idct_dc_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize);
                }
            }else{
                for(i=16; i<16+8; i++){
                    if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
                        uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i];
                        svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);
                    }
                }
            }
        }
    }
    if(h->deblocking_filter) {
        if (!simple && FRAME_MBAFF) {
            const int mb_y = s->mb_y - 1;
            uint8_t  *pair_dest_y, *pair_dest_cb, *pair_dest_cr;
            const int mb_xy= mb_x + mb_y*s->mb_stride;
            const int mb_type_top   = s->current_picture.mb_type[mb_xy];
            const int mb_type_bottom= s->current_picture.mb_type[mb_xy+s->mb_stride];
            if (!bottom) return;
            pair_dest_y  = s->current_picture.data[0] + (mb_y * 16* s->linesize  ) + mb_x * 16;
            pair_dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
            pair_dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
            if(IS_INTRA(mb_type_top | mb_type_bottom))
                xchg_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize, 0);
            backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize);
            s->mb_y--;
            tprintf(h->s.avctx, "call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y);
            fill_caches(h, mb_type_top, 1);
            h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]);
            h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]);
            filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);
            s->mb_y++;
            tprintf(h->s.avctx, "call mbaff filter_mb\n");
            fill_caches(h, mb_type_bottom, 1);
            h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
            h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
            filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
        } else {
            tprintf(h->s.avctx, "call filter_mb\n");
            backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simple);
            fill_caches(h, mb_type, 1);
            filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
        }
    }
}
['static int decode_slice(struct AVCodecContext *avctx, H264Context *h){\n    MpegEncContext * const s = &h->s;\n    const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;\n    s->mb_skip_run= -1;\n    if( h->pps.cabac ) {\n        int i;\n        align_get_bits( &s->gb );\n        ff_init_cabac_states( &h->cabac);\n        ff_init_cabac_decoder( &h->cabac,\n                               s->gb.buffer + get_bits_count(&s->gb)/8,\n                               ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8);\n        for( i= 0; i < 460; i++ ) {\n            int pre;\n            if( h->slice_type == FF_I_TYPE )\n                pre = av_clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 );\n            else\n                pre = av_clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 );\n            if( pre <= 63 )\n                h->cabac_state[i] = 2 * ( 63 - pre ) + 0;\n            else\n                h->cabac_state[i] = 2 * ( pre - 64 ) + 1;\n        }\n        for(;;){\n            int ret = decode_mb_cabac(h);\n            int eos;\n            if(ret>=0) hl_decode_mb(h);\n            if( ret >= 0 && FRAME_MBAFF ) {\n                s->mb_y++;\n                if(ret>=0) ret = decode_mb_cabac(h);\n                if(ret>=0) hl_decode_mb(h);\n                s->mb_y--;\n            }\n            eos = get_cabac_terminate( &h->cabac );\n            if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) {\n                av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                return -1;\n            }\n            if( ++s->mb_x >= s->mb_width ) {\n                s->mb_x = 0;\n                ff_draw_horiz_band(s, 16*s->mb_y, 16);\n                ++s->mb_y;\n                if(FIELD_OR_MBAFF_PICTURE) {\n                    ++s->mb_y;\n                }\n            }\n            if( eos || s->mb_y >= s->mb_height ) {\n                tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                return 0;\n            }\n        }\n    } else {\n        for(;;){\n            int ret = decode_mb_cavlc(h);\n            if(ret>=0) hl_decode_mb(h);\n            if(ret>=0 && FRAME_MBAFF){\n                s->mb_y++;\n                ret = decode_mb_cavlc(h);\n                if(ret>=0) hl_decode_mb(h);\n                s->mb_y--;\n            }\n            if(ret<0){\n                av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                return -1;\n            }\n            if(++s->mb_x >= s->mb_width){\n                s->mb_x=0;\n                ff_draw_horiz_band(s, 16*s->mb_y, 16);\n                ++s->mb_y;\n                if(FIELD_OR_MBAFF_PICTURE) {\n                    ++s->mb_y;\n                }\n                if(s->mb_y >= s->mb_height){\n                    tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n                    if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return 0;\n                    }else{\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return -1;\n                    }\n                }\n            }\n            if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){\n                tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n                if(get_bits_count(&s->gb) == s->gb.size_in_bits ){\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                    return 0;\n                }else{\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                    return -1;\n                }\n            }\n        }\n    }\n#if 0\n    for(;s->mb_y < s->mb_height; s->mb_y++){\n        for(;s->mb_x < s->mb_width; s->mb_x++){\n            int ret= decode_mb(h);\n            hl_decode_mb(h);\n            if(ret<0){\n                av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                return -1;\n            }\n            if(++s->mb_x >= s->mb_width){\n                s->mb_x=0;\n                if(++s->mb_y >= s->mb_height){\n                    if(get_bits_count(s->gb) == s->gb.size_in_bits){\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return 0;\n                    }else{\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return -1;\n                    }\n                }\n            }\n            if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){\n                if(get_bits_count(s->gb) == s->gb.size_in_bits){\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                    return 0;\n                }else{\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                    return -1;\n                }\n            }\n        }\n        s->mb_x=0;\n        ff_draw_horiz_band(s, 16*s->mb_y, 16);\n    }\n#endif\n    return -1;\n}', 'static int decode_mb_cabac(H264Context *h) {\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;\n    int mb_type, partition_count, cbp = 0;\n    int dct8x8_allowed= h->pps.transform_8x8_mode;\n    s->dsp.clear_blocks(h->mb);\n    tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n    if( h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE ) {\n        int skip;\n        if( FRAME_MBAFF && s->mb_x==0 && (s->mb_y&1)==0 )\n            predict_field_decoding_flag(h);\n        if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )\n            skip = h->next_mb_skipped;\n        else\n            skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );\n        if( skip ) {\n            if( FRAME_MBAFF && (s->mb_y&1)==0 ){\n                s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP;\n                h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );\n                if(h->next_mb_skipped)\n                    predict_field_decoding_flag(h);\n                else\n                    h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n            }\n            decode_mb_skip(h);\n            h->cbp_table[mb_xy] = 0;\n            h->chroma_pred_mode_table[mb_xy] = 0;\n            h->last_qscale_diff = 0;\n            return 0;\n        }\n    }\n    if(FRAME_MBAFF){\n        if( (s->mb_y&1) == 0 )\n            h->mb_mbaff =\n            h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n    }else\n        h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);\n    h->prev_mb_skipped = 0;\n    compute_mb_neighbors(h);\n    if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) {\n        av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\\n" );\n        return -1;\n    }\n    if( h->slice_type == FF_B_TYPE ) {\n        if( mb_type < 23 ){\n            partition_count= b_mb_type_info[mb_type].partition_count;\n            mb_type=         b_mb_type_info[mb_type].type;\n        }else{\n            mb_type -= 23;\n            goto decode_intra_mb;\n        }\n    } else if( h->slice_type == FF_P_TYPE ) {\n        if( mb_type < 5) {\n            partition_count= p_mb_type_info[mb_type].partition_count;\n            mb_type=         p_mb_type_info[mb_type].type;\n        } else {\n            mb_type -= 5;\n            goto decode_intra_mb;\n        }\n    } else {\n       assert(h->slice_type == FF_I_TYPE);\ndecode_intra_mb:\n        partition_count = 0;\n        cbp= i_mb_type_info[mb_type].cbp;\n        h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n        mb_type= i_mb_type_info[mb_type].type;\n    }\n    if(MB_FIELD)\n        mb_type |= MB_TYPE_INTERLACED;\n    h->slice_table[ mb_xy ]= h->slice_num;\n    if(IS_INTRA_PCM(mb_type)) {\n        const uint8_t *ptr;\n        unsigned int x, y;\n        ptr= h->cabac.bytestream;\n        if(h->cabac.low&0x1) ptr--;\n        if(CABAC_BITS==16){\n            if(h->cabac.low&0x1FF) ptr--;\n        }\n        for(y=0; y<16; y++){\n            const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);\n            for(x=0; x<16; x++){\n                tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\\n", *ptr);\n                h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++;\n            }\n        }\n        for(y=0; y<8; y++){\n            const int index= 256 + 4*(y&3) + 32*(y>>2);\n            for(x=0; x<8; x++){\n                tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\\n", *ptr);\n                h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;\n            }\n        }\n        for(y=0; y<8; y++){\n            const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);\n            for(x=0; x<8; x++){\n                tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\\n", *ptr);\n                h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;\n            }\n        }\n        ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n        h->cbp_table[mb_xy] = 0x1ef;\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        s->current_picture.qscale_table[mb_xy]= 0;\n        h->chroma_qp[0] = get_chroma_qp(h, 0, 0);\n        h->chroma_qp[1] = get_chroma_qp(h, 1, 0);\n        memset(h->non_zero_count[mb_xy], 16, 16);\n        s->current_picture.mb_type[mb_xy]= mb_type;\n        return 0;\n    }\n    if(MB_MBAFF){\n        h->ref_count[0] <<= 1;\n        h->ref_count[1] <<= 1;\n    }\n    fill_caches(h, mb_type, 0);\n    if( IS_INTRA( mb_type ) ) {\n        int i, pred_mode;\n        if( IS_INTRA4x4( mb_type ) ) {\n            if( dct8x8_allowed && decode_cabac_mb_transform_size( h ) ) {\n                mb_type |= MB_TYPE_8x8DCT;\n                for( i = 0; i < 16; i+=4 ) {\n                    int pred = pred_intra_mode( h, i );\n                    int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n                    fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n                }\n            } else {\n                for( i = 0; i < 16; i++ ) {\n                    int pred = pred_intra_mode( h, i );\n                    h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n                }\n            }\n            write_back_intra_pred_mode(h);\n            if( check_intra4x4_pred_mode(h) < 0 ) return -1;\n        } else {\n            h->intra16x16_pred_mode= check_intra_pred_mode( h, h->intra16x16_pred_mode );\n            if( h->intra16x16_pred_mode < 0 ) return -1;\n        }\n        h->chroma_pred_mode_table[mb_xy] =\n        pred_mode                        = decode_cabac_mb_chroma_pre_mode( h );\n        pred_mode= check_intra_pred_mode( h, pred_mode );\n        if( pred_mode < 0 ) return -1;\n        h->chroma_pred_mode= pred_mode;\n    } else if( partition_count == 4 ) {\n        int i, j, sub_partition_count[4], list, ref[2][4];\n        if( h->slice_type == FF_B_TYPE ) {\n            for( i = 0; i < 4; i++ ) {\n                h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );\n                sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n                h->sub_mb_type[i]=      b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n            }\n            if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |\n                          h->sub_mb_type[2] | h->sub_mb_type[3]) ) {\n                pred_direct_motion(h, &mb_type);\n                h->ref_cache[0][scan8[4]] =\n                h->ref_cache[1][scan8[4]] =\n                h->ref_cache[0][scan8[12]] =\n                h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n                if( h->ref_count[0] > 1 || h->ref_count[1] > 1 ) {\n                    for( i = 0; i < 4; i++ )\n                        if( IS_DIRECT(h->sub_mb_type[i]) )\n                            fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, 1, 1 );\n                }\n            }\n        } else {\n            for( i = 0; i < 4; i++ ) {\n                h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );\n                sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n                h->sub_mb_type[i]=      p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n            }\n        }\n        for( list = 0; list < h->list_count; list++ ) {\n                for( i = 0; i < 4; i++ ) {\n                    if(IS_DIRECT(h->sub_mb_type[i])) continue;\n                    if(IS_DIR(h->sub_mb_type[i], 0, list)){\n                        if( h->ref_count[list] > 1 )\n                            ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );\n                        else\n                            ref[list][i] = 0;\n                    } else {\n                        ref[list][i] = -1;\n                    }\n                                                       h->ref_cache[list][ scan8[4*i]+1 ]=\n                    h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n                }\n        }\n        if(dct8x8_allowed)\n            dct8x8_allowed = get_dct8x8_allowed(h);\n        for(list=0; list<h->list_count; list++){\n            for(i=0; i<4; i++){\n                h->ref_cache[list][ scan8[4*i]   ]=h->ref_cache[list][ scan8[4*i]+1 ];\n                if(IS_DIRECT(h->sub_mb_type[i])){\n                    fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4);\n                    continue;\n                }\n                if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){\n                    const int sub_mb_type= h->sub_mb_type[i];\n                    const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n                    for(j=0; j<sub_partition_count[i]; j++){\n                        int mpx, mpy;\n                        int mx, my;\n                        const int index= 4*i + block_width*j;\n                        int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n                        int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n                        pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy);\n                        mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 );\n                        my = mpy + decode_cabac_mb_mvd( h, list, index, 1 );\n                        tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                        if(IS_SUB_8X8(sub_mb_type)){\n                            mv_cache[ 1 ][0]=\n                            mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n                            mv_cache[ 1 ][1]=\n                            mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n                            mvd_cache[ 1 ][0]=\n                            mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mx - mpx;\n                            mvd_cache[ 1 ][1]=\n                            mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= my - mpy;\n                        }else if(IS_SUB_8X4(sub_mb_type)){\n                            mv_cache[ 1 ][0]= mx;\n                            mv_cache[ 1 ][1]= my;\n                            mvd_cache[ 1 ][0]= mx - mpx;\n                            mvd_cache[ 1 ][1]= my - mpy;\n                        }else if(IS_SUB_4X8(sub_mb_type)){\n                            mv_cache[ 8 ][0]= mx;\n                            mv_cache[ 8 ][1]= my;\n                            mvd_cache[ 8 ][0]= mx - mpx;\n                            mvd_cache[ 8 ][1]= my - mpy;\n                        }\n                        mv_cache[ 0 ][0]= mx;\n                        mv_cache[ 0 ][1]= my;\n                        mvd_cache[ 0 ][0]= mx - mpx;\n                        mvd_cache[ 0 ][1]= my - mpy;\n                    }\n                }else{\n                    uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];\n                    uint32_t *pd= (uint32_t *)&h->mvd_cache[list][ scan8[4*i] ][0];\n                    p[0] = p[1] = p[8] = p[9] = 0;\n                    pd[0]= pd[1]= pd[8]= pd[9]= 0;\n                }\n            }\n        }\n    } else if( IS_DIRECT(mb_type) ) {\n        pred_direct_motion(h, &mb_type);\n        fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4);\n        fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4);\n        dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n    } else {\n        int list, mx, my, i, mpx, mpy;\n        if(IS_16X16(mb_type)){\n            for(list=0; list<h->list_count; list++){\n                if(IS_DIR(mb_type, 0, list)){\n                        const int ref = h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 0 ) : 0;\n                        fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n                }else\n                    fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1);\n            }\n            for(list=0; list<h->list_count; list++){\n                if(IS_DIR(mb_type, 0, list)){\n                    pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy);\n                    mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 );\n                    my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 );\n                    tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                    fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx-mpx,my-mpy), 4);\n                    fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n                }else\n                    fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4);\n            }\n        }\n        else if(IS_16X8(mb_type)){\n            for(list=0; list<h->list_count; list++){\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0;\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n                        }else\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for(list=0; list<h->list_count; list++){\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy);\n                        mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 );\n                        my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 );\n                        tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4);\n                        fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n                        fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n                    }\n                }\n            }\n        }else{\n            assert(IS_8X16(mb_type));\n            for(list=0; list<h->list_count; list++){\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0;\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n                        }else\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for(list=0; list<h->list_count; list++){\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy);\n                        mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 );\n                        my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 );\n                        tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4);\n                        fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n                        fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n                    }\n                }\n            }\n        }\n    }\n   if( IS_INTER( mb_type ) ) {\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        write_back_motion( h, mb_type );\n   }\n    if( !IS_INTRA16x16( mb_type ) ) {\n        cbp  = decode_cabac_mb_cbp_luma( h );\n        cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;\n    }\n    h->cbp_table[mb_xy] = h->cbp = cbp;\n    if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n        if( decode_cabac_mb_transform_size( h ) )\n            mb_type |= MB_TYPE_8x8DCT;\n    }\n    s->current_picture.mb_type[mb_xy]= mb_type;\n    if( cbp || IS_INTRA16x16( mb_type ) ) {\n        const uint8_t *scan, *scan8x8, *dc_scan;\n        const uint32_t *qmul;\n        int dqp;\n        if(IS_INTERLACED(mb_type)){\n            scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n            scan= s->qscale ? h->field_scan : h->field_scan_q0;\n            dc_scan= luma_dc_field_scan;\n        }else{\n            scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n            scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n            dc_scan= luma_dc_zigzag_scan;\n        }\n        h->last_qscale_diff = dqp = decode_cabac_mb_dqp( h );\n        if( dqp == INT_MIN ){\n            av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", s->mb_x, s->mb_y);\n            return -1;\n        }\n        s->qscale += dqp;\n        if(((unsigned)s->qscale) > 51){\n            if(s->qscale<0) s->qscale+= 52;\n            else            s->qscale-= 52;\n        }\n        h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n        h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n        if( IS_INTRA16x16( mb_type ) ) {\n            int i;\n            decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16);\n            if( cbp&15 ) {\n                qmul = h->dequant4_coeff[0][s->qscale];\n                for( i = 0; i < 16; i++ ) {\n                    decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15);\n                }\n            } else {\n                fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);\n            }\n        } else {\n            int i8x8, i4x4;\n            for( i8x8 = 0; i8x8 < 4; i8x8++ ) {\n                if( cbp & (1<<i8x8) ) {\n                    if( IS_8x8DCT(mb_type) ) {\n                        decode_cabac_residual(h, h->mb + 64*i8x8, 5, 4*i8x8,\n                            scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64);\n                    } else {\n                        qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale];\n                        for( i4x4 = 0; i4x4 < 4; i4x4++ ) {\n                            const int index = 4*i8x8 + i4x4;\n                            decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, qmul, 16);\n                        }\n                    }\n                } else {\n                    uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];\n                    nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;\n                }\n            }\n        }\n        if( cbp&0x30 ){\n            int c;\n            for( c = 0; c < 2; c++ ) {\n                decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4);\n            }\n        }\n        if( cbp&0x20 ) {\n            int c, i;\n            for( c = 0; c < 2; c++ ) {\n                qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n                for( i = 0; i < 4; i++ ) {\n                    const int index = 16 + 4 * c + i;\n                    decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, qmul, 15);\n                }\n            }\n        } else {\n            uint8_t * const nnz= &h->non_zero_count_cache[0];\n            nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n            nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n        }\n    } else {\n        uint8_t * const nnz= &h->non_zero_count_cache[0];\n        fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);\n        nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n        nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n        h->last_qscale_diff = 0;\n    }\n    s->current_picture.qscale_table[mb_xy]= s->qscale;\n    write_back_non_zero_count(h);\n    if(MB_MBAFF){\n        h->ref_count[0] >>= 1;\n        h->ref_count[1] >>= 1;\n    }\n    return 0;\n}', 'static void hl_decode_mb(H264Context *h){\n    MpegEncContext * const s = &h->s;\n    const int mb_x= s->mb_x;\n    const int mb_y= s->mb_y;\n    const int mb_xy= mb_x + mb_y*s->mb_stride;\n    const int mb_type= s->current_picture.mb_type[mb_xy];\n    int is_complex = FRAME_MBAFF || MB_FIELD || IS_INTRA_PCM(mb_type) || s->codec_id != CODEC_ID_H264 || (ENABLE_GRAY && (s->flags&CODEC_FLAG_GRAY)) || s->encoding;\n    if(!s->decode)\n        return;\n    if (is_complex)\n        hl_decode_mb_complex(h);\n    else hl_decode_mb_simple(h);\n}', 'static void av_noinline hl_decode_mb_complex(H264Context *h){\n    hl_decode_mb_internal(h, 0);\n}', 'static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){\n    MpegEncContext * const s = &h->s;\n    const int mb_x= s->mb_x;\n    const int mb_y= s->mb_y;\n    const int mb_xy= mb_x + mb_y*s->mb_stride;\n    const int mb_type= s->current_picture.mb_type[mb_xy];\n    uint8_t  *dest_y, *dest_cb, *dest_cr;\n    int linesize, uvlinesize  ;\n    int i;\n    int *block_offset = &h->block_offset[0];\n    const unsigned int bottom = mb_y & 1;\n    const int transform_bypass = (s->qscale == 0 && h->sps.transform_bypass), is_h264 = (simple || s->codec_id == CODEC_ID_H264);\n    void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);\n    void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);\n    dest_y  = s->current_picture.data[0] + (mb_y * 16* s->linesize  ) + mb_x * 16;\n    dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;\n    dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;\n    s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + 64, s->linesize, 4);\n    s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + 64, dest_cr - dest_cb, 2);\n    if (!simple && MB_FIELD) {\n        linesize   = h->mb_linesize   = s->linesize * 2;\n        uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;\n        block_offset = &h->block_offset[24];\n        if(mb_y&1){\n            dest_y -= s->linesize*15;\n            dest_cb-= s->uvlinesize*7;\n            dest_cr-= s->uvlinesize*7;\n        }\n        if(FRAME_MBAFF) {\n            int list;\n            for(list=0; list<h->list_count; list++){\n                if(!USES_LIST(mb_type, list))\n                    continue;\n                if(IS_16X16(mb_type)){\n                    int8_t *ref = &h->ref_cache[list][scan8[0]];\n                    fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1);\n                }else{\n                    for(i=0; i<16; i+=4){\n                        int ref = h->ref_cache[list][scan8[i]];\n                        if(ref >= 0)\n                            fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1);\n                    }\n                }\n            }\n        }\n    } else {\n        linesize   = h->mb_linesize   = s->linesize;\n        uvlinesize = h->mb_uvlinesize = s->uvlinesize;\n    }\n    if(transform_bypass){\n        idct_dc_add =\n        idct_add = IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4;\n    }else if(IS_8x8DCT(mb_type)){\n        idct_dc_add = s->dsp.h264_idct8_dc_add;\n        idct_add = s->dsp.h264_idct8_add;\n    }else{\n        idct_dc_add = s->dsp.h264_idct_dc_add;\n        idct_add = s->dsp.h264_idct_add;\n    }\n    if(!simple && FRAME_MBAFF && h->deblocking_filter && IS_INTRA(mb_type)\n       && (!bottom || !IS_INTRA(s->current_picture.mb_type[mb_xy-s->mb_stride]))){\n        int mbt_y = mb_y&~1;\n        uint8_t *top_y  = s->current_picture.data[0] + (mbt_y * 16* s->linesize  ) + mb_x * 16;\n        uint8_t *top_cb = s->current_picture.data[1] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;\n        uint8_t *top_cr = s->current_picture.data[2] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;\n        xchg_pair_border(h, top_y, top_cb, top_cr, s->linesize, s->uvlinesize, 1);\n    }\n    if (!simple && IS_INTRA_PCM(mb_type)) {\n        unsigned int x, y;\n        for(i=0; i<16; i++) {\n            for (y=0; y<4; y++) {\n                for (x=0; x<4; x++) {\n                    *(dest_y + block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x];\n                }\n            }\n        }\n        for(i=16; i<16+4; i++) {\n            for (y=0; y<4; y++) {\n                for (x=0; x<4; x++) {\n                    *(dest_cb + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];\n                }\n            }\n        }\n        for(i=20; i<20+4; i++) {\n            for (y=0; y<4; y++) {\n                for (x=0; x<4; x++) {\n                    *(dest_cr + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];\n                }\n            }\n        }\n    } else {\n        if(IS_INTRA(mb_type)){\n            if(h->deblocking_filter && (simple || !FRAME_MBAFF))\n                xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple);\n            if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){\n                h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);\n                h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);\n            }\n            if(IS_INTRA4x4(mb_type)){\n                if(simple || !s->encoding){\n                    if(IS_8x8DCT(mb_type)){\n                        for(i=0; i<16; i+=4){\n                            uint8_t * const ptr= dest_y + block_offset[i];\n                            const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];\n                            const int nnz = h->non_zero_count_cache[ scan8[i] ];\n                            h->hpc.pred8x8l[ dir ](ptr, (h->topleft_samples_available<<i)&0x8000,\n                                                   (h->topright_samples_available<<i)&0x4000, linesize);\n                            if(nnz){\n                                if(nnz == 1 && h->mb[i*16])\n                                    idct_dc_add(ptr, h->mb + i*16, linesize);\n                                else\n                                    idct_add(ptr, h->mb + i*16, linesize);\n                            }\n                        }\n                    }else\n                    for(i=0; i<16; i++){\n                        uint8_t * const ptr= dest_y + block_offset[i];\n                        uint8_t *topright;\n                        const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];\n                        int nnz, tr;\n                        if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){\n                            const int topright_avail= (h->topright_samples_available<<i)&0x8000;\n                            assert(mb_y || linesize <= block_offset[i]);\n                            if(!topright_avail){\n                                tr= ptr[3 - linesize]*0x01010101;\n                                topright= (uint8_t*) &tr;\n                            }else\n                                topright= ptr + 4 - linesize;\n                        }else\n                            topright= NULL;\n                        h->hpc.pred4x4[ dir ](ptr, topright, linesize);\n                        nnz = h->non_zero_count_cache[ scan8[i] ];\n                        if(nnz){\n                            if(is_h264){\n                                if(nnz == 1 && h->mb[i*16])\n                                    idct_dc_add(ptr, h->mb + i*16, linesize);\n                                else\n                                    idct_add(ptr, h->mb + i*16, linesize);\n                            }else\n                                svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0);\n                        }\n                    }\n                }\n            }else{\n                h->hpc.pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize);\n                if(is_h264){\n                    if(!transform_bypass)\n                        h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[0][s->qscale][0]);\n                }else\n                    svq3_luma_dc_dequant_idct_c(h->mb, s->qscale);\n            }\n            if(h->deblocking_filter && (simple || !FRAME_MBAFF))\n                xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple);\n        }else if(is_h264){\n            hl_motion(h, dest_y, dest_cb, dest_cr,\n                      s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n                      s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n                      s->dsp.weight_h264_pixels_tab, s->dsp.biweight_h264_pixels_tab);\n        }\n        if(!IS_INTRA4x4(mb_type)){\n            if(is_h264){\n                if(IS_INTRA16x16(mb_type)){\n                    for(i=0; i<16; i++){\n                        if(h->non_zero_count_cache[ scan8[i] ])\n                            idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);\n                        else if(h->mb[i*16])\n                            idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);\n                    }\n                }else{\n                    const int di = IS_8x8DCT(mb_type) ? 4 : 1;\n                    for(i=0; i<16; i+=di){\n                        int nnz = h->non_zero_count_cache[ scan8[i] ];\n                        if(nnz){\n                            if(nnz==1 && h->mb[i*16])\n                                idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);\n                            else\n                                idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);\n                        }\n                    }\n                }\n            }else{\n                for(i=0; i<16; i++){\n                    if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){\n                        uint8_t * const ptr= dest_y + block_offset[i];\n                        svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0);\n                    }\n                }\n            }\n        }\n        if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){\n            uint8_t *dest[2] = {dest_cb, dest_cr};\n            if(transform_bypass){\n                idct_add = idct_dc_add = s->dsp.add_pixels4;\n            }else{\n                idct_add = s->dsp.h264_idct_add;\n                idct_dc_add = s->dsp.h264_idct_dc_add;\n                chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);\n                chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);\n            }\n            if(is_h264){\n                for(i=16; i<16+8; i++){\n                    if(h->non_zero_count_cache[ scan8[i] ])\n                        idct_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize);\n                    else if(h->mb[i*16])\n                        idct_dc_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize);\n                }\n            }else{\n                for(i=16; i<16+8; i++){\n                    if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){\n                        uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i];\n                        svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);\n                    }\n                }\n            }\n        }\n    }\n    if(h->deblocking_filter) {\n        if (!simple && FRAME_MBAFF) {\n            const int mb_y = s->mb_y - 1;\n            uint8_t  *pair_dest_y, *pair_dest_cb, *pair_dest_cr;\n            const int mb_xy= mb_x + mb_y*s->mb_stride;\n            const int mb_type_top   = s->current_picture.mb_type[mb_xy];\n            const int mb_type_bottom= s->current_picture.mb_type[mb_xy+s->mb_stride];\n            if (!bottom) return;\n            pair_dest_y  = s->current_picture.data[0] + (mb_y * 16* s->linesize  ) + mb_x * 16;\n            pair_dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;\n            pair_dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;\n            if(IS_INTRA(mb_type_top | mb_type_bottom))\n                xchg_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize, 0);\n            backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize);\n            s->mb_y--;\n            tprintf(h->s.avctx, "call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\\n", mb_x, mb_y, pair_dest_y, dest_y);\n            fill_caches(h, mb_type_top, 1);\n            h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]);\n            h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]);\n            filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);\n            s->mb_y++;\n            tprintf(h->s.avctx, "call mbaff filter_mb\\n");\n            fill_caches(h, mb_type_bottom, 1);\n            h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy+s->mb_stride]);\n            h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy+s->mb_stride]);\n            filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);\n        } else {\n            tprintf(h->s.avctx, "call filter_mb\\n");\n            backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simple);\n            fill_caches(h, mb_type, 1);\n            filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);\n        }\n    }\n}']