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

KimJeongYeon see2002 at gmail.com
Fri Apr 7 14:47:11 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 | 56 +++++++++++++++++++++++++++++++--------
 1 file changed, 45 insertions(+), 11 deletions(-)

diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index f7e8734..4f3b7e2 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");
@@ -62,6 +63,7 @@ typedef enum _process_cmd_type {
 
 struct filter {
     char *name;
+    char *parameters;
     uint32_t module_index;
     pa_sink *sink;
     pa_sink *sink_master;
@@ -103,13 +105,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;
@@ -123,6 +126,7 @@ static void filter_free(struct filter *f) {
     pa_assert(f);
 
     pa_xfree(f->name);
+    pa_xfree(f->parameters);
     pa_xfree(f);
 }
 
@@ -146,6 +150,26 @@ static const char* should_filter(pa_object *o, bool is_sink_input) {
     return NULL;
 }
 
+static const char* should_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);
+    if ((parameters = pa_proplist_gets(pl, prop_parameters)) && !pa_streq(parameters, "")) {
+        pa_xfree(prop_parameters);
+        return parameters;
+    }
+
+    pa_xfree(prop_parameters);
+    return NULL;
+}
+
 static bool should_group_filter(struct filter *filter) {
     return pa_streq(filter->name, "echo-cancel");
 }
@@ -365,7 +389,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;
@@ -375,7 +399,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;
 
@@ -388,7 +412,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 {
@@ -418,6 +442,7 @@ static bool can_unload_module(struct userdata *u, uint32_t idx) {
 
 static pa_hook_result_t process(struct userdata *u, pa_object *o, process_cmd_type_t cmd, bool is_sink_input) {
     const char *want;
+    const char *parameters;
     bool done_something = false;
     pa_sink *sink = NULL;
     pa_source *source = NULL;
@@ -455,7 +480,11 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, process_cmd_ty
             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 = should_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.");
@@ -466,16 +495,17 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, process_cmd_ty
             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;
             }
@@ -514,7 +544,11 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, process_cmd_ty
 
 done:
     pa_xfree(module_name);
-    pa_xfree(fltr);
+    if (fltr) {
+        pa_xfree(fltr->name);
+        pa_xfree(fltr->parameters);
+        pa_xfree(fltr);
+    }
 
     return PA_HOOK_OK;
 }
-- 
2.7.4



More information about the pulseaudio-discuss mailing list