Commit 179f99f7 authored by Gildas Bazin's avatar Gildas Bazin

* src/input/*: fixed some deadlock issues.

   The locking is still far from perfect and will need some cleanup but this is a step in the right direction.
parent 609daab5
......@@ -319,11 +319,8 @@ static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
}
psz_description = LanguageGetName( fmt->psz_language );
es->p_es = input_AddES( p_input,
p_prgm,
fmt->i_id + 1,
fmt->i_cat,
psz_description, 0 );
es->p_es = input_AddES( p_input, p_prgm, fmt->i_id + 1,
fmt->i_cat, psz_description, 0 );
es->p_es->i_stream_id = fmt->i_id;
es->p_es->i_fourcc = fmt->i_codec;
......@@ -495,13 +492,14 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
if( es->p_es->p_dec &&
(es->p_es->i_cat!=AUDIO_ES || !p_sys->p_input->stream.control.b_mute) )
{
vlc_mutex_unlock( &out->p_sys->p_input->stream.stream_lock );
input_DecodeBlock( es->p_es->p_dec, p_block );
}
else
{
vlc_mutex_unlock( &out->p_sys->p_input->stream.stream_lock );
block_Release( p_block );
}
vlc_mutex_unlock( &out->p_sys->p_input->stream.stream_lock );
return VLC_SUCCESS;
}
......
......@@ -190,36 +190,20 @@ decoder_t * input_RunDecoder( input_thread_t * p_input, es_descriptor_t * p_es )
void input_EndDecoder( input_thread_t * p_input, es_descriptor_t * p_es )
{
decoder_t *p_dec = p_es->p_dec;
int i_dummy;
p_dec->b_die = VLC_TRUE;
if( p_dec->p_owner->b_own_thread )
{
/* Make sure the thread leaves the NextDataPacket() function by
* sending it a few null packets. */
for( i_dummy = 0; i_dummy < PADDING_PACKET_NUMBER; i_dummy++ )
{
input_NullPacket( p_input, p_es );
}
/* Make sure the thread leaves the function by
* sending it an empty block. */
block_t *p_block = block_New( p_dec, 0 );
input_DecodeBlock( p_dec, p_block );
if( p_es->p_pes != NULL )
{
input_DecodePES( p_es->p_dec, p_es->p_pes );
}
/* Waiting for the thread to exit */
/* I thought that unlocking was better since thread join can be long
* but it actually creates late pictures and freezes --stef */
/* vlc_mutex_unlock( &p_input->stream.stream_lock ); */
vlc_thread_join( p_dec );
/* vlc_mutex_lock( &p_input->stream.stream_lock ); */
#if 0
/* XXX We don't do it here because of dll loader that want close in the
* same thread than open/decode */
/* Unneed module */
module_Unneed( p_dec, p_dec->p_module );
#endif
/* Don't module_Unneed() here because of the dll loader that wants
* close() in the same thread than open()/decode() */
}
else
{
......@@ -261,7 +245,7 @@ void input_DecodePES( decoder_t * p_dec, pes_packet_t * p_pes )
{
uint8_t *p_buffer = p_block->p_buffer;
for( p_data = p_pes->p_first; p_data != NULL; p_data = p_data->p_next )
for( p_data = p_pes->p_first; p_data; p_data = p_data->p_next )
{
int i_copy = p_data->p_payload_end - p_data->p_payload_start;
......@@ -553,7 +537,7 @@ static decoder_t * CreateDecoder( input_thread_t * p_input,
*/
static int DecoderThread( decoder_t * p_dec )
{
block_t *p_block;
block_t *p_block;
/* The decoder's main loop */
while( !p_dec->b_die && !p_dec->b_error )
......@@ -563,12 +547,7 @@ static int DecoderThread( decoder_t * p_dec )
p_dec->b_error = 1;
break;
}
if( p_block->i_buffer <= 0 )
{
block_Release( p_block );
continue;
}
if( DecoderDecode( p_dec, p_block ) )
if( DecoderDecode( p_dec, p_block ) != VLC_SUCCESS )
{
break;
}
......@@ -578,15 +557,11 @@ static int DecoderThread( decoder_t * p_dec )
{
/* Trash all received PES packets */
p_block = block_FifoGet( p_dec->p_owner->p_fifo );
if( p_block )
{
block_Release( p_block );
}
if( p_block ) block_Release( p_block );
}
/* XXX We do it here because of dll loader that want close in the
* same thread than open/decode */
/* Unneed module */
/* We do it here because of the dll loader that wants close() in the
* same thread than open()/decode() */
module_Unneed( p_dec, p_dec->p_module );
return 0;
......
......@@ -132,6 +132,8 @@ int input_InitStream( input_thread_t * p_input, size_t i_data_len )
*****************************************************************************/
void input_EndStream( input_thread_t * p_input )
{
vlc_mutex_lock( &p_input->stream.stream_lock );
/* Free all programs and associated ES, and associated decoders. */
while( p_input->stream.i_pgrm_number )
{
......@@ -161,6 +163,8 @@ void input_EndStream( input_thread_t * p_input )
free( p_input->stream.p_demux_data );
}
vlc_mutex_unlock( &p_input->stream.stream_lock );
/* Free navigation variables */
var_Destroy( p_input, "program" );
var_Destroy( p_input, "title" );
......@@ -958,8 +962,13 @@ int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
}
/* FIXME: input_UnselectES() shouldn't actually be entered with the
* input lock, the locking should be done here and only where necessary. */
vlc_mutex_unlock( &p_input->stream.stream_lock );
/* Actually unselect the ES */
input_EndDecoder( p_input, p_es );
vlc_mutex_lock( &p_input->stream.stream_lock );
p_es->p_pes = NULL;
if( ( p_es->p_dec == NULL ) &&
......
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