From e7226984ac13aacb84eae77a372df8ff7685848f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 17 Jan 2015 22:28:46 +0100 Subject: [PATCH] h264: move [{top,left}_]cbp into the per-slice context --- libavcodec/h264.h | 8 +++++--- libavcodec/h264_cabac.c | 18 +++++++++--------- libavcodec/h264_cavlc.c | 2 +- libavcodec/h264_loopfilter.c | 6 +++--- libavcodec/h264_mb.c | 2 +- libavcodec/h264_mb_template.c | 2 +- libavcodec/h264_mvpred.h | 8 ++++---- libavcodec/h264_slice.c | 10 +++++----- libavcodec/svq3.c | 2 +- 9 files changed, 30 insertions(+), 28 deletions(-) diff --git a/libavcodec/h264.h b/libavcodec/h264.h index e998eb6cc3..e08e5baf85 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -359,6 +359,10 @@ typedef struct H264SliceContext { int col_parity; int col_fieldoff; + int cbp; + int top_cbp; + int left_cbp; + int dist_scale_factor[32]; int dist_scale_factor_field[2][32]; int map_col_to_list0[2][16 + 32]; @@ -484,9 +488,7 @@ typedef struct H264Context { /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0, 1, 2), 0x0? luma_cbp */ uint16_t *cbp_table; - int cbp; - int top_cbp; - int left_cbp; + /* chroma_pred_mode for i4x4 or i16x16, else 0 */ uint8_t *chroma_pred_mode_table; int last_qscale_diff; diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index 8107b6c6ef..df6baee9fc 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -1406,8 +1406,8 @@ static int decode_cabac_mb_cbp_luma(H264Context *h, H264SliceContext *sl) { int cbp_b, cbp_a, ctx, cbp = 0; - cbp_a = h->left_cbp; - cbp_b = h->top_cbp; + cbp_a = sl->left_cbp; + cbp_b = sl->top_cbp; ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04); cbp += get_cabac_noinline(&sl->cabac, &sl->cabac_state[73 + ctx]); @@ -1424,8 +1424,8 @@ static int decode_cabac_mb_cbp_chroma(H264Context *h, H264SliceContext *sl) int ctx; int cbp_a, cbp_b; - cbp_a = (h->left_cbp>>4)&0x03; - cbp_b = (h-> top_cbp>>4)&0x03; + cbp_a = (sl->left_cbp>>4)&0x03; + cbp_b = (sl-> top_cbp>>4)&0x03; ctx = 0; if( cbp_a > 0 ) ctx++; @@ -1555,12 +1555,12 @@ static av_always_inline int get_cabac_cbf_ctx(H264Context *h, H264SliceContext * if( is_dc ) { if( cat == 3 ) { idx -= CHROMA_DC_BLOCK_INDEX; - nza = (h->left_cbp>>(6+idx))&0x01; - nzb = (h-> top_cbp>>(6+idx))&0x01; + nza = (sl->left_cbp>>(6+idx))&0x01; + nzb = (sl-> top_cbp>>(6+idx))&0x01; } else { idx -= LUMA_DC_BLOCK_INDEX; - nza = h->left_cbp&(0x100< top_cbp&(0x100<left_cbp&(0x100< top_cbp&(0x100<non_zero_count_cache[scan8[idx] - 1]; @@ -2315,7 +2315,7 @@ decode_intra_mb: cbp |= decode_cabac_mb_cbp_chroma(h, sl) << 4; } - h->cbp_table[mb_xy] = h->cbp = cbp; + h->cbp_table[mb_xy] = sl->cbp = cbp; if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) { mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline(&sl->cabac, &sl->cabac_state[399 + sl->neighbor_transform_size]); diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index 5b9939ece4..b16b6b66c2 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -1075,7 +1075,7 @@ decode_intra_mb: if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ mb_type |= MB_TYPE_8x8DCT*get_bits1(&h->gb); } - h->cbp= + sl->cbp= h->cbp_table[mb_xy]= cbp; h->cur_pic.mb_type[mb_xy] = mb_type; diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c index 4ac04b14b4..c58d3f1728 100644 --- a/libavcodec/h264_loopfilter.c +++ b/libavcodec/h264_loopfilter.c @@ -360,7 +360,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, } else { LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]); int edges; - if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 && !chroma444 ) { + if( IS_8x8DCT(mb_type) && (sl->cbp&7) == 7 && !chroma444 ) { edges = 4; AV_WN64A(bS[0][0], 0x0002000200020002ULL); AV_WN64A(bS[0][2], 0x0002000200020002ULL); @@ -370,7 +370,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4); //(mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : (mb_type & MB_TYPE_16x8) ? 1 : 0; 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; + edges = 4 - 3*((mb_type>>3) & !(sl->cbp & 15)); //(mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; h->h264dsp.h264_loop_filter_strength(bS, sl->non_zero_count_cache, sl->ref_cache, sl->mv_cache, sl->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE(h)); } @@ -487,7 +487,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl, static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1}, {0,3,1,1,3,3,3,3}}; const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7]; - const int edges = mask_edge== 3 && !(h->cbp&15) ? 1 : 4; + const int edges = mask_edge== 3 && !(sl->cbp&15) ? 1 : 4; // how often to recheck mv-based bS when iterating along each edge const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)); diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c index 0bc43dbd81..5176e54e33 100644 --- a/libavcodec/h264_mb.c +++ b/libavcodec/h264_mb.c @@ -763,7 +763,7 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, H264SliceCon linesize, sl->non_zero_count_cache + p * 5 * 8); } - } else if (h->cbp & 15) { + } else if (sl->cbp & 15) { if (transform_bypass) { const int di = IS_8x8DCT(mb_type) ? 4 : 1; idct_add = IS_8x8DCT(mb_type) ? h->h264dsp.h264_add_pixels8_clear diff --git a/libavcodec/h264_mb_template.c b/libavcodec/h264_mb_template.c index 97d134b17e..558a9b5de4 100644 --- a/libavcodec/h264_mb_template.c +++ b/libavcodec/h264_mb_template.c @@ -194,7 +194,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) PIXEL_SHIFT, block_offset, linesize, dest_y, 0); if ((SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) && - (h->cbp & 0x30)) { + (sl->cbp & 0x30)) { uint8_t *dest[2] = { dest_cb, dest_cr }; if (transform_bypass) { if (IS_INTRA(mb_type) && h->sps.profile_idc == 244 && diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h index 4684077059..5666871f5f 100644 --- a/libavcodec/h264_mvpred.h +++ b/libavcodec/h264_mvpred.h @@ -589,16 +589,16 @@ static void fill_decode_caches(H264Context *h, H264SliceContext *sl, int mb_type if (CABAC(h)) { // top_cbp if (top_type) - h->top_cbp = h->cbp_table[top_xy]; + sl->top_cbp = h->cbp_table[top_xy]; else - h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; + sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; // left_cbp if (left_type[LTOP]) { - h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | + sl->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) | (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2); } else { - h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; + sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } } } diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index e9a68d2051..ac186a66db 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1993,7 +1993,7 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]); AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]); AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]); - h->cbp = h->cbp_table[mb_xy]; + sl->cbp = h->cbp_table[mb_xy]; if (top_type) { nnz = h->non_zero_count[top_xy]; @@ -2030,22 +2030,22 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) nnz_cache[scan8[0]] = nnz_cache[scan8[1]] = nnz_cache[scan8[2]] = - nnz_cache[scan8[3]] = (h->cbp & 0x1000) >> 12; + nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12; nnz_cache[scan8[0 + 4]] = nnz_cache[scan8[1 + 4]] = nnz_cache[scan8[2 + 4]] = - nnz_cache[scan8[3 + 4]] = (h->cbp & 0x2000) >> 12; + nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12; nnz_cache[scan8[0 + 8]] = nnz_cache[scan8[1 + 8]] = nnz_cache[scan8[2 + 8]] = - nnz_cache[scan8[3 + 8]] = (h->cbp & 0x4000) >> 12; + nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12; nnz_cache[scan8[0 + 12]] = nnz_cache[scan8[1 + 12]] = nnz_cache[scan8[2 + 12]] = - nnz_cache[scan8[3 + 12]] = (h->cbp & 0x8000) >> 12; + nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12; } } diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 95f6051823..316699c37c 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -761,7 +761,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type) } } - h->cbp = cbp; + sl->cbp = cbp; h->cur_pic.mb_type[mb_xy] = mb_type; if (IS_INTRA(mb_type))