diff --git a/common/frame.c b/common/frame.c index a1a36b5..9956527 100644 --- a/common/frame.c +++ b/common/frame.c @@ -825,8 +825,6 @@ void x264_deblock_init( int cpu, x264_deblock_function_t *pf ) /* threading */ - -#ifdef HAVE_PTHREAD void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ) { x264_pthread_mutex_lock( &frame->mutex ); @@ -843,42 +841,6 @@ void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ) x264_pthread_mutex_unlock( &frame->mutex ); } -void x264_frame_size_estimated_set( x264_t *h, int bits ) -{ - x264_pthread_mutex_lock( &h->fenc->mutex ); - x264_ratecontrol_set_estimated_size(h, bits); - x264_pthread_mutex_unlock( &h->fenc->mutex ); -} - -int x264_frame_size_estimated_get( x264_t const *h) -{ - int size; - x264_pthread_mutex_lock( &h->fenc->mutex ); - size = x264_ratecontrol_get_estimated_size(h); - x264_pthread_mutex_unlock( &h->fenc->mutex ); - return size; -} - -#else -void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ) -{} -void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ) -{} - -void x264_frame_size_estimated_set( x264_t *h, int bits ) -{ - x264_ratecontrol_set_estimated_size(h, bits); -} - -int x264_frame_size_estimated_get( x264_t const *h) -{ - int size; - size = x264_ratecontrol_set_estimated_size(h); - return size; -} -#endif - - /* list operators */ void x264_frame_push( x264_frame_t **list, x264_frame_t *frame ) diff --git a/common/frame.h b/common/frame.h index 25a373e..1cd7b64 100644 --- a/common/frame.h +++ b/common/frame.h @@ -121,9 +121,6 @@ void x264_deblock_init( int cpu, x264_deblock_function_t *pf ); void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ); void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ); -void x264_frame_size_estimated_set( x264_t *h, int bits ); -int x264_frame_size_estimated_get( x264_t const *h); - void x264_frame_push( x264_frame_t **list, x264_frame_t *frame ); x264_frame_t *x264_frame_pop( x264_frame_t **list ); void x264_frame_unshift( x264_frame_t **list, x264_frame_t *frame ); diff --git a/common/osdep.h b/common/osdep.h index c3c8149..8d284fe 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -37,6 +37,7 @@ #endif #ifdef _MSC_VER +#include #define inline __inline #define strcasecmp stricmp #define strncasecmp strnicmp @@ -44,6 +45,7 @@ #define fseek _fseeki64 #define ftell _ftelli64 #define isfinite _finite +#define usleep(t) Sleep((t) / 1000) #define _CRT_SECURE_NO_DEPRECATE #define X264_VERSION "" // no configure script for msvc #endif diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index e15fe16..37cd994 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -729,12 +729,18 @@ void x264_ratecontrol_delete( x264_t *h ) void x264_ratecontrol_set_estimated_size( x264_t *h, int bits ) { + x264_pthread_mutex_lock( &h->fenc->mutex ); h->rc->frame_size_estimated = bits; + x264_pthread_mutex_unlock( &h->fenc->mutex ); } int x264_ratecontrol_get_estimated_size( x264_t const *h) { - return h->rc->frame_size_estimated; + int size; + x264_pthread_mutex_lock( &h->fenc->mutex ); + size = h->rc->frame_size_estimated; + x264_pthread_mutex_unlock( &h->fenc->mutex ); + return size; } static void accum_p_qp_update( x264_t *h, float qp ) @@ -919,7 +925,7 @@ void x264_ratecontrol_mb( x264_t *h, int bits ) rc->qpm = X264_MIN(X264_MAX( rc->qp, avg_qp), 51); //avg_qp could go higher than 51 due to pb_offset i_estimated = row_bits_so_far(h, y); //FIXME: compute full estimated size if (i_estimated > h->rc->frame_size_planned) - x264_frame_size_estimated_set(h, i_estimated); + x264_ratecontrol_set_estimated_size(h, i_estimated); } } else @@ -975,7 +981,7 @@ void x264_ratecontrol_mb( x264_t *h, int bits ) rc->qpm --; b1 = predict_row_size_sum( h, y, rc->qpm ); } - x264_frame_size_estimated_set(h, b1); + x264_ratecontrol_set_estimated_size(h, b1); } } /* loses the fractional part of the frame-wise qp */ @@ -1327,7 +1333,7 @@ static void update_vbv_plan( x264_t *h ) double bits = t->rc->frame_size_planned; if( !t->b_thread_active ) continue; - bits = X264_MAX(bits, x264_frame_size_estimated_get(t)); + bits = X264_MAX(bits, x264_ratecontrol_get_estimated_size(t)); rcc->buffer_fill += rcc->buffer_rate - bits; rcc->buffer_fill = x264_clip3( rcc->buffer_fill, 0, rcc->buffer_size ); } @@ -1464,7 +1470,7 @@ static float rate_estimate_qscale( x264_t *h ) q += rcc->pb_offset; rcc->frame_size_planned = predict_size( rcc->pred_b_from_p, q, h->fref1[h->i_ref1-1]->i_satd ); - x264_frame_size_estimated_set(h, rcc->frame_size_planned); + x264_ratecontrol_set_estimated_size(h, rcc->frame_size_planned); rcc->last_satd = 0; return qp2qscale(q); } @@ -1594,7 +1600,7 @@ static float rate_estimate_qscale( x264_t *h ) rcc->frame_size_planned = qscale2bits(&rce, q); else rcc->frame_size_planned = predict_size( &rcc->pred[h->sh.i_type], q, rcc->last_satd ); - x264_frame_size_estimated_set(h, rcc->frame_size_planned); + x264_ratecontrol_set_estimated_size(h, rcc->frame_size_planned); return q; } }