]> git.sesse.net Git - vlc/commitdiff
* Several stability patches for multiple input streams aout.
authorChristophe Massiot <massiot@videolan.org>
Sat, 28 Sep 2002 13:05:16 +0000 (13:05 +0000)
committerChristophe Massiot <massiot@videolan.org>
Sat, 28 Sep 2002 13:05:16 +0000 (13:05 +0000)
modules/audio_mixer/spdif.c
modules/audio_mixer/trivial.c
modules/codec/faad/decoder.c
modules/codec/lpcm.c
modules/codec/mad/decoder.c
src/audio_output/mixer.c

index 36ae56d09cbb1ae85a4dab90cfe2ad95770b8166..de662b6e79c431e1e98601ff1ce897a23e1ed3b5 100644 (file)
@@ -2,7 +2,7 @@
  * spdif.c : dummy mixer for S/PDIF output (1 input only)
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: spdif.c,v 1.6 2002/09/20 23:27:03 massiot Exp $
+ * $Id: spdif.c,v 1.7 2002/09/28 13:05:16 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -73,8 +73,32 @@ static int Create( vlc_object_t *p_this )
  *****************************************************************************/
 static void DoWork( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
 {
-    aout_input_t * p_input = p_aout->pp_inputs[0];
-    if ( p_input->b_error ) return;
+    int i = 0;
+    aout_input_t * p_input = p_aout->pp_inputs[i];
+    while ( p_input->b_error )
+    {
+        p_input = p_aout->pp_inputs[++i];
+    }
     aout_FifoPop( p_aout, &p_input->fifo );
+
+    /* Empty other FIFOs to avoid a memory leak. */
+    for ( i++; i < p_aout->i_nb_inputs; i++ )
+    {
+        aout_fifo_t * p_fifo;
+        aout_buffer_t * p_deleted;
+
+        p_input = p_aout->pp_inputs[i];
+        if ( p_input->b_error ) continue;
+        p_fifo = &p_input->fifo;
+        p_deleted = p_fifo->p_first;  
+        while ( p_deleted != NULL )
+        {
+            aout_buffer_t * p_next = p_deleted->p_next;
+            aout_BufferFree( p_deleted );
+            p_deleted = p_next;
+        }
+        p_fifo->p_first = NULL;
+        p_fifo->pp_last = &p_fifo->p_first;
+    }
 }
 
index e426b4486d34cac5bebe15ba27d7d935349d23f8..0e2c1764454dfa6549463d43fac53bbd09892156 100644 (file)
@@ -2,7 +2,7 @@
  * trivial.c : trivial mixer plug-in (1 input, no downmixing)
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: trivial.c,v 1.7 2002/09/20 23:27:03 massiot Exp $
+ * $Id: trivial.c,v 1.8 2002/09/28 13:05:16 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -71,13 +71,21 @@ static int Create( vlc_object_t *p_this )
  *****************************************************************************/
 static void DoWork( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
 {
-    aout_input_t * p_input = p_aout->pp_inputs[0];
+    int i = 0;
+    aout_input_t * p_input = p_aout->pp_inputs[i];
     int i_nb_bytes = p_buffer->i_nb_samples * sizeof(s32)
                       * p_aout->mixer.mixer.i_channels;
-    byte_t * p_in = p_input->p_first_byte_to_mix;
-    byte_t * p_out = p_buffer->p_buffer;
+    byte_t * p_in;
+    byte_t * p_out;
 
-    if ( p_input->b_error ) return;
+    while ( p_input->b_error )
+    {
+        p_input = p_aout->pp_inputs[++i];
+        /* This can't crash because if no input has b_error == 0, the
+         * audio mixer cannot run and we can't be here. */
+    }
+    p_in = p_input->p_first_byte_to_mix;
+    p_out = p_buffer->p_buffer;
 
     for ( ; ; )
     {
@@ -114,5 +122,25 @@ static void DoWork( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
             break;
         }
     }
+
+    /* Empty other FIFOs to avoid a memory leak. */
+    for ( i++; i < p_aout->i_nb_inputs; i++ )
+    {
+        aout_fifo_t * p_fifo;
+        aout_buffer_t * p_deleted;
+
+        p_input = p_aout->pp_inputs[i];
+        if ( p_input->b_error ) continue;
+        p_fifo = &p_input->fifo;
+        p_deleted = p_fifo->p_first;
+        while ( p_deleted != NULL )
+        {
+            aout_buffer_t * p_next = p_deleted->p_next;
+            aout_BufferFree( p_deleted );
+            p_deleted = p_next;
+        }
+        p_fifo->p_first = NULL;
+        p_fifo->pp_last = &p_fifo->p_first;
+    }
 }
 
index f95e00be22c26334ea48e3b15ae86fc342725e7f..7c5966ece2f3e364363482dad192cca8cccf603c 100644 (file)
@@ -2,7 +2,7 @@
  * decoder.c: AAC decoder using libfaad2
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: decoder.c,v 1.3 2002/09/26 22:40:21 massiot Exp $
+ * $Id: decoder.c,v 1.4 2002/09/28 13:05:16 massiot Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *      
@@ -329,6 +329,8 @@ static int InitThread( adec_thread_t * p_adec )
     p_adec->output_format.i_format = AOUT_FMT_FLOAT32;
     p_adec->output_format.i_rate = i_rate;
     p_adec->output_format.i_channels = i_channels;
+    p_adec->p_aout = NULL;
+    p_adec->p_aout_input = NULL;
   
 #if 0
     if( !p_adec->format.p_data )
index 69782e674e3811efe90b09356de95074f8157197..4c315d7025ce70458caf4be57289780afcdbecd2 100644 (file)
@@ -2,7 +2,7 @@
  * lpcm.c: lpcm decoder module
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: lpcm.c,v 1.2 2002/09/26 22:40:20 massiot Exp $
+ * $Id: lpcm.c,v 1.3 2002/09/28 13:05:16 massiot Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Henri Fallon <henri@videolan.org>
@@ -131,6 +131,7 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
     p_dec->output_format.i_rate = 48000;
     
     aout_DateInit( &p_dec->end_date, 48000 );
+    p_dec->p_aout = NULL;
     p_dec->p_aout_input = aout_DecNew( p_dec->p_fifo,
                                        &p_dec->p_aout,
                                        &p_dec->output_format );
index 9fcdc825064185902816569da74595289f4d1c79..07658a5eb1e464a0273fdfc461c3750fcb35dd76 100644 (file)
@@ -190,7 +190,7 @@ static void EndThread (mad_adec_thread_t * p_dec)
     /* If the audio output fifo was created, we destroy it */
     if (p_dec->p_aout_input != NULL)
     {
-        aout_InputDelete( p_dec->p_aout, p_dec->p_aout_input );
+        aout_DecDelete( p_dec->p_aout, p_dec->p_aout_input );
     }
 
     /* mad_decoder_finish releases the memory allocated inside the struct */
index d07b49bbd77c70ee06f23275fdb0fc6c7a99494d..4e990045b94334324f69ddebef9d43b416b4b5f6 100644 (file)
@@ -2,7 +2,7 @@
  * mixer.c : audio output mixing operations
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: mixer.c,v 1.16 2002/09/26 22:40:25 massiot Exp $
+ * $Id: mixer.c,v 1.17 2002/09/28 13:05:16 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -74,7 +74,7 @@ int aout_MixerDelete( aout_instance_t * p_aout )
  *****************************************************************************/
 static int MixBuffer( aout_instance_t * p_aout )
 {
-    int             i, i_nb_real_inputs = 0;
+    int             i, i_first_input = 0;
     aout_buffer_t * p_output_buffer;
     mtime_t start_date, end_date;
     audio_date_t exact_start_date;
@@ -168,8 +168,11 @@ static int MixBuffer( aout_instance_t * p_aout )
         mtime_t prev_date;
         vlc_bool_t b_drop_buffers;
 
-        if ( p_input->b_error ) continue;
-        i_nb_real_inputs++;
+        if ( p_input->b_error )
+        {
+            if ( i_first_input == i ) i_first_input++;
+            continue;
+        }
 
         p_buffer = p_fifo->p_first;
         if ( p_buffer == NULL )
@@ -268,7 +271,7 @@ static int MixBuffer( aout_instance_t * p_aout )
         if ( p_buffer == NULL ) break;
     }
 
-    if ( i < p_aout->i_nb_inputs || !i_nb_real_inputs )
+    if ( i < p_aout->i_nb_inputs || i_first_input == p_aout->i_nb_inputs )
     {
         /* Interrupted before the end... We can't run. */
         vlc_mutex_unlock( &p_aout->input_fifos_lock );
@@ -281,7 +284,7 @@ static int MixBuffer( aout_instance_t * p_aout )
                         / p_aout->output.output.i_rate,
                       /* This is a bit kludgy, but is actually only used
                        * for the S/PDIF dummy mixer : */
-                      p_aout->pp_inputs[0]->fifo.p_first,
+                      p_aout->pp_inputs[i_first_input]->fifo.p_first,
                       p_output_buffer );
     if ( p_output_buffer == NULL )
     {