From: Sangchul Lee Date: Mon, 29 May 2017 02:44:16 +0000 (+0900) Subject: Add sound_manager_acquire_focus_all() and sound_manager_release_focus_all() X-Git-Tag: submit/tizen/20170615.073353~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F18%2F131818%2F8;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add sound_manager_acquire_focus_all() and sound_manager_release_focus_all() These functions do not return error even though one or all of focuses have already been released or acquired. These are intended to be used to acquire all focuses or release all focuses with checking its state more loosely. [Version] 0.4.8 [Issue Type] New API Change-Id: Icb1757bef790f01875ef8d97cf07026966122b8e Signed-off-by: Sangchul Lee --- diff --git a/include/sound_manager.h b/include/sound_manager.h index 470cfec..28ad773 100644 --- a/include/sound_manager.h +++ b/include/sound_manager.h @@ -796,16 +796,19 @@ int sound_manager_apply_stream_routing(sound_stream_info_h stream_info); * @retval #SOUND_MANAGER_ERROR_INVALID_STATE Invalid state * @retval #SOUND_MANAGER_ERROR_POLICY Noncompliance with the sound system policy * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system - * @pre Call sound_manager_create_stream_information() with its parameter for sound_stream_focus_state_changed_cb before calling this function. + * @pre Call sound_manager_create_stream_information() with its parameter for sound_stream_focus_state_changed_cb\n + * before calling this function. * @see sound_manager_create_stream_information() * @see sound_manager_destroy_stream_information() + * @see sound_manager_acquire_focus_all() * @see sound_manager_release_focus() + * @see sound_manager_release_focus_all() * @see sound_manager_get_focus_state() */ int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, int sound_behavior, const char *extra_info); /** - * @brief Releases the acquired focus. + * @brief Releases the acquired stream focus. * @since_tizen 3.0 * * @param[in] stream_info The handle of stream information @@ -822,10 +825,65 @@ int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_fo * @see sound_manager_create_stream_information() * @see sound_manager_destroy_stream_information() * @see sound_manager_acquire_focus() + * @see sound_manager_acquire_focus_all() + * @see sound_manager_release_focus_all() * @see sound_manager_get_focus_state() */ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, int sound_behavior, const char *extra_info); +/** + * @brief Acquires all the stream focuses. + * @since_tizen 4.0 + * + * @remarks This function does not return error even though one or all of focuses have already been acquired.\n + * Use sound_manager_get_focus_state() to get acquired focus state if it returns #SOUND_MANAGER_ERROR_POLICY. + * + * @param[in] stream_info The handle of stream information + * @param[in] sound_behavior The requesting sound behavior, values of #sound_behavior_e combined with bitwise 'or' + * @param[in] extra_info The extra information for this request (optional, this can be NULL) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SOUND_MANAGER_ERROR_POLICY Noncompliance with the sound system policy + * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system + * @pre Call sound_manager_create_stream_information() with its parameter for sound_stream_focus_state_changed_cb\n + * before calling this function. + * @see sound_manager_create_stream_information() + * @see sound_manager_destroy_stream_information() + * @see sound_manager_acquire_focus() + * @see sound_manager_release_focus() + * @see sound_manager_release_focus_all() + * @see sound_manager_get_focus_state() + */ +int sound_manager_acquire_focus_all(sound_stream_info_h stream_info, int sound_behavior, const char *extra_info); + +/** + * @brief Releases all the acquired stream focuses. + * @since_tizen 4.0 + * + * @remarks This function does not return error even though one or all of focuses have already been released. + * + * @param[in] stream_info The handle of stream information + * @param[in] sound_behavior The requesting sound behavior, values of #sound_behavior_e combined with bitwise 'or' + * @param[in] extra_info The extra information for this request (optional, this can be NULL) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SOUND_MANAGER_ERROR_POLICY Noncompliance with the sound system policy + * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system + * @pre Call sound_manager_create_stream_information(), sound_manager_acquire_focus() and sound_manager_acquire_focus_all()\n + * before calling this function. + * @see sound_manager_create_stream_information() + * @see sound_manager_destroy_stream_information() + * @see sound_manager_acquire_focus() + * @see sound_manager_acquire_focus_all() + * @see sound_manager_release_focus() + * @see sound_manager_get_focus_state() + */ +int sound_manager_release_focus_all(sound_stream_info_h stream_info, int sound_behavior, const char *extra_info); + /** * @brief Gets the state of focus. * @since_tizen 3.0 diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index aedba9c..85d471d 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.7 +Version: 0.4.8 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index b255243..65c7089 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -380,7 +380,7 @@ int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_fo return _convert_sound_manager_error_code(__func__, ret); if (stream_h->is_focus_unavailable) { - LOGE("acquiring focus is not allowed for this strema type(%s)", stream_h->stream_type); + 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); } @@ -442,6 +442,72 @@ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_fo return _convert_sound_manager_error_code(__func__, ret); } +int sound_manager_acquire_focus_all(sound_stream_info_h stream_info, int sound_behavior, const char *extra_info) +{ + int ret = MM_ERROR_NONE; + int focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH; + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + LOGI(">> enter"); + + SM_INSTANCE_CHECK(stream_h); + + 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); + } + + if (stream_h->user_cb == NULL) { + LOGE("focus state changed callback should be set before acquiring focus"); + 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); + } + + focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH & ~(stream_h->acquired_focus); + if (!focus_mask) { + LOGI("PLAYBACK/RECORDING focuses have already been ACQUIRED"); + return SOUND_MANAGER_ERROR_NONE; + } + + 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; + stream_h->prev_acquired_focus |= focus_mask; + _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus); + } + + return _convert_sound_manager_error_code(__func__, ret); +} + +int sound_manager_release_focus_all(sound_stream_info_h stream_info, int sound_behavior, const char *extra_info) +{ + int ret = MM_ERROR_NONE; + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + LOGI(">> enter"); + + SM_INSTANCE_CHECK(stream_h); + + if (!stream_h->acquired_focus) { + LOGI("PLAYBACK/RECORDING focuses have already been RELEASED"); + return SOUND_MANAGER_ERROR_NONE; + } + + ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)stream_h->acquired_focus, sound_behavior, extra_info); + if (ret == MM_ERROR_NONE) { + stream_h->acquired_focus = 0; + stream_h->prev_acquired_focus = 0; + _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus); + } + + return _convert_sound_manager_error_code(__func__, ret); +} + int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_focus_state_e *state_for_playback, sound_stream_focus_state_e *state_for_recording) { int ret = MM_ERROR_NONE; diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index 93628b2..716c502 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -75,6 +75,8 @@ enum { CURRENT_STATUS_SET_STREAM_ROUTING_OPTION, CURRENT_STATUS_ACQUIRE_FOCUS, CURRENT_STATUS_RELEASE_FOCUS, + CURRENT_STATUS_ACQUIRE_FOCUS_ALL, + CURRENT_STATUS_RELEASE_FOCUS_ALL, CURRENT_STATUS_GET_ACQUIRED_FOCUS, CURRENT_STATUS_GET_SOUND_TYPE, CURRENT_STATUS_DESTROY_STREAM_INFO, @@ -241,6 +243,10 @@ void _interpret_main_menu(char *cmd) g_menu_state = CURRENT_STATUS_ACQUIRE_FOCUS; else if (strncmp(cmd, "rfc", 3) == 0) g_menu_state = CURRENT_STATUS_RELEASE_FOCUS; + else if (strncmp(cmd, "afa", 3) == 0) + g_menu_state = CURRENT_STATUS_ACQUIRE_FOCUS_ALL; + else if (strncmp(cmd, "rfa", 3) == 0) + g_menu_state = CURRENT_STATUS_RELEASE_FOCUS_ALL; else if (strncmp(cmd, "gfs", 3) == 0) g_menu_state = CURRENT_STATUS_GET_ACQUIRED_FOCUS; else if (strncmp(cmd, "gst", 3) == 0) @@ -351,6 +357,8 @@ void display_sub_basic() g_print("afc. Acquire Focus\t"); g_print("rfc. Release Focus\t"); g_print("gfs. Get Focus State\n"); + g_print("afa. Acquire Focus All\t"); + g_print("rfa. Release Focus All\n"); g_print("afw. Add Focus State Watch CB\t"); g_print("rfw. Remove Focus State Watch CB\n"); g_print("sfr. Set Focus Reacquisition\t"); @@ -467,6 +475,10 @@ static void displaymenu() g_print("*** input focus type to acquire (0:playback, 1:recording, 2:both, 3:both+noResume, 4:both+fading)\n"); else if (g_menu_state == CURRENT_STATUS_RELEASE_FOCUS) g_print("*** input focus type to release (0:playback, 1:recording, 2:both, 3:both+noResume, 4:both+fading)\n"); + else if (g_menu_state == CURRENT_STATUS_ACQUIRE_FOCUS_ALL) + g_print("*** input behavior for acquire all (0:without behavior, 1:with noResume, 2:with fading)\n"); + else if (g_menu_state == CURRENT_STATUS_RELEASE_FOCUS_ALL) + g_print("*** input behavior for release all (0:without behavior, 1:with noResume, 2:with fading)\n"); else if (g_menu_state == CURRENT_STATUS_GET_ACQUIRED_FOCUS) g_print("*** press enter to get focus state\n"); else if (g_menu_state == CURRENT_STATUS_GET_SOUND_TYPE) @@ -1646,6 +1658,58 @@ static void interpret(char *cmd) reset_menu_state(); break; } + case CURRENT_STATUS_ACQUIRE_FOCUS_ALL: { + int ret = SOUND_MANAGER_ERROR_NONE; + int behavior = atoi(cmd); + + switch (behavior) { + case 0: /* without behavior */ + behavior = SOUND_BEHAVIOR_NONE; + break; + case 1: /* no-resumption */ + behavior = SOUND_BEHAVIOR_NO_RESUME; + break; + case 2: /* fading */ + behavior = SOUND_BEHAVIOR_FADING; + break; + default: + g_print("invalid selection(%d), keep going without behavior..\n", behavior); + behavior = SOUND_BEHAVIOR_NONE; + break; + } + ret = sound_manager_acquire_focus_all(g_stream_info_h, behavior, "sound_manager_test(acquire_focus_all)"); + if (ret) + g_print("fail to sound_manager_acquire_focus_all(), ret(0x%x)\n", ret); + + reset_menu_state(); + break; + } + case CURRENT_STATUS_RELEASE_FOCUS_ALL: { + int ret = SOUND_MANAGER_ERROR_NONE; + int behavior = atoi(cmd); + + switch (behavior) { + case 0: /* without behavior */ + behavior = SOUND_BEHAVIOR_NONE; + break; + case 1: /* no-resumption */ + behavior = SOUND_BEHAVIOR_NO_RESUME; + break; + case 2: /* fading */ + behavior = SOUND_BEHAVIOR_FADING; + break; + default: + g_print("invalid selection(%d), keep going without behavior..\n", behavior); + behavior = SOUND_BEHAVIOR_NONE; + break; + } + ret = sound_manager_release_focus_all(g_stream_info_h, behavior, "sound_manager_test(release_focus_all)"); + if (ret) + g_print("fail to sound_manager_release_focus_all(), ret(0x%x)\n", ret); + + reset_menu_state(); + break; + } case CURRENT_STATUS_GET_ACQUIRED_FOCUS: { sound_stream_focus_state_e for_playback; sound_stream_focus_state_e for_recording;