From 8ee605f188e97835b28c549f2423c74079d7c466 Mon Sep 17 00:00:00 2001 From: Yunqing Wang Date: Thu, 13 Nov 2014 13:38:23 -0800 Subject: [PATCH] vp9_ethread: modify the cyclic refresh struct Two members in struct CYCLIC_REFRESH int64_t projected_rate_sb; int64_t projected_dist_sb; are updated at the superblock level, which makes them shared data in the multi-thread situation, and requires extra work to handle them. However, those values are updated and used immediately, and therefore can be removed. This patch cleaned up the code and removed the two members. Change-Id: I2c6ee4552bf49fb63ce590cdb47f9723974fffb1 --- vp9/encoder/vp9_aq_cyclicrefresh.c | 20 +++++++------------- vp9/encoder/vp9_aq_cyclicrefresh.h | 6 ++---- vp9/encoder/vp9_encodeframe.c | 10 +++------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c index 1fc4ecdee..1f8641e20 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.c +++ b/vp9/encoder/vp9_aq_cyclicrefresh.c @@ -38,9 +38,6 @@ struct CYCLIC_REFRESH { int rdmult; // Cyclic refresh map. signed char *map; - // Projected rate and distortion for the current superblock. - int64_t projected_rate_sb; - int64_t projected_dist_sb; // Thresholds applied to projected rate/distortion of the superblock. int64_t thresh_rate_sb; int64_t thresh_dist_sb; @@ -92,12 +89,13 @@ static int apply_cyclic_refresh_bitrate(const VP9_COMMON *cm, // mode, and rate/distortion. static int candidate_refresh_aq(const CYCLIC_REFRESH *cr, const MB_MODE_INFO *mbmi, - BLOCK_SIZE bsize, int use_rd) { + BLOCK_SIZE bsize, int use_rd, + int64_t rate_sb) { if (use_rd) { MV mv = mbmi->mv[0].as_mv; // If projected rate is below the thresh_rate (well below target, // so undershoot expected), accept it for lower-qp coding. - if (cr->projected_rate_sb < cr->thresh_rate_sb) + if (rate_sb < cr->thresh_rate_sb) return 1; // Otherwise, reject the block for lower-qp coding if any of the following: // 1) mode uses large mv @@ -125,7 +123,8 @@ static int candidate_refresh_aq(const CYCLIC_REFRESH *cr, void vp9_cyclic_refresh_update_segment(VP9_COMP *const cpi, MB_MODE_INFO *const mbmi, int mi_row, int mi_col, - BLOCK_SIZE bsize, int use_rd) { + BLOCK_SIZE bsize, int use_rd, + int64_t rate_sb) { const VP9_COMMON *const cm = &cpi->common; CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; const int bw = num_8x8_blocks_wide_lookup[bsize]; @@ -133,7 +132,8 @@ void vp9_cyclic_refresh_update_segment(VP9_COMP *const cpi, const int xmis = MIN(cm->mi_cols - mi_col, bw); const int ymis = MIN(cm->mi_rows - mi_row, bh); const int block_index = mi_row * cm->mi_cols + mi_col; - const int refresh_this_block = candidate_refresh_aq(cr, mbmi, bsize, use_rd); + const int refresh_this_block = candidate_refresh_aq(cr, mbmi, bsize, use_rd, + rate_sb); // Default is to not update the refresh map. int new_map_value = cr->map[block_index]; int x = 0; int y = 0; @@ -311,12 +311,6 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { } } -void vp9_cyclic_refresh_set_rate_and_dist_sb(CYCLIC_REFRESH *cr, - int64_t rate_sb, int64_t dist_sb) { - cr->projected_rate_sb = rate_sb; - cr->projected_dist_sb = dist_sb; -} - int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr) { return cr->rdmult; } diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.h b/vp9/encoder/vp9_aq_cyclicrefresh.h index f556d658b..fbc057b6f 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.h +++ b/vp9/encoder/vp9_aq_cyclicrefresh.h @@ -33,14 +33,12 @@ void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr); void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi, MB_MODE_INFO *const mbmi, int mi_row, int mi_col, - BLOCK_SIZE bsize, int use_rd); + BLOCK_SIZE bsize, int use_rd, + int64_t rate_sb); // Setup cyclic background refresh: set delta q and segmentation map. void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi); -void vp9_cyclic_refresh_set_rate_and_dist_sb(CYCLIC_REFRESH *cr, - int64_t rate_sb, int64_t dist_sb); - int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr); #ifdef __cplusplus diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 7660299d0..a977a4a79 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -641,11 +641,8 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, // Else for cyclic refresh mode update the segment map, set the segment id // and then update the quantizer. if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - - vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, - ctx->rate, ctx->dist); vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0].src_mi->mbmi, - mi_row, mi_col, bsize, 1); + mi_row, mi_col, bsize, 1, ctx->rate); } } @@ -1310,10 +1307,9 @@ static void update_state_rt(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, : cm->last_frame_seg_map; mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); } else { - vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, - ctx->rate, ctx->dist); // Setting segmentation map for cyclic_refresh - vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize, 1); + vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize, 1, + ctx->rate); } vp9_init_plane_quantizers(cpi, x); } -- 2.40.0