shithub: libvpx

Download patch

ref: 38eb8e7752da9cc086f7843ecf830c37ba11157e
parent: 16f50c34b37402d691b8137cb57fd09972292945
author: Jingning Han <[email protected]>
date: Tue Nov 13 18:20:03 EST 2018

Fix GF-only frame type allocation

Rework the recursive ARF allocation to avoid missing one frame's
type assignment issue in GF only GOP structure. This fixes a rare
encoder failure issue in GF only setting.

Change-Id: I3e41fe36d3cb954de25ffc058a42b2b8be0fcd7a

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2112,14 +2112,14 @@
   TWO_PASS *twopass = &cpi->twopass;
   const FIRSTPASS_STATS *const start_pos = twopass->stats_in;
   FIRSTPASS_STATS fpf_frame;
-  const int mid = (start + end) >> 1;
-  const int min_frame_interval = 3;
+  const int mid = (start + end + 1) >> 1;
+  const int min_frame_interval = 2;
   int idx;
 
   // Process regular P frames
   if ((end - start < min_frame_interval) ||
       (depth > gf_group->allowed_max_layer_depth)) {
-    for (idx = start; idx < end; ++idx) {
+    for (idx = start; idx <= end; ++idx) {
       gf_group->update_type[*index_counter] = LF_UPDATE;
       gf_group->arf_src_offset[*index_counter] = 0;
       gf_group->frame_gop_index[*index_counter] = idx;
@@ -2151,7 +2151,7 @@
 
   ++(*index_counter);
 
-  find_arf_order(cpi, gf_group, index_counter, depth + 1, start, mid);
+  find_arf_order(cpi, gf_group, index_counter, depth + 1, start, mid - 1);
 
   gf_group->update_type[*index_counter] = USE_BUF_FRAME;
   gf_group->arf_src_offset[*index_counter] = 0;
@@ -2183,11 +2183,11 @@
   TWO_PASS *const twopass = &cpi->twopass;
   GF_GROUP *const gf_group = &twopass->gf_group;
   int frame_index = 0;
-  int key_frame;
+  int key_frame = cpi->common.frame_type == KEY_FRAME;
   int layer_depth = 1;
+  int gop_frames =
+      rc->baseline_gf_interval - (key_frame || rc->source_alt_ref_pending);
 
-  key_frame = cpi->common.frame_type == KEY_FRAME;
-
   gf_group->frame_start = cpi->common.current_video_frame;
   gf_group->frame_end = gf_group->frame_start + rc->baseline_gf_interval;
   gf_group->max_layer_depth = 0;
@@ -2215,8 +2215,7 @@
     gf_group->allowed_max_layer_depth = cpi->oxcf.enable_auto_arf;
   }
 
-  find_arf_order(cpi, gf_group, &frame_index, layer_depth, 1,
-                 rc->baseline_gf_interval);
+  find_arf_order(cpi, gf_group, &frame_index, layer_depth, 1, gop_frames);
 
   set_gf_overlay_frame_type(gf_group, frame_index, rc->source_alt_ref_pending);
   gf_group->arf_src_offset[frame_index] = 0;