case MM_SOUND_DEVICE_TYPE_MIRRORING:
*sound_device_type = SOUND_DEVICE_FORWARDING;
break;
+ default:
+ LOGE("not supported device_type(%d)", device_type);
+ return MM_ERROR_INVALID_ARGUMENT;
}
return MM_ERROR_NONE;
g_voip_ringtone_stream_info = malloc(sizeof(sound_stream_info_s));
if (!g_voip_ringtone_stream_info) {
ret = MM_ERROR_OUT_OF_MEMORY;
- goto ERROR_CASE;
+ goto ERROR_CASE_RINGTONE;
}
memset(g_voip_ringtone_stream_info, 0, sizeof(sound_stream_info_s));
g_voip_ringtone_stream_info->stream_type = "ringtone-voip";
if ((ret = _make_pa_connection_and_register_focus(g_voip_ringtone_stream_info, true, _voip_focus_state_change_callback, NULL))) {
SM_SAFE_FREE(g_voip_ringtone_stream_info);
- goto ERROR_CASE;
+ goto ERROR_CASE_RINGTONE;
}
}
if ((ret = mm_sound_acquire_focus(g_voip_ringtone_stream_info->index, FOCUS_FOR_BOTH, EXT_INFO_VOIP_SESSION))) {
if (ret != MM_ERROR_SOUND_INVALID_STATE)
- goto ERROR_CASE;
+ goto ERROR_CASE_RINGTONE;
LOGI("already acquired, skip it");
ret = MM_ERROR_NONE;
}
if (!g_voip_ringtone_vstream_h) {
if ((ret = _make_progress_virtual_stream(g_voip_ringtone_stream_info, &g_voip_ringtone_vstream_h))) {
ret = MM_ERROR_SOUND_INTERNAL;
- goto ERROR_CASE;
+ goto ERROR_CASE_RINGTONE;
}
}
goto ERROR_CASE;
}
}
+ if (proper_device)
+ mm_sound_get_device_id(proper_device, &g_cached_voip_device_id);
+ else
+ g_cached_voip_device_id = -1;
+ if (proper_device2)
+ mm_sound_get_device_id(proper_device2, &g_cached_voip_device_id2);
+ else
+ g_cached_voip_device_id2 = -1;
+ if (device_list)
+ mm_sound_free_device_list(device_list);
}
g_cached_session_mode = mode;
- if (proper_device)
- mm_sound_get_device_id(proper_device, &g_cached_voip_device_id);
- else
- g_cached_voip_device_id = -1;
- if (proper_device2)
- mm_sound_get_device_id(proper_device2, &g_cached_voip_device_id2);
- else
- g_cached_voip_device_id2 = -1;
- if (device_list)
- mm_sound_free_device_list(device_list);
+ return ret;
+ERROR_CASE_RINGTONE:
+ if (g_voip_ringtone_vstream_h) {
+ _destroy_virtual_stream(g_voip_ringtone_vstream_h);
+ g_voip_ringtone_vstream_h = NULL;
+ }
+ if (g_voip_ringtone_stream_info) {
+ _destroy_pa_connection_and_unregister_focus(g_voip_ringtone_stream_info);
+ SM_SAFE_FREE(g_voip_ringtone_stream_info);
+ }
return ret;
ERROR_CASE:
if (g_voip_vstream_h) {
_destroy_virtual_stream(g_voip_vstream_h);
g_voip_vstream_h = NULL;
}
- if (g_voip_ringtone_vstream_h) {
- _destroy_virtual_stream(g_voip_ringtone_vstream_h);
- g_voip_ringtone_vstream_h = NULL;
- }
if (g_voip_stream_info) {
_destroy_pa_connection_and_unregister_focus(g_voip_stream_info);
SM_SAFE_FREE(g_voip_stream_info);
}
- if (g_voip_ringtone_stream_info) {
- _destroy_pa_connection_and_unregister_focus(g_voip_ringtone_stream_info);
- SM_SAFE_FREE(g_voip_ringtone_stream_info);
- }
ERROR_CASE_NO_DESTROY:
if (device_list)
mm_sound_free_device_list(device_list);
int i = 0;
int j = 0;
bool added_successfully = false;
-#if 0
- /* not ready yet. after preparing in libmm-sound, it'll be enabled */
- bool use_internal_codec = false;
-#endif
char *device_type_str = NULL;
int device_id = 0;
mm_sound_device_type_e mm_sound_device_type;
SM_INSTANCE_CHECK_FOR_PRIV(stream_info);
SM_NULL_ARG_CHECK_FOR_PRIV(device);
- if (stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL ||
- stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
-#if 0
- /* not ready yet. after preparing in libmm-sound, it'll be enabled */
- if (stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
- if ((ret = mm_sound_get_device_use_internal_codec(device, &use_internal_codec)))
- return ret;
- if (use_internal_codec)
- return MM_ERROR_POLICY_INTERNAL;
- }
-#endif
- if ((ret = mm_sound_get_device_id(device, &device_id)))
- return ret;
- if ((ret = mm_sound_get_device_type(device, &mm_sound_device_type)))
- return ret;
- if (ret == MM_ERROR_NONE)
- _convert_device_type(mm_sound_device_type, &device_type);
- if ((ret = _convert_device_type_enum_to_str(device_type, &device_type_str)))
- return ret;
- if ((ret = mm_sound_get_device_io_direction(device, &device_direction)))
- return ret;
-
- if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_IN || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
- for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
- if (!stream_info->stream_conf_info.avail_in_devices[i])
- break;
+ if (stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL &&
+ stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL_EXT) {
+ LOGE("route type is not manual or manual-ext");
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
- if (!strncmp(stream_info->stream_conf_info.avail_in_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN)) {
- for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
- if (!stream_info->manual_route_info.route_in_devices[j]) {
- stream_info->manual_route_info.route_in_devices[j] = (unsigned int)device_id;
- added_successfully = true;
- break;
- }
- if (stream_info->manual_route_info.route_in_devices[j] == (unsigned int)device_id) {
- /* it was already set */
- return MM_ERROR_POLICY_DUPLICATED;
- }
- }
+ if ((ret = mm_sound_get_device_id(device, &device_id)))
+ return ret;
+ if ((ret = mm_sound_get_device_type(device, &mm_sound_device_type)))
+ return ret;
+ if ((ret = _convert_device_type(mm_sound_device_type, &device_type)))
+ return ret;
+ if ((ret = _convert_device_type_enum_to_str(device_type, &device_type_str)))
+ return ret;
+ if ((ret = mm_sound_get_device_io_direction(device, &device_direction)))
+ return ret;
+
+ if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_IN || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
+ for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
+ if (!stream_info->stream_conf_info.avail_in_devices[i])
+ break;
+ if (strncmp(stream_info->stream_conf_info.avail_in_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN))
+ continue;
+
+ for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
+ if (!stream_info->manual_route_info.route_in_devices[j]) {
+ stream_info->manual_route_info.route_in_devices[j] = (unsigned int)device_id;
+ added_successfully = true;
+ break;
+ }
+ if (stream_info->manual_route_info.route_in_devices[j] == (unsigned int)device_id) {
+ LOGE("failed to add device, this IN/BOTH-device[type:%s, id:%d] has been already set", device_type_str, device_id);
+ return MM_ERROR_POLICY_DUPLICATED;
}
}
}
- if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_OUT || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
- for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
- if (!stream_info->stream_conf_info.avail_out_devices[i])
- break;
+ }
+ if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_OUT || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
+ for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
+ if (!stream_info->stream_conf_info.avail_out_devices[i])
+ break;
+ if (strncmp(stream_info->stream_conf_info.avail_out_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN))
+ continue;
- if (!strncmp(stream_info->stream_conf_info.avail_out_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN)) {
- for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
- if (!stream_info->manual_route_info.route_out_devices[j]) {
- stream_info->manual_route_info.route_out_devices[j] = (unsigned int)device_id;
- added_successfully = true;
- break;
- }
- if (stream_info->manual_route_info.route_out_devices[j] == (unsigned int)device_id) {
- /* it was already set */
- return MM_ERROR_POLICY_DUPLICATED;
- }
- }
+ for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
+ if (!stream_info->manual_route_info.route_out_devices[j]) {
+ stream_info->manual_route_info.route_out_devices[j] = (unsigned int)device_id;
+ added_successfully = true;
+ break;
+ }
+ if (stream_info->manual_route_info.route_out_devices[j] == (unsigned int)device_id) {
+ LOGE("failed to add device, this OUT/BOTH-device[type:%s, id:%d] has been already set", device_type_str, device_id);
+ return MM_ERROR_POLICY_DUPLICATED;
}
}
}
}
- if (!added_successfully)
- ret = MM_ERROR_POLICY_INTERNAL;
+ if (!added_successfully) {
+ LOGE("failed to add device, not supported device[type:%s, id:%d]", device_type_str, device_id);
+ return MM_ERROR_POLICY_INTERNAL;
+ }
LOGI("*** add device(type[%s],id[%d]), ret(0x%x)", device_type_str, device_id, ret);
- return ret;
+ return MM_ERROR_NONE;
}
int _remove_device_for_stream_routing(sound_stream_info_s *stream_info, sound_device_h device)
SM_INSTANCE_CHECK_FOR_PRIV(stream_info);
SM_NULL_ARG_CHECK_FOR_PRIV(device);
- if (stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL ||
- stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
- if ((ret = mm_sound_get_device_id(device, &device_id)))
- return ret;
- if ((ret = mm_sound_get_device_type(device, &mm_sound_device_type)))
- return ret;
- if (ret == MM_ERROR_NONE)
- _convert_device_type(mm_sound_device_type, &device_type);
- if ((ret = _convert_device_type_enum_to_str(device_type, &device_type_str)))
- return ret;
- if ((ret = mm_sound_get_device_io_direction(device, &device_direction)))
- return ret;
-
- if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_IN || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
- for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
- if (!stream_info->stream_conf_info.avail_in_devices[i])
- break;
+ if (stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL &&
+ stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL_EXT) {
+ LOGE("route type is not manual or manual-ext");
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
- if (!strncmp(stream_info->stream_conf_info.avail_in_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN)) {
- for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
- if (stream_info->manual_route_info.route_in_devices[j] == (unsigned int)device_id) {
- removed_successfully = true;
- stream_info->manual_route_info.route_in_devices[j] = 0;
- break;
- }
- }
+ if ((ret = mm_sound_get_device_id(device, &device_id)))
+ return ret;
+ if ((ret = mm_sound_get_device_type(device, &mm_sound_device_type)))
+ return ret;
+ if ((ret = _convert_device_type(mm_sound_device_type, &device_type)))
+ return ret;
+ if ((ret = _convert_device_type_enum_to_str(device_type, &device_type_str)))
+ return ret;
+ if ((ret = mm_sound_get_device_io_direction(device, &device_direction)))
+ return ret;
+
+ if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_IN || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
+ for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
+ if (!stream_info->stream_conf_info.avail_in_devices[i])
+ break;
+ if (strncmp(stream_info->stream_conf_info.avail_in_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN))
+ continue;
+
+ for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
+ if (stream_info->manual_route_info.route_in_devices[j] == (unsigned int)device_id) {
+ removed_successfully = true;
+ stream_info->manual_route_info.route_in_devices[j] = 0;
+ break;
}
}
}
- if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_OUT || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
- for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
- if (!stream_info->stream_conf_info.avail_out_devices[i])
- break;
+ }
+ if (device_direction == MM_SOUND_DEVICE_IO_DIRECTION_OUT || device_direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) {
+ for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
+ if (!stream_info->stream_conf_info.avail_out_devices[i])
+ break;
+ if (strncmp(stream_info->stream_conf_info.avail_out_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN))
+ continue;
- if (!strncmp(stream_info->stream_conf_info.avail_out_devices[i], device_type_str, SOUND_DEVICE_TYPE_LEN)) {
- for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
- if (stream_info->manual_route_info.route_out_devices[j] == (unsigned int)device_id) {
- removed_successfully = true;
- stream_info->manual_route_info.route_out_devices[j] = 0;
- break;
- }
- }
+ for (j = 0; j < AVAIL_DEVICES_MAX; j++) {
+ if (stream_info->manual_route_info.route_out_devices[j] == (unsigned int)device_id) {
+ removed_successfully = true;
+ stream_info->manual_route_info.route_out_devices[j] = 0;
+ break;
}
}
}
}
- if (!removed_successfully)
- ret = MM_ERROR_INVALID_ARGUMENT;
+ if (!removed_successfully) {
+ LOGE("failed to remove device, could not find this device[type:%s, id:%d]", device_type_str, device_id);
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
- LOGI("*** remove device(type[%s],id[%d]), ret(0x%x)", device_type_str, device_id, ret);
+ LOGI("*** remove device[type:%s, id:%d], ret(0x%x)", device_type_str, device_id, ret);
- return ret;
+ return MM_ERROR_NONE;
}
int _apply_stream_routing(sound_stream_info_s *stream_info)
{
- int ret = MM_ERROR_NONE;
int i = 0;
- bool need_to_apply = false;
SM_INSTANCE_CHECK_FOR_PRIV(stream_info);
- if (stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL ||
- stream_info->stream_conf_info.route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
- for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
- if (stream_info->manual_route_info.route_in_devices[i]) {
- need_to_apply = true;
- break;
- }
- if (stream_info->manual_route_info.route_out_devices[i]) {
- need_to_apply = true;
- break;
- }
- }
- if (need_to_apply)
- ret = _set_manual_route_info(stream_info->index, &stream_info->manual_route_info);
- else
- return MM_ERROR_SOUND_INVALID_STATE;
+ if (stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL &&
+ stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL_EXT) {
+ LOGE("route type is not manual or manual-ext");
+ return MM_ERROR_SOUND_INTERNAL;
+ }
- } else
- ret = MM_ERROR_SOUND_INVALID_STATE;
+ for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
+ if (stream_info->manual_route_info.route_in_devices[i] ||
+ stream_info->manual_route_info.route_out_devices[i])
+ return _set_manual_route_info(stream_info->index, &stream_info->manual_route_info);
+ }
- return ret;
+ return MM_ERROR_SOUND_INVALID_STATE;
}
int _create_virtual_stream(sound_stream_info_s *stream_info, virtual_sound_stream_info_s **virtual_stream)