return false;
}
-static void update_sink_or_source_as_device_change(pa_stream_manager *m, stream_route_type_t stream_route_type, pa_idxset *streams,
- stream_type_t stream_type, pa_tz_device *device, bool is_connected) {
+static void check_and_move_streams_by_device_connection_change(pa_stream_manager *m, stream_route_type_t stream_route_type,
+ pa_idxset *streams, stream_type_t stream_type, pa_tz_device *device, bool is_connected) {
#define MAX_CACHED_LEN 128
typedef struct _cached_device_list {
const char *device_type;
return PA_HOOK_OK;
}
+static void update_sink_or_source_by_device_connection_change(pa_stream_manager *m, pa_tz_device_hook_data_for_conn_changed *data,
+ bool use_internal_codec, dm_device_direction_t device_direction) {
+ pa_sink *sink = NULL;
+ pa_source *source = NULL;
+
+ pa_assert(m);
+ pa_assert(data);
+
+ /* Update streams belong to this external device that have MAUAL_EXT route type */
+ if (!use_internal_codec) {
+ if ((device_direction & DM_DEVICE_DIRECTION_IN) &&
+ (source = pa_tz_device_get_source(data->device, NULL)))
+ check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, source->outputs,
+ STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
+ if ((device_direction & DM_DEVICE_DIRECTION_OUT) &&
+ (sink = pa_tz_device_get_sink(data->device, NULL)))
+ check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, sink->inputs,
+ STREAM_SINK_INPUT, data->device, data->is_connected);
+ }
+
+ /* Update all the streams that have AUTO route type */
+ if (device_direction & DM_DEVICE_DIRECTION_IN) {
+ check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->source_outputs,
+ STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
+ check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->source_outputs,
+ STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
+ }
+ if (device_direction & DM_DEVICE_DIRECTION_OUT) {
+ check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->sink_inputs,
+ STREAM_SINK_INPUT, data->device, data->is_connected);
+ check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->sink_inputs,
+ STREAM_SINK_INPUT, data->device, data->is_connected);
+ }
+}
+
/* Reorganize routing when a device has been connected or disconnected */
static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_device_hook_data_for_conn_changed *data, pa_stream_manager *m) {
const char *active_dev = NULL;
uint32_t s_idx = 0;
uint32_t device_id = 0;
pa_sink *sink = NULL;
- pa_source *source = NULL;
pa_sink_input *si = NULL;
pa_sink_input *highest_prior_si = NULL;
pa_source_output *highest_prior_so = NULL;
}
}
- /* Update streams belong to this external device that have MAUAL_EXT route type */
- if (!use_internal_codec) {
- if (device_direction & DM_DEVICE_DIRECTION_IN) {
- if ((source = pa_tz_device_get_source(data->device, NULL)))
- update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, source->outputs,
- STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
- }
- if (device_direction & DM_DEVICE_DIRECTION_OUT) {
- if ((sink = pa_tz_device_get_sink(data->device, NULL)))
- update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, sink->inputs,
- STREAM_SINK_INPUT, data->device, data->is_connected);
- }
- }
-
- /* Update all the streams that have AUTO route type */
- if (device_direction & DM_DEVICE_DIRECTION_IN) {
- update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->source_outputs,
- STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
- update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->source_outputs,
- STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
- }
- if (device_direction & DM_DEVICE_DIRECTION_OUT) {
- update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->sink_inputs,
- STREAM_SINK_INPUT, data->device, data->is_connected);
- update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->sink_inputs,
- STREAM_SINK_INPUT, data->device, data->is_connected);
- }
+ update_sink_or_source_by_device_connection_change(m, data, use_internal_codec, device_direction);
/* If the route type is AUTO SERIES, notify again */
highest_prior_so = m->cur_highest_priority.source_output;