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
32 #include <asoundlib.h>
34 #include <pulse/xmalloc.h>
35 #include <pulse/util.h>
37 #include <pulsecore/core-error.h>
38 #include <pulsecore/core.h>
39 #include <pulsecore/module.h>
40 #include <pulsecore/memchunk.h>
41 #include <pulsecore/sink.h>
42 #include <pulsecore/modargs.h>
43 #include <pulsecore/core-util.h>
44 #include <pulsecore/sample-util.h>
45 #include <pulsecore/log.h>
46 #include <pulsecore/macro.h>
47 #include <pulsecore/thread.h>
48 #include <pulsecore/core-error.h>
49 #include <pulsecore/thread-mq.h>
50 #include <pulsecore/rtpoll.h>
52 #include "alsa-util.h"
53 #include "module-alsa-source-symdef.h"
55 PA_MODULE_AUTHOR("Lennart Poettering")
56 PA_MODULE_DESCRIPTION("ALSA Source")
57 PA_MODULE_VERSION(PACKAGE_VERSION
)
59 "source_name=<name for the source> "
60 "device=<ALSA device> "
61 "format=<sample format> "
62 "channels=<number of channels> "
64 "fragments=<number of fragments> "
65 "fragment_size=<fragment size> "
66 "channel_map=<channel map> "
67 "mmap=<enable memory mapping?>")
69 #define DEFAULT_DEVICE "default"
77 pa_thread_mq thread_mq
;
80 snd_pcm_t
*pcm_handle
;
82 pa_alsa_fdlist
*mixer_fdl
;
83 snd_mixer_t
*mixer_handle
;
84 snd_mixer_elem_t
*mixer_elem
;
85 long hw_volume_max
, hw_volume_min
;
87 size_t frame_size
, fragment_size
, hwbuf_size
;
94 pa_rtpoll_item
*alsa_rtpoll_item
;
97 static const char* const valid_modargs
[] = {
110 static int mmap_read(struct userdata
*u
) {
114 pa_source_assert_ref(u
->source
);
119 const snd_pcm_channel_area_t
*areas
;
120 snd_pcm_uframes_t offset
, frames
;
124 if ((n
= snd_pcm_avail_update(u
->pcm_handle
)) < 0) {
127 pa_log_debug("snd_pcm_avail_update: Buffer underrun!");
129 if ((err
= snd_pcm_recover(u
->pcm_handle
, n
, 1)) == 0)
135 pa_log("snd_pcm_avail_update: %s", snd_strerror(n
));
139 /* pa_log("Got request for %i samples", (int) n); */
146 if ((err
= snd_pcm_mmap_begin(u
->pcm_handle
, &areas
, &offset
, &frames
)) < 0) {
149 pa_log_debug("snd_pcm_mmap_begin: Buffer underrun!");
151 if ((err
= snd_pcm_recover(u
->pcm_handle
, err
, 1)) == 0)
157 pa_log("Failed to write data to DSP: %s", snd_strerror(err
));
161 /* Check these are multiples of 8 bit */
162 pa_assert((areas
[0].first
& 7) == 0);
163 pa_assert((areas
[0].step
& 7)== 0);
165 /* We assume a single interleaved memory buffer */
166 pa_assert((areas
[0].first
>> 3) == 0);
167 pa_assert((areas
[0].step
>> 3) == u
->frame_size
);
169 p
= (uint8_t*) areas
[0].addr
+ (offset
* u
->frame_size
);
171 chunk
.memblock
= pa_memblock_new_fixed(u
->core
->mempool
, p
, frames
* u
->frame_size
, 1);
172 chunk
.length
= pa_memblock_get_length(chunk
.memblock
);
175 pa_source_post(u
->source
, &chunk
);
177 /* FIXME: Maybe we can do something to keep this memory block
178 * a little bit longer around? */
179 pa_memblock_unref_fixed(chunk
.memblock
);
181 if ((err
= snd_pcm_mmap_commit(u
->pcm_handle
, offset
, frames
)) < 0) {
184 pa_log_debug("snd_pcm_mmap_commit: Buffer underrun!");
186 if ((err
= snd_pcm_recover(u
->pcm_handle
, err
, 1)) == 0)
192 pa_log("Failed to write data to DSP: %s", snd_strerror(err
));
198 /* pa_log("wrote %i samples", (int) frames); */
202 static int unix_read(struct userdata
*u
) {
203 snd_pcm_status_t
*status
;
206 snd_pcm_status_alloca(&status
);
209 pa_source_assert_ref(u
->source
);
218 if ((err
= snd_pcm_status(u
->pcm_handle
, status
)) < 0) {
219 pa_log("Failed to query DSP status data: %s", snd_strerror(t
));
223 if (snd_pcm_status_get_avail_max(status
)*u
->frame_size
>= u
->hwbuf_size
)
224 pa_log_debug("Buffer overrun!");
226 l
= snd_pcm_status_get_avail(status
) * u
->frame_size
;
231 chunk
.memblock
= pa_memblock_new(u
->core
->mempool
, l
);
233 p
= pa_memblock_acquire(chunk
.memblock
);
234 t
= snd_pcm_readi(u
->pcm_handle
, (uint8_t*) p
, l
/ u
->frame_size
);
235 pa_memblock_release(chunk
.memblock
);
237 /* pa_log("wrote %i bytes of %u (%u)", t*u->frame_size, u->memchunk.length, l); */
242 pa_memblock_unref(chunk
.memblock
);
244 if ((t
= snd_pcm_recover(u
->pcm_handle
, t
, 1)) == 0)
248 pa_log_debug("EAGAIN");
251 pa_log("Failed to read data from DSP: %s", snd_strerror(t
));
257 chunk
.length
= t
* u
->frame_size
;
259 pa_source_post(u
->source
, &chunk
);
260 pa_memblock_unref(chunk
.memblock
);
264 if (t
* u
->frame_size
>= (unsigned) l
)
269 static pa_usec_t
source_get_latency(struct userdata
*u
) {
271 snd_pcm_status_t
*status
;
272 snd_pcm_sframes_t frames
= 0;
275 snd_pcm_status_alloca(&status
);
278 pa_assert(u
->pcm_handle
);
280 if ((err
= snd_pcm_status(u
->pcm_handle
, status
)) < 0)
281 pa_log("Failed to get delay: %s", snd_strerror(err
));
283 frames
= snd_pcm_status_get_delay(status
);
286 r
= pa_bytes_to_usec(frames
* u
->frame_size
, &u
->source
->sample_spec
);
291 static int build_pollfd(struct userdata
*u
) {
293 struct pollfd
*pollfd
;
297 pa_assert(u
->pcm_handle
);
299 if ((n
= snd_pcm_poll_descriptors_count(u
->pcm_handle
)) < 0) {
300 pa_log("snd_pcm_poll_descriptors_count() failed: %s", snd_strerror(n
));
304 if (u
->alsa_rtpoll_item
)
305 pa_rtpoll_item_free(u
->alsa_rtpoll_item
);
307 u
->alsa_rtpoll_item
= pa_rtpoll_item_new(u
->rtpoll
, n
);
308 pollfd
= pa_rtpoll_item_get_pollfd(u
->alsa_rtpoll_item
, NULL
);
310 if ((err
= snd_pcm_poll_descriptors(u
->pcm_handle
, pollfd
, n
)) < 0) {
311 pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err
));
318 static int suspend(struct userdata
*u
) {
320 pa_assert(u
->pcm_handle
);
323 snd_pcm_close(u
->pcm_handle
);
324 u
->pcm_handle
= NULL
;
326 if (u
->alsa_rtpoll_item
) {
327 pa_rtpoll_item_free(u
->alsa_rtpoll_item
);
328 u
->alsa_rtpoll_item
= NULL
;
331 pa_log_debug("Device suspended...");
336 static int unsuspend(struct userdata
*u
) {
340 snd_pcm_uframes_t period_size
;
343 pa_assert(!u
->pcm_handle
);
345 pa_log_debug("Trying resume...");
347 snd_config_update_free_global();
348 if ((err
= snd_pcm_open(&u
->pcm_handle
, u
->device_name
, SND_PCM_STREAM_CAPTURE
, SND_PCM_NONBLOCK
)) < 0) {
349 pa_log("Error opening PCM device %s: %s", u
->device_name
, snd_strerror(err
));
353 ss
= u
->source
->sample_spec
;
354 nfrags
= u
->nfragments
;
355 period_size
= u
->fragment_size
/ u
->frame_size
;
358 if ((err
= pa_alsa_set_hw_params(u
->pcm_handle
, &ss
, &nfrags
, &period_size
, &b
)) < 0) {
359 pa_log("Failed to set hardware parameters: %s", snd_strerror(err
));
363 if (b
!= u
->use_mmap
) {
364 pa_log_warn("Resume failed, couldn't get original access mode.");
368 if (!pa_sample_spec_equal(&ss
, &u
->source
->sample_spec
)) {
369 pa_log_warn("Resume failed, couldn't restore original sample settings.");
373 if (nfrags
!= u
->nfragments
|| period_size
*u
->frame_size
!= u
->fragment_size
) {
374 pa_log_warn("Resume failed, couldn't restore original fragment settings.");
378 if ((err
= pa_alsa_set_sw_params(u
->pcm_handle
)) < 0) {
379 pa_log("Failed to set software parameters: %s", snd_strerror(err
));
383 if (build_pollfd(u
) < 0)
386 snd_pcm_start(u
->pcm_handle
);
388 /* FIXME: We need to reload the volume somehow */
390 pa_log_debug("Resumed successfully...");
396 snd_pcm_close(u
->pcm_handle
);
397 u
->pcm_handle
= NULL
;
403 static int source_process_msg(pa_msgobject
*o
, int code
, void *data
, int64_t offset
, pa_memchunk
*chunk
) {
404 struct userdata
*u
= PA_SOURCE(o
)->userdata
;
408 case PA_SOURCE_MESSAGE_GET_LATENCY
: {
412 r
= source_get_latency(u
);
414 *((pa_usec_t
*) data
) = r
;
419 case PA_SOURCE_MESSAGE_SET_STATE
:
421 switch ((pa_source_state_t
) PA_PTR_TO_UINT(data
)) {
423 case PA_SOURCE_SUSPENDED
:
424 pa_assert(PA_SOURCE_OPENED(u
->source
->thread_info
.state
));
432 case PA_SOURCE_RUNNING
:
434 if (u
->source
->thread_info
.state
== PA_SOURCE_SUSPENDED
) {
435 if (unsuspend(u
) < 0)
441 case PA_SOURCE_DISCONNECTED
:
448 return pa_source_process_msg(o
, code
, data
, offset
, chunk
);
451 static int mixer_callback(snd_mixer_elem_t
*elem
, unsigned int mask
) {
452 struct userdata
*u
= snd_mixer_elem_get_callback_private(elem
);
455 pa_assert(u
->mixer_handle
);
457 if (mask
== SND_CTL_EVENT_MASK_REMOVE
)
460 if (mask
& SND_CTL_EVENT_MASK_VALUE
) {
461 pa_source_get_volume(u
->source
);
462 pa_source_get_mute(u
->source
);
468 static int source_get_volume_cb(pa_source
*s
) {
469 struct userdata
*u
= s
->userdata
;
474 pa_assert(u
->mixer_elem
);
476 for (i
= 0; i
< s
->sample_spec
.channels
; i
++) {
479 pa_assert(snd_mixer_selem_has_capture_channel(u
->mixer_elem
, i
));
481 if ((err
= snd_mixer_selem_get_capture_volume(u
->mixer_elem
, i
, &vol
)) < 0)
484 set_vol
= (long) roundf(((float) s
->volume
.values
[i
] * (u
->hw_volume_max
- u
->hw_volume_min
)) / PA_VOLUME_NORM
) + u
->hw_volume_min
;
486 /* Try to avoid superfluous volume changes */
488 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
));
494 pa_log_error("Unable to read volume: %s", snd_strerror(err
));
496 s
->get_volume
= NULL
;
497 s
->set_volume
= NULL
;
501 static int source_set_volume_cb(pa_source
*s
) {
502 struct userdata
*u
= s
->userdata
;
507 pa_assert(u
->mixer_elem
);
509 for (i
= 0; i
< s
->sample_spec
.channels
; i
++) {
513 pa_assert(snd_mixer_selem_has_capture_channel(u
->mixer_elem
, i
));
515 vol
= s
->volume
.values
[i
];
517 if (vol
> PA_VOLUME_NORM
)
518 vol
= PA_VOLUME_NORM
;
520 alsa_vol
= (long) roundf(((float) vol
* (u
->hw_volume_max
- u
->hw_volume_min
)) / PA_VOLUME_NORM
) + u
->hw_volume_min
;
522 if ((err
= snd_mixer_selem_set_capture_volume(u
->mixer_elem
, i
, alsa_vol
)) < 0)
529 pa_log_error("Unable to set volume: %s", snd_strerror(err
));
531 s
->get_volume
= NULL
;
532 s
->set_volume
= NULL
;
536 static int source_get_mute_cb(pa_source
*s
) {
537 struct userdata
*u
= s
->userdata
;
541 pa_assert(u
->mixer_elem
);
543 if ((err
= snd_mixer_selem_get_capture_switch(u
->mixer_elem
, 0, &sw
)) < 0) {
544 pa_log_error("Unable to get switch: %s", snd_strerror(err
));
556 static int source_set_mute_cb(pa_source
*s
) {
557 struct userdata
*u
= s
->userdata
;
561 pa_assert(u
->mixer_elem
);
563 if ((err
= snd_mixer_selem_set_capture_switch_all(u
->mixer_elem
, !s
->muted
)) < 0) {
564 pa_log_error("Unable to set switch: %s", snd_strerror(err
));
574 static void thread_func(void *userdata
) {
575 struct userdata
*u
= userdata
;
579 pa_log_debug("Thread starting up");
581 if (u
->core
->high_priority
)
584 pa_thread_mq_install(&u
->thread_mq
);
585 pa_rtpoll_install(u
->rtpoll
);
587 if (build_pollfd(u
) < 0)
590 snd_pcm_start(u
->pcm_handle
);
593 pa_msgobject
*object
;
599 /* pa_log("loop"); */
601 /* Render some data and write it to the dsp */
602 if (PA_SOURCE_OPENED(u
->source
->thread_info
.state
)) {
605 if (mmap_read(u
) < 0)
609 if (unix_read(u
) < 0)
614 /* pa_log("loop2"); */
616 /* Check whether there is a message for us to process */
617 if (pa_asyncmsgq_get(u
->thread_mq
.inq
, &object
, &code
, &data
, &offset
, &chunk
, 0) == 0) {
620 /* pa_log("processing msg"); */
622 if (!object
&& code
== PA_MESSAGE_SHUTDOWN
) {
623 pa_asyncmsgq_done(u
->thread_mq
.inq
, 0);
627 ret
= pa_asyncmsgq_dispatch(object
, code
, data
, offset
, &chunk
);
628 pa_asyncmsgq_done(u
->thread_mq
.inq
, ret
);
632 if (pa_rtpoll_run(u
->rtpoll
) < 0) {
633 pa_log("poll() failed: %s", pa_cstrerror(errno
));
637 if (PA_SOURCE_OPENED(u
->source
->thread_info
.state
)) {
638 struct pollfd
*pollfd
;
639 unsigned short revents
= 0;
643 pollfd
= pa_rtpoll_item_get_pollfd(u
->alsa_rtpoll_item
, &n
);
645 if ((err
= snd_pcm_poll_descriptors_revents(u
->pcm_handle
, pollfd
, n
, &revents
)) < 0) {
646 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", snd_strerror(err
));
650 if (revents
& (POLLERR
|POLLNVAL
|POLLHUP
)) {
651 if (revents
& POLLERR
)
652 pa_log_warn("Got POLLERR from ALSA");
653 if (revents
& POLLNVAL
)
654 pa_log_warn("Got POLLNVAL from ALSA");
655 if (revents
& POLLHUP
)
656 pa_log_warn("Got POLLHUP from ALSA");
660 /* pa_log("got alsa event"); */
665 /* We have to continue processing messages until we receive the
666 * SHUTDOWN message */
667 pa_asyncmsgq_post(u
->thread_mq
.outq
, PA_MSGOBJECT(u
->core
), PA_CORE_MESSAGE_UNLOAD_MODULE
, u
->module
, 0, NULL
, NULL
);
668 pa_asyncmsgq_wait_for(u
->thread_mq
.inq
, PA_MESSAGE_SHUTDOWN
);
671 pa_log_debug("Thread shutting down");
674 int pa__init(pa_module
*m
) {
676 pa_modargs
*ma
= NULL
;
677 struct userdata
*u
= NULL
;
681 unsigned nfrags
, frag_size
;
682 snd_pcm_uframes_t period_size
;
684 snd_pcm_info_t
*pcm_info
= NULL
;
688 char *name_buf
= NULL
;
692 snd_pcm_info_alloca(&pcm_info
);
696 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
697 pa_log("Failed to parse module arguments");
701 ss
= m
->core
->default_sample_spec
;
702 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_ALSA
) < 0) {
703 pa_log("Failed to parse sample specification");
707 frame_size
= pa_frame_size(&ss
);
709 nfrags
= m
->core
->default_n_fragments
;
710 frag_size
= pa_usec_to_bytes(m
->core
->default_fragment_size_msec
*1000, &ss
);
712 frag_size
= frame_size
;
714 if (pa_modargs_get_value_u32(ma
, "fragments", &nfrags
) < 0 || pa_modargs_get_value_u32(ma
, "fragment_size", &frag_size
) < 0) {
715 pa_log("Failed to parse buffer metrics");
718 period_size
= frag_size
/frame_size
;
720 if (pa_modargs_get_value_boolean(ma
, "mmap", &use_mmap
) < 0) {
721 pa_log("Failed to parse mmap argument.");
725 u
= pa_xnew0(struct userdata
, 1);
729 u
->use_mmap
= use_mmap
;
730 pa_thread_mq_init(&u
->thread_mq
, m
->core
->mainloop
);
731 u
->rtpoll
= pa_rtpoll_new();
732 u
->alsa_rtpoll_item
= NULL
;
733 pa_rtpoll_item_new_asyncmsgq(u
->rtpoll
, u
->thread_mq
.inq
);
735 snd_config_update_free_global();
736 if ((err
= snd_pcm_open(&u
->pcm_handle
, dev
= pa_modargs_get_value(ma
, "device", DEFAULT_DEVICE
), SND_PCM_STREAM_CAPTURE
, SND_PCM_NONBLOCK
)) < 0) {
737 pa_log("Error opening PCM device %s: %s", dev
, snd_strerror(err
));
741 u
->device_name
= pa_xstrdup(dev
);
743 if ((err
= snd_pcm_info(u
->pcm_handle
, pcm_info
)) < 0) {
744 pa_log("Error fetching PCM info: %s", snd_strerror(err
));
749 if ((err
= pa_alsa_set_hw_params(u
->pcm_handle
, &ss
, &nfrags
, &period_size
, &b
)) < 0) {
750 pa_log("Failed to set hardware parameters: %s", snd_strerror(err
));
754 if (use_mmap
&& !b
) {
755 pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
756 u
->use_mmap
= use_mmap
= b
;
760 pa_log_info("Successfully enabled mmap() mode.");
762 if ((err
= pa_alsa_set_sw_params(u
->pcm_handle
)) < 0) {
763 pa_log("Failed to set software parameters: %s", snd_strerror(err
));
767 /* ALSA might tweak the sample spec, so recalculate the frame size */
768 frame_size
= pa_frame_size(&ss
);
770 if (ss
.channels
!= map
.channels
)
771 /* Seems ALSA didn't like the channel number, so let's fix the channel map */
772 pa_channel_map_init_auto(&map
, ss
.channels
, PA_CHANNEL_MAP_ALSA
);
774 if ((err
= snd_mixer_open(&u
->mixer_handle
, 0)) < 0)
775 pa_log("Error opening mixer: %s", snd_strerror(err
));
778 if ((pa_alsa_prepare_mixer(u
->mixer_handle
, dev
) < 0) ||
779 !(u
->mixer_elem
= pa_alsa_find_elem(u
->mixer_handle
, "Capture", NULL
))) {
780 snd_mixer_close(u
->mixer_handle
);
781 u
->mixer_handle
= NULL
;
785 if ((name
= pa_modargs_get_value(ma
, "source_name", NULL
)))
788 name
= name_buf
= pa_sprintf_malloc("alsa_input.%s", dev
);
792 u
->source
= pa_source_new(m
->core
, __FILE__
, name
, namereg_fail
, &ss
, &map
);
796 pa_log("Failed to create source object");
800 u
->source
->parent
.process_msg
= source_process_msg
;
801 u
->source
->userdata
= u
;
803 pa_source_set_module(u
->source
, m
);
804 pa_source_set_asyncmsgq(u
->source
, u
->thread_mq
.inq
);
805 pa_source_set_description(u
->source
, t
= pa_sprintf_malloc(
806 "ALSA PCM on %s (%s)%s",
808 snd_pcm_info_get_name(pcm_info
),
809 use_mmap
? " via DMA" : ""));
812 u
->source
->is_hardware
= 1;
814 u
->frame_size
= frame_size
;
815 u
->fragment_size
= frag_size
= period_size
* frame_size
;
816 u
->nfragments
= nfrags
;
817 u
->hwbuf_size
= u
->fragment_size
* nfrags
;
819 pa_log_info("Using %u fragments of size %lu bytes.", nfrags
, (long unsigned) u
->fragment_size
);
821 if (u
->mixer_handle
) {
822 assert(u
->mixer_elem
);
824 if (snd_mixer_selem_has_capture_volume(u
->mixer_elem
)) {
827 for (i
= 0;i
< ss
.channels
;i
++) {
828 if (!snd_mixer_selem_has_capture_channel(u
->mixer_elem
, i
))
832 if (i
== ss
.channels
) {
833 u
->source
->get_volume
= source_get_volume_cb
;
834 u
->source
->set_volume
= source_set_volume_cb
;
835 snd_mixer_selem_get_capture_volume_range(u
->mixer_elem
, &u
->hw_volume_min
, &u
->hw_volume_max
);
839 if (snd_mixer_selem_has_capture_switch(u
->mixer_elem
)) {
840 u
->source
->get_mute
= source_get_mute_cb
;
841 u
->source
->set_mute
= source_set_mute_cb
;
844 u
->mixer_fdl
= pa_alsa_fdlist_new();
846 if (pa_alsa_fdlist_set_mixer(u
->mixer_fdl
, u
->mixer_handle
, m
->core
->mainloop
) < 0) {
847 pa_log("failed to initialise file descriptor monitoring");
851 snd_mixer_elem_set_callback(u
->mixer_elem
, mixer_callback
);
852 snd_mixer_elem_set_callback_private(u
->mixer_elem
, u
);
856 if (!(u
->thread
= pa_thread_new(thread_func
, u
))) {
857 pa_log("Failed to create thread.");
860 /* Get initial mixer settings */
861 if (u
->source
->get_volume
)
862 u
->source
->get_volume(u
->source
);
863 if (u
->source
->get_mute
)
864 u
->source
->get_mute(u
->source
);
880 void pa__done(pa_module
*m
) {
885 if (!(u
= m
->userdata
))
889 pa_source_disconnect(u
->source
);
892 pa_asyncmsgq_send(u
->thread_mq
.inq
, NULL
, PA_MESSAGE_SHUTDOWN
, NULL
, 0, NULL
);
893 pa_thread_free(u
->thread
);
896 pa_thread_mq_done(&u
->thread_mq
);
899 pa_source_unref(u
->source
);
901 if (u
->alsa_rtpoll_item
)
902 pa_rtpoll_item_free(u
->alsa_rtpoll_item
);
905 pa_rtpoll_free(u
->rtpoll
);
908 pa_alsa_fdlist_free(u
->mixer_fdl
);
911 snd_mixer_close(u
->mixer_handle
);
914 snd_pcm_drop(u
->pcm_handle
);
915 snd_pcm_close(u
->pcm_handle
);
918 pa_xfree(u
->device_name
);
921 snd_config_update_free_global();