[vlc-commits] PulseAudio: fix locking when changing device

Rémi Denis-Courmont git at videolan.org
Tue Apr 12 21:16:40 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Apr 12 22:16:24 2011 +0300| [9ddb2cef0a1bf2e3711dcb12aba0fa7dbe8e365e] | committer: Rémi Denis-Courmont

PulseAudio: fix locking when changing device

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

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

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 0f97a36..26f8679 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -50,8 +50,8 @@ vlc_module_end ()
 /* NOTE:
  * Be careful what you do when the PulseAudio mainloop is held, which is to say
  * within PulseAudio callbacks, or after pa_threaded_mainloop_lock().
- * In particular, the VLC audio output object variables can be manipulated with
- * the PulseAudio mainloop lock held, but not vice versa! */
+ * In particular, a VLC variable callback cannot be triggered nor deleted with
+ * the PulseAudio mainloop lock held, if the callback acquires the lock. */
 
 struct aout_sys_t
 {
@@ -354,16 +354,19 @@ static int StreamMove(vlc_object_t *obj, const char *varname, vlc_value_t old,
     uint32_t idx = pa_stream_get_index(s);
     uint32_t sink_idx = val.i_int;
 
+    (void) varname; (void) old;
+
+    pa_threaded_mainloop_lock(sys->mainloop);
     op = pa_context_move_sink_input_by_index(sys->context, idx, sink_idx,
                                              NULL, NULL);
-    if (unlikely(op == NULL)) {
+    if (likely(op != NULL)) {
+        pa_operation_unref(op);
+        msg_Dbg(aout, "moving to sink %"PRIu32, sink_idx);
+    } else
         error(aout, "cannot move sink", sys->context);
-        return VLC_EGENERIC;
-    }
-    pa_operation_unref(op);
-    msg_Dbg(aout, "moving to sink %"PRIu32, sink_idx);
-    (void) varname; (void) old;
-    return VLC_SUCCESS;
+    pa_threaded_mainloop_unlock(sys->mainloop);
+
+    return (op != NULL) ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
 



More information about the vlc-commits mailing list