Revision dc172ecc libavcodec/h264_cabac.c

View differences:

libavcodec/h264_cabac.c
1105 1105

  
1106 1106
        int j= scantable[index[--coeff_count]];
1107 1107

  
1108
        if( get_cabac( CC, ctx ) == 0 ) {
1109
            node_ctx = coeff_abs_level_transition[0][node_ctx];
1110
            if( is_dc ) {
1111
                block[j] = get_cabac_bypass_sign( CC, -1);
1112
            }else{
1113
                block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6;
1114
            }
1115
        } else {
1116
            int coeff_abs = 2;
1117
            ctx = coeff_abs_levelgt1_ctx[node_ctx] + abs_level_m1_ctx_base;
1118
            node_ctx = coeff_abs_level_transition[1][node_ctx];
1119

  
1120
            while( coeff_abs < 15 && get_cabac( CC, ctx ) ) {
1121
                coeff_abs++;
1122
            }
1123

  
1124
            if( coeff_abs >= 15 ) {
1125
                int j = 0;
1126
                while( get_cabac_bypass( CC ) ) {
1127
                    j++;
1128
                }
1129

  
1130
                coeff_abs=1;
1131
                while( j-- ) {
1132
                    coeff_abs += coeff_abs + get_cabac_bypass( CC );
1133
                }
1134
                coeff_abs+= 14;
1135
            }
1108
#define STORE_BLOCK(type) \
1109
        if( get_cabac( CC, ctx ) == 0 ) { \
1110
            node_ctx = coeff_abs_level_transition[0][node_ctx]; \
1111
            if( is_dc ) { \
1112
                ((type*)block)[j] = get_cabac_bypass_sign( CC, -1); \
1113
            }else{ \
1114
                ((type*)block)[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; \
1115
            } \
1116
        } else { \
1117
            int coeff_abs = 2; \
1118
            ctx = coeff_abs_levelgt1_ctx[node_ctx] + abs_level_m1_ctx_base; \
1119
            node_ctx = coeff_abs_level_transition[1][node_ctx]; \
1120
\
1121
            while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \
1122
                coeff_abs++; \
1123
            } \
1124
\
1125
            if( coeff_abs >= 15 ) { \
1126
                int j = 0; \
1127
                while( get_cabac_bypass( CC ) ) { \
1128
                    j++; \
1129
                } \
1130
\
1131
                coeff_abs=1; \
1132
                while( j-- ) { \
1133
                    coeff_abs += coeff_abs + get_cabac_bypass( CC ); \
1134
                } \
1135
                coeff_abs+= 14; \
1136
            } \
1137
\
1138
            if( is_dc ) { \
1139
                ((type*)block)[j] = get_cabac_bypass_sign( CC, -coeff_abs ); \
1140
            }else{ \
1141
                ((type*)block)[j] = ((int)(get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32)) >> 6; \
1142
            } \
1143
        }
1136 1144

  
1137
            if( is_dc ) {
1138
                block[j] = get_cabac_bypass_sign( CC, -coeff_abs );
1139
            }else{
1140
                block[j] = (get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32) >> 6;
1141
            }
1145
        if (h->pixel_size == 2) {
1146
            STORE_BLOCK(int32_t)
1147
        } else {
1148
            STORE_BLOCK(int16_t)
1142 1149
        }
1143 1150
    } while( coeff_count );
1144 1151
#ifdef CABAC_ON_STACK
......
1304 1311
    h->slice_table[ mb_xy ]= h->slice_num;
1305 1312

  
1306 1313
    if(IS_INTRA_PCM(mb_type)) {
1314
        const int mb_size = 384*h->sps.bit_depth_luma/8;
1307 1315
        const uint8_t *ptr;
1308 1316

  
1309 1317
        // We assume these blocks are very rare so we do not optimize it.
......
1316 1324
        }
1317 1325

  
1318 1326
        // The pixels are stored in the same order as levels in h->mb array.
1319
        memcpy(h->mb, ptr, 256); ptr+=256;
1327
        memcpy(h->mb, ptr, 2*mb_size/3); ptr+=2*mb_size/3;
1320 1328
        if(CHROMA){
1321
            memcpy(h->mb+128, ptr, 128); ptr+=128;
1329
            memcpy(h->mb+mb_size/3, ptr, mb_size/3); ptr+=mb_size/3;
1322 1330
        }
1323 1331

  
1324 1332
        ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
......
1652 1660
            //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" );
1653 1661
            AV_ZERO128(h->mb_luma_dc+0);
1654 1662
            AV_ZERO128(h->mb_luma_dc+8);
1663
            AV_ZERO128(h->mb_luma_dc+16);
1664
            AV_ZERO128(h->mb_luma_dc+24);
1655 1665
            decode_cabac_residual_dc( h, h->mb_luma_dc, 0, LUMA_DC_BLOCK_INDEX, scan, 16);
1656 1666

  
1657 1667
            if( cbp&15 ) {
1658 1668
                qmul = h->dequant4_coeff[0][s->qscale];
1659 1669
                for( i = 0; i < 16; i++ ) {
1660 1670
                    //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i );
1661
                    decode_cabac_residual_nondc(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15);
1671
                    decode_cabac_residual_nondc(h, h->mb + 16*i*h->pixel_size, 1, i, scan + 1, qmul, 15);
1662 1672
                }
1663 1673
            } else {
1664 1674
                fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);
......
1668 1678
            for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
1669 1679
                if( cbp & (1<<i8x8) ) {
1670 1680
                    if( IS_8x8DCT(mb_type) ) {
1671
                        decode_cabac_residual_nondc(h, h->mb + 64*i8x8, 5, 4*i8x8,
1681
                        decode_cabac_residual_nondc(h, h->mb + 64*i8x8*h->pixel_size, 5, 4*i8x8,
1672 1682
                            scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64);
1673 1683
                    } else {
1674 1684
                        qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale];
......
1676 1686
                            const int index = 4*i8x8 + i4x4;
1677 1687
                            //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index );
1678 1688
//START_TIMER
1679
                            decode_cabac_residual_nondc(h, h->mb + 16*index, 2, index, scan, qmul, 16);
1689
                            decode_cabac_residual_nondc(h, h->mb + 16*index*h->pixel_size, 2, index, scan, qmul, 16);
1680 1690
//STOP_TIMER("decode_residual")
1681 1691
                        }
1682 1692
                    }
......
1691 1701
            int c;
1692 1702
            for( c = 0; c < 2; c++ ) {
1693 1703
                //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
1694
                decode_cabac_residual_dc(h, h->mb + 256 + 16*4*c, 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);
1704
                decode_cabac_residual_dc(h, h->mb + (256 + 16*4*c)*h->pixel_size, 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);
1695 1705
            }
1696 1706
        }
1697 1707

  
......
1702 1712
                for( i = 0; i < 4; i++ ) {
1703 1713
                    const int index = 16 + 4 * c + i;
1704 1714
                    //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 );
1705
                    decode_cabac_residual_nondc(h, h->mb + 16*index, 4, index, scan + 1, qmul, 15);
1715
                    decode_cabac_residual_nondc(h, h->mb + 16*index*h->pixel_size, 4, index, scan + 1, qmul, 15);
1706 1716
                }
1707 1717
            }
1708 1718
        } else {

Also available in: Unified diff