Fix invalid operation in _set_session_mode() and refactor internal functions related... 86/120586/3 accepted/tizen/3.0/common/20170330.124949 accepted/tizen/3.0/ivi/20170329.223030 accepted/tizen/3.0/mobile/20170329.222931 accepted/tizen/3.0/tv/20170329.222949 accepted/tizen/3.0/wearable/20170329.223010 submit/tizen_3.0/20170329.043647
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 23 Mar 2017 08:17:43 +0000 (17:17 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 23 Mar 2017 08:30:04 +0000 (17:30 +0900)
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 <sc11.lee@samsung.com>
packaging/capi-media-sound-manager.spec
src/sound_manager.c
src/sound_manager_private.c

index 77f034c..5e16f91 100755 (executable)
@@ -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
index 47e8133..8caaf24 100644 (file)
@@ -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);
 }
index 0bcb611..83002cb 100644 (file)
@@ -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)