Change user data of registering focus(watch) callback to simplify logic in the callback 96/118996/3
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 15 Mar 2017 05:13:56 +0000 (14:13 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 15 Mar 2017 08:35:27 +0000 (17:35 +0900)
[Version] 0.3.104
[Profile] Common
[Issue Type] Enhancement

Change-Id: I697cece8738f7e049d1279c0cc454eb43e07c789
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 0ad293ce9b7fe59bb3b1e9cee20248db8cba16f6..eeddec6edd4cc1e92aa5b7caf31b1a7db19ad61e 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.3.103
+Version:    0.3.104
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 652ca6b9ab96ea5eee622fe889a00b7dc8de5212..8af287801f1564c5744f4d9ab8a0088fdd0db091 100644 (file)
@@ -557,7 +557,7 @@ int sound_manager_add_focus_state_watch_cb(sound_stream_focus_mask_e focus_mask,
                goto LEAVE;
        }
 
-       ret = mm_sound_set_focus_watch_callback((mm_sound_focus_type_e)focus_mask, _focus_watch_callback, user_data, id);
+       ret = mm_sound_set_focus_watch_callback((mm_sound_focus_type_e)focus_mask, _focus_watch_callback, &focus_watch_info_arr[i], id);
        if (ret == MM_ERROR_NONE) {
                SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret);
                focus_watch_info_arr[i].id = *id;
index 70d51ba87b3528dd2a950cb910827ac6a50a6651..5b35dd59badbc1b4410f580d6a32ae0dd11d8d3a 100644 (file)
@@ -51,8 +51,6 @@ extern _session_interrupt_info_s g_session_interrupt_cb_table;
 extern _session_mode_e g_cached_session_mode;
 extern int g_cached_voip_device_id;
 extern int g_cached_voip_device_id2;
-extern _focus_watch_info_s focus_watch_info_arr[SOUND_STREAM_INFO_ARR_MAX];
-sound_stream_info_s *sound_stream_info_arr[SOUND_STREAM_INFO_ARR_MAX];
 sound_stream_info_s *g_voip_stream_info = NULL;
 sound_stream_info_s *g_voip_ringtone_stream_info = NULL;
 virtual_sound_stream_info_s *g_voip_vstream_h = NULL;
@@ -551,34 +549,37 @@ const char* _convert_api_name(native_api_e api_name)
 void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason, int option, const char *extra_info, void *user_data)
 {
        int ret = MM_ERROR_NONE;
-       int i = 0;
        sound_stream_focus_change_reason_e change_reason = SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA;
+       sound_stream_info_s *stream_info;
 
        LOGI(">> enter");
 
-       ret = _convert_stream_type_to_change_reason(reason, &change_reason);
-       if (ret) {
-               LOGE("failed to _convert_stream_type_to_enum(), reason(%s), err(0x%08x)", reason, ret);
+       if (!user_data) {
+               LOGE("user_data is null");
                goto LEAVE;
        }
 
-       for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++) {
-               if (sound_stream_info_arr[i] && sound_stream_info_arr[i]->index == index) {
-                       if (state == FOCUS_IS_RELEASED)
-                               sound_stream_info_arr[i]->acquired_focus &= ~focus_type;
-                       else if (state == FOCUS_IS_ACQUIRED)
-                               sound_stream_info_arr[i]->acquired_focus |= focus_type;
-
-                       LOGI("[FOCUS USER CALLBACK(%p) START]", sound_stream_info_arr[i]->user_cb);
-                       sound_stream_info_arr[i]->user_cb((sound_stream_info_h)sound_stream_info_arr[i],
-                                       focus_type, state, change_reason, option, extra_info, sound_stream_info_arr[i]->user_data);
-                       LOGI("[FOCUS USER CALLBACK(%p) END]", sound_stream_info_arr[i]->user_cb);
-                       _update_focus_status(sound_stream_info_arr[i]->index, (unsigned int)sound_stream_info_arr[i]->acquired_focus);
-                       break;
-               }
+       stream_info = (sound_stream_info_s *)user_data;
+       if (stream_info->index != index) {
+               LOGE("index is not valid, (%d, %d)", stream_info->index, index);
+               goto LEAVE;
+       }
+
+       if ((ret = _convert_stream_type_to_change_reason(reason, &change_reason))) {
+               LOGE("failed to _convert_stream_type_to_enum(), reason(%s), err(0x%08x)", reason, ret);
+               goto LEAVE;
        }
-       if (i == SOUND_STREAM_INFO_ARR_MAX)
-               LOGE("could not find index(%d), failed to call user callback", index);
+
+       if (state == FOCUS_IS_RELEASED)
+               stream_info->acquired_focus &= ~focus_type;
+       else if (state == FOCUS_IS_ACQUIRED)
+               stream_info->acquired_focus |= focus_type;
+
+       LOGI("[FOCUS USER CALLBACK(%p) START]", stream_info->user_cb);
+       stream_info->user_cb((sound_stream_info_h)stream_info, focus_type, state, change_reason,
+                                               option, extra_info, stream_info->user_data);
+       LOGI("[FOCUS USER CALLBACK(%p) END]", stream_info->user_cb);
+       _update_focus_status(stream_info->index, (unsigned int)stream_info->acquired_focus);
 
 LEAVE:
        LOGI("<< leave");
@@ -589,25 +590,28 @@ LEAVE:
 void _focus_watch_callback(int index, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason, const char *extra_info, void *user_data)
 {
        int ret = MM_ERROR_NONE;
-       int i = 0;
        sound_stream_focus_change_reason_e change_reason = SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA;
+       _focus_watch_info_s *watch_info;
 
-       ret = _convert_stream_type_to_change_reason(reason, &change_reason);
-       if (ret) {
-               LOGE("failed to _convert_stream_type_to_enum(), reason(%s), err(0x%08x)", reason, ret);
+       if (!user_data) {
+               LOGE("user_data is null");
                goto LEAVE;
        }
 
-       for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++) {
-               if ((focus_watch_info_arr[i].id > 0) && (focus_watch_info_arr[i].id == index)) {
-                       LOGI("[FOCUS WATCH USER CALLBACK(%p, id:%d) START]", focus_watch_info_arr[i].user_cb, index);
-                       focus_watch_info_arr[i].user_cb(index, focus_type, state, change_reason, extra_info, focus_watch_info_arr[i].user_data);
-                       LOGI("[FOCUS WATCH USER CALLBACK(%p) END]", focus_watch_info_arr[i].user_cb);
-                       break;
-               }
+       watch_info = (_focus_watch_info_s *)user_data;
+       if (watch_info->id != index) {
+               LOGE("index is not valid, (%d, %d)", watch_info->id, index);
+               goto LEAVE;
+       }
+
+       if ((ret = _convert_stream_type_to_change_reason(reason, &change_reason))) {
+               LOGE("failed to _convert_stream_type_to_enum(), reason(%s), err(0x%08x)", reason, ret);
+               goto LEAVE;
        }
-       if (i == SOUND_STREAM_INFO_ARR_MAX)
-               LOGE("could not find index(%d), failed to call user callback", index);
+
+       LOGI("[FOCUS WATCH USER CALLBACK(%p, id:%d) START]", watch_info->user_cb, index);
+       watch_info->user_cb(index, focus_type, state, change_reason, extra_info, watch_info->user_data);
+       LOGI("[FOCUS WATCH USER CALLBACK(%p) END]", watch_info->user_cb);
 
 LEAVE:
        LOGI("<< leave");
@@ -1561,16 +1565,6 @@ int _make_pa_connection_and_register_focus(sound_stream_info_s *stream_h, bool i
        if (is_focus_cb_thread)
                return MM_ERROR_SOUND_INVALID_OPERATION;
 
-       if (!stream_h->is_focus_unavailable) {
-               for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++)
-                       if (sound_stream_info_arr[i] == NULL)
-                               break;
-               if (i == SOUND_STREAM_INFO_ARR_MAX) {
-                       LOGE("client sound stream info array is full");
-                       goto PA_ERROR;
-               }
-       }
-
        /* get configuration information of this stream type */
        if ((ret = _get_stream_conf_info(stream_h->stream_type, &stream_h->stream_conf_info)))
                return ret;
@@ -1617,13 +1611,12 @@ int _make_pa_connection_and_register_focus(sound_stream_info_s *stream_h, bool i
        /* register focus */
        if (!stream_h->is_focus_unavailable) {
                if (is_for_session)
-                       ret = mm_sound_register_focus_for_session(stream_h->index, getpid(), stream_h->stream_type, _focus_state_change_callback, user_data);
+                       ret = mm_sound_register_focus_for_session(stream_h->index, getpid(), stream_h->stream_type, _focus_state_change_callback, stream_h);
                else
-                       ret = mm_sound_register_focus(stream_h->index, stream_h->stream_type, _focus_state_change_callback, user_data);
+                       ret = mm_sound_register_focus(stream_h->index, stream_h->stream_type, _focus_state_change_callback, stream_h);
                if (ret == MM_ERROR_NONE) {
                        stream_h->user_cb = callback;
                        stream_h->user_data = user_data;
-                       sound_stream_info_arr[i] = stream_h;
                } else {
                        LOGE("failed to register focus, ret(0x%x)", ret);
                        /* disconnect */
@@ -1704,13 +1697,6 @@ int _destroy_pa_connection_and_unregister_focus(sound_stream_info_s *stream_h)
 
        SM_SAFE_FREE(stream_h->stream_conf_info.volume_type);
 
-       for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++) {
-               if (sound_stream_info_arr[i] && sound_stream_info_arr[i]->index == stream_h->index) {
-                       sound_stream_info_arr[i] = NULL;
-                       break;
-               }
-       }
-
        return ret;
 }