From 0f7dd403243f35c7d1059fdf9826efef185c189d Mon Sep 17 00:00:00 2001 From: Zoe Liu Date: Thu, 4 Feb 2016 05:33:22 -0800 Subject: [PATCH] Define a macro to replace hardcoded values The definition is for the number of frames to check to determine the recent decay rate, further to determine the next key frame in the first pass of the encoder. Change-Id: Ic696d6eb518a86fa296842273cf8767ef0b0e27a --- vp10/encoder/firstpass.c | 12 +++++++++--- vp9/encoder/vp9_firstpass.c | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/vp10/encoder/firstpass.c b/vp10/encoder/firstpass.c index 80e461b32..bc1ce001b 100644 --- a/vp10/encoder/firstpass.c +++ b/vp10/encoder/firstpass.c @@ -2135,6 +2135,8 @@ static int test_candidate_kf(TWO_PASS *twopass, return is_viable_kf; } +#define FRAMES_TO_CHECK_DECAY 8 + static void find_next_key_frame(VP10_COMP *cpi, FIRSTPASS_STATS *this_frame) { int i, j; RATE_CONTROL *const rc = &cpi->rc; @@ -2153,7 +2155,7 @@ static void find_next_key_frame(VP10_COMP *cpi, FIRSTPASS_STATS *this_frame) { double boost_score = 0.0; double kf_mod_err = 0.0; double kf_group_err = 0.0; - double recent_loop_decay[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; + double recent_loop_decay[FRAMES_TO_CHECK_DECAY]; vp10_zero(next_frame); @@ -2180,6 +2182,10 @@ static void find_next_key_frame(VP10_COMP *cpi, FIRSTPASS_STATS *this_frame) { kf_mod_err = calculate_modified_err(cpi, twopass, oxcf, this_frame); + // Initialize the decay rates for the recent frames to check + for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) + recent_loop_decay[j] = 1.0; + // Find the next keyframe. i = 0; while (twopass->stats_in < twopass->stats_in_end && @@ -2206,9 +2212,9 @@ static void find_next_key_frame(VP10_COMP *cpi, FIRSTPASS_STATS *this_frame) { // We want to know something about the recent past... rather than // as used elsewhere where we are concerned with decay in prediction // quality since the last GF or KF. - recent_loop_decay[i % 8] = loop_decay_rate; + recent_loop_decay[i % FRAMES_TO_CHECK_DECAY] = loop_decay_rate; decay_accumulator = 1.0; - for (j = 0; j < 8; ++j) + for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) decay_accumulator *= recent_loop_decay[j]; // Special check for transition or high motion followed by a diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 71843eea7..9d3b15407 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -2260,6 +2260,8 @@ static int test_candidate_kf(TWO_PASS *twopass, return is_viable_kf; } +#define FRAMES_TO_CHECK_DECAY 8 + static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { int i, j; RATE_CONTROL *const rc = &cpi->rc; @@ -2278,7 +2280,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { double boost_score = 0.0; double kf_mod_err = 0.0; double kf_group_err = 0.0; - double recent_loop_decay[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; + double recent_loop_decay[FRAMES_TO_CHECK_DECAY]; vp9_zero(next_frame); @@ -2305,6 +2307,10 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { kf_mod_err = calculate_modified_err(cpi, twopass, oxcf, this_frame); + // Initialize the decay rates for the recent frames to check + for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) + recent_loop_decay[j] = 1.0; + // Find the next keyframe. i = 0; while (twopass->stats_in < twopass->stats_in_end && @@ -2331,9 +2337,9 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { // We want to know something about the recent past... rather than // as used elsewhere where we are concerned with decay in prediction // quality since the last GF or KF. - recent_loop_decay[i % 8] = loop_decay_rate; + recent_loop_decay[i % FRAMES_TO_CHECK_DECAY] = loop_decay_rate; decay_accumulator = 1.0; - for (j = 0; j < 8; ++j) + for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) decay_accumulator *= recent_loop_decay[j]; // Special check for transition or high motion followed by a