if (s == def)
continue;
+ if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)))
+ continue;
+
if (role_match(s->proplist, role)) {
new_data->sink = s;
new_data->save_sink = FALSE;
if (s == def)
continue;
+ if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
+ continue;
+
if (role_match(s->proplist, role)) {
new_data->source = s;
new_data->save_source = FALSE;
if (si->save_sink)
continue;
+ /* Skip this if it is already in the process of being moved
+ * anyway */
+ if (!si->sink)
+ continue;
+
+ /* 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
+ interfere with that */
+ if (!PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(si)))
+ continue;
+
if (!(role = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_ROLE)))
continue;
if (so->direct_on_input)
continue;
+ /* Skip this if it is already in the process of being moved
+ * anyway */
+ if (!so->source)
+ continue;
+
+ /* 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
+ interfere with that */
+ if (!PA_SOURCE_OUTPUT_IS_LINKED(pa_source_output_get_state(so)))
+ continue;
+
if (!(role = pa_proplist_gets(so->proplist, PA_PROP_MEDIA_ROLE)))
continue;
uint32_t jdx;
pa_sink *d;
+ if (!si->sink)
+ continue;
+
if (!(role = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_ROLE)))
continue;
/* Would the default sink fit? If so, let's use it */
- if (def != sink && role_match(def->proplist, role)) {
- pa_sink_input_move_to(si, def, FALSE);
- continue;
- }
+ if (def != sink && role_match(def->proplist, role))
+ if (pa_sink_input_move_to(si, def, FALSE) >= 0)
+ continue;
/* Try to find some other fitting sink */
PA_IDXSET_FOREACH(d, c->sinks, jdx) {
if (d == def || d == sink)
continue;
- if (role_match(d->proplist, role)) {
- pa_sink_input_move_to(si, d, FALSE);
- break;
- }
+ if (!PA_SINK_IS_LINKED(pa_sink_get_state(d)))
+ continue;
+
+ if (role_match(d->proplist, role))
+ if (pa_sink_input_move_to(si, d, FALSE) >= 0)
+ break;
}
}
if (so->direct_on_input)
continue;
+ if (!so->source)
+ continue;
+
if (!(role = pa_proplist_gets(so->proplist, PA_PROP_MEDIA_ROLE)))
continue;
if (d == def || d == source)
continue;
+ if (!PA_SOURCE_IS_LINKED(pa_source_get_state(d)))
+ continue;
+
if (role_match(d->proplist, role) && !source->monitor_of == !d->monitor_of) {
pa_source_output_move_to(so, d, FALSE);
break;
if (target == skip)
continue;
+ if (!PA_SINK_IS_LINKED(pa_sink_get_state(target)))
+ continue;
+
if (pa_sink_input_may_move_to(i, target))
return target;
}
if (!target->monitor_of != !skip->monitor_of)
continue;
+ if (!PA_SOURCE_IS_LINKED(pa_source_get_state(target)))
+ continue;
+
if (pa_source_output_may_move_to(o, target))
return target;
}
if (si->save_sink)
continue;
+ /* Skip this if it is already in the process of being moved
+ * anyway */
+ if (!si->sink)
+ continue;
+
/* 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
interfere with that */
if (so->direct_on_input)
continue;
+ /* Skip this if it is already in the process of being moved anyway */
+ if (!so->source)
+ continue;
+
/* 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
interfere with that */
char *name;
struct entry *e;
+ if (!si->sink)
+ continue;
+
if (!(name = get_name(si->proplist, "sink-input")))
continue;
char *name;
struct entry *e;
+ if (so->direct_on_input)
+ continue;
+
+ if (!so->source)
+ continue;
+
if (!(name = get_name(so->proplist, "source-output")))
continue;
pa_sink* pa_namereg_set_default_sink(pa_core*c, pa_sink *s) {
pa_assert(c);
+ if (s && !PA_SINK_IS_LINKED(pa_sink_get_state(s)))
+ return NULL;
+
if (c->default_sink != s) {
c->default_sink = s;
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
pa_source* pa_namereg_set_default_source(pa_core*c, pa_source *s) {
pa_assert(c);
+ if (s && !PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
+ return NULL;
+
if (c->default_source != s) {
c->default_source = s;
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
pa_sink *pa_namereg_get_default_sink(pa_core *c) {
pa_sink *s;
+ uint32_t idx;
pa_assert(c);
- if (c->default_sink)
+ if (c->default_sink && PA_SINK_IS_LINKED(pa_sink_get_state(c->default_sink)))
return c->default_sink;
- if ((s = pa_idxset_first(c->sinks, NULL)))
- return pa_namereg_set_default_sink(c, s);
+ /* FIXME: the selection here should be based priority values on
+ * the sinks */
+
+ PA_IDXSET_FOREACH(s, c->sinks, idx)
+ if (PA_SINK_IS_LINKED(pa_sink_get_state(s)))
+ return pa_namereg_set_default_sink(c, s);
return NULL;
}
pa_assert(c);
- if (c->default_source)
+ if (c->default_source && PA_SOURCE_IS_LINKED(pa_source_get_state(c->default_source)))
return c->default_source;
- for (s = PA_SOURCE(pa_idxset_first(c->sources, &idx)); s; s = PA_SOURCE(pa_idxset_next(c->sources, &idx)))
- if (!s->monitor_of)
+ /* First, try to find one that isn't a monitor */
+ PA_IDXSET_FOREACH(s, c->sources, idx)
+ if (!s->monitor_of && PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
return pa_namereg_set_default_source(c, s);
- if ((s = pa_idxset_first(c->sources, NULL)))
- return pa_namereg_set_default_source(c, s);
+ /* Then, fallback to a monitor */
+ PA_IDXSET_FOREACH(s, c->sources, idx)
+ if (PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
+ return pa_namereg_set_default_source(c, s);
return NULL;
}