/* Re-trigger for routing update for streams using auto route type */
static void process_stream_as_device_change_for_auto_route(pa_stream_manager *m, void *stream, stream_type_t stream_type,
- bool is_connected, bool use_internal_codec) {
+ bool is_connected, pa_tz_device *device) {
stream_route_type_t route_type;
+ const char *device_type;
+ bool use_internal_codec;
pa_assert(m);
pa_assert(stream);
+ pa_assert(device);
+
+ device_type = pa_tz_device_get_type(device);
+ if (stream_type == STREAM_SINK_INPUT) {
+ pa_sink *sink;
+ if ((sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL)))
+ use_internal_codec = sink->use_internal_codec;
+ else
+ pa_log_warn("sink is null");
+ } else {
+ pa_source *source;
+ if ((source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL)))
+ use_internal_codec = source->use_internal_codec;
+ else
+ pa_log_warn("source is null");
+ }
- pa_log_info("[SM][PROCESS_STREAM_FOR_AUTO] stream(%p), stream_type(%d), is_connected(%d), use_internal_codec(%d)",
- stream, stream_type, is_connected, use_internal_codec);
+ pa_log_info("[SM][PROCESS_STREAM_FOR_AUTO] stream(%p), stream_type(%d), is_connected(%d), device_type(%s), use_internal_codec(%d)",
+ stream, stream_type, is_connected, device_type, use_internal_codec);
if (get_route_type(stream, stream_type, false, &route_type) ||
(route_type != STREAM_ROUTE_TYPE_AUTO && route_type != STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))
if (((stream_type == STREAM_SINK_INPUT) && (!m->cur_highest_priority.sink_input || (m->cur_highest_priority.sink_input != stream))) ||
((stream_type == STREAM_SOURCE_OUTPUT) && (!m->cur_highest_priority.source_output || (m->cur_highest_priority.source_output != stream))))
process_stream(m, stream, stream_type, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED, false);
- } else
+ } else {
process_stream(m, stream, stream_type, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, false);
+ pa_proplist_sets(GET_STREAM_PROPLIST(stream, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, device_type);
+ }
} else {
/* it is caused by the disconnection of external device
* and the supported next device of this stream using internal audio codec */
pa_source *next_source = NULL;
pa_source *null_source = NULL;
bool available = false;
- bool use_internal_codec = false;
cached_device_list cached_prev_dev_list[MAX_CACHED_LEN] = {{NULL, 0}, };
uint32_t cnt = 0;
pa_sink *combine_sink = NULL;
source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL);
PA_IDXSET_FOREACH(s, streams, s_idx) { /* streams: core->source_outputs/core->sink_inputs */
- if (!get_route_type(s, stream_type, false, &route_type) && (route_type == stream_route_type)) {
- role = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROLE);
- pa_log_debug(" -- idx(%u), route_type(%d), role(%s)", s_idx, route_type, role);
- if (is_connected) {
- /* CONNECTED: move a stream to the new device if possible */
- if (sink && (sink != ((pa_sink_input*)s)->sink)) {
- if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) {
- is_available_device_for_auto_route(m, route_type, cur_device_type, device_type, role, stream_type, &available);
- if (available) {
- pa_sink_input_move_to(s, sink, false);
- pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)",
- s, ((pa_sink_input*)s)->index, sink, sink->name, device_type);
- use_internal_codec = sink->use_internal_codec;
- }
- } else
- pa_log_error(" -- could not find current device type for s->sink(%p)", ((pa_sink_input*)s)->sink);
- } else if (source && (source != ((pa_source_output*)s)->source)) {
- if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) {
- is_available_device_for_auto_route(m, route_type, cur_device_type, device_type, role, stream_type, &available);
- if (available) {
- pa_source_output_move_to(s, source, false);
- pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)",
- s, ((pa_source_output*)s)->index, source, source->name, device_type);
- use_internal_codec = source->use_internal_codec;
- }
- } else
- pa_log_error(" -- could not find current device type for s->source(%p)", ((pa_source_output*)s)->source);
+ if (get_route_type(s, stream_type, false, &route_type))
+ continue;
+ if (route_type != stream_route_type)
+ continue;
+ role = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROLE);
+ pa_log_debug(" -- idx(%u), route_type(%d), role(%s)", s_idx, route_type, role);
+ if (is_connected) {
+ /* CONNECTED: move a stream to the new device if possible */
+ if (sink && (sink != ((pa_sink_input*)s)->sink)) {
+ if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) {
+ is_available_device_for_auto_route(m, route_type, cur_device_type, device_type, role, stream_type, &available);
+ if (available) {
+ pa_sink_input_move_to(s, sink, false);
+ pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)",
+ s, ((pa_sink_input*)s)->index, sink, sink->name, device_type);
+ }
+ } else
+ pa_log_error(" -- could not find current device type for s->sink(%p)", ((pa_sink_input*)s)->sink);
+ } else if (source && (source != ((pa_source_output*)s)->source)) {
+ if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) {
+ is_available_device_for_auto_route(m, route_type, cur_device_type, device_type, role, stream_type, &available);
+ if (available) {
+ pa_source_output_move_to(s, source, false);
+ pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)",
+ s, ((pa_source_output*)s)->index, source, source->name, device_type);
+ }
} else
- pa_log_debug("no need to move for stream(%p, idx:%u)", s, GET_STREAM_INDEX(s, stream_type));
+ pa_log_error(" -- could not find current device type for s->source(%p)", ((pa_source_output*)s)->source);
+ } else
+ pa_log_debug("no need to move for stream(%p, idx:%u)", s, GET_STREAM_INDEX(s, stream_type));
- if (available) {
- cached_prev_dev_list[cnt++].device_type = cur_device_type;
- /* trigger to update routing path */
- process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, use_internal_codec);
+ if (available) {
+ cached_prev_dev_list[cnt++].device_type = cur_device_type;
+ /* trigger to update routing path */
+ process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, device);
+ }
+ } else if (!is_connected) {
+ /* DISCONNECTED: find a connected device that has the next priority */
+ if ((sink && (sink == ((pa_sink_input*)s)->sink))) {
+ if (!is_active_device_of_stream(s, stream_type, device_type))
+ continue;
+ find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device);
+ if (next_device) {
+ if ((next_sink = pa_tz_device_get_sink(next_device, DEVICE_ROLE_NORMAL))) {
+ new_device_type = pa_tz_device_get_type(next_device);
+ /* update activated device */
+ pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type);
+ cached_prev_dev_list[cnt++].device_type = device_type;
+ /* trigger to update routing path if the next device uses internal audio codec */
+ process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_device);
+
+ pa_sink_input_move_to(s, next_sink, false);
+ pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)",
+ s, ((pa_sink_input*)s)->index, next_sink, next_sink->name, new_device_type);
+ }
}
- } else if (!is_connected) {
- /* DISCONNECTED: find a connected device that has the next priority */
- if ((sink && (sink == ((pa_sink_input*)s)->sink))) {
- if (!is_active_device_of_stream(s, stream_type, device_type))
- continue;
- find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device);
- if (next_device) {
- if ((next_sink = pa_tz_device_get_sink(next_device, DEVICE_ROLE_NORMAL))) {
- new_device_type = pa_tz_device_get_type(next_device);
- /* update activated device */
- pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type);
- cached_prev_dev_list[cnt++].device_type = device_type;
- /* trigger to update routing path if the next device uses internal audio codec */
- if (next_sink->use_internal_codec)
- process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_sink->use_internal_codec);
-
- pa_sink_input_move_to(s, next_sink, false);
- pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)",
- s, ((pa_sink_input*)s)->index, next_sink, next_sink->name, new_device_type);
- }
- }
- if (!next_device || !next_sink) {
- pa_sink_input_move_to(s, null_sink, false);
- pa_log_warn(" -- *** sink-input(%p,%u) moves to sink(%p,%s)",
- s, ((pa_sink_input*)s)->index, null_sink, null_sink->name);
- }
+ if (!next_device || !next_sink) {
+ pa_sink_input_move_to(s, null_sink, false);
+ pa_log_warn(" -- *** sink-input(%p,%u) moves to sink(%p,%s)",
+ s, ((pa_sink_input*)s)->index, null_sink, null_sink->name);
+ }
- } else if (source && (source == ((pa_source_output*)s)->source)) {
- if (!is_active_device_of_stream(s, stream_type, device_type))
- continue;
- find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device);
- if (next_device) {
- if ((next_source = pa_tz_device_get_source(next_device, DEVICE_ROLE_NORMAL))) {
- new_device_type = pa_tz_device_get_type(next_device);
- /* update activated device */
- pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type);
- cached_prev_dev_list[cnt++].device_type = device_type;
- /* trigger to update routing path if the next device uses internal audio codec */
- if (next_source->use_internal_codec)
- process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_source->use_internal_codec);
-
- pa_source_output_move_to(s, next_source, false);
- pa_log_warn(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)",
- s, ((pa_source_output*)s)->index, next_source, next_source->name, new_device_type);
- }
- }
- if (!next_device || !next_source) {
- pa_source_output_move_to(s, null_source, false);
- pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s)",
- s, ((pa_source_output*)s)->index, null_source, null_source->name);
- }
+ } else if (source && (source == ((pa_source_output*)s)->source)) {
+ if (!is_active_device_of_stream(s, stream_type, device_type))
+ continue;
+ find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device);
+ if (next_device) {
+ if ((next_source = pa_tz_device_get_source(next_device, DEVICE_ROLE_NORMAL))) {
+ new_device_type = pa_tz_device_get_type(next_device);
+ /* update activated device */
+ pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type);
+ cached_prev_dev_list[cnt++].device_type = device_type;
+ /* trigger to update routing path if the next device uses internal audio codec */
+ if (next_source->use_internal_codec)
+ process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_device);
+
+ pa_source_output_move_to(s, next_source, false);
+ pa_log_warn(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)",
+ s, ((pa_source_output*)s)->index, next_source, next_source->name, new_device_type);
+ }
+ }
+ if (!next_device || !next_source) {
+ pa_source_output_move_to(s, null_source, false);
+ pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s)",
+ s, ((pa_source_output*)s)->index, null_source, null_source->name);
}
}
}