Commit fb1317c8 authored by Rafaël Carré's avatar Rafaël Carré

transcode: simplify locking in encoder thread

parent 23b2d367
...@@ -74,50 +74,35 @@ static void* EncoderThread( void *obj ) ...@@ -74,50 +74,35 @@ static void* EncoderThread( void *obj )
int canc = vlc_savecancel (); int canc = vlc_savecancel ();
block_t *p_block = NULL; block_t *p_block = NULL;
vlc_mutex_lock( &p_sys->lock_out );
for( ;; ) for( ;; )
{ {
vlc_mutex_lock( &p_sys->lock_out );
while( !p_sys->b_abort && while( !p_sys->b_abort &&
(p_pic = picture_fifo_Pop( p_sys->pp_pics )) == NULL ) (p_pic = picture_fifo_Pop( p_sys->pp_pics )) == NULL )
vlc_cond_wait( &p_sys->cond, &p_sys->lock_out ); vlc_cond_wait( &p_sys->cond, &p_sys->lock_out );
if( p_sys->b_abort && !p_pic )
{
vlc_mutex_unlock( &p_sys->lock_out );
break;
}
vlc_mutex_unlock( &p_sys->lock_out );
if( p_pic ) if( p_pic )
{ {
/* release lock while encoding */
vlc_mutex_unlock( &p_sys->lock_out );
p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic ); p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic );
picture_Release( p_pic );
vlc_mutex_lock( &p_sys->lock_out ); vlc_mutex_lock( &p_sys->lock_out );
block_ChainAppend( &p_sys->p_buffers, p_block );
vlc_mutex_unlock( &p_sys->lock_out ); block_ChainAppend( &p_sys->p_buffers, p_block );
picture_Release( p_pic );
} }
vlc_mutex_lock( &p_sys->lock_out );
if( p_sys->b_abort ) if( p_sys->b_abort )
{
vlc_mutex_unlock( &p_sys->lock_out );
break; break;
}
vlc_mutex_unlock( &p_sys->lock_out );
} }
/*Encode what we have in the buffer on closing*/ /*Encode what we have in the buffer on closing*/
vlc_mutex_lock( &p_sys->lock_out );
while( (p_pic = picture_fifo_Pop( p_sys->pp_pics )) != NULL ) while( (p_pic = picture_fifo_Pop( p_sys->pp_pics )) != NULL )
{ {
p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic ); p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic );
block_ChainAppend( &p_sys->p_buffers, p_block );
picture_Release( p_pic ); picture_Release( p_pic );
block_ChainAppend( &p_sys->p_buffers, p_block );
} }
/*Now flush encoder*/ /*Now flush encoder*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment