From 353642bc53de23e3e51940960c8c2b8f6602566e Mon Sep 17 00:00:00 2001 From: Scott LaVarnway Date: Wed, 29 May 2013 16:42:23 -0400 Subject: [PATCH] Moved use_prev_in_find_mv_refs check to frame level This patch checks at the frame level to see if the previous mode info context can be used. This patch eliminates the flag check that was done for every mode and removes another check that was done prior to every vp9_find_mv_refs(). Change-Id: I9da5e18b7e7e28f8b1f90d527cad087073df2d73 --- vp9/common/vp9_blockd.h | 1 - vp9/common/vp9_findnearmv.c | 8 +------- vp9/common/vp9_onyxc_int.h | 11 +++++++++++ vp9/decoder/vp9_decodemv.c | 15 +++------------ vp9/decoder/vp9_decodframe.c | 7 ++++++- vp9/encoder/vp9_encodeframe.c | 7 ++++++- vp9/encoder/vp9_onyx_if.c | 2 ++ vp9/encoder/vp9_rdopt.c | 6 +----- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index 9626540..b622aa3 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -786,5 +786,4 @@ static void txfrm_block_to_raster_xy(MACROBLOCKD *xd, *x = (raster_mb & (tx_cols - 1)) << (txwl); *y = raster_mb >> tx_cols_lg2 << (txwl); } - #endif // VP9_COMMON_VP9_BLOCKD_H_ diff --git a/vp9/common/vp9_findnearmv.c b/vp9/common/vp9_findnearmv.c index 5e14a8c..435dfdc 100644 --- a/vp9/common/vp9_findnearmv.c +++ b/vp9/common/vp9_findnearmv.c @@ -61,18 +61,12 @@ void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, int_mv mv_list[MAX_MV_REF_CANDIDATES]; MODE_INFO *mi = xd->mode_info_context; MB_MODE_INFO *const mbmi = &mi->mbmi; - int use_prev_in_find_mv_refs; assert(ref_idx == 0 || ref_idx == 1); assert(MAX_MV_REF_CANDIDATES == 2); // makes code here slightly easier - use_prev_in_find_mv_refs = cm->width == cm->last_width && - cm->height == cm->last_height && - !cm->error_resilient_mode && - cm->last_show_frame; vp9_find_mv_refs_idx(cm, xd, xd->mode_info_context, - use_prev_in_find_mv_refs ? - xd->prev_mode_info_context : NULL, + xd->prev_mode_info_context, ref_idx ? mbmi->second_ref_frame : mbmi->ref_frame, mv_list, cm->ref_frame_sign_bias, block_idx); diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index c277ea3..07d82b3 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -333,4 +333,15 @@ static int get_mi_col(const MACROBLOCKD *xd) { static int get_token_alloc(int mb_rows, int mb_cols) { return mb_rows * mb_cols * (48 * 16 + 4); } + +static void set_prev_mi(VP9_COMMON *cm) { + const int use_prev_in_find_mv_refs = cm->width == cm->last_width && + cm->height == cm->last_height && + !cm->error_resilient_mode && + cm->last_show_frame; + // Special case: set prev_mi to NULL when the previous mode info + // context cannot be used. + cm->prev_mi = use_prev_in_find_mv_refs ? + cm->prev_mip + cm->mode_info_stride + 1 : NULL; +} #endif // VP9_COMMON_VP9_ONYXC_INT_H_ diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index f21a050..2ae807f 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -531,11 +531,6 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, int bw = 1 << b_width_log2(bsize); int bh = 1 << b_height_log2(bsize); - const int use_prev_in_find_mv_refs = cm->width == cm->last_width && - cm->height == cm->last_height && - !cm->error_resilient_mode && - cm->last_show_frame; - int mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge; int j, idx, idy; @@ -582,10 +577,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, printf("%d %d\n", xd->mode_info_context->mbmi.mv[0].as_mv.row, xd->mode_info_context->mbmi.mv[0].as_mv.col); #endif - vp9_find_mv_refs(cm, xd, mi, use_prev_in_find_mv_refs ? - xd->prev_mode_info_context : NULL, - ref_frame, mbmi->ref_mvs[ref_frame], - cm->ref_frame_sign_bias); + vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context, ref_frame, + mbmi->ref_mvs[ref_frame], cm->ref_frame_sign_bias); vp9_mv_ref_probs(cm, mv_ref_p, mbmi->mb_mode_context[ref_frame]); @@ -636,9 +629,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, if (mbmi->second_ref_frame > 0) { const MV_REFERENCE_FRAME second_ref_frame = mbmi->second_ref_frame; - vp9_find_mv_refs(cm, xd, mi, - use_prev_in_find_mv_refs ? - xd->prev_mode_info_context : NULL, + vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context, second_ref_frame, mbmi->ref_mvs[second_ref_frame], cm->ref_frame_sign_bias); diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index 70e0c87..5f62248 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -403,7 +403,10 @@ static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize, xd->mode_info_context = cm->mi + mi_idx; xd->mode_info_context->mbmi.sb_type = bsize; - xd->prev_mode_info_context = cm->prev_mi + mi_idx; + // Special case: if prev_mi is NULL, the previous mode info context + // cannot be used. + xd->prev_mode_info_context = cm->prev_mi ? + cm->prev_mi + mi_idx : NULL; for (i = 0; i < MAX_MB_PLANE; i++) { xd->plane[i].above_context = cm->above_context[i] + @@ -1099,6 +1102,8 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { for (i = 0; i < MAX_MB_PLANE; ++i) vp9_zero(xd->plane[i].qcoeff); + set_prev_mi(pc); + vp9_decode_mode_mvs_init(pbi, &header_bc); decode_tiles(pbi, data, first_partition_size, &header_bc, &residual_bc); diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index fb8a790..ebee191 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -551,7 +551,10 @@ static void set_offsets(VP9_COMP *cpi, x->partition_info = x->pi + idx_str; xd->mode_info_context = cm->mi + idx_str; mbmi = &xd->mode_info_context->mbmi; - xd->prev_mode_info_context = cm->prev_mi + idx_str; + // Special case: if prev_mi is NULL, the previous mode info context + // cannot be used. + xd->prev_mode_info_context = cm->prev_mi ? + cm->prev_mi + idx_str : NULL; // Set up destination pointers setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); @@ -1202,6 +1205,8 @@ static void encode_frame_internal(VP9_COMP *cpi) { vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff)); vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes)); + set_prev_mi(cm); + { struct vpx_usec_timer emr_timer; vpx_usec_timer_start(&emr_timer); diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index d42bcbb..4bbb415 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -3545,6 +3545,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO)); } + // restore prev_mi + cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1; } static void Pass2Encode(VP9_COMP *cpi, unsigned long *size, diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 2eb3f9b..aa05577 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -1751,7 +1751,6 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]]; MACROBLOCKD *const xd = &x->e_mbd; MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; - int use_prev_in_find_mv_refs; // set up scaling factors scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1]; @@ -1768,11 +1767,8 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, &scale[frame_type], &scale[frame_type]); // Gets an initial list of candidate vectors from neighbours and orders them - use_prev_in_find_mv_refs = cm->width == cm->last_width && - cm->height == cm->last_height && - !cpi->common.error_resilient_mode; vp9_find_mv_refs(&cpi->common, xd, xd->mode_info_context, - use_prev_in_find_mv_refs ? xd->prev_mode_info_context : NULL, + xd->prev_mode_info_context, frame_type, mbmi->ref_mvs[frame_type], cpi->common.ref_frame_sign_bias); -- 2.7.4