From: Simon Horlick Date: Tue, 29 Mar 2011 14:46:34 +0000 (+0100) Subject: MBAFF: CABAC encoding of skips X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=e2d4d910221c0bfc816f7f19e9cc8b1309b191f8;p=x264.git MBAFF: CABAC encoding of skips --- diff --git a/common/common.h b/common/common.h index 263f9941..f19f2f64 100644 --- a/common/common.h +++ b/common/common.h @@ -750,6 +750,7 @@ struct x264_t /* number of neighbors (top and left) that used 8x8 dct */ int i_neighbour_transform_size; + int i_neighbour_skip; /* neighbor CBPs */ int i_cbp_top; diff --git a/common/macroblock.c b/common/macroblock.c index d8e95ca8..251fa2d9 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -1138,6 +1138,35 @@ void x264_macroblock_cache_load( x264_t *h, int mb_x, int mb_y ) } } + if( h->param.b_cabac ) + { + int left_xy, top_xy; + if( h->sh.b_mbaff ) + { + /* Neighbours here are calculated based on field_decoding_flag */ + int mb_xy = mb_x + (mb_y&~1)*h->mb.i_mb_stride; + left_xy = mb_xy - 1; + if( (mb_y&1) && mb_x > 0 && h->mb.field_decoding_flag == h->mb.field[left_xy] ) + left_xy += h->mb.i_mb_stride; + if( h->mb.field_decoding_flag ) + { + top_xy = mb_xy - h->mb.i_mb_stride; + if( !(mb_y&1) && top_xy >= 0 && h->mb.slice_table[top_xy] == h->sh.i_first_mb && h->mb.field[top_xy] ) + top_xy -= h->mb.i_mb_stride; + } + else + top_xy = mb_x + (mb_y-1)*h->mb.i_mb_stride; + } + else + { + left_xy = h->mb.i_mb_left_xy[0]; + top_xy = h->mb.i_mb_top_xy; + } + + h->mb.cache.i_neighbour_skip = (mb_x > 0 && h->mb.slice_table[left_xy] == h->sh.i_first_mb && !IS_SKIP( h->mb.type[left_xy] )) + + (top_xy >= 0 && h->mb.slice_table[top_xy] == h->sh.i_first_mb && !IS_SKIP( h->mb.type[top_xy] )); + } + /* load skip */ if( h->sh.i_type == SLICE_TYPE_B ) { diff --git a/encoder/cabac.c b/encoder/cabac.c index 02dcedd8..e04f14ba 100644 --- a/encoder/cabac.c +++ b/encoder/cabac.c @@ -296,9 +296,9 @@ static void x264_cabac_mb_qp_delta( x264_t *h, x264_cabac_t *cb ) #if !RDO_SKIP_BS void x264_cabac_mb_skip( x264_t *h, int b_skip ) { - int ctx = ((h->mb.i_neighbour & MB_LEFT) && !IS_SKIP( h->mb.i_mb_type_left[0] )) - + ((h->mb.i_neighbour & MB_TOP) && !IS_SKIP( h->mb.i_mb_type_top )) - + (h->sh.i_type == SLICE_TYPE_P ? 11 : 24); + int ctx = h->mb.cache.i_neighbour_skip + 11; + if( h->sh.i_type != SLICE_TYPE_P ) + ctx += 13; x264_cabac_encode_decision( &h->cabac, ctx, b_skip ); } #endif @@ -351,7 +351,7 @@ static void x264_cabac_mb_ref( x264_t *h, x264_cabac_t *cb, int i_list, int idx const int i8 = x264_scan8[idx]; const int i_refa = h->mb.cache.ref[i_list][i8 - 1]; const int i_refb = h->mb.cache.ref[i_list][i8 - 8]; - int ctx = 0; + int ctx = 0; if( i_refa > 0 && !h->mb.cache.skip[i8 - 1] ) ctx++;