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 #include <asoundlib.h>
33 #include <pulse/xmalloc.h>
34 #include <pulse/util.h>
36 #include <pulsecore/core-error.h>
37 #include <pulsecore/core.h>
38 #include <pulsecore/module.h>
39 #include <pulsecore/memchunk.h>
40 #include <pulsecore/sink.h>
41 #include <pulsecore/modargs.h>
42 #include <pulsecore/core-util.h>
43 #include <pulsecore/sample-util.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/macro.h>
46 #include <pulsecore/thread.h>
47 #include <pulsecore/core-error.h>
48 #include <pulsecore/thread-mq.h>
49 #include <pulsecore/rtpoll.h>
51 #include "alsa-util.h"
52 #include "module-alsa-source-symdef.h"
54 PA_MODULE_AUTHOR("Lennart Poettering")
55 PA_MODULE_DESCRIPTION("ALSA Source")
56 PA_MODULE_VERSION(PACKAGE_VERSION
)
58 "source_name=<name for the source> "
59 "device=<ALSA device> "
60 "format=<sample format> "
61 "channels=<number of channels> "
63 "fragments=<number of fragments> "
64 "fragment_size=<fragment size> "
65 "channel_map=<channel map> "
66 "mmap=<enable memory mapping?>")
68 #define DEFAULT_DEVICE "default"
76 pa_thread_mq thread_mq
;
79 snd_pcm_t
*pcm_handle
;
81 pa_alsa_fdlist
*mixer_fdl
;
82 snd_mixer_t
*mixer_handle
;
83 snd_mixer_elem_t
*mixer_elem
;
84 long hw_volume_max
, hw_volume_min
;
86 size_t frame_size
, fragment_size
, hwbuf_size
;
93 pa_rtpoll_item
*alsa_rtpoll_item
;
96 static const char* const valid_modargs
[] = {
109 static int mmap_read(struct userdata
*u
) {
113 pa_source_assert_ref(u
->source
);
118 const snd_pcm_channel_area_t
*areas
;
119 snd_pcm_uframes_t offset
, frames
;
123 if ((n
= snd_pcm_avail_update(u
->pcm_handle
)) < 0) {
126 pa_log_debug("snd_pcm_avail_update: Buffer underrun!");
128 if ((err
= snd_pcm_recover(u
->pcm_handle
, n
, 1)) == 0)
134 pa_log("snd_pcm_avail_update: %s", snd_strerror(err
));
138 /* pa_log("Got request for %i samples", (int) n); */
145 if ((err
= snd_pcm_mmap_begin(u
->pcm_handle
, &areas
, &offset
, &frames
)) < 0) {
148 pa_log_debug("snd_pcm_mmap_begin: Buffer underrun!");
150 if ((err
= snd_pcm_recover(u
->pcm_handle
, err
, 1)) == 0)
156 pa_log("Failed to write data to DSP: %s", snd_strerror(err
));
160 /* Check these are multiples of 8 bit */
161 pa_assert((areas
[0].first
& 7) == 0);
162 pa_assert((areas
[0].step
& 7)== 0);
164 /* We assume a single interleaved memory buffer */
165 pa_assert((areas
[0].first
>> 3) == 0);
166 pa_assert((areas
[0].step
>> 3) == u
->frame_size
);
168 p
= (uint8_t*) areas
[0].addr
+ (offset
* u
->frame_size
);
170 chunk
.memblock
= pa_memblock_new_fixed(u
->core
->mempool
, p
, frames
* u
->frame_size
, 1);
171 chunk
.length
= pa_memblock_get_length(chunk
.memblock
);
174 pa_source_post(u
->source
, &chunk
);
176 /* FIXME: Maybe we can do something to keep this memory block
177 * a little bit longer around? */
178 pa_memblock_unref_fixed(chunk
.memblock
);
180 if ((err
= snd_pcm_mmap_commit(u
->pcm_handle
, offset
, frames
)) < 0) {
183 pa_log_debug("snd_pcm_mmap_commit: Buffer underrun!");
185 if ((err
= snd_pcm_recover(u
->pcm_handle
, err
, 1)) == 0)
191 pa_log("Failed to write data to DSP: %s", snd_strerror(err
));
197 /* pa_log("wrote %i samples", (int) frames); */
201 static int unix_read(struct userdata
*u
) {
202 snd_pcm_status_t
*status
;
205 snd_pcm_status_alloca(&status
);
208 pa_source_assert_ref(u
->source
);
212 snd_pcm_sframes_t t
, k
;
217 if ((err
= snd_pcm_status(u
->pcm_handle
, status
)) < 0) {
218 pa_log("Failed to query DSP status data: %s", snd_strerror(err
));
222 if (snd_pcm_status_get_avail_max(status
)*u
->frame_size
>= u
->hwbuf_size
)
223 pa_log_debug("Buffer overrun!");
225 l
= snd_pcm_status_get_avail(status
) * u
->frame_size
;
230 chunk
.memblock
= pa_memblock_new(u
->core
->mempool
, (size_t) -1);
232 k
= pa_memblock_get_length(chunk
.memblock
);
237 k
= (k
/u
->frame_size
)*u
->frame_size
;
239 p
= pa_memblock_acquire(chunk
.memblock
);
240 t
= snd_pcm_readi(u
->pcm_handle
, (uint8_t*) p
, k
/ u
->frame_size
);
241 pa_memblock_release(chunk
.memblock
);
243 /* pa_log("wrote %i bytes of %u (%u)", t*u->frame_size, u->memchunk.length, l); */
248 pa_memblock_unref(chunk
.memblock
);
250 if ((t
= snd_pcm_recover(u
->pcm_handle
, t
, 1)) == 0)
254 pa_log_debug("EAGAIN");
257 pa_log("Failed to read data from DSP: %s", snd_strerror(t
));
263 chunk
.length
= t
* u
->frame_size
;
265 pa_source_post(u
->source
, &chunk
);
266 pa_memblock_unref(chunk
.memblock
);
270 if (t
* u
->frame_size
>= (unsigned) l
)
275 static pa_usec_t
source_get_latency(struct userdata
*u
) {
277 snd_pcm_status_t
*status
;
278 snd_pcm_sframes_t frames
= 0;
281 snd_pcm_status_alloca(&status
);
284 pa_assert(u
->pcm_handle
);
286 if ((err
= snd_pcm_status(u
->pcm_handle
, status
)) < 0)
287 pa_log("Failed to get delay: %s", snd_strerror(err
));
289 frames
= snd_pcm_status_get_delay(status
);
292 r
= pa_bytes_to_usec(frames
* u
->frame_size
, &u
->source
->sample_spec
);
297 static int build_pollfd(struct userdata
*u
) {
299 struct pollfd
*pollfd
;
303 pa_assert(u
->pcm_handle
);
305 if ((n
= snd_pcm_poll_descriptors_count(u
->pcm_handle
)) < 0) {
306 pa_log("snd_pcm_poll_descriptors_count() failed: %s", snd_strerror(n
));
310 if (u
->alsa_rtpoll_item
)
311 pa_rtpoll_item_free(u
->alsa_rtpoll_item
);
313 u
->alsa_rtpoll_item
= pa_rtpoll_item_new(u
->rtpoll
, PA_RTPOLL_NEVER
, n
);
314 pollfd
= pa_rtpoll_item_get_pollfd(u
->alsa_rtpoll_item
, NULL
);
316 if ((err
= snd_pcm_poll_descriptors(u
->pcm_handle
, pollfd
, n
)) < 0) {
317 pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err
));
324 static int suspend(struct userdata
*u
) {
326 pa_assert(u
->pcm_handle
);
329 snd_pcm_close(u
->pcm_handle
);
330 u
->pcm_handle
= NULL
;
332 if (u
->alsa_rtpoll_item
) {
333 pa_rtpoll_item_free(u
->alsa_rtpoll_item
);
334 u
->alsa_rtpoll_item
= NULL
;
337 pa_log_info("Device suspended...");
342 static int unsuspend(struct userdata
*u
) {
346 snd_pcm_uframes_t period_size
;
349 pa_assert(!u
->pcm_handle
);
351 pa_log_info("Trying resume...");
353 snd_config_update_free_global();
354 if ((err
= snd_pcm_open(&u
->pcm_handle
, u
->device_name
, SND_PCM_STREAM_CAPTURE
, SND_PCM_NONBLOCK
)) < 0) {
355 pa_log("Error opening PCM device %s: %s", u
->device_name
, snd_strerror(err
));
359 ss
= u
->source
->sample_spec
;
360 nfrags
= u
->nfragments
;
361 period_size
= u
->fragment_size
/ u
->frame_size
;
364 if ((err
= pa_alsa_set_hw_params(u
->pcm_handle
, &ss
, &nfrags
, &period_size
, &b
)) < 0) {
365 pa_log("Failed to set hardware parameters: %s", snd_strerror(err
));
369 if (b
!= u
->use_mmap
) {
370 pa_log_warn("Resume failed, couldn't get original access mode.");
374 if (!pa_sample_spec_equal(&ss
, &u
->source
->sample_spec
)) {
375 pa_log_warn("Resume failed, couldn't restore original sample settings.");
379 if (nfrags
!= u
->nfragments
|| period_size
*u
->frame_size
!= u
->fragment_size
) {
380 pa_log_warn("Resume failed, couldn't restore original fragment settings.");
384 if ((err
= pa_alsa_set_sw_params(u
->pcm_handle
)) < 0) {
385 pa_log("Failed to set software parameters: %s", snd_strerror(err
));
389 if (build_pollfd(u
) < 0)
392 snd_pcm_start(u
->pcm_handle
);
394 /* FIXME: We need to reload the volume somehow */
396 pa_log_info("Resumed successfully...");
402 snd_pcm_close(u
->pcm_handle
);
403 u
->pcm_handle
= NULL
;
409 static int source_process_msg(pa_msgobject
*o
, int code
, void *data
, int64_t offset
, pa_memchunk
*chunk
) {
410 struct userdata
*u
= PA_SOURCE(o
)->userdata
;
414 case PA_SOURCE_MESSAGE_GET_LATENCY
: {
418 r
= source_get_latency(u
);
420 *((pa_usec_t
*) data
) = r
;
425 case PA_SOURCE_MESSAGE_SET_STATE
:
427 switch ((pa_source_state_t
) PA_PTR_TO_UINT(data
)) {
429 case PA_SOURCE_SUSPENDED
:
430 pa_assert(PA_SOURCE_OPENED(u
->source
->thread_info
.state
));
438 case PA_SOURCE_RUNNING
:
440 if (u
->source
->thread_info
.state
== PA_SOURCE_SUSPENDED
) {
441 if (unsuspend(u
) < 0)
447 case PA_SOURCE_UNLINKED
:
455 return pa_source_process_msg(o
, code
, data
, offset
, chunk
);
458 static int mixer_callback(snd_mixer_elem_t
*elem
, unsigned int mask
) {
459 struct userdata
*u
= snd_mixer_elem_get_callback_private(elem
);
462 pa_assert(u
->mixer_handle
);
464 if (mask
== SND_CTL_EVENT_MASK_REMOVE
)
467 if (mask
& SND_CTL_EVENT_MASK_VALUE
) {
468 pa_source_get_volume(u
->source
);
469 pa_source_get_mute(u
->source
);
475 static int source_get_volume_cb(pa_source
*s
) {
476 struct userdata
*u
= s
->userdata
;
481 pa_assert(u
->mixer_elem
);
483 for (i
= 0; i
< s
->sample_spec
.channels
; i
++) {
486 pa_assert(snd_mixer_selem_has_capture_channel(u
->mixer_elem
, i
));
488 if ((err
= snd_mixer_selem_get_capture_volume(u
->mixer_elem
, i
, &vol
)) < 0)
491 set_vol
= (long) roundf(((float) s
->volume
.values
[i
] * (u
->hw_volume_max
- u
->hw_volume_min
)) / PA_VOLUME_NORM
) + u
->hw_volume_min
;
493 /* Try to avoid superfluous volume changes */
495 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
));
501 pa_log_error("Unable to read volume: %s", snd_strerror(err
));
503 s
->get_volume
= NULL
;
504 s
->set_volume
= NULL
;
508 static int source_set_volume_cb(pa_source
*s
) {
509 struct userdata
*u
= s
->userdata
;
514 pa_assert(u
->mixer_elem
);
516 for (i
= 0; i
< s
->sample_spec
.channels
; i
++) {
520 pa_assert(snd_mixer_selem_has_capture_channel(u
->mixer_elem
, i
));
522 vol
= s
->volume
.values
[i
];
524 if (vol
> PA_VOLUME_NORM
)
525 vol
= PA_VOLUME_NORM
;
527 alsa_vol
= (long) roundf(((float) vol
* (u
->hw_volume_max
- u
->hw_volume_min
)) / PA_VOLUME_NORM
) + u
->hw_volume_min
;
529 if ((err
= snd_mixer_selem_set_capture_volume(u
->mixer_elem
, i
, alsa_vol
)) < 0)
536 pa_log_error("Unable to set volume: %s", snd_strerror(err
));
538 s
->get_volume
= NULL
;
539 s
->set_volume
= NULL
;
543 static int source_get_mute_cb(pa_source
*s
) {
544 struct userdata
*u
= s
->userdata
;
548 pa_assert(u
->mixer_elem
);
550 if ((err
= snd_mixer_selem_get_capture_switch(u
->mixer_elem
, 0, &sw
)) < 0) {
551 pa_log_error("Unable to get switch: %s", snd_strerror(err
));
563 static int source_set_mute_cb(pa_source
*s
) {
564 struct userdata
*u
= s
->userdata
;
568 pa_assert(u
->mixer_elem
);
570 if ((err
= snd_mixer_selem_set_capture_switch_all(u
->mixer_elem
, !s
->muted
)) < 0) {
571 pa_log_error("Unable to set switch: %s", snd_strerror(err
));
581 static void thread_func(void *userdata
) {
582 struct userdata
*u
= userdata
;
586 pa_log_debug("Thread starting up");
588 if (u
->core
->high_priority
)
591 pa_thread_mq_install(&u
->thread_mq
);
592 pa_rtpoll_install(u
->rtpoll
);
594 if (build_pollfd(u
) < 0)
597 snd_pcm_start(u
->pcm_handle
);
602 /* Read some data and pass it to the sources */
603 if (PA_SOURCE_OPENED(u
->source
->thread_info
.state
)) {
606 if (mmap_read(u
) < 0)
610 if (unix_read(u
) < 0)
615 /* Hmm, nothing to do. Let's sleep */
616 if ((ret
= pa_rtpoll_run(u
->rtpoll
, 1)) < 0)
622 /* Tell ALSA about this and process its response */
623 if (PA_SOURCE_OPENED(u
->source
->thread_info
.state
)) {
624 struct pollfd
*pollfd
;
625 unsigned short revents
= 0;
629 pollfd
= pa_rtpoll_item_get_pollfd(u
->alsa_rtpoll_item
, &n
);
631 if ((err
= snd_pcm_poll_descriptors_revents(u
->pcm_handle
, pollfd
, n
, &revents
)) < 0) {
632 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", snd_strerror(err
));
636 if (revents
& (POLLERR
|POLLNVAL
|POLLHUP
)) {
637 if (revents
& POLLERR
)
638 pa_log_warn("Got POLLERR from ALSA");
639 if (revents
& POLLNVAL
)
640 pa_log_warn("Got POLLNVAL from ALSA");
641 if (revents
& POLLHUP
)
642 pa_log_warn("Got POLLHUP from ALSA");
650 /* If this was no regular exit from the loop we have to continue
651 * processing messages until we received PA_MESSAGE_SHUTDOWN */
652 pa_asyncmsgq_post(u
->thread_mq
.outq
, PA_MSGOBJECT(u
->core
), PA_CORE_MESSAGE_UNLOAD_MODULE
, u
->module
, 0, NULL
, NULL
);
653 pa_asyncmsgq_wait_for(u
->thread_mq
.inq
, PA_MESSAGE_SHUTDOWN
);
656 pa_log_debug("Thread shutting down");
659 int pa__init(pa_module
*m
) {
661 pa_modargs
*ma
= NULL
;
662 struct userdata
*u
= NULL
;
666 unsigned nfrags
, frag_size
;
667 snd_pcm_uframes_t period_size
;
669 snd_pcm_info_t
*pcm_info
= NULL
;
673 char *name_buf
= NULL
;
677 snd_pcm_info_alloca(&pcm_info
);
681 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
682 pa_log("Failed to parse module arguments");
686 ss
= m
->core
->default_sample_spec
;
687 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_ALSA
) < 0) {
688 pa_log("Failed to parse sample specification");
692 frame_size
= pa_frame_size(&ss
);
694 nfrags
= m
->core
->default_n_fragments
;
695 frag_size
= pa_usec_to_bytes(m
->core
->default_fragment_size_msec
*1000, &ss
);
697 frag_size
= frame_size
;
699 if (pa_modargs_get_value_u32(ma
, "fragments", &nfrags
) < 0 || pa_modargs_get_value_u32(ma
, "fragment_size", &frag_size
) < 0) {
700 pa_log("Failed to parse buffer metrics");
703 period_size
= frag_size
/frame_size
;
705 if (pa_modargs_get_value_boolean(ma
, "mmap", &use_mmap
) < 0) {
706 pa_log("Failed to parse mmap argument.");
710 u
= pa_xnew0(struct userdata
, 1);
714 u
->use_mmap
= use_mmap
;
715 pa_thread_mq_init(&u
->thread_mq
, m
->core
->mainloop
);
716 u
->rtpoll
= pa_rtpoll_new();
717 u
->alsa_rtpoll_item
= NULL
;
718 pa_rtpoll_item_new_asyncmsgq(u
->rtpoll
, PA_RTPOLL_EARLY
, u
->thread_mq
.inq
);
720 snd_config_update_free_global();
722 dev
= pa_xstrdup(pa_modargs_get_value(ma
, "device", DEFAULT_DEVICE
));
726 if ((err
= snd_pcm_open(&u
->pcm_handle
, dev
, SND_PCM_STREAM_CAPTURE
, SND_PCM_NONBLOCK
)) < 0) {
727 pa_log("Error opening PCM device %s: %s", dev
, snd_strerror(err
));
733 if ((err
= pa_alsa_set_hw_params(u
->pcm_handle
, &ss
, &nfrags
, &period_size
, &b
)) < 0) {
736 /* Hmm, some hw is very exotic, so we retry with plughw, if hw didn't work */
738 if (pa_startswith(dev
, "hw:")) {
739 char *d
= pa_sprintf_malloc("plughw:%s", dev
+3);
740 pa_log_debug("Opening the device as '%s' didn't work, retrying with '%s'.", dev
, d
);
744 snd_pcm_close(u
->pcm_handle
);
745 u
->pcm_handle
= NULL
;
750 pa_log("Failed to set hardware parameters: %s", snd_strerror(err
));
758 u
->device_name
= dev
;
760 if (use_mmap
&& !b
) {
761 pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
762 u
->use_mmap
= use_mmap
= b
;
766 pa_log_info("Successfully enabled mmap() mode.");
768 if ((err
= snd_pcm_info(u
->pcm_handle
, pcm_info
)) < 0) {
769 pa_log("Error fetching PCM info: %s", snd_strerror(err
));
773 if ((err
= pa_alsa_set_sw_params(u
->pcm_handle
)) < 0) {
774 pa_log("Failed to set software parameters: %s", snd_strerror(err
));
778 /* ALSA might tweak the sample spec, so recalculate the frame size */
779 frame_size
= pa_frame_size(&ss
);
781 if (ss
.channels
!= map
.channels
)
782 /* Seems ALSA didn't like the channel number, so let's fix the channel map */
783 pa_channel_map_init_auto(&map
, ss
.channels
, PA_CHANNEL_MAP_ALSA
);
785 if ((err
= snd_mixer_open(&u
->mixer_handle
, 0)) < 0)
786 pa_log("Error opening mixer: %s", snd_strerror(err
));
789 if ((pa_alsa_prepare_mixer(u
->mixer_handle
, dev
) < 0) ||
790 !(u
->mixer_elem
= pa_alsa_find_elem(u
->mixer_handle
, "Capture", NULL
))) {
791 snd_mixer_close(u
->mixer_handle
);
792 u
->mixer_handle
= NULL
;
796 if ((name
= pa_modargs_get_value(ma
, "source_name", NULL
)))
799 name
= name_buf
= pa_sprintf_malloc("alsa_input.%s", dev
);
803 u
->source
= pa_source_new(m
->core
, __FILE__
, name
, namereg_fail
, &ss
, &map
);
807 pa_log("Failed to create source object");
811 u
->source
->parent
.process_msg
= source_process_msg
;
812 u
->source
->userdata
= u
;
814 pa_source_set_module(u
->source
, m
);
815 pa_source_set_asyncmsgq(u
->source
, u
->thread_mq
.inq
);
816 pa_source_set_rtpoll(u
->source
, u
->rtpoll
);
817 pa_source_set_description(u
->source
, t
= pa_sprintf_malloc(
818 "ALSA PCM on %s (%s)%s",
820 snd_pcm_info_get_name(pcm_info
),
821 use_mmap
? " via DMA" : ""));
824 u
->source
->flags
= PA_SOURCE_HARDWARE
|PA_SOURCE_CAN_SUSPEND
|PA_SOURCE_LATENCY
|PA_SOURCE_HW_VOLUME_CTRL
;
826 u
->frame_size
= frame_size
;
827 u
->fragment_size
= frag_size
= period_size
* frame_size
;
828 u
->nfragments
= nfrags
;
829 u
->hwbuf_size
= u
->fragment_size
* nfrags
;
831 pa_log_info("Using %u fragments of size %lu bytes.", nfrags
, (long unsigned) u
->fragment_size
);
833 if (u
->mixer_handle
) {
834 pa_assert(u
->mixer_elem
);
836 if (snd_mixer_selem_has_capture_volume(u
->mixer_elem
)) {
839 for (i
= 0;i
< ss
.channels
;i
++) {
840 if (!snd_mixer_selem_has_capture_channel(u
->mixer_elem
, i
))
844 if (i
== ss
.channels
) {
845 u
->source
->get_volume
= source_get_volume_cb
;
846 u
->source
->set_volume
= source_set_volume_cb
;
847 snd_mixer_selem_get_capture_volume_range(u
->mixer_elem
, &u
->hw_volume_min
, &u
->hw_volume_max
);
851 if (snd_mixer_selem_has_capture_switch(u
->mixer_elem
)) {
852 u
->source
->get_mute
= source_get_mute_cb
;
853 u
->source
->set_mute
= source_set_mute_cb
;
856 u
->mixer_fdl
= pa_alsa_fdlist_new();
858 if (pa_alsa_fdlist_set_mixer(u
->mixer_fdl
, u
->mixer_handle
, m
->core
->mainloop
) < 0) {
859 pa_log("failed to initialise file descriptor monitoring");
863 snd_mixer_elem_set_callback(u
->mixer_elem
, mixer_callback
);
864 snd_mixer_elem_set_callback_private(u
->mixer_elem
, u
);
868 if (!(u
->thread
= pa_thread_new(thread_func
, u
))) {
869 pa_log("Failed to create thread.");
872 /* Get initial mixer settings */
873 if (u
->source
->get_volume
)
874 u
->source
->get_volume(u
->source
);
875 if (u
->source
->get_mute
)
876 u
->source
->get_mute(u
->source
);
878 pa_source_put(u
->source
);
894 void pa__done(pa_module
*m
) {
899 if (!(u
= m
->userdata
))
903 pa_source_unlink(u
->source
);
906 pa_asyncmsgq_send(u
->thread_mq
.inq
, NULL
, PA_MESSAGE_SHUTDOWN
, NULL
, 0, NULL
);
907 pa_thread_free(u
->thread
);
910 pa_thread_mq_done(&u
->thread_mq
);
913 pa_source_unref(u
->source
);
915 if (u
->alsa_rtpoll_item
)
916 pa_rtpoll_item_free(u
->alsa_rtpoll_item
);
919 pa_rtpoll_free(u
->rtpoll
);
922 pa_alsa_fdlist_free(u
->mixer_fdl
);
925 snd_mixer_close(u
->mixer_handle
);
928 snd_pcm_drop(u
->pcm_handle
);
929 snd_pcm_close(u
->pcm_handle
);
932 pa_xfree(u
->device_name
);
935 snd_config_update_free_global();