]> git.sesse.net Git - vlc/commitdiff
* modules/audio_filter/resampler/coreaudio.c: more accurate frame length
authorChristophe Massiot <massiot@videolan.org>
Sun, 11 May 2003 01:00:26 +0000 (01:00 +0000)
committerChristophe Massiot <massiot@videolan.org>
Sun, 11 May 2003 01:00:26 +0000 (01:00 +0000)
  calculation
* modules/audio_output/coreaudio.c: apparently the audio card clock can
  be screwed, so probe it at every buffer
* src/audio_output/output.c: Thou shalt not drop buffers

modules/audio_filter/resampler/coreaudio.c
modules/audio_output/coreaudio.c
src/audio_output/output.c

index a3a4146075c6ab400e2f652e7cf8645c8f162aa6..8a682f904ec14afee6dd50578d24121dafb2a628 100644 (file)
@@ -2,7 +2,7 @@
  * coreaudio.c resampler based on CoreAudio's AudioConverter
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: coreaudio.c,v 1.3 2003/05/04 15:02:42 massiot Exp $
+ * $Id: coreaudio.c,v 1.4 2003/05/11 01:00:26 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -54,6 +54,7 @@ struct aout_filter_sys_t
     AudioStreamBasicDescription s_src_stream_format;
     AudioStreamBasicDescription s_dst_stream_format;
     AudioConverterRef   s_converter;
+    unsigned int i_remainder;
     unsigned int i_first_rate;
 };
 
@@ -109,6 +110,7 @@ static int Create( vlc_object_t *p_this )
     }
     memset( p_filter->p_sys, 0, sizeof(struct aout_filter_sys_t) );
     p_sys->i_first_rate = i_first_rate;
+    p_sys->i_remainder = 0;
 
     p_sys->s_src_stream_format.mFormatID = kAudioFormatLinearPCM;
     p_sys->s_src_stream_format.mFormatFlags
@@ -240,11 +242,14 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
                      (char *)&err );
         }
         p_filter->b_continuity = VLC_TRUE;
+        p_sys->i_remainder = 0;
     }
 #endif
 
-    i_out_nb = p_in_buf->i_nb_samples * p_filter->output.i_rate
-                                    / p_sys->i_first_rate;
+    i_out_nb = (p_in_buf->i_nb_samples * p_filter->output.i_rate
+                 + p_sys->i_remainder) / p_sys->i_first_rate;
+    p_sys->i_remainder = (p_in_buf->i_nb_samples * p_filter->output.i_rate
+                 + p_sys->i_remainder) % p_sys->i_first_rate;
 
     i_output_size = i_out_nb * 4 * i_nb_channels;
     if ( i_output_size > p_out_buf->i_size )
index a1abfafe26cff164e1cf8d29f0ae1ee5bf76cdc3..1daa70243990763a4fa1bed03968ba71ae6bb21f 100644 (file)
@@ -2,7 +2,7 @@
  * coreaudio.c: CoreAudio output plugin
  *****************************************************************************
  * Copyright (C) 2002-2003 VideoLAN
- * $Id: coreaudio.c,v 1.3 2003/05/04 22:42:15 gbazin Exp $
+ * $Id: coreaudio.c,v 1.4 2003/05/11 01:00:26 massiot Exp $
  *
  * Authors: Colin Delacroix <colin@zoy.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -586,6 +586,13 @@ static OSStatus IOCallback( AudioDeviceID inDevice,
 
     host_time.mFlags = kAudioTimeStampHostTimeValid;
     AudioDeviceTranslateTime( inDevice, inOutputTime, &host_time );
+
+#if 1
+    p_sys->clock_diff = - (mtime_t)
+        AudioConvertHostTimeToNanos( AudioGetCurrentHostTime() ) / 1000; 
+    p_sys->clock_diff += mdate();
+#endif
+
     current_date = p_sys->clock_diff +
                    AudioConvertHostTimeToNanos( host_time.mHostTime ) / 1000;
 
index 3441f548a85d195b7a1b09f362c5f9e20280adc8..3fcf77695b10c6ced6292b64275f9397668f8a8a 100644 (file)
@@ -2,7 +2,7 @@
  * output.c : internal management of output streams for the audio output
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: output.c,v 1.39 2003/05/04 23:39:02 gbazin Exp $
+ * $Id: output.c,v 1.40 2003/05/11 01:00:26 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -271,7 +271,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
     vlc_mutex_lock( &p_aout->output_fifo_lock );
 
     p_buffer = p_aout->output.fifo.p_first;
-    while ( p_buffer && p_buffer->start_date < mdate() )
+    while ( p_buffer && p_buffer->start_date < mdate() - AOUT_PTS_TOLERANCE )
     {
         msg_Dbg( p_aout, "audio output is too slow ("I64Fd"), "
                  "trashing "I64Fd"us", mdate() - p_buffer->start_date,
@@ -304,7 +304,8 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
     /* Here we suppose that all buffers have the same duration - this is
      * generally true, and anyway if it's wrong it won't be a disaster. */
     if ( p_buffer->start_date > start_date
-                         + (p_buffer->end_date - p_buffer->start_date) )
+                         + (p_buffer->end_date - p_buffer->start_date)
+                         + AOUT_PTS_TOLERANCE )
     {
         vlc_mutex_unlock( &p_aout->output_fifo_lock );
         if ( !p_aout->output.b_starving )