From: Sangchul Lee Date: Thu, 23 Mar 2017 08:17:43 +0000 (+0900) Subject: Fix invalid operation in _set_session_mode() and refactor internal functions related... X-Git-Tag: submit/tizen_3.0/20170329.043647^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12c7794e46c7a5578edb6598b5eb67102e34f850;p=platform%2Fcore%2Fapi%2Fsound-manager.git Fix invalid operation in _set_session_mode() and refactor internal functions related to manual routing Also more logs are added for easy debugging. [Version] 0.3.107 [Profile] Common [Issue Type] Bug fix and refactoring Change-Id: I77935aa524135081c1dfd56e4b86782c012572d7 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 77f034c..5e16f91 100755 --- a/packaging/capi-media-sound-manager.spec +++ b/packaging/capi-media-sound-manager.spec @@ -1,6 +1,6 @@ Name: capi-media-sound-manager Summary: Sound Manager library -Version: 0.3.106 +Version: 0.3.107 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index 47e8133..8caaf24 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -1199,7 +1199,7 @@ int sound_manager_get_device_type(sound_device_h device, sound_device_type_e *ty ret = mm_sound_get_device_type(device, &mm_sound_device_type); if (ret == MM_ERROR_NONE) - _convert_device_type(mm_sound_device_type, type); + ret = _convert_device_type(mm_sound_device_type, type); return _convert_sound_manager_error_code(__func__, ret); } diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index 0bcb611..83002cb 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -494,6 +494,9 @@ int _convert_device_type(mm_sound_device_type_e device_type, sound_device_type_e 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; @@ -1356,19 +1359,19 @@ int _set_session_mode(_session_mode_e mode) 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; } @@ -1380,7 +1383,7 @@ int _set_session_mode(_session_mode_e mode) 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; } } @@ -1522,38 +1525,40 @@ int _set_session_mode(_session_mode_e mode) 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); @@ -1715,10 +1720,6 @@ int _add_device_for_stream_routing(sound_stream_info_s *stream_info, sound_devic 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; @@ -1728,76 +1729,72 @@ int _add_device_for_stream_routing(sound_stream_info_s *stream_info, sound_devic 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) @@ -1815,90 +1812,85 @@ int _remove_device_for_stream_routing(sound_stream_info_s *stream_info, sound_de 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)