From 7055d13f2f55ad7e78c1c12aad3a7024ac0be7f1 Mon Sep 17 00:00:00 2001 From: Simon Horlick Date: Tue, 29 Mar 2011 20:26:33 +0100 Subject: [PATCH] MBAFF: Disallow skip where predicted interlace flag would be wrong --- common/common.h | 1 + common/macroblock.c | 25 +++++++++++++++++++++++++ encoder/macroblock.c | 7 +------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/common/common.h b/common/common.h index 1cc6508d..085f257a 100644 --- a/common/common.h +++ b/common/common.h @@ -618,6 +618,7 @@ struct x264_t int i_mb_topright_y; x264_left_table_t *left_index_table; int topleft_partition; + int b_allow_skip; /**** thread synchronization ends here ****/ /* subsequent variables are either thread-local or constant, diff --git a/common/macroblock.c b/common/macroblock.c index 34a05d4f..24ac3f79 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -1109,6 +1109,31 @@ void x264_macroblock_cache_load( x264_t *h, int mb_x, int mb_y ) } } + /* Check whether skip here would cause decoder to predict interlace mode incorrectly. + * FIXME: It might be better to change the interlace type rather than forcing a skip to be non-skip. */ + h->mb.b_allow_skip = 1; + if( h->sh.b_mbaff ) + { + if( (mb_y&1) && IS_SKIP(h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride]) ) + { + if( h->mb.i_neighbour & MB_LEFT ) + { + if( h->mb.field[h->mb.i_mb_xy - 1] != h->mb.b_interlaced ) + h->mb.b_allow_skip = 0; + } + else if( h->mb.i_neighbour & MB_TOP ) + { + if( h->mb.field[h->mb.i_mb_top_xy] != h->mb.b_interlaced ) + h->mb.b_allow_skip = 0; + } + else // Frame mb pair is predicted + { + if( h->mb.b_interlaced ) + h->mb.b_allow_skip = 0; + } + } + } + /* load skip */ if( h->sh.i_type == SLICE_TYPE_B ) { diff --git a/encoder/macroblock.c b/encoder/macroblock.c index 441df88a..80a30bb8 100644 --- a/encoder/macroblock.c +++ b/encoder/macroblock.c @@ -569,13 +569,8 @@ void x264_macroblock_encode( x264_t *h ) return; } - if( h->sh.b_mbaff - && h->mb.i_mb_xy == h->sh.i_first_mb + h->mb.i_mb_stride - && IS_SKIP(h->mb.type[h->sh.i_first_mb]) ) + if( !h->mb.b_allow_skip ) { - /* The first skip is predicted to be a frame mb pair. - * We don't yet support the aff part of mbaff, so force it to non-skip - * so that we can pick the aff flag. */ b_force_no_skip = 1; if( IS_SKIP(h->mb.i_type) ) { -- 2.40.0