1 /*****************************************************************************
2 * pulse.c : Pulseaudio output plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
5 * Copyright (C) 2009-2011 RĂ©mi Denis-Courmont
7 * Authors: Martin Hamrle <hamrle @ post . cz>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
34 #include <pulse/pulseaudio.h>
35 #include <vlc_pulse.h>
36 #if !PA_CHECK_VERSION(0,9,22)
37 # include <vlc_xlib.h>
40 static int Open ( vlc_object_t * );
41 static void Close ( vlc_object_t * );
44 set_shortname( "PulseAudio" )
45 set_description( N_("Pulseaudio audio output") )
46 set_capability( "audio output", 160 )
47 set_category( CAT_AUDIO )
48 set_subcategory( SUBCAT_AUDIO_AOUT )
49 add_shortcut( "pulseaudio", "pa" )
50 set_callbacks( Open, Close )
54 * - pause input on policy event
55 * - resample to compensate for long term drift
56 * - select music or video stream property correctly (?)
57 * - set further appropriate stream properties
58 * - update output devices list dynamically
62 * Be careful what you do when the PulseAudio mainloop is held, which is to say
63 * within PulseAudio callbacks, or after vlc_pa_lock().
64 * In particular, a VLC variable callback cannot be triggered nor deleted with
65 * the PulseAudio mainloop lock held, if the callback acquires the lock. */
69 pa_stream *stream; /**< PulseAudio playback stream object */
70 pa_context *context; /**< PulseAudio connection context */
71 pa_time_event *trigger; /**< Deferred stream trigger */
72 pa_volume_t base_volume; /**< 0dB reference volume */
73 pa_cvolume cvolume; /**< actual sink input volume */
74 mtime_t paused; /**< Time when (last) paused */
75 mtime_t pts; /**< Play time of buffer write offset */
76 mtime_t desync; /**< Measured desynchronization */
77 unsigned rate; /**< Current stream sample rate */
80 static void sink_input_info_cb(pa_context *, const pa_sink_input_info *,
84 static void context_cb(pa_context *ctx, pa_subscription_event_type_t type,
85 uint32_t idx, void *userdata)
87 audio_output_t *aout = userdata;
88 aout_sys_t *sys = aout->sys;
91 switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK)
93 case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
94 if (idx != pa_stream_get_index(sys->stream))
95 break; /* only interested in our sink input */
97 /* Gee... PA will not provide the infos directly in the event. */
98 switch (type & PA_SUBSCRIPTION_EVENT_TYPE_MASK)
100 case PA_SUBSCRIPTION_EVENT_REMOVE:
101 msg_Err(aout, "sink input killed!");
105 op = pa_context_get_sink_input_info(ctx, idx, sink_input_info_cb,
107 if (likely(op != NULL))
108 pa_operation_unref(op);
113 default: /* unsubscribed facility?! */
120 static void sink_list_cb(pa_context *c, const pa_sink_info *i, int eol,
123 audio_output_t *aout = userdata;
124 vlc_value_t val, text;
130 msg_Dbg(aout, "listing sink %s (%"PRIu32"): %s", i->name, i->index,
132 val.i_int = i->index;
133 text.psz_string = (char *)i->description;
134 var_Change(aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text);
137 static void sink_info_cb(pa_context *c, const pa_sink_info *i, int eol,
140 audio_output_t *aout = userdata;
141 aout_sys_t *sys = aout->sys;
147 /* PulseAudio flat volume NORM / 100% / 0dB corresponds to no software
148 * amplification and maximum hardware amplification.
149 * VLC maps DEFAULT / 100% to no gain at all (software/hardware).
150 * Thus we need to use the sink base_volume as a multiplier,
151 * if and only if flat volume is active for our current sink. */
152 if (i->flags & PA_SINK_FLAT_VOLUME)
153 sys->base_volume = i->base_volume;
155 sys->base_volume = PA_VOLUME_NORM;
156 msg_Dbg(aout, "base volume: %"PRIu32, sys->base_volume);
160 /*** Latency management and lip synchronization ***/
161 static mtime_t vlc_pa_get_latency(audio_output_t *aout,
162 pa_context *ctx, pa_stream *s)
167 if (pa_stream_get_latency(s, &latency, &negative)) {
168 if (pa_context_errno (ctx) != PA_ERR_NODATA)
169 vlc_pa_error(aout, "unknown latency", ctx);
170 return VLC_TS_INVALID;
172 return negative ? -latency : +latency;
175 static void stream_reset_sync(pa_stream *s, audio_output_t *aout)
177 aout_sys_t *sys = aout->sys;
178 const unsigned rate = aout->format.i_rate;
180 sys->pts = VLC_TS_INVALID;
182 pa_operation *op = pa_stream_update_sample_rate(s, rate, NULL, NULL);
183 if (unlikely(op == NULL))
185 pa_operation_unref(op);
189 static void stream_start(pa_stream *s, audio_output_t *aout)
191 aout_sys_t *sys = aout->sys;
194 if (sys->trigger != NULL) {
195 vlc_pa_rttime_free(sys->trigger);
199 op = pa_stream_cork(s, 0, NULL, NULL);
201 pa_operation_unref(op);
202 op = pa_stream_trigger(s, NULL, NULL);
203 if (likely(op != NULL))
204 pa_operation_unref(op);
207 static void stream_stop(pa_stream *s, audio_output_t *aout)
209 aout_sys_t *sys = aout->sys;
212 if (sys->trigger != NULL) {
213 vlc_pa_rttime_free(sys->trigger);
217 op = pa_stream_cork(s, 1, NULL, NULL);
219 pa_operation_unref(op);
222 static void stream_trigger_cb(pa_mainloop_api *api, pa_time_event *e,
223 const struct timeval *tv, void *userdata)
225 audio_output_t *aout = userdata;
226 aout_sys_t *sys = aout->sys;
228 msg_Dbg(aout, "starting deferred");
229 assert (sys->trigger == e);
230 stream_start(sys->stream, aout);
231 (void) api; (void) e; (void) tv;
235 * Starts or resumes the playback stream.
236 * Tries start playing back audio samples at the most accurate time
237 * in order to minimize desync and resampling during early playback.
238 * @note PulseAudio lock required.
240 static void stream_resync(audio_output_t *aout, pa_stream *s)
242 aout_sys_t *sys = aout->sys;
245 assert (pa_stream_is_corked(s) > 0);
246 assert (sys->pts != VLC_TS_INVALID);
248 delta = vlc_pa_get_latency(aout, sys->context, s);
249 if (unlikely(delta == VLC_TS_INVALID))
250 delta = 0; /* screwed */
252 delta = (sys->pts - mdate()) - delta;
254 if (sys->trigger == NULL) {
255 msg_Dbg(aout, "deferring start (%"PRId64" us)", delta);
256 delta += pa_rtclock_now();
257 sys->trigger = pa_context_rttime_new(sys->context, delta,
258 stream_trigger_cb, aout);
261 msg_Warn(aout, "starting late (%"PRId64" us)", delta);
262 stream_start(s, aout);
266 static void stream_latency_cb(pa_stream *s, void *userdata)
268 audio_output_t *aout = userdata;
269 aout_sys_t *sys = aout->sys;
270 mtime_t delta, change;
272 if (pa_stream_is_corked(s))
274 if (sys->pts == VLC_TS_INVALID)
276 msg_Dbg(aout, "missing latency from input");
280 /* Compute lip desynchronization */
281 delta = vlc_pa_get_latency(aout, sys->context, s);
282 if (delta == VLC_TS_INVALID)
285 delta = (sys->pts - mdate()) - delta;
286 change = delta - sys->desync;
288 //msg_Dbg(aout, "desync: %+"PRId64" us (variation: %+"PRId64" us)",
291 const unsigned inrate = aout->format.i_rate;
292 unsigned outrate = sys->rate;
295 if (delta < -AOUT_MAX_PTS_DELAY)
296 msg_Warn(aout, "too late by %"PRId64" us", -delta);
297 else if (delta > +AOUT_MAX_PTS_ADVANCE)
298 msg_Warn(aout, "too early by %"PRId64" us", delta);
299 else if (outrate == inrate)
300 return; /* In sync, do not add unnecessary disturbance! */
304 /* Compute playback sample rate */
305 /* This is empirical (especially the shift values).
306 * Feel free to define something smarter. */
307 int adj = sync ? (outrate - inrate)
308 : outrate * ((delta >> 4) + change) / (CLOCK_FREQ << 2);
309 /* This avoids too quick rate variation. It sounds really bad and
310 * causes unstability (e.g. oscillation around the correct rate). */
311 int limit = inrate >> 10;
312 /* However, to improve stability and try to converge, closing to the
313 * nominal rate is favored over drifting from it. */
314 if ((adj > 0) == (sys->rate > inrate))
322 /* This keeps the effective rate within specified range
323 * (+/-AOUT_MAX_RESAMPLING% - see <vlc_aout.h>) of the nominal rate. */
324 limit = inrate * AOUT_MAX_RESAMPLING / 100;
325 if (outrate > inrate + limit)
326 outrate = inrate + limit;
327 if (outrate < inrate - limit)
328 outrate = inrate - limit;
330 /* Apply adjusted sample rate */
331 if (outrate == sys->rate)
333 pa_operation *op = pa_stream_update_sample_rate(s, outrate, NULL, NULL);
334 if (unlikely(op == NULL)) {
335 vlc_pa_error(aout, "cannot change sample rate", sys->context);
338 pa_operation_unref(op);
339 msg_Dbg(aout, "changed sample rate to %u Hz",outrate);
344 /*** Stream helpers ***/
345 static void stream_state_cb(pa_stream *s, void *userdata)
347 switch (pa_stream_get_state(s)) {
348 case PA_STREAM_READY:
349 case PA_STREAM_FAILED:
350 case PA_STREAM_TERMINATED:
358 static void stream_moved_cb(pa_stream *s, void *userdata)
360 audio_output_t *aout = userdata;
361 aout_sys_t *sys = aout->sys;
363 uint32_t idx = pa_stream_get_device_index(s);
365 msg_Dbg(aout, "connected to sink %"PRIu32": %s", idx,
366 pa_stream_get_device_name(s));
367 op = pa_context_get_sink_info_by_index(sys->context, idx,
369 if (likely(op != NULL))
370 pa_operation_unref(op);
372 /* Update the variable if someone else moved our stream */
373 var_Change(aout, "audio-device", VLC_VAR_SETVALUE,
374 &(vlc_value_t){ .i_int = idx }, NULL);
377 static void stream_overflow_cb(pa_stream *s, void *userdata)
379 audio_output_t *aout = userdata;
381 msg_Err(aout, "overflow");
385 static void stream_started_cb(pa_stream *s, void *userdata)
387 audio_output_t *aout = userdata;
389 msg_Dbg(aout, "started");
393 static void stream_suspended_cb(pa_stream *s, void *userdata)
395 audio_output_t *aout = userdata;
397 msg_Dbg(aout, "suspended");
398 stream_reset_sync(s, aout);
401 static void stream_underflow_cb(pa_stream *s, void *userdata)
403 audio_output_t *aout = userdata;
405 msg_Warn(aout, "underflow");
406 stream_stop(s, aout);
407 stream_reset_sync(s, aout);
410 static int stream_wait(pa_stream *stream)
412 pa_stream_state_t state;
414 while ((state = pa_stream_get_state(stream)) != PA_STREAM_READY) {
415 if (state == PA_STREAM_FAILED || state == PA_STREAM_TERMINATED)
424 static void sink_input_info_cb(pa_context *ctx, const pa_sink_input_info *i,
425 int eol, void *userdata)
427 audio_output_t *aout = userdata;
428 aout_sys_t *sys = aout->sys;
435 sys->cvolume = i->volume;
436 volume = pa_cvolume_max(&i->volume) / (float)PA_VOLUME_NORM;
437 aout_VolumeHardSet(aout, volume, i->mute);
441 /*** VLC audio output callbacks ***/
443 /* Memory free callback. The block_t address is in front of the data. */
444 static void data_free(void *data)
446 block_t **pp = data, *block;
448 memcpy(&block, pp - 1, sizeof (block));
449 block_Release(block);
452 static void *data_convert(block_t **pp)
454 block_t *block = *pp;
455 /* In most cases, there is enough head room, and this is really cheap: */
456 block = block_Realloc(block, sizeof (block), block->i_buffer);
458 if (unlikely(block == NULL))
461 memcpy(block->p_buffer, &block, sizeof (block));
462 block->p_buffer += sizeof (block);
463 block->i_buffer -= sizeof (block);
464 return block->p_buffer;
468 * Queue one audio frame to the playabck stream
470 static void Play(audio_output_t *aout, block_t *block)
472 aout_sys_t *sys = aout->sys;
473 pa_stream *s = sys->stream;
475 const void *ptr = data_convert(&block);
476 if (unlikely(ptr == NULL))
479 size_t len = block->i_buffer;
480 mtime_t pts = block->i_pts + block->i_length;
482 /* Note: The core already holds the output FIFO lock at this point.
483 * Therefore we must not under any circumstances (try to) acquire the
484 * output FIFO lock while the PulseAudio threaded main loop lock is held
485 * (including from PulseAudio stream callbacks). Otherwise lock inversion
486 * will take place, and sooner or later a deadlock. */
490 if (pa_stream_is_corked(s) > 0)
491 stream_resync(aout, s);
493 #if 0 /* Fault injector to test underrun recovery */
494 static volatile unsigned u = 0;
495 if ((++u % 1000) == 0) {
496 msg_Err(aout, "fault injection");
497 pa_operation_unref(pa_stream_flush(s, NULL, NULL));
501 if (pa_stream_write(s, ptr, len, data_free, 0, PA_SEEK_RELATIVE) < 0) {
502 vlc_pa_error(aout, "cannot write", sys->context);
503 block_Release(block);
510 * Cork or uncork the playback stream
512 static void Pause(audio_output_t *aout, bool paused, mtime_t date)
514 aout_sys_t *sys = aout->sys;
515 pa_stream *s = sys->stream;
521 stream_stop(s, aout);
523 assert (sys->paused != VLC_TS_INVALID);
525 msg_Dbg(aout, "resuming after %"PRId64" us", date);
526 sys->paused = VLC_TS_INVALID;
528 stream_resync(aout, s);
535 * Flush or drain the playback stream
537 static void Flush(audio_output_t *aout, bool wait)
539 aout_sys_t *sys = aout->sys;
540 pa_stream *s = sys->stream;
546 op = pa_stream_drain(s, NULL, NULL);
547 /* TODO: wait for drain completion*/
549 op = pa_stream_flush(s, NULL, NULL);
551 pa_operation_unref(op);
555 static int VolumeSet(audio_output_t *aout, float vol, bool mute)
557 aout_sys_t *sys = aout->sys;
559 uint32_t idx = pa_stream_get_index(sys->stream);
561 pa_cvolume cvolume = sys->cvolume;
562 pa_volume_t volume = sys->base_volume;
564 pa_cvolume_scale(&cvolume, PA_VOLUME_NORM); /* preserve balance */
566 /* VLC provides the software volume so convert directly to PulseAudio
567 * software volume, pa_volume_t. This is not a linear amplification factor
568 * so do not use PulseAudio linear amplification! */
569 vol *= PA_VOLUME_NORM;
570 if (unlikely(vol >= PA_VOLUME_MAX))
572 volume = pa_sw_volume_multiply(volume, lround(vol));
573 pa_sw_cvolume_multiply_scalar(&cvolume, &cvolume, volume);
575 assert(pa_cvolume_valid(&cvolume));
578 op = pa_context_set_sink_input_volume(sys->context, idx, &cvolume, NULL, NULL);
579 if (likely(op != NULL))
580 pa_operation_unref(op);
581 op = pa_context_set_sink_input_mute(sys->context, idx, mute, NULL, NULL);
582 if (likely(op != NULL))
583 pa_operation_unref(op);
589 static int StreamMove(vlc_object_t *obj, const char *varname, vlc_value_t old,
590 vlc_value_t val, void *userdata)
592 audio_output_t *aout = (audio_output_t *)obj;
593 aout_sys_t *sys = aout->sys;
594 pa_stream *s = userdata;
596 uint32_t idx = pa_stream_get_index(s);
597 uint32_t sink_idx = val.i_int;
599 (void) varname; (void) old;
602 op = pa_context_move_sink_input_by_index(sys->context, idx, sink_idx,
604 if (likely(op != NULL)) {
605 pa_operation_unref(op);
606 msg_Dbg(aout, "moving to sink %"PRIu32, sink_idx);
608 vlc_pa_error(obj, "cannot move sink", sys->context);
611 return (op != NULL) ? VLC_SUCCESS : VLC_EGENERIC;
616 * Create a PulseAudio playback stream, a.k.a. a sink input.
618 static int Open(vlc_object_t *obj)
620 #if !PA_CHECK_VERSION(0,9,22)
621 if (!vlc_xlib_init(obj))
625 audio_output_t *aout = (audio_output_t *)obj;
628 /* Sample format specification */
629 struct pa_sample_spec ss;
630 vlc_fourcc_t format = aout->format.i_format;
635 format = VLC_CODEC_F32B;
637 ss.format = PA_SAMPLE_FLOAT32BE;
640 format = VLC_CODEC_F32L;
642 ss.format = PA_SAMPLE_FLOAT32LE;
645 format = VLC_CODEC_FL32;
646 ss.format = PA_SAMPLE_FLOAT32NE;
649 ss.format = PA_SAMPLE_S32BE;
652 ss.format = PA_SAMPLE_S32LE;
655 ss.format = PA_SAMPLE_S24BE;
658 ss.format = PA_SAMPLE_S24LE;
661 ss.format = PA_SAMPLE_S16BE;
664 ss.format = PA_SAMPLE_S16LE;
667 format = VLC_CODEC_U8;
669 ss.format = PA_SAMPLE_U8;
674 format = VLC_CODEC_FL32;
675 ss.format = PA_SAMPLE_FLOAT32NE;
679 format = VLC_CODEC_S16N;
680 ss.format = PA_SAMPLE_S16NE;
685 ss.rate = aout->format.i_rate;
686 ss.channels = aout_FormatNbChannels(&aout->format);
687 if (!pa_sample_spec_valid(&ss)) {
688 msg_Err(aout, "unsupported sample specification");
692 /* Channel mapping (order defined in vlc_aout.h) */
693 struct pa_channel_map map;
696 if (aout->format.i_physical_channels & AOUT_CHAN_LEFT)
697 map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_LEFT;
698 if (aout->format.i_physical_channels & AOUT_CHAN_RIGHT)
699 map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT;
700 if (aout->format.i_physical_channels & AOUT_CHAN_MIDDLELEFT)
701 map.map[map.channels++] = PA_CHANNEL_POSITION_SIDE_LEFT;
702 if (aout->format.i_physical_channels & AOUT_CHAN_MIDDLERIGHT)
703 map.map[map.channels++] = PA_CHANNEL_POSITION_SIDE_RIGHT;
704 if (aout->format.i_physical_channels & AOUT_CHAN_REARLEFT)
705 map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_LEFT;
706 if (aout->format.i_physical_channels & AOUT_CHAN_REARRIGHT)
707 map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_RIGHT;
708 if (aout->format.i_physical_channels & AOUT_CHAN_REARCENTER)
709 map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_CENTER;
710 if (aout->format.i_physical_channels & AOUT_CHAN_CENTER)
712 if (ss.channels == 1)
713 map.map[map.channels++] = PA_CHANNEL_POSITION_MONO;
715 map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_CENTER;
717 if (aout->format.i_physical_channels & AOUT_CHAN_LFE)
718 map.map[map.channels++] = PA_CHANNEL_POSITION_LFE;
720 for (unsigned i = 0; map.channels < ss.channels; i++) {
721 map.map[map.channels++] = PA_CHANNEL_POSITION_AUX0 + i;
722 msg_Warn(aout, "mapping channel %"PRIu8" to AUX%u", map.channels, i);
725 if (!pa_channel_map_valid(&map)) {
726 msg_Err(aout, "unsupported channel map");
729 const char *name = pa_channel_map_to_name(&map);
730 msg_Dbg(aout, "using %s channel map", (name != NULL) ? name : "?");
733 /* Stream parameters */
734 const pa_stream_flags_t flags = PA_STREAM_START_CORKED
735 //| PA_STREAM_INTERPOLATE_TIMING
736 | PA_STREAM_AUTO_TIMING_UPDATE
737 | PA_STREAM_VARIABLE_RATE;
739 struct pa_buffer_attr attr;
741 /* PulseAudio assumes that tlength bytes are available in the buffer. Thus
742 * we need to be conservative and set the minimum value that the VLC
743 * audio decoder thread warrants. Otherwise, PulseAudio buffers will
744 * underrun on hardware with large buffers. VLC keeps at least
745 * AOUT_MIN_PREPARE and at most AOUT_MAX_PREPARE worth of audio buffers.
746 * TODO? tlength could be adaptively increased to reduce wakeups. */
747 attr.tlength = pa_usec_to_bytes(AOUT_MIN_PREPARE_TIME, &ss);
748 attr.prebuf = 0; /* trigger manually */
750 attr.fragsize = 0; /* not used for output */
752 /* Allocate structures */
753 aout_sys_t *sys = malloc(sizeof(*sys));
754 if (unlikely(sys == NULL))
757 pa_context *ctx = vlc_pa_connect (obj);
768 sys->paused = VLC_TS_INVALID;
769 sys->pts = VLC_TS_INVALID;
774 const pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK_INPUT;
776 pa_context_set_subscribe_callback(ctx, context_cb, aout);
777 op = pa_context_subscribe(ctx, mask, NULL, NULL);
778 if (likely(op != NULL))
779 pa_operation_unref(op);
782 sys->base_volume = PA_VOLUME_NORM;
783 pa_cvolume_set(&sys->cvolume, ss.channels, PA_VOLUME_NORM);
786 /* Create a playback stream */
787 pa_stream *s = pa_stream_new(ctx, "audio stream", &ss, &map);
789 vlc_pa_error(obj, "stream creation failure", ctx);
793 pa_stream_set_state_callback(s, stream_state_cb, NULL);
794 pa_stream_set_latency_update_callback(s, stream_latency_cb, aout);
795 pa_stream_set_moved_callback(s, stream_moved_cb, aout);
796 pa_stream_set_overflow_callback(s, stream_overflow_cb, aout);
797 pa_stream_set_started_callback(s, stream_started_cb, aout);
798 pa_stream_set_suspended_callback(s, stream_suspended_cb, aout);
799 pa_stream_set_underflow_callback(s, stream_underflow_cb, aout);
801 if (pa_stream_connect_playback(s, NULL, &attr, flags, NULL, NULL) < 0
803 vlc_pa_error(obj, "stream connection failure", ctx);
807 const struct pa_buffer_attr *pba = pa_stream_get_buffer_attr(s);
808 msg_Dbg(aout, "using buffer metrics: maxlength=%u, tlength=%u, "
809 "prebuf=%u, minreq=%u",
810 pba->maxlength, pba->tlength, pba->prebuf, pba->minreq);
812 var_Create(aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE);
813 var_Change(aout, "audio-device", VLC_VAR_SETTEXT,
814 &(vlc_value_t){ .psz_string = (char *)_("Audio device") },
816 var_AddCallback (aout, "audio-device", StreamMove, s);
817 op = pa_context_get_sink_info_list(ctx, sink_list_cb, aout);
818 /* We may need to wait for completion... once LibVLC supports this */
820 pa_operation_unref(op);
821 stream_moved_cb(s, aout);
824 aout->format.i_format = format;
825 aout->pf_play = Play;
826 aout->pf_pause = Pause;
827 aout->pf_flush = Flush;
828 aout_VolumeHardInit (aout, VolumeSet);
838 * Removes a PulseAudio playback stream
840 static void Close (vlc_object_t *obj)
842 audio_output_t *aout = (audio_output_t *)obj;
843 aout_sys_t *sys = aout->sys;
844 pa_context *ctx = sys->context;
845 pa_stream *s = sys->stream;
848 /* The callback takes mainloop lock, so it CANNOT be held here! */
849 var_DelCallback (aout, "audio-device", StreamMove, s);
850 var_Destroy (aout, "audio-device");
853 if (unlikely(sys->trigger != NULL))
854 vlc_pa_rttime_free(sys->trigger);
855 pa_stream_disconnect(s);
857 /* Clear all callbacks */
858 pa_stream_set_state_callback(s, NULL, NULL);
859 pa_stream_set_latency_update_callback(s, NULL, NULL);
860 pa_stream_set_moved_callback(s, NULL, NULL);
861 pa_stream_set_overflow_callback(s, NULL, NULL);
862 pa_stream_set_started_callback(s, NULL, NULL);
863 pa_stream_set_suspended_callback(s, NULL, NULL);
864 pa_stream_set_underflow_callback(s, NULL, NULL);
870 vlc_pa_disconnect(obj, ctx);