[pulseaudio-discuss] [PATCH v3 3/3] filter-apply: Supports ladspa-sink and virtual-surround-sink properly

KimJeongYeon see2002 at gmail.com
Thu Apr 13 14:08:26 UTC 2017


filter-apply able to load ladspa-sink, virtual-surround-sink using new
'filter.apply.{MODULE_NAME}.parameter' property.
e.g) paplay file.wav --property=filter.apply=ladspa-sink \
                     --property=filter.apply.ladspa-sink.parameters="plugin=ladspa label=ladspa_stereo control=0"

Signed-off-by: KimJeongYeon <jeongyeon.kim at samsung.com>
---
 src/modules/module-filter-apply.c | 51 ++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index 193b2ce..e91fb37 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -37,8 +37,9 @@
 
 #include "module-filter-apply-symdef.h"
 
-#define PA_PROP_FILTER_APPLY_MOVING "filter.apply.moving"
-#define PA_PROP_MDM_AUTO_FILTERED   "module-device-manager.auto_filtered"
+#define PA_PROP_FILTER_APPLY_PARAMETERS PA_PROP_FILTER_APPLY".%s.parameters"
+#define PA_PROP_FILTER_APPLY_MOVING     "filter.apply.moving"
+#define PA_PROP_MDM_AUTO_FILTERED       "module-device-manager.auto_filtered"
 
 PA_MODULE_AUTHOR("Colin Guthrie");
 PA_MODULE_DESCRIPTION("Load filter sinks automatically when needed");
@@ -56,6 +57,7 @@ static const char* const valid_modargs[] = {
 
 struct filter {
     char *name;
+    char *parameters;
     uint32_t module_index;
     pa_sink *sink;
     pa_sink *sink_master;
@@ -97,13 +99,14 @@ static int filter_compare(const void *a, const void *b) {
     return 0;
 }
 
-static struct filter *filter_new(const char *name, pa_sink *sink, pa_source *source) {
+static struct filter *filter_new(const char *name, const char *parameters, pa_sink *sink, pa_source *source) {
     struct filter *f;
 
     pa_assert(sink || source);
 
     f = pa_xnew(struct filter, 1);
     f->name = pa_xstrdup(name);
+    f->parameters = pa_xstrdup(parameters);
     f->sink_master = sink;
     f->source_master = source;
     f->module_index = PA_INVALID_INDEX;
@@ -116,11 +119,12 @@ static struct filter *filter_new(const char *name, pa_sink *sink, pa_source *sou
 static void filter_free(struct filter *f) {
     if (f) {
         pa_xfree(f->name);
+        pa_xfree(f->parameters);
         pa_xfree(f);
     }
 }
 
-static const char* should_filter(pa_object *o, bool is_sink_input) {
+static const char* get_filter_name(pa_object *o, bool is_sink_input) {
     const char *apply;
     pa_proplist *pl;
 
@@ -140,6 +144,23 @@ static const char* should_filter(pa_object *o, bool is_sink_input) {
     return NULL;
 }
 
+static const char* get_filter_parameters(pa_object *o, const char *want, bool is_sink_input) {
+    const char *parameters;
+    char *prop_parameters;
+    pa_proplist *pl;
+
+    if (is_sink_input)
+        pl = PA_SINK_INPUT(o)->proplist;
+    else
+        pl = PA_SOURCE_OUTPUT(o)->proplist;
+
+    prop_parameters = pa_sprintf_malloc(PA_PROP_FILTER_APPLY_PARAMETERS, want);
+    parameters = pa_proplist_gets(pl, prop_parameters);
+    pa_xfree(prop_parameters);
+
+    return parameters;
+}
+
 static bool should_group_filter(struct filter *filter) {
     return pa_streq(filter->name, "echo-cancel");
 }
@@ -359,7 +380,7 @@ static void move_objects_for_filter(struct userdata *u, pa_object *o, struct fil
 
 /* Note that we assume a filter will provide at most one sink and at most one
  * source (and at least one of either). */
-static void find_filters_for_module(struct userdata *u, pa_module *m, const char *name) {
+static void find_filters_for_module(struct userdata *u, pa_module *m, const char *name, const char *parameters) {
     uint32_t idx;
     pa_sink *sink;
     pa_source *source;
@@ -369,7 +390,7 @@ static void find_filters_for_module(struct userdata *u, pa_module *m, const char
         if (sink->module == m) {
             pa_assert(pa_sink_is_filter(sink));
 
-            fltr = filter_new(name, sink->input_to_master->sink, NULL);
+            fltr = filter_new(name, parameters, sink->input_to_master->sink, NULL);
             fltr->module_index = m->index;
             fltr->sink = sink;
 
@@ -382,7 +403,7 @@ static void find_filters_for_module(struct userdata *u, pa_module *m, const char
             pa_assert(pa_source_is_filter(source));
 
             if (!fltr) {
-                fltr = filter_new(name, NULL, source->output_from_master->source);
+                fltr = filter_new(name, parameters, NULL, source->output_from_master->source);
                 fltr->module_index = m->index;
                 fltr->source = source;
             } else {
@@ -412,6 +433,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 *parameters;
     bool done_something = false;
     pa_sink *sink = NULL;
     pa_source *source = NULL;
@@ -436,7 +458,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
         goto done;
 
     /* If the stream doesn't what any filter, then let it be. */
-    if ((want = should_filter(o, is_sink_input))) {
+    if ((want = get_filter_name(o, is_sink_input))) {
         /* We need to ensure the SI is playing on a sink of this type
          * attached to the sink it's "officially" playing on */
 
@@ -449,7 +471,11 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
             goto done;
         }
 
-        fltr = filter_new(want, sink, source);
+        /* Some filter modules might require parameters by default.
+         * (e.g 'plugin', 'label', 'control' of module-ladspa-sink) */
+        parameters = get_filter_parameters(o, want, is_sink_input);
+
+        fltr = filter_new(want, parameters, sink, source);
 
         if (should_group_filter(fltr) && !find_paired_master(u, fltr, o, is_sink_input)) {
             pa_log_debug("Want group filtering but don't have enough streams.");
@@ -460,16 +486,17 @@ 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",
+            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 : "",
+                    fltr->parameters ? fltr->parameters : "");
 
             pa_log_debug("Loading %s with arguments '%s'", module_name, args);
 
             if ((m = pa_module_load(u->core, module_name, args))) {
-                find_filters_for_module(u, m, want);
+                find_filters_for_module(u, m, want, parameters);
                 filter = pa_hashmap_get(u->filters, fltr);
                 done_something = true;
             }
-- 
2.7.4



More information about the pulseaudio-discuss mailing list