[vlc-devel] [RFC PATCH 5/6] pulse: implement drain

Thomas Guillem thomas at gllm.fr
Thu Mar 16 16:43:24 CET 2017


Listen to the underflow callback to know when pulse is drained.

--

I tried first to listen to drain callbacks but was not able to receive them.
See the commit here:
https://github.com/tguillem/vlc/commit/f0410e2e8ecfac67dabfd5447f33571ebe3ea533

The pa_stream_drain pa_operation is always in a running state.

Will be squashed with 4/6

---
 modules/audio_output/pulse.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index cc995efb57..abb27dc863 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <math.h>
 #include <vlc_common.h>
+#include <vlc_threads.h>
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
 #include <vlc_cpu.h>
@@ -75,6 +76,8 @@ struct aout_sys_t
     char *sink_force; /**< Forced sink name (stream must be NULL) */
 
     struct sink *sinks; /**< Locally-cached list of sinks */
+
+    bool draining;
 };
 
 static void VolumeReport(audio_output_t *aout)
@@ -352,8 +355,11 @@ static void stream_suspended_cb(pa_stream *s, void *userdata)
 static void stream_underflow_cb(pa_stream *s, void *userdata)
 {
     audio_output_t *aout = userdata;
+    aout_sys_t *sys = aout->sys;
 
-    msg_Dbg(aout, "underflow");
+    msg_Err(aout, "underflow");
+    if (sys->draining)
+        aout->event.drain_report(aout);
     (void) s;
 }
 
@@ -564,7 +570,31 @@ static void Flush(audio_output_t *aout)
     sys->first_pts = VLC_TS_INVALID;
     stream_stop(s, aout);
 
+    sys->draining = false;
+    pa_threaded_mainloop_unlock(sys->mainloop);
+}
+
+/**
+ * Drain the playback stream
+ */
+static int Drain(audio_output_t *aout)
+{
+    aout_sys_t *sys = aout->sys;
+    pa_stream *s = sys->stream;
+    pa_operation *op;
+
+    pa_threaded_mainloop_lock(sys->mainloop);
+    op = pa_stream_drain(s, NULL, NULL);
+    if (op == NULL)
+    {
+        pa_threaded_mainloop_unlock(sys->mainloop);
+        return VLC_EGENERIC;
+    }
+    pa_operation_unref(op);
+    sys->draining = true;
+
     pa_threaded_mainloop_unlock(sys->mainloop);
+    return VLC_SUCCESS;
 }
 
 static int VolumeSet(audio_output_t *aout, float vol)
@@ -955,6 +985,7 @@ static void Stop(audio_output_t *aout)
     pa_stream *s = sys->stream;
 
     pa_threaded_mainloop_lock(sys->mainloop);
+    sys->draining = false;
     if (unlikely(sys->trigger != NULL))
         vlc_pa_rttime_free(sys->mainloop, sys->trigger);
     pa_stream_disconnect(s);
@@ -997,6 +1028,7 @@ static int Open(vlc_object_t *obj)
     sys->flags_force = PA_STREAM_NOFLAGS;
     sys->sink_force = NULL;
     sys->sinks = NULL;
+    sys->draining = false;
 
     aout->sys = sys;
     aout->start = Start;
@@ -1005,6 +1037,7 @@ static int Open(vlc_object_t *obj)
     aout->play = Play;
     aout->pause = Pause;
     aout->flush = Flush;
+    aout->drain = Drain;
     aout->volume_set = VolumeSet;
     aout->mute_set = MuteSet;
     aout->device_select = StreamMove;
-- 
2.11.0



More information about the vlc-devel mailing list