[vlc-devel] [RFC PATCH 5/5] aout: use original pts as play date

Thomas Guillem thomas at gllm.fr
Thu Feb 28 16:59:54 CET 2019


Previous commits were necessary in order to invalidate last_pts in case of
filter error.

This will be needed if scaletempo/soxr patches are merged.

This will be also required by the new output clock. Indeed, in case of rate
change, only the filters are changed but not the aout. This means that
aout->time_get() timebase need to be the same than clock update points: the
orignal pts given by the decoder. In case the filters are outputting slightly
more or less data because of a ressampler imprecision, the delay will be
corrected via aout->time_get.
---
 src/audio_output/aout_internal.h |  1 +
 src/audio_output/dec.c           | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 32be61034f..b5bb9f9918 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -67,6 +67,7 @@ typedef struct
         int resamp_type; /**< Resampler mode (FIXME: redundant / resampling) */
         bool discontinuity;
     } sync;
+    vlc_tick_t last_pts;
 
     int requested_stereo_mode; /**< Requested stereo mode set by the user */
 
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 3f99580b74..5369534010 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -99,6 +99,7 @@ error:
     owner->sync.rate = 1.f;
     owner->sync.resamp_type = AOUT_RESAMPLING_NONE;
     owner->sync.discontinuity = true;
+    owner->last_pts = VLC_TICK_INVALID;
 
     atomic_init (&owner->buffers_lost, 0);
     atomic_init (&owner->buffers_played, 0);
@@ -362,6 +363,11 @@ int aout_DecPlay(audio_output_t *aout, block_t *block)
         vlc_mutex_unlock (&owner->vp.lock);
     }
 
+    /* Use the original PTS for synchronization and as a play date of the aout
+     * module */
+    if (owner->last_pts == VLC_TICK_INVALID)
+        owner->last_pts = block->i_pts;
+
     block = aout_FiltersPlay(owner->filters, block, owner->sync.rate);
     if (block == NULL)
     {
@@ -377,11 +383,12 @@ int aout_DecPlay(audio_output_t *aout, block_t *block)
     aout_volume_Amplify (owner->volume, block);
 
     /* Drift correction */
-    aout_DecSynchronize(aout, block->i_pts);
+    aout_DecSynchronize(aout, owner->last_pts);
 
     /* Output */
     owner->sync.discontinuity = false;
-    aout->play(aout, block, block->i_pts);
+    aout->play(aout, block, owner->last_pts);
+    owner->last_pts = VLC_TICK_INVALID;
     atomic_fetch_add_explicit(&owner->buffers_played, 1, memory_order_relaxed);
     return ret;
 drop:
@@ -389,6 +396,7 @@ drop:
     block_Release (block);
 lost:
     atomic_fetch_add_explicit(&owner->buffers_lost, 1, memory_order_relaxed);
+    owner->last_pts = VLC_TICK_INVALID;
     return ret;
 }
 
@@ -436,4 +444,5 @@ void aout_DecFlush (audio_output_t *aout, bool wait)
         aout->flush(aout, wait);
     }
     owner->sync.discontinuity = true;
+    owner->last_pts = VLC_TICK_INVALID;
 }
-- 
2.20.1



More information about the vlc-devel mailing list