]> git.sesse.net Git - vlc/blobdiff - src/audio_output/input.c
* Finally fixed the segfault when resampling.
[vlc] / src / audio_output / input.c
index 81689a37acc04329873c4e1c4c2ad1412ae11faf..a12db52b9a2c6edf097f4516073623b5cd66ad40 100644 (file)
@@ -2,7 +2,7 @@
  * input.c : internal management of input streams for the audio output
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: input.c,v 1.7 2002/08/21 22:41:59 massiot Exp $
+ * $Id: input.c,v 1.10 2002/08/28 22:25:39 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
 
 #include <vlc/vlc.h>
 
+#ifdef HAVE_ALLOCA_H
+#   include <alloca.h>
+#endif
+
 #include "audio_output.h"
 #include "aout_internal.h"
 
@@ -229,7 +233,7 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         /* The decoder is _very_ late. This can only happen if the user
          * pauses the stream (or if the decoder is buggy, which cannot
          * happen :). */
-        msg_Warn( p_aout, "Computed PTS is out of range (%lld), clearing out",
+        msg_Warn( p_aout, "computed PTS is out of range (%lld), clearing out",
                   start_date );
         vlc_mutex_lock( &p_aout->mixer_lock );
         aout_FifoSet( p_aout, &p_input->fifo, 0 );
@@ -237,7 +241,7 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         start_date = 0;
     } 
 
-    if ( p_buffer->start_date < mdate() - AOUT_MIN_PREPARE_TIME )
+    if ( p_buffer->start_date < mdate() + AOUT_MIN_PREPARE_TIME )
     {
         /* The decoder gives us f*cked up PTS. It's its business, but we
          * can't present it anyway, so drop the buffer. */
@@ -264,7 +268,7 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
          *    synchronization
          * Solution : resample the buffer to avoid a scratch.
          */
-        audio_sample_format_t new_output;
+        audio_sample_format_t new_input;
         int i_ratio, i_nb_filters;
         mtime_t old_duration;
         aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
@@ -275,7 +279,7 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         msg_Warn( p_aout, "buffer is %lld %s, resampling",
                          drift > 0 ? drift : -drift,
                          drift > 0 ? "in advance" : "late" );
-        memcpy( &new_output, &p_aout->mixer.mixer,
+        memcpy( &new_input, &p_input->input,
                 sizeof(audio_sample_format_t) );
         old_duration = p_buffer->end_date - p_buffer->start_date;
         duration = p_buffer->end_date - start_date;
@@ -289,11 +293,12 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         {
             duration = old_duration * 150 / 100;
         }
-        new_output.i_rate = new_output.i_rate * duration / old_duration;
+        new_input.i_rate = new_input.i_rate * old_duration / duration;
+        aout_FormatPrepare( &new_input );
 
         if ( aout_FiltersCreatePipeline( p_aout, pp_filters,
-                                         &i_nb_filters, &p_input->input,
-                                         &new_output ) < 0 )
+                                         &i_nb_filters, &new_input,
+                                         &p_aout->mixer.mixer ) < 0 )
         {
             msg_Err( p_aout, "couldn't set an input pipeline for resampling" );
             vlc_mutex_lock( &p_aout->mixer_lock );
@@ -314,16 +319,17 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
                                  &dummy_alloc );
         dummy_alloc.i_bytes_per_sec = __MAX(
                                     dummy_alloc.i_bytes_per_sec,
-                                    p_input->input.i_bytes_per_frame
-                                     * p_input->input.i_rate
-                                     / p_input->input.i_frame_length );
+                                    new_input.i_bytes_per_frame
+                                     * new_input.i_rate
+                                     / new_input.i_frame_length );
         dummy_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
 
-        aout_BufferAlloc( &dummy_alloc, old_duration, NULL, p_new_buffer );
+        aout_BufferAlloc( &dummy_alloc, duration, NULL, p_new_buffer );
         memcpy( p_new_buffer->p_buffer, p_buffer->p_buffer,
                 p_buffer->i_nb_bytes );
         p_new_buffer->i_nb_samples = p_buffer->i_nb_samples;
         p_new_buffer->i_nb_bytes = p_buffer->i_nb_bytes;
+
         aout_BufferFree( p_buffer );
         p_buffer = p_new_buffer;