[pulseaudio-discuss] [PATCH] filter-apply, ladspa-sink: filter-apply supports ladspa-sink properly
KimJeongYeon
jeongyeon.kim at samsung.com
Tue Jun 14 06:08:49 UTC 2016
Currently, filter-apply didn't support ladspa-sink based filters, because:
1) loading ladspa-sink failed due to some argument mismatched. (e.g 'master' used instead of 'sink_master')
2) ladspa-sink required additional parameters by default. (e.g plugin/label/control/...)
This patch also suggested to introduce new sink-input property to append extra parameters.
#define PA_PROP_FILTER_APPLY_EXTRA_PARAMETERS "filter.apply.extra.parameters"
3) ladspa-sink support autoloaded feature.
Signed-off-by: KimJeongYeon <jeongyeon.kim at samsung.com>
---
src/modules/module-filter-apply.c | 27 +++++++++++++++++++++++++--
src/modules/module-ladspa-sink.c | 32 ++++++++++++++++++++++++++++----
src/pulse/proplist.h | 3 +++
3 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index 364d68b..49f42b5 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -140,6 +140,23 @@ static const char* should_filter(pa_object *o, bool is_sink_input) {
return NULL;
}
+static const char* should_filter_extra_parameters(pa_object *o, bool is_sink_input) {
+ const char *extra_parameters;
+ pa_proplist *pl;
+
+ if (is_sink_input)
+ pl = PA_SINK_INPUT(o)->proplist;
+ else
+ pl = PA_SOURCE_OUTPUT(o)->proplist;
+
+ /* If the stream need extra parameters, append them to module. */
+ if ((extra_parameters = pa_proplist_gets(pl, PA_PROP_FILTER_APPLY_EXTRA_PARAMETERS)) && !pa_streq(extra_parameters, "")) {
+ return extra_parameters;
+ }
+
+ return NULL;
+}
+
static bool should_group_filter(struct filter *filter) {
return pa_streq(filter->name, "echo-cancel");
}
@@ -412,6 +429,7 @@ static bool can_unload_module(struct userdata *u, uint32_t idx) {
static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_input) {
const char *want;
+ const char *extra_parameters;
bool done_something = false;
pa_sink *sink = NULL;
pa_source *source = NULL;
@@ -460,11 +478,16 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
char *args;
pa_module *m;
- args = pa_sprintf_malloc("autoloaded=1 %s%s %s%s",
+ /* Some filter modules might be required extra parameters by default.
+ * (e.g 'plugin', 'label', 'control' of module-ladspa-sink) */
+ extra_parameters = should_filter_extra_parameters(o, is_sink_input);
+
+ args = pa_sprintf_malloc("autoloaded=1 %s%s %s%s %s",
fltr->sink_master ? "sink_master=" : "",
fltr->sink_master ? fltr->sink_master->name : "",
fltr->source_master ? "source_master=" : "",
- fltr->source_master ? fltr->source_master->name : "");
+ fltr->source_master ? fltr->source_master->name : "",
+ extra_parameters ? extra_parameters : "");
pa_log_debug("Loading %s with arguments '%s'", module_name, args);
diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c
index 38b94e3..87b0710 100644
--- a/src/modules/module-ladspa-sink.c
+++ b/src/modules/module-ladspa-sink.c
@@ -54,7 +54,7 @@ PA_MODULE_LOAD_ONCE(false);
PA_MODULE_USAGE(
_("sink_name=<name for the sink> "
"sink_properties=<properties for the sink> "
- "master=<name of sink to filter> "
+ "sink_master=<name of sink to filter> "
"format=<sample format> "
"rate=<sample rate> "
"channels=<number of channels> "
@@ -63,9 +63,11 @@ PA_MODULE_USAGE(
"label=<ladspa plugin label> "
"control=<comma separated list of input control values> "
"input_ladspaport_map=<comma separated list of input LADSPA port names> "
- "output_ladspaport_map=<comma separated list of output LADSPA port names> "));
+ "output_ladspaport_map=<comma separated list of output LADSPA port names> "
+ "autoloaded=<set if this module is being loaded automatically> "));
#define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
+#define DEFAULT_AUTOLOADED false
/* PLEASE NOTICE: The PortAudio ports and the LADSPA ports are two different concepts.
They are not related and where possible the names of the LADSPA port variables contains "ladspa" to avoid confusion */
@@ -99,12 +101,13 @@ struct userdata {
#endif
bool auto_desc;
+ bool autoloaded;
};
static const char* const valid_modargs[] = {
"sink_name",
"sink_properties",
- "master",
+ "sink_master",
"format",
"rate",
"channels",
@@ -114,6 +117,7 @@ static const char* const valid_modargs[] = {
"control",
"input_ladspaport_map",
"output_ladspaport_map",
+ "autoloaded",
NULL
};
@@ -640,6 +644,19 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s
}
/* Called from main context */
+static bool sink_input_may_move_to_cb(pa_sink_input *i, pa_sink *dest) {
+ struct userdata *u;
+
+ pa_sink_input_assert_ref(i);
+ pa_assert_se(u = i->userdata);
+
+ if (u->autoloaded)
+ return false;
+
+ return u->sink != dest;
+}
+
+/* Called from main context */
static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
struct userdata *u;
@@ -968,7 +985,7 @@ int pa__init(pa_module*m) {
goto fail;
}
- if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "master", NULL), PA_NAMEREG_SINK))) {
+ if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink_master", NULL), PA_NAMEREG_SINK))) {
pa_log("Master sink not found");
goto fail;
}
@@ -1226,6 +1243,12 @@ int pa__init(pa_module*m) {
goto fail;
}
+ u->autoloaded = DEFAULT_AUTOLOADED;
+ if (pa_modargs_get_value_boolean(ma, "autoloaded", &u->autoloaded) < 0) {
+ pa_log("Failed to parse autoloaded value");
+ goto fail;
+ }
+
if ((u->auto_desc = !pa_proplist_contains(sink_data.proplist, PA_PROP_DEVICE_DESCRIPTION))) {
const char *z;
@@ -1278,6 +1301,7 @@ int pa__init(pa_module*m) {
u->sink_input->attach = sink_input_attach_cb;
u->sink_input->detach = sink_input_detach_cb;
u->sink_input->state_change = sink_input_state_change_cb;
+ u->sink_input->may_move_to = sink_input_may_move_to_cb;
u->sink_input->moving = sink_input_moving_cb;
u->sink_input->mute_changed = sink_input_mute_changed_cb;
u->sink_input->userdata = u;
diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h
index bc9e8f8..8c8b742 100644
--- a/src/pulse/proplist.h
+++ b/src/pulse/proplist.h
@@ -69,6 +69,9 @@ PA_C_DECL_BEGIN
/** For streams: the name of a filter that is desired, e.g.\ "echo-cancel" or "equalizer-sink". Differs from PA_PROP_FILTER_WANT in that it forces PulseAudio to apply the filter, regardless of whether PulseAudio thinks it makes sense to do so or not. If this is set, PA_PROP_FILTER_WANT is ignored. In other words, you almost certainly do not want to use this. \since 1.0 */
#define PA_PROP_FILTER_APPLY "filter.apply"
+/** For streams: some module required extra parameters, e.g.\ "plugin=ladspa label=ladspa_stereo control=0" in case of "ladspa-sink" filter */
+#define PA_PROP_FILTER_APPLY_EXTRA_PARAMETERS "filter.apply.extra.parameters"
+
/** For streams: the name of a filter that should specifically suppressed (i.e.\ overrides PA_PROP_FILTER_WANT). Useful for the times that PA_PROP_FILTER_WANT is automatically added (e.g. echo-cancellation for phone streams when $VOIP_APP does its own, internal AEC) \since 1.0 */
#define PA_PROP_FILTER_SUPPRESS "filter.suppress"
--
2.7.4
More information about the pulseaudio-discuss
mailing list