module-device-manager: Refine logic to ignore filtered streams

Rather than entirely ignore streams for which we have automatically
loaded a filter, this makes module-device-manager only avoid rerouting
such streams within their existing filter hierarchy.

If, for example, m-d-m decided to move a stream which is currently
routed to speakers/mic which we requested echo cancellation for, to a
USB headset, the previous logic would disallow such a move even though
it was legitimate.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93443

Signed-off-by: Arun Raghavan <git@arunraghavan.net>
This commit is contained in:
Arun Raghavan 2016-05-06 11:56:00 +05:30
parent 4331733c19
commit fcee3da944
2 changed files with 31 additions and 15 deletions

View file

@ -649,9 +649,10 @@ static void update_highest_priority_device_indexes(struct userdata *u, const cha
} }
static void route_sink_input(struct userdata *u, pa_sink_input *si) { static void route_sink_input(struct userdata *u, pa_sink_input *si) {
const char *ignore; const char *auto_filtered_prop;
const char *role; const char *role;
uint32_t role_index, device_index; uint32_t role_index, device_index;
bool auto_filtered = false;
pa_sink *sink; pa_sink *sink;
pa_assert(u); pa_assert(u);
@ -664,9 +665,9 @@ static void route_sink_input(struct userdata *u, pa_sink_input *si) {
if (!si->sink) if (!si->sink)
return; return;
ignore = pa_proplist_gets(si->proplist, "module-device-manager.ignore"); auto_filtered_prop = pa_proplist_gets(si->proplist, "module-device-manager.auto_filtered");
if (ignore && (pa_parse_boolean(ignore) == 1)) if (auto_filtered_prop)
return; auto_filtered = (pa_parse_boolean(auto_filtered_prop) == 1);
/* It might happen that a stream and a sink are set up at the /* It might happen that a stream and a sink are set up at the
same time, in which case we want to make sure we don't same time, in which case we want to make sure we don't
@ -689,6 +690,13 @@ static void route_sink_input(struct userdata *u, pa_sink_input *si) {
if (!(sink = pa_idxset_get_by_index(u->core->sinks, device_index))) if (!(sink = pa_idxset_get_by_index(u->core->sinks, device_index)))
return; return;
if (auto_filtered) {
/* For streams for which a filter has been loaded by another module, we
* do not try to execute moves within the same filter hierarchy */
if (pa_sink_get_master(si->sink) == pa_sink_get_master(sink))
return;
}
if (si->sink != sink) if (si->sink != sink)
pa_sink_input_move_to(si, sink, false); pa_sink_input_move_to(si, sink, false);
} }
@ -712,9 +720,10 @@ static pa_hook_result_t route_sink_inputs(struct userdata *u, pa_sink *ignore_si
} }
static void route_source_output(struct userdata *u, pa_source_output *so) { static void route_source_output(struct userdata *u, pa_source_output *so) {
const char *ignore; const char *auto_filtered_prop;
const char *role; const char *role;
uint32_t role_index, device_index; uint32_t role_index, device_index;
bool auto_filtered = false;
pa_source *source; pa_source *source;
pa_assert(u); pa_assert(u);
@ -730,9 +739,9 @@ static void route_source_output(struct userdata *u, pa_source_output *so) {
if (!so->source) if (!so->source)
return; return;
ignore = pa_proplist_gets(so->proplist, "module-device-manager.ignore"); auto_filtered_prop = pa_proplist_gets(so->proplist, "module-device-manager.auto_filtered");
if (ignore && (pa_parse_boolean(ignore) == 1)) if (auto_filtered_prop)
return; auto_filtered = (pa_parse_boolean(auto_filtered_prop) == 1);
/* It might happen that a stream and a source are set up at the /* It might happen that a stream and a source are set up at the
same time, in which case we want to make sure we don't same time, in which case we want to make sure we don't
@ -755,6 +764,13 @@ static void route_source_output(struct userdata *u, pa_source_output *so) {
if (!(source = pa_idxset_get_by_index(u->core->sources, device_index))) if (!(source = pa_idxset_get_by_index(u->core->sources, device_index)))
return; return;
if (auto_filtered) {
/* For streams for which a filter has been loaded by another module, we
* do not try to execute moves within the same filter hierarchy */
if (pa_source_get_master(so->source) == pa_source_get_master(source))
return;
}
if (so->source != source) if (so->source != source)
pa_source_output_move_to(so, source, false); pa_source_output_move_to(so, source, false);
} }

View file

@ -38,7 +38,7 @@
#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_MOVING "filter.apply.moving"
#define PA_PROP_MDM_IGNORE "module-device-manager.ignore" #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");
@ -66,8 +66,8 @@ struct filter {
struct userdata { struct userdata {
pa_core *core; pa_core *core;
pa_hashmap *filters; pa_hashmap *filters;
/* Keep track of streams we're managing PA_PROP_MDM_IGNORE on, we're only /* Keep track of streams we're managing PA_PROP_MDM_AUTO_FILTERED on, we're
* maintaining membership, so key and value are just the * only maintaining membership, so key and value are just the
* pa_sink_input/pa_source_output. */ * pa_sink_input/pa_source_output. */
pa_hashmap *mdm_ignored_inputs, *mdm_ignored_outputs; pa_hashmap *mdm_ignored_inputs, *mdm_ignored_outputs;
bool autoclean; bool autoclean;
@ -280,10 +280,10 @@ static int do_move(struct userdata *u, pa_object *obj, pa_object *parent, bool i
pa_hashmap_put(is_input ? u->mdm_ignored_inputs : u->mdm_ignored_outputs, obj, obj); pa_hashmap_put(is_input ? u->mdm_ignored_inputs : u->mdm_ignored_outputs, obj, obj);
if (is_input) { if (is_input) {
pa_sink_input_set_property(PA_SINK_INPUT(obj), PA_PROP_MDM_IGNORE, "1"); pa_sink_input_set_property(PA_SINK_INPUT(obj), PA_PROP_MDM_AUTO_FILTERED, "1");
return pa_sink_input_move_to(PA_SINK_INPUT(obj), PA_SINK(parent), false); return pa_sink_input_move_to(PA_SINK_INPUT(obj), PA_SINK(parent), false);
} else { } else {
pa_source_output_set_property(PA_SOURCE_OUTPUT(obj), PA_PROP_MDM_IGNORE, "1"); pa_source_output_set_property(PA_SOURCE_OUTPUT(obj), PA_PROP_MDM_AUTO_FILTERED, "1");
return pa_source_output_move_to(PA_SOURCE_OUTPUT(obj), PA_SOURCE(parent), false); return pa_source_output_move_to(PA_SOURCE_OUTPUT(obj), PA_SOURCE(parent), false);
} }
} }
@ -670,12 +670,12 @@ static pa_hook_result_t source_unlink_cb(pa_core *core, pa_source *source, struc
static void unset_mdm_ignore_input(pa_sink_input *i) static void unset_mdm_ignore_input(pa_sink_input *i)
{ {
pa_sink_input_set_property(i, PA_PROP_MDM_IGNORE, NULL); pa_sink_input_set_property(i, PA_PROP_MDM_AUTO_FILTERED, NULL);
} }
static void unset_mdm_ignore_output(pa_source_output *o) static void unset_mdm_ignore_output(pa_source_output *o)
{ {
pa_source_output_set_property(o, PA_PROP_MDM_IGNORE, NULL); pa_source_output_set_property(o, PA_PROP_MDM_AUTO_FILTERED, NULL);
} }
int pa__init(pa_module *m) { int pa__init(pa_module *m) {