[vlc-commits] aout_InputPlay: compute drift once (rather than 2-4 times)
Rémi Denis-Courmont
git at videolan.org
Thu Jun 9 18:17:36 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun 9 19:08:57 2011 +0300| [fa5084f6804886c9e0a329b247834c23c344312d] | committer: Rémi Denis-Courmont
aout_InputPlay: compute drift once (rather than 2-4 times)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fa5084f6804886c9e0a329b247834c23c344312d
---
src/audio_output/input.c | 52 ++++++++++++++++++---------------------------
1 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/src/audio_output/input.c b/src/audio_output/input.c
index 993db6f..28620d7 100644
--- a/src/audio_output/input.c
+++ b/src/audio_output/input.c
@@ -581,12 +581,17 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
/* If the audio drift is too big then it's not worth trying to resample
* the audio. */
- mtime_t i_pts_tolerance = 3 * AOUT_PTS_TOLERANCE * i_input_rate / INPUT_RATE_DEFAULT;
- if ( start_date != 0 &&
- ( start_date < p_buffer->i_pts - i_pts_tolerance ) )
+ if( !start_date )
+ start_date = p_buffer->i_pts;
+
+ mtime_t tolerance = 3 * AOUT_PTS_TOLERANCE
+ * i_input_rate / INPUT_RATE_DEFAULT;
+ mtime_t drift = start_date - p_buffer->i_pts;
+
+ if( drift < -tolerance )
{
- msg_Warn( p_aout, "audio drift is too big (%"PRId64"), clearing out",
- start_date - p_buffer->i_pts );
+ msg_Warn( p_aout, "buffer way too early (%"PRId64"), clearing queue",
+ drift );
aout_lock_input_fifos( p_aout );
aout_FifoSet( &p_input->mixer.fifo, 0 );
aout_unlock_input_fifos( p_aout );
@@ -594,19 +599,16 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
msg_Warn( p_aout, "timing screwed, stopping resampling" );
inputResamplingStop( p_input );
p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
- start_date = 0;
+ start_date = p_buffer->i_pts;
}
- else if ( start_date != 0 &&
- ( start_date > p_buffer->i_pts + i_pts_tolerance) )
+ else if( drift > +tolerance )
{
- msg_Warn( p_aout, "audio drift is too big (%"PRId64"), dropping buffer",
- start_date - p_buffer->i_pts );
+ msg_Warn( p_aout, "buffer way too late (%"PRId64"), dropping buffer",
+ drift );
inputDrop( p_input, p_buffer );
return 0;
}
- if ( start_date == 0 ) start_date = p_buffer->i_pts;
-
#ifndef AOUT_PROCESS_BEFORE_CHEKS
/* Run pre-filters. */
aout_FiltersPlay( p_input->pp_filters, p_input->i_nb_filters, &p_buffer );
@@ -617,8 +619,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
/* Run the resampler if needed.
* We first need to calculate the output rate of this resampler. */
if ( ( p_input->i_resampling_type == AOUT_RESAMPLING_NONE ) &&
- ( start_date < p_buffer->i_pts - AOUT_PTS_TOLERANCE
- || start_date > p_buffer->i_pts + AOUT_PTS_TOLERANCE ) &&
+ ( drift < -AOUT_PTS_TOLERANCE || drift > +AOUT_PTS_TOLERANCE ) &&
p_input->i_nb_resamplers > 0 )
{
/* Can happen in several circumstances :
@@ -628,20 +629,13 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
* synchronization
* Solution : resample the buffer to avoid a scratch.
*/
- mtime_t drift = p_buffer->i_pts - start_date;
-
p_input->i_resamp_start_date = now;
- p_input->i_resamp_start_drift = (int)drift;
-
- if ( drift > 0 )
- p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
- else
- p_input->i_resampling_type = AOUT_RESAMPLING_UP;
-
- msg_Warn( p_aout, "buffer is %"PRId64" %s, triggering %ssampling",
- drift > 0 ? drift : -drift,
- drift > 0 ? "in advance" : "late",
- drift > 0 ? "down" : "up");
+ p_input->i_resamp_start_drift = (int)-drift;
+ p_input->i_resampling_type = (drift < 0) ? AOUT_RESAMPLING_DOWN
+ : AOUT_RESAMPLING_UP;
+ msg_Warn( p_aout, (drift < 0)
+ ? "buffer too early (%"PRId64"), down-sampling"
+ : "buffer too late (%"PRId64"), up-sampling", drift );
}
if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
@@ -651,13 +645,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
* it isn't too audible to the listener. */
if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
- {
p_input->pp_resamplers[0]->fmt_in.audio.i_rate += 2; /* Hz */
- }
else
- {
p_input->pp_resamplers[0]->fmt_in.audio.i_rate -= 2; /* Hz */
- }
/* Check if everything is back to normal, in which case we can stop the
* resampling */
More information about the vlc-commits
mailing list