1285
1285
unsigned long ctx = 0;
1287
ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy]>>7)&(h->slice_table[mba_xy] == h->slice_num);
1288
ctx += (s->current_picture.mb_type[mbb_xy]>>7)&(h->slice_table[mbb_xy] == h->slice_num);
1287
ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num);
1288
ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
1290
1290
return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] );
1330
1330
mba_xy = mb_xy - 1;
1332
1332
&& h->slice_table[mba_xy] == h->slice_num
1333
&& MB_FIELD == !!IS_INTERLACED( s->current_picture.mb_type[mba_xy] ) )
1333
&& MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) )
1334
1334
mba_xy += s->mb_stride;
1335
1335
if( MB_FIELD ){
1336
1336
mbb_xy = mb_xy - s->mb_stride;
1338
1338
&& h->slice_table[mbb_xy] == h->slice_num
1339
&& IS_INTERLACED( s->current_picture.mb_type[mbb_xy] ) )
1339
&& IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) )
1340
1340
mbb_xy -= s->mb_stride;
1342
1342
mbb_xy = mb_x + (mb_y-1)*s->mb_stride;
1346
1346
mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE);
1349
if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ))
1349
if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] ))
1351
if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ))
1351
if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] ))
1354
1354
if( h->slice_type_nos == AV_PICTURE_TYPE_B )
1378
1378
/* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */
1379
if( h->left_type[0] && h->chroma_pred_mode_table[mba_xy] != 0 )
1379
if( h->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0 )
1382
if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 )
1382
if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 )
1385
1385
if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 )
1565
1565
5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
1568
static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff, int is_dc ) {
1568
static av_always_inline void
1569
decode_cabac_residual_internal(H264Context *h, DCTELEM *block,
1570
int cat, int n, const uint8_t *scantable,
1571
const uint32_t *qmul, int max_coeff,
1572
int is_dc, int chroma422)
1569
1574
static const int significant_coeff_flag_offset[2][14] = {
1570
1575
{ 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718 },
1571
1576
{ 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733 }
1587
1592
9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
1588
1593
9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 }
1595
static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 };
1590
1596
/* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
1591
1597
* 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
1592
1598
* map node ctx => cabac ctx for level=1 */
1593
1599
static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 };
1594
1600
/* map node ctx => cabac ctx for level>1 */
1595
static const uint8_t coeff_abs_levelgt1_ctx[8] = { 5, 5, 5, 5, 6, 7, 8, 9 };
1601
static const uint8_t coeff_abs_levelgt1_ctx[2][8] = {
1602
{ 5, 5, 5, 5, 6, 7, 8, 9 },
1603
{ 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case
1596
1605
static const uint8_t coeff_abs_level_transition[2][8] = {
1597
1606
/* update node ctx after decoding a level=1 */
1598
1607
{ 1, 2, 3, 3, 4, 5, 6, 7 },
1647
1656
index[coeff_count++] = last;\
1649
1658
const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
1650
#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
1659
#if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
1651
1660
coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index,
1652
last_coeff_ctx_base-significant_coeff_ctx_base, sig_off);
1661
last_coeff_ctx_base, sig_off);
1654
coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index,
1655
last_coeff_ctx_base-significant_coeff_ctx_base);
1663
if (is_dc && chroma422) { // dc 422
1664
DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
1666
coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index,
1667
last_coeff_ctx_base-significant_coeff_ctx_base);
1657
1670
DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] );
1659
DECODE_SIGNIFICANCE( max_coeff - 1, last, last );
1672
if (is_dc && chroma422) { // dc 422
1673
DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
1675
DECODE_SIGNIFICANCE(max_coeff - 1, last, last);
1662
1679
assert(coeff_count > 0);
1735
1752
static void decode_cabac_residual_dc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) {
1736
decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1);
1753
decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0);
1756
static void decode_cabac_residual_dc_internal_422(H264Context *h, DCTELEM *block,
1757
int cat, int n, const uint8_t *scantable,
1760
decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1);
1739
1763
static void decode_cabac_residual_nondc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
1740
decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0);
1764
decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0);
1743
1767
/* cat: 0-> DC 16x16 n = 0
1761
1785
decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff );
1788
static av_always_inline void
1789
decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block,
1790
int cat, int n, const uint8_t *scantable,
1793
/* read coded block flag */
1794
if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) {
1795
h->non_zero_count_cache[scan8[n]] = 0;
1798
decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff);
1764
1801
static av_always_inline void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
1765
1802
/* read coded block flag */
1766
1803
if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
1821
uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8+16*p] ];
1822
nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
1858
fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);
1829
* decodes a macroblock
1830
* @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed
1865
* Decode a macroblock.
1866
* @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed
1832
1868
int ff_h264_decode_mb_cabac(H264Context *h) {
1833
1869
MpegEncContext * const s = &h->s;
1850
1886
/* read skip flags */
1852
1888
if( FRAME_MBAFF && (s->mb_y&1)==0 ){
1853
s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP;
1889
s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP;
1854
1890
h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );
1855
1891
if(!h->next_mb_skipped)
1856
1892
h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
1966
2002
h->cbp_table[mb_xy] = 0xf7ef;
1967
2003
h->chroma_pred_mode_table[mb_xy] = 0;
1968
2004
// In deblocking, the quantizer is 0
1969
s->current_picture.qscale_table[mb_xy]= 0;
2005
s->current_picture.f.qscale_table[mb_xy] = 0;
1970
2006
// All coeffs are present
1971
2007
memset(h->non_zero_count[mb_xy], 16, 48);
1972
s->current_picture.mb_type[mb_xy]= mb_type;
2008
s->current_picture.f.mb_type[mb_xy] = mb_type;
1973
2009
h->last_qscale_diff = 0;
1999
2035
//av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] );
2002
ff_h264_write_back_intra_pred_mode(h);
2038
write_back_intra_pred_mode(h);
2003
2039
if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;
2005
2041
h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode );
2248
2284
* the transform mode of the current macroblock there. */
2249
2285
if (CHROMA444 && IS_8x8DCT(mb_type)){
2287
uint8_t *nnz_cache = h->non_zero_count_cache;
2251
2288
for (i = 0; i < 2; i++){
2252
if (h->left_type[i] && !IS_8x8DCT(h->left_type[i])){
2253
h->non_zero_count_cache[3+8* 1 + 2*8*i]=
2254
h->non_zero_count_cache[3+8* 2 + 2*8*i]=
2255
h->non_zero_count_cache[3+8* 6 + 2*8*i]=
2256
h->non_zero_count_cache[3+8* 7 + 2*8*i]=
2257
h->non_zero_count_cache[3+8*11 + 2*8*i]=
2258
h->non_zero_count_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;
2289
if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){
2290
nnz_cache[3+8* 1 + 2*8*i]=
2291
nnz_cache[3+8* 2 + 2*8*i]=
2292
nnz_cache[3+8* 6 + 2*8*i]=
2293
nnz_cache[3+8* 7 + 2*8*i]=
2294
nnz_cache[3+8*11 + 2*8*i]=
2295
nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;
2261
2298
if (h->top_type && !IS_8x8DCT(h->top_type)){
2262
2299
uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
2263
AV_WN32A(&h->non_zero_count_cache[4+8* 0], top_empty);
2264
AV_WN32A(&h->non_zero_count_cache[4+8* 5], top_empty);
2265
AV_WN32A(&h->non_zero_count_cache[4+8*10], top_empty);
2300
AV_WN32A(&nnz_cache[4+8* 0], top_empty);
2301
AV_WN32A(&nnz_cache[4+8* 5], top_empty);
2302
AV_WN32A(&nnz_cache[4+8*10], top_empty);
2268
s->current_picture.mb_type[mb_xy]= mb_type;
2305
s->current_picture.f.mb_type[mb_xy] = mb_type;
2270
2307
if( cbp || IS_INTRA16x16( mb_type ) ) {
2271
2308
const uint8_t *scan, *scan8x8;
2314
2351
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);
2315
2352
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);
2353
} else if (CHROMA422) {
2356
for( c = 0; c < 2; c++ ) {
2357
//av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
2358
decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3,
2359
CHROMA_DC_BLOCK_INDEX + c,
2360
chroma422_dc_scan, 8);
2366
for( c = 0; c < 2; c++ ) {
2367
DCTELEM *mb = h->mb + (16*(16 + 16*c) << pixel_shift);
2368
qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
2369
for (i8x8 = 0; i8x8 < 2; i8x8++) {
2370
for (i = 0; i < 4; i++) {
2371
const int index = 16 + 16 * c + 8*i8x8 + i;
2372
//av_log(s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16);
2373
decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15);
2374
mb += 16<<pixel_shift;
2379
fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
2380
fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
2382
} else /* yuv420 */ {
2317
2383
if( cbp&0x30 ){
2319
2385
for( c = 0; c < 2; c++ ) {