From 66323307029f9e9c9ed3f40aa225019e1f074f20 Mon Sep 17 00:00:00 2001 From: Deb Mukherjee Date: Thu, 29 Nov 2012 16:39:15 -0800 Subject: [PATCH] Adds switchable filters with superblocks Allows switchbale filters to be used without mismatch when the superblock experiment is on. Also removes a spurious clamping code in decodemv.c which causes rare encode/decode mismatches. Change-Id: I809d9ee0b2859552b613500b539a615515b863ae --- vp9/common/vp9_pred_common.c | 2 ++ vp9/decoder/vp9_decodemv.c | 4 ++++ vp9/decoder/vp9_decodframe.c | 22 ++++++++++++++++------ vp9/encoder/vp9_encodeframe.c | 31 ++++++++++++++++++++++++------- vp9/encoder/vp9_rdopt.c | 21 +++++++++++++-------- 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/vp9/common/vp9_pred_common.c b/vp9/common/vp9_pred_common.c index cb65d72..2abae34 100644 --- a/vp9/common/vp9_pred_common.c +++ b/vp9/common/vp9_pred_common.c @@ -74,11 +74,13 @@ unsigned char vp9_get_pred_context(const VP9_COMMON *const cm, left_interp = vp9_switchable_interp_map[(m - 1)->mbmi.interp_filter]; else left_interp = VP9_SWITCHABLE_FILTERS; + assert(left_interp != -1); if (above_in_image && above_mode >= NEARESTMV && above_mode <= SPLITMV) above_interp = vp9_switchable_interp_map[ (m - cm->mode_info_stride)->mbmi.interp_filter]; else above_interp = VP9_SWITCHABLE_FILTERS; + assert(above_interp != -1); if (left_interp == above_interp) pred_context = left_interp; diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index d08998b..7e53884 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -998,6 +998,9 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, break; } + /* Commenting this section out, not sure why this was needed, and + * there are mismatches with this section in rare cases since it is + * not done in the encoder at all. mbmi->need_to_clamp_mvs |= check_mv_bounds(&blockmv, mb_to_left_edge, mb_to_right_edge, @@ -1010,6 +1013,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, mb_to_top_edge, mb_to_bottom_edge); } + */ { /* Fill (uniform) modes, mvs of jth subset. diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index 8ea0f09..f95a83a 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -696,13 +696,13 @@ static void decode_superblock(VP9D_COMP *pbi, MACROBLOCKD *xd, assert(xd->mode_info_context->mbmi.encoded_as_sb); + if (pbi->common.frame_type != KEY_FRAME) + vp9_setup_interp_filters(xd, xd->mode_info_context->mbmi.interp_filter, pc); + // re-initialize macroblock dequantizer before detokenization if (xd->segmentation_enabled) mb_init_dequantizer(pbi, xd); - if (pbi->common.frame_type != KEY_FRAME) - vp9_setup_interp_filters(xd, xd->mode_info_context->mbmi.interp_filter, pc); - if (xd->mode_info_context->mbmi.mb_skip_coeff) { vp9_reset_mb_tokens_context(xd); if (mb_col < pc->mb_cols - 1) @@ -739,6 +739,7 @@ static void decode_superblock(VP9D_COMP *pbi, MACROBLOCKD *xd, if (mb_col + x_idx >= pc->mb_cols || mb_row + y_idx >= pc->mb_rows) continue; + xd->above_context = pc->above_context + mb_col + x_idx; xd->left_context = pc->left_context + y_idx; xd->mode_info_context = orig_mi + x_idx + y_idx * pc->mode_info_stride; @@ -832,6 +833,12 @@ static void decode_macroblock(VP9D_COMP *pbi, MACROBLOCKD *xd, } } } else { +#ifdef DEC_DEBUG + if (dec_debug) + printf("Decoding mb: %d %d interp %d\n", + xd->mode_info_context->mbmi.mode, tx_size, + xd->mode_info_context->mbmi.interp_filter); +#endif vp9_build_inter_predictors_mb(xd); } @@ -859,7 +866,6 @@ static void decode_macroblock(VP9D_COMP *pbi, MACROBLOCKD *xd, printf("%3d ", xd->dst.u_buffer[i * xd->dst.uv_stride + j]); printf("\n"); } - } else { printf("\n"); printf("final v\n"); for (i = 0; i < 8; i++) { @@ -969,8 +975,8 @@ decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc, int mbrow, MACROBLOCKD *xd, } #endif #ifdef DEC_DEBUG - dec_debug = (pbi->common.current_video_frame == 73 && - mb_row == 4 && mb_col == 13); + dec_debug = (pbi->common.current_video_frame == 46 && + mb_row == 5 && mb_col == 2); if (dec_debug) #if CONFIG_SUPERBLOCKS printf("Enter Debug %d %d sb %d\n", mb_row, mb_col, @@ -993,6 +999,10 @@ decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc, int mbrow, MACROBLOCKD *xd, vp9_decode_mb_mode_mv(pbi, xd, mb_row, mb_col, bc); update_blockd_bmi(xd); +#ifdef DEC_DEBUG + if (dec_debug) + printf("Hello\n"); +#endif /* Select the appropriate reference frame for this MB */ if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 8ef442a..b7f8cf4 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -578,6 +578,13 @@ static void update_state(VP9_COMP *cpi, MACROBLOCK *x, ++cpi->interintra_count[0]; } } + if (cpi->common.mcomp_filter_type == SWITCHABLE && + mbmi->mode >= NEARESTMV && + mbmi->mode <= SPLITMV) { + ++cpi->switchable_interp_count + [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] + [vp9_switchable_interp_map[mbmi->interp_filter]]; + } #endif cpi->prediction_error += ctx->distortion; @@ -727,10 +734,18 @@ static void pick_mb_modes(VP9_COMP *cpi, vp9_intra_prediction_down_copy(xd); +#ifdef ENC_DEBUG + enc_debug = (cpi->common.current_video_frame == 46 && + mb_row == 5 && mb_col == 2); +#endif // Find best coding mode & reconstruct the MB so it is available // as a predictor for MBs that follow in the SB if (cm->frame_type == KEY_FRAME) { int r, d; +#ifdef ENC_DEBUG + if (enc_debug) + printf("intra pick_mb_modes %d %d\n", mb_row, mb_col); +#endif vp9_rd_pick_intra_mode(cpi, x, &r, &d); *totalrate += r; *totaldist += d; @@ -759,10 +774,8 @@ static void pick_mb_modes(VP9_COMP *cpi, } #ifdef ENC_DEBUG - enc_debug = (cpi->common.current_video_frame == 73 && - mb_row == 4 && mb_col == 13); if (enc_debug) - printf("pick_mb_modes %d %d\n", mb_row, mb_col); + printf("inter pick_mb_modes %d %d\n", mb_row, mb_col); #endif vp9_pick_mode_inter_macroblock(cpi, x, recon_yoffset, recon_uvoffset, &r, &d); @@ -2028,8 +2041,8 @@ static void encode_macroblock(VP9_COMP *cpi, MACROBLOCK *x, #endif #ifdef ENC_DEBUG - enc_debug = (cpi->common.current_video_frame == 73 && - mb_row == 4 && mb_col == 13); + enc_debug = (cpi->common.current_video_frame == 46 && + mb_row == 5 && mb_col == 2); if (enc_debug) printf("Encode MB %d %d output %d\n", mb_row, mb_col, output_enabled); #endif @@ -2099,10 +2112,11 @@ static void encode_macroblock(VP9_COMP *cpi, MACROBLOCK *x, int ref_fb_idx; #ifdef ENC_DEBUG if (enc_debug) - printf("Mode %d skip %d tx_size %d ref %d ref2 %d mv %d %d\n", + printf("Mode %d skip %d tx_size %d ref %d ref2 %d mv %d %d interp %d\n", mbmi->mode, x->skip, mbmi->txfm_size, mbmi->ref_frame, mbmi->second_ref_frame, - mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col); + mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col, + mbmi->interp_filter); #endif assert(cm->frame_type != KEY_FRAME); @@ -2304,6 +2318,8 @@ static void encode_superblock(VP9_COMP *cpi, MACROBLOCK *x, vp9_update_zbin_extra(cpi, x); } } else { + vp9_setup_interp_filters(xd, xd->mode_info_context->mbmi.interp_filter, cm); + if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { // Adjust the zbin based on this MB rate. adjust_act_zbin(cpi, x); @@ -2338,6 +2354,7 @@ static void encode_superblock(VP9_COMP *cpi, MACROBLOCK *x, vp9_set_pred_flag(xd, PRED_REF, ref_pred_flag); } + if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME) { vp9_build_intra_predictors_sby_s(&x->e_mbd); vp9_build_intra_predictors_sbuv_s(&x->e_mbd); diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 84cff6e..32eeb32 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -4035,13 +4035,6 @@ static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, #if CONFIG_COMP_INTERINTRA_PRED ++cpi->interintra_select_count[is_best_interintra]; #endif - if (cpi->common.mcomp_filter_type == SWITCHABLE && - best_mbmode.mode >= NEARESTMV && - best_mbmode.mode <= SPLITMV) { - ++cpi->switchable_interp_count - [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] - [vp9_switchable_interp_map[best_mbmode.interp_filter]]; - } // Reduce the activation RD thresholds for the best choice mode if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && @@ -4367,6 +4360,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, rate_uv_tokenonly_8x8 = 0; int dist_uv_4x4 = 0, dist_uv_8x8 = 0, uv_skip_4x4 = 0, uv_skip_8x8 = 0; MB_PREDICTION_MODE mode_uv_4x4 = NEARESTMV, mode_uv_8x8 = NEARESTMV; + int switchable_filter_index = 0; x->skip = 0; xd->mode_info_context->mbmi.segment_id = segment_id; @@ -4403,7 +4397,8 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, mode_uv_8x8 = mbmi->uv_mode; } - for (mode_index = 0; mode_index < MAX_MODES; mode_index++) { + for (mode_index = 0; mode_index < MAX_MODES; + mode_index += (!switchable_filter_index)) { int mode_excluded = 0; int64_t this_rd = INT64_MAX; int disable_skip = 0; @@ -4437,6 +4432,16 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, mbmi->second_mode = (MB_PREDICTION_MODE)(DC_PRED - 1); mbmi->second_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1); #endif + if (cpi->common.mcomp_filter_type == SWITCHABLE && + this_mode >= NEARESTMV && this_mode <= SPLITMV) { + mbmi->interp_filter = + vp9_switchable_interp[switchable_filter_index++]; + if (switchable_filter_index == VP9_SWITCHABLE_FILTERS) + switchable_filter_index = 0; + } else { + mbmi->interp_filter = cpi->common.mcomp_filter_type; + } + vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); if (!(cpi->ref_frame_flags & flag_list[ref_frame])) continue; -- 2.7.4