From: Sangchul Lee Date: Mon, 14 Dec 2015 01:53:42 +0000 (+0900) Subject: Add internal APIs for querying the reason for the current acquired focus(playback... X-Git-Tag: submit/tizen/20151221.042414^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e96b6d065b088a11b0aadaddeb8bdc3e4d20dd9;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add internal APIs for querying the reason for the current acquired focus(playback/recording) in the system int sound_manager_get_reason_for_current_playback_focus(sound_stream_focus_change_reason_e *acquired_by, char **additional_info) int sound_manager_get_reason_for_current_recording_focus(sound_stream_focus_change_reason_e *acquired_by, char **additional_info) User can get the reason for the current acquired focus via the new APIs globally. Modify debug logs. [Version] Release 0.3.37 [profile] Common [Issue Type] Feature enhancement Change-Id: If635cfe476376f6a69d88ffec9d46fb0616c6490 Signed-off-by: Sangchul Lee --- diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index dc3e4e1..ef9927e 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -214,6 +214,42 @@ int sound_manager_get_type_from_stream_information(sound_stream_info_h stream_in */ int sound_manager_get_index_from_stream_information(sound_stream_info_h stream_info, int *index); +/** + * @internal + * @brief Gets the reason for the current acquired playback focus. + * @since_tizen 3.0 + * @param[out] acquired_by The reason for the current acquired playback focus + * @param[out] additional_info The additional information of the acquired playback focus (this can be null) + * + * @remarks If there is no acquired playback focus in this system, it'll return #SOUND_MANAGER_ERROR_NO_DATA. + * + * @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_NO_DATA No data + * @see sound_manager_get_reason_for_current_recording_focus() + */ +int sound_manager_get_reason_for_current_playback_focus(sound_stream_focus_change_reason_e *acquired_by, char **additional_info); + +/** + * @internal + * @brief Gets the reason for the current acquired recording focus. + * @since_tizen 3.0 + * @param[out] acquired_by The reason for the current acquired recording focus + * @param[out] additional_info The additional information of the acquired recording focus (this can be null) + * + * @remarks If there is no acquired recording focus in this system, it'll return #SOUND_MANAGER_ERROR_NO_DATA. + * + * @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_NO_DATA No data + * @see sound_manager_get_reason_for_current_playback_focus() + */ +int sound_manager_get_reason_for_current_recording_focus(sound_stream_focus_change_reason_e *acquired_by, char **additional_info); + /** * @internal * @brief Creates a virtual stream handle. diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 1825eb0..a6a21dd 100755 --- 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.3.36 +Version: 0.3.37 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index 2beb770..1a555d4 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -65,7 +65,7 @@ int sound_manager_set_volume(sound_type_e type, int volume) return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT); ret = mm_sound_volume_set_value(type, volume); - LOGI("returns : type=%d, volume=%d, ret=%p", type, volume, ret); + LOGI("type=%d, volume=%d", type, volume); return _convert_sound_manager_error_code(__func__, ret); } @@ -84,7 +84,7 @@ int sound_manager_get_volume(sound_type_e type, int *volume) if (ret == MM_ERROR_NONE) *volume = uvolume; - LOGI("returns : type=%d, volume=%d, ret=%p", type, *volume, ret); + LOGI("type=%d, volume=%d", type, *volume); return _convert_sound_manager_error_code(__func__, ret); } @@ -121,7 +121,7 @@ int sound_manager_get_current_sound_type(sound_type_e *type) *type = mm_sound_vol_type; } } - LOGI("returns : type=%d, ret=%p", *type, ret); + LOGI("type=%d", *type); return _convert_sound_manager_error_code(__func__, ret); } @@ -201,7 +201,7 @@ int sound_manager_create_stream_information(sound_stream_type_e stream_type, sou if (ret == MM_ERROR_NONE) { *stream_info = (sound_stream_info_h)stream_h; SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret); - LOGI("<< leave : stream_h(%p), index(%u), user_cb(%p), cnt(%d), ret(%p)", stream_h, stream_h->index, stream_h->user_cb, g_stream_info_count, ret); + LOGI("stream_h(%p), index(%u), user_cb(%p), cnt(%d), ret(0x%x)", stream_h, stream_h->index, stream_h->user_cb, g_stream_info_count, ret); } } if (ret) @@ -231,7 +231,7 @@ int sound_manager_destroy_stream_information(sound_stream_info_h stream_info) } SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex); - LOGI("<< leave : cnt(%d), ret(%p)", g_stream_info_count, ret); + LOGD("cnt(%d)", g_stream_info_count); return _convert_sound_manager_error_code(__func__, ret); } @@ -245,8 +245,6 @@ int sound_manager_add_device_for_stream_routing(sound_stream_info_h stream_info, ret = _add_device_for_stream_routing(stream_h, device); - LOGI("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -259,8 +257,6 @@ int sound_manager_remove_device_for_stream_routing(sound_stream_info_h stream_in ret = _remove_device_for_stream_routing(stream_h, device); - LOGI("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -273,8 +269,6 @@ int sound_manager_apply_stream_routing(sound_stream_info_h stream_info) ret = _apply_stream_routing(stream_h); - LOGI("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -289,8 +283,6 @@ int sound_manager_set_focus_reacquisition(sound_stream_info_h stream_info, bool ret = mm_sound_set_focus_reacquisition(stream_h->index, enable); - LOGI("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -306,8 +298,6 @@ int sound_manager_get_focus_reacquisition(sound_stream_info_h stream_info, bool ret = mm_sound_get_focus_reacquisition(stream_h->index, enabled); - LOGI("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -326,8 +316,6 @@ 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("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -346,8 +334,6 @@ 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("<< leave : ret(%p)", ret); - return _convert_sound_manager_error_code(__func__, ret); } @@ -367,7 +353,7 @@ int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_ if (state_for_recording) *state_for_recording = ((stream_h->acquired_focus & SOUND_STREAM_FOCUS_FOR_RECORDING) ? (SOUND_STREAM_FOCUS_STATE_ACQUIRED) : (SOUND_STREAM_FOCUS_STATE_RELEASED)); - LOGI("<< leave : acquired_focus(%p)", stream_h->acquired_focus); + LOGI("acquired_focus(0x%x)", stream_h->acquired_focus); return _convert_sound_manager_error_code(__func__, ret); } @@ -389,8 +375,6 @@ int sound_manager_get_sound_type(sound_stream_info_h stream_info, sound_type_e * LOGI("sound type(%d)", *sound_type); } - LOGI("<< leave : sound type(%d)", *sound_type); - return _convert_sound_manager_error_code(__func__, ret); } @@ -418,7 +402,7 @@ int sound_manager_set_focus_state_watch_cb(sound_stream_focus_mask_e focus_mask, SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex); - LOGI("<< leave : cnt(%d), ret(%p)", g_stream_info_count, ret); + LOGD("cnt(%d)", g_stream_info_count); return _convert_sound_manager_error_code(__func__, ret); } @@ -447,7 +431,7 @@ int sound_manager_unset_focus_state_watch_cb(void) SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex); - LOGI("<< leave : cnt(%d), ret(%p)", g_stream_info_count, ret); + LOGD("cnt(%d)", g_stream_info_count); return _convert_sound_manager_error_code(__func__, ret); } @@ -492,7 +476,7 @@ int sound_manager_set_session_type(sound_session_type_e type) if (ret == MM_ERROR_NONE) { if (cur_session == MM_SESSION_TYPE_MEDIA_RECORD) { if (type > SOUND_SESSION_TYPE_MEDIA) { - LOGE("<< leave : Could not set this type(%d) during camera/recorder/audio-io(in)/radio", type); + LOGE("Could not set this type(%d) during camera/recorder/audio-io(in)/radio", type); return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL); } } @@ -501,7 +485,7 @@ int sound_manager_set_session_type(sound_session_type_e type) if (g_session_interrupt_cb_table.is_registered) { if (new_session == cur_session || ((new_session == SOUND_SESSION_TYPE_MEDIA) && (cur_session == MM_SESSION_TYPE_MEDIA_RECORD))) { - LOGI("<< leave : already set type=%d, ret=%p", type, ret); + LOGI("already set type=%d, ret=0x%x", type, ret); return SOUND_MANAGER_ERROR_NONE; } else { ret = mm_session_finish(); @@ -532,7 +516,7 @@ int sound_manager_set_session_type(sound_session_type_e type) if (ret == MM_ERROR_NONE) g_session_interrupt_cb_table.is_registered = 1; - LOGI("<< leave : type=%d, ret=%p", type, ret); + LOGI("type=%d", type); return _convert_sound_manager_error_code(__func__, ret); } @@ -556,7 +540,7 @@ int sound_manager_get_session_type(sound_session_type_e *type) (cur_session != MM_SESSION_TYPE_VOIP)) { if (g_cached_session != -1) cur_session = g_cached_session; - else /* will be never reach here. just prevent code */ + else /* will be never reached here. just prevent code */ cur_session = SOUND_SESSION_TYPE_DEFAULT; } @@ -582,9 +566,9 @@ int sound_manager_get_session_type(sound_session_type_e *type) break; } - LOGI("returns : type=%d, ret=%p", *type, ret); + LOGI("type=%d", *type); - return 0; + return SOUND_MANAGER_ERROR_NONE; } int sound_manager_set_media_session_option(sound_session_option_for_starting_e s_option, sound_session_option_for_during_play_e d_option) @@ -662,9 +646,9 @@ int sound_manager_set_media_session_option(sound_session_option_for_starting_e s } if (updated) - LOGI("<< leave : updated"); + LOGI("updated"); else - LOGI("<< leave : already set same option(%x), skip it", session_option); + LOGI("already set same option(%x), skip it", session_option); return _convert_sound_manager_error_code(__func__, ret); } @@ -706,7 +690,7 @@ int sound_manager_get_media_session_option(sound_session_option_for_starting_e * else *d_option = SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY; - LOGI("<< leave : option for starting=%d, for during play=%d", *s_option, *d_option); + LOGI(" option for starting=%d, for during play=%d", *s_option, *d_option); return SOUND_MANAGER_ERROR_NONE; } @@ -763,9 +747,9 @@ int sound_manager_set_media_session_resumption_option(sound_session_option_for_r } if (updated) - LOGI("<< leave : updated"); + LOGI("updated"); else - LOGI("<< leave : already set same option(%x), skip it", session_option); + LOGI("already set same option(0x%x), skip it", session_option); return _convert_sound_manager_error_code(__func__, ret); } @@ -802,7 +786,7 @@ int sound_manager_get_media_session_resumption_option(sound_session_option_for_r else *option = SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM; - LOGI("<< leave : option for resumption=%d (0:by system, 1:by system or media paused)", *option); + LOGI("option for resumption=%d (0:by system, 1:by system or media paused)", *option); return SOUND_MANAGER_ERROR_NONE; } @@ -827,7 +811,7 @@ int sound_manager_set_voip_session_mode(sound_session_voip_mode_e mode) } ret = _set_session_mode((_session_mode_e)mode); - LOGI("<< leave : session=%p, mode=%d, ret=%p", session, mode, ret); + LOGI("session=%d, mode=%d", session, mode); return _convert_sound_manager_error_code(__func__, ret); } @@ -839,7 +823,7 @@ int sound_manager_get_voip_session_mode(sound_session_voip_mode_e *mode) int session_options = 0; if (mode == NULL) { - LOGI("mode is null"); + LOGE("mode is null"); return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT); } @@ -852,7 +836,7 @@ int sound_manager_get_voip_session_mode(sound_session_voip_mode_e *mode) *mode = (sound_session_voip_mode_e)g_cached_session_mode; - LOGI("returns : session=%p, mode=%d, ret=%p", session, *mode, ret); + LOGI("session=%d, mode=%d", session, *mode); return _convert_sound_manager_error_code(__func__, ret); } @@ -1088,7 +1072,7 @@ void __sound_manager_finalize(void) LOGI(""); ret = mm_session_finish(); if (ret != MM_ERROR_NONE) - LOGE("[%s] failed to mm_session_finish(), ret(%p)", __func__, ret); + LOGE("[%s] failed to mm_session_finish(), ret(0x%x)", __func__, ret); g_session_interrupt_cb_table.is_registered = 0; LOGI(""); diff --git a/src/sound_manager_internal.c b/src/sound_manager_internal.c index a698bc4..4c0a12a 100644 --- a/src/sound_manager_internal.c +++ b/src/sound_manager_internal.c @@ -81,7 +81,7 @@ int sound_manager_create_stream_information_internal(sound_stream_type_internal_ ret = _make_pa_connection_and_register_focus(stream_h, callback, user_data); if (!ret) { *stream_info = (sound_stream_info_h)stream_h; - LOGI("<< leave : stream_h(%p), index(%u), user_cb(%p), ret(%p)", stream_h, stream_h->index, stream_h->user_cb, ret); + LOGI("stream_h(%p), index(%u), user_cb(%p), ret(0x%x)", stream_h, stream_h->index, stream_h->user_cb, ret); } } if (ret) @@ -154,6 +154,52 @@ int sound_manager_get_index_from_stream_information(sound_stream_info_h stream_i return _convert_sound_manager_error_code(__func__, ret); } +int sound_manager_get_reason_for_current_playback_focus(sound_stream_focus_change_reason_e *acquired_by, char **additional_info) +{ + int ret = MM_ERROR_NONE; + char *stream_type_str = NULL; + char *additional_info_str = NULL; + + LOGI(">> enter"); + + SM_NULL_ARG_CHECK(acquired_by); + + ret = mm_sound_get_stream_type_of_acquired_focus((int)SOUND_STREAM_FOCUS_FOR_PLAYBACK, &stream_type_str, &additional_info_str); + if (ret == MM_ERROR_NONE) { + LOGI("current acquired [playback] focus: stream_type=%s", stream_type_str); + ret = _convert_stream_type_to_change_reason(stream_type_str, acquired_by); + if ((ret == MM_ERROR_NONE) && additional_info) { + LOGI(" : reason=%d, additional_info=%s", *acquired_by, additional_info_str); + *additional_info = additional_info_str; + } + } + + return _convert_sound_manager_error_code(__func__, ret); +} + +int sound_manager_get_reason_for_current_recording_focus(sound_stream_focus_change_reason_e *acquired_by, char **additional_info) +{ + int ret = MM_ERROR_NONE; + char *stream_type_str = NULL; + char *additional_info_str = NULL; + + LOGI(">> enter"); + + SM_NULL_ARG_CHECK(acquired_by); + + ret = mm_sound_get_stream_type_of_acquired_focus((int)SOUND_STREAM_FOCUS_FOR_RECORDING, &stream_type_str, &additional_info_str); + if (ret == MM_ERROR_NONE) { + LOGI("current acquired [recording] focus: stream_type=%s", stream_type_str); + ret = _convert_stream_type_to_change_reason(stream_type_str, acquired_by); + if ((ret == MM_ERROR_NONE) && additional_info) { + LOGI(" : reason=%d, additional_info=%s", *acquired_by, additional_info_str); + *additional_info = additional_info_str; + } + } + + return _convert_sound_manager_error_code(__func__, ret); +} + int sound_manager_create_virtual_stream(sound_stream_info_h stream_info, virtual_sound_stream_h *virtual_stream) { int ret = MM_ERROR_NONE; diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index 06e3fb9..e0a10a4 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -96,11 +96,16 @@ int _convert_sound_manager_error_code(const char *func, int code) ret = SOUND_MANAGER_ERROR_INVALID_STATE; errorstr = "INVALID_STATE"; break; + default: + LOGW("it should not be reached here, this error(0x%x) should be defined.", code); + ret = SOUND_MANAGER_ERROR_INTERNAL; + errorstr = "INTERNAL"; + break; } if (ret) - LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code); + LOGE("[%s] >> leave : %s(0x%08x), mm_error(0x%08x)", func, errorstr, ret, code); else - LOGD("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code); + LOGD("[%s] >> leave : %s(0x%08x)", func, errorstr, ret); return ret; } @@ -1409,7 +1414,7 @@ PA_ERROR: stream_h->pa_mainloop = NULL; } ret = MM_ERROR_SOUND_INTERNAL; - LOGE("pa_ret(%d), ret(%p)", pa_ret, ret); + LOGE("pa_ret(%d), ret(0x%x)", pa_ret, ret); SUCCESS: return ret; diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index 301627c..4104b8d 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -71,6 +71,8 @@ enum { CURRENT_STATUS_UNSET_FOCUS_WATCH_CB, CURRENT_STATUS_SET_FOCUS_REACQUISITION, CURRENT_STATUS_GET_FOCUS_REACQUISITION, + CURRENT_STATUS_GET_REASON_FOR_P_FOCUS, + CURRENT_STATUS_GET_REASON_FOR_R_FOCUS, CURRENT_STATUS_CREATE_VIRTUAL_STREAM, CURRENT_STATUS_START_VIRTUAL_STREAM, CURRENT_STATUS_STOP_VIRTUAL_STREAM, @@ -217,6 +219,10 @@ void _interpret_main_menu(char *cmd) g_menu_state = CURRENT_STATUS_SET_FOCUS_REACQUISITION; else if (strncmp(cmd, "gfr", 3) == 0) g_menu_state = CURRENT_STATUS_GET_FOCUS_REACQUISITION; + else if (strncmp(cmd, "grp", 3) == 0) + g_menu_state = CURRENT_STATUS_GET_REASON_FOR_P_FOCUS; + else if (strncmp(cmd, "grr", 3) == 0) + g_menu_state = CURRENT_STATUS_GET_REASON_FOR_R_FOCUS; else if (strncmp(cmd, "dsi", 3) == 0) g_menu_state = CURRENT_STATUS_DESTROY_STREAM_INFO; else if (strncmp(cmd, "vcr", 3) == 0) @@ -301,6 +307,8 @@ void display_sub_basic() g_print("ufw. Unset Focus State Watch CB\n"); g_print("sfr. Set Focus Reacquisition\t"); g_print("gfr. Get Focus Reacquisition\n"); + g_print("grp. Get Reason for Current Acquired Playback Focus\t"); + g_print("grr. Get Reason for Current Acquired Recording Focus\n"); g_print("sso. *Set option for stream routing\n"); g_print("vcr. *Create VStream\t"); g_print("vsr. *Start VStream\t"); @@ -408,6 +416,10 @@ static void displaymenu() g_print("*** input focus reacquisition property (1:enable, 2:disable)\n"); else if (g_menu_state == CURRENT_STATUS_GET_FOCUS_REACQUISITION) g_print("*** press enter to get focus reacquisition property (1:enabled, 2:disabled)\n"); + else if (g_menu_state == CURRENT_STATUS_GET_REASON_FOR_P_FOCUS) + g_print("*** press enter to get reason for current playback focus\n"); + else if (g_menu_state == CURRENT_STATUS_GET_REASON_FOR_R_FOCUS) + g_print("*** press enter to get reason for current recording focus\n"); else if (g_menu_state == CURRENT_STATUS_CREATE_VIRTUAL_STREAM) g_print("*** press enter to create virtual stream\n"); else if (g_menu_state == CURRENT_STATUS_START_VIRTUAL_STREAM) @@ -1208,7 +1220,7 @@ static void interpret(char *cmd) focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK; break; } - ret = sound_manager_acquire_focus(g_stream_info_h, focus_mask, NULL); + ret = sound_manager_acquire_focus(g_stream_info_h, focus_mask, "sound_manager_test_ac"); if (ret) g_print("fail to sound_manager_acquire_focus(), ret(0x%x)\n", ret); @@ -1235,7 +1247,7 @@ static void interpret(char *cmd) focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK; break; } - ret = sound_manager_release_focus(g_stream_info_h, focus_mask, NULL); + ret = sound_manager_release_focus(g_stream_info_h, focus_mask, "sound_manager_test_rel"); if (ret) g_print("fail to sound_manager_acquire_focus(), ret(0x%x)\n", ret); @@ -1356,6 +1368,30 @@ static void interpret(char *cmd) reset_menu_state(); break; } + case CURRENT_STATUS_GET_REASON_FOR_P_FOCUS: { + int ret = SOUND_MANAGER_ERROR_NONE; + char *additional_info = NULL; + sound_stream_focus_change_reason_e reason; + ret = sound_manager_get_reason_for_current_playback_focus(&reason, &additional_info); + if (ret) + g_print("fail to sound_manager_get_reason_for_current_playback_focus, ret(0x%x)\n", ret); + else + g_print("reason(%d), additional_info(%s)\n", reason, additional_info); + reset_menu_state(); + break; + } + case CURRENT_STATUS_GET_REASON_FOR_R_FOCUS: { + int ret = SOUND_MANAGER_ERROR_NONE; + char *additional_info = NULL; + sound_stream_focus_change_reason_e reason; + ret = sound_manager_get_reason_for_current_recording_focus(&reason, &additional_info); + if (ret) + g_print("fail to sound_manager_get_reason_for_current_recording_focus, ret(0x%x)\n", ret); + else + g_print("reason(%d), additional_info(%s)\n", reason, additional_info); + reset_menu_state(); + break; + } case CURRENT_STATUS_CREATE_VIRTUAL_STREAM: { int ret = SOUND_MANAGER_ERROR_NONE; if (!g_stream_info_h || g_vstream_h) {