ref: 6ec984e4407728927661a3320970904c031ead05
parent: 509b27e4a0a2fe692dee04f644b01c894d36528d
parent: c929797b683bb12dbbd4440d83c4e6befa15259d
author: Jingning Han <[email protected]>
date: Wed Sep 5 23:45:13 EDT 2018
Merge "Recursive rate allocation for multi-layer ARF coding"
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2704,24 +2704,38 @@
if (cpi->multi_layer_arf) {
int idx;
- int total_delta = 0;
- int gap_bits;
- target_frame_size = normal_frame_bits;
- target_frame_size =
- clamp(target_frame_size, 0, VPXMIN(max_bits, (int)total_group_bits));
+ int arf_depth_bits[10] = { 0 };
+ int arf_depth_counts[10] = { 0 };
+ int total_arfs = 1; // Account for the base layer ARF.
+ int arf_boost_factor = 0;
+ int arf_group_bits;
- gap_bits = VPXMAX(0, gf_arf_bits - target_frame_size);
-
for (idx = frame_index; idx < gop_frames; ++idx) {
- int layer_arf_delta;
- if (gf_group->update_type[idx] == ARF_UPDATE) {
- layer_arf_delta = gap_bits >> (gf_group->layer_depth[idx] + 2);
- total_delta += layer_arf_delta;
- }
+ if (gf_group->update_type[idx] == ARF_UPDATE)
+ ++arf_depth_counts[gf_group->layer_depth[idx]];
}
- total_group_bits -= total_delta;
+ for (idx = 2; idx < 10; ++idx) {
+ int depth_boost_factor =
+ VPXMAX(MIN_ARF_GF_BOOST, rc->gfu_boost >> (idx + 1));
+ if (arf_depth_counts[idx] == 0) break;
+
+ arf_boost_factor = depth_boost_factor * arf_depth_counts[idx];
+
+ arf_group_bits =
+ calculate_boost_bits(rc->baseline_gf_interval - total_arfs,
+ arf_boost_factor, total_group_bits);
+
+ arf_depth_bits[idx] = (arf_group_bits + (arf_depth_counts[idx] >> 1)) /
+ arf_depth_counts[idx];
+
+ total_group_bits -= arf_group_bits;
+ total_arfs += arf_depth_counts[idx];
+ }
+
+ // offset the base layer arf
+ normal_frames -= (total_arfs - 1);
if (normal_frames > 1)
normal_frame_bits = (int)(total_group_bits / normal_frames);
else
@@ -2733,11 +2747,10 @@
// The first layer ARF has its bit allocation assigned.
for (idx = frame_index; idx < gop_frames; ++idx) {
- int layer_arf_delta;
switch (gf_group->update_type[idx]) {
case ARF_UPDATE:
- layer_arf_delta = gap_bits >> (gf_group->layer_depth[idx] + 1);
- gf_group->bit_allocation[idx] = target_frame_size + layer_arf_delta;
+ gf_group->bit_allocation[idx] =
+ arf_depth_bits[gf_group->layer_depth[idx]];
break;
case USE_BUF_FRAME: gf_group->bit_allocation[idx] = 0; break;
default: gf_group->bit_allocation[idx] = target_frame_size; break;
@@ -2744,9 +2757,6 @@
}
}
gf_group->bit_allocation[idx] = 0;
-
- // Adjust the first layer ARF rate allocation.
- gf_group->bit_allocation[1] = gf_arf_bits;
for (idx = 0; idx < gop_frames; ++idx)
if (gf_group->update_type[idx] == LF_UPDATE) break;