[pulseaudio-discuss] [PATCH] filter-apply, ladspa-sink, virtual-surround-sink: filter-apply supports ladspa-sink and virtual-surround-sink properly
KimJeongYeon
jeongyeon.kim at samsung.com
Thu Jun 16 07:14:24 UTC 2016
Currently, filter-apply doesn't support ladspa-sink based filters, because:
* loading ladspa-sink failed due to some argument mismatched.
(e.g 'master' used instead of 'sink_master')
* ladspa-sink required additional parameters by default.
(e.g plugin/label/control/...)
Changes in v1:
* filter-apply able to load ladspa-sink.
* This patch introduces new sink-input(source-output) property to append extra parameters.
#define PA_PROP_FILTER_APPLY_EXTRA_PARAMETERS "filter.apply.extra.parameters"
e.g) paplay file.wav --property=filter.apply=ladspa-sink \
--property=filter.apply.extra.parameters="plugin=ladspa label=ladspa_stereo control=0"
* ladspa-sink support autoloaded feature.
Changes in v2:
* Additionally, support virtual-surround-sink too.
Signed-off-by: KimJeongYeon <jeongyeon.kim at samsung.com>
---
src/modules/module-filter-apply.c | 27 +++++++++++++++++++++++--
src/modules/module-ladspa-sink.c | 32 ++++++++++++++++++++++++++----
src/modules/module-virtual-surround-sink.c | 31 ++++++++++++++++++++++++++---
src/pulse/proplist.h | 3 +++
4 files changed, 84 insertions(+), 9 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/modules/module-virtual-surround-sink.c b/src/modules/module-virtual-surround-sink.c
index 6c7120a..0cf3910 100644
--- a/src/modules/module-virtual-surround-sink.c
+++ b/src/modules/module-virtual-surround-sink.c
@@ -50,7 +50,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> "
@@ -58,9 +58,11 @@ PA_MODULE_USAGE(
"use_volume_sharing=<yes or no> "
"force_flat_volume=<yes or no> "
"hrir=/path/to/left_hrir.wav "
+ "autoloaded=<set if this module is being loaded automatically> "
));
#define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
+#define DEFAULT_AUTOLOADED false
struct userdata {
pa_module *module;
@@ -87,12 +89,14 @@ struct userdata {
float *input_buffer;
int input_buffer_offset;
+
+ bool autoloaded;
};
static const char* const valid_modargs[] = {
"sink_name",
"sink_properties",
- "master",
+ "sink_master",
"format",
"rate",
"channels",
@@ -100,6 +104,7 @@ static const char* const valid_modargs[] = {
"use_volume_sharing",
"force_flat_volume",
"hrir",
+ "autoloaded",
NULL
};
@@ -428,6 +433,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;
@@ -591,7 +609,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;
}
@@ -672,6 +690,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;
@@ -731,6 +755,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->volume_changed = use_volume_sharing ? NULL : sink_input_volume_changed_cb;
u->sink_input->mute_changed = sink_input_mute_changed_cb;
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