focus_reacquisition implemented according to Sound_stream_focus 01/58101/8
authorShubham Kumar <shubham.srib@samsung.com>
Wed, 27 Jan 2016 12:08:25 +0000 (17:38 +0530)
committerShubham Kumar <shubham.srib@samsung.com>
Tue, 2 Feb 2016 10:47:31 +0000 (16:17 +0530)
Change-Id: I8ae1ef5e31ed2f84413ed55c1a93c6b0a50925c3
Signed-off-by: Shubham Kumar <shubham.srib@samsung.com>
src/core/mp-player-mgr.c

index 4cc0238..c32083a 100755 (executable)
@@ -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;
 }