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 /* Hmm, process any rewind request that might be queued up */
182 pa_sink_process_rewind(u
->sink
, 0);
184 while (pa_memblockq_peek(u
->memblockq
, &tchunk
) < 0) {
187 pa_sink_render(u
->sink
, nbytes
, &nchunk
);
188 pa_memblockq_push(u
->memblockq
, &nchunk
);
189 pa_memblock_unref(nchunk
.memblock
);
192 tchunk
.length
= PA_MIN(nbytes
, tchunk
.length
);
193 pa_assert(tchunk
.length
> 0);
195 fs
= pa_frame_size(&i
->sample_spec
);
196 n
= (unsigned) (PA_MIN(tchunk
.length
, u
->block_size
) / fs
);
201 chunk
->length
= n
*fs
;
202 chunk
->memblock
= pa_memblock_new(i
->sink
->core
->mempool
, chunk
->length
);
204 pa_memblockq_drop(u
->memblockq
, chunk
->length
);
206 src
= (float*) ((uint8_t*) pa_memblock_acquire(tchunk
.memblock
) + tchunk
.index
);
207 dst
= (float*) pa_memblock_acquire(chunk
->memblock
);
209 for (c
= 0; c
< u
->channels
; c
++) {
210 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, u
->input
, sizeof(float), src
+c
, u
->channels
*sizeof(float), n
);
211 u
->descriptor
->run(u
->handle
[c
], n
);
212 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, dst
+c
, u
->channels
*sizeof(float), u
->output
, sizeof(float), n
);
215 pa_memblock_release(tchunk
.memblock
);
216 pa_memblock_release(chunk
->memblock
);
218 pa_memblock_unref(tchunk
.memblock
);
223 /* Called from I/O thread context */
224 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
228 pa_sink_input_assert_ref(i
);
229 pa_assert_se(u
= i
->userdata
);
231 if (!u
->sink
|| !PA_SINK_IS_OPENED(u
->sink
->thread_info
.state
))
234 if (u
->sink
->thread_info
.rewind_nbytes
> 0) {
237 max_rewrite
= nbytes
+ pa_memblockq_get_length(u
->memblockq
);
238 amount
= PA_MIN(u
->sink
->thread_info
.rewind_nbytes
, max_rewrite
);
239 u
->sink
->thread_info
.rewind_nbytes
= 0;
244 pa_memblockq_seek(u
->memblockq
, - (int64_t) amount
, PA_SEEK_RELATIVE
, TRUE
);
246 pa_log_debug("Resetting plugin");
248 /* Reset the plugin */
249 if (u
->descriptor
->deactivate
)
250 for (c
= 0; c
< u
->channels
; c
++)
251 u
->descriptor
->deactivate(u
->handle
[c
]);
252 if (u
->descriptor
->activate
)
253 for (c
= 0; c
< u
->channels
; c
++)
254 u
->descriptor
->activate(u
->handle
[c
]);
258 pa_sink_process_rewind(u
->sink
, amount
);
259 pa_memblockq_rewind(u
->memblockq
, nbytes
);
262 /* Called from I/O thread context */
263 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
266 pa_sink_input_assert_ref(i
);
267 pa_assert_se(u
= i
->userdata
);
269 if (!u
->sink
|| !PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
))
272 pa_memblockq_set_maxrewind(u
->memblockq
, nbytes
);
273 pa_sink_set_max_rewind_within_thread(u
->sink
, nbytes
);
276 /* Called from I/O thread context */
277 static void sink_input_update_max_request_cb(pa_sink_input
*i
, size_t nbytes
) {
280 pa_sink_input_assert_ref(i
);
281 pa_assert_se(u
= i
->userdata
);
283 if (!u
->sink
|| !PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
))
286 pa_sink_set_max_request_within_thread(u
->sink
, nbytes
);
289 /* Called from I/O thread context */
290 static void sink_input_update_sink_latency_range_cb(pa_sink_input
*i
) {
293 pa_sink_input_assert_ref(i
);
294 pa_assert_se(u
= i
->userdata
);
296 if (!u
->sink
|| !PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
))
299 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
302 /* Called from I/O thread context */
303 static void sink_input_detach_cb(pa_sink_input
*i
) {
306 pa_sink_input_assert_ref(i
);
307 pa_assert_se(u
= i
->userdata
);
309 if (!u
->sink
|| !PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
))
312 pa_sink_detach_within_thread(u
->sink
);
313 pa_sink_set_asyncmsgq(u
->sink
, NULL
);
314 pa_sink_set_rtpoll(u
->sink
, NULL
);
317 /* Called from I/O thread context */
318 static void sink_input_attach_cb(pa_sink_input
*i
) {
321 pa_sink_input_assert_ref(i
);
322 pa_assert_se(u
= i
->userdata
);
324 if (!u
->sink
|| !PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
))
327 pa_sink_set_asyncmsgq(u
->sink
, i
->sink
->asyncmsgq
);
328 pa_sink_set_rtpoll(u
->sink
, i
->sink
->rtpoll
);
329 pa_sink_attach_within_thread(u
->sink
);
331 pa_sink_set_latency_range_within_thread(u
->sink
, u
->master
->thread_info
.min_latency
, u
->master
->thread_info
.max_latency
);
334 /* Called from main context */
335 static void sink_input_kill_cb(pa_sink_input
*i
) {
338 pa_sink_input_assert_ref(i
);
339 pa_assert_se(u
= i
->userdata
);
341 pa_sink_unlink(u
->sink
);
342 pa_sink_input_unlink(u
->sink_input
);
344 pa_sink_unref(u
->sink
);
346 pa_sink_input_unref(u
->sink_input
);
347 u
->sink_input
= NULL
;
349 pa_module_unload_request(u
->module
, TRUE
);
352 /* Called from IO thread context */
353 static void sink_input_state_change_cb(pa_sink_input
*i
, pa_sink_input_state_t state
) {
356 pa_sink_input_assert_ref(i
);
357 pa_assert_se(u
= i
->userdata
);
359 /* If we are added for the first time, ask for a rewinding so that
360 * we are heard right-away. */
361 if (PA_SINK_INPUT_IS_LINKED(state
) &&
362 i
->thread_info
.state
== PA_SINK_INPUT_INIT
) {
363 pa_log_debug("Requesting rewind due to state change.");
364 pa_sink_input_request_rewind(i
, 0, FALSE
, TRUE
, TRUE
);
368 /* Called from main context */
369 static pa_bool_t
sink_input_may_move_to_cb(pa_sink_input
*i
, pa_sink
*dest
) {
372 pa_sink_input_assert_ref(i
);
373 pa_assert_se(u
= i
->userdata
);
375 return u
->sink
!= dest
;
378 int pa__init(pa_module
*m
) {
386 pa_sink_input_new_data sink_input_data
;
387 pa_sink_new_data sink_data
;
388 const char *plugin
, *label
;
389 LADSPA_Descriptor_Function descriptor_func
;
390 const char *e
, *cdata
;
391 const LADSPA_Descriptor
*d
;
392 unsigned long input_port
, output_port
, p
, j
, n_control
;
394 pa_bool_t
*use_default
= NULL
;
398 pa_assert(sizeof(LADSPA_Data
) == sizeof(float));
400 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
401 pa_log("Failed to parse module arguments.");
405 if (!(master
= pa_namereg_get(m
->core
, pa_modargs_get_value(ma
, "master", NULL
), PA_NAMEREG_SINK
))) {
406 pa_log("Master sink not found");
410 ss
= master
->sample_spec
;
411 ss
.format
= PA_SAMPLE_FLOAT32
;
412 map
= master
->channel_map
;
413 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_DEFAULT
) < 0) {
414 pa_log("Invalid sample format specification or channel map");
418 if (!(plugin
= pa_modargs_get_value(ma
, "plugin", NULL
))) {
419 pa_log("Missing LADSPA plugin name");
423 if (!(label
= pa_modargs_get_value(ma
, "label", NULL
))) {
424 pa_log("Missing LADSPA plugin label");
428 cdata
= pa_modargs_get_value(ma
, "control", NULL
);
430 u
= pa_xnew0(struct userdata
, 1);
436 u
->sink_input
= NULL
;
437 u
->memblockq
= pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH
, 0, pa_frame_size(&ss
), 1, 1, 0, NULL
);
439 if (!(e
= getenv("LADSPA_PATH")))
442 /* FIXME: This is not exactly thread safe */
443 t
= pa_xstrdup(lt_dlgetsearchpath());
444 lt_dlsetsearchpath(e
);
445 m
->dl
= lt_dlopenext(plugin
);
446 lt_dlsetsearchpath(t
);
450 pa_log("Failed to load LADSPA plugin: %s", lt_dlerror());
454 if (!(descriptor_func
= (LADSPA_Descriptor_Function
) pa_load_sym(m
->dl
, NULL
, "ladspa_descriptor"))) {
455 pa_log("LADSPA module lacks ladspa_descriptor() symbol.");
461 if (!(d
= descriptor_func(j
))) {
462 pa_log("Failed to find plugin label '%s' in plugin '%s'.", label
, plugin
);
466 if (strcmp(d
->Label
, label
) == 0)
472 pa_log_debug("Module: %s", plugin
);
473 pa_log_debug("Label: %s", d
->Label
);
474 pa_log_debug("Unique ID: %lu", d
->UniqueID
);
475 pa_log_debug("Name: %s", d
->Name
);
476 pa_log_debug("Maker: %s", d
->Maker
);
477 pa_log_debug("Copyright: %s", d
->Copyright
);
479 input_port
= output_port
= (unsigned long) -1;
482 for (p
= 0; p
< d
->PortCount
; p
++) {
484 if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
486 if (strcmp(d
->PortNames
[p
], "Input") == 0) {
487 pa_assert(input_port
== (unsigned long) -1);
490 pa_log("Found audio input port on plugin we cannot handle: %s", d
->PortNames
[p
]);
494 } else if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
496 if (strcmp(d
->PortNames
[p
], "Output") == 0) {
497 pa_assert(output_port
== (unsigned long) -1);
500 pa_log("Found audio output port on plugin we cannot handle: %s", d
->PortNames
[p
]);
504 } else if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
507 pa_assert(LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]));
508 pa_log_debug("Ignored control output port \"%s\".", d
->PortNames
[p
]);
512 if ((input_port
== (unsigned long) -1) || (output_port
== (unsigned long) -1)) {
513 pa_log("Failed to identify input and output ports. "
514 "Right now this module can only deal with plugins which provide an 'Input' and an 'Output' audio port. "
519 u
->block_size
= pa_frame_align(pa_mempool_block_size_max(m
->core
->mempool
), &ss
);
521 u
->input
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
522 if (LADSPA_IS_INPLACE_BROKEN(d
->Properties
))
523 u
->output
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
525 u
->output
= u
->input
;
527 u
->channels
= ss
.channels
;
529 for (c
= 0; c
< ss
.channels
; c
++) {
530 if (!(u
->handle
[c
] = d
->instantiate(d
, ss
.rate
))) {
531 pa_log("Failed to instantiate plugin %s with label %s for channel %i", plugin
, d
->Label
, c
);
535 d
->connect_port(u
->handle
[c
], input_port
, u
->input
);
536 d
->connect_port(u
->handle
[c
], output_port
, u
->output
);
539 if (!cdata
&& n_control
> 0) {
540 pa_log("This plugin requires specification of %lu control parameters.", n_control
);
545 const char *state
= NULL
;
549 u
->control
= pa_xnew(LADSPA_Data
, (unsigned) n_control
);
550 use_default
= pa_xnew(pa_bool_t
, (unsigned) n_control
);
553 while ((k
= pa_split(cdata
, ",", &state
)) && p
< n_control
) {
557 use_default
[p
++] = TRUE
;
562 if (pa_atod(k
, &f
) < 0) {
563 pa_log("Failed to parse control value '%s'", k
);
570 use_default
[p
] = FALSE
;
571 u
->control
[p
++] = (LADSPA_Data
) f
;
574 /* The previous loop doesn't take the last control value into account
575 if it is left empty, so we do it here. */
576 if (*cdata
== 0 || cdata
[strlen(cdata
) - 1] == ',') {
578 use_default
[p
] = TRUE
;
582 if (p
> n_control
|| k
) {
583 pa_log("Too many control values passed, %lu expected.", n_control
);
589 pa_log("Not enough control values passed, %lu expected, %lu passed.", n_control
, p
);
594 for (p
= 0; p
< d
->PortCount
; p
++) {
595 LADSPA_PortRangeHintDescriptor hint
= d
->PortRangeHints
[p
].HintDescriptor
;
597 if (!LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
600 if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
])) {
601 for (c
= 0; c
< ss
.channels
; c
++)
602 d
->connect_port(u
->handle
[c
], p
, &u
->control_out
);
606 pa_assert(h
< n_control
);
608 if (use_default
[h
]) {
609 LADSPA_Data lower
, upper
;
611 if (!LADSPA_IS_HINT_HAS_DEFAULT(hint
)) {
612 pa_log("Control port value left empty but plugin defines no default.");
616 lower
= d
->PortRangeHints
[p
].LowerBound
;
617 upper
= d
->PortRangeHints
[p
].UpperBound
;
619 if (LADSPA_IS_HINT_SAMPLE_RATE(hint
)) {
620 lower
*= (LADSPA_Data
) ss
.rate
;
621 upper
*= (LADSPA_Data
) ss
.rate
;
624 switch (hint
& LADSPA_HINT_DEFAULT_MASK
) {
626 case LADSPA_HINT_DEFAULT_MINIMUM
:
627 u
->control
[h
] = lower
;
630 case LADSPA_HINT_DEFAULT_MAXIMUM
:
631 u
->control
[h
] = upper
;
634 case LADSPA_HINT_DEFAULT_LOW
:
635 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
636 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.75 + log(upper
) * 0.25);
638 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.75 + upper
* 0.25);
641 case LADSPA_HINT_DEFAULT_MIDDLE
:
642 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
643 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.5 + log(upper
) * 0.5);
645 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.5 + upper
* 0.5);
648 case LADSPA_HINT_DEFAULT_HIGH
:
649 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
650 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.25 + log(upper
) * 0.75);
652 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.25 + upper
* 0.75);
655 case LADSPA_HINT_DEFAULT_0
:
659 case LADSPA_HINT_DEFAULT_1
:
663 case LADSPA_HINT_DEFAULT_100
:
667 case LADSPA_HINT_DEFAULT_440
:
672 pa_assert_not_reached();
676 if (LADSPA_IS_HINT_INTEGER(hint
))
677 u
->control
[h
] = roundf(u
->control
[h
]);
679 pa_log_debug("Binding %f to port %s", u
->control
[h
], d
->PortNames
[p
]);
681 for (c
= 0; c
< ss
.channels
; c
++)
682 d
->connect_port(u
->handle
[c
], p
, &u
->control
[h
]);
687 pa_assert(h
== n_control
);
691 for (c
= 0; c
< u
->channels
; c
++)
692 d
->activate(u
->handle
[c
]);
695 pa_sink_new_data_init(&sink_data
);
696 sink_data
.driver
= __FILE__
;
697 sink_data
.module
= m
;
698 if (!(sink_data
.name
= pa_xstrdup(pa_modargs_get_value(ma
, "sink_name", NULL
))))
699 sink_data
.name
= pa_sprintf_malloc("%s.ladspa", master
->name
);
700 sink_data
.namereg_fail
= FALSE
;
701 pa_sink_new_data_set_sample_spec(&sink_data
, &ss
);
702 pa_sink_new_data_set_channel_map(&sink_data
, &map
);
703 z
= pa_proplist_gets(master
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
704 pa_proplist_setf(sink_data
.proplist
, PA_PROP_DEVICE_DESCRIPTION
, "LADSPA Plugin %s on %s", label
, z
? z
: master
->name
);
705 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_MASTER_DEVICE
, master
->name
);
706 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_CLASS
, "filter");
707 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.module", plugin
);
708 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.label", d
->Label
);
709 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.name", d
->Name
);
710 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.maker", d
->Maker
);
711 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.copyright", d
->Copyright
);
712 pa_proplist_setf(sink_data
.proplist
, "device.ladspa.unique_id", "%lu", (unsigned long) d
->UniqueID
);
714 if (pa_modargs_get_proplist(ma
, "sink_properties", sink_data
.proplist
, PA_UPDATE_REPLACE
) < 0) {
715 pa_log("Invalid properties");
716 pa_sink_new_data_done(&sink_data
);
720 u
->sink
= pa_sink_new(m
->core
, &sink_data
, PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
);
721 pa_sink_new_data_done(&sink_data
);
724 pa_log("Failed to create sink.");
728 u
->sink
->parent
.process_msg
= sink_process_msg
;
729 u
->sink
->set_state
= sink_set_state
;
730 u
->sink
->update_requested_latency
= sink_update_requested_latency
;
731 u
->sink
->request_rewind
= sink_request_rewind
;
732 u
->sink
->userdata
= u
;
734 pa_sink_set_asyncmsgq(u
->sink
, master
->asyncmsgq
);
735 pa_sink_set_rtpoll(u
->sink
, master
->rtpoll
);
737 /* Create sink input */
738 pa_sink_input_new_data_init(&sink_input_data
);
739 sink_input_data
.driver
= __FILE__
;
740 sink_input_data
.module
= m
;
741 sink_input_data
.sink
= u
->master
;
742 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_NAME
, "LADSPA Stream");
743 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_ROLE
, "filter");
744 pa_sink_input_new_data_set_sample_spec(&sink_input_data
, &ss
);
745 pa_sink_input_new_data_set_channel_map(&sink_input_data
, &map
);
747 pa_sink_input_new(&u
->sink_input
, m
->core
, &sink_input_data
, PA_SINK_INPUT_DONT_MOVE
);
748 pa_sink_input_new_data_done(&sink_input_data
);
753 u
->sink_input
->pop
= sink_input_pop_cb
;
754 u
->sink_input
->process_rewind
= sink_input_process_rewind_cb
;
755 u
->sink_input
->update_max_rewind
= sink_input_update_max_rewind_cb
;
756 u
->sink_input
->update_max_request
= sink_input_update_max_request_cb
;
757 u
->sink_input
->update_sink_latency_range
= sink_input_update_sink_latency_range_cb
;
758 u
->sink_input
->kill
= sink_input_kill_cb
;
759 u
->sink_input
->attach
= sink_input_attach_cb
;
760 u
->sink_input
->detach
= sink_input_detach_cb
;
761 u
->sink_input
->state_change
= sink_input_state_change_cb
;
762 u
->sink_input
->may_move_to
= sink_input_may_move_to_cb
;
763 u
->sink_input
->userdata
= u
;
765 pa_sink_put(u
->sink
);
766 pa_sink_input_put(u
->sink_input
);
770 pa_xfree(use_default
);
778 pa_xfree(use_default
);
785 int pa__get_n_used(pa_module
*m
) {
789 pa_assert_se(u
= m
->userdata
);
791 return pa_sink_linked_by(u
->sink
);
794 void pa__done(pa_module
*m
) {
800 if (!(u
= m
->userdata
))
804 pa_sink_unlink(u
->sink
);
805 pa_sink_unref(u
->sink
);
809 pa_sink_input_unlink(u
->sink_input
);
810 pa_sink_input_unref(u
->sink_input
);
813 for (c
= 0; c
< u
->channels
; c
++)
815 if (u
->descriptor
->deactivate
)
816 u
->descriptor
->deactivate(u
->handle
[c
]);
817 u
->descriptor
->cleanup(u
->handle
[c
]);
820 if (u
->output
!= u
->input
)
824 pa_memblockq_free(u
->memblockq
);
828 pa_xfree(u
->control
);