From 74efda4bd6af40c73a78e82b65beb53079d68b8e Mon Sep 17 00:00:00 2001 From: Scott LaVarnway Date: Mon, 10 Dec 2012 10:33:01 -0800 Subject: [PATCH] Moved zbin_mode_boost to macroblock struct Fixing unsafe threading in VP8 encoder. Change-Id: Ibf4c89a2043654834747811bc11eb283de0bb830 --- vp8/encoder/block.h | 3 +++ vp8/encoder/encodeframe.c | 18 +++++++++--------- vp8/encoder/ethreading.c | 2 ++ vp8/encoder/onyx_if.c | 6 +++--- vp8/encoder/onyx_int.h | 4 ---- vp8/encoder/quantize.c | 14 +++++++------- vp8/encoder/rdopt.c | 12 ++++++------ 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/vp8/encoder/block.h b/vp8/encoder/block.h index 4d161f9..e3ff888 100644 --- a/vp8/encoder/block.h +++ b/vp8/encoder/block.h @@ -142,6 +142,9 @@ typedef struct macroblock int rd_threshes[MAX_MODES]; unsigned int mbs_tested_so_far; unsigned int mode_test_hit_counts[MAX_MODES]; + int zbin_mode_boost_enabled; + int zbin_mode_boost; + int last_zbin_mode_boost; int last_zbin_over_quant; int zbin_over_quant; diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index 219f7f3..9eaf670 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -1229,7 +1229,7 @@ int vp8cx_encode_inter_macroblock if (cpi->sf.RD) { - int zbin_mode_boost_enabled = cpi->zbin_mode_boost_enabled; + int zbin_mode_boost_enabled = x->zbin_mode_boost_enabled; /* Are we using the fast quantizer for the mode selection? */ if(cpi->sf.use_fastquant_for_pick) @@ -1239,7 +1239,7 @@ int vp8cx_encode_inter_macroblock /* the fast quantizer does not use zbin_extra, so * do not recalculate */ - cpi->zbin_mode_boost_enabled = 0; + x->zbin_mode_boost_enabled = 0; } vp8_rd_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate, &distortion, &intra_error); @@ -1252,7 +1252,7 @@ int vp8cx_encode_inter_macroblock } /* restore cpi->zbin_mode_boost_enabled */ - cpi->zbin_mode_boost_enabled = zbin_mode_boost_enabled; + x->zbin_mode_boost_enabled = zbin_mode_boost_enabled; } else @@ -1298,22 +1298,22 @@ int vp8cx_encode_inter_macroblock /* Experimental code. Special case for gf and arf zeromv modes. * Increase zbin size to supress noise */ - cpi->zbin_mode_boost = 0; - if (cpi->zbin_mode_boost_enabled) + x->zbin_mode_boost = 0; + if (x->zbin_mode_boost_enabled) { if ( xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME ) { if (xd->mode_info_context->mbmi.mode == ZEROMV) { if (xd->mode_info_context->mbmi.ref_frame != LAST_FRAME) - cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; + x->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; else - cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; + x->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; } else if (xd->mode_info_context->mbmi.mode == SPLITMV) - cpi->zbin_mode_boost = 0; + x->zbin_mode_boost = 0; else - cpi->zbin_mode_boost = MV_ZBIN_BOOST; + x->zbin_mode_boost = MV_ZBIN_BOOST; } } diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c index 3fb4c5b..58c8b0f 100644 --- a/vp8/encoder/ethreading.c +++ b/vp8/encoder/ethreading.c @@ -425,6 +425,8 @@ static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc) sizeof(x->rd_thresh_mult)); z->zbin_over_quant = x->zbin_over_quant; + z->zbin_mode_boost_enabled = x->zbin_mode_boost_enabled; + z->zbin_mode_boost = x->zbin_mode_boost; } } diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index eeba574..0b7f280 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -3309,18 +3309,18 @@ static void encode_frame_to_data_rate /* Clear zbin over-quant value and mode boost values. */ cpi->mb.zbin_over_quant = 0; - cpi->zbin_mode_boost = 0; + cpi->mb.zbin_mode_boost = 0; /* Enable or disable mode based tweaking of the zbin * For 2 Pass Only used where GF/ARF prediction quality * is above a threshold */ - cpi->zbin_mode_boost_enabled = 1; + cpi->mb.zbin_mode_boost_enabled = 1; if (cpi->pass == 2) { if ( cpi->gfu_boost <= 400 ) { - cpi->zbin_mode_boost_enabled = 0; + cpi->mb.zbin_mode_boost_enabled = 0; } } diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 8dbd5a2..7682ecc 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -412,10 +412,6 @@ typedef struct VP8_COMP int ni_frames; int avg_frame_qindex; - int zbin_mode_boost; - int zbin_mode_boost_enabled; - int last_zbin_mode_boost; - int64_t total_byte_count; int buffered_mode; diff --git a/vp8/encoder/quantize.c b/vp8/encoder/quantize.c index 7bdacc0..33c8ef0 100644 --- a/vp8/encoder/quantize.c +++ b/vp8/encoder/quantize.c @@ -588,19 +588,19 @@ void vp8cx_init_quantizer(VP8_COMP *cpi) #define ZBIN_EXTRA_Y \ (( cpi->common.Y1dequant[QIndex][1] * \ ( x->zbin_over_quant + \ - cpi->zbin_mode_boost + \ + x->zbin_mode_boost + \ x->act_zbin_adj ) ) >> 7) #define ZBIN_EXTRA_UV \ (( cpi->common.UVdequant[QIndex][1] * \ ( x->zbin_over_quant + \ - cpi->zbin_mode_boost + \ + x->zbin_mode_boost + \ x->act_zbin_adj ) ) >> 7) #define ZBIN_EXTRA_Y2 \ (( cpi->common.Y2dequant[QIndex][1] * \ ( (x->zbin_over_quant / 2) + \ - cpi->zbin_mode_boost + \ + x->zbin_mode_boost + \ x->act_zbin_adj ) ) >> 7) void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip) @@ -703,14 +703,14 @@ void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip) x->q_index = QIndex; x->last_zbin_over_quant = x->zbin_over_quant; - cpi->last_zbin_mode_boost = cpi->zbin_mode_boost; + x->last_zbin_mode_boost = x->zbin_mode_boost; x->last_act_zbin_adj = x->act_zbin_adj; } else if(x->last_zbin_over_quant != x->zbin_over_quant - || cpi->last_zbin_mode_boost != cpi->zbin_mode_boost + || x->last_zbin_mode_boost != x->zbin_mode_boost || x->last_act_zbin_adj != x->act_zbin_adj) { /* Y */ @@ -730,7 +730,7 @@ void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip) x->block[24].zbin_extra = (short)zbin_extra; x->last_zbin_over_quant = x->zbin_over_quant; - cpi->last_zbin_mode_boost = cpi->zbin_mode_boost; + x->last_zbin_mode_boost = x->zbin_mode_boost; x->last_act_zbin_adj = x->act_zbin_adj; } } @@ -764,7 +764,7 @@ void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x) void vp8cx_frame_init_quantizer(VP8_COMP *cpi) { /* Clear Zbin mode boost for default case */ - cpi->zbin_mode_boost = 0; + cpi->mb.zbin_mode_boost = 0; /* MB level quantizer setup */ vp8cx_mb_init_quantizer(cpi, &cpi->mb, 0); diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index 1e46632..ceb817c 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -2102,23 +2102,23 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, /* Experimental code. Special case for gf and arf zeromv modes. * Increase zbin size to supress noise */ - if (cpi->zbin_mode_boost_enabled) + if (x->zbin_mode_boost_enabled) { if ( this_ref_frame == INTRA_FRAME ) - cpi->zbin_mode_boost = 0; + x->zbin_mode_boost = 0; else { if (vp8_mode_order[mode_index] == ZEROMV) { if (this_ref_frame != LAST_FRAME) - cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; + x->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; else - cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; + x->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; } else if (vp8_mode_order[mode_index] == SPLITMV) - cpi->zbin_mode_boost = 0; + x->zbin_mode_boost = 0; else - cpi->zbin_mode_boost = MV_ZBIN_BOOST; + x->zbin_mode_boost = MV_ZBIN_BOOST; } vp8_update_zbin_extra(cpi, x); -- 2.7.4