av1/encoder/ratectrl.c
// Similar to find_qindex_by_rate() function in ratectrl.c, but returns the q
// index with rate just above or below the desired rate, depending on which of
// the two rates is closer to the desired rate.
// Also, respects the selected aq_mode when computing the rate.
Similar to find_qindex_by_rate() function in ratectrl.c, but returns the q
index with rate just above or below the desired rate, depending on which of
the two rates is closer to the desired rate.
Also, respects the selected aq_mode when computing the rate.
Similar to find_qindex_by_rate () function in ratectrl . c but returns the q index with rate just above or below the desired rate depending on which of the two rates is closer to the desired rate . Also respects the selected aq_mode when computing the rate .
static int find_closest_qindex_by_rate(int desired_bits_per_mb,
                                       const AV1_COMP *cpi,
                                       double correction_factor,
                                       int best_qindex, int worst_qindex) {
  const int use_cyclic_refresh = cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
                                 cpi->cyclic_refresh->apply_cyclic_refresh;
  assert(best_qindex <= worst_qindex);
  int low = best_qindex;
  int high = worst_qindex;
  while (low < high) {
    const int mid = (low + high) >> 1;
    const int mid_bits_per_mb =
        get_bits_per_mb(cpi, use_cyclic_refresh, correction_factor, mid);
    if (mid_bits_per_mb > desired_bits_per_mb) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  assert(low == high);
  const int curr_q = low;
  const int curr_bits_per_mb =
      get_bits_per_mb(cpi, use_cyclic_refresh, correction_factor, curr_q);
  const int curr_bit_diff = (curr_bits_per_mb <= desired_bits_per_mb)
                                ? desired_bits_per_mb - curr_bits_per_mb
                                : INT_MAX;
  assert((curr_bit_diff != INT_MAX && curr_bit_diff >= 0) ||
         curr_q == worst_qindex);
  const int prev_q = curr_q - 1;
  int prev_bit_diff;
  if (curr_bit_diff == INT_MAX || curr_q == best_qindex) {
    prev_bit_diff = INT_MAX;
  } else {
    const int prev_bits_per_mb =
        get_bits_per_mb(cpi, use_cyclic_refresh, correction_factor, prev_q);
    assert(prev_bits_per_mb > desired_bits_per_mb);
    prev_bit_diff = prev_bits_per_mb - desired_bits_per_mb;
  }
  return (curr_bit_diff <= prev_bit_diff) ? curr_q : prev_q;
}
static int find_closest_qindex_by_rate ( int desired_bits_per_mb , const AV1_COMP * cpi , double correction_factor , int best_qindex , int worst_qindex ) { const int use_cyclic_refresh = cpi -> oxcf . aq_mode == CYCLIC_REFRESH_AQ && cpi -> cyclic_refresh -> apply_cyclic_refresh ; assert ( best_qindex <= worst_qindex ) ; int low = best_qindex ; int high = worst_qindex ; while ( low < high ) { const int mid = ( low + high ) >> 1 ; const int mid_bits_per_mb = get_bits_per_mb ( cpi , use_cyclic_refresh , correction_factor , mid ) ; if ( mid_bits_per_mb > desired_bits_per_mb ) { low = mid + 1 ; } else { high = mid ; } } assert ( low == high ) ; const int curr_q = low ; const int curr_bits_per_mb = get_bits_per_mb ( cpi , use_cyclic_refresh , correction_factor , curr_q ) ; const int curr_bit_diff = ( curr_bits_per_mb <= desired_bits_per_mb ) ? desired_bits_per_mb - curr_bits_per_mb : INT_MAX ; assert ( ( curr_bit_diff != INT_MAX && curr_bit_diff >= 0 ) || curr_q == worst_qindex ) ; const int prev_q = curr_q - 1 ; int prev_bit_diff ; if ( curr_bit_diff == INT_MAX || curr_q == best_qindex ) { prev_bit_diff = INT_MAX ; } else { const int prev_bits_per_mb = get_bits_per_mb ( cpi , use_cyclic_refresh , correction_factor , prev_q ) ; assert ( prev_bits_per_mb > desired_bits_per_mb ) ; prev_bit_diff = prev_bits_per_mb - desired_bits_per_mb ; } return ( curr_bit_diff <= prev_bit_diff ) ? curr_q : prev_q ; }
Similar to find_qindex_by_rate() function in ratectrl.c, but returns the q
index with rate just above or below the desired rate, depending on which of
the two rates is closer to the desired rate.
Similar to find_qindex_by_rate () function in ratectrl . c but returns the q index with rate just above or below the desired rate depending on which of the two rates is closer to the desired rate .
// Find 'qindex' based on 'desired_bits_per_mb'. // Calculate rate difference of this q index from the desired rate. // Calculate rate difference for previous q index too. // Pick one of the two q indices, depending on which one has rate closer to // the desired rate.