diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2015-03-21 14:02:02 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-03-21 14:02:02 +0100 |
commit | b7e0356cc33297d8db12b56051841f914b6f1ba9 (patch) | |
tree | c520d2fee090f90cd02b1565dea019c23dabd6df | |
parent | 6ec279b54c09f47208930021a38a742f2cc09324 (diff) | |
parent | f69574cf7aca4fe4d57a2155e925f37fc863474d (diff) | |
download | ffmpeg-b7e0356cc33297d8db12b56051841f914b6f1ba9.tar.gz |
Merge commit 'f69574cf7aca4fe4d57a2155e925f37fc863474d'
* commit 'f69574cf7aca4fe4d57a2155e925f37fc863474d':
h264: move non_zero_count_cache into the per-slice context
Conflicts:
libavcodec/h264.c
libavcodec/h264_cabac.c
libavcodec/h264_cavlc.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/h264.c | 3 | ||||
-rw-r--r-- | libavcodec/h264.h | 17 | ||||
-rw-r--r-- | libavcodec/h264_cabac.c | 90 | ||||
-rw-r--r-- | libavcodec/h264_cavlc.c | 51 | ||||
-rw-r--r-- | libavcodec/h264_loopfilter.c | 22 | ||||
-rw-r--r-- | libavcodec/h264_mb.c | 18 | ||||
-rw-r--r-- | libavcodec/h264_mb_template.c | 12 | ||||
-rw-r--r-- | libavcodec/h264_mvpred.h | 2 | ||||
-rw-r--r-- | libavcodec/h264_slice.c | 2 | ||||
-rw-r--r-- | libavcodec/svq3.c | 6 |
10 files changed, 120 insertions, 103 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 0a01237113..b48d660f32 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -64,11 +64,12 @@ static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, int mb_x, int mb_y, int mb_intra, int mb_skipped) { H264Context *h = opaque; + H264SliceContext *sl = &h->slice_ctx[0]; h->mb_x = mb_x; h->mb_y = mb_y; h->mb_xy = mb_x + mb_y * h->mb_stride; - memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache)); + memset(sl->non_zero_count_cache, 0, sizeof(sl->non_zero_count_cache)); av_assert1(ref >= 0); /* FIXME: It is possible albeit uncommon that slice references * differ between slices. We take the easy approach and ignore diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 54a69f40aa..6f7421af37 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -378,6 +378,12 @@ typedef struct H264SliceContext { unsigned int top_samples_available; unsigned int topright_samples_available; unsigned int left_samples_available; + + /** + * non zero coeff count cache. + * is 64 if not available. + */ + DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8]; } H264SliceContext; /** @@ -420,12 +426,6 @@ typedef struct H264Context { H264PredContext hpc; uint8_t (*top_borders[2])[(16 * 3) * 2]; - /** - * non zero coeff count cache. - * is 64 if not available. - */ - DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8]; - uint8_t (*non_zero_count)[48]; /** @@ -1017,11 +1017,12 @@ static av_always_inline void write_back_intra_pred_mode(H264Context *h, i4x4[6] = i4x4_cache[7 + 8 * 1]; } -static av_always_inline void write_back_non_zero_count(H264Context *h) +static av_always_inline void write_back_non_zero_count(H264Context *h, + H264SliceContext *sl) { const int mb_xy = h->mb_xy; uint8_t *nnz = h->non_zero_count[mb_xy]; - uint8_t *nnz_cache = h->non_zero_count_cache; + uint8_t *nnz_cache = sl->non_zero_count_cache; AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]); AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]); diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index 831c5934e0..0bc4076729 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -1534,7 +1534,10 @@ static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\ } -static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int max_coeff, int is_dc ) { +static av_always_inline int get_cabac_cbf_ctx(H264Context *h, H264SliceContext *sl, + int cat, int idx, int max_coeff, + int is_dc) +{ int nza, nzb; int ctx = 0; static const uint16_t base_ctx[14] = {85,89,93,97,101,1012,460,464,468,1016,472,476,480,1020}; @@ -1550,8 +1553,8 @@ static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, nzb = h-> top_cbp&(0x100<<idx); } } else { - nza = h->non_zero_count_cache[scan8[idx] - 1]; - nzb = h->non_zero_count_cache[scan8[idx] - 8]; + nza = sl->non_zero_count_cache[scan8[idx] - 1]; + nzb = sl->non_zero_count_cache[scan8[idx] - 8]; } if( nza > 0 ) @@ -1564,7 +1567,8 @@ static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, } static av_always_inline void -decode_cabac_residual_internal(H264Context *h, int16_t *block, +decode_cabac_residual_internal(H264Context *h, H264SliceContext *sl, + int16_t *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff, int is_dc, int chroma422) @@ -1684,13 +1688,13 @@ decode_cabac_residual_internal(H264Context *h, int16_t *block, h->cbp_table[h->mb_xy] |= 0x40 << (n - CHROMA_DC_BLOCK_INDEX); else h->cbp_table[h->mb_xy] |= 0x100 << (n - LUMA_DC_BLOCK_INDEX); - h->non_zero_count_cache[scan8[n]] = coeff_count; + sl->non_zero_count_cache[scan8[n]] = coeff_count; } else { if( max_coeff == 64 ) - fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1); else { av_assert2( cat == 1 || cat == 2 || cat == 4 || cat == 7 || cat == 8 || cat == 11 || cat == 12 ); - h->non_zero_count_cache[scan8[n]] = coeff_count; + sl->non_zero_count_cache[scan8[n]] = coeff_count; } } @@ -1751,31 +1755,34 @@ decode_cabac_residual_internal(H264Context *h, int16_t *block, } static av_noinline void decode_cabac_residual_dc_internal(H264Context *h, + H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff) { - decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0); + decode_cabac_residual_internal(h, sl, block, cat, n, scantable, NULL, max_coeff, 1, 0); } static av_noinline void decode_cabac_residual_dc_internal_422(H264Context *h, + H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff) { - decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1); + decode_cabac_residual_internal(h, sl, block, cat, n, scantable, NULL, max_coeff, 1, 1); } static av_noinline void decode_cabac_residual_nondc_internal(H264Context *h, + H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff) { - decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0); + decode_cabac_residual_internal(h, sl, block, cat, n, scantable, qmul, max_coeff, 0, 0); } /* cat: 0-> DC 16x16 n = 0 @@ -1791,33 +1798,36 @@ static av_noinline void decode_cabac_residual_nondc_internal(H264Context *h, * as well as because most blocks have zero CBFs. */ static av_always_inline void decode_cabac_residual_dc(H264Context *h, + H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff) { /* read coded block flag */ - if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 1 ) ] ) == 0 ) { - h->non_zero_count_cache[scan8[n]] = 0; + if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, sl, cat, n, max_coeff, 1)]) == 0 ) { + sl->non_zero_count_cache[scan8[n]] = 0; return; } - decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff ); + decode_cabac_residual_dc_internal(h, sl, block, cat, n, scantable, max_coeff); } static av_always_inline void -decode_cabac_residual_dc_422(H264Context *h, int16_t *block, +decode_cabac_residual_dc_422(H264Context *h, H264SliceContext *sl, + int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff) { /* read coded block flag */ - if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) { - h->non_zero_count_cache[scan8[n]] = 0; + if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, sl, cat, n, max_coeff, 1)]) == 0) { + sl->non_zero_count_cache[scan8[n]] = 0; return; } - decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff); + decode_cabac_residual_dc_internal_422(h, sl, block, cat, n, scantable, max_coeff); } static av_always_inline void decode_cabac_residual_nondc(H264Context *h, + H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, @@ -1825,15 +1835,15 @@ static av_always_inline void decode_cabac_residual_nondc(H264Context *h, int max_coeff) { /* read coded block flag */ - if( (cat != 5 || CHROMA444(h)) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) { + if( (cat != 5 || CHROMA444(h)) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, sl, cat, n, max_coeff, 0)]) == 0) { if( max_coeff == 64 ) { - fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1); } else { - h->non_zero_count_cache[scan8[n]] = 0; + sl->non_zero_count_cache[scan8[n]] = 0; } return; } - decode_cabac_residual_nondc_internal( h, block, cat, n, scantable, qmul, max_coeff ); + decode_cabac_residual_nondc_internal(h, sl, block, cat, n, scantable, qmul, max_coeff); } static av_always_inline void decode_cabac_luma_residual(H264Context *h, H264SliceContext *sl, @@ -1849,16 +1859,16 @@ static av_always_inline void decode_cabac_luma_residual(H264Context *h, H264Slic AV_ZERO128(h->mb_luma_dc[p]+8); AV_ZERO128(h->mb_luma_dc[p]+16); AV_ZERO128(h->mb_luma_dc[p]+24); - decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16); + decode_cabac_residual_dc(h, sl, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16); if( cbp&15 ) { qmul = h->dequant4_coeff[p][qscale]; for( i4x4 = 0; i4x4 < 16; i4x4++ ) { const int index = 16*p + i4x4; - decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15); + decode_cabac_residual_nondc(h, sl, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15); } } else { - fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1); } } else { int cqm = (IS_INTRA( mb_type ) ? 0:3) + p; @@ -1866,19 +1876,19 @@ static av_always_inline void decode_cabac_luma_residual(H264Context *h, H264Slic if( cbp & (1<<i8x8) ) { if( IS_8x8DCT(mb_type) ) { const int index = 16*p + 4*i8x8; - decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index, + decode_cabac_residual_nondc(h, sl, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index, scan8x8, h->dequant8_coeff[cqm][qscale], 64); } else { qmul = h->dequant4_coeff[cqm][qscale]; for( i4x4 = 0; i4x4 < 4; i4x4++ ) { const int index = 16*p + 4*i8x8 + i4x4; //START_TIMER - decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16); + decode_cabac_residual_nondc(h, sl, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16); //STOP_TIMER("decode_residual") } } } else { - fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1); } } } @@ -2315,7 +2325,7 @@ decode_intra_mb: * the transform mode of the current macroblock there. */ if (CHROMA444(h) && IS_8x8DCT(mb_type)){ int i; - uint8_t *nnz_cache = h->non_zero_count_cache; + uint8_t *nnz_cache = sl->non_zero_count_cache; for (i = 0; i < 2; i++){ if (sl->left_type[LEFT(i)] && !IS_8x8DCT(sl->left_type[LEFT(i)])) { nnz_cache[3+8* 1 + 2*8*i]= @@ -2385,7 +2395,7 @@ decode_intra_mb: if( cbp&0x30 ){ int c; for (c = 0; c < 2; c++) - decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, + decode_cabac_residual_dc_422(h, sl, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX + c, chroma422_dc_scan, 8); } @@ -2398,20 +2408,20 @@ decode_intra_mb: for (i8x8 = 0; i8x8 < 2; i8x8++) { for (i = 0; i < 4; i++) { const int index = 16 + 16 * c + 8*i8x8 + i; - decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15); + decode_cabac_residual_nondc(h, sl, mb, 4, index, scan + 1, qmul, 15); mb += 16<<pixel_shift; } } } } else { - fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } } else /* yuv420 */ { if( cbp&0x30 ){ int c; for (c = 0; c < 2; c++) - decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4); + decode_cabac_residual_dc(h, sl, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4); } if( cbp&0x20 ) { @@ -2420,23 +2430,23 @@ decode_intra_mb: qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[c]]; for( i = 0; i < 4; i++ ) { const int index = 16 + 16 * c + i; - decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15); + decode_cabac_residual_nondc(h, sl, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15); } } } else { - fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } } } else { - fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); h->last_qscale_diff = 0; } h->cur_pic.qscale_table[mb_xy] = sl->qscale; - write_back_non_zero_count(h); + write_back_non_zero_count(h, sl); return 0; } diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index a08f8f4e1a..2d948b3259 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -284,10 +284,11 @@ static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2]; * Get the predicted number of non-zero coefficients. * @param n block index */ -static inline int pred_non_zero_count(H264Context *h, int n){ +static inline int pred_non_zero_count(H264Context *h, H264SliceContext *sl, int n) +{ const int index8= scan8[n]; - const int left= h->non_zero_count_cache[index8 - 1]; - const int top = h->non_zero_count_cache[index8 - 8]; + const int left = sl->non_zero_count_cache[index8 - 1]; + const int top = sl->non_zero_count_cache[index8 - 8]; int i= left + top; if(i<64) i= (i+1)>>1; @@ -442,7 +443,11 @@ static inline int get_level_prefix(GetBitContext *gb){ * @param max_coeff number of coefficients in the block * @return <0 if an error occurred */ -static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ +static int decode_residual(H264Context *h, H264SliceContext *sl, + GetBitContext *gb, int16_t *block, int n, + const uint8_t *scantable, const uint32_t *qmul, + int max_coeff) +{ static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; int level[16]; int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before; @@ -457,16 +462,16 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in total_coeff= coeff_token>>2; }else{ if(n >= LUMA_DC_BLOCK_INDEX){ - total_coeff= pred_non_zero_count(h, (n - LUMA_DC_BLOCK_INDEX)*16); + total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16); coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); total_coeff= coeff_token>>2; }else{ - total_coeff= pred_non_zero_count(h, n); + total_coeff= pred_non_zero_count(h, sl, n); coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); total_coeff= coeff_token>>2; } } - h->non_zero_count_cache[ scan8[n] ]= total_coeff; + sl->non_zero_count_cache[scan8[n]] = total_coeff; //FIXME set last_non_zero? @@ -638,7 +643,7 @@ static av_always_inline int decode_luma_residual(H264Context *h, H264SliceContex AV_ZERO128(h->mb_luma_dc[p]+8); AV_ZERO128(h->mb_luma_dc[p]+16); AV_ZERO128(h->mb_luma_dc[p]+24); - if( decode_residual(h, h->intra_gb_ptr, h->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX+p, scan, NULL, 16) < 0){ + if( decode_residual(h, sl, h->intra_gb_ptr, h->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX+p, scan, NULL, 16) < 0){ return -1; //FIXME continue if partitioned and other return -1 too } @@ -648,7 +653,7 @@ static av_always_inline int decode_luma_residual(H264Context *h, H264SliceContex for(i8x8=0; i8x8<4; i8x8++){ for(i4x4=0; i4x4<4; i4x4++){ const int index= i4x4 + 4*i8x8 + p*16; - if( decode_residual(h, h->intra_gb_ptr, h->mb + (16*index << pixel_shift), + if( decode_residual(h, sl, h->intra_gb_ptr, h->mb + (16*index << pixel_shift), index, scan + 1, h->dequant4_coeff[p][qscale], 15) < 0 ){ return -1; } @@ -656,7 +661,7 @@ static av_always_inline int decode_luma_residual(H264Context *h, H264SliceContex } return 0xf; }else{ - fill_rectangle(&h->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1); return 0; } }else{ @@ -670,25 +675,25 @@ static av_always_inline int decode_luma_residual(H264Context *h, H264SliceContex uint8_t *nnz; for(i4x4=0; i4x4<4; i4x4++){ const int index= i4x4 + 4*i8x8 + p*16; - if( decode_residual(h, gb, buf, index, scan8x8+16*i4x4, + if( decode_residual(h, sl, gb, buf, index, scan8x8+16*i4x4, h->dequant8_coeff[cqm][qscale], 16) < 0 ) return -1; } - nnz= &h->non_zero_count_cache[ scan8[4*i8x8+p*16] ]; + nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]]; nnz[0] += nnz[1] + nnz[8] + nnz[9]; new_cbp |= !!nnz[0] << i8x8; }else{ for(i4x4=0; i4x4<4; i4x4++){ const int index= i4x4 + 4*i8x8 + p*16; - if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, + if( decode_residual(h, sl, gb, h->mb + (16*index << pixel_shift), index, scan, h->dequant4_coeff[cqm][qscale], 16) < 0 ){ return -1; } - new_cbp |= h->non_zero_count_cache[ scan8[index] ] << i8x8; + new_cbp |= sl->non_zero_count_cache[scan8[index]] << i8x8; } } }else{ - uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8+p*16] ]; + uint8_t * const nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]]; nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; } } @@ -1135,7 +1140,7 @@ decode_intra_mb: if(cbp&0x30){ for(chroma_idx=0; chroma_idx<2; chroma_idx++) - if (decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift), + if (decode_residual(h, sl, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX+chroma_idx, CHROMA422(h) ? chroma422_dc_scan : chroma_dc_scan, NULL, 4*num_c8x8) < 0) { @@ -1150,24 +1155,24 @@ decode_intra_mb: for (i8x8 = 0; i8x8<num_c8x8; i8x8++) { for (i4x4 = 0; i4x4 < 4; i4x4++) { const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4; - if (decode_residual(h, gb, mb, index, scan + 1, qmul, 15) < 0) + if (decode_residual(h, sl, gb, mb, index, scan + 1, qmul, 15) < 0) return -1; mb += 16 << pixel_shift; } } } }else{ - fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } } }else{ - fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); - fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); + fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } h->cur_pic.qscale_table[mb_xy] = sl->qscale; - write_back_non_zero_count(h); + write_back_non_zero_count(h, sl); return 0; } diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c index fb4cc8ecc9..63580201f3 100644 --- a/libavcodec/h264_loopfilter.c +++ b/libavcodec/h264_loopfilter.c @@ -369,7 +369,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1); // (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) && (h->left_type[LTOP] & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : 0; int step = 1+(mb_type>>24); //IS_8x8DCT(mb_type) ? 2 : 1; edges = 4 - 3*((mb_type>>3) & !(h->cbp & 15)); //(mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; - h->h264dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, + h->h264dsp.h264_loop_filter_strength(bS, sl->non_zero_count_cache, h->ref_cache, h->mv_cache, h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE(h)); } if( IS_INTRA(left_type) ) @@ -510,15 +510,15 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl, AV_WN64A(bS, 0x0003000300030003ULL); } else { if (!CABAC(h) && IS_8x8DCT(h->cur_pic.mb_type[mbn_xy])) { - bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]); - bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]); - bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]); - bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+3]); + bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000) || sl->non_zero_count_cache[scan8[0]+0]); + bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000) || sl->non_zero_count_cache[scan8[0]+1]); + bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000) || sl->non_zero_count_cache[scan8[0]+2]); + bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000) || sl->non_zero_count_cache[scan8[0]+3]); }else{ const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 3*4; int i; for( i = 0; i < 4; i++ ) { - bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]); + bS[i] = 1 + !!(sl->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]); } } } @@ -574,8 +574,8 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl, int b_idx= 8 + 4 + x + 8*y; int bn_idx= b_idx - (dir ? 8:1); - if( h->non_zero_count_cache[b_idx] | - h->non_zero_count_cache[bn_idx] ) { + if (sl->non_zero_count_cache[b_idx] | + sl->non_zero_count_cache[bn_idx]) { bS[i] = 2; } else if(!mv_done) @@ -657,8 +657,8 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl, int b_idx= 8 + 4 + x + 8*y; int bn_idx= b_idx - (dir ? 8:1); - if( h->non_zero_count_cache[b_idx] | - h->non_zero_count_cache[bn_idx] ) { + if (sl->non_zero_count_cache[b_idx] | + sl->non_zero_count_cache[bn_idx]) { bS[i] = 2; } else if(!mv_done) @@ -765,7 +765,7 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, if( IS_INTRA( mbn_type ) ) bS[i] = 4; else{ - bS[i] = 1 + !!(h->non_zero_count_cache[12+8*(i>>1)] | + bS[i] = 1 + !!(sl->non_zero_count_cache[12+8*(i>>1)] | ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ? (h->cbp_table[mbn_xy] & (((MB_FIELD(h) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12)) : diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c index 419bb481c0..bdc17eca2f 100644 --- a/libavcodec/h264_mb.c +++ b/libavcodec/h264_mb.c @@ -640,7 +640,7 @@ static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, (sl-> topleft_samples_available << i) & 0x8000, (sl->topright_samples_available << i) & 0x4000, linesize); } else { - const int nnz = h->non_zero_count_cache[scan8[i + p * 16]]; + const int nnz = sl->non_zero_count_cache[scan8[i + p * 16]]; h->hpc.pred8x8l[dir](ptr, (sl->topleft_samples_available << i) & 0x8000, (sl->topright_samples_available << i) & 0x4000, linesize); if (nnz) { @@ -686,7 +686,7 @@ static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, topright = NULL; h->hpc.pred4x4[dir](ptr, topright, linesize); - nnz = h->non_zero_count_cache[scan8[i + p * 16]]; + nnz = sl->non_zero_count_cache[scan8[i + p * 16]]; if (nnz) { if (is_h264) { if (nnz == 1 && dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) @@ -702,7 +702,7 @@ static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, } else { h->hpc.pred16x16[sl->intra16x16_pred_mode](dest_y, linesize); if (is_h264) { - if (h->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) { + if (sl->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) { if (!transform_bypass) h->h264dsp.h264_luma_dc_dequant_idct(h->mb + (p * 256 << pixel_shift), h->mb_luma_dc[p], @@ -751,7 +751,7 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, H264SliceCon linesize); } else { for (i = 0; i < 16; i++) - if (h->non_zero_count_cache[scan8[i + p * 16]] || + if (sl->non_zero_count_cache[scan8[i + p * 16]] || dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) h->h264dsp.h264_add_pixels4_clear(dest_y + block_offset[i], h->mb + (i * 16 + p * 256 << pixel_shift), @@ -761,7 +761,7 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, H264SliceCon h->h264dsp.h264_idct_add16intra(dest_y, block_offset, h->mb + (p * 256 << pixel_shift), linesize, - h->non_zero_count_cache + p * 5 * 8); + sl->non_zero_count_cache + p * 5 * 8); } } else if (h->cbp & 15) { if (transform_bypass) { @@ -769,7 +769,7 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, H264SliceCon idct_add = IS_8x8DCT(mb_type) ? h->h264dsp.h264_add_pixels8_clear : h->h264dsp.h264_add_pixels4_clear; for (i = 0; i < 16; i += di) - if (h->non_zero_count_cache[scan8[i + p * 16]]) + if (sl->non_zero_count_cache[scan8[i + p * 16]]) idct_add(dest_y + block_offset[i], h->mb + (i * 16 + p * 256 << pixel_shift), linesize); @@ -778,17 +778,17 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, H264SliceCon h->h264dsp.h264_idct8_add4(dest_y, block_offset, h->mb + (p * 256 << pixel_shift), linesize, - h->non_zero_count_cache + p * 5 * 8); + sl->non_zero_count_cache + p * 5 * 8); else h->h264dsp.h264_idct_add16(dest_y, block_offset, h->mb + (p * 256 << pixel_shift), linesize, - h->non_zero_count_cache + p * 5 * 8); + sl->non_zero_count_cache + p * 5 * 8); } } } else if (CONFIG_SVQ3_DECODER) { for (i = 0; i < 16; i++) - if (h->non_zero_count_cache[scan8[i + p * 16]] || h->mb[i * 16 + p * 256]) { + if (sl->non_zero_count_cache[scan8[i + p * 16]] || h->mb[i * 16 + p * 256]) { // FIXME benchmark weird rule, & below uint8_t *const ptr = dest_y + block_offset[i]; ff_svq3_add_idct_c(ptr, h->mb + i * 16 + p * 256, linesize, diff --git a/libavcodec/h264_mb_template.c b/libavcodec/h264_mb_template.c index 99b817c729..5506e114f2 100644 --- a/libavcodec/h264_mb_template.c +++ b/libavcodec/h264_mb_template.c @@ -209,14 +209,14 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) idct_add = h->h264dsp.h264_add_pixels4_clear; for (j = 1; j < 3; j++) { for (i = j * 16; i < j * 16 + 4; i++) - if (h->non_zero_count_cache[scan8[i]] || + if (sl->non_zero_count_cache[scan8[i]] || dctcoef_get(h->mb, PIXEL_SHIFT, i * 16)) idct_add(dest[j - 1] + block_offset[i], h->mb + (i * 16 << PIXEL_SHIFT), uvlinesize); if (chroma422) { for (i = j * 16 + 4; i < j * 16 + 8; i++) - if (h->non_zero_count_cache[scan8[i + 4]] || + if (sl->non_zero_count_cache[scan8[i + 4]] || dctcoef_get(h->mb, PIXEL_SHIFT, i * 16)) idct_add(dest[j - 1] + block_offset[i + 4], h->mb + (i * 16 << PIXEL_SHIFT), @@ -234,15 +234,15 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) qp[0] = sl->chroma_qp[0]; qp[1] = sl->chroma_qp[1]; } - if (h->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 0]]) + if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 0]]) h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16 * 16 * 1 << PIXEL_SHIFT), h->dequant4_coeff[IS_INTRA(mb_type) ? 1 : 4][qp[0]][0]); - if (h->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 1]]) + if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 1]]) h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16 * 16 * 2 << PIXEL_SHIFT), h->dequant4_coeff[IS_INTRA(mb_type) ? 2 : 5][qp[1]][0]); h->h264dsp.h264_idct_add8(dest, block_offset, h->mb, uvlinesize, - h->non_zero_count_cache); + sl->non_zero_count_cache); } else if (CONFIG_SVQ3_DECODER) { h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16 * 16 * 1, h->dequant4_coeff[IS_INTRA(mb_type) ? 1 : 4][sl->chroma_qp[0]][0]); @@ -250,7 +250,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) h->dequant4_coeff[IS_INTRA(mb_type) ? 2 : 5][sl->chroma_qp[1]][0]); for (j = 1; j < 3; j++) { for (i = j * 16; i < j * 16 + 4; i++) - if (h->non_zero_count_cache[scan8[i]] || h->mb[i * 16]) { + if (sl->non_zero_count_cache[scan8[i]] || h->mb[i * 16]) { uint8_t *const ptr = dest[j - 1] + block_offset[i]; ff_svq3_add_idct_c(ptr, h->mb + i * 16, uvlinesize, diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h index c92421d3b6..4fea67c198 100644 --- a/libavcodec/h264_mvpred.h +++ b/libavcodec/h264_mvpred.h @@ -539,7 +539,7 @@ static void fill_decode_caches(H264Context *h, H264SliceContext *sl, int mb_type */ /* FIXME: constraint_intra_pred & partitioning & nnz * (let us hope this is just a typo in the spec) */ - nnz_cache = h->non_zero_count_cache; + nnz_cache = sl->non_zero_count_cache; if (top_type) { nnz = h->non_zero_count[top_xy]; AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 1d34bcc045..cc30ee2d13 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -2207,7 +2207,7 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) top_type, left_type, mb_xy, 1); nnz = h->non_zero_count[mb_xy]; - nnz_cache = h->non_zero_count_cache; + nnz_cache = sl->non_zero_count_cache; AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]); AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]); AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]); diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 754a3f72a0..0f3e4c611f 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -691,7 +691,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type) memset(sl->intra4x4_pred_mode + h->mb2br_xy[mb_xy], DC_PRED, 8); } if (!IS_SKIP(mb_type) || h->pict_type == AV_PICTURE_TYPE_B) { - memset(h->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t)); + memset(sl->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t)); } if (!IS_INTRA16x16(mb_type) && @@ -733,7 +733,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type) k = index ? (1 * (j & 1) + 2 * (i & 1) + 2 * (j & 2) + 4 * (i & 2)) : (4 * i + j); - h->non_zero_count_cache[scan8[k]] = 1; + sl->non_zero_count_cache[scan8[k]] = 1; if (svq3_decode_block(&h->gb, &h->mb[16 * k], index, type)) { av_log(h->avctx, AV_LOG_ERROR, @@ -755,7 +755,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type) for (i = 1; i < 3; i++) { for (j = 0; j < 4; j++) { k = 16 * i + j; - h->non_zero_count_cache[scan8[k]] = 1; + sl->non_zero_count_cache[scan8[k]] = 1; if (svq3_decode_block(&h->gb, &h->mb[16 * k], 1, 1)) { av_log(h->avctx, AV_LOG_ERROR, |