]> granicus.if.org Git - libvpx/commitdiff
Assign target bits for multi-layer ARF system
authorJingning Han <jingning@google.com>
Mon, 27 Aug 2018 23:17:29 +0000 (16:17 -0700)
committerJingning Han <jingning@google.com>
Tue, 4 Sep 2018 14:28:33 +0000 (07:28 -0700)
Keep the ARF and P frame rate allocation distribution. All the
intermediate ARFs are treated same as regular P frames.

Change-Id: I7807b8e6a8f19b6e1b09b9b7d119b3c88ef90b67

vp9/encoder/vp9_firstpass.c

index 38e1d37cc4b2d4a060467ea35399c3d9353340fe..2c36e06ee9f3e4e9c298fa52e43fa337a174382d 100644 (file)
@@ -2369,7 +2369,7 @@ static void find_arf_order(GF_GROUP *gf_group, int *layer_depth,
   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 @@ static void define_gf_group_structure(VP9_COMP *cpi) {
 
     (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 @@ static void define_gf_group_structure(VP9_COMP *cpi) {
 
   // 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 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
   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;
 
@@ -2702,6 +2704,27 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
   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);
     tot_norm_frame_score = calculate_group_score(cpi, av_score, normal_frames);