rc: turn off gf constrain for external RC
authorJerome Jiang <jianj@google.com>
Tue, 22 Jun 2021 00:22:51 +0000 (17:22 -0700)
committerJerome Jiang <jianj@google.com>
Tue, 22 Jun 2021 20:05:25 +0000 (13:05 -0700)
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

test/ratectrl_rtc_test.cc
vp9/encoder/vp9_ratectrl.c
vp9/encoder/vp9_ratectrl.h
vp9/ratectrl_rtc.cc
vp9/ratectrl_rtc.h

index e9a9f15..5e5a179 100644 (file)
@@ -61,6 +61,7 @@ struct FrameInfo {
 //  - 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 @@ class RcInterfaceTest : public ::testing::Test {
     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 @@ class RcInterfaceTest : public ::testing::Test {
   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() {
index dbbd458..26e1d53 100644 (file)
@@ -407,6 +407,7 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
   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 @@ void vp9_set_gf_update_one_pass_vbr(VP9_COMP *const cpi) {
         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;
index bdddd2d..83a12cd 100644 (file)
@@ -207,6 +207,10 @@ typedef struct {
   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;
index 8455ca9..2595a2b 100644 (file)
@@ -46,7 +46,6 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) {
   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 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) {
   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 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) {
         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_);
index a1f2767..c7c0505 100644 (file)
@@ -51,8 +51,6 @@ struct VP9RateControlRtcConfig {
   int ts_rate_decimator[VPX_TS_MAX_LAYERS];
   // vbr, cbr
   enum vpx_rc_mode rc_mode;
-  // key frame frequency
-  int key_freq;
 };
 
 struct VP9FrameParamsQpRTC {