mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
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"
This commit is contained in:
parent
145da09aca
commit
caabff2728
1 changed files with 39 additions and 12 deletions
|
|
@ -37,8 +37,9 @@
|
||||||
|
|
||||||
#include "module-filter-apply-symdef.h"
|
#include "module-filter-apply-symdef.h"
|
||||||
|
|
||||||
#define PA_PROP_FILTER_APPLY_MOVING "filter.apply.moving"
|
#define PA_PROP_FILTER_APPLY_PARAMETERS PA_PROP_FILTER_APPLY".%s.parameters"
|
||||||
#define PA_PROP_MDM_AUTO_FILTERED "module-device-manager.auto_filtered"
|
#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_AUTHOR("Colin Guthrie");
|
||||||
PA_MODULE_DESCRIPTION("Load filter sinks automatically when needed");
|
PA_MODULE_DESCRIPTION("Load filter sinks automatically when needed");
|
||||||
|
|
@ -56,6 +57,7 @@ static const char* const valid_modargs[] = {
|
||||||
|
|
||||||
struct filter {
|
struct filter {
|
||||||
char *name;
|
char *name;
|
||||||
|
char *parameters;
|
||||||
uint32_t module_index;
|
uint32_t module_index;
|
||||||
pa_sink *sink;
|
pa_sink *sink;
|
||||||
pa_sink *sink_master;
|
pa_sink *sink_master;
|
||||||
|
|
@ -97,13 +99,14 @@ static int filter_compare(const void *a, const void *b) {
|
||||||
return 0;
|
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;
|
struct filter *f;
|
||||||
|
|
||||||
pa_assert(sink || source);
|
pa_assert(sink || source);
|
||||||
|
|
||||||
f = pa_xnew(struct filter, 1);
|
f = pa_xnew(struct filter, 1);
|
||||||
f->name = pa_xstrdup(name);
|
f->name = pa_xstrdup(name);
|
||||||
|
f->parameters = pa_xstrdup(parameters);
|
||||||
f->sink_master = sink;
|
f->sink_master = sink;
|
||||||
f->source_master = source;
|
f->source_master = source;
|
||||||
f->module_index = PA_INVALID_INDEX;
|
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) {
|
static void filter_free(struct filter *f) {
|
||||||
if (f) {
|
if (f) {
|
||||||
pa_xfree(f->name);
|
pa_xfree(f->name);
|
||||||
|
pa_xfree(f->parameters);
|
||||||
pa_xfree(f);
|
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;
|
const char *apply;
|
||||||
pa_proplist *pl;
|
pa_proplist *pl;
|
||||||
|
|
||||||
|
|
@ -140,6 +144,23 @@ static const char* should_filter(pa_object *o, bool is_sink_input) {
|
||||||
return NULL;
|
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) {
|
static bool should_group_filter(struct filter *filter) {
|
||||||
return pa_streq(filter->name, "echo-cancel");
|
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
|
/* Note that we assume a filter will provide at most one sink and at most one
|
||||||
* source (and at least one of either). */
|
* 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;
|
uint32_t idx;
|
||||||
pa_sink *sink;
|
pa_sink *sink;
|
||||||
pa_source *source;
|
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) {
|
if (sink->module == m) {
|
||||||
pa_assert(pa_sink_is_filter(sink));
|
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->module_index = m->index;
|
||||||
fltr->sink = sink;
|
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));
|
pa_assert(pa_source_is_filter(source));
|
||||||
|
|
||||||
if (!fltr) {
|
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->module_index = m->index;
|
||||||
fltr->source = source;
|
fltr->source = source;
|
||||||
} else {
|
} 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) {
|
static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_input) {
|
||||||
const char *want;
|
const char *want;
|
||||||
|
const char *parameters;
|
||||||
bool done_something = false;
|
bool done_something = false;
|
||||||
pa_sink *sink = NULL;
|
pa_sink *sink = NULL;
|
||||||
pa_source *source = 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;
|
goto done;
|
||||||
|
|
||||||
/* If the stream doesn't what any filter, then let it be. */
|
/* 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
|
/* We need to ensure the SI is playing on a sink of this type
|
||||||
* attached to the sink it's "officially" playing on */
|
* 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;
|
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)) {
|
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.");
|
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;
|
char *args;
|
||||||
pa_module *m;
|
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 ? "sink_master=" : "",
|
||||||
fltr->sink_master ? fltr->sink_master->name : "",
|
fltr->sink_master ? fltr->sink_master->name : "",
|
||||||
fltr->source_master ? "source_master=" : "",
|
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);
|
pa_log_debug("Loading %s with arguments '%s'", module_name, args);
|
||||||
|
|
||||||
if ((m = pa_module_load(u->core, 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);
|
filter = pa_hashmap_get(u->filters, fltr);
|
||||||
done_something = true;
|
done_something = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue