- /* tweak quality based on difference from predicted size */
- if( y < h->sps->i_mb_height-1 )// && h->stat.i_frame_count[h->sh.i_type] > 0 )
- {
- int prev_row_qp = h->fdec->i_row_qp[y];
- int b0 = predict_row_size_sum( h, y, rc->qpm );
- int b1 = b0;
- int i_qp_max = X264_MIN( prev_row_qp + h->param.rc.i_qp_step, h->param.rc.i_qp_max );
- int i_qp_min = X264_MAX( prev_row_qp - h->param.rc.i_qp_step, h->param.rc.i_qp_min );
- float buffer_left_planned = rc->buffer_fill - rc->frame_size_planned;
-
- /* More threads means we have to be more cautious in letting ratecontrol use up extra bits.
- * In 2-pass mode we can be more trusting of the planned frame sizes, since they were decided
- * by actual encoding instead of SATD prediction. */
- float rc_tol = h->param.rc.b_stat_read ? (buffer_left_planned / rc->buffer_size) * rc->frame_size_planned
- : (buffer_left_planned / h->param.i_threads);
- /* Don't modify the row QPs until a sufficent amount of the bits of the frame have been processed, in case a flat */
- /* area at the top of the frame was measured inaccurately. */
- if( row_bits_so_far(h,y) < 0.05 * rc->frame_size_planned )
- return;
-
- if(h->sh.i_type != SLICE_TYPE_I)
- rc_tol /= 2;
-
- if( !rc->b_vbv_min_rate )
- i_qp_min = X264_MAX( i_qp_min, h->sh.i_qp );
-
- while( rc->qpm < i_qp_max
- && ((b1 > rc->frame_size_planned + rc_tol) ||
- (rc->buffer_fill - b1 < buffer_left_planned * 0.5) ||
- (b1 > rc->frame_size_planned && rc->qpm < rc->qp_novbv)) )
- {
- rc->qpm ++;
- b1 = predict_row_size_sum( h, y, rc->qpm );
- }