av1/encoder/ratectrl.c
// Adjust active_worst_quality level based on buffer level.
Adjust active_worst_quality level based on buffer level.
Adjust active_worst_quality level based on buffer level .
static int calc_active_worst_quality_one_pass_cbr(const AV1_COMP *cpi) {
  const AV1_COMMON *const cm = &cpi->common;
  const RATE_CONTROL *rc = &cpi->rc;
  int64_t critical_level = rc->optimal_buffer_level >> 3;
  int64_t buff_lvl_step = 0;
  int adjustment = 0;
  int active_worst_quality;
  int ambient_qp;
  if (cm->current_frame.frame_type == KEY_FRAME) return rc->worst_quality;
  ambient_qp = (cm->current_frame.frame_number < 5)
                   ? AOMMIN(rc->avg_frame_qindex[INTER_FRAME],
                            rc->avg_frame_qindex[KEY_FRAME])
                   : rc->avg_frame_qindex[INTER_FRAME];
  active_worst_quality = AOMMIN(rc->worst_quality, ambient_qp * 5 / 4);
  if (rc->buffer_level > rc->optimal_buffer_level) {
    int max_adjustment_down = active_worst_quality / 3;
    if (max_adjustment_down) {
      buff_lvl_step = ((rc->maximum_buffer_size - rc->optimal_buffer_level) /
                       max_adjustment_down);
      if (buff_lvl_step)
        adjustment = (int)((rc->buffer_level - rc->optimal_buffer_level) /
                           buff_lvl_step);
      active_worst_quality -= adjustment;
    }
  } else if (rc->buffer_level > critical_level) {
    if (critical_level) {
      buff_lvl_step = (rc->optimal_buffer_level - critical_level);
      if (buff_lvl_step) {
        adjustment = (int)((rc->worst_quality - ambient_qp) *
                           (rc->optimal_buffer_level - rc->buffer_level) /
                           buff_lvl_step);
      }
      active_worst_quality = ambient_qp + adjustment;
    }
  } else {
    active_worst_quality = rc->worst_quality;
  }
  return active_worst_quality;
}
static int calc_active_worst_quality_one_pass_cbr ( const AV1_COMP * cpi ) { const AV1_COMMON * const cm = & cpi -> common ; const RATE_CONTROL * rc = & cpi -> rc ; int64_t critical_level = rc -> optimal_buffer_level >> 3 ; int64_t buff_lvl_step = 0 ; int adjustment = 0 ; int active_worst_quality ; int ambient_qp ; if ( cm -> current_frame . frame_type == KEY_FRAME ) return rc -> worst_quality ; ambient_qp = ( cm -> current_frame . frame_number < 5 ) ? AOMMIN ( rc -> avg_frame_qindex [ INTER_FRAME ] , rc -> avg_frame_qindex [ KEY_FRAME ] ) : rc -> avg_frame_qindex [ INTER_FRAME ] ; active_worst_quality = AOMMIN ( rc -> worst_quality , ambient_qp * 5 / 4 ) ; if ( rc -> buffer_level > rc -> optimal_buffer_level ) { int max_adjustment_down = active_worst_quality / 3 ; if ( max_adjustment_down ) { buff_lvl_step = ( ( rc -> maximum_buffer_size - rc -> optimal_buffer_level ) / max_adjustment_down ) ; if ( buff_lvl_step ) adjustment = ( int ) ( ( rc -> buffer_level - rc -> optimal_buffer_level ) / buff_lvl_step ) ; active_worst_quality -= adjustment ; } } else if ( rc -> buffer_level > critical_level ) { if ( critical_level ) { buff_lvl_step = ( rc -> optimal_buffer_level - critical_level ) ; if ( buff_lvl_step ) { adjustment = ( int ) ( ( rc -> worst_quality - ambient_qp ) * ( rc -> optimal_buffer_level - rc -> buffer_level ) / buff_lvl_step ) ; } active_worst_quality = ambient_qp + adjustment ; } } else { active_worst_quality = rc -> worst_quality ; } return active_worst_quality ; }
Adjust active_worst_quality level based on buffer level.
Adjust active_worst_quality level based on buffer level .
// Adjust active_worst_quality: If buffer is above the optimal/target level, // bring active_worst_quality down depending on fullness of buffer. // If buffer is below the optimal level, let the active_worst_quality go from // ambient Q (at buffer = optimal level) to worst_quality level // (at buffer = critical level). // Buffer level below which we push active_worst to worst_quality. // For ambient_qp we use minimum of avg_frame_qindex[KEY_FRAME/INTER_FRAME] // for the first few frames following key frame. These are both initialized // to worst_quality and updated with (3/4, 1/4) average in postencode_update. // So for first few frames following key, the qp of that key frame is weighted // into the active_worst_quality setting. // Adjust down. // Maximum limit for down adjustment, ~30%. // Adjust up from ambient Q. // Set to worst_quality if buffer is below critical level.