shithub: libvpx

Download patch

ref: 793ae588538f20bff0993574381e73ebce677d1b
parent: d24a72ef737a91aee6cff56625e789fc283d6f15
author: angiebird <angiebird@google.com>
date: Mon Oct 21 14:04:49 EDT 2019

Pass first_pass_info/show_idx to test_candidate_kf

Change-Id: I5c18de464be9981236f95c62391258c4963e469b

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2945,9 +2945,14 @@
 #define V_LOW_INTRA 0.5
 
 static int test_candidate_kf(TWO_PASS *twopass,
-                             const FIRSTPASS_STATS *last_frame,
-                             const FIRSTPASS_STATS *this_frame,
-                             const FIRSTPASS_STATS *next_frame) {
+                             const FIRST_PASS_INFO *first_pass_info,
+                             int show_idx) {
+  const FIRSTPASS_STATS *last_frame =
+      fps_get_frame_stats(first_pass_info, show_idx - 1);
+  const FIRSTPASS_STATS *this_frame =
+      fps_get_frame_stats(first_pass_info, show_idx);
+  const FIRSTPASS_STATS *next_frame =
+      fps_get_frame_stats(first_pass_info, show_idx + 1);
   int is_viable_kf = 0;
   double pcnt_intra = 1.0 - this_frame->pcnt_inter;
 
@@ -3106,9 +3111,6 @@
     int i = 0;
     while (twopass->stats_in < twopass->stats_in_end &&
            rc->frames_to_key < cpi->oxcf.key_freq) {
-      // Load the next frame's stats.
-      const FIRSTPASS_STATS *last_frame =
-          fps_get_frame_stats(first_pass_info, kf_show_idx + i);
       FIRSTPASS_STATS this_frame;
       input_stats(twopass, &this_frame);
 
@@ -3117,8 +3119,7 @@
         double loop_decay_rate;
 
         // Check for a scene cut.
-        if (test_candidate_kf(twopass, last_frame, &this_frame,
-                              twopass->stats_in))
+        if (test_candidate_kf(twopass, first_pass_info, kf_show_idx + i + 1))
           break;
 
         // How fast is the prediction quality decaying?
--- a/vp9/encoder/vp9_firstpass.h
+++ b/vp9/encoder/vp9_firstpass.h
@@ -164,7 +164,7 @@
 
 static INLINE const FIRSTPASS_STATS *fps_get_frame_stats(
     const FIRST_PASS_INFO *first_pass_info, int show_idx) {
-  if (show_idx >= first_pass_info->num_frames) {
+  if (show_idx < 0 || show_idx >= first_pass_info->num_frames) {
     return NULL;
   }
   return &first_pass_info->stats[show_idx];