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_input
*sink_input
;
72 const LADSPA_Descriptor
*descriptor
;
74 LADSPA_Handle handle
[PA_CHANNELS_MAX
];
75 LADSPA_Data
*input
, *output
;
77 unsigned long input_port
, output_port
;
80 /* This is a dummy buffer. Every port must be connected, but we don't care
81 about control out ports. We connect them all to this single buffer. */
82 LADSPA_Data control_out
;
84 pa_memblockq
*memblockq
;
87 static const char* const valid_modargs
[] = {
101 /* Called from I/O thread context */
102 static int sink_process_msg(pa_msgobject
*o
, int code
, void *data
, int64_t offset
, pa_memchunk
*chunk
) {
103 struct userdata
*u
= PA_SINK(o
)->userdata
;
107 case PA_SINK_MESSAGE_GET_LATENCY
:
109 /* The sink is _put() before the sink input is, so let's
110 * make sure we don't access it in that time. Also, the
111 * sink input is first shut down, the sink second. */
112 if (!PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
) ||
113 !PA_SINK_INPUT_IS_LINKED(u
->sink_input
->thread_info
.state
)) {
114 *((pa_usec_t
*) data
) = 0;
118 *((pa_usec_t
*) data
) =
120 /* Get the latency of the master sink */
121 pa_sink_get_latency_within_thread(u
->sink_input
->sink
) +
123 /* Add the latency internal to our sink input on top */
124 pa_bytes_to_usec(pa_memblockq_get_length(u
->sink_input
->thread_info
.render_memblockq
), &u
->sink_input
->sink
->sample_spec
);
129 return pa_sink_process_msg(o
, code
, data
, offset
, chunk
);
132 /* Called from main context */
133 static int sink_set_state(pa_sink
*s
, pa_sink_state_t state
) {
136 pa_sink_assert_ref(s
);
137 pa_assert_se(u
= s
->userdata
);
139 if (!PA_SINK_IS_LINKED(state
) ||
140 !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u
->sink_input
)))
143 pa_sink_input_cork(u
->sink_input
, state
== PA_SINK_SUSPENDED
);
147 /* Called from I/O thread context */
148 static void sink_request_rewind(pa_sink
*s
) {
151 pa_sink_assert_ref(s
);
152 pa_assert_se(u
= s
->userdata
);
154 if (!PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
) ||
155 !PA_SINK_INPUT_IS_LINKED(u
->sink_input
->thread_info
.state
))
158 /* Just hand this one over to the master sink */
159 pa_sink_input_request_rewind(u
->sink_input
, s
->thread_info
.rewind_nbytes
+ pa_memblockq_get_length(u
->memblockq
), TRUE
, FALSE
, FALSE
);
162 /* Called from I/O thread context */
163 static void sink_update_requested_latency(pa_sink
*s
) {
166 pa_sink_assert_ref(s
);
167 pa_assert_se(u
= s
->userdata
);
169 if (!PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
) ||
170 !PA_SINK_INPUT_IS_LINKED(u
->sink_input
->thread_info
.state
))
173 /* Just hand this one over to the master sink */
174 pa_sink_input_set_requested_latency_within_thread(
176 pa_sink_get_requested_latency_within_thread(s
));
179 /* Called from I/O thread context */
180 static int sink_input_pop_cb(pa_sink_input
*i
, size_t nbytes
, pa_memchunk
*chunk
) {
187 pa_sink_input_assert_ref(i
);
189 pa_assert_se(u
= i
->userdata
);
191 /* Hmm, process any rewind request that might be queued up */
192 pa_sink_process_rewind(u
->sink
, 0);
194 while (pa_memblockq_peek(u
->memblockq
, &tchunk
) < 0) {
197 pa_sink_render(u
->sink
, nbytes
, &nchunk
);
198 pa_memblockq_push(u
->memblockq
, &nchunk
);
199 pa_memblock_unref(nchunk
.memblock
);
202 tchunk
.length
= PA_MIN(nbytes
, tchunk
.length
);
203 pa_assert(tchunk
.length
> 0);
205 fs
= pa_frame_size(&i
->sample_spec
);
206 n
= (unsigned) (PA_MIN(tchunk
.length
, u
->block_size
) / fs
);
211 chunk
->length
= n
*fs
;
212 chunk
->memblock
= pa_memblock_new(i
->sink
->core
->mempool
, chunk
->length
);
214 pa_memblockq_drop(u
->memblockq
, chunk
->length
);
216 src
= (float*) ((uint8_t*) pa_memblock_acquire(tchunk
.memblock
) + tchunk
.index
);
217 dst
= (float*) pa_memblock_acquire(chunk
->memblock
);
219 for (c
= 0; c
< u
->channels
; c
++) {
220 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, u
->input
, sizeof(float), src
+c
, u
->channels
*sizeof(float), n
);
221 u
->descriptor
->run(u
->handle
[c
], n
);
222 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, dst
+c
, u
->channels
*sizeof(float), u
->output
, sizeof(float), n
);
225 pa_memblock_release(tchunk
.memblock
);
226 pa_memblock_release(chunk
->memblock
);
228 pa_memblock_unref(tchunk
.memblock
);
233 /* Called from I/O thread context */
234 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
238 pa_sink_input_assert_ref(i
);
239 pa_assert_se(u
= i
->userdata
);
241 if (u
->sink
->thread_info
.rewind_nbytes
> 0) {
244 max_rewrite
= nbytes
+ pa_memblockq_get_length(u
->memblockq
);
245 amount
= PA_MIN(u
->sink
->thread_info
.rewind_nbytes
, max_rewrite
);
246 u
->sink
->thread_info
.rewind_nbytes
= 0;
251 pa_memblockq_seek(u
->memblockq
, - (int64_t) amount
, PA_SEEK_RELATIVE
, TRUE
);
253 pa_log_debug("Resetting plugin");
255 /* Reset the plugin */
256 if (u
->descriptor
->deactivate
)
257 for (c
= 0; c
< u
->channels
; c
++)
258 u
->descriptor
->deactivate(u
->handle
[c
]);
259 if (u
->descriptor
->activate
)
260 for (c
= 0; c
< u
->channels
; c
++)
261 u
->descriptor
->activate(u
->handle
[c
]);
265 pa_sink_process_rewind(u
->sink
, amount
);
266 pa_memblockq_rewind(u
->memblockq
, nbytes
);
269 /* Called from I/O thread context */
270 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
273 pa_sink_input_assert_ref(i
);
274 pa_assert_se(u
= i
->userdata
);
276 pa_memblockq_set_maxrewind(u
->memblockq
, nbytes
);
277 pa_sink_set_max_rewind_within_thread(u
->sink
, nbytes
);
280 /* Called from I/O thread context */
281 static void sink_input_update_max_request_cb(pa_sink_input
*i
, size_t nbytes
) {
284 pa_sink_input_assert_ref(i
);
285 pa_assert_se(u
= i
->userdata
);
287 pa_sink_set_max_request_within_thread(u
->sink
, nbytes
);
290 /* Called from I/O thread context */
291 static void sink_input_update_sink_latency_range_cb(pa_sink_input
*i
) {
294 pa_sink_input_assert_ref(i
);
295 pa_assert_se(u
= i
->userdata
);
297 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
300 /* Called from I/O thread context */
301 static void sink_input_update_sink_fixed_latency_cb(pa_sink_input
*i
) {
304 pa_sink_input_assert_ref(i
);
305 pa_assert_se(u
= i
->userdata
);
307 pa_sink_set_fixed_latency_within_thread(u
->sink
, i
->sink
->thread_info
.fixed_latency
);
310 /* Called from I/O thread context */
311 static void sink_input_detach_cb(pa_sink_input
*i
) {
314 pa_sink_input_assert_ref(i
);
315 pa_assert_se(u
= i
->userdata
);
317 pa_sink_detach_within_thread(u
->sink
);
319 pa_sink_set_rtpoll(u
->sink
, NULL
);
322 /* Called from I/O thread context */
323 static void sink_input_attach_cb(pa_sink_input
*i
) {
326 pa_sink_input_assert_ref(i
);
327 pa_assert_se(u
= i
->userdata
);
329 pa_sink_set_rtpoll(u
->sink
, i
->sink
->thread_info
.rtpoll
);
330 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
331 pa_sink_set_fixed_latency_within_thread(u
->sink
, i
->sink
->thread_info
.fixed_latency
);
332 pa_sink_set_max_request_within_thread(u
->sink
, pa_sink_input_get_max_request(i
));
333 pa_sink_set_max_rewind_within_thread(u
->sink
, pa_sink_input_get_max_rewind(i
));
335 pa_sink_attach_within_thread(u
->sink
);
338 /* Called from main context */
339 static void sink_input_kill_cb(pa_sink_input
*i
) {
342 pa_sink_input_assert_ref(i
);
343 pa_assert_se(u
= i
->userdata
);
345 /* The order here matters! We first kill the sink input, followed
346 * by the sink. That means the sink callbacks must be protected
347 * against an unconnected sink input! */
348 pa_sink_input_unlink(u
->sink_input
);
349 pa_sink_unlink(u
->sink
);
351 pa_sink_input_unref(u
->sink_input
);
352 u
->sink_input
= NULL
;
354 pa_sink_unref(u
->sink
);
357 pa_module_unload_request(u
->module
, TRUE
);
360 /* Called from IO thread context */
361 static void sink_input_state_change_cb(pa_sink_input
*i
, pa_sink_input_state_t state
) {
364 pa_sink_input_assert_ref(i
);
365 pa_assert_se(u
= i
->userdata
);
367 /* If we are added for the first time, ask for a rewinding so that
368 * we are heard right-away. */
369 if (PA_SINK_INPUT_IS_LINKED(state
) &&
370 i
->thread_info
.state
== PA_SINK_INPUT_INIT
) {
371 pa_log_debug("Requesting rewind due to state change.");
372 pa_sink_input_request_rewind(i
, 0, FALSE
, TRUE
, TRUE
);
376 /* Called from main context */
377 static pa_bool_t
sink_input_may_move_to_cb(pa_sink_input
*i
, pa_sink
*dest
) {
380 pa_sink_input_assert_ref(i
);
381 pa_assert_se(u
= i
->userdata
);
383 return u
->sink
!= dest
;
386 /* Called from main context */
387 static void sink_input_moving_cb(pa_sink_input
*i
, pa_sink
*dest
) {
390 pa_sink_input_assert_ref(i
);
391 pa_assert_se(u
= i
->userdata
);
393 pa_sink_set_asyncmsgq(u
->sink
, dest
->asyncmsgq
);
394 pa_sink_update_flags(u
->sink
, PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
, dest
->flags
);
397 int pa__init(pa_module
*m
) {
405 pa_sink_input_new_data sink_input_data
;
406 pa_sink_new_data sink_data
;
407 const char *plugin
, *label
;
408 LADSPA_Descriptor_Function descriptor_func
;
409 const char *e
, *cdata
;
410 const LADSPA_Descriptor
*d
;
411 unsigned long input_port
, output_port
, p
, j
, n_control
;
413 pa_bool_t
*use_default
= NULL
;
417 pa_assert_cc(sizeof(LADSPA_Data
) == sizeof(float));
419 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
420 pa_log("Failed to parse module arguments.");
424 if (!(master
= pa_namereg_get(m
->core
, pa_modargs_get_value(ma
, "master", NULL
), PA_NAMEREG_SINK
))) {
425 pa_log("Master sink not found");
429 ss
= master
->sample_spec
;
430 ss
.format
= PA_SAMPLE_FLOAT32
;
431 map
= master
->channel_map
;
432 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_DEFAULT
) < 0) {
433 pa_log("Invalid sample format specification or channel map");
437 if (!(plugin
= pa_modargs_get_value(ma
, "plugin", NULL
))) {
438 pa_log("Missing LADSPA plugin name");
442 if (!(label
= pa_modargs_get_value(ma
, "label", NULL
))) {
443 pa_log("Missing LADSPA plugin label");
447 cdata
= pa_modargs_get_value(ma
, "control", NULL
);
449 u
= pa_xnew0(struct userdata
, 1);
452 u
->memblockq
= pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH
, 0, pa_frame_size(&ss
), 1, 1, 0, NULL
);
454 if (!(e
= getenv("LADSPA_PATH")))
457 /* FIXME: This is not exactly thread safe */
458 t
= pa_xstrdup(lt_dlgetsearchpath());
459 lt_dlsetsearchpath(e
);
460 m
->dl
= lt_dlopenext(plugin
);
461 lt_dlsetsearchpath(t
);
465 pa_log("Failed to load LADSPA plugin: %s", lt_dlerror());
469 if (!(descriptor_func
= (LADSPA_Descriptor_Function
) pa_load_sym(m
->dl
, NULL
, "ladspa_descriptor"))) {
470 pa_log("LADSPA module lacks ladspa_descriptor() symbol.");
476 if (!(d
= descriptor_func(j
))) {
477 pa_log("Failed to find plugin label '%s' in plugin '%s'.", label
, plugin
);
481 if (strcmp(d
->Label
, label
) == 0)
487 pa_log_debug("Module: %s", plugin
);
488 pa_log_debug("Label: %s", d
->Label
);
489 pa_log_debug("Unique ID: %lu", d
->UniqueID
);
490 pa_log_debug("Name: %s", d
->Name
);
491 pa_log_debug("Maker: %s", d
->Maker
);
492 pa_log_debug("Copyright: %s", d
->Copyright
);
494 input_port
= output_port
= (unsigned long) -1;
497 for (p
= 0; p
< d
->PortCount
; p
++) {
499 if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
501 if (strcmp(d
->PortNames
[p
], "Input") == 0) {
502 pa_assert(input_port
== (unsigned long) -1);
505 pa_log("Found audio input port on plugin we cannot handle: %s", d
->PortNames
[p
]);
509 } else if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
511 if (strcmp(d
->PortNames
[p
], "Output") == 0) {
512 pa_assert(output_port
== (unsigned long) -1);
515 pa_log("Found audio output port on plugin we cannot handle: %s", d
->PortNames
[p
]);
519 } else if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
522 pa_assert(LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]));
523 pa_log_debug("Ignored control output port \"%s\".", d
->PortNames
[p
]);
527 if ((input_port
== (unsigned long) -1) || (output_port
== (unsigned long) -1)) {
528 pa_log("Failed to identify input and output ports. "
529 "Right now this module can only deal with plugins which provide an 'Input' and an 'Output' audio port. "
534 u
->block_size
= pa_frame_align(pa_mempool_block_size_max(m
->core
->mempool
), &ss
);
536 u
->input
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
537 if (LADSPA_IS_INPLACE_BROKEN(d
->Properties
))
538 u
->output
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
540 u
->output
= u
->input
;
542 u
->channels
= ss
.channels
;
544 for (c
= 0; c
< ss
.channels
; c
++) {
545 if (!(u
->handle
[c
] = d
->instantiate(d
, ss
.rate
))) {
546 pa_log("Failed to instantiate plugin %s with label %s for channel %i", plugin
, d
->Label
, c
);
550 d
->connect_port(u
->handle
[c
], input_port
, u
->input
);
551 d
->connect_port(u
->handle
[c
], output_port
, u
->output
);
554 if (!cdata
&& n_control
> 0) {
555 pa_log("This plugin requires specification of %lu control parameters.", n_control
);
560 const char *state
= NULL
;
564 u
->control
= pa_xnew(LADSPA_Data
, (unsigned) n_control
);
565 use_default
= pa_xnew(pa_bool_t
, (unsigned) n_control
);
568 while ((k
= pa_split(cdata
, ",", &state
)) && p
< n_control
) {
572 use_default
[p
++] = TRUE
;
577 if (pa_atod(k
, &f
) < 0) {
578 pa_log("Failed to parse control value '%s'", k
);
585 use_default
[p
] = FALSE
;
586 u
->control
[p
++] = (LADSPA_Data
) f
;
589 /* The previous loop doesn't take the last control value into account
590 if it is left empty, so we do it here. */
591 if (*cdata
== 0 || cdata
[strlen(cdata
) - 1] == ',') {
593 use_default
[p
] = TRUE
;
597 if (p
> n_control
|| k
) {
598 pa_log("Too many control values passed, %lu expected.", n_control
);
604 pa_log("Not enough control values passed, %lu expected, %lu passed.", n_control
, p
);
609 for (p
= 0; p
< d
->PortCount
; p
++) {
610 LADSPA_PortRangeHintDescriptor hint
= d
->PortRangeHints
[p
].HintDescriptor
;
612 if (!LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
615 if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
])) {
616 for (c
= 0; c
< ss
.channels
; c
++)
617 d
->connect_port(u
->handle
[c
], p
, &u
->control_out
);
621 pa_assert(h
< n_control
);
623 if (use_default
[h
]) {
624 LADSPA_Data lower
, upper
;
626 if (!LADSPA_IS_HINT_HAS_DEFAULT(hint
)) {
627 pa_log("Control port value left empty but plugin defines no default.");
631 lower
= d
->PortRangeHints
[p
].LowerBound
;
632 upper
= d
->PortRangeHints
[p
].UpperBound
;
634 if (LADSPA_IS_HINT_SAMPLE_RATE(hint
)) {
635 lower
*= (LADSPA_Data
) ss
.rate
;
636 upper
*= (LADSPA_Data
) ss
.rate
;
639 switch (hint
& LADSPA_HINT_DEFAULT_MASK
) {
641 case LADSPA_HINT_DEFAULT_MINIMUM
:
642 u
->control
[h
] = lower
;
645 case LADSPA_HINT_DEFAULT_MAXIMUM
:
646 u
->control
[h
] = upper
;
649 case LADSPA_HINT_DEFAULT_LOW
:
650 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
651 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.75 + log(upper
) * 0.25);
653 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.75 + upper
* 0.25);
656 case LADSPA_HINT_DEFAULT_MIDDLE
:
657 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
658 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.5 + log(upper
) * 0.5);
660 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.5 + upper
* 0.5);
663 case LADSPA_HINT_DEFAULT_HIGH
:
664 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
665 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.25 + log(upper
) * 0.75);
667 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.25 + upper
* 0.75);
670 case LADSPA_HINT_DEFAULT_0
:
674 case LADSPA_HINT_DEFAULT_1
:
678 case LADSPA_HINT_DEFAULT_100
:
682 case LADSPA_HINT_DEFAULT_440
:
687 pa_assert_not_reached();
691 if (LADSPA_IS_HINT_INTEGER(hint
))
692 u
->control
[h
] = roundf(u
->control
[h
]);
694 pa_log_debug("Binding %f to port %s", u
->control
[h
], d
->PortNames
[p
]);
696 for (c
= 0; c
< ss
.channels
; c
++)
697 d
->connect_port(u
->handle
[c
], p
, &u
->control
[h
]);
702 pa_assert(h
== n_control
);
706 for (c
= 0; c
< u
->channels
; c
++)
707 d
->activate(u
->handle
[c
]);
710 pa_sink_new_data_init(&sink_data
);
711 sink_data
.driver
= __FILE__
;
712 sink_data
.module
= m
;
713 if (!(sink_data
.name
= pa_xstrdup(pa_modargs_get_value(ma
, "sink_name", NULL
))))
714 sink_data
.name
= pa_sprintf_malloc("%s.ladspa", master
->name
);
715 pa_sink_new_data_set_sample_spec(&sink_data
, &ss
);
716 pa_sink_new_data_set_channel_map(&sink_data
, &map
);
717 z
= pa_proplist_gets(master
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
718 pa_proplist_setf(sink_data
.proplist
, PA_PROP_DEVICE_DESCRIPTION
, "LADSPA Plugin %s on %s", d
->Name
, z
? z
: master
->name
);
719 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_MASTER_DEVICE
, master
->name
);
720 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_CLASS
, "filter");
721 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.module", plugin
);
722 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.label", d
->Label
);
723 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.name", d
->Name
);
724 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.maker", d
->Maker
);
725 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.copyright", d
->Copyright
);
726 pa_proplist_setf(sink_data
.proplist
, "device.ladspa.unique_id", "%lu", (unsigned long) d
->UniqueID
);
728 if (pa_modargs_get_proplist(ma
, "sink_properties", sink_data
.proplist
, PA_UPDATE_REPLACE
) < 0) {
729 pa_log("Invalid properties");
730 pa_sink_new_data_done(&sink_data
);
734 u
->sink
= pa_sink_new(m
->core
, &sink_data
, master
->flags
& (PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
));
735 pa_sink_new_data_done(&sink_data
);
738 pa_log("Failed to create sink.");
742 u
->sink
->parent
.process_msg
= sink_process_msg
;
743 u
->sink
->set_state
= sink_set_state
;
744 u
->sink
->update_requested_latency
= sink_update_requested_latency
;
745 u
->sink
->request_rewind
= sink_request_rewind
;
746 u
->sink
->userdata
= u
;
748 pa_sink_set_asyncmsgq(u
->sink
, master
->asyncmsgq
);
750 /* Create sink input */
751 pa_sink_input_new_data_init(&sink_input_data
);
752 sink_input_data
.driver
= __FILE__
;
753 sink_input_data
.module
= m
;
754 sink_input_data
.sink
= master
;
755 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_NAME
, "LADSPA Stream");
756 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_ROLE
, "filter");
757 pa_sink_input_new_data_set_sample_spec(&sink_input_data
, &ss
);
758 pa_sink_input_new_data_set_channel_map(&sink_input_data
, &map
);
760 pa_sink_input_new(&u
->sink_input
, m
->core
, &sink_input_data
, 0);
761 pa_sink_input_new_data_done(&sink_input_data
);
766 u
->sink_input
->pop
= sink_input_pop_cb
;
767 u
->sink_input
->process_rewind
= sink_input_process_rewind_cb
;
768 u
->sink_input
->update_max_rewind
= sink_input_update_max_rewind_cb
;
769 u
->sink_input
->update_max_request
= sink_input_update_max_request_cb
;
770 u
->sink_input
->update_sink_latency_range
= sink_input_update_sink_latency_range_cb
;
771 u
->sink_input
->update_sink_fixed_latency
= sink_input_update_sink_fixed_latency_cb
;
772 u
->sink_input
->kill
= sink_input_kill_cb
;
773 u
->sink_input
->attach
= sink_input_attach_cb
;
774 u
->sink_input
->detach
= sink_input_detach_cb
;
775 u
->sink_input
->state_change
= sink_input_state_change_cb
;
776 u
->sink_input
->may_move_to
= sink_input_may_move_to_cb
;
777 u
->sink_input
->moving
= sink_input_moving_cb
;
778 u
->sink_input
->userdata
= u
;
780 pa_sink_put(u
->sink
);
781 pa_sink_input_put(u
->sink_input
);
785 pa_xfree(use_default
);
793 pa_xfree(use_default
);
800 int pa__get_n_used(pa_module
*m
) {
804 pa_assert_se(u
= m
->userdata
);
806 return pa_sink_linked_by(u
->sink
);
809 void pa__done(pa_module
*m
) {
815 if (!(u
= m
->userdata
))
818 /* See comments in sink_input_kill_cb() above regarding
819 * destruction order! */
822 pa_sink_input_unlink(u
->sink_input
);
825 pa_sink_unlink(u
->sink
);
828 pa_sink_input_unref(u
->sink_input
);
831 pa_sink_unref(u
->sink
);
833 for (c
= 0; c
< u
->channels
; c
++)
835 if (u
->descriptor
->deactivate
)
836 u
->descriptor
->deactivate(u
->handle
[c
]);
837 u
->descriptor
->cleanup(u
->handle
[c
]);
840 if (u
->output
!= u
->input
)
844 pa_memblockq_free(u
->memblockq
);
848 pa_xfree(u
->control
);