From d89c1b43816f05e43a836d38764d74d499e82a80 Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Thu, 9 Jun 2011 01:34:14 +0400 Subject: [PATCH] Fix various issues with VBV+threads Eliminate the race condition with interframe row predictors and threads. Recalculate frame_size_estimated at the end of a frame, for improved update_vbv_plan. Some cosmetics. --- encoder/ratecontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 97b5ee88..9be06452 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -1219,6 +1219,8 @@ void x264_ratecontrol_start( x264_t *h, int i_force_qp, int overhead ) if( rc->b_vbv ) { memset( h->fdec->i_row_bits, 0, h->mb.i_mb_height * sizeof(int) ); + memset( h->fdec->f_row_qp, 0, h->mb.i_mb_height * sizeof(float) ); + memset( h->fdec->f_row_qscale, 0, h->mb.i_mb_height * sizeof(float) ); rc->row_pred = &rc->row_preds[h->sh.i_type]; rc->buffer_rate = h->fenc->i_cpb_duration * rc->vbv_max_rate * h->sps->vui.i_num_units_in_tick / h->sps->vui.i_time_scale; update_vbv_plan( h, overhead ); @@ -1310,6 +1312,7 @@ static float predict_row_size( x264_t *h, int y, float qscale ) { if( h->sh.i_type == SLICE_TYPE_P && h->fref[0][0]->i_type == h->fdec->i_type + && h->fref[0][0]->f_row_qscale[y] > 0 && h->fref[0][0]->i_row_satd[y] > 0 && (abs(h->fref[0][0]->i_row_satd[y] - h->fdec->i_row_satd[y]) < h->fdec->i_row_satd[y]/2)) { @@ -1457,6 +1460,8 @@ void x264_ratecontrol_mb( x264_t *h, int bits ) h->rc->frame_size_estimated = b1 - size_of_other_slices; } + else + h->rc->frame_size_estimated = predict_row_size_sum( h, y, rc->qpm ); } int x264_ratecontrol_qp( x264_t *h ) @@ -1917,7 +1922,7 @@ static void update_vbv_plan( x264_t *h, int overhead ) double bits = t->rc->frame_size_planned; if( !t->b_thread_active ) continue; - bits = X264_MAX(bits, t->rc->frame_size_estimated); + bits = X264_MAX(bits, t->rc->frame_size_estimated); rcc->buffer_fill -= bits; rcc->buffer_fill = X264_MAX( rcc->buffer_fill, 0 ); rcc->buffer_fill += t->rc->buffer_rate; @@ -2163,7 +2168,7 @@ static float rate_estimate_qscale( x264_t *h ) double bits = t->rc->frame_size_planned; if( !t->b_thread_active ) continue; - bits = X264_MAX(bits, t->rc->frame_size_estimated); + bits = X264_MAX(bits, t->rc->frame_size_estimated); predicted_bits += (int64_t)bits; } } -- 2.40.0