+ 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 bool find_paired_master(struct userdata *u, struct filter *filter, pa_object *o, bool 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 bool nothing_attached(struct filter *f) {
+ bool no_si = true, no_so = true;
+
+ if (f->sink)
+ no_si = pa_idxset_isempty(f->sink->inputs);
+ if (f->source)
+ no_so = pa_idxset_isempty(f->source->outputs);
+
+ return no_si && no_so;