Merge "rc: turn off gf constrain for external RC" into main
authorJerome Jiang <jianj@google.com>
Tue, 22 Jun 2021 22:13:38 +0000 (22:13 +0000)
committerGerrit Code Review <noreply-gerritcodereview@google.com>
Tue, 22 Jun 2021 22:13:38 +0000 (22:13 +0000)
1  2 
vp9/encoder/vp9_ratectrl.c

@@@ -407,6 -407,7 +407,7 @@@ void vp9_rc_init(const VP9EncoderConfi
    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;
@@@ -1717,12 -1718,10 +1718,12 @@@ void vp9_rc_set_frame_target(VP9_COMP *
    }
  
  #if CONFIG_RATE_CTRL
 -  if (cpi->encode_command.use_external_target_frame_bits) {
 -    rc->this_frame_target = cpi->encode_command.target_frame_bits;
 +  if (cpi->oxcf.use_simple_encode_api) {
 +    if (cpi->encode_command.use_external_target_frame_bits) {
 +      rc->this_frame_target = cpi->encode_command.target_frame_bits;
 +    }
    }
 -#endif
 +#endif  // CONFIG_RATE_CTRL
  
    // Target rate per SB64 (including partial SB64s.
    rc->sb64_target_rate = (int)(((int64_t)rc->this_frame_target * 64 * 64) /
@@@ -2008,7 -2007,7 +2009,7 @@@ void vp9_rc_postencode_update_drop_fram
    }
  }
  
 -int vp9_calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
 +int vp9_calc_pframe_target_size_one_pass_vbr(const VP9_COMP *cpi) {
    const RATE_CONTROL *const rc = &cpi->rc;
    const int af_ratio = rc->af_ratio_onepass_vbr;
    int64_t target =
    return vp9_rc_clamp_pframe_target_size(cpi, (int)target);
  }
  
 -int vp9_calc_iframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
 +int vp9_calc_iframe_target_size_one_pass_vbr(const VP9_COMP *cpi) {
    static const int kf_ratio = 25;
    const RATE_CONTROL *rc = &cpi->rc;
    const int target = rc->avg_frame_bandwidth * kf_ratio;
@@@ -2085,7 -2084,8 +2086,8 @@@ void vp9_set_gf_update_one_pass_vbr(VP9
          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;
@@@ -2535,25 -2535,26 +2537,25 @@@ void vp9_rc_set_gf_interval_range(cons
      rc->min_gf_interval = FIXED_GF_INTERVAL;
      rc->static_scene_max_gf_interval = FIXED_GF_INTERVAL;
    } else {
 +    double framerate = cpi->framerate;
      // Set Maximum gf/arf interval
      rc->max_gf_interval = oxcf->max_gf_interval;
      rc->min_gf_interval = oxcf->min_gf_interval;
  #if CONFIG_RATE_CTRL
 +    if (oxcf->use_simple_encode_api) {
 +      // In this experiment, we avoid framerate being changed dynamically during
 +      // encoding.
 +      framerate = oxcf->init_framerate;
 +    }
 +#endif  // CONFIG_RATE_CTRL
      if (rc->min_gf_interval == 0) {
        rc->min_gf_interval = vp9_rc_get_default_min_gf_interval(
 -          oxcf->width, oxcf->height, oxcf->init_framerate);
 +          oxcf->width, oxcf->height, framerate);
      }
      if (rc->max_gf_interval == 0) {
 -      rc->max_gf_interval = vp9_rc_get_default_max_gf_interval(
 -          oxcf->init_framerate, rc->min_gf_interval);
 +      rc->max_gf_interval =
 +          vp9_rc_get_default_max_gf_interval(framerate, rc->min_gf_interval);
      }
 -#else
 -    if (rc->min_gf_interval == 0)
 -      rc->min_gf_interval = vp9_rc_get_default_min_gf_interval(
 -          oxcf->width, oxcf->height, cpi->framerate);
 -    if (rc->max_gf_interval == 0)
 -      rc->max_gf_interval = vp9_rc_get_default_max_gf_interval(
 -          cpi->framerate, rc->min_gf_interval);
 -#endif
  
      // Extended max interval for genuinely static scenes like slide shows.
      rc->static_scene_max_gf_interval = MAX_STATIC_GF_GROUP_LENGTH;