// Prior to encoding the frame, estimate the bits per mb, for a given q = i and // a corresponding delta-q (for segment 1). This function is called in the // rc_regulate_q() to set the base qp index. // Note: the segment map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or // to 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock, prior to encoding. int vp9_cyclic_refresh_rc_bits_per_mb(const VP9_COMP *cpi, int i, double correction_factor) { const VP9_COMMON *const cm = &cpi->common; CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; int bits_per_mb; int num8x8bl = cm->MBs << 2; // Weight for segment prior to encoding: take the average of the target // number for the frame to be encoded and the actual from the previous frame. int target_refresh = cr->percent_refresh * cm->mi_rows * cm->mi_cols / 100; double weight_segment = (double)((target_refresh + cr->actual_num_seg1_blocks + cr->actual_num_seg2_blocks) >> 1) / num8x8bl; // Compute delta-q corresponding to qindex i. int deltaq = compute_deltaq(cpi, i, cr->rate_ratio_qdelta); // Take segment weighted average for bits per mb. bits_per_mb = (int)((1.0 - weight_segment) * vp9_rc_bits_per_mb(cm->frame_type, i, correction_factor, cm->bit_depth) + weight_segment * vp9_rc_bits_per_mb(cm->frame_type, i + deltaq, correction_factor, cm->bit_depth)); return bits_per_mb; }
static int estimate_bits_at_q(int frame_kind, int q, int mbs, double correction_factor) { const int bpm = (int)(vp9_rc_bits_per_mb(frame_kind, q, correction_factor)); // Attempt to retain reasonable accuracy without overflow. The cutoff is // chosen such that the maximum product of Bpm and MBs fits 31 bits. The // largest Bpm takes 20 bits. return (mbs > (1 << 11)) ? (bpm >> BPER_MB_NORMBITS) * mbs : (bpm * mbs) >> BPER_MB_NORMBITS; }