vlc | branch: master | Ilkka Ollakka <il...@videolan.org> | Sat Sep 24 19:04:41 2016 +0300| [8f851fb2d61771f0d26f9e21c4a639ba3484ad00] | committer: Ilkka Ollakka
transcode: use semaphore to limit how many pictures are in picture pool in threading case > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8f851fb2d61771f0d26f9e21c4a639ba3484ad00 --- modules/stream_out/transcode/transcode.c | 8 +++++++- modules/stream_out/transcode/transcode.h | 2 ++ modules/stream_out/transcode/video.c | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c index 912205e..25e5bd5 100644 --- a/modules/stream_out/transcode/transcode.c +++ b/modules/stream_out/transcode/transcode.c @@ -131,6 +131,9 @@ #define HP_LONGTEXT N_( \ "Runs the optional encoder thread at the OUTPUT priority instead of " \ "VIDEO." ) +#define POOL_TEXT N_("Picture pool size") +#define POOL_LONGTEXT N_( "Defines how many pictures we allow to be in pool "\ + "between decoder/encoder threads when threads > 0" ) static const char *const ppsz_deinterlace_type[] = @@ -216,6 +219,8 @@ vlc_module_begin () set_section( N_("Miscellaneous"), NULL ) add_integer( SOUT_CFG_PREFIX "threads", 0, THREADS_TEXT, THREADS_LONGTEXT, true ) + add_integer( SOUT_CFG_PREFIX "pool-size", 10, POOL_TEXT, POOL_LONGTEXT, true ) + change_integer_range( 1, 1000 ) add_bool( SOUT_CFG_PREFIX "high-priority", false, HP_TEXT, HP_LONGTEXT, true ) @@ -226,7 +231,7 @@ static const char *const ppsz_sout_options[] = { "scale", "fps", "width", "height", "vfilter", "deinterlace", "deinterlace-module", "threads", "aenc", "acodec", "ab", "alang", "afilter", "samplerate", "channels", "senc", "scodec", "soverlay", - "sfilter", "osd", "high-priority", "maxwidth", "maxheight", + "sfilter", "osd", "high-priority", "maxwidth", "maxheight", "pool-size", NULL }; @@ -374,6 +379,7 @@ static int Open( vlc_object_t *p_this ) free( psz_string ); p_sys->i_threads = var_GetInteger( p_stream, SOUT_CFG_PREFIX "threads" ); + p_sys->pool_size = var_GetInteger( p_stream, SOUT_CFG_PREFIX "pool-size" ); p_sys->b_high_priority = var_GetBool( p_stream, SOUT_CFG_PREFIX "high-priority" ); if( p_sys->i_vcodec ) diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h index ab1904c..eca3298 100644 --- a/modules/stream_out/transcode/transcode.h +++ b/modules/stream_out/transcode/transcode.h @@ -22,6 +22,8 @@ struct sout_stream_sys_t vlc_cond_t cond; bool b_abort; picture_fifo_t *pp_pics; + vlc_sem_t picture_pool_has_room; + uint32_t pool_size; vlc_thread_t thread; /* Audio */ diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c index 50f98f0..349d56e 100644 --- a/modules/stream_out/transcode/video.c +++ b/modules/stream_out/transcode/video.c @@ -81,6 +81,7 @@ static void* EncoderThread( void *obj ) while( !p_sys->b_abort && (p_pic = picture_fifo_Pop( p_sys->pp_pics )) == NULL ) vlc_cond_wait( &p_sys->cond, &p_sys->lock_out ); + vlc_sem_post( &p_sys->picture_pool_has_room ); if( p_pic ) { @@ -100,6 +101,7 @@ static void* EncoderThread( void *obj ) /*Encode what we have in the buffer on closing*/ while( (p_pic = picture_fifo_Pop( p_sys->pp_pics )) != NULL ) { + vlc_sem_post( &p_sys->picture_pool_has_room ); p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic ); picture_Release( p_pic ); block_ChainAppend( &p_sys->p_buffers, p_block ); @@ -227,6 +229,9 @@ int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_sys_t *id ) free( id->p_decoder->p_owner ); return VLC_ENOMEM; } + /* We allow at max 500 pictures in pool before we wait for room */ + vlc_sem_init( &p_sys->picture_pool_has_room, p_sys->pool_size ); + vlc_mutex_init( &p_sys->lock_out ); vlc_cond_init( &p_sys->cond ); p_sys->p_buffers = NULL; @@ -705,6 +710,7 @@ static void OutputFrame( sout_stream_t *p_stream, picture_t *p_pic, sout_stream_ if( p_sys->i_threads ) { + vlc_sem_wait( &p_sys->picture_pool_has_room ); vlc_mutex_lock( &p_sys->lock_out ); picture_fifo_Push( p_sys->pp_pics, p_pic ); vlc_cond_signal( &p_sys->cond ); _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits