[pulseaudio-commits] 4 commits - src/modules
Georg Chini
gchini at kemper.freedesktop.org
Thu Apr 13 19:31:06 UTC 2017
src/modules/module-filter-apply.c | 61 ++++++++++++++++++++---------
src/modules/module-ladspa-sink.c | 39 ++++++++++++++++--
src/modules/module-virtual-surround-sink.c | 40 ++++++++++++++++---
3 files changed, 113 insertions(+), 27 deletions(-)
New commits:
commit caabff2728d9d588664f8a0ea2f8441804c8b91a
Author: KimjeongYeon <see2002 at gmail.com>
Date: Thu Apr 13 21:09:49 2017 +0200
filter-apply: Add ability to pass parameters to a filter module
Currently passing parameters to a filter loaded by module-filter-apply is
not possible.
To enable passing parameters to a filter this patch uses an additional property
filter.apply.{MODULE_NAME}.parameters. This way, filters like virtual-surround-sink
and ladspa-sink are fully supported. For example:
paplay file.wav --property=filter.apply=ladspa-sink \
--property=filter.apply.ladspa-sink.parameters="plugin=ladspa \
label=ladspa_stereo control=0"
diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index 193b2ce2..e91fb37d 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;
}
commit 145da09aca8b54d611999ebf661b05ceb9e1c62f
Author: KimjeongYeon <see2002 at gmail.com>
Date: Thu Apr 13 20:58:14 2017 +0200
ladspa-sink: Add sink_master argument to enable filter-apply to load the module
Currently, module-filter-apply cannot load module-ladspa-sink because filter-apply
provides the argument "sink_master" but ladspa-sink expects "master" instead.
Therefore this patch adds the sink_master argument to module-ladspa-sink.
Additionally, the autoloaded argument was also added.
diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c
index 6dd29873..2409d610 100644
--- a/src/modules/module-ladspa-sink.c
+++ b/src/modules/module-ladspa-sink.c
@@ -55,6 +55,7 @@ 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 +64,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 +102,14 @@ struct userdata {
#endif
bool auto_desc;
+ bool autoloaded;
};
static const char* const valid_modargs[] = {
"sink_name",
"sink_properties",
- "master",
+ "master", /* Will be deprecated. */
+ "sink_master",
"format",
"rate",
"channels",
@@ -114,6 +119,7 @@ static const char* const valid_modargs[] = {
"control",
"input_ladspaport_map",
"output_ladspaport_map",
+ "autoloaded",
NULL
};
@@ -640,6 +646,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,9 +987,12 @@ 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))) {
- pa_log("Master sink not found");
- goto fail;
+ if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink_master", NULL), PA_NAMEREG_SINK))) {
+ if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "master", NULL), PA_NAMEREG_SINK))) {
+ pa_log("Master sink not found.");
+ goto fail;
+ } else
+ pa_log("Argument 'master' will be deprecated, please use 'sink_master' instead.");
}
ss = master->sample_spec;
@@ -1231,6 +1253,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;
@@ -1283,6 +1311,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;
commit ba4de85b530d91f5f7d81f3bf29a0ae8bc60b04e
Author: KimjeongYeon <see2002 at gmail.com>
Date: Thu Apr 13 20:44:41 2017 +0200
virtual-surround-sink: Add sink_master argument to enable filter-apply to load the module
Currently, module-filter-apply cannot load module-virtual-surround-sink because filter-apply
provides the argument "sink_master" but virtual-surround-sink expects "master" instead.
Therefore this patch adds the sink_master argument to module-virtual-surround-sink.
Additionally, the autoloaded argument was also added.
diff --git a/src/modules/module-virtual-surround-sink.c b/src/modules/module-virtual-surround-sink.c
index 4a53623c..47716da2 100644
--- a/src/modules/module-virtual-surround-sink.c
+++ b/src/modules/module-virtual-surround-sink.c
@@ -51,6 +51,7 @@ 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 +59,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 +90,15 @@ struct userdata {
float *input_buffer;
int input_buffer_offset;
+
+ bool autoloaded;
};
static const char* const valid_modargs[] = {
"sink_name",
"sink_properties",
- "master",
+ "master", /* Will be deprecated. */
+ "sink_master",
"format",
"rate",
"channels",
@@ -100,6 +106,7 @@ static const char* const valid_modargs[] = {
"use_volume_sharing",
"force_flat_volume",
"hrir",
+ "autoloaded",
NULL
};
@@ -428,6 +435,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;
@@ -561,7 +581,7 @@ int pa__init(pa_module*m) {
pa_sample_spec ss, sink_input_ss;
pa_channel_map map, sink_input_map;
pa_modargs *ma;
- pa_sink *master=NULL;
+ pa_sink *master = NULL;
pa_sink_input_new_data sink_input_data;
pa_sink_new_data sink_data;
bool use_volume_sharing = true;
@@ -591,9 +611,12 @@ 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))) {
- pa_log("Master sink not found");
- goto fail;
+ if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink_master", NULL), PA_NAMEREG_SINK))) {
+ if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "master", NULL), PA_NAMEREG_SINK))) {
+ pa_log("Master sink not found.");
+ goto fail;
+ } else
+ pa_log("Argument 'master' will be deprecated, please use 'sink_master' instead.");
}
pa_assert(master);
@@ -672,6 +695,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 +760,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;
commit 1f0c4f7d6af250e1d8dbb020de0f83afcec858b0
Author: KimjeongYeon <see2002 at gmail.com>
Date: Thu Apr 13 20:33:26 2017 +0200
filter-apply: Fix memory leak in process()
fltr->name should be freed before freeing fltr. Because filter_free()
can never be called from other places without f set, the pa_assert()
can be removed and filter_free() can be used in process() as well.
diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index 364d68be..193b2ce2 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -114,10 +114,10 @@ static struct filter *filter_new(const char *name, pa_sink *sink, pa_source *sou
}
static void filter_free(struct filter *f) {
- pa_assert(f);
-
- pa_xfree(f->name);
- pa_xfree(f);
+ if (f) {
+ pa_xfree(f->name);
+ pa_xfree(f);
+ }
}
static const char* should_filter(pa_object *o, bool is_sink_input) {
@@ -506,7 +506,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
done:
pa_xfree(module_name);
- pa_xfree(fltr);
+ filter_free(fltr);
return PA_HOOK_OK;
}
More information about the pulseaudio-commits
mailing list