[vlc-commits] PulseAudio: Properly cork/uncork streams on pause/resume.

Colin Guthrie git at videolan.org
Thu Jul 14 21:17:36 CEST 2011


vlc | branch: master | Colin Guthrie <colin at mageia.org> | Thu Jun  2 22:08:49 2011 +0200| [10a1ac82693789c1506c0172a0f835e5d12864b7] | committer: Rémi Denis-Courmont

PulseAudio: Properly cork/uncork streams on pause/resume.

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=10a1ac82693789c1506c0172a0f835e5d12864b7
---

 modules/audio_output/pulse.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 1e1c0f0..0598327 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -252,7 +252,7 @@ static void Play(aout_instance_t *aout)
      * will take place, and sooner or later a deadlock. */
     pa_threaded_mainloop_lock(sys->mainloop);
 
-    if (pa_stream_is_corked(sys->stream) > 0) {
+    if (pa_stream_is_corked(s) > 0) {
         pa_operation *op = pa_stream_cork(s, 0, NULL, NULL);
         if (op != NULL)
             pa_operation_unref(op);
@@ -316,6 +316,25 @@ static void Play(aout_instance_t *aout)
     pa_threaded_mainloop_unlock(sys->mainloop);
 }
 
+static void Pause(aout_instance_t *aout, bool b_paused, mtime_t i_date)
+{
+    aout_sys_t *sys = aout->output.p_sys;
+    pa_stream *s = sys->stream;
+
+    /* Note: The core already holds the output FIFO lock at this point.
+     * Therefore we must not under any circumstances (try to) acquire the
+     * output FIFO lock while the PulseAudio threaded main loop lock is held
+     * (including from PulseAudio stream callbacks). Otherwise lock inversion
+     * will take place, and sooner or later a deadlock. */
+    pa_threaded_mainloop_lock(sys->mainloop);
+
+    pa_operation *op = pa_stream_cork(s, b_paused ? 1 : 0, NULL, NULL);
+    if (op != NULL)
+        pa_operation_unref(op);
+
+    pa_threaded_mainloop_unlock(sys->mainloop);
+}
+
 static int VolumeSet(aout_instance_t *aout, audio_volume_t vol, bool mute)
 {
     aout_sys_t *sys = aout->output.p_sys;
@@ -581,7 +600,7 @@ static int Open(vlc_object_t *obj)
     pa_threaded_mainloop_unlock(mainloop);
 
     aout->output.pf_play = Play;
-    aout->output.pf_pause = NULL;
+    aout->output.pf_pause = Pause;
     aout->output.pf_volume_set = VolumeSet;
     return VLC_SUCCESS;
 



More information about the vlc-commits mailing list