shithub: libvpx

Download patch

ref: a00c56373ea7d12bf6b1ab8060ccdb4af03c1794
parent: 1f45e7b07ec839dae7a90455e00c3b2d553ea772
author: Jerome Jiang <jianj@google.com>
date: Mon Jun 21 13:22:51 EDT 2021

rc: turn off gf constrain for external RC

Added a new flag in rate control which turns off gf interval constrain
on key frame frequency for external RC.

It remains on for libvpx.

Change-Id: I18bb0d8247a421193f023619f906d0362b873b31

--- a/test/ratectrl_rtc_test.cc
+++ b/test/ratectrl_rtc_test.cc
@@ -61,6 +61,7 @@
 //  - Set rc_end_usage to VPX_VBR
 //  - AQ Mode 0
 //  - Disable vp9_compute_frame_low_motion in vp9_encoder.c
+//  - Set rc->constrain_gf_key_freq_onepass_vbr = 0 in vp9_rc_init
 // examples/vpx_temporal_svc_encoder gipsrec_motion1.1280_720.yuv out vp9
 //    1280 720 1 30 7 0 0 1 0 1000
 //
@@ -192,8 +193,7 @@
     for (size_t i = 0; i < kNumFrame; i++) {
       one_layer_file >> frame_info;
       if (frame_info.frame_id > 0) frame_params.frame_type = INTER_FRAME;
-      if (frame_info.frame_id % rc_cfg_.key_freq == 0)
-        frame_params.frame_type = KEY_FRAME;
+      if (frame_info.frame_id % 300 == 0) frame_params.frame_type = KEY_FRAME;
       ASSERT_EQ(frame_info.spatial_id, 0);
       ASSERT_EQ(frame_info.temporal_id, 0);
       rc_api_->ComputeQP(frame_params);
@@ -229,19 +229,16 @@
   void SetConfigOneLayerCBR() {
     SetConfig();
     rc_cfg_.rc_mode = VPX_CBR;
-    rc_cfg_.key_freq = 3000;
   }
 
   void SetConfigOneLayerVBR() {
     SetConfig();
     rc_cfg_.rc_mode = VPX_VBR;
-    rc_cfg_.key_freq = 3000;
   }
 
   void SetConfigOneLayerVBRPeriodicKey() {
     SetConfig();
     rc_cfg_.rc_mode = VPX_VBR;
-    rc_cfg_.key_freq = 300;
   }
 
   void SetConfigSVC() {
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -407,6 +407,7 @@
   rc->source_alt_ref_active = 0;
 
   rc->frames_till_gf_update_due = 0;
+  rc->constrain_gf_key_freq_onepass_vbr = 1;
   rc->ni_av_qi = oxcf->worst_allowed_q;
   rc->ni_tot_qi = 0;
   rc->ni_frames = 0;
@@ -2083,7 +2084,8 @@
         rc->gfu_boost = DEFAULT_GF_BOOST >> 1;
       rc->af_ratio_onepass_vbr = VPXMIN(15, VPXMAX(5, 3 * rc->gfu_boost / 400));
     }
-    adjust_gfint_frame_constraint(cpi, rc->frames_to_key);
+    if (rc->constrain_gf_key_freq_onepass_vbr)
+      adjust_gfint_frame_constraint(cpi, rc->frames_to_key);
     rc->frames_till_gf_update_due = rc->baseline_gf_interval;
     cpi->refresh_golden_frame = 1;
     rc->source_alt_ref_pending = 0;
--- a/vp9/encoder/vp9_ratectrl.h
+++ b/vp9/encoder/vp9_ratectrl.h
@@ -207,6 +207,10 @@
   int preserve_arf_as_gld;
   int preserve_next_arf_as_gld;
   int show_arf_as_gld;
+
+  // Flag to constrain golden frame interval on key frame frequency for 1 pass
+  // VBR.
+  int constrain_gf_key_freq_onepass_vbr;
 } RATE_CONTROL;
 
 struct VP9_COMP;
--- a/vp9/ratectrl_rtc.cc
+++ b/vp9/ratectrl_rtc.cc
@@ -46,7 +46,6 @@
   oxcf->content = VP9E_CONTENT_DEFAULT;
   oxcf->drop_frames_water_mark = 0;
   cm->current_video_frame = 0;
-  oxcf->key_freq = rc_cfg.key_freq;
   rc->kf_boost = DEFAULT_KF_BOOST;
 
   UpdateRateControl(rc_cfg);
@@ -60,7 +59,7 @@
   rc->rc_2_frame = 0;
   vp9_rc_init_minq_luts();
   vp9_rc_init(oxcf, 0, rc);
-  rc->frames_to_key = oxcf->key_freq;
+  rc->constrain_gf_key_freq_onepass_vbr = 0;
   cpi_->sf.use_nonrd_pick_mode = 1;
 }
 
@@ -152,8 +151,7 @@
         target = vp9_calc_pframe_target_size_one_pass_cbr(cpi_);
     } else if (cpi_->oxcf.rc_mode == VPX_VBR) {
       if (cm->frame_type == KEY_FRAME) {
-        cpi_->rc.this_key_frame_forced =
-            cm->current_video_frame != 0 && cpi_->rc.frames_to_key == 0;
+        cpi_->rc.this_key_frame_forced = cm->current_video_frame != 0;
         cpi_->rc.frames_to_key = cpi_->oxcf.key_freq;
       }
       vp9_set_gf_update_one_pass_vbr(cpi_);
--- a/vp9/ratectrl_rtc.h
+++ b/vp9/ratectrl_rtc.h
@@ -51,8 +51,6 @@
   int ts_rate_decimator[VPX_TS_MAX_LAYERS];
   // vbr, cbr
   enum vpx_rc_mode rc_mode;
-  // key frame frequency
-  int key_freq;
 };
 
 struct VP9FrameParamsQpRTC {