Conditions for checking focus state is revised considering that it could be called... 09/134209/1 accepted/tizen/unified/20170630.083023 submit/tizen/20170615.073353
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 15 Jun 2017 07:43:32 +0000 (16:43 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 15 Jun 2017 08:14:11 +0000 (17:14 +0900)
[Version] 0.4.10
[Issue Type] Fix bug and enhancement

Change-Id: Ibb74305e23fc16745adb26ac5103e0bdabdc22e4
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 3a501a7d35247b6e4c76aaa4625822c32b7fce73..30212e7c29d37208552bcc0af388ce889c25fa39 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.4.9
+Version:    0.4.10
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 65c7089f71d8ea7ac55001f30e2af8b12d808473..2959a19e368d3c4557e1745d54751bff13df1c23 100644 (file)
@@ -389,16 +389,17 @@ int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_fo
                return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
        }
 
-       if (is_focus_cb_thread && (stream_h->prev_acquired_focus & focus_mask)) {
-               LOGE("invalid state: focus_mask[0x%x], prev_acquired_focus[0x%x]", focus_mask, stream_h->prev_acquired_focus);
-               return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
-       }
-
        if (stream_h->acquired_focus & focus_mask) {
                LOGE("invalid state: focus_mask[0x%x], acquired_focus[0x%x]", focus_mask, stream_h->acquired_focus);
                return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
        }
 
+       if (is_focus_cb_thread && ((stream_h->prev_acquired_focus | ~stream_h->acquired_focus) & SOUND_STREAM_FOCUS_FOR_BOTH) != focus_mask) {
+               LOGE("just lost focus in this callback, it is not allowed to acquire the focus[0x%x] again. acquired_focus[0x%x], prev[0x%x]",
+                       focus_mask, stream_h->acquired_focus, stream_h->prev_acquired_focus);
+               return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
+       }
+
        ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
        if (ret == MM_ERROR_NONE) {
                stream_h->acquired_focus |= focus_mask;
@@ -406,6 +407,8 @@ int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_fo
                _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
        }
 
+       LOGI("acquired_focus[0x%x], prev[0x%x]", stream_h->acquired_focus, stream_h->prev_acquired_focus);
+
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
@@ -422,13 +425,14 @@ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_fo
        if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
                return _convert_sound_manager_error_code(__func__, ret);
 
-       if (is_focus_cb_thread && !(stream_h->prev_acquired_focus & focus_mask)) {
-               LOGE("invalid state: focus_mask[0x%x], prev_acquired_focus[0x%x]", focus_mask, stream_h->prev_acquired_focus);
+       if (!(stream_h->acquired_focus & focus_mask)) {
+               LOGE("invalid state: focus_mask[0x%x], acquired_focus[0x%x]", focus_mask, stream_h->acquired_focus);
                return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
        }
 
-       if (!(stream_h->acquired_focus & focus_mask)) {
-               LOGE("invalid state: focus_mask[0x%x], acquired_focus[0x%x]", focus_mask, stream_h->acquired_focus);
+       if (is_focus_cb_thread && ((stream_h->prev_acquired_focus & stream_h->acquired_focus) != focus_mask)) {
+               LOGE("just acquired focus in this callback, it is not allowed to release the focus[0x%x] again. acquired_focus[0x%x], prev[0x%x]",
+                       focus_mask, stream_h->acquired_focus, stream_h->prev_acquired_focus);
                return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
        }
 
@@ -439,6 +443,8 @@ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_fo
                _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
        }
 
+       LOGI("acquired_focus[0x%x], prev[0x%x]", stream_h->acquired_focus, stream_h->prev_acquired_focus);
+
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
@@ -446,12 +452,16 @@ int sound_manager_acquire_focus_all(sound_stream_info_h stream_info, int sound_b
 {
        int ret = MM_ERROR_NONE;
        int focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
+       bool is_focus_cb_thread = false;
        sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
 
        LOGI(">> enter");
 
        SM_INSTANCE_CHECK(stream_h);
 
+       if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
+               return _convert_sound_manager_error_code(__func__, ret);
+
        if (stream_h->is_focus_unavailable) {
                LOGE("acquiring focus is not allowed for this stream type(%s)", stream_h->stream_type);
                return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
@@ -462,10 +472,10 @@ int sound_manager_acquire_focus_all(sound_stream_info_h stream_info, int sound_b
                return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
        }
 
-       if ((stream_h->acquired_focus & focus_mask) || (stream_h->prev_acquired_focus & focus_mask)) {
-               LOGE("invalid state : focus_mask[0x%x], acquired_focus[0x%x], prev[0x%x]",
-                       focus_mask, stream_h->acquired_focus, stream_h->prev_acquired_focus);
-               return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
+       if (is_focus_cb_thread && (stream_h->prev_acquired_focus > stream_h->acquired_focus)) {
+               LOGE("just lost focus in this callback, it is not allowed to acquire all again. acquired_focus[0x%x], prev[0x%x]",
+                       stream_h->acquired_focus, stream_h->prev_acquired_focus);
+               return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
        }
 
        focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH & ~(stream_h->acquired_focus);
@@ -487,12 +497,22 @@ int sound_manager_acquire_focus_all(sound_stream_info_h stream_info, int sound_b
 int sound_manager_release_focus_all(sound_stream_info_h stream_info, int sound_behavior, const char *extra_info)
 {
        int ret = MM_ERROR_NONE;
+       bool is_focus_cb_thread = false;
        sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
 
        LOGI(">> enter");
 
        SM_INSTANCE_CHECK(stream_h);
 
+       if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
+               return _convert_sound_manager_error_code(__func__, ret);
+
+       if (is_focus_cb_thread && (stream_h->prev_acquired_focus < stream_h->acquired_focus)) {
+               LOGE("just acquired focus in this callback, it is not allowed to release all again. acquired_focus[0x%x], prev[0x%x]",
+                       stream_h->acquired_focus, stream_h->prev_acquired_focus);
+               return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
+       }
+
        if (!stream_h->acquired_focus) {
                LOGI("PLAYBACK/RECORDING focuses have already been RELEASED");
                return SOUND_MANAGER_ERROR_NONE;
index 6d3a64bfe1cb697208f3e46403ba70e0e1488370..a47563e2cbed39cc230c9a7978a2e66b4a87731e 100644 (file)
@@ -593,6 +593,11 @@ void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, m
        if (state == FOCUS_IS_RELEASED)
                _update_focus_status(stream_info->index, (unsigned int)stream_info->acquired_focus);
 
+       if (state == FOCUS_IS_RELEASED)
+               stream_info->prev_acquired_focus &= ~focus_type;
+       else if (state == FOCUS_IS_ACQUIRED)
+               stream_info->prev_acquired_focus |= focus_type;
+
 LEAVE:
        LOGI("<< leave");