4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #ifdef HAVE_SYS_POLL_H
37 #include <asoundlib.h>
39 #include <pulse/xmalloc.h>
40 #include <pulse/util.h>
42 #include <pulsecore/core.h>
43 #include <pulsecore/module.h>
44 #include <pulsecore/memchunk.h>
45 #include <pulsecore/sink.h>
46 #include <pulsecore/modargs.h>
47 #include <pulsecore/core-util.h>
48 #include <pulsecore/sample-util.h>
49 #include <pulsecore/log.h>
50 #include <pulsecore/macro.h>
51 #include <pulsecore/thread.h>
52 #include <pulsecore/core-error.h>
54 #include "alsa-util.h"
55 #include "module-alsa-sink-symdef.h"
57 PA_MODULE_AUTHOR("Lennart Poettering")
58 PA_MODULE_DESCRIPTION("ALSA Sink")
59 PA_MODULE_VERSION(PACKAGE_VERSION
)
61 "sink_name=<name for the sink> "
62 "device=<ALSA device> "
63 "format=<sample format> "
64 "channels=<number of channels> "
66 "fragments=<number of fragments> "
67 "fragment_size=<fragment size> "
68 "channel_map=<channel map> "
69 "mmap=<enable memory mapping?>")
71 #define DEFAULT_DEVICE "default"
73 #define DEFAULT_NFRAGS 4
74 #define DEFAULT_FRAGSIZE_MSEC 25
81 pa_asyncmsgq
*asyncmsgq
;
83 snd_pcm_t
*pcm_handle
;
85 pa_alsa_fdlist
*mixer_fdl
;
86 snd_mixer_t
*mixer_handle
;
87 snd_mixer_elem_t
*mixer_elem
;
88 long hw_volume_max
, hw_volume_min
;
90 size_t frame_size
, fragment_size
, hwbuf_size
;
100 struct pollfd
*pollfd
;
109 static const char* const valid_modargs
[] = {
122 static int mmap_write(struct userdata
*u
) {
125 const snd_pcm_channel_area_t
*areas
;
126 snd_pcm_uframes_t offset
, frames
;
136 if ((n
= snd_pcm_avail_update(u
->pcm_handle
)) < 0) {
139 pa_log_debug("snd_pcm_avail_update: Buffer underrun!");
143 if ((err
= snd_pcm_recover(u
->pcm_handle
, n
, 1)) == 0)
149 pa_log("snd_pcm_avail_update: %s", snd_strerror(n
));
153 /* pa_log("Got request for %i samples", (int) n); */
160 if ((err
= snd_pcm_mmap_begin(u
->pcm_handle
, &areas
, &offset
, &frames
)) < 0) {
163 pa_log_debug("snd_pcm_mmap_begin: Buffer underrun!");
167 if ((err
= snd_pcm_recover(u
->pcm_handle
, err
, 1)) == 0)
173 pa_log("Failed to write data to DSP: %s", snd_strerror(err
));
177 /* Check these are multiples of 8 bit */
178 pa_assert((areas
[0].first
& 7) == 0);
179 pa_assert((areas
[0].step
& 7)== 0);
181 /* We assume a single interleaved memory buffer */
182 pa_assert((areas
[0].first
>> 3) == 0);
183 pa_assert((areas
[0].step
>> 3) == u
->frame_size
);
185 p
= (uint8_t*) areas
[0].addr
+ (offset
* u
->frame_size
);
187 chunk
.memblock
= pa_memblock_new_fixed(u
->core
->mempool
, p
, frames
* u
->frame_size
, 1);
188 chunk
.length
= pa_memblock_get_length(chunk
.memblock
);
191 pa_sink_render_into_full(u
->sink
, &chunk
);
193 /* FIXME: Maybe we can do something to keep this memory block
194 * a little bit longer around? */
195 pa_memblock_unref_fixed(chunk
.memblock
);
197 if ((err
= snd_pcm_mmap_commit(u
->pcm_handle
, offset
, frames
)) < 0) {
200 pa_log_debug("snd_pcm_mmap_commit: Buffer underrun!");
204 if ((err
= snd_pcm_recover(u
->pcm_handle
, err
, 1)) == 0)
210 pa_log("Failed to write data to DSP: %s", snd_strerror(err
));
216 /* pa_log("wrote %i samples", (int) frames); */
220 static pa_usec_t
sink_get_latency(struct userdata
*u
) {
222 snd_pcm_sframes_t frames
= 0;
227 snd_pcm_avail_update(u
->pcm_handle
);
229 if ((err
= snd_pcm_delay(u
->pcm_handle
, &frames
)) < 0) {
230 pa_log("Failed to get delay: %s", snd_strerror(err
));
235 r
= pa_bytes_to_usec(frames
* u
->frame_size
, &u
->sink
->sample_spec
);
237 if (u
->memchunk
.memblock
)
238 r
+= pa_bytes_to_usec(u
->memchunk
.length
, &u
->sink
->sample_spec
);
243 static int build_pollfd(struct userdata
*u
) {
247 pa_assert(u
->pcm_handle
);
249 if ((u
->n_alsa_fds
= snd_pcm_poll_descriptors_count(u
->pcm_handle
)) < 0) {
250 pa_log("snd_pcm_poll_descriptors_count() failed: %s", snd_strerror(u
->n_alsa_fds
));
255 u
->pollfd
= pa_xnew0(struct pollfd
, POLLFD_ALSA_BASE
+ u
->n_alsa_fds
);
257 u
->pollfd
[POLLFD_ASYNCQ
].fd
= pa_asyncmsgq_get_fd(u
->asyncmsgq
);
258 u
->pollfd
[POLLFD_ASYNCQ
].events
= POLLIN
;
260 if ((err
= snd_pcm_poll_descriptors(u
->pcm_handle
, u
->pollfd
+POLLFD_ALSA_BASE
, u
->n_alsa_fds
)) < 0) {
261 pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err
));
268 static int suspend(struct userdata
*u
) {
270 pa_assert(u
->pcm_handle
);
272 snd_pcm_drain(u
->pcm_handle
); /* Let's suspend */
273 snd_pcm_close(u
->pcm_handle
);
274 u
->pcm_handle
= NULL
;
276 pa_log_debug("Device suspended...");
281 static int unsuspend(struct userdata
*u
) {
285 snd_pcm_uframes_t period_size
;
288 pa_assert(!u
->pcm_handle
);
290 pa_log_debug("Trying resume...");
292 snd_config_update_free_global();
293 if ((err
= snd_pcm_open(&u
->pcm_handle
, u
->device_name
, SND_PCM_STREAM_PLAYBACK
, SND_PCM_NONBLOCK
)) < 0) {
294 pa_log("Error opening PCM device %s: %s", u
->device_name
, snd_strerror(err
));
298 ss
= u
->sink
->sample_spec
;
299 nfrags
= u
->nfragments
;
300 period_size
= u
->fragment_size
/ u
->frame_size
;
303 if ((err
= pa_alsa_set_hw_params(u
->pcm_handle
, &ss
, &nfrags
, &period_size
, &b
)) < 0) {
304 pa_log("Failed to set hardware parameters: %s", snd_strerror(err
));
308 if (b
!= u
->use_mmap
) {
309 pa_log_warn("Resume failed, couldn't get original access mode.");
313 if (!pa_sample_spec_equal(&ss
, &u
->sink
->sample_spec
)) {
314 pa_log_warn("Resume failed, couldn't restore original sample settings.");
318 if (nfrags
!= u
->nfragments
|| period_size
*u
->frame_size
!= u
->fragment_size
) {
319 pa_log_warn("Resume failed, couldn't restore original fragment settings.");
323 if ((err
= pa_alsa_set_sw_params(u
->pcm_handle
)) < 0) {
324 pa_log("Failed to set software parameters: %s", snd_strerror(err
));
328 if (build_pollfd(u
) < 0)
331 /* FIXME: We need to reload the volume somehow */
335 pa_log_debug("Resumed successfully...");
340 snd_pcm_close(u
->pcm_handle
);
341 u
->pcm_handle
= NULL
;
346 static int sink_process_msg(pa_msgobject
*o
, int code
, void *data
, int64_t offset
, pa_memchunk
*chunk
) {
347 struct userdata
*u
= PA_SINK(o
)->userdata
;
351 case PA_SINK_MESSAGE_GET_LATENCY
: {
355 r
= sink_get_latency(u
);
357 *((pa_usec_t
*) data
) = r
;
362 case PA_SINK_MESSAGE_SET_STATE
:
364 switch ((pa_sink_state_t
) PA_PTR_TO_UINT(data
)) {
366 case PA_SINK_SUSPENDED
:
367 pa_assert(PA_SINK_OPENED(u
->sink
->thread_info
.state
));
375 case PA_SINK_RUNNING
:
377 if (u
->sink
->thread_info
.state
== PA_SINK_SUSPENDED
) {
378 if (unsuspend(u
) < 0)
384 case PA_SINK_DISCONNECTED
:
391 return pa_sink_process_msg(o
, code
, data
, offset
, chunk
);
394 static int mixer_callback(snd_mixer_elem_t
*elem
, unsigned int mask
) {
395 struct userdata
*u
= snd_mixer_elem_get_callback_private(elem
);
398 pa_assert(u
->mixer_handle
);
400 if (mask
== SND_CTL_EVENT_MASK_REMOVE
)
403 if (mask
& SND_CTL_EVENT_MASK_VALUE
) {
404 pa_sink_get_volume(u
->sink
);
405 pa_sink_get_mute(u
->sink
);
411 static int sink_get_volume_cb(pa_sink
*s
) {
412 struct userdata
*u
= s
->userdata
;
417 pa_assert(u
->mixer_elem
);
419 for (i
= 0; i
< s
->sample_spec
.channels
; i
++) {
422 pa_assert(snd_mixer_selem_has_playback_channel(u
->mixer_elem
, i
));
424 if ((err
= snd_mixer_selem_get_playback_volume(u
->mixer_elem
, i
, &vol
)) < 0)
427 set_vol
= (long) roundf(((float) s
->volume
.values
[i
] * (u
->hw_volume_max
- u
->hw_volume_min
)) / PA_VOLUME_NORM
) + u
->hw_volume_min
;
429 /* Try to avoid superfluous volume changes */
431 s
->volume
.values
[i
] = (pa_volume_t
) roundf(((float) (vol
- u
->hw_volume_min
) * PA_VOLUME_NORM
) / (u
->hw_volume_max
- u
->hw_volume_min
));
437 pa_log_error("Unable to read volume: %s", snd_strerror(err
));
439 s
->get_volume
= NULL
;
440 s
->set_volume
= NULL
;
444 static int sink_set_volume_cb(pa_sink
*s
) {
445 struct userdata
*u
= s
->userdata
;
450 pa_assert(u
->mixer_elem
);
452 for (i
= 0; i
< s
->sample_spec
.channels
; i
++) {
456 pa_assert(snd_mixer_selem_has_playback_channel(u
->mixer_elem
, i
));
458 vol
= s
->volume
.values
[i
];
460 if (vol
> PA_VOLUME_NORM
)
461 vol
= PA_VOLUME_NORM
;
463 alsa_vol
= (long) roundf(((float) vol
* (u
->hw_volume_max
- u
->hw_volume_min
)) / PA_VOLUME_NORM
) + u
->hw_volume_min
;
465 if ((err
= snd_mixer_selem_set_playback_volume(u
->mixer_elem
, i
, alsa_vol
)) < 0)
472 pa_log_error("Unable to set volume: %s", snd_strerror(err
));
474 s
->get_volume
= NULL
;
475 s
->set_volume
= NULL
;
479 static int sink_get_mute_cb(pa_sink
*s
) {
480 struct userdata
*u
= s
->userdata
;
484 pa_assert(u
->mixer_elem
);
486 if ((err
= snd_mixer_selem_get_playback_switch(u
->mixer_elem
, 0, &sw
)) < 0) {
487 pa_log_error("Unable to get switch: %s", snd_strerror(err
));
499 static int sink_set_mute_cb(pa_sink
*s
) {
500 struct userdata
*u
= s
->userdata
;
504 pa_assert(u
->mixer_elem
);
506 if ((err
= snd_mixer_selem_set_playback_switch_all(u
->mixer_elem
, !s
->muted
)) < 0) {
507 pa_log_error("Unable to set switch: %s", snd_strerror(err
));
517 static void thread_func(void *userdata
) {
519 struct userdata
*u
= userdata
;
520 unsigned short revents
= 0;
521 snd_pcm_status_t
*status
;
525 snd_pcm_status_alloca(&status
);
527 pa_log_debug("Thread starting up");
529 if (build_pollfd(u
) < 0)
533 pa_msgobject
*object
;
540 /* pa_log("loop"); */
542 /* Check whether there is a message for us to process */
543 if (pa_asyncmsgq_get(u
->asyncmsgq
, &object
, &code
, &data
, &offset
, &chunk
, 0) == 0) {
546 /* pa_log("processing msg"); */
548 if (!object
&& code
== PA_MESSAGE_SHUTDOWN
) {
549 pa_asyncmsgq_done(u
->asyncmsgq
, 0);
553 ret
= pa_asyncmsgq_dispatch(object
, code
, data
, offset
, &chunk
);
554 pa_asyncmsgq_done(u
->asyncmsgq
, ret
);
558 /* pa_log("loop2"); */
560 /* Render some data and write it to the dsp */
562 if (PA_SINK_OPENED(u
->sink
->thread_info
.state
) && ((revents
& POLLOUT
) || u
->first
== 1)) {
564 pa_assert(u
->pcm_handle
);
568 if ((work_done
= mmap_write(u
)) < 0)
578 if ((err
= snd_pcm_status(u
->pcm_handle
, status
)) < 0) {
579 pa_log("Failed to query DSP status data: %s", snd_strerror(t
));
583 if (snd_pcm_status_get_avail_max(status
)*u
->frame_size
>= u
->hwbuf_size
)
584 pa_log_debug("Buffer underrun!");
586 l
= snd_pcm_status_get_avail(status
) * u
->frame_size
;
588 /* pa_log("%u bytes to write", l); */
593 if (u
->memchunk
.length
<= 0)
594 pa_sink_render(u
->sink
, l
, &u
->memchunk
);
596 pa_assert(u
->memchunk
.length
> 0);
598 p
= pa_memblock_acquire(u
->memchunk
.memblock
);
599 t
= snd_pcm_writei(u
->pcm_handle
, (const uint8_t*) p
+ u
->memchunk
.index
, u
->memchunk
.length
/ u
->frame_size
);
600 pa_memblock_release(u
->memchunk
.memblock
);
602 /* pa_log("wrote %i bytes of %u (%u)", t*u->frame_size, u->memchunk.length, l); */
608 if ((t
= snd_pcm_recover(u
->pcm_handle
, t
, 1)) == 0)
612 pa_log_debug("EAGAIN");
615 pa_log("Failed to write data to DSP: %s", snd_strerror(t
));
620 u
->memchunk
.index
+= t
* u
->frame_size
;
621 u
->memchunk
.length
-= t
* u
->frame_size
;
623 if (u
->memchunk
.length
<= 0) {
624 pa_memblock_unref(u
->memchunk
.memblock
);
625 pa_memchunk_reset(&u
->memchunk
);
630 if (t
* u
->frame_size
>= (unsigned) l
)
640 pa_log_info("Starting playback.");
641 snd_pcm_start(u
->pcm_handle
);
649 /* Hmm, nothing to do. Let's sleep */
650 if (pa_asyncmsgq_before_poll(u
->asyncmsgq
) < 0)
653 /* pa_log("polling for %i", POLLFD_ALSA_BASE + (PA_SINK_OPENED(u->sink->thread_info.state) ? u->n_alsa_fds : 0)); */
654 r
= poll(u
->pollfd
, POLLFD_ALSA_BASE
+ (PA_SINK_OPENED(u
->sink
->thread_info
.state
) ? u
->n_alsa_fds
: 0), -1);
655 /* pa_log("poll end"); */
657 pa_asyncmsgq_after_poll(u
->asyncmsgq
);
660 if (errno
== EINTR
) {
661 u
->pollfd
[POLLFD_ASYNCQ
].revents
= 0;
666 pa_log("poll() failed: %s", pa_cstrerror(errno
));
672 if (PA_SINK_OPENED(u
->sink
->thread_info
.state
)) {
673 if ((err
= snd_pcm_poll_descriptors_revents(u
->pcm_handle
, u
->pollfd
+ POLLFD_ALSA_BASE
, u
->n_alsa_fds
, &revents
)) < 0) {
674 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", snd_strerror(err
));
678 if (revents
& (POLLERR
|POLLNVAL
|POLLHUP
)) {
679 if (revents
& POLLERR
)
680 pa_log_warn("Got POLLERR from ALSA");
681 if (revents
& POLLNVAL
)
682 pa_log_warn("Got POLLNVAL from ALSA");
683 if (revents
& POLLHUP
)
684 pa_log_warn("Got POLLHUP from ALSA");
691 pa_assert((u
->pollfd
[POLLFD_ASYNCQ
].revents
& ~POLLIN
) == 0);
695 /* We have to continue processing messages until we receive the
696 * SHUTDOWN message */
697 pa_asyncmsgq_post(u
->core
->asyncmsgq
, PA_MSGOBJECT(u
->core
), PA_CORE_MESSAGE_UNLOAD_MODULE
, u
->module
, 0, NULL
, NULL
);
698 pa_asyncmsgq_wait_for(u
->asyncmsgq
, PA_MESSAGE_SHUTDOWN
);
701 pa_log_debug("Thread shutting down");
704 int pa__init(pa_core
*c
, pa_module
*m
) {
706 pa_modargs
*ma
= NULL
;
708 struct userdata
*u
= NULL
;
712 uint32_t nfrags
, frag_size
;
713 snd_pcm_uframes_t period_size
;
715 snd_pcm_info_t
*pcm_info
= NULL
;
719 char *name_buf
= NULL
;
726 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
727 pa_log("Failed to parse module arguments");
731 ss
= c
->default_sample_spec
;
732 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_ALSA
) < 0) {
733 pa_log("Failed to parse sample specification and channel map");
737 frame_size
= pa_frame_size(&ss
);
739 nfrags
= DEFAULT_NFRAGS
;
740 frag_size
= pa_usec_to_bytes(DEFAULT_FRAGSIZE_MSEC
*1000, &ss
);
742 frag_size
= frame_size
;
744 if (pa_modargs_get_value_u32(ma
, "fragments", &nfrags
) < 0 || pa_modargs_get_value_u32(ma
, "fragment_size", &frag_size
) < 0) {
745 pa_log("Failed to parse buffer metrics");
748 period_size
= frag_size
/frame_size
;
750 if (pa_modargs_get_value_boolean(ma
, "mmap", &use_mmap
) < 0) {
751 pa_log("Failed to parse mmap argument.");
755 u
= pa_xnew0(struct userdata
, 1);
759 u
->use_mmap
= use_mmap
;
763 pa_assert_se(u
->asyncmsgq
= pa_asyncmsgq_new(0));
765 snd_config_update_free_global();
766 if ((err
= snd_pcm_open(&u
->pcm_handle
, dev
= pa_modargs_get_value(ma
, "device", DEFAULT_DEVICE
), SND_PCM_STREAM_PLAYBACK
, SND_PCM_NONBLOCK
)) < 0) {
767 pa_log("Error opening PCM device %s: %s", dev
, snd_strerror(err
));
771 u
->device_name
= pa_xstrdup(dev
);
773 if ((err
= snd_pcm_info_malloc(&pcm_info
)) < 0 ||
774 (err
= snd_pcm_info(u
->pcm_handle
, pcm_info
)) < 0) {
775 pa_log("Error fetching PCM info: %s", snd_strerror(err
));
780 if ((err
= pa_alsa_set_hw_params(u
->pcm_handle
, &ss
, &nfrags
, &period_size
, &b
)) < 0) {
781 pa_log("Failed to set hardware parameters: %s", snd_strerror(err
));
785 if (use_mmap
&& !b
) {
786 pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
787 u
->use_mmap
= use_mmap
= b
;
791 pa_log_info("Successfully enabled mmap() mode.");
793 if ((err
= pa_alsa_set_sw_params(u
->pcm_handle
)) < 0) {
794 pa_log("Failed to set software parameters: %s", snd_strerror(err
));
798 /* ALSA might tweak the sample spec, so recalculate the frame size */
799 frame_size
= pa_frame_size(&ss
);
801 if (ss
.channels
!= map
.channels
)
802 /* Seems ALSA didn't like the channel number, so let's fix the channel map */
803 pa_channel_map_init_auto(&map
, ss
.channels
, PA_CHANNEL_MAP_ALSA
);
805 if ((err
= snd_mixer_open(&u
->mixer_handle
, 0)) < 0)
806 pa_log_warn("Error opening mixer: %s", snd_strerror(err
));
809 if ((pa_alsa_prepare_mixer(u
->mixer_handle
, dev
) < 0) ||
810 !(u
->mixer_elem
= pa_alsa_find_elem(u
->mixer_handle
, "Master", "PCM"))) {
812 snd_mixer_close(u
->mixer_handle
);
813 u
->mixer_handle
= NULL
;
817 if ((name
= pa_modargs_get_value(ma
, "sink_name", NULL
)))
820 name
= name_buf
= pa_sprintf_malloc("alsa_output.%s", dev
);
824 u
->sink
= pa_sink_new(c
, __FILE__
, name
, namereg_fail
, &ss
, &map
);
828 pa_log("Failed to create sink object");
832 u
->sink
->parent
.process_msg
= sink_process_msg
;
833 u
->sink
->userdata
= u
;
835 pa_sink_set_module(u
->sink
, m
);
836 pa_sink_set_asyncmsgq(u
->sink
, u
->asyncmsgq
);
837 pa_sink_set_description(u
->sink
, t
= pa_sprintf_malloc(
838 "ALSA PCM on %s (%s)",
840 snd_pcm_info_get_name(pcm_info
)));
843 u
->sink
->is_hardware
= 1;
845 u
->frame_size
= frame_size
;
846 u
->fragment_size
= frag_size
= period_size
* frame_size
;
847 u
->nfragments
= nfrags
;
848 u
->hwbuf_size
= u
->fragment_size
* nfrags
;
850 pa_log_info("Using %u fragments of size %lu bytes.", nfrags
, (long unsigned) u
->fragment_size
);
852 pa_memchunk_reset(&u
->memchunk
);
854 if (u
->mixer_handle
) {
855 /* Initialize mixer code */
857 pa_assert(u
->mixer_elem
);
859 if (snd_mixer_selem_has_playback_volume(u
->mixer_elem
)) {
862 for (i
= 0;i
< ss
.channels
; i
++) {
863 if (!snd_mixer_selem_has_playback_channel(u
->mixer_elem
, i
))
867 if (i
== ss
.channels
) {
868 u
->sink
->get_volume
= sink_get_volume_cb
;
869 u
->sink
->set_volume
= sink_set_volume_cb
;
870 snd_mixer_selem_get_playback_volume_range(u
->mixer_elem
, &u
->hw_volume_min
, &u
->hw_volume_max
);
874 if (snd_mixer_selem_has_playback_switch(u
->mixer_elem
)) {
875 u
->sink
->get_mute
= sink_get_mute_cb
;
876 u
->sink
->set_mute
= sink_set_mute_cb
;
879 u
->mixer_fdl
= pa_alsa_fdlist_new();
881 if (pa_alsa_fdlist_set_mixer(u
->mixer_fdl
, u
->mixer_handle
, c
->mainloop
) < 0) {
882 pa_log("failed to initialise file descriptor monitoring");
886 snd_mixer_elem_set_callback(u
->mixer_elem
, mixer_callback
);
887 snd_mixer_elem_set_callback_private(u
->mixer_elem
, u
);
891 if (!(u
->thread
= pa_thread_new(thread_func
, u
))) {
892 pa_log("Failed to create thread.");
896 /* Get initial mixer settings */
897 if (u
->sink
->get_volume
)
898 u
->sink
->get_volume(u
->sink
);
899 if (u
->sink
->get_mute
)
900 u
->sink
->get_mute(u
->sink
);
910 snd_pcm_info_free(pcm_info
);
922 void pa__done(pa_core
*c
, pa_module
*m
) {
928 if (!(u
= m
->userdata
))
932 pa_sink_disconnect(u
->sink
);
935 pa_asyncmsgq_send(u
->asyncmsgq
, NULL
, PA_MESSAGE_SHUTDOWN
, NULL
, 0, NULL
);
936 pa_thread_free(u
->thread
);
940 pa_asyncmsgq_free(u
->asyncmsgq
);
943 pa_sink_unref(u
->sink
);
945 if (u
->memchunk
.memblock
)
946 pa_memblock_unref(u
->memchunk
.memblock
);
949 pa_alsa_fdlist_free(u
->mixer_fdl
);
952 snd_mixer_close(u
->mixer_handle
);
955 snd_pcm_drop(u
->pcm_handle
);
956 snd_pcm_close(u
->pcm_handle
);
960 pa_xfree(u
->device_name
);
963 snd_config_update_free_global();