2 This file is part of PulseAudio.
4 Copyright 2004-2008 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 /* TODO: Some plugins cause latency, and some even report it by using a control
23 out port. We don't currently use the latency information. */
29 #include <pulse/xmalloc.h>
30 #include <pulse/i18n.h>
32 #include <pulsecore/core-error.h>
33 #include <pulsecore/namereg.h>
34 #include <pulsecore/sink.h>
35 #include <pulsecore/module.h>
36 #include <pulsecore/core-util.h>
37 #include <pulsecore/modargs.h>
38 #include <pulsecore/log.h>
39 #include <pulsecore/thread.h>
40 #include <pulsecore/thread-mq.h>
41 #include <pulsecore/rtpoll.h>
42 #include <pulsecore/sample-util.h>
43 #include <pulsecore/ltdl-helper.h>
45 #include "module-ladspa-sink-symdef.h"
48 PA_MODULE_AUTHOR("Lennart Poettering");
49 PA_MODULE_DESCRIPTION(_("Virtual LADSPA sink"));
50 PA_MODULE_VERSION(PACKAGE_VERSION);
51 PA_MODULE_LOAD_ONCE(FALSE);
53 _("sink_name=<name for the sink> "
54 "sink_properties=<properties for the sink> "
55 "master=<name of sink to filter> "
56 "format=<sample format> "
58 "channels=<number of channels> "
59 "channel_map=<channel map> "
60 "plugin=<ladspa plugin name> "
61 "label=<ladspa plugin label> "
62 "control=<comma seperated list of input control values>"));
64 #define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
70 pa_sink *sink, *master;
71 pa_sink_input *sink_input;
73 const LADSPA_Descriptor *descriptor;
75 LADSPA_Handle handle[PA_CHANNELS_MAX];
76 LADSPA_Data *input, *output;
78 unsigned long input_port, output_port;
81 /* This is a dummy buffer. Every port must be connected, but we don't care
82 about control out ports. We connect them all to this single buffer. */
83 LADSPA_Data control_out;
85 pa_memblockq *memblockq;
88 static const char* const valid_modargs[] = {
102 /* Called from I/O thread context */
103 static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
104 struct userdata *u = PA_SINK(o)->userdata;
108 case PA_SINK_MESSAGE_GET_LATENCY: {
111 /* Get the latency of the master sink */
112 if (PA_MSGOBJECT(u->master)->process_msg(PA_MSGOBJECT(u->master), PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
115 /* Add the latency internal to our sink input on top */
116 usec += pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->master->sample_spec);
118 *((pa_usec_t*) data) = usec;
123 return pa_sink_process_msg(o, code, data, offset, chunk);
126 /* Called from main context */
127 static int sink_set_state(pa_sink *s, pa_sink_state_t state) {
130 pa_sink_assert_ref(s);
131 pa_assert_se(u = s->userdata);
133 if (PA_SINK_IS_LINKED(state) &&
135 PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u->sink_input)))
137 pa_sink_input_cork(u->sink_input, state == PA_SINK_SUSPENDED);
142 /* Called from I/O thread context */
143 static void sink_request_rewind(pa_sink *s) {
146 pa_sink_assert_ref(s);
147 pa_assert_se(u = s->userdata);
149 /* Just hand this one over to the master sink */
150 pa_sink_input_request_rewind(u->sink_input, s->thread_info.rewind_nbytes + pa_memblockq_get_length(u->memblockq), TRUE, FALSE, FALSE);
153 /* Called from I/O thread context */
154 static void sink_update_requested_latency(pa_sink *s) {
157 pa_sink_assert_ref(s);
158 pa_assert_se(u = s->userdata);
160 /* Just hand this one over to the master sink */
161 pa_sink_input_set_requested_latency_within_thread(
163 pa_sink_get_requested_latency_within_thread(s));
166 /* Called from I/O thread context */
167 static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
174 pa_sink_input_assert_ref(i);
176 pa_assert_se(u = i->userdata);
178 if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state))
181 while (pa_memblockq_peek(u->memblockq, &tchunk) < 0) {
184 pa_sink_render(u->sink, nbytes, &nchunk);
185 pa_memblockq_push(u->memblockq, &nchunk);
186 pa_memblock_unref(nchunk.memblock);
189 tchunk.length = PA_MIN(nbytes, tchunk.length);
190 pa_assert(tchunk.length > 0);
192 fs = pa_frame_size(&i->sample_spec);
193 n = (unsigned) (PA_MIN(tchunk.length, u->block_size) / fs);
198 chunk->length = n*fs;
199 chunk->memblock = pa_memblock_new(i->sink->core->mempool, chunk->length);
201 pa_memblockq_drop(u->memblockq, chunk->length);
203 src = (float*) ((uint8_t*) pa_memblock_acquire(tchunk.memblock) + tchunk.index);
204 dst = (float*) pa_memblock_acquire(chunk->memblock);
206 for (c = 0; c < u->channels; c++) {
207 pa_sample_clamp(PA_SAMPLE_FLOAT32NE, u->input, sizeof(float), src+c, u->channels*sizeof(float), n);
208 u->descriptor->run(u->handle[c], n);
209 pa_sample_clamp(PA_SAMPLE_FLOAT32NE, dst+c, u->channels*sizeof(float), u->output, sizeof(float), n);
212 pa_memblock_release(tchunk.memblock);
213 pa_memblock_release(chunk->memblock);
215 pa_memblock_unref(tchunk.memblock);
220 /* Called from I/O thread context */
221 static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
225 pa_sink_input_assert_ref(i);
226 pa_assert_se(u = i->userdata);
228 if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state))
231 if (u->sink->thread_info.rewind_nbytes > 0) {
234 max_rewrite = nbytes + pa_memblockq_get_length(u->memblockq);
235 amount = PA_MIN(u->sink->thread_info.rewind_nbytes, max_rewrite);
236 u->sink->thread_info.rewind_nbytes = 0;
241 pa_memblockq_seek(u->memblockq, - (int64_t) amount, PA_SEEK_RELATIVE, TRUE);
243 pa_log_debug("Resetting plugin");
245 /* Reset the plugin */
246 if (u->descriptor->deactivate)
247 for (c = 0; c < u->channels; c++)
248 u->descriptor->deactivate(u->handle[c]);
249 if (u->descriptor->activate)
250 for (c = 0; c < u->channels; c++)
251 u->descriptor->activate(u->handle[c]);
255 pa_sink_process_rewind(u->sink, amount);
256 pa_memblockq_rewind(u->memblockq, nbytes);
259 /* Called from I/O thread context */
260 static void sink_input_update_max_rewind_cb(pa_sink_input *i, size_t nbytes) {
263 pa_sink_input_assert_ref(i);
264 pa_assert_se(u = i->userdata);
266 if (!u->sink || !PA_SINK_IS_LINKED(u->sink->thread_info.state))
269 pa_memblockq_set_maxrewind(u->memblockq, nbytes);
270 pa_sink_set_max_rewind_within_thread(u->sink, nbytes);
273 /* Called from I/O thread context */
274 static void sink_input_update_max_request_cb(pa_sink_input *i, size_t nbytes) {
277 pa_sink_input_assert_ref(i);
278 pa_assert_se(u = i->userdata);
280 if (!u->sink || !PA_SINK_IS_LINKED(u->sink->thread_info.state))
283 pa_sink_set_max_request_within_thread(u->sink, nbytes);
286 /* Called from I/O thread context */
287 static void sink_input_update_sink_latency_range_cb(pa_sink_input *i) {
290 pa_sink_input_assert_ref(i);
291 pa_assert_se(u = i->userdata);
293 if (!u->sink || !PA_SINK_IS_LINKED(u->sink->thread_info.state))
296 pa_sink_set_latency_range_within_thread(u->sink, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
299 /* Called from I/O thread context */
300 static void sink_input_detach_cb(pa_sink_input *i) {
303 pa_sink_input_assert_ref(i);
304 pa_assert_se(u = i->userdata);
306 if (!u->sink || !PA_SINK_IS_LINKED(u->sink->thread_info.state))
309 pa_sink_detach_within_thread(u->sink);
310 pa_sink_set_asyncmsgq(u->sink, NULL);
311 pa_sink_set_rtpoll(u->sink, NULL);
314 /* Called from I/O thread context */
315 static void sink_input_attach_cb(pa_sink_input *i) {
318 pa_sink_input_assert_ref(i);
319 pa_assert_se(u = i->userdata);
321 if (!u->sink || !PA_SINK_IS_LINKED(u->sink->thread_info.state))
324 pa_sink_set_asyncmsgq(u->sink, i->sink->asyncmsgq);
325 pa_sink_set_rtpoll(u->sink, i->sink->rtpoll);
326 pa_sink_attach_within_thread(u->sink);
328 pa_sink_set_latency_range_within_thread(u->sink, u->master->thread_info.min_latency, u->master->thread_info.max_latency);
331 /* Called from main context */
332 static void sink_input_kill_cb(pa_sink_input *i) {
335 pa_sink_input_assert_ref(i);
336 pa_assert_se(u = i->userdata);
338 pa_sink_unlink(u->sink);
339 pa_sink_input_unlink(u->sink_input);
341 pa_sink_unref(u->sink);
343 pa_sink_input_unref(u->sink_input);
344 u->sink_input = NULL;
346 pa_module_unload_request(u->module, TRUE);
349 /* Called from IO thread context */
350 static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t state) {
353 pa_sink_input_assert_ref(i);
354 pa_assert_se(u = i->userdata);
356 /* If we are added for the first time, ask for a rewinding so that
357 * we are heard right-away. */
358 if (PA_SINK_INPUT_IS_LINKED(state) &&
359 i->thread_info.state == PA_SINK_INPUT_INIT) {
360 pa_log_debug("Requesting rewind due to state change.");
361 pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE);
365 /* Called from main context */
366 static pa_bool_t sink_input_may_move_to_cb(pa_sink_input *i, pa_sink *dest) {
369 pa_sink_input_assert_ref(i);
370 pa_assert_se(u = i->userdata);
372 return u->sink != dest;
375 int pa__init(pa_module*m) {
383 pa_sink_input_new_data sink_input_data;
384 pa_sink_new_data sink_data;
385 const char *plugin, *label;
386 LADSPA_Descriptor_Function descriptor_func;
387 const char *e, *cdata;
388 const LADSPA_Descriptor *d;
389 unsigned long input_port, output_port, p, j, n_control;
391 pa_bool_t *use_default = NULL;
395 pa_assert(sizeof(LADSPA_Data) == sizeof(float));
397 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
398 pa_log("Failed to parse module arguments.");
402 if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "master", NULL), PA_NAMEREG_SINK))) {
403 pa_log("Master sink not found");
407 ss = master->sample_spec;
408 ss.format = PA_SAMPLE_FLOAT32;
409 map = master->channel_map;
410 if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
411 pa_log("Invalid sample format specification or channel map");
415 if (!(plugin = pa_modargs_get_value(ma, "plugin", NULL))) {
416 pa_log("Missing LADSPA plugin name");
420 if (!(label = pa_modargs_get_value(ma, "label", NULL))) {
421 pa_log("Missing LADSPA plugin label");
425 cdata = pa_modargs_get_value(ma, "control", NULL);
427 u = pa_xnew0(struct userdata, 1);
433 u->sink_input = NULL;
434 u->memblockq = pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH, 0, pa_frame_size(&ss), 1, 1, 0, NULL);
436 if (!(e = getenv("LADSPA_PATH")))
439 /* FIXME: This is not exactly thread safe */
440 t = pa_xstrdup(lt_dlgetsearchpath());
441 lt_dlsetsearchpath(e);
442 m->dl = lt_dlopenext(plugin);
443 lt_dlsetsearchpath(t);
447 pa_log("Failed to load LADSPA plugin: %s", lt_dlerror());
451 if (!(descriptor_func = (LADSPA_Descriptor_Function) pa_load_sym(m->dl, NULL, "ladspa_descriptor"))) {
452 pa_log("LADSPA module lacks ladspa_descriptor() symbol.");
458 if (!(d = descriptor_func(j))) {
459 pa_log("Failed to find plugin label '%s' in plugin '%s'.", label, plugin);
463 if (strcmp(d->Label, label) == 0)
469 pa_log_debug("Module: %s", plugin);
470 pa_log_debug("Label: %s", d->Label);
471 pa_log_debug("Unique ID: %lu", d->UniqueID);
472 pa_log_debug("Name: %s", d->Name);
473 pa_log_debug("Maker: %s", d->Maker);
474 pa_log_debug("Copyright: %s", d->Copyright);
476 input_port = output_port = (unsigned long) -1;
479 for (p = 0; p < d->PortCount; p++) {
481 if (LADSPA_IS_PORT_INPUT(d->PortDescriptors[p]) && LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p])) {
483 if (strcmp(d->PortNames[p], "Input") == 0) {
484 pa_assert(input_port == (unsigned long) -1);
487 pa_log("Found audio input port on plugin we cannot handle: %s", d->PortNames[p]);
491 } else if (LADSPA_IS_PORT_OUTPUT(d->PortDescriptors[p]) && LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p])) {
493 if (strcmp(d->PortNames[p], "Output") == 0) {
494 pa_assert(output_port == (unsigned long) -1);
497 pa_log("Found audio output port on plugin we cannot handle: %s", d->PortNames[p]);
501 } else if (LADSPA_IS_PORT_INPUT(d->PortDescriptors[p]) && LADSPA_IS_PORT_CONTROL(d->PortDescriptors[p]))
504 pa_assert(LADSPA_IS_PORT_OUTPUT(d->PortDescriptors[p]) && LADSPA_IS_PORT_CONTROL(d->PortDescriptors[p]));
505 pa_log_debug("Ignored control output port \"%s\".", d->PortNames[p]);
509 if ((input_port == (unsigned long) -1) || (output_port == (unsigned long) -1)) {
510 pa_log("Failed to identify input and output ports. "
511 "Right now this module can only deal with plugins which provide an 'Input' and an 'Output' audio port. "
516 u->block_size = pa_frame_align(pa_mempool_block_size_max(m->core->mempool), &ss);
518 u->input = (LADSPA_Data*) pa_xnew(uint8_t, (unsigned) u->block_size);
519 if (LADSPA_IS_INPLACE_BROKEN(d->Properties))
520 u->output = (LADSPA_Data*) pa_xnew(uint8_t, (unsigned) u->block_size);
522 u->output = u->input;
524 u->channels = ss.channels;
526 for (c = 0; c < ss.channels; c++) {
527 if (!(u->handle[c] = d->instantiate(d, ss.rate))) {
528 pa_log("Failed to instantiate plugin %s with label %s for channel %i", plugin, d->Label, c);
532 d->connect_port(u->handle[c], input_port, u->input);
533 d->connect_port(u->handle[c], output_port, u->output);
536 if (!cdata && n_control > 0) {
537 pa_log("This plugin requires specification of %lu control parameters.", n_control);
542 const char *state = NULL;
546 u->control = pa_xnew(LADSPA_Data, (unsigned) n_control);
547 use_default = pa_xnew(pa_bool_t, (unsigned) n_control);
550 while ((k = pa_split(cdata, ",", &state)) && p < n_control) {
554 use_default[p++] = TRUE;
559 if (pa_atod(k, &f) < 0) {
560 pa_log("Failed to parse control value '%s'", k);
567 use_default[p] = FALSE;
568 u->control[p++] = (LADSPA_Data) f;
571 /* The previous loop doesn't take the last control value into account
572 if it is left empty, so we do it here. */
573 if (*cdata == 0 || cdata[strlen(cdata) - 1] == ',') {
575 use_default[p] = TRUE;
579 if (p > n_control || k) {
580 pa_log("Too many control values passed, %lu expected.", n_control);
586 pa_log("Not enough control values passed, %lu expected, %lu passed.", n_control, p);
591 for (p = 0; p < d->PortCount; p++) {
592 LADSPA_PortRangeHintDescriptor hint = d->PortRangeHints[p].HintDescriptor;
594 if (!LADSPA_IS_PORT_CONTROL(d->PortDescriptors[p]))
597 if (LADSPA_IS_PORT_OUTPUT(d->PortDescriptors[p])) {
598 for (c = 0; c < ss.channels; c++)
599 d->connect_port(u->handle[c], p, &u->control_out);
603 pa_assert(h < n_control);
605 if (use_default[h]) {
606 LADSPA_Data lower, upper;
608 if (!LADSPA_IS_HINT_HAS_DEFAULT(hint)) {
609 pa_log("Control port value left empty but plugin defines no default.");
613 lower = d->PortRangeHints[p].LowerBound;
614 upper = d->PortRangeHints[p].UpperBound;
616 if (LADSPA_IS_HINT_SAMPLE_RATE(hint)) {
617 lower *= (LADSPA_Data) ss.rate;
618 upper *= (LADSPA_Data) ss.rate;
621 switch (hint & LADSPA_HINT_DEFAULT_MASK) {
623 case LADSPA_HINT_DEFAULT_MINIMUM:
624 u->control[h] = lower;
627 case LADSPA_HINT_DEFAULT_MAXIMUM:
628 u->control[h] = upper;
631 case LADSPA_HINT_DEFAULT_LOW:
632 if (LADSPA_IS_HINT_LOGARITHMIC(hint))
633 u->control[h] = (LADSPA_Data) exp(log(lower) * 0.75 + log(upper) * 0.25);
635 u->control[h] = (LADSPA_Data) (lower * 0.75 + upper * 0.25);
638 case LADSPA_HINT_DEFAULT_MIDDLE:
639 if (LADSPA_IS_HINT_LOGARITHMIC(hint))
640 u->control[h] = (LADSPA_Data) exp(log(lower) * 0.5 + log(upper) * 0.5);
642 u->control[h] = (LADSPA_Data) (lower * 0.5 + upper * 0.5);
645 case LADSPA_HINT_DEFAULT_HIGH:
646 if (LADSPA_IS_HINT_LOGARITHMIC(hint))
647 u->control[h] = (LADSPA_Data) exp(log(lower) * 0.25 + log(upper) * 0.75);
649 u->control[h] = (LADSPA_Data) (lower * 0.25 + upper * 0.75);
652 case LADSPA_HINT_DEFAULT_0:
656 case LADSPA_HINT_DEFAULT_1:
660 case LADSPA_HINT_DEFAULT_100:
664 case LADSPA_HINT_DEFAULT_440:
669 pa_assert_not_reached();
673 if (LADSPA_IS_HINT_INTEGER(hint))
674 u->control[h] = roundf(u->control[h]);
676 pa_log_debug("Binding %f to port %s", u->control[h], d->PortNames[p]);
678 for (c = 0; c < ss.channels; c++)
679 d->connect_port(u->handle[c], p, &u->control[h]);
684 pa_assert(h == n_control);
688 for (c = 0; c < u->channels; c++)
689 d->activate(u->handle[c]);
692 pa_sink_new_data_init(&sink_data);
693 sink_data.driver = __FILE__;
694 sink_data.module = m;
695 if (!(sink_data.name = pa_xstrdup(pa_modargs_get_value(ma, "sink_name", NULL))))
696 sink_data.name = pa_sprintf_malloc("%s.ladspa", master->name);
697 sink_data.namereg_fail = FALSE;
698 pa_sink_new_data_set_sample_spec(&sink_data, &ss);
699 pa_sink_new_data_set_channel_map(&sink_data, &map);
700 z = pa_proplist_gets(master->proplist, PA_PROP_DEVICE_DESCRIPTION);
701 pa_proplist_setf(sink_data.proplist, PA_PROP_DEVICE_DESCRIPTION, "LADSPA Plugin %s on %s", label, z ? z : master->name);
702 pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_MASTER_DEVICE, master->name);
703 pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_CLASS, "filter");
704 pa_proplist_sets(sink_data.proplist, "device.ladspa.module", plugin);
705 pa_proplist_sets(sink_data.proplist, "device.ladspa.label", d->Label);
706 pa_proplist_sets(sink_data.proplist, "device.ladspa.name", d->Name);
707 pa_proplist_sets(sink_data.proplist, "device.ladspa.maker", d->Maker);
708 pa_proplist_sets(sink_data.proplist, "device.ladspa.copyright", d->Copyright);
709 pa_proplist_setf(sink_data.proplist, "device.ladspa.unique_id", "%lu", (unsigned long) d->UniqueID);
711 if (pa_modargs_get_proplist(ma, "sink_properties", sink_data.proplist, PA_UPDATE_REPLACE) < 0) {
712 pa_log("Invalid properties");
713 pa_sink_new_data_done(&sink_data);
717 u->sink = pa_sink_new(m->core, &sink_data, PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY);
718 pa_sink_new_data_done(&sink_data);
721 pa_log("Failed to create sink.");
725 u->sink->parent.process_msg = sink_process_msg;
726 u->sink->set_state = sink_set_state;
727 u->sink->update_requested_latency = sink_update_requested_latency;
728 u->sink->request_rewind = sink_request_rewind;
729 u->sink->userdata = u;
731 pa_sink_set_asyncmsgq(u->sink, master->asyncmsgq);
732 pa_sink_set_rtpoll(u->sink, master->rtpoll);
734 /* Create sink input */
735 pa_sink_input_new_data_init(&sink_input_data);
736 sink_input_data.driver = __FILE__;
737 sink_input_data.module = m;
738 sink_input_data.sink = u->master;
739 pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "LADSPA Stream");
740 pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
741 pa_sink_input_new_data_set_sample_spec(&sink_input_data, &ss);
742 pa_sink_input_new_data_set_channel_map(&sink_input_data, &map);
744 pa_sink_input_new(&u->sink_input, m->core, &sink_input_data, PA_SINK_INPUT_DONT_MOVE);
745 pa_sink_input_new_data_done(&sink_input_data);
750 u->sink_input->pop = sink_input_pop_cb;
751 u->sink_input->process_rewind = sink_input_process_rewind_cb;
752 u->sink_input->update_max_rewind = sink_input_update_max_rewind_cb;
753 u->sink_input->update_max_request = sink_input_update_max_request_cb;
754 u->sink_input->update_sink_latency_range = sink_input_update_sink_latency_range_cb;
755 u->sink_input->kill = sink_input_kill_cb;
756 u->sink_input->attach = sink_input_attach_cb;
757 u->sink_input->detach = sink_input_detach_cb;
758 u->sink_input->state_change = sink_input_state_change_cb;
759 u->sink_input->may_move_to = sink_input_may_move_to_cb;
760 u->sink_input->userdata = u;
762 pa_sink_put(u->sink);
763 pa_sink_input_put(u->sink_input);
767 pa_xfree(use_default);
775 pa_xfree(use_default);
782 int pa__get_n_used(pa_module *m) {
786 pa_assert_se(u = m->userdata);
788 return pa_sink_linked_by(u->sink);
791 void pa__done(pa_module*m) {
797 if (!(u = m->userdata))
801 pa_sink_unlink(u->sink);
802 pa_sink_unref(u->sink);
806 pa_sink_input_unlink(u->sink_input);
807 pa_sink_input_unref(u->sink_input);
810 for (c = 0; c < u->channels; c++)
812 if (u->descriptor->deactivate)
813 u->descriptor->deactivate(u->handle[c]);
814 u->descriptor->cleanup(u->handle[c]);
817 if (u->output != u->input)
821 pa_memblockq_free(u->memblockq);
825 pa_xfree(u->control);