[vlc-devel] [PATCH] pulse: always use the first date for start calculation

Thomas Guillem thomas at gllm.fr
Mon Sep 24 16:45:12 CEST 2018


Comment: OK, this is not really what we decided yesterday during VDD. This
patch feel saner than always using the last date (cf. "pulse: calculate the
start time from the last date played" on ML).
This commit results of the "starting late" branch being always called from
stream_latency_cb() with a value arround -10ms (for my case).

Regression introduced by 3b0ddde7811fa912ea061d559bb19df49810d810 that only
used the first date from stream_latency_cb() and not from Play().

---
 modules/audio_output/pulse.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 2753fb87fd..6cb11d9175 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -68,7 +68,6 @@ typedef struct
     pa_threaded_mainloop *mainloop; /**< PulseAudio thread */
     pa_time_event *trigger; /**< Deferred stream trigger */
     pa_cvolume cvolume; /**< actual sink input volume */
-    vlc_tick_t first_pts; /**< Play stream timestamp of buffer start */
     vlc_tick_t first_date; /**< Play system timestamp of buffer start */
 
     pa_volume_t volume_force; /**< Forced volume (stream must be NULL) */
@@ -222,12 +221,12 @@ static void stream_trigger_cb(pa_mainloop_api *api, pa_time_event *e,
  * in order to minimize desync and resampling during early playback.
  * @note PulseAudio lock required.
  */
-static void stream_start(pa_stream *s, audio_output_t *aout, vlc_tick_t date)
+static void stream_start(pa_stream *s, audio_output_t *aout)
 {
     aout_sys_t *sys = aout->sys;
     vlc_tick_t delta;
 
-    assert (sys->first_pts != VLC_TICK_INVALID);
+    assert (sys->first_date != VLC_TICK_INVALID);
 
     if (sys->trigger != NULL) {
         vlc_pa_rttime_free(sys->mainloop, sys->trigger);
@@ -240,7 +239,7 @@ static void stream_start(pa_stream *s, audio_output_t *aout, vlc_tick_t date)
         delta = 0; /* screwed */
     }
 
-    delta = (date - vlc_tick_now()) - delta;
+    delta = (sys->first_date - vlc_tick_now()) - delta;
     if (delta > 0) {
         msg_Dbg(aout, "deferring start (%"PRId64" us)", delta);
         delta += pa_rtclock_now();
@@ -258,10 +257,10 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
     aout_sys_t *sys = aout->sys;
 
     /* This callback is _never_ called while paused. */
-    if (sys->first_pts == VLC_TICK_INVALID)
+    if (sys->first_date == VLC_TICK_INVALID)
         return; /* nothing to do if buffers are (still) empty */
     if (pa_stream_is_corked(s) > 0)
-        stream_start(s, aout, sys->first_date);
+        stream_start(s, aout);
 }
 
 
@@ -331,7 +330,7 @@ static void stream_overflow_cb(pa_stream *s, void *userdata)
     if (unlikely(op == NULL))
         return;
     pa_operation_unref(op);
-    sys->first_pts = VLC_TICK_INVALID;
+    sys->first_date = VLC_TICK_INVALID;
 }
 
 static void stream_started_cb(pa_stream *s, void *userdata)
@@ -504,13 +503,11 @@ static void Play(audio_output_t *aout, block_t *block, vlc_tick_t date)
      * will take place, and sooner or later a deadlock. */
     pa_threaded_mainloop_lock(sys->mainloop);
 
-    if (sys->first_pts == VLC_TICK_INVALID) {
-        sys->first_pts = block->i_pts;
+    if (sys->first_date == VLC_TICK_INVALID)
         sys->first_date = date;
-    }
 
     if (pa_stream_is_corked(s) > 0)
-        stream_start(s, aout, date);
+        stream_start(s, aout);
 
 #if 0 /* Fault injector to test underrun recovery */
     static volatile unsigned u = 0;
@@ -543,7 +540,7 @@ static void Pause(audio_output_t *aout, bool paused, vlc_tick_t date)
         stream_stop(s, aout);
     } else {
         pa_stream_set_latency_update_callback(s, stream_latency_cb, aout);
-        if (likely(sys->first_pts != VLC_TICK_INVALID))
+        if (likely(sys->first_date != VLC_TICK_INVALID))
             stream_start_now(s, aout);
     }
 
@@ -576,7 +573,7 @@ static void Flush(audio_output_t *aout, bool wait)
         op = pa_stream_flush(s, NULL, NULL);
     if (op != NULL)
         pa_operation_unref(op);
-    sys->first_pts = VLC_TICK_INVALID;
+    sys->first_date = VLC_TICK_INVALID;
     stream_stop(s, aout);
 
     pa_threaded_mainloop_unlock(sys->mainloop);
@@ -807,7 +804,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 
     sys->trigger = NULL;
     pa_cvolume_init(&sys->cvolume);
-    sys->first_pts = VLC_TICK_INVALID;
+    sys->first_date = VLC_TICK_INVALID;
 
     pa_format_info *formatv = pa_format_info_new();
     formatv->encoding = encoding;
-- 
2.19.0



More information about the vlc-devel mailing list