device-manager: Refactor the routing method to allow the routing of a single stream

This commit is contained in:
Colin Guthrie 2009-09-20 20:57:34 +01:00
parent 8d0787c1d5
commit d3460e3498

View file

@ -598,6 +598,47 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
return PA_HOOK_OK; return PA_HOOK_OK;
} }
static void route_sink_input(struct userdata *u, pa_sink_input *si) {
const char *role;
uint32_t role_index, device_index;
pa_sink *sink;
pa_assert(u);
pa_assert(u->do_routing);
if (si->save_sink)
return;
/* Skip this if it is already in the process of being moved anyway */
if (!si->sink)
return;
/* 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)))
return;
if (!(role = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_ROLE)))
role_index = get_role_index("");
else
role_index = get_role_index(role);
if (PA_INVALID_INDEX == role_index)
return;
device_index = u->preferred_sinks[role_index];
if (PA_INVALID_INDEX == device_index)
return;
if (!(sink = pa_idxset_get_by_index(u->core->sinks, device_index)))
return;
if (si->sink != sink)
pa_sink_input_move_to(si, sink, TRUE);
}
static pa_hook_result_t route_sink_inputs(struct userdata *u, pa_sink *ignore_sink) { static pa_hook_result_t route_sink_inputs(struct userdata *u, pa_sink *ignore_sink) {
pa_sink_input *si; pa_sink_input *si;
uint32_t idx; uint32_t idx;
@ -610,43 +651,53 @@ static pa_hook_result_t route_sink_inputs(struct userdata *u, pa_sink *ignore_si
update_highest_priority_device_indexes(u, "sink:", ignore_sink); update_highest_priority_device_indexes(u, "sink:", ignore_sink);
PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) { PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
route_sink_input(u, si);
}
return PA_HOOK_OK;
}
static void route_source_output(struct userdata *u, pa_source_output *so) {
const char *role; const char *role;
uint32_t role_index, device_index; uint32_t role_index, device_index;
pa_sink *sink; pa_source *source;
if (si->save_sink) pa_assert(u);
continue; pa_assert(u->do_routing);
if (so->save_source)
return;
if (so->direct_on_input)
return;
/* Skip this if it is already in the process of being moved anyway */ /* Skip this if it is already in the process of being moved anyway */
if (!si->sink) if (!so->source)
continue; return;
/* It might happen that a stream and a sink 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
interfere with that */ interfere with that */
if (!PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(si))) if (!PA_SOURCE_OUTPUT_IS_LINKED(pa_source_output_get_state(so)))
continue; return;
if (!(role = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_ROLE))) if (!(role = pa_proplist_gets(so->proplist, PA_PROP_MEDIA_ROLE)))
role_index = get_role_index(""); role_index = get_role_index("");
else else
role_index = get_role_index(role); role_index = get_role_index(role);
if (PA_INVALID_INDEX == role_index) if (PA_INVALID_INDEX == role_index)
continue; return;
device_index = u->preferred_sinks[role_index]; device_index = u->preferred_sources[role_index];
if (PA_INVALID_INDEX == device_index) if (PA_INVALID_INDEX == device_index)
continue; return;
if (!(sink = pa_idxset_get_by_index(u->core->sinks, device_index))) if (!(source = pa_idxset_get_by_index(u->core->sources, device_index)))
continue; return;
if (si->sink != sink) if (so->source != source)
pa_sink_input_move_to(si, sink, TRUE); pa_source_output_move_to(so, source, TRUE);
}
return PA_HOOK_OK;
} }
static pa_hook_result_t route_source_outputs(struct userdata *u, pa_source* ignore_source) { static pa_hook_result_t route_source_outputs(struct userdata *u, pa_source* ignore_source) {
@ -661,43 +712,7 @@ static pa_hook_result_t route_source_outputs(struct userdata *u, pa_source* igno
update_highest_priority_device_indexes(u, "source:", ignore_source); update_highest_priority_device_indexes(u, "source:", ignore_source);
PA_IDXSET_FOREACH(so, u->core->source_outputs, idx) { PA_IDXSET_FOREACH(so, u->core->source_outputs, idx) {
const char *role; route_source_output(u, so);
uint32_t role_index, device_index;
pa_source *source;
if (so->save_source)
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)))
role_index = get_role_index("");
else
role_index = get_role_index(role);
if (PA_INVALID_INDEX == role_index)
continue;
device_index = u->preferred_sources[role_index];
if (PA_INVALID_INDEX == device_index)
continue;
if (!(source = pa_idxset_get_by_index(u->core->sources, device_index)))
continue;
if (so->source != source)
pa_source_output_move_to(so, source, TRUE);
} }
return PA_HOOK_OK; return PA_HOOK_OK;