[vlc-devel] [PATCH 09/18] aout: add timing notify

Thomas Guillem thomas at gllm.fr
Thu Mar 7 15:25:31 CET 2019


From: RĂ©mi Denis-Courmont <remi at remlab.net>

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
---
 include/vlc_aout.h               |  1 +
 src/audio_output/aout_internal.h |  2 ++
 src/audio_output/dec.c           | 27 ++++++++++++++++-----------
 src/audio_output/output.c        |  7 +++++++
 4 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 11209ee0ce..a4ae6bc498 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -112,6 +112,7 @@
 #include <vlc_block.h>
 
 struct vlc_audio_output_events {
+    void (*timing_report)(audio_output_t *, vlc_tick_t system_now, vlc_tick_t pts);
     void (*volume_report)(audio_output_t *, float);
     void (*mute_report)(audio_output_t *, bool);
     void (*policy_report)(audio_output_t *, bool);
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 5b302a5d93..69825aba35 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -136,6 +136,8 @@ void aout_DecChangePause(audio_output_t *, bool b_paused, vlc_tick_t i_date);
 void aout_DecChangeRate(audio_output_t *aout, float rate);
 void aout_DecFlush(audio_output_t *, bool wait);
 void aout_RequestRestart (audio_output_t *, unsigned);
+void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t system_ts,
+                          vlc_tick_t audio_ts);
 
 static inline void aout_InputRequestRestart(audio_output_t *aout)
 {
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 81fc4fdef8..e32dc19cee 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -221,9 +221,8 @@ static void aout_DecSilence (audio_output_t *aout, vlc_tick_t length, vlc_tick_t
 
 static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
 {
-    aout_owner_t *owner = aout_owner (aout);
-    const float rate = owner->sync.rate;
-    vlc_tick_t drift;
+    vlc_tick_t now = vlc_tick_now();
+    vlc_tick_t delay;
 
     /**
      * Depending on the drift between the actual and intended playback times,
@@ -241,9 +240,18 @@ static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
      * all samples in the buffer will have been played. Then:
      *    pts = vlc_tick_now() + delay
      */
-    if (aout->time_get(aout, &drift) != 0)
+    if (aout->time_get(aout, &delay) != 0)
         return; /* nothing can be done if timing is unknown */
-    drift += vlc_tick_now () - dec_pts;
+
+    aout_RequestRetiming(aout, now, dec_pts - delay);
+}
+
+void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t system_ts,
+                          vlc_tick_t audio_ts)
+{
+    aout_owner_t *owner = aout_owner (aout);
+    const float rate = owner->sync.rate;
+    vlc_tick_t drift = system_ts - audio_ts;
 
     /* Late audio output.
      * This can happen due to insufficient caching, scheduling jitter
@@ -265,11 +273,8 @@ static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
         aout_StopResampling (aout);
         owner->sync.discontinuity = true;
 
-        /* Now the output might be too early... Recheck. */
-        if (aout->time_get(aout, &drift) != 0)
-            return; /* nothing can be done if timing is unknown */
-        drift += vlc_tick_now () - dec_pts;
-    }
+        return; /* nothing can be done if timing is unknown */
+}
 
     /* Early audio output.
      * This is rare except at startup when the buffers are still empty. */
@@ -279,7 +284,7 @@ static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
         if (!owner->sync.discontinuity)
             msg_Warn (aout, "playback way too early (%"PRId64"): "
                       "playing silence", drift);
-        aout_DecSilence (aout, -drift, dec_pts);
+        aout_DecSilence (aout, -drift, audio_ts);
 
         aout_StopResampling (aout);
         owner->sync.discontinuity = true;
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index be7c386f99..f12121a704 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -70,6 +70,12 @@ static int var_CopyDevice (vlc_object_t *src, const char *name,
     return var_Set (dst, "audio-device", value);
 }
 
+static void aout_TimingNotify(audio_output_t *aout, vlc_tick_t system_ts,
+                              vlc_tick_t audio_ts)
+{
+    aout_RequestRetiming(aout, system_ts, audio_ts);
+}
+
 /**
  * Supply or update the current custom ("hardware") volume.
  * @param volume current custom volume
@@ -159,6 +165,7 @@ static int aout_GainNotify (audio_output_t *aout, float gain)
 }
 
 static const struct vlc_audio_output_events aout_events = {
+    aout_TimingNotify,
     aout_VolumeNotify,
     aout_MuteNotify,
     aout_PolicyNotify,
-- 
2.20.1



More information about the vlc-devel mailing list