From: Sangchul Lee Date: Thu, 15 Jun 2017 07:43:32 +0000 (+0900) Subject: Conditions for checking focus state is revised considering that it could be called... X-Git-Tag: submit/tizen/20170615.073353^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fb6fed74bddfd14ccfdf905e5cad0aaf4d0b0ad;p=platform%2Fcore%2Fapi%2Fsound-manager.git Conditions for checking focus state is revised considering that it could be called within focus callback [Version] 0.4.10 [Issue Type] Fix bug and enhancement Change-Id: Ibb74305e23fc16745adb26ac5103e0bdabdc22e4 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 3a501a7..30212e7 100644 --- 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.4.9 +Version: 0.4.10 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index 65c7089..2959a19 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -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; diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index 6d3a64b..a47563e 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -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");