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_cb(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_cb(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_cb(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_cb(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 main context */
180 static void sink_set_volume_cb(pa_sink
*s
) {
183 pa_sink_assert_ref(s
);
184 pa_assert_se(u
= s
->userdata
);
186 if (!PA_SINK_IS_LINKED(pa_sink_get_state(s
)) ||
187 !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u
->sink_input
)))
190 pa_sink_input_set_volume(u
->sink_input
, &s
->real_volume
, s
->save_volume
, TRUE
);
193 /* Called from main context */
194 static void sink_set_mute_cb(pa_sink
*s
) {
197 pa_sink_assert_ref(s
);
198 pa_assert_se(u
= s
->userdata
);
200 if (!PA_SINK_IS_LINKED(pa_sink_get_state(s
)) ||
201 !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u
->sink_input
)))
204 pa_sink_input_set_mute(u
->sink_input
, s
->muted
, s
->save_muted
);
207 /* Called from I/O thread context */
208 static int sink_input_pop_cb(pa_sink_input
*i
, size_t nbytes
, pa_memchunk
*chunk
) {
215 pa_sink_input_assert_ref(i
);
217 pa_assert_se(u
= i
->userdata
);
219 /* Hmm, process any rewind request that might be queued up */
220 pa_sink_process_rewind(u
->sink
, 0);
222 while (pa_memblockq_peek(u
->memblockq
, &tchunk
) < 0) {
225 pa_sink_render(u
->sink
, nbytes
, &nchunk
);
226 pa_memblockq_push(u
->memblockq
, &nchunk
);
227 pa_memblock_unref(nchunk
.memblock
);
230 tchunk
.length
= PA_MIN(nbytes
, tchunk
.length
);
231 pa_assert(tchunk
.length
> 0);
233 fs
= pa_frame_size(&i
->sample_spec
);
234 n
= (unsigned) (PA_MIN(tchunk
.length
, u
->block_size
) / fs
);
239 chunk
->length
= n
*fs
;
240 chunk
->memblock
= pa_memblock_new(i
->sink
->core
->mempool
, chunk
->length
);
242 pa_memblockq_drop(u
->memblockq
, chunk
->length
);
244 src
= (float*) ((uint8_t*) pa_memblock_acquire(tchunk
.memblock
) + tchunk
.index
);
245 dst
= (float*) pa_memblock_acquire(chunk
->memblock
);
247 for (c
= 0; c
< u
->channels
; c
++) {
248 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, u
->input
, sizeof(float), src
+c
, u
->channels
*sizeof(float), n
);
249 u
->descriptor
->run(u
->handle
[c
], n
);
250 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, dst
+c
, u
->channels
*sizeof(float), u
->output
, sizeof(float), n
);
253 pa_memblock_release(tchunk
.memblock
);
254 pa_memblock_release(chunk
->memblock
);
256 pa_memblock_unref(tchunk
.memblock
);
261 /* Called from I/O thread context */
262 static void sink_input_process_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
->thread_info
.rewind_nbytes
> 0) {
272 max_rewrite
= nbytes
+ pa_memblockq_get_length(u
->memblockq
);
273 amount
= PA_MIN(u
->sink
->thread_info
.rewind_nbytes
, max_rewrite
);
274 u
->sink
->thread_info
.rewind_nbytes
= 0;
279 pa_memblockq_seek(u
->memblockq
, - (int64_t) amount
, PA_SEEK_RELATIVE
, TRUE
);
281 pa_log_debug("Resetting plugin");
283 /* Reset the plugin */
284 if (u
->descriptor
->deactivate
)
285 for (c
= 0; c
< u
->channels
; c
++)
286 u
->descriptor
->deactivate(u
->handle
[c
]);
287 if (u
->descriptor
->activate
)
288 for (c
= 0; c
< u
->channels
; c
++)
289 u
->descriptor
->activate(u
->handle
[c
]);
293 pa_sink_process_rewind(u
->sink
, amount
);
294 pa_memblockq_rewind(u
->memblockq
, nbytes
);
297 /* Called from I/O thread context */
298 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
301 pa_sink_input_assert_ref(i
);
302 pa_assert_se(u
= i
->userdata
);
304 pa_memblockq_set_maxrewind(u
->memblockq
, nbytes
);
305 pa_sink_set_max_rewind_within_thread(u
->sink
, nbytes
);
308 /* Called from I/O thread context */
309 static void sink_input_update_max_request_cb(pa_sink_input
*i
, size_t nbytes
) {
312 pa_sink_input_assert_ref(i
);
313 pa_assert_se(u
= i
->userdata
);
315 pa_sink_set_max_request_within_thread(u
->sink
, nbytes
);
318 /* Called from I/O thread context */
319 static void sink_input_update_sink_latency_range_cb(pa_sink_input
*i
) {
322 pa_sink_input_assert_ref(i
);
323 pa_assert_se(u
= i
->userdata
);
325 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
328 /* Called from I/O thread context */
329 static void sink_input_update_sink_fixed_latency_cb(pa_sink_input
*i
) {
332 pa_sink_input_assert_ref(i
);
333 pa_assert_se(u
= i
->userdata
);
335 pa_sink_set_fixed_latency_within_thread(u
->sink
, i
->sink
->thread_info
.fixed_latency
);
338 /* Called from I/O thread context */
339 static void sink_input_detach_cb(pa_sink_input
*i
) {
342 pa_sink_input_assert_ref(i
);
343 pa_assert_se(u
= i
->userdata
);
345 pa_sink_detach_within_thread(u
->sink
);
347 pa_sink_set_rtpoll(u
->sink
, NULL
);
350 /* Called from I/O thread context */
351 static void sink_input_attach_cb(pa_sink_input
*i
) {
354 pa_sink_input_assert_ref(i
);
355 pa_assert_se(u
= i
->userdata
);
357 pa_sink_set_rtpoll(u
->sink
, i
->sink
->thread_info
.rtpoll
);
358 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
359 pa_sink_set_fixed_latency_within_thread(u
->sink
, i
->sink
->thread_info
.fixed_latency
);
360 pa_sink_set_max_request_within_thread(u
->sink
, pa_sink_input_get_max_request(i
));
361 pa_sink_set_max_rewind_within_thread(u
->sink
, pa_sink_input_get_max_rewind(i
));
363 pa_sink_attach_within_thread(u
->sink
);
366 /* Called from main context */
367 static void sink_input_kill_cb(pa_sink_input
*i
) {
370 pa_sink_input_assert_ref(i
);
371 pa_assert_se(u
= i
->userdata
);
373 /* The order here matters! We first kill the sink input, followed
374 * by the sink. That means the sink callbacks must be protected
375 * against an unconnected sink input! */
376 pa_sink_input_unlink(u
->sink_input
);
377 pa_sink_unlink(u
->sink
);
379 pa_sink_input_unref(u
->sink_input
);
380 u
->sink_input
= NULL
;
382 pa_sink_unref(u
->sink
);
385 pa_module_unload_request(u
->module
, TRUE
);
388 /* Called from IO thread context */
389 static void sink_input_state_change_cb(pa_sink_input
*i
, pa_sink_input_state_t state
) {
392 pa_sink_input_assert_ref(i
);
393 pa_assert_se(u
= i
->userdata
);
395 /* If we are added for the first time, ask for a rewinding so that
396 * we are heard right-away. */
397 if (PA_SINK_INPUT_IS_LINKED(state
) &&
398 i
->thread_info
.state
== PA_SINK_INPUT_INIT
) {
399 pa_log_debug("Requesting rewind due to state change.");
400 pa_sink_input_request_rewind(i
, 0, FALSE
, TRUE
, TRUE
);
404 /* Called from main context */
405 static pa_bool_t
sink_input_may_move_to_cb(pa_sink_input
*i
, pa_sink
*dest
) {
408 pa_sink_input_assert_ref(i
);
409 pa_assert_se(u
= i
->userdata
);
411 return u
->sink
!= dest
;
414 /* Called from main context */
415 static void sink_input_moving_cb(pa_sink_input
*i
, pa_sink
*dest
) {
418 pa_sink_input_assert_ref(i
);
419 pa_assert_se(u
= i
->userdata
);
422 pa_sink_set_asyncmsgq(u
->sink
, dest
->asyncmsgq
);
423 pa_sink_update_flags(u
->sink
, PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
, dest
->flags
);
425 pa_sink_set_asyncmsgq(u
->sink
, NULL
);
428 /* Called from main context */
429 static void sink_input_volume_changed_cb(pa_sink_input
*i
) {
432 pa_sink_input_assert_ref(i
);
433 pa_assert_se(u
= i
->userdata
);
435 pa_sink_volume_changed(u
->sink
, &i
->volume
);
438 /* Called from main context */
439 static void sink_input_mute_changed_cb(pa_sink_input
*i
) {
442 pa_sink_input_assert_ref(i
);
443 pa_assert_se(u
= i
->userdata
);
445 pa_sink_mute_changed(u
->sink
, i
->muted
);
448 int pa__init(pa_module
*m
) {
456 pa_sink_input_new_data sink_input_data
;
457 pa_sink_new_data sink_data
;
458 const char *plugin
, *label
;
459 LADSPA_Descriptor_Function descriptor_func
;
460 const char *e
, *cdata
;
461 const LADSPA_Descriptor
*d
;
462 unsigned long input_port
, output_port
, p
, j
, n_control
;
464 pa_bool_t
*use_default
= NULL
;
468 pa_assert_cc(sizeof(LADSPA_Data
) == sizeof(float));
470 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
471 pa_log("Failed to parse module arguments.");
475 if (!(master
= pa_namereg_get(m
->core
, pa_modargs_get_value(ma
, "master", NULL
), PA_NAMEREG_SINK
))) {
476 pa_log("Master sink not found");
480 ss
= master
->sample_spec
;
481 ss
.format
= PA_SAMPLE_FLOAT32
;
482 map
= master
->channel_map
;
483 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_DEFAULT
) < 0) {
484 pa_log("Invalid sample format specification or channel map");
488 if (!(plugin
= pa_modargs_get_value(ma
, "plugin", NULL
))) {
489 pa_log("Missing LADSPA plugin name");
493 if (!(label
= pa_modargs_get_value(ma
, "label", NULL
))) {
494 pa_log("Missing LADSPA plugin label");
498 cdata
= pa_modargs_get_value(ma
, "control", NULL
);
500 u
= pa_xnew0(struct userdata
, 1);
503 u
->memblockq
= pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH
, 0, pa_frame_size(&ss
), 1, 1, 0, NULL
);
505 if (!(e
= getenv("LADSPA_PATH")))
508 /* FIXME: This is not exactly thread safe */
509 t
= pa_xstrdup(lt_dlgetsearchpath());
510 lt_dlsetsearchpath(e
);
511 m
->dl
= lt_dlopenext(plugin
);
512 lt_dlsetsearchpath(t
);
516 pa_log("Failed to load LADSPA plugin: %s", lt_dlerror());
520 if (!(descriptor_func
= (LADSPA_Descriptor_Function
) pa_load_sym(m
->dl
, NULL
, "ladspa_descriptor"))) {
521 pa_log("LADSPA module lacks ladspa_descriptor() symbol.");
527 if (!(d
= descriptor_func(j
))) {
528 pa_log("Failed to find plugin label '%s' in plugin '%s'.", label
, plugin
);
532 if (strcmp(d
->Label
, label
) == 0)
538 pa_log_debug("Module: %s", plugin
);
539 pa_log_debug("Label: %s", d
->Label
);
540 pa_log_debug("Unique ID: %lu", d
->UniqueID
);
541 pa_log_debug("Name: %s", d
->Name
);
542 pa_log_debug("Maker: %s", d
->Maker
);
543 pa_log_debug("Copyright: %s", d
->Copyright
);
545 input_port
= output_port
= (unsigned long) -1;
548 for (p
= 0; p
< d
->PortCount
; p
++) {
550 if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
552 if (strcmp(d
->PortNames
[p
], "Input") == 0) {
553 pa_assert(input_port
== (unsigned long) -1);
556 pa_log("Found audio input port on plugin we cannot handle: %s", d
->PortNames
[p
]);
560 } else if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
562 if (strcmp(d
->PortNames
[p
], "Output") == 0) {
563 pa_assert(output_port
== (unsigned long) -1);
566 pa_log("Found audio output port on plugin we cannot handle: %s", d
->PortNames
[p
]);
570 } else if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
573 pa_assert(LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]));
574 pa_log_debug("Ignored control output port \"%s\".", d
->PortNames
[p
]);
578 if ((input_port
== (unsigned long) -1) || (output_port
== (unsigned long) -1)) {
579 pa_log("Failed to identify input and output ports. "
580 "Right now this module can only deal with plugins which provide an 'Input' and an 'Output' audio port. "
585 u
->block_size
= pa_frame_align(pa_mempool_block_size_max(m
->core
->mempool
), &ss
);
587 u
->input
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
588 if (LADSPA_IS_INPLACE_BROKEN(d
->Properties
))
589 u
->output
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
591 u
->output
= u
->input
;
593 u
->channels
= ss
.channels
;
595 for (c
= 0; c
< ss
.channels
; c
++) {
596 if (!(u
->handle
[c
] = d
->instantiate(d
, ss
.rate
))) {
597 pa_log("Failed to instantiate plugin %s with label %s for channel %i", plugin
, d
->Label
, c
);
601 d
->connect_port(u
->handle
[c
], input_port
, u
->input
);
602 d
->connect_port(u
->handle
[c
], output_port
, u
->output
);
605 if (!cdata
&& n_control
> 0) {
606 pa_log("This plugin requires specification of %lu control parameters.", n_control
);
611 const char *state
= NULL
;
615 u
->control
= pa_xnew(LADSPA_Data
, (unsigned) n_control
);
616 use_default
= pa_xnew(pa_bool_t
, (unsigned) n_control
);
619 while ((k
= pa_split(cdata
, ",", &state
)) && p
< n_control
) {
623 use_default
[p
++] = TRUE
;
628 if (pa_atod(k
, &f
) < 0) {
629 pa_log("Failed to parse control value '%s'", k
);
636 use_default
[p
] = FALSE
;
637 u
->control
[p
++] = (LADSPA_Data
) f
;
640 /* The previous loop doesn't take the last control value into account
641 if it is left empty, so we do it here. */
642 if (*cdata
== 0 || cdata
[strlen(cdata
) - 1] == ',') {
644 use_default
[p
] = TRUE
;
648 if (p
> n_control
|| k
) {
649 pa_log("Too many control values passed, %lu expected.", n_control
);
655 pa_log("Not enough control values passed, %lu expected, %lu passed.", n_control
, p
);
660 for (p
= 0; p
< d
->PortCount
; p
++) {
661 LADSPA_PortRangeHintDescriptor hint
= d
->PortRangeHints
[p
].HintDescriptor
;
663 if (!LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
666 if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
])) {
667 for (c
= 0; c
< ss
.channels
; c
++)
668 d
->connect_port(u
->handle
[c
], p
, &u
->control_out
);
672 pa_assert(h
< n_control
);
674 if (use_default
[h
]) {
675 LADSPA_Data lower
, upper
;
677 if (!LADSPA_IS_HINT_HAS_DEFAULT(hint
)) {
678 pa_log("Control port value left empty but plugin defines no default.");
682 lower
= d
->PortRangeHints
[p
].LowerBound
;
683 upper
= d
->PortRangeHints
[p
].UpperBound
;
685 if (LADSPA_IS_HINT_SAMPLE_RATE(hint
)) {
686 lower
*= (LADSPA_Data
) ss
.rate
;
687 upper
*= (LADSPA_Data
) ss
.rate
;
690 switch (hint
& LADSPA_HINT_DEFAULT_MASK
) {
692 case LADSPA_HINT_DEFAULT_MINIMUM
:
693 u
->control
[h
] = lower
;
696 case LADSPA_HINT_DEFAULT_MAXIMUM
:
697 u
->control
[h
] = upper
;
700 case LADSPA_HINT_DEFAULT_LOW
:
701 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
702 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.75 + log(upper
) * 0.25);
704 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.75 + upper
* 0.25);
707 case LADSPA_HINT_DEFAULT_MIDDLE
:
708 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
709 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.5 + log(upper
) * 0.5);
711 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.5 + upper
* 0.5);
714 case LADSPA_HINT_DEFAULT_HIGH
:
715 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
716 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.25 + log(upper
) * 0.75);
718 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.25 + upper
* 0.75);
721 case LADSPA_HINT_DEFAULT_0
:
725 case LADSPA_HINT_DEFAULT_1
:
729 case LADSPA_HINT_DEFAULT_100
:
733 case LADSPA_HINT_DEFAULT_440
:
738 pa_assert_not_reached();
742 if (LADSPA_IS_HINT_INTEGER(hint
))
743 u
->control
[h
] = roundf(u
->control
[h
]);
745 pa_log_debug("Binding %f to port %s", u
->control
[h
], d
->PortNames
[p
]);
747 for (c
= 0; c
< ss
.channels
; c
++)
748 d
->connect_port(u
->handle
[c
], p
, &u
->control
[h
]);
753 pa_assert(h
== n_control
);
757 for (c
= 0; c
< u
->channels
; c
++)
758 d
->activate(u
->handle
[c
]);
761 pa_sink_new_data_init(&sink_data
);
762 sink_data
.driver
= __FILE__
;
763 sink_data
.module
= m
;
764 if (!(sink_data
.name
= pa_xstrdup(pa_modargs_get_value(ma
, "sink_name", NULL
))))
765 sink_data
.name
= pa_sprintf_malloc("%s.ladspa", master
->name
);
766 pa_sink_new_data_set_sample_spec(&sink_data
, &ss
);
767 pa_sink_new_data_set_channel_map(&sink_data
, &map
);
768 z
= pa_proplist_gets(master
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
769 pa_proplist_setf(sink_data
.proplist
, PA_PROP_DEVICE_DESCRIPTION
, "LADSPA Plugin %s on %s", d
->Name
, z
? z
: master
->name
);
770 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_MASTER_DEVICE
, master
->name
);
771 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_CLASS
, "filter");
772 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.module", plugin
);
773 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.label", d
->Label
);
774 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.name", d
->Name
);
775 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.maker", d
->Maker
);
776 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.copyright", d
->Copyright
);
777 pa_proplist_setf(sink_data
.proplist
, "device.ladspa.unique_id", "%lu", (unsigned long) d
->UniqueID
);
779 if (pa_modargs_get_proplist(ma
, "sink_properties", sink_data
.proplist
, PA_UPDATE_REPLACE
) < 0) {
780 pa_log("Invalid properties");
781 pa_sink_new_data_done(&sink_data
);
785 u
->sink
= pa_sink_new(m
->core
, &sink_data
,
786 PA_SINK_HW_MUTE_CTRL
|PA_SINK_HW_VOLUME_CTRL
|PA_SINK_DECIBEL_VOLUME
|
787 (master
->flags
& (PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
)));
788 pa_sink_new_data_done(&sink_data
);
791 pa_log("Failed to create sink.");
795 u
->sink
->parent
.process_msg
= sink_process_msg_cb
;
796 u
->sink
->set_state
= sink_set_state_cb
;
797 u
->sink
->update_requested_latency
= sink_update_requested_latency_cb
;
798 u
->sink
->request_rewind
= sink_request_rewind_cb
;
799 u
->sink
->set_volume
= sink_set_volume_cb
;
800 u
->sink
->set_mute
= sink_set_mute_cb
;
801 u
->sink
->userdata
= u
;
803 pa_sink_set_asyncmsgq(u
->sink
, master
->asyncmsgq
);
805 /* Create sink input */
806 pa_sink_input_new_data_init(&sink_input_data
);
807 sink_input_data
.driver
= __FILE__
;
808 sink_input_data
.module
= m
;
809 sink_input_data
.sink
= master
;
810 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_NAME
, "LADSPA Stream");
811 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_ROLE
, "filter");
812 pa_sink_input_new_data_set_sample_spec(&sink_input_data
, &ss
);
813 pa_sink_input_new_data_set_channel_map(&sink_input_data
, &map
);
815 pa_sink_input_new(&u
->sink_input
, m
->core
, &sink_input_data
, 0);
816 pa_sink_input_new_data_done(&sink_input_data
);
821 u
->sink_input
->pop
= sink_input_pop_cb
;
822 u
->sink_input
->process_rewind
= sink_input_process_rewind_cb
;
823 u
->sink_input
->update_max_rewind
= sink_input_update_max_rewind_cb
;
824 u
->sink_input
->update_max_request
= sink_input_update_max_request_cb
;
825 u
->sink_input
->update_sink_latency_range
= sink_input_update_sink_latency_range_cb
;
826 u
->sink_input
->update_sink_fixed_latency
= sink_input_update_sink_fixed_latency_cb
;
827 u
->sink_input
->kill
= sink_input_kill_cb
;
828 u
->sink_input
->attach
= sink_input_attach_cb
;
829 u
->sink_input
->detach
= sink_input_detach_cb
;
830 u
->sink_input
->state_change
= sink_input_state_change_cb
;
831 u
->sink_input
->may_move_to
= sink_input_may_move_to_cb
;
832 u
->sink_input
->moving
= sink_input_moving_cb
;
833 u
->sink_input
->volume_changed
= sink_input_volume_changed_cb
;
834 u
->sink_input
->mute_changed
= sink_input_mute_changed_cb
;
835 u
->sink_input
->userdata
= u
;
837 pa_sink_put(u
->sink
);
838 pa_sink_input_put(u
->sink_input
);
842 pa_xfree(use_default
);
850 pa_xfree(use_default
);
857 int pa__get_n_used(pa_module
*m
) {
861 pa_assert_se(u
= m
->userdata
);
863 return pa_sink_linked_by(u
->sink
);
866 void pa__done(pa_module
*m
) {
872 if (!(u
= m
->userdata
))
875 /* See comments in sink_input_kill_cb() above regarding
876 * destruction order! */
879 pa_sink_input_unlink(u
->sink_input
);
882 pa_sink_unlink(u
->sink
);
885 pa_sink_input_unref(u
->sink_input
);
888 pa_sink_unref(u
->sink
);
890 for (c
= 0; c
< u
->channels
; c
++)
892 if (u
->descriptor
->deactivate
)
893 u
->descriptor
->deactivate(u
->handle
[c
]);
894 u
->descriptor
->cleanup(u
->handle
[c
]);
897 if (u
->output
!= u
->input
)
901 pa_memblockq_free(u
->memblockq
);
905 pa_xfree(u
->control
);