]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/pulse.c
macosx: re-implemented time slider to fit the new style
[vlc] / modules / audio_output / pulse.c
index 3041a5b4d5eefaffd211c6c065caf7493c2454a6..e2ee41988a0770622a3a11ea2bd34e94354a858f 100644 (file)
@@ -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
 {
@@ -163,6 +163,10 @@ static void stream_moved_cb(pa_stream *s, void *userdata)
                                            sink_info_cb, aout);
     if (likely(op != NULL))
         pa_operation_unref(op);
+
+    /* Update the variable if someone else moved our stream */
+    var_Change(aout, "audio-device", VLC_VAR_SETVALUE,
+               &(vlc_value_t){ .i_int = idx }, NULL);
 }
 
 static void stream_overflow_cb(pa_stream *s, void *userdata)
@@ -269,7 +273,7 @@ static void Play(aout_instance_t *aout)
         if (pa_context_errno(sys->context) != PA_ERR_NODATA)
             error(aout, "cannot determine latency", sys->context);
     } else {
-        mtime_t gap = aout_FifoFirstDate(aout, &aout->output.fifo) - mdate()
+        mtime_t gap = aout_FifoFirstDate(&aout->output.fifo) - mdate()
                 - latency;
 
         if (gap > AOUT_PTS_TOLERANCE)
@@ -291,7 +295,7 @@ static void Play(aout_instance_t *aout)
      * If this function is changed to not always dequeue blocks, be sure to
      * limit the queue size to a reasonable limit to avoid huge leaks. */
     for (;;) {
-        block_t *block = aout_FifoPop(aout, &aout->output.fifo);
+        block_t *block = aout_FifoPop(&aout->output.fifo);
         if (block == NULL)
             break;
 
@@ -350,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;
 }
 
 
@@ -553,7 +560,6 @@ static int Open(vlc_object_t *obj)
         error(aout, "cannot connect stream", ctx);
         goto fail;
     }
-    stream_moved_cb(s, aout);
 
     const struct pa_buffer_attr *pba = pa_stream_get_buffer_attr(s);
     msg_Dbg(aout, "using buffer metrics: maxlength=%u, tlength=%u, "
@@ -571,6 +577,7 @@ static int Open(vlc_object_t *obj)
     /* We may need to wait for completion... once LibVLC supports this */
     if (op != NULL)
         pa_operation_unref(op);
+    stream_moved_cb(s, aout);
     pa_threaded_mainloop_unlock(mainloop);
 
     aout->output.pf_play = Play;