[pulseaudio-commits] 2 commits - src/modules src/pulsecore
Arun Raghavan
arun at kemper.freedesktop.org
Sat Nov 26 00:33:49 PST 2011
src/modules/module-filter-apply.c | 179 +++++++++++++++++++++++++++++++-----
src/modules/module-stream-restore.c | 50 ++--------
src/pulsecore/proplist-util.c | 30 ++++++
src/pulsecore/proplist-util.h | 1
4 files changed, 203 insertions(+), 57 deletions(-)
New commits:
commit fabb28f935118d8d88e76f1d47726c283c2a9c8d
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date: Thu Nov 17 20:01:59 2011 +0530
filters: Handle echo-cancel streams better
This makes handling of echo-cancel streams (and potentially other
filters that need to work with multiple streams) cleaner. We do this by
adding the ability to apply filter on a group of streams rather than
always treating streams individually.
This is required, for example, when changing the input source for an
echo-cancel source output. When this happens, we want to change the
module-echo-cancel instance to actually cancel between the new source
and old sink.
To do this when one stream in a group moves, we create a new filter
instance between the current master sink/source pair and move the
relevant streams to the virtual sink/source from this new instance.
diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index d1fb5df..cd0cd8d 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -35,6 +35,7 @@
#include <pulsecore/hook-list.h>
#include <pulsecore/sink-input.h>
#include <pulsecore/modargs.h>
+#include <pulsecore/proplist-util.h>
#include "module-filter-apply-symdef.h"
@@ -89,7 +90,7 @@ static unsigned filter_hash(const void *p) {
else if (!f->sink_master && f->source_master)
return (unsigned) ((f->source_master->index << 16) + pa_idxset_string_hash_func(f->name));
else
- pa_assert_not_reached();
+ return (unsigned) (f->sink_master->index + (f->source_master->index << 16) + pa_idxset_string_hash_func(f->name));
}
static int filter_compare(const void *a, const void *b) {
@@ -147,12 +148,96 @@ static const char* should_filter(pa_object *o, pa_bool_t is_sink_input) {
return NULL;
}
+static pa_bool_t should_group_filter(struct filter *filter) {
+ return pa_streq(filter->name, "echo-cancel");
+}
+
+static char* get_group(pa_object *o, pa_bool_t is_sink_input) {
+ pa_proplist *pl;
+
+ if (is_sink_input)
+ pl = PA_SINK_INPUT(o)->proplist;
+ else
+ pl = PA_SOURCE_OUTPUT(o)->proplist;
+
+ /* There's a bit of cleverness here -- the second argument ensures that we
+ * only group streams that require the same filter */
+ return pa_proplist_get_stream_group(pl, pa_proplist_gets(pl, PA_PROP_FILTER_APPLY), NULL);
+}
+
+/* For filters that apply on a source-output/sink-input pair, this finds the
+ * master sink if we know the master source, or vice versa. It does this by
+ * looking up streams that belong to the same stream group as the original
+ * object. The idea is that streams from the sam group are always routed
+ * together. */
+static pa_bool_t find_paired_master(struct userdata *u, struct filter *filter, pa_object *o, pa_bool_t is_sink_input) {
+ char *group;
+
+ if ((group = get_group(o, is_sink_input))) {
+ uint32_t idx;
+ char *g;
+ char *module_name = pa_sprintf_malloc("module-%s", filter->name);
+
+ if (is_sink_input) {
+ pa_source_output *so;
+
+ PA_IDXSET_FOREACH(so, u->core->source_outputs, idx) {
+ g = get_group(PA_OBJECT(so), FALSE);
+
+ if (pa_streq(g, group)) {
+ if (pa_streq(module_name, so->source->module->name)) {
+ /* Make sure we're not routing to another instance of
+ * the same filter. */
+ filter->source_master = so->source->output_from_master->source;
+ } else {
+ filter->source_master = so->source;
+ }
+
+ pa_xfree(g);
+ break;
+ }
+
+ pa_xfree (g);
+ }
+ } else {
+ pa_sink_input *si;
+
+ PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
+ g = get_group(PA_OBJECT(si), TRUE);
+
+ if (pa_streq(g, group)) {
+ if (pa_streq(module_name, si->sink->module->name)) {
+ /* Make sure we're not routing to another instance of
+ * the same filter. */
+ filter->sink_master = si->sink->input_to_master->sink;
+ } else {
+ filter->sink_master = si->sink;
+ }
+
+ pa_xfree(g);
+ break;
+ }
+
+ pa_xfree(g);
+ }
+ }
+
+ pa_xfree(group);
+ pa_xfree(module_name);
+
+ if (!filter->sink_master || !filter->source_master)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static pa_bool_t nothing_attached(struct filter *f) {
pa_bool_t no_si = TRUE, no_so = TRUE;
if (f->sink)
no_si = pa_idxset_isempty(f->sink->inputs);
- else if (f->source)
+ if (f->source)
no_so = pa_idxset_isempty(f->source->outputs);
return no_si && no_so;
@@ -215,11 +300,15 @@ static void move_object_for_filter(pa_object *o, struct filter* filter, pa_bool_
if (is_sink_input) {
pl = PA_SINK_INPUT(o)->proplist;
- pa_assert_se(parent = PA_OBJECT(restore ? filter->sink_master : filter->sink));
+ parent = PA_OBJECT(restore ? filter->sink_master : filter->sink);
+ if (!parent)
+ return;
name = PA_SINK(parent)->name;
} else {
pl = PA_SOURCE_OUTPUT(o)->proplist;
- pa_assert_se(parent = PA_OBJECT(restore ? filter->source_master : filter->source));
+ parent = PA_OBJECT(restore ? filter->source_master : filter->source);
+ if (!parent)
+ return;
name = PA_SOURCE(parent)->name;
}
@@ -235,11 +324,48 @@ static void move_object_for_filter(pa_object *o, struct filter* filter, pa_bool_
pa_proplist_unset(pl, PA_PROP_FILTER_APPLY_MOVING);
}
+static void move_objects_for_filter(struct userdata *u, pa_object *o, struct filter* filter, pa_bool_t restore,
+ pa_bool_t is_sink_input) {
+
+ if (!should_group_filter(filter))
+ move_object_for_filter(o, filter, restore, is_sink_input);
+ else {
+ pa_source_output *so;
+ pa_sink_input *si;
+ char *g, *group;
+ uint32_t idx;
+
+ group = get_group(o, is_sink_input);
+
+ PA_IDXSET_FOREACH(so, u->core->source_outputs, idx) {
+ g = get_group(PA_OBJECT(so), FALSE);
+
+ if (pa_streq(g, group))
+ move_object_for_filter(PA_OBJECT(so), filter, restore, FALSE);
+
+ pa_xfree(g);
+ }
+
+ PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
+ g = get_group(PA_OBJECT(si), TRUE);
+
+ if (pa_streq(g, group))
+ move_object_for_filter(PA_OBJECT(si), filter, restore, TRUE);
+
+ pa_xfree(g);
+ }
+
+ pa_xfree(group);
+ }
+}
+
+/* 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) {
uint32_t idx;
pa_sink *sink;
pa_source *source;
- struct filter *fltr;
+ struct filter *fltr = NULL;
PA_IDXSET_FOREACH(sink, u->core->sinks, idx) {
if (sink->module == m) {
@@ -249,7 +375,7 @@ static void find_filters_for_module(struct userdata *u, pa_module *m, const char
fltr->module_index = m->index;
fltr->sink = sink;
- pa_hashmap_put(u->filters, fltr, fltr);
+ break;
}
}
@@ -257,13 +383,20 @@ static void find_filters_for_module(struct userdata *u, pa_module *m, const char
if (source->module == m && !source->monitor_of) {
pa_assert(source->output_from_master != NULL);
- fltr = filter_new(name, NULL, source->output_from_master->source);
- fltr->module_index = m->index;
- fltr->source = source;
+ if (!fltr) {
+ fltr = filter_new(name, NULL, source->output_from_master->source);
+ fltr->module_index = m->index;
+ fltr->source = source;
+ } else {
+ fltr->source = source;
+ fltr->source_master = source->output_from_master->source;
+ }
- pa_hashmap_put(u->filters, fltr, fltr);
+ break;
}
}
+
+ pa_hashmap_put(u->filters, fltr, fltr);
}
static pa_bool_t can_unload_module(struct userdata *u, uint32_t idx) {
@@ -284,16 +417,13 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_s
pa_bool_t done_something = FALSE;
pa_sink *sink = NULL;
pa_source *source = NULL;
- const char *sink_name = NULL, *source_name = NULL;
pa_module *module;
if (is_sink_input) {
sink = PA_SINK_INPUT(o)->sink;
- sink_name = sink->name;
module = sink->module;
} else {
source = PA_SOURCE_OUTPUT(o)->source;
- source_name = source->name;
module = source->module;
}
@@ -321,12 +451,21 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_s
fltr = filter_new(want, 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.");
+ return PA_HOOK_OK;
+ }
+
if (!(filter = pa_hashmap_get(u->filters, fltr))) {
char *args;
pa_module *m;
- args = pa_sprintf_malloc("autoloaded=1 %s_master=%s", is_sink_input ? "sink" : "source",
- is_sink_input ? sink_name : source_name);
+ args = pa_sprintf_malloc("autoloaded=1 %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 : "");
+
pa_log_debug("Loading %s with arguments '%s'", module_name, args);
if ((m = pa_module_load(u->core, module_name, args))) {
@@ -340,7 +479,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_s
pa_xfree(fltr);
if (!filter) {
- pa_log("Unable to load %s for <%s>", module_name, is_sink_input ? sink_name : source_name);
+ pa_log("Unable to load %s", module_name);
pa_xfree(module_name);
return PA_HOOK_OK;
}
@@ -349,7 +488,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_s
/* We can move the stream now as we know the destination. If this
* isn't true, we will do it later when the sink appears. */
if ((is_sink_input && filter->sink) || (!is_sink_input && filter->source)) {
- move_object_for_filter(o, filter, FALSE, is_sink_input);
+ move_objects_for_filter(u, o, filter, FALSE, is_sink_input);
done_something = TRUE;
}
} else {
@@ -360,7 +499,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_s
* This can happen if an input's proplist changes */
PA_HASHMAP_FOREACH(filter, u->filters, state) {
if ((is_sink_input && sink == filter->sink) || (!is_sink_input && source == filter->source)) {
- move_object_for_filter(o, filter, TRUE, is_sink_input);
+ move_objects_for_filter(u, o, filter, TRUE, is_sink_input);
done_something = TRUE;
break;
}
@@ -430,7 +569,7 @@ static pa_hook_result_t sink_unlink_cb(pa_core *core, pa_sink *sink, struct user
pa_sink_input *i;
PA_IDXSET_FOREACH(i, sink->inputs, idx)
- move_object_for_filter(PA_OBJECT(i), filter, TRUE, TRUE);
+ move_objects_for_filter(u, PA_OBJECT(i), filter, TRUE, TRUE);
}
idx = filter->module_index;
@@ -502,7 +641,7 @@ static pa_hook_result_t source_unlink_cb(pa_core *core, pa_source *source, struc
pa_source_output *o;
PA_IDXSET_FOREACH(o, source->outputs, idx)
- move_object_for_filter(PA_OBJECT(o), filter, TRUE, FALSE);
+ move_objects_for_filter(u, PA_OBJECT(o), filter, TRUE, FALSE);
}
idx = filter->module_index;
commit 1798c653db696a9d44bbcec469e672829bb0231d
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date: Wed Nov 23 16:26:40 2011 +0530
proplist: Add internal API to get stream group
This moves out code from module-stream-restore and makes an internal API
out of it to get a "stream group" for a given sink input or source output.
This is factored out for reuse in module-filter-*.
The stream group basically provides some means of attaching a logical
identification to the stream (by role, application id, etc.).
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index fe7708b..4d34523 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -51,6 +51,7 @@
#include <pulsecore/pstream-util.h>
#include <pulsecore/database.h>
#include <pulsecore/tagstruct.h>
+#include <pulsecore/proplist-util.h>
#ifdef HAVE_DBUS
#include <pulsecore/dbus-util.h>
@@ -971,31 +972,6 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
pa_log_info("Synced.");
}
-static char *get_name(pa_proplist *p, const char *prefix) {
- const char *r;
- char *t;
-
- if (!p)
- return NULL;
-
- if ((r = pa_proplist_gets(p, IDENTIFICATION_PROPERTY)))
- return pa_xstrdup(r);
-
- if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_ROLE)))
- t = pa_sprintf_malloc("%s-by-media-role:%s", prefix, r);
- else if ((r = pa_proplist_gets(p, PA_PROP_APPLICATION_ID)))
- t = pa_sprintf_malloc("%s-by-application-id:%s", prefix, r);
- else if ((r = pa_proplist_gets(p, PA_PROP_APPLICATION_NAME)))
- t = pa_sprintf_malloc("%s-by-application-name:%s", prefix, r);
- else if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_NAME)))
- t = pa_sprintf_malloc("%s-by-media-name:%s", prefix, r);
- else
- t = pa_sprintf_malloc("%s-fallback:%s", prefix, r);
-
- pa_proplist_sets(p, IDENTIFICATION_PROPERTY, t);
- return t;
-}
-
static struct entry* entry_new(void) {
struct entry *r = pa_xnew0(struct entry, 1);
r->version = ENTRY_VERSION;
@@ -1300,7 +1276,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
if (!(sink_input = pa_idxset_get_by_index(c->sink_inputs, idx)))
return;
- if (!(name = get_name(sink_input->proplist, "sink-input")))
+ if (!(name = pa_proplist_get_stream_group(sink_input->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
return;
if ((old = entry_read(u, name))) {
@@ -1350,7 +1326,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
if (!(source_output = pa_idxset_get_by_index(c->source_outputs, idx)))
return;
- if (!(name = get_name(source_output->proplist, "source-output")))
+ if (!(name = pa_proplist_get_stream_group(source_output->proplist, "source-output", IDENTIFICATION_PROPERTY)))
return;
if ((old = entry_read(u, name))) {
@@ -1443,7 +1419,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
pa_assert(u);
pa_assert(u->restore_device);
- if (!(name = get_name(new_data->proplist, "sink-input")))
+ if (!(name = pa_proplist_get_stream_group(new_data->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
return PA_HOOK_OK;
if (new_data->sink)
@@ -1485,7 +1461,7 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
pa_assert(u);
pa_assert(u->restore_volume || u->restore_muted);
- if (!(name = get_name(new_data->proplist, "sink-input")))
+ if (!(name = pa_proplist_get_stream_group(new_data->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
return PA_HOOK_OK;
if ((e = entry_read(u, name))) {
@@ -1539,7 +1515,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
if (new_data->direct_on_input)
return PA_HOOK_OK;
- if (!(name = get_name(new_data->proplist, "source-output")))
+ if (!(name = pa_proplist_get_stream_group(new_data->proplist, "source-output", IDENTIFICATION_PROPERTY)))
return PA_HOOK_OK;
if (new_data->source)
@@ -1582,7 +1558,7 @@ static pa_hook_result_t source_output_fixate_hook_callback(pa_core *c, pa_source
pa_assert(u);
pa_assert(u->restore_volume || u->restore_muted);
- if (!(name = get_name(new_data->proplist, "source-output")))
+ if (!(name = pa_proplist_get_stream_group(new_data->proplist, "source-output", IDENTIFICATION_PROPERTY)))
return PA_HOOK_OK;
if ((e = entry_read(u, name))) {
@@ -1654,7 +1630,7 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, struct
if (!PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(si)))
continue;
- if (!(name = get_name(si->proplist, "sink-input")))
+ if (!(name = pa_proplist_get_stream_group(si->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
continue;
if ((e = entry_read(u, name))) {
@@ -1702,7 +1678,7 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
if (!PA_SOURCE_OUTPUT_IS_LINKED(pa_source_output_get_state(so)))
continue;
- if (!(name = get_name(so->proplist, "source-output")))
+ if (!(name = pa_proplist_get_stream_group(so->proplist, "source-output", IDENTIFICATION_PROPERTY)))
continue;
if ((e = entry_read(u, name))) {
@@ -1738,7 +1714,7 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, str
if (!si->sink)
continue;
- if (!(name = get_name(si->proplist, "sink-input")))
+ if (!(name = pa_proplist_get_stream_group(si->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
continue;
if ((e = entry_read(u, name))) {
@@ -1784,7 +1760,7 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc
if (!so->source)
continue;
- if (!(name = get_name(so->proplist, "source-output")))
+ if (!(name = pa_proplist_get_stream_group(so->proplist, "source-output", IDENTIFICATION_PROPERTY)))
continue;
if ((e = entry_read(u, name))) {
@@ -1903,7 +1879,7 @@ static void entry_apply(struct userdata *u, const char *name, struct entry *e) {
char *n;
pa_sink *s;
- if (!(n = get_name(si->proplist, "sink-input")))
+ if (!(n = pa_proplist_get_stream_group(si->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
continue;
if (!pa_streq(name, n)) {
@@ -1951,7 +1927,7 @@ static void entry_apply(struct userdata *u, const char *name, struct entry *e) {
char *n;
pa_source *s;
- if (!(n = get_name(so->proplist, "source-output")))
+ if (!(n = pa_proplist_get_stream_group(so->proplist, "source-output", IDENTIFICATION_PROPERTY)))
continue;
if (!pa_streq(name, n)) {
diff --git a/src/pulsecore/proplist-util.c b/src/pulsecore/proplist-util.c
index 642c498..bec857a 100644
--- a/src/pulsecore/proplist-util.c
+++ b/src/pulsecore/proplist-util.c
@@ -241,3 +241,33 @@ void pa_init_proplist(pa_proplist *p) {
}
}
}
+
+char *pa_proplist_get_stream_group(pa_proplist *p, const char *prefix, const char *cache) {
+ const char *r;
+ char *t;
+
+ if (!p)
+ return NULL;
+
+ if (cache && (r = pa_proplist_gets(p, cache)))
+ return pa_xstrdup(r);
+
+ if (!prefix)
+ prefix = "stream";
+
+ if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_ROLE)))
+ t = pa_sprintf_malloc("%s-by-media-role:%s", prefix, r);
+ else if ((r = pa_proplist_gets(p, PA_PROP_APPLICATION_ID)))
+ t = pa_sprintf_malloc("%s-by-application-id:%s", prefix, r);
+ else if ((r = pa_proplist_gets(p, PA_PROP_APPLICATION_NAME)))
+ t = pa_sprintf_malloc("%s-by-application-name:%s", prefix, r);
+ else if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_NAME)))
+ t = pa_sprintf_malloc("%s-by-media-name:%s", prefix, r);
+ else
+ t = pa_sprintf_malloc("%s-fallback:%s", prefix, r);
+
+ if (cache)
+ pa_proplist_sets(p, cache, t);
+
+ return t;
+}
diff --git a/src/pulsecore/proplist-util.h b/src/pulsecore/proplist-util.h
index c6bdc10..3d08776 100644
--- a/src/pulsecore/proplist-util.h
+++ b/src/pulsecore/proplist-util.h
@@ -25,5 +25,6 @@
#include <pulse/proplist.h>
void pa_init_proplist(pa_proplist *p);
+char *pa_proplist_get_stream_group(pa_proplist *pl, const char *prefix, const char *cache);
#endif
More information about the pulseaudio-commits
mailing list