}
}
-ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data) {
+static ret_msg_t prepare_and_invoke_hook_to_select_device(pa_stream_manager *m, notify_command_type_t command, stream_type_t type,
+ bool is_new_data, void *user_data) {
+ ret_msg_t ret = RET_MSG_OK;
pa_stream_manager_hook_data_for_select hook_call_select_data;
- pa_stream_manager_hook_data_for_route hook_call_route_data;
- hal_stream_connection_info stream_conn_info;
- hal_route_option route_option;
+ pa_idxset *filtered_avail_devices = NULL;
void *s = NULL;
- const char *modifier_gain = NULL;
- ret_msg_t ret = RET_MSG_OK;
pa_assert(m);
- pa_log_debug("[%s]: type(%d), is_new_data(%d), user_data(%p)", notify_command_type_str[command], type, is_new_data, user_data);
+ pa_assert(user_data);
- switch (command) {
- case NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT: {
- pa_assert(user_data);
- memset(&hook_call_select_data, 0, sizeof(pa_stream_manager_hook_data_for_select));
- hook_call_select_data.stream = s = user_data;
- if (s) {
- pa_idxset *filtered_avail_devices = NULL;
- hook_call_select_data.stream_type = type;
- hook_call_select_data.origins_from_new_data = is_new_data;
- if (is_new_data) {
- hook_call_select_data.stream_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type),
- PA_PROP_MEDIA_ROLE);
- hook_call_select_data.device_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type),
- PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
- fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data);
- hook_call_select_data.sample_spec = GET_STREAM_NEW_SAMPLE_SPEC(s, type);
- if (type == STREAM_SINK_INPUT) {
- hook_call_select_data.occupying_role = m->cur_highest_priority.role_si;
- if (IS_ROLE_COMMUNICATION(hook_call_select_data.occupying_role)) {
- /* Currently, if bt-sco is used by communication stream, other streams can not go with bt-a2dp.
- Here we exclude bt-a2dp device type, therefore this stream can be mixed together by using another device */
- filtered_avail_devices = get_avail_devices_except_bt_a2dp(hook_call_select_data.idx_avail_devices);
- hook_call_select_data.idx_avail_devices = filtered_avail_devices;
- }
- hook_call_select_data.proper_sink = &(((pa_sink_input_new_data*)s)->sink);
- /* need to check modifier_gain, because we do not skip a stream that is from module-sound-player */
- modifier_gain = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
- if (((pa_sink_input_new_data*)s)->sink && !modifier_gain) {
- pa_log_info(" - sink(%s) has been already selected, skip selecting sink",
- (((pa_sink_input_new_data*)s)->sink)->name);
- goto BREAK_WITH_FREE;
- }
- } else if (type == STREAM_SOURCE_OUTPUT) {
- hook_call_select_data.occupying_role = m->cur_highest_priority.role_so;
- hook_call_select_data.proper_source = &(((pa_source_output_new_data*)s)->source);
- if (((pa_source_output_new_data*)s)->source) {
- pa_log_info(" - source(%s) has been already selected, skip selecting source",
- (((pa_source_output_new_data*)s)->source)->name);
- break;
- }
- }
- } else {
- hook_call_select_data.stream_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type),
- PA_PROP_MEDIA_ROLE);
- hook_call_select_data.device_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type),
- PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
- fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data);
- hook_call_select_data.sample_spec = GET_STREAM_SAMPLE_SPEC(s, type);
- if (type == STREAM_SINK_INPUT)
- hook_call_select_data.proper_sink = &(((pa_sink_input*)s)->sink);
- else if (type == STREAM_SOURCE_OUTPUT)
- hook_call_select_data.proper_source = &(((pa_source_output*)s)->source);
+ if (command != NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT)
+ return RET_MSG_ERROR_INVALID_ARGUMENT;
+
+ memset(&hook_call_select_data, 0, sizeof(pa_stream_manager_hook_data_for_select));
+ hook_call_select_data.stream = s = user_data;
+ if (!s)
+ return ret;
+
+ hook_call_select_data.stream_type = type;
+ hook_call_select_data.origins_from_new_data = is_new_data;
+ if (is_new_data) {
+ hook_call_select_data.stream_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type),
+ PA_PROP_MEDIA_ROLE);
+ hook_call_select_data.device_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type),
+ PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+ fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data);
+ hook_call_select_data.sample_spec = GET_STREAM_NEW_SAMPLE_SPEC(s, type);
+ if (type == STREAM_SINK_INPUT) {
+ const char *modifier_gain = NULL;
+ hook_call_select_data.occupying_role = m->cur_highest_priority.role_si;
+ if (IS_ROLE_COMMUNICATION(hook_call_select_data.occupying_role)) {
+ /* Currently, if bt-sco is used by communication stream, other streams can not go with bt-a2dp.
+ Here we exclude bt-a2dp device type, therefore this stream can be mixed together by using another device */
+ filtered_avail_devices = get_avail_devices_except_bt_a2dp(hook_call_select_data.idx_avail_devices);
+ hook_call_select_data.idx_avail_devices = filtered_avail_devices;
+ }
+ hook_call_select_data.proper_sink = &(((pa_sink_input_new_data*)s)->sink);
+ /* need to check modifier_gain, because we do not skip a stream that is from module-sound-player */
+ modifier_gain = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
+ if (((pa_sink_input_new_data*)s)->sink && !modifier_gain) {
+ pa_log_info(" - sink(%s) has been already selected, skip selecting sink",
+ (((pa_sink_input_new_data*)s)->sink)->name);
+ goto BREAK_WITH_FREE;
+ }
+ } else if (type == STREAM_SOURCE_OUTPUT) {
+ hook_call_select_data.occupying_role = m->cur_highest_priority.role_so;
+ hook_call_select_data.proper_source = &(((pa_source_output_new_data*)s)->source);
+ if (((pa_source_output_new_data*)s)->source) {
+ pa_log_info(" - source(%s) has been already selected, skip selecting source",
+ (((pa_source_output_new_data*)s)->source)->name);
+ return ret;
}
- if (hook_call_select_data.route_type == STREAM_ROUTE_TYPE_MANUAL)
- CONVERT_TO_DEVICE_ROLE(hook_call_select_data.stream_role, hook_call_select_data.device_role);
- if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE), &hook_call_select_data))
- ret = RET_MSG_ERROR_INTERNAL;
-BREAK_WITH_FREE:
- pa_xfree(filtered_avail_devices);
}
- break;
- }
- case NOTIFY_COMMAND_CHANGE_ROUTE_START: {
+ } else {
+ hook_call_select_data.stream_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type),
+ PA_PROP_MEDIA_ROLE);
+ hook_call_select_data.device_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type),
+ PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+ fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data);
+ hook_call_select_data.sample_spec = GET_STREAM_SAMPLE_SPEC(s, type);
+ if (type == STREAM_SINK_INPUT)
+ hook_call_select_data.proper_sink = &(((pa_sink_input*)s)->sink);
+ else if (type == STREAM_SOURCE_OUTPUT)
+ hook_call_select_data.proper_source = &(((pa_source_output*)s)->source);
+ }
+ if (hook_call_select_data.route_type == STREAM_ROUTE_TYPE_MANUAL)
+ CONVERT_TO_DEVICE_ROLE(hook_call_select_data.stream_role, hook_call_select_data.device_role);
+ if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE), &hook_call_select_data))
+ ret = RET_MSG_ERROR_INTERNAL;
+BREAK_WITH_FREE:
+ pa_xfree(filtered_avail_devices);
+
+ return ret;
+}
+
+static ret_msg_t prepare_and_invoke_hook_to_change_route(pa_stream_manager *m, notify_command_type_t command, stream_type_t type,
+ bool is_new_data, void *user_data) {
+ ret_msg_t ret = RET_MSG_OK;
+ pa_stream_manager_hook_data_for_route hook_call_route_data;
+ void *s = NULL;
+
+ pa_assert(m);
+
+ if (command != NOTIFY_COMMAND_CHANGE_ROUTE_START &&
+ command != NOTIFY_COMMAND_CHANGE_ROUTE_END)
+ return RET_MSG_ERROR_INVALID_ARGUMENT;
+
+ if (command == NOTIFY_COMMAND_CHANGE_ROUTE_START) {
pa_assert(user_data);
memset(&hook_call_route_data, 0, sizeof(pa_stream_manager_hook_data_for_route));
hook_call_route_data.stream = s = user_data;
- if (s) {
- if (is_new_data) {
- hook_call_route_data.origins_from_new_data = true;
- hook_call_route_data.stream_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
- hook_call_route_data.device_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
- hook_call_route_data.sample_spec = GET_STREAM_NEW_SAMPLE_SPEC(s, type);
- if (type == STREAM_SINK_INPUT) {
- hook_call_route_data.proper_sink = &(((pa_sink_input_new_data*)s)->sink);
- } else if (type == STREAM_SOURCE_OUTPUT) {
- hook_call_route_data.proper_source = &(((pa_source_output_new_data*)s)->source);
- }
- } else {
- hook_call_route_data.stream_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
- hook_call_route_data.device_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
- hook_call_route_data.sample_spec = GET_STREAM_SAMPLE_SPEC(s, type);
- hook_call_route_data.idx_streams = (type == STREAM_SINK_INPUT) ? ((pa_sink_input*)s)->sink->inputs :
- ((pa_source_output*)s)->source->outputs;
+ if (!s)
+ return ret;
+
+ if (is_new_data) {
+ hook_call_route_data.origins_from_new_data = true;
+ hook_call_route_data.stream_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
+ hook_call_route_data.device_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+ hook_call_route_data.sample_spec = GET_STREAM_NEW_SAMPLE_SPEC(s, type);
+ if (type == STREAM_SINK_INPUT) {
+ hook_call_route_data.proper_sink = &(((pa_sink_input_new_data*)s)->sink);
+ } else if (type == STREAM_SOURCE_OUTPUT) {
+ hook_call_route_data.proper_source = &(((pa_source_output_new_data*)s)->source);
}
- hook_call_route_data.stream_type = type;
- if (hook_call_route_data.route_type == STREAM_ROUTE_TYPE_MANUAL)
- CONVERT_TO_DEVICE_ROLE(hook_call_route_data.stream_role, hook_call_route_data.device_role);
- fill_device_info_to_hook_data(m, &hook_call_route_data, command, type, s, is_new_data);
- if (hook_call_route_data.route_type == STREAM_ROUTE_TYPE_MANUAL || hook_call_route_data.route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
- if (hook_call_route_data.idx_manual_devices && !pa_idxset_size(hook_call_route_data.idx_manual_devices)) {
- pa_log_warn("no manual device for this type(%d)", type);
- hook_call_route_data.stream = NULL;
- }
+ } else {
+ hook_call_route_data.stream_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
+ hook_call_route_data.device_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+ hook_call_route_data.sample_spec = GET_STREAM_SAMPLE_SPEC(s, type);
+ hook_call_route_data.idx_streams = (type == STREAM_SINK_INPUT) ? ((pa_sink_input*)s)->sink->inputs :
+ ((pa_source_output*)s)->source->outputs;
+ }
+ hook_call_route_data.stream_type = type;
+ if (hook_call_route_data.route_type == STREAM_ROUTE_TYPE_MANUAL)
+ CONVERT_TO_DEVICE_ROLE(hook_call_route_data.stream_role, hook_call_route_data.device_role);
+ fill_device_info_to_hook_data(m, &hook_call_route_data, command, type, s, is_new_data);
+ if (hook_call_route_data.route_type == STREAM_ROUTE_TYPE_MANUAL || hook_call_route_data.route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
+ if (hook_call_route_data.idx_manual_devices && !pa_idxset_size(hook_call_route_data.idx_manual_devices)) {
+ pa_log_warn("no manual device for this type(%d)", type);
+ hook_call_route_data.stream = NULL;
}
- if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data))
- ret = RET_MSG_ERROR_INTERNAL;
}
- break;
- }
- case NOTIFY_COMMAND_CHANGE_ROUTE_END: {
+ if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data))
+ ret = RET_MSG_ERROR_INTERNAL;
+
+ } else {
memset(&hook_call_route_data, 0, sizeof(pa_stream_manager_hook_data_for_route));
s = (type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input) :
(void*)(m->cur_highest_priority.source_output);
}
if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data))
ret = RET_MSG_ERROR_INTERNAL;
- break;
}
+
+ return ret;
+}
+
+ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data) {
+ hal_stream_connection_info stream_conn_info;
+ hal_route_option route_option;
+ void *s = NULL;
+ ret_msg_t ret = RET_MSG_OK;
+
+ pa_assert(m);
+ pa_log_debug("[%s]: type(%d), is_new_data(%d), user_data(%p)", notify_command_type_str[command], type, is_new_data, user_data);
+
+ switch (command) {
+ case NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT:
+ ret = prepare_and_invoke_hook_to_select_device(m, command, type, is_new_data, user_data);
+ break;
+
+ case NOTIFY_COMMAND_CHANGE_ROUTE_START:
+ case NOTIFY_COMMAND_CHANGE_ROUTE_END:
+ ret = prepare_and_invoke_hook_to_change_route(m, command, type, is_new_data, user_data);
+ break;
+
case NOTIFY_COMMAND_UPDATE_ROUTE_OPTION: {
pa_assert(user_data);
memset(&route_option, 0, sizeof(hal_route_option));
ret = RET_MSG_ERROR_INTERNAL;
break;
}
+
case NOTIFY_COMMAND_INFORM_STREAM_CONNECTED:
case NOTIFY_COMMAND_INFORM_STREAM_DISCONNECTED: {
pa_assert(user_data);