From 269428e35c3312233ff0ff66bda5752f70a274f6 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Fri, 15 Jan 2016 14:32:52 -0800 Subject: [PATCH] Tie the bit cost scale to a define. This is a pure-refactor in preparation to potentially raise the bit-cost resolution. Verified at good speed 0 and rt speed -6. Change-Id: I5347e6e8c28a9ad9dd0aae1d76a3d0f3c2335bb9 --- vp9/encoder/vp9_cost.h | 3 +++ vp9/encoder/vp9_encodemb.c | 4 +++- vp9/encoder/vp9_encodemv.c | 3 ++- vp9/encoder/vp9_pickmode.c | 4 ++-- vp9/encoder/vp9_rd.c | 2 +- vp9/encoder/vp9_rd.h | 3 ++- vp9/encoder/vp9_rdopt.c | 2 +- vp9/encoder/vp9_subexp.c | 2 +- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/vp9/encoder/vp9_cost.h b/vp9/encoder/vp9_cost.h index eac74c40b..d8bf23f1e 100644 --- a/vp9/encoder/vp9_cost.h +++ b/vp9/encoder/vp9_cost.h @@ -19,6 +19,9 @@ extern "C" { extern const unsigned int vp9_prob_cost[256]; +// The factor to scale from cost in bits to cost in vp9_prob_cost units. +#define VP9_PROB_COST_SHIFT 8 + #define vp9_cost_zero(prob) (vp9_prob_cost[prob]) #define vp9_cost_one(prob) vp9_cost_zero(vpx_complement(prob)) diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c index 3c6a9283c..e34500975 100644 --- a/vp9/encoder/vp9_encodemb.c +++ b/vp9/encoder/vp9_encodemb.c @@ -50,7 +50,9 @@ void vp9_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) { pd->dst.buf, pd->dst.stride); } -#define RDTRUNC(RM, DM, R, D) ((128 + (R) * (RM)) & 0xFF) +#define RDTRUNC(RM, DM, R, D) \ + (((1 << (VP9_PROB_COST_SHIFT - 1)) + (R) * (RM)) & \ + ((1 << VP9_PROB_COST_SHIFT) - 1)) typedef struct vp9_token_state { int rate; diff --git a/vp9/encoder/vp9_encodemv.c b/vp9/encoder/vp9_encodemv.c index 3bcd6a3b6..109eba8c7 100644 --- a/vp9/encoder/vp9_encodemv.c +++ b/vp9/encoder/vp9_encodemv.c @@ -138,7 +138,8 @@ static int update_mv(vpx_writer *w, const unsigned int ct[2], vpx_prob *cur_p, vpx_prob upd_p) { const vpx_prob new_p = get_binary_prob(ct[0], ct[1]) | 1; const int update = cost_branch256(ct, *cur_p) + vp9_cost_zero(upd_p) > - cost_branch256(ct, new_p) + vp9_cost_one(upd_p) + 7 * 256; + cost_branch256(ct, new_p) + vp9_cost_one(upd_p) + + (7 << VP9_PROB_COST_SHIFT); vpx_write(w, update, upd_p); if (update) { *cur_p = new_p; diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 4880ff680..ec70df6d8 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -682,8 +682,8 @@ static void block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, int64_t *dist, } if (*skippable == 0) { - *rate <<= 10; - *rate += (eob_cost << 8); + *rate <<= (2 + VP9_PROB_COST_SHIFT); + *rate += (eob_cost << VP9_PROB_COST_SHIFT); } } #endif diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c index eda774376..6431b0364 100644 --- a/vp9/encoder/vp9_rd.c +++ b/vp9/encoder/vp9_rd.c @@ -409,7 +409,7 @@ void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n_log2, (((uint64_t)qstep * qstep << (n_log2 + 10)) + (var >> 1)) / var; const int xsq_q10 = (int)VPXMIN(xsq_q10_64, MAX_XSQ_Q10); model_rd_norm(xsq_q10, &r_q10, &d_q10); - *rate = ((r_q10 << n_log2) + 2) >> 2; + *rate = ROUND_POWER_OF_TWO(r_q10 << n_log2, 10 - VP9_PROB_COST_SHIFT); *dist = (var * (int64_t)d_q10 + 512) >> 10; } } diff --git a/vp9/encoder/vp9_rd.h b/vp9/encoder/vp9_rd.h index 28385c981..5e6e773a1 100644 --- a/vp9/encoder/vp9_rd.h +++ b/vp9/encoder/vp9_rd.h @@ -17,6 +17,7 @@ #include "vp9/encoder/vp9_block.h" #include "vp9/encoder/vp9_context_tree.h" +#include "vp9/encoder/vp9_cost.h" #ifdef __cplusplus extern "C" { @@ -25,7 +26,7 @@ extern "C" { #define RDDIV_BITS 7 #define RDCOST(RM, DM, R, D) \ - (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM)) + (ROUND_POWER_OF_TWO(((int64_t)R) * (RM), VP9_PROB_COST_SHIFT) + (D << DM)) #define QIDX_SKIP_THRESH 115 #define MV_COST_WEIGHT 108 diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 8ab4c8b35..ca0456144 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -248,7 +248,7 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, int quantizer = (pd->dequant[1] >> dequant_shift); if (quantizer < 120) - rate = (square_error * (280 - quantizer)) >> 8; + rate = (square_error * (280 - quantizer)) >> (16 - VP9_PROB_COST_SHIFT); else rate = 0; dist = (square_error * quantizer) >> 8; diff --git a/vp9/encoder/vp9_subexp.c b/vp9/encoder/vp9_subexp.c index 7aa8fc3f6..1a8719940 100644 --- a/vp9/encoder/vp9_subexp.c +++ b/vp9/encoder/vp9_subexp.c @@ -80,7 +80,7 @@ static int remap_prob(int v, int m) { static int prob_diff_update_cost(vpx_prob newp, vpx_prob oldp) { int delp = remap_prob(newp, oldp); - return update_bits[delp] * 256; + return update_bits[delp] << VP9_PROB_COST_SHIFT; } static void encode_uniform(vpx_writer *w, int v) { -- 2.49.0