shithub: libvpx

Download patch

ref: 9987c484550764f434bd0d3553cea32b0b95b921
parent: 57038c687d6074f2de80620640410ad539c1638c
parent: ae7d53202e70b943c3a2abe928bfe8233a6c355a
author: Jingning Han <[email protected]>
date: Tue Sep 4 14:29:25 EDT 2018

Merge "Assign target bits for multi-layer ARF system"

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2369,7 +2369,7 @@
   find_arf_order(gf_group, layer_depth, index_counter, depth + 1, mid + 1, end);
 }
 
-static void define_gf_group_structure(VP9_COMP *cpi) {
+static int define_gf_group_structure(VP9_COMP *cpi) {
   RATE_CONTROL *const rc = &cpi->rc;
   TWO_PASS *const twopass = &cpi->twopass;
   GF_GROUP *const gf_group = &twopass->gf_group;
@@ -2444,7 +2444,7 @@
 
     (void)layer_depth;
 
-    return;
+    return frame_index;
   }
 
   // Note index of the first normal inter frame int eh group (not gf kf arf)
@@ -2494,6 +2494,8 @@
 
   // Note whether multi-arf was enabled this group for next time.
   cpi->multi_arf_last_grp_enabled = cpi->multi_arf_enabled;
+
+  return frame_index;
 }
 
 static void allocate_gf_multi_arf_bits(VP9_COMP *cpi, int64_t gf_group_bits,
@@ -2664,7 +2666,7 @@
   double this_frame_score = 1.0;
 
   // Define the GF structure and specify
-  define_gf_group_structure(cpi);
+  int gop_frames = define_gf_group_structure(cpi);
 
   key_frame = cpi->common.frame_type == KEY_FRAME;
 
@@ -2701,6 +2703,27 @@
     normal_frame_bits = (int)(total_group_bits / normal_frames);
   else
     normal_frame_bits = (int)total_group_bits;
+
+  if (cpi->multi_layer_arf) {
+    int idx;
+    target_frame_size = normal_frame_bits;
+    target_frame_size =
+        clamp(target_frame_size, 0, VPXMIN(max_bits, (int)total_group_bits));
+
+    for (idx = frame_index; idx < gop_frames; ++idx) {
+      if (gf_group->update_type[idx] == USE_BUF_FRAME)
+        gf_group->bit_allocation[idx] = 0;
+      else
+        gf_group->bit_allocation[idx] = target_frame_size;
+    }
+    gf_group->bit_allocation[idx] = 0;
+
+    for (idx = 0; idx < gop_frames; ++idx)
+      if (gf_group->update_type[idx] == LF_UPDATE) break;
+    gf_group->first_inter_index = idx;
+
+    return;
+  }
 
   if (oxcf->vbr_corpus_complexity) {
     av_score = get_distribution_av_err(cpi, twopass);