From: Gildas Bazin Date: Sun, 18 Apr 2004 22:48:23 +0000 (+0000) Subject: * src/input/*: fixed some deadlock issues. X-Git-Tag: 0.7.2~374 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=179f99f7c7321d856b7a3f76d4af796cde79f53a;p=vlc * 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. --- diff --git a/src/input/es_out.c b/src/input/es_out.c index 173c72bc2f..b1c1033d73 100644 --- a/src/input/es_out.c +++ b/src/input/es_out.c @@ -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; } diff --git a/src/input/input_dec.c b/src/input/input_dec.c index 65eae02e8b..0b5979b202 100644 --- a/src/input/input_dec.c +++ b/src/input/input_dec.c @@ -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; diff --git a/src/input/input_programs.c b/src/input/input_programs.c index f5b08b1011..469510d36d 100644 --- a/src/input/input_programs.c +++ b/src/input/input_programs.c @@ -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 ) &&