Commit 9a005c99 authored by Deb Mukherjee's avatar Deb Mukherjee Committed by Gerrit Code Review

Merge "Rate control changes on active_worst_quality"

parents e7198563 1e59cbf2
......@@ -1460,7 +1460,7 @@ static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) {
// int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0;
int use_8x8 = 1;
if (cm->frame_type && !cpi->is_src_frame_alt_ref &&
if (cm->frame_type && !cpi->rc.is_src_frame_alt_ref &&
((use_8x8 && bsize == BLOCK_16X16) ||
bsize == BLOCK_32X32 || bsize == BLOCK_64X64)) {
int ref0 = 0, ref1 = 0, ref2 = 0, ref3 = 0;
......@@ -1949,7 +1949,7 @@ static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile,
|| cm->prev_mi == 0
|| cpi->common.show_frame == 0
|| cpi->common.frame_type == KEY_FRAME
|| cpi->is_src_frame_alt_ref
|| cpi->rc.is_src_frame_alt_ref
|| ((cpi->sf.use_lastframe_partitioning ==
LAST_FRAME_PARTITION_LOW_MOTION) &&
sb_has_motion(cpi, prev_mi_8x8))) {
......@@ -2279,7 +2279,7 @@ static int get_frame_type(VP9_COMP *cpi) {
int frame_type;
if (frame_is_intra_only(&cpi->common))
frame_type = 0;
else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame)
else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame)
frame_type = 3;
else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)
frame_type = 1;
......
......@@ -1514,6 +1514,8 @@ void define_fixed_arf_period(VP9_COMP *cpi) {
cpi->this_frame_weight = cpi->arf_weight[cpi->sequence_number];
assert(cpi->this_frame_weight >= 0);
cpi->twopass.gf_zeromotion_pct = 0;
// Initialize frame coding order variables.
cpi->new_frame_coding_order_period = 0;
cpi->next_frame_in_order = 0;
......@@ -1522,14 +1524,14 @@ void define_fixed_arf_period(VP9_COMP *cpi) {
vp9_zero(cpi->arf_buffer_idx);
vpx_memset(cpi->arf_weight, -1, sizeof(cpi->arf_weight));
if (cpi->twopass.frames_to_key <= (FIXED_ARF_GROUP_SIZE + 8)) {
if (cpi->rc.frames_to_key <= (FIXED_ARF_GROUP_SIZE + 8)) {
// Setup a GF group close to the keyframe.
cpi->source_alt_ref_pending = 0;
cpi->rc.baseline_gf_interval = cpi->twopass.frames_to_key;
cpi->rc.source_alt_ref_pending = 0;
cpi->rc.baseline_gf_interval = cpi->rc.frames_to_key;
schedule_frames(cpi, 0, (cpi->rc.baseline_gf_interval - 1), 2, 0, 0);
} else {
// Setup a fixed period ARF group.
cpi->source_alt_ref_pending = 1;
cpi->rc.source_alt_ref_pending = 1;
cpi->rc.baseline_gf_interval = FIXED_ARF_GROUP_SIZE;
schedule_frames(cpi, 0, -(cpi->rc.baseline_gf_interval - 1), 2, 1, 0);
}
......@@ -1627,16 +1629,17 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// bits to spare and are better with a smaller interval and smaller boost.
// At high Q when there are few bits to spare we are better with a longer
// interval to spread the cost of the GF.
//
active_max_gf_interval =
12 + ((int)vp9_convert_qindex_to_q(cpi->rc.active_worst_quality) >> 5);
11 + ((int)vp9_convert_qindex_to_q(cpi->rc.last_q[INTER_FRAME]) >> 5);
if (active_max_gf_interval > cpi->rc.max_gf_interval)
active_max_gf_interval = cpi->rc.max_gf_interval;
i = 0;
while (((i < cpi->twopass.static_scene_max_gf_interval) ||
((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL)) &&
(i < cpi->twopass.frames_to_key)) {
((cpi->rc.frames_to_key - i) < MIN_GF_INTERVAL)) &&
(i < cpi->rc.frames_to_key)) {
i++; // Increment the loop counter
// Accumulate error score of frames in this gf group
......@@ -1691,7 +1694,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Don't break out with a very short interval
(i > MIN_GF_INTERVAL) &&
// Don't break out very close to a key frame
((cpi->twopass.frames_to_key - i) >= MIN_GF_INTERVAL) &&
((cpi->rc.frames_to_key - i) >= MIN_GF_INTERVAL) &&
((boost_score > 125.0) || (next_frame.pcnt_inter < 0.75)) &&
(!flash_detected) &&
((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
......@@ -1707,17 +1710,17 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
old_boost_score = boost_score;
}
cpi->gf_zeromotion_pct = (int)(zero_motion_accumulator * 1000.0);
cpi->twopass.gf_zeromotion_pct = (int)(zero_motion_accumulator * 1000.0);
// Don't allow a gf too near the next kf
if ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL) {
while (i < cpi->twopass.frames_to_key) {
if ((cpi->rc.frames_to_key - i) < MIN_GF_INTERVAL) {
while (i < cpi->rc.frames_to_key) {
i++;
if (EOF == input_stats(cpi, this_frame))
break;
if (i < cpi->twopass.frames_to_key) {
if (i < cpi->rc.frames_to_key) {
mod_frame_err = calculate_modified_err(cpi, this_frame);
gf_group_err += mod_frame_err;
}
......@@ -1744,7 +1747,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
(i < cpi->oxcf.lag_in_frames) &&
(i >= MIN_GF_INTERVAL) &&
// dont use ARF very near next kf
(i <= (cpi->twopass.frames_to_key - MIN_GF_INTERVAL)) &&
(i <= (cpi->rc.frames_to_key - MIN_GF_INTERVAL)) &&
((next_frame.pcnt_inter > 0.75) ||
(next_frame.pcnt_second_ref > 0.5)) &&
((mv_in_out_accumulator / (double)i > -0.2) ||
......@@ -1753,7 +1756,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Alternative boost calculation for alt ref
cpi->rc.gfu_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost,
&b_boost);
cpi->source_alt_ref_pending = 1;
cpi->rc.source_alt_ref_pending = 1;
#if CONFIG_MULTIPLE_ARF
// Set the ARF schedule.
......@@ -1763,7 +1766,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
#endif
} else {
cpi->rc.gfu_boost = (int)boost_score;
cpi->source_alt_ref_pending = 0;
cpi->rc.source_alt_ref_pending = 0;
#if CONFIG_MULTIPLE_ARF
// Set the GF schedule.
if (cpi->multi_arf_enabled) {
......@@ -1818,7 +1821,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// where cpi->twopass.kf_group_bits is tied to cpi->twopass.bits_left.
// This is also important for short clips where there may only be one
// key frame.
if (cpi->twopass.frames_to_key >= (int)(cpi->twopass.total_stats.count -
if (cpi->rc.frames_to_key >= (int)(cpi->twopass.total_stats.count -
cpi->common.current_video_frame)) {
cpi->twopass.kf_group_bits =
(cpi->twopass.bits_left > 0) ? cpi->twopass.bits_left : 0;
......@@ -1854,7 +1857,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Assign bits to the arf or gf.
for (i = 0;
i <= (cpi->source_alt_ref_pending && cpi->common.frame_type != KEY_FRAME);
i <= (cpi->rc.source_alt_ref_pending &&
cpi->common.frame_type != KEY_FRAME);
++i) {
int allocation_chunks;
int q = cpi->rc.last_q[INTER_FRAME];
......@@ -1865,7 +1869,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Set max and minimum boost and hence minimum allocation
boost = clamp(boost, 125, (cpi->rc.baseline_gf_interval + 1) * 200);
if (cpi->source_alt_ref_pending && i == 0)
if (cpi->rc.source_alt_ref_pending && i == 0)
allocation_chunks = ((cpi->rc.baseline_gf_interval + 1) * 100) + boost;
else
allocation_chunks = (cpi->rc.baseline_gf_interval * 100) + (boost - 100);
......@@ -1918,7 +1922,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
if (i == 0) {
cpi->twopass.gf_bits = gf_bits;
}
if (i == 1 || (!cpi->source_alt_ref_pending
if (i == 1 || (!cpi->rc.source_alt_ref_pending
&& (cpi->common.frame_type != KEY_FRAME))) {
// Per frame bit target for this frame
cpi->rc.per_frame_bandwidth = gf_bits;
......@@ -1937,7 +1941,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// For normal GFs we want to remove the error score for the first frame
// of the group (except in Key frame case where this has already
// happened)
if (!cpi->source_alt_ref_pending && cpi->common.frame_type != KEY_FRAME)
if (!cpi->rc.source_alt_ref_pending && cpi->common.frame_type != KEY_FRAME)
cpi->twopass.gf_group_error_left = (int64_t)(gf_group_err
- gf_first_frame_err);
else
......@@ -1953,7 +1957,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// despite (MIN_GF_INTERVAL) and would cause a divide by 0 in the
// calculation of alt_extra_bits.
if (cpi->rc.baseline_gf_interval >= 3) {
const int boost = cpi->source_alt_ref_pending ?
const int boost = cpi->rc.source_alt_ref_pending ?
b_boost : cpi->rc.gfu_boost;
if (boost >= 150) {
......@@ -2095,7 +2099,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
// estimate for the clip is bad, but helps prevent excessive
// variation in Q, especially near the end of a clip
// where for example a small overspend may cause Q to crash
adjust_maxq_qrange(cpi);
// adjust_maxq_qrange(cpi);
}
vp9_zero(this_frame);
if (EOF == input_stats(cpi, &this_frame))
......@@ -2105,7 +2109,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
this_frame_coded_error = this_frame.coded_error;
// keyframe and section processing !
if (cpi->twopass.frames_to_key == 0) {
if (cpi->rc.frames_to_key == 0) {
// Define next KF group and assign bits to it
this_frame_copy = this_frame;
find_next_key_frame(cpi, &this_frame_copy);
......@@ -2116,8 +2120,6 @@ void vp9_second_pass(VP9_COMP *cpi) {
// Define next gf group and assign bits to it
this_frame_copy = this_frame;
cpi->gf_zeromotion_pct = 0;
#if CONFIG_MULTIPLE_ARF
if (cpi->multi_arf_enabled) {
define_fixed_arf_period(cpi);
......@@ -2128,7 +2130,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
}
#endif
if (cpi->gf_zeromotion_pct > 995) {
if (cpi->twopass.gf_zeromotion_pct > 995) {
// As long as max_thresh for encode breakout is small enough, it is ok
// to enable it for no-show frame, i.e. set enable_encode_breakout to 2.
if (!cpi->common.show_frame)
......@@ -2143,7 +2145,8 @@ void vp9_second_pass(VP9_COMP *cpi) {
// from that arf boost and it should not be given extra bits
// If the previous group was NOT coded using arf we may want to apply
// some boost to this GF as well
if (cpi->source_alt_ref_pending && (cpi->common.frame_type != KEY_FRAME)) {
if (cpi->rc.source_alt_ref_pending &&
cpi->common.frame_type != KEY_FRAME) {
// Assign a standard frames worth of bits from those allocated
// to the GF group
int bak = cpi->rc.per_frame_bandwidth;
......@@ -2175,7 +2178,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
if (cpi->target_bandwidth < 0)
cpi->target_bandwidth = 0;
cpi->twopass.frames_to_key--;
cpi->rc.frames_to_key--;
// Update the total stats remaining structure
subtract_stats(&cpi->twopass.total_left_stats, &this_frame);
......@@ -2271,6 +2274,7 @@ static int test_candidate_kf(VP9_COMP *cpi,
return is_viable_kf;
}
static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
int i, j;
FIRSTPASS_STATS last_frame;
......@@ -2297,15 +2301,15 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
cpi->common.frame_type = KEY_FRAME;
// is this a forced key frame by interval
cpi->this_key_frame_forced = cpi->next_key_frame_forced;
cpi->rc.this_key_frame_forced = cpi->rc.next_key_frame_forced;
// Clear the alt ref active flag as this can never be active on a key frame
cpi->source_alt_ref_active = 0;
cpi->rc.source_alt_ref_active = 0;
// Kf is always a gf so clear frames till next gf counter
cpi->rc.frames_till_gf_update_due = 0;
cpi->twopass.frames_to_key = 1;
cpi->rc.frames_to_key = 1;
// Take a copy of the initial frame details
first_frame = *this_frame;
......@@ -2357,14 +2361,14 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
break;
// Step on to the next frame
cpi->twopass.frames_to_key++;
cpi->rc.frames_to_key++;
// If we don't have a real key frame within the next two
// forcekeyframeevery intervals then break out of the loop.
if (cpi->twopass.frames_to_key >= 2 * (int)cpi->key_frame_frequency)
if (cpi->rc.frames_to_key >= 2 * (int)cpi->key_frame_frequency)
break;
} else {
cpi->twopass.frames_to_key++;
cpi->rc.frames_to_key++;
}
i++;
}
......@@ -2374,11 +2378,11 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// This code centers the extra kf if the actual natural
// interval is between 1x and 2x
if (cpi->oxcf.auto_key
&& cpi->twopass.frames_to_key > (int)cpi->key_frame_frequency) {
&& cpi->rc.frames_to_key > (int)cpi->key_frame_frequency) {
FIRSTPASS_STATS *current_pos = cpi->twopass.stats_in;
FIRSTPASS_STATS tmp_frame;
cpi->twopass.frames_to_key /= 2;
cpi->rc.frames_to_key /= 2;
// Copy first frame details
tmp_frame = first_frame;
......@@ -2391,7 +2395,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
kf_group_coded_err = 0;
// Rescan to get the correct error data for the forced kf group
for (i = 0; i < cpi->twopass.frames_to_key; i++) {
for (i = 0; i < cpi->rc.frames_to_key; i++) {
// Accumulate kf group errors
kf_group_err += calculate_modified_err(cpi, &tmp_frame);
kf_group_intra_err += tmp_frame.intra_error;
......@@ -2404,9 +2408,9 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Reset to the start of the group
reset_fpf_position(cpi, current_pos);
cpi->next_key_frame_forced = 1;
cpi->rc.next_key_frame_forced = 1;
} else {
cpi->next_key_frame_forced = 0;
cpi->rc.next_key_frame_forced = 0;
}
// Special case for the last frame of the file
if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end) {
......@@ -2436,7 +2440,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
cpi->twopass.modified_error_left));
// Clip based on maximum per frame rate defined by the user.
max_grp_bits = (int64_t)max_bits * (int64_t)cpi->twopass.frames_to_key;
max_grp_bits = (int64_t)max_bits * (int64_t)cpi->rc.frames_to_key;
if (cpi->twopass.kf_group_bits > max_grp_bits)
cpi->twopass.kf_group_bits = max_grp_bits;
} else {
......@@ -2452,7 +2456,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
loop_decay_rate = 1.00; // Starting decay rate
// Scan through the kf group collating various stats.
for (i = 0; i < cpi->twopass.frames_to_key; i++) {
for (i = 0; i < cpi->rc.frames_to_key; i++) {
double r;
if (EOF == input_stats(cpi, &next_frame))
......@@ -2495,7 +2499,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
zero_stats(&sectionstats);
reset_fpf_position(cpi, start_position);
for (i = 0; i < cpi->twopass.frames_to_key; i++) {
for (i = 0; i < cpi->rc.frames_to_key; i++) {
input_stats(cpi, &next_frame);
accumulate_stats(&sectionstats, &next_frame);
}
......@@ -2516,8 +2520,8 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
int allocation_chunks;
int alt_kf_bits;
if (kf_boost < (cpi->twopass.frames_to_key * 3))
kf_boost = (cpi->twopass.frames_to_key * 3);
if (kf_boost < (cpi->rc.frames_to_key * 3))
kf_boost = (cpi->rc.frames_to_key * 3);
if (kf_boost < 300) // Min KF boost
kf_boost = 300;
......@@ -2525,7 +2529,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Make a note of baseline boost and the zero motion
// accumulator value for use elsewhere.
cpi->rc.kf_boost = kf_boost;
cpi->kf_zeromotion_pct = (int)(zero_motion_accumulator * 100.0);
cpi->twopass.kf_zeromotion_pct = (int)(zero_motion_accumulator * 100.0);
// We do three calculations for kf size.
// The first is based on the error score for the whole kf group.
......@@ -2537,14 +2541,14 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Special case if the sequence appears almost totaly static
// In this case we want to spend almost all of the bits on the
// key frame.
// cpi->twopass.frames_to_key-1 because key frame itself is taken
// cpi->rc.frames_to_key-1 because key frame itself is taken
// care of by kf_boost.
if (zero_motion_accumulator >= 0.99) {
allocation_chunks =
((cpi->twopass.frames_to_key - 1) * 10) + kf_boost;
((cpi->rc.frames_to_key - 1) * 10) + kf_boost;
} else {
allocation_chunks =
((cpi->twopass.frames_to_key - 1) * 100) + kf_boost;
((cpi->rc.frames_to_key - 1) * 100) + kf_boost;
}
// Prevent overflow
......@@ -2566,10 +2570,10 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// kf group (which does sometimes happen... eg a blank intro frame)
// Then use an alternate calculation based on the kf error score
// which should give a smaller key frame.
if (kf_mod_err < kf_group_err / cpi->twopass.frames_to_key) {
if (kf_mod_err < kf_group_err / cpi->rc.frames_to_key) {
double alt_kf_grp_bits =
((double)cpi->twopass.bits_left *
(kf_mod_err * (double)cpi->twopass.frames_to_key) /
(kf_mod_err * (double)cpi->rc.frames_to_key) /
DOUBLE_DIVIDE_CHECK(cpi->twopass.modified_error_left));
alt_kf_bits = (int)((double)kf_boost *
......
......@@ -399,8 +399,7 @@ void vp9_update_mbgraph_stats(VP9_COMP *cpi) {
// being a GF - so exit if we don't look ahead beyond that
if (n_frames <= cpi->rc.frames_till_gf_update_due)
return;
if (n_frames > (int)cpi->frames_till_alt_ref_frame)
n_frames = cpi->frames_till_alt_ref_frame;
if (n_frames > MAX_LAG_BUFFERS)
n_frames = MAX_LAG_BUFFERS;
......
......@@ -302,7 +302,7 @@ static void setup_in_frame_q_adj(VP9_COMP *cpi) {
if (cm->frame_type == KEY_FRAME ||
cpi->refresh_alt_ref_frame ||
(cpi->refresh_golden_frame && !cpi->is_src_frame_alt_ref)) {
(cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) {
// Clear down the segment map
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
......@@ -389,7 +389,7 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
// First normal frame in a valid gf or alt ref group
if (cpi->rc.frames_since_golden == 0) {
// Set up segment features for normal frames in an arf group
if (cpi->source_alt_ref_active) {
if (cpi->rc.source_alt_ref_active) {
seg->update_map = 0;
seg->update_data = 1;
seg->abs_delta = SEGMENT_DELTADATA;
......@@ -421,7 +421,7 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
vp9_clearall_segfeatures(seg);
}
} else if (cpi->is_src_frame_alt_ref) {
} else if (cpi->rc.is_src_frame_alt_ref) {
// Special case where we are coding over the top of a previous
// alt ref frame.
// Segment coding disabled for compred testing
......@@ -1048,6 +1048,7 @@ int vp9_reverse_trans(int x) {
return 63;
};
void vp9_new_framerate(VP9_COMP *cpi, double framerate) {
if (framerate < 0.1)
framerate = 30;
......@@ -1124,7 +1125,15 @@ static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
// Initialize active best and worst q and average q values.
cpi->rc.active_worst_quality = cpi->oxcf.worst_allowed_q;
cpi->rc.avg_frame_qindex = cpi->oxcf.worst_allowed_q;
cpi->rc.avg_frame_qindex[0] = (cpi->oxcf.worst_allowed_q +
cpi->oxcf.best_allowed_q) / 2;
cpi->rc.avg_frame_qindex[1] = (cpi->oxcf.worst_allowed_q +
cpi->oxcf.best_allowed_q) / 2;
cpi->rc.avg_frame_qindex[2] = (cpi->oxcf.worst_allowed_q +
cpi->oxcf.best_allowed_q) / 2;
cpi->rc.last_q[0] = cpi->oxcf.best_allowed_q;
cpi->rc.last_q[1] = cpi->oxcf.best_allowed_q;
cpi->rc.last_q[2] = cpi->oxcf.best_allowed_q;
// Initialise the starting buffer levels
cpi->rc.buffer_level = cpi->oxcf.starting_buffer_level;
......@@ -1288,6 +1297,7 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
if (cpi->oxcf.fixed_q >= 0) {
cpi->rc.last_q[0] = cpi->oxcf.fixed_q;
cpi->rc.last_q[1] = cpi->oxcf.fixed_q;
cpi->rc.last_q[2] = cpi->oxcf.fixed_q;
cpi->rc.last_boosted_qindex = cpi->oxcf.fixed_q;
}
......@@ -1307,7 +1317,7 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
#else
cpi->alt_ref_source = NULL;
#endif
cpi->is_src_frame_alt_ref = 0;
cpi->rc.is_src_frame_alt_ref = 0;
#if 0
// Experimental RD Code
......@@ -1567,14 +1577,14 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
/*Initialize the feed-forward activity masking.*/
cpi->activity_avg = 90 << 12;
cpi->frames_since_key = 8; // Sensible default for first frame.
cpi->key_frame_frequency = cpi->oxcf.key_freq;
cpi->this_key_frame_forced = 0;
cpi->next_key_frame_forced = 0;
cpi->source_alt_ref_pending = 0;
cpi->source_alt_ref_active = 0;
cpi->rc.frames_since_key = 8; // Sensible default for first frame.
cpi->rc.this_key_frame_forced = 0;
cpi->rc.next_key_frame_forced = 0;
cpi->rc.source_alt_ref_pending = 0;
cpi->rc.source_alt_ref_active = 0;
cpi->refresh_alt_ref_frame = 0;
#if CONFIG_MULTIPLE_ARF
......@@ -1627,7 +1637,6 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
cpi->first_time_stamp_ever = INT64_MAX;
cpi->rc.frames_till_gf_update_due = 0;
cpi->rc.key_frame_count = 1;
cpi->rc.ni_av_qi = cpi->oxcf.worst_allowed_q;
cpi->rc.ni_tot_qi = 0;
......@@ -1652,9 +1661,6 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX];
cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp);
for (i = 0; i < KEY_FRAME_CONTEXT; i++)
cpi->rc.prior_key_frame_distance[i] = (int)cpi->output_framerate;
#ifdef OUTPUT_YUV_SRC
yuv_file = fopen("bd.yuv", "ab");
#endif
......@@ -2309,11 +2315,12 @@ static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
if (!cpi->multi_arf_enabled)
#endif
// Clear the alternate reference update pending flag.
cpi->source_alt_ref_pending = 0;
cpi->rc.source_alt_ref_pending = 0;
// Set the alternate reference frame active flag
cpi->source_alt_ref_active = 1;
cpi->rc.source_alt_ref_active = 1;
}
static void update_golden_frame_stats(VP9_COMP *cpi) {
// Update the Golden frame usage counts.
if (cpi->refresh_golden_frame) {
......@@ -2326,7 +2333,7 @@ static void update_golden_frame_stats(VP9_COMP *cpi) {
// set a flag to say so.
if (cpi->oxcf.fixed_q >= 0 &&
cpi->oxcf.play_alternate && !cpi->refresh_alt_ref_frame) {
cpi->source_alt_ref_pending = 1;
cpi->rc.source_alt_ref_pending = 1;
cpi->rc.frames_till_gf_update_due = cpi->rc.baseline_gf_interval;
// TODO(ivan): For SVC encoder, GF automatic update is disabled by using
......@@ -2336,8 +2343,8 @@ static void update_golden_frame_stats(VP9_COMP *cpi) {
}
}
if (!cpi->source_alt_ref_pending)
cpi->source_alt_ref_active = 0;
if (!cpi->rc.source_alt_ref_pending)
cpi->rc.source_alt_ref_active = 0;
// Decrement count down till next gf
if (cpi->rc.frames_till_gf_update_due > 0)
......@@ -2348,9 +2355,6 @@ static void update_golden_frame_stats(VP9_COMP *cpi) {
if (cpi->rc.frames_till_gf_update_due > 0)
cpi->rc.frames_till_gf_update_due--;
if (cpi->frames_till_alt_ref_frame)
cpi->frames_till_alt_ref_frame--;
cpi->rc.frames_since_golden++;
}
}
......@@ -2642,7 +2646,7 @@ static void output_frame_level_debug_stats(VP9_COMP *cpi) {
(double)cpi->twopass.bits_left /
(1 + cpi->twopass.total_left_stats.coded_error),
cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost,
cpi->kf_zeromotion_pct);
cpi->twopass.kf_zeromotion_pct);
fclose(f);
......@@ -2736,7 +2740,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
loop = 0;
} else {
// Special case handling for forced key frames
if ((cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced) {
if ((cm->frame_type == KEY_FRAME) && cpi->rc.this_key_frame_forced) {
int last_q = *q;
int kf_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm));
......@@ -2850,7 +2854,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
}
}
if (cpi->is_src_frame_alt_ref)
if (cpi->rc.is_src_frame_alt_ref)
loop = 0;
if (loop) {
......@@ -2873,7 +2877,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
int frame_over_shoot_limit;
int frame_under_shoot_limit;
int top_index;
int top_index_prop;
int bottom_index;
SPEED_FEATURES *const sf = &cpi->sf;
......@@ -2912,14 +2915,14 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cpi->zbin_mode_boost_enabled = 0;
// Current default encoder behavior for the altref sign bias.
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = cpi->source_alt_ref_active;
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active;
// Check to see if a key frame is signaled.
// For two pass with auto key frame enabled cm->frame_type may already be
// set, but not for one pass.
if ((cm->current_video_frame == 0) ||
(cm->frame_flags & FRAMEFLAGS_KEY) ||
(cpi->oxcf.auto_key && (cpi->frames_since_key %
(cpi->oxcf.auto_key && (cpi->rc.frames_since_key %
cpi->key_frame_frequency == 0))) {
// Set frame type to key frame for the force key frame, if we exceed the
// maximum distance in an automatic keyframe selection or for the first
......@@ -2962,7 +2965,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
}
// The alternate reference frame cannot be active for a key frame.
cpi->source_alt_ref_active = 0;
cpi->rc.source_alt_ref_active = 0;
cm->error_resilient_mode = (cpi->oxcf.error_resilient_mode != 0);
cm->frame_parallel_decoding_mode =
......@@ -3029,8 +3032,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
// Decide q and q bounds
q = vp9_rc_pick_q_and_adjust_q_bounds(cpi,
&bottom_index,
&top_index,
&top_index_prop);
&top_index);
if (!frame_is_intra_only(cm)) {
cm->mcomp_filter_type = DEFAULT_INTERP_FILTER;
......@@ -3050,7 +3052,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
// Special case code to reduce pulsing when key frames are forced at a
// fixed interval. Note the reconstruction error if it is the frame before
// the force key frame
if (cpi->next_key_frame_forced && (cpi->twopass.frames_to_key == 0)) {
if (cpi->rc.next_key_frame_forced && (cpi->rc.frames_to_key == 0)) {
cpi->ambient_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm));
}
......@@ -3122,7 +3124,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
* needed in motion search besides loopfilter */
cm->last_frame_type = cm->frame_type;
vp9_rc_postencode_update(cpi, *size, top_index_prop);
vp9_rc_postencode_update(cpi, *size);
#if 0
output_frame_level_debug_stats(cpi);
......@@ -3187,6 +3189,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
// As this frame is a key frame the next defaults to an inter frame.
cm->frame_type = INTER_FRAME;
vp9_clear_system_state();
cpi->rc.frames_since_key = 0;
} else {