[vlc-devel] [RFC PATCH 02/13] aout: add timing notify

Thomas Guillem thomas at gllm.fr
Wed Jun 27 14:41:24 CEST 2018


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

---
 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 5020763977..0cdbc6183d 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, vlc_tick_t);
     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 8b5ff1bf26..c3d58b8b60 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -147,6 +147,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 audio_ts,
+                          vlc_tick_t system_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 4f90c04d3c..18f51ebabb 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -227,9 +227,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,
@@ -247,9 +246,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, dec_pts - delay, now);
+}
+
+void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t audio_ts,
+                          vlc_tick_t system_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
@@ -272,11 +280,8 @@ static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
         owner->sync.end = VLC_TS_INVALID;
         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. */
@@ -286,7 +291,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 19f195eb80..e96d9031f8 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -71,6 +71,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 audio_ts,
+                              vlc_tick_t system_ts)
+{
+    aout_RequestRetiming(aout, audio_ts, system_ts);
+}
+
 /**
  * Supply or update the current custom ("hardware") volume.
  * @param volume current custom volume
@@ -160,6 +166,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.18.0



More information about the vlc-devel mailing list