]> git.sesse.net Git - vlc/commitdiff
* src/input/*: fixed some deadlock issues.
authorGildas Bazin <gbazin@videolan.org>
Sun, 18 Apr 2004 22:48:23 +0000 (22:48 +0000)
committerGildas Bazin <gbazin@videolan.org>
Sun, 18 Apr 2004 22:48:23 +0000 (22:48 +0000)
   The locking is still far from perfect and will need some cleanup but this is a step in the right direction.

src/input/es_out.c
src/input/input_dec.c
src/input/input_programs.c

index 173c72bc2f7df4b7519bca9053598cd23693cca8..b1c1033d730ac2e00dad9ef098c5207118623e7c 100644 (file)
@@ -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;
 }
index 65eae02e8b8c4e7b00f45af85ade1cd241308e2b..0b5979b202722e16b673e3a1888658e39fc64349 100644 (file)
@@ -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;
index f5b08b1011ba782004b8c001c5f62032c16b4128..469510d36d0d9a7b8b0d176929637292d67973b0 100644 (file)
@@ -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 ) &&