summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_firstpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/encoder/vp9_firstpass.c')
-rw-r--r--vp9/encoder/vp9_firstpass.c98
1 files changed, 45 insertions, 53 deletions
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index 38e98cd1e..58c3a435d 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2085,18 +2085,6 @@ static int calculate_boost_bits(int frame_count, int boost,
0);
}
-// Current limit on maximum number of active arfs in a GF/ARF group.
-#define MAX_ACTIVE_ARFS 2
-#define ARF_SLOT1 2
-#define ARF_SLOT2 3
-// This function indirects the choice of buffers for arfs.
-// At the moment the values are fixed but this may change as part of
-// the integration process with other codec features that swap buffers around.
-static void get_arf_buffer_indices(unsigned char *arf_buffer_indices) {
- arf_buffer_indices[0] = ARF_SLOT1;
- arf_buffer_indices[1] = ARF_SLOT2;
-}
-
// Used in corpus vbr: Calculates the total normalized group complexity score
// for a given number of frames starting at the current position in the stats
// file.
@@ -2172,6 +2160,20 @@ static void find_arf_order(VP9_COMP *cpi, GF_GROUP *gf_group,
find_arf_order(cpi, gf_group, index_counter, depth + 1, mid + 1, end);
}
+static INLINE void set_gf_overlay_frame_type(GF_GROUP *gf_group,
+ int frame_index,
+ int source_alt_ref_active) {
+ if (source_alt_ref_active) {
+ gf_group->update_type[frame_index] = OVERLAY_UPDATE;
+ gf_group->rf_level[frame_index] = INTER_NORMAL;
+ gf_group->layer_depth[frame_index] = MAX_ARF_LAYERS - 1;
+ } else {
+ gf_group->update_type[frame_index] = GF_UPDATE;
+ gf_group->rf_level[frame_index] = GF_ARF_STD;
+ gf_group->layer_depth[frame_index] = 0;
+ }
+}
+
static int define_gf_group_structure(VP9_COMP *cpi) {
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
@@ -2179,7 +2181,6 @@ static int define_gf_group_structure(VP9_COMP *cpi) {
int i;
int frame_index = 0;
int key_frame;
- unsigned char arf_buffer_indices[MAX_ACTIVE_ARFS];
int normal_frames;
key_frame = cpi->common.frame_type == KEY_FRAME;
@@ -2187,24 +2188,11 @@ static int define_gf_group_structure(VP9_COMP *cpi) {
gf_group->frame_start = cpi->common.current_video_frame;
gf_group->frame_end = gf_group->frame_start + rc->baseline_gf_interval - 1;
- get_arf_buffer_indices(arf_buffer_indices);
-
// For key frames the frame target rate is already set and it
// is also the golden frame.
// === [frame_index == 0] ===
- if (!key_frame) {
- if (rc->source_alt_ref_active) {
- gf_group->update_type[frame_index] = OVERLAY_UPDATE;
- gf_group->rf_level[frame_index] = INTER_NORMAL;
- gf_group->layer_depth[frame_index] = MAX_ARF_LAYERS - 1;
- } else {
- gf_group->update_type[frame_index] = GF_UPDATE;
- gf_group->rf_level[frame_index] = GF_ARF_STD;
- gf_group->layer_depth[frame_index] = 0;
- }
- gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0];
- gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
- }
+ if (!key_frame)
+ set_gf_overlay_frame_type(gf_group, frame_index, rc->source_alt_ref_active);
++frame_index;
@@ -2213,12 +2201,8 @@ static int define_gf_group_structure(VP9_COMP *cpi) {
gf_group->update_type[frame_index] = ARF_UPDATE;
gf_group->rf_level[frame_index] = GF_ARF_STD;
gf_group->layer_depth[frame_index] = 1;
-
gf_group->arf_src_offset[frame_index] =
(unsigned char)(rc->baseline_gf_interval - 1);
-
- gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0];
- gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
++frame_index;
}
@@ -2226,13 +2210,9 @@ static int define_gf_group_structure(VP9_COMP *cpi) {
find_arf_order(cpi, gf_group, &frame_index, 2, 0,
rc->baseline_gf_interval - 1);
- if (rc->source_alt_ref_pending) {
- gf_group->update_type[frame_index] = OVERLAY_UPDATE;
- gf_group->rf_level[frame_index] = INTER_NORMAL;
- } else {
- gf_group->update_type[frame_index] = GF_UPDATE;
- gf_group->rf_level[frame_index] = GF_ARF_STD;
- }
+ set_gf_overlay_frame_type(gf_group, frame_index,
+ rc->source_alt_ref_pending);
+
gf_group->arf_src_offset[frame_index] = 0;
return frame_index;
@@ -2242,12 +2222,8 @@ static int define_gf_group_structure(VP9_COMP *cpi) {
rc->baseline_gf_interval - (key_frame || rc->source_alt_ref_pending);
for (i = 0; i < normal_frames; ++i) {
- int arf_idx = 0;
if (twopass->stats_in >= twopass->stats_in_end) break;
- gf_group->arf_update_idx[frame_index] = arf_buffer_indices[arf_idx];
- gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx];
-
gf_group->update_type[frame_index] = LF_UPDATE;
gf_group->rf_level[frame_index] = INTER_NORMAL;
gf_group->arf_src_offset[frame_index] = 0;
@@ -2260,8 +2236,8 @@ static int define_gf_group_structure(VP9_COMP *cpi) {
// We need to configure the frame at the end of the sequence + 1 that will be
// the start frame for the next group. Otherwise prior to the call to
// vp9_rc_get_second_pass_params() the data will be undefined.
- gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0];
- gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
+
+ set_gf_overlay_frame_type(gf_group, frame_index, rc->source_alt_ref_pending);
if (rc->source_alt_ref_pending) {
gf_group->update_type[frame_index] = OVERLAY_UPDATE;
@@ -2383,9 +2359,6 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
}
gf_group->bit_allocation[idx] = 0;
- for (idx = 0; idx < gop_frames; ++idx)
- if (gf_group->update_type[idx] == LF_UPDATE) break;
-
return;
}
@@ -2485,6 +2458,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
const int is_key_frame = frame_is_intra_only(cm);
const int arf_active_or_kf = is_key_frame || rc->source_alt_ref_active;
+ double gop_intra_factor = 1.0;
+
// Reset the GF group data structures unless this is a key
// frame in which case it will already have been done.
if (is_key_frame == 0) {
@@ -2524,8 +2499,11 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
{
int int_max_q = (int)(vp9_convert_qindex_to_q(twopass->active_worst_quality,
cpi->common.bit_depth));
- int int_lbq = (int)(vp9_convert_qindex_to_q(rc->last_boosted_qindex,
- cpi->common.bit_depth));
+ int q_term = (cm->current_video_frame == 0)
+ ? int_max_q / 32
+ : (int)(vp9_convert_qindex_to_q(rc->last_boosted_qindex,
+ cpi->common.bit_depth) /
+ 6);
active_min_gf_interval =
rc->min_gf_interval + arf_active_or_kf + VPXMIN(2, int_max_q / 200);
active_min_gf_interval =
@@ -2535,7 +2513,10 @@ 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 + arf_active_or_kf + VPXMIN(4, (int_lbq / 6));
+ active_max_gf_interval = 11 + arf_active_or_kf + VPXMIN(5, q_term);
+
+ // Force max GF interval to be odd.
+ active_max_gf_interval = active_max_gf_interval | 0x01;
// We have: active_min_gf_interval <=
// rc->max_gf_interval + arf_active_or_kf.
@@ -2552,6 +2533,17 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
active_max_gf_interval = rc->frames_to_key / 2;
}
+ if (cpi->multi_layer_arf) {
+ int layers = 0;
+ int max_layers = VPXMIN(MAX_ARF_LAYERS, cpi->oxcf.enable_auto_arf);
+
+ // Adapt the intra_error factor to active_max_gf_interval limit.
+ for (i = active_max_gf_interval; i > 0; i >>= 1) ++layers;
+
+ layers = VPXMIN(max_layers, layers);
+ gop_intra_factor += (layers * 0.25);
+ }
+
i = 0;
while (i < rc->static_scene_max_gf_interval && i < rc->frames_to_key) {
++i;
@@ -2624,11 +2616,11 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Don't break out with a very short interval.
(i >= active_min_gf_interval) &&
// If possible dont break very close to a kf
- ((rc->frames_to_key - i) >= rc->min_gf_interval) &&
+ ((rc->frames_to_key - i) >= rc->min_gf_interval) && (i & 0x01) &&
(!flash_detected) &&
((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
(abs_mv_in_out_accumulator > abs_mv_in_out_thresh) ||
- (sr_accumulator > next_frame.intra_error)))) {
+ (sr_accumulator > gop_intra_factor * next_frame.intra_error)))) {
break;
}