From d94fe067ec49ae573e8e2aabc20dca41226a0f45 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Date: Wed, 27 Jan 2016 17:38:25 +0530 Subject: [PATCH] focus_reacquisition implemented according to Sound_stream_focus Change-Id: I8ae1ef5e31ed2f84413ed55c1a93c6b0a50925c3 Signed-off-by: Shubham Kumar --- src/core/mp-player-mgr.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/core/mp-player-mgr.c b/src/core/mp-player-mgr.c index 4cc0238..c32083a 100755 --- a/src/core/mp-player-mgr.c +++ b/src/core/mp-player-mgr.c @@ -49,6 +49,7 @@ static bool is_seeking = false; static bool resume_on_seek_done = false; static bool pause_on_seek_done = false; static int g_reserved_seek_pos = -1; +bool reacquire_state; static Seek_Done_Cb g_requesting_cb = NULL; static void *g_requesting_cb_data = NULL; @@ -678,6 +679,7 @@ mp_player_mgr_destroy(void *data) struct appdata *ad = data; MP_CHECK_FALSE(ad); int res = true; + int error = -1; if (ad->current_track_info) { if (mp_setting_read_playing_status(ad->current_track_info->uri, "paused") != 1) { mp_setting_write_playing_status(ad->current_track_info->uri, "paused"); @@ -706,6 +708,10 @@ mp_player_mgr_destroy(void *data) mp_setting_set_player_state(MP_PLAY_STATE_NONE); } + error = sound_manager_destroy_stream_information(ad->stream_info); + if (error != SOUND_MANAGER_ERROR_NONE) { + DEBUG_TRACE("unable to destroy stream. error code [%x]", error); + } is_seeking = false; g_reserved_seek_pos = -1; g_reserved_cb = NULL; @@ -785,6 +791,11 @@ mp_player_mgr_play(void *data) if (error != SOUND_MANAGER_ERROR_NONE) { ERROR_TRACE("failed to acquire focus [%x]", error); } + + sound_manager_get_focus_reacquisition(ad->stream_info, &reacquire_state); + if (reacquire_state == EINA_FALSE) { + sound_manager_set_focus_reacquisition(ad->stream_info, EINA_TRUE); + } err = g_player_apis.start(_player); PLAYER_LEAVE_LOG("start"); @@ -848,7 +859,7 @@ mp_player_mgr_resume(void *data) startfunc; struct appdata *ad = data; MP_CHECK_FALSE(ad); - int err = -1; + int err = -1,error = -1; mp_util_lock_cpu(); if (!mp_player_mgr_is_active()) { @@ -860,6 +871,15 @@ mp_player_mgr_resume(void *data) } } + error = sound_manager_acquire_focus(ad->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL); + if (error != SOUND_MANAGER_ERROR_NONE) { + ERROR_TRACE("failed to acquire focus [%x]", error); + } + + sound_manager_get_focus_reacquisition(ad->stream_info, &reacquire_state); + if (reacquire_state == EINA_FALSE) { + sound_manager_set_focus_reacquisition(ad->stream_info, EINA_TRUE); + } if (mp_player_mgr_get_state() != PLAYER_STATE_IDLE) { DEBUG_TRACE("player state is ready"); PLAYER_ENTER_LOG("start"); @@ -1123,10 +1143,16 @@ void mp_player_focus_callback(sound_stream_info_h stream_info, sound_stream_focu &state_for_recording); if (state_for_playback == SOUND_STREAM_FOCUS_STATE_RELEASED) { mp_player_mgr_pause(ad); - sound_manager_release_focus(ad->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL); + + if (reason_for_change != SOUND_STREAM_FOCUS_CHANGED_BY_ALARM && + reason_for_change != SOUND_STREAM_FOCUS_CHANGED_BY_NOTIFICATION) { + sound_manager_get_focus_reacquisition(ad->stream_info, &reacquire_state); + if (reacquire_state == EINA_TRUE) { + sound_manager_set_focus_reacquisition(ad->stream_info, EINA_FALSE); + } + } } else { ret = mp_player_mgr_play(ad); - sound_manager_acquire_focus(ad->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL); } } @@ -1136,16 +1162,14 @@ mp_player_mgr_session_init(void) { struct appdata *ad = mp_util_get_appdata(); int ret = SOUND_MANAGER_ERROR_NONE; + if (!ad->stream_info) { + ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, mp_player_focus_callback, ad, &ad->stream_info); - PLAYER_ENTER_LOG("sound_manager_set_session_type"); - ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, mp_player_focus_callback, ad, &ad->stream_info); - PLAYER_LEAVE_LOG("sound_manager_set_session_type"); - - - if (ret != SOUND_MANAGER_ERROR_NONE) { - return FALSE; + if (ret != SOUND_MANAGER_ERROR_NONE) { + EVENT_TRACE("failed to create_stream_information %x", ret); + return FALSE; + } } - return TRUE; } -- 2.7.4