summaryrefslogtreecommitdiff
path: root/vp9
diff options
context:
space:
mode:
authorYaowu Xu <yaowu@google.com>2018-11-07 11:20:32 -0800
committerYaowu Xu <yaowu@google.com>2018-11-07 11:33:07 -0800
commit5c96d3b82b985df06b586296ecac7ee5ba390b3d (patch)
tree3488c1f183a98fb91b2a3085cca81f4a74774fbf /vp9
parentec12c265e970b220b914587aaf7f26871860e538 (diff)
downloadlibvpx-5c96d3b82b985df06b586296ecac7ee5ba390b3d.tar.gz
libvpx-5c96d3b82b985df06b586296ecac7ee5ba390b3d.tar.bz2
libvpx-5c96d3b82b985df06b586296ecac7ee5ba390b3d.zip
Simplify rdmult computation
Recognizing that max dc_quant used in rdmult computation is 21387 and 21387 * 21387 * 88 / 24 is still within the range of int32_t, this commit simplifies the computation with minor cleanups. Change-Id: I2ac7e8315d103c0bb39b70c312c87c0fda47b4f9
Diffstat (limited to 'vp9')
-rw-r--r--vp9/encoder/vp9_encoder.c4
-rw-r--r--vp9/encoder/vp9_rd.c23
-rw-r--r--vp9/encoder/vp9_rd.h3
-rw-r--r--vp9/encoder/vp9_temporal_filter.c3
4 files changed, 12 insertions, 21 deletions
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
index 40c7a626e..b0ad5e334 100644
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -6241,9 +6241,7 @@ void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, int frame_idx,
xd->cur_buf = this_frame;
// Get rd multiplier set up.
- rdmult =
- (int)vp9_compute_rd_mult_based_on_qindex(cpi, tpl_frame->base_qindex);
- if (rdmult < 1) rdmult = 1;
+ rdmult = vp9_compute_rd_mult_based_on_qindex(cpi, tpl_frame->base_qindex);
set_error_per_bit(&cpi->td.mb, rdmult);
vp9_initialize_me_consts(cpi, &cpi->td.mb, tpl_frame->base_qindex);
diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c
index d6ec96b82..e65cf42d8 100644
--- a/vp9/encoder/vp9_rd.c
+++ b/vp9/encoder/vp9_rd.c
@@ -173,27 +173,23 @@ static const int rd_boost_factor[16] = { 64, 32, 32, 32, 24, 16, 12, 12,
static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = { 128, 144, 128,
128, 144, 144 };
-int64_t vp9_compute_rd_mult_based_on_qindex(const VP9_COMP *cpi, int qindex) {
- const int64_t q = vp9_dc_quant(qindex, 0, cpi->common.bit_depth);
+int vp9_compute_rd_mult_based_on_qindex(const VP9_COMP *cpi, int qindex) {
+ // largest dc_quant is 21387, therefore rdmult should always fit in int32_t
+ const int q = vp9_dc_quant(qindex, 0, cpi->common.bit_depth);
+ int rdmult = q * q;
+ rdmult = rdmult * 3 + (rdmult * 2 / 3);
#if CONFIG_VP9_HIGHBITDEPTH
- int64_t rdmult = 0;
switch (cpi->common.bit_depth) {
- case VPX_BITS_8: rdmult = 88 * q * q / 24; break;
- case VPX_BITS_10: rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 4); break;
- default:
- assert(cpi->common.bit_depth == VPX_BITS_12);
- rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 8);
- break;
+ case VPX_BITS_10: rdmult = ROUND_POWER_OF_TWO(rdmult, 4); break;
+ case VPX_BITS_12: rdmult = ROUND_POWER_OF_TWO(rdmult, 8); break;
+ default: break;
}
-#else
- int64_t rdmult = 88 * q * q / 24;
#endif // CONFIG_VP9_HIGHBITDEPTH
- return rdmult;
+ return rdmult > 0 ? rdmult : 1;
}
int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) {
int64_t rdmult = vp9_compute_rd_mult_based_on_qindex(cpi, qindex);
-
if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
@@ -205,7 +201,6 @@ int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) {
rdmult = (rdmult * rd_frame_type_factor[frame_type]) >> 7;
rdmult += ((rdmult * rd_boost_factor[boost_index]) >> 7);
}
- if (rdmult < 1) rdmult = 1;
return (int)rdmult;
}
diff --git a/vp9/encoder/vp9_rd.h b/vp9/encoder/vp9_rd.h
index a1a98bd91..fa85f2176 100644
--- a/vp9/encoder/vp9_rd.h
+++ b/vp9/encoder/vp9_rd.h
@@ -134,8 +134,7 @@ struct TileDataEnc;
struct VP9_COMP;
struct macroblock;
-int64_t vp9_compute_rd_mult_based_on_qindex(const struct VP9_COMP *cpi,
- int qindex);
+int vp9_compute_rd_mult_based_on_qindex(const struct VP9_COMP *cpi, int qindex);
int vp9_compute_rd_mult(const struct VP9_COMP *cpi, int qindex);
diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c
index 5333e4cd4..4c1d8894b 100644
--- a/vp9/encoder/vp9_temporal_filter.c
+++ b/vp9/encoder/vp9_temporal_filter.c
@@ -952,8 +952,7 @@ void vp9_temporal_filter(VP9_COMP *cpi, int distance) {
}
// Initialize errorperbit and sabperbit.
- rdmult = (int)vp9_compute_rd_mult_based_on_qindex(cpi, ARNR_FILT_QINDEX);
- if (rdmult < 1) rdmult = 1;
+ rdmult = vp9_compute_rd_mult_based_on_qindex(cpi, ARNR_FILT_QINDEX);
set_error_per_bit(&cpi->td.mb, rdmult);
vp9_initialize_me_consts(cpi, &cpi->td.mb, ARNR_FILT_QINDEX);