Implemented Sound focus acquire and release in play and pause of video player 83/59583/11
authorANKIT <ar.raj@samsung.com>
Tue, 16 Feb 2016 12:41:44 +0000 (18:11 +0530)
committerANKIT <ar.raj@samsung.com>
Fri, 4 Mar 2016 11:10:01 +0000 (16:40 +0530)
Change-Id: I10c797541a2503cb886130ffadca37dd5b4ded31
Signed-off-by: ANKIT <ar.raj@samsung.com>
playview/src/core/include/vp-mm-player.h
playview/src/core/vp-mm-player.c
playview/src/core/vp-sound.c
playview/src/view/include/vp-play-normal-view.h
playview/src/view/vp-play-normal-view.c
playview/src/vp-play-view.c

index 571e56a..6f86c25 100644 (file)
@@ -236,6 +236,7 @@ typedef struct _MMPlayer {
        vp_mm_player_rotate_t nRotate;
        vp_mm_player_state_t nState;
        vp_mm_player_display_mode_t nDisplayMode;
+       sound_stream_info_h     stream_info;
 
        int nDuration;
        int nVideoWidth;
@@ -256,6 +257,7 @@ typedef struct _MMPlayer {
 
        int nZoomPosX;
        int nZoomPosY;
+       bool reacquire_state;
 
        void *pVideoSink;
 } MMPlayer;
@@ -271,6 +273,7 @@ bool vp_mm_player_is_realize(mm_player_handle pPlayerHandle);
 
 bool vp_mm_player_set_callback(mm_player_handle pPlayerHandle, vp_mm_player_callback_t nCallbackType, void *pCallback);
 bool vp_mm_player_set_user_param(mm_player_handle pPlayerHandle, void *pParam);
+bool vp_mm_player_set_stream_info(mm_player_handle pPlayerHandle, void *stream_info);
 
 bool vp_mm_player_play(mm_player_handle pPlayerHandle);
 bool vp_mm_player_stop(mm_player_handle pPlayerHandle);
index ab7db1b..0566169 100644 (file)
@@ -1230,6 +1230,23 @@ mm_player_handle vp_mm_player_create()
 
        VideoLogInfo(">> player create");
 
+       sound_manager_get_focus_reacquisition(pMMPlayer->stream_info, &pMMPlayer->reacquire_state);
+       if (pMMPlayer->reacquire_state == EINA_FALSE)
+               sound_manager_set_focus_reacquisition(pMMPlayer->stream_info, EINA_TRUE);
+       sound_stream_focus_state_e state_for_playback;
+       sound_stream_focus_state_e state_for_recording;
+       int ret = -1;
+       ret = sound_manager_get_focus_state(pMMPlayer->stream_info, &state_for_playback, &state_for_recording);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               VideoLogError("failed to get focus state error[%x]", ret);
+               }
+       if (state_for_playback == SOUND_STREAM_FOCUS_STATE_RELEASED) {
+               int error = SOUND_MANAGER_ERROR_NONE;
+               error = sound_manager_acquire_focus(pMMPlayer->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+               if (error != SOUND_MANAGER_ERROR_NONE)
+                       VideoLogError("failed to acquire focus [%x]", error);
+       }
+
        int nRet = 0;
        nRet = player_create(&pMMPlayer->pPlayer);
        if (nRet != PLAYER_ERROR_NONE) {
@@ -1678,6 +1695,26 @@ bool vp_mm_player_set_user_param(mm_player_handle pPlayerHandle,
        return TRUE;
 }
 
+bool vp_mm_player_set_stream_info(mm_player_handle pPlayerHandle,
+                                 void *stream_info)
+{
+       if (pPlayerHandle == NULL) {
+               VideoLogError("pPlayerHandle is NULL");
+               return FALSE;
+       }
+
+       if (stream_info == NULL) {
+               VideoLogError("stream info is NULL");
+               return FALSE;
+       }
+
+       MMPlayer *pMMPlayer = (MMPlayer *)pPlayerHandle;
+
+       pMMPlayer->stream_info = stream_info;
+
+       return TRUE;
+}
+
 bool vp_mm_player_play(mm_player_handle pPlayerHandle)
 {
        if (pPlayerHandle == NULL) {
@@ -1698,6 +1735,22 @@ bool vp_mm_player_play(mm_player_handle pPlayerHandle)
                VideoLogError("Not realized");
                return FALSE;
        }
+       sound_manager_get_focus_reacquisition(pMMPlayer->stream_info, &pMMPlayer->reacquire_state);
+       if (pMMPlayer->reacquire_state == EINA_FALSE)
+               sound_manager_set_focus_reacquisition(pMMPlayer->stream_info, EINA_TRUE);
+       sound_stream_focus_state_e state_for_playback;
+       sound_stream_focus_state_e state_for_recording;
+       int ret = -1;
+       ret = sound_manager_get_focus_state(pMMPlayer->stream_info, &state_for_playback, &state_for_recording);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               VideoLogError("failed to get focus state error[%x]", ret);
+       }
+       if (state_for_playback == SOUND_STREAM_FOCUS_STATE_RELEASED) {
+               int error = SOUND_MANAGER_ERROR_NONE;
+               error = sound_manager_acquire_focus(pMMPlayer->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+               if (error != SOUND_MANAGER_ERROR_NONE)
+                       VideoLogError("failed to acquire focus [%x]", error);
+       }
 
        VideoLogWarning("[player_start start]");
        int nRet = player_start(pMMPlayer->pPlayer);
@@ -1739,6 +1792,20 @@ bool vp_mm_player_stop(mm_player_handle pPlayerHandle)
                return FALSE;
        }
        VideoLogWarning("[player_stop end]");
+       sound_stream_focus_state_e state_for_playback;
+       sound_stream_focus_state_e state_for_recording;
+       int ret = -1;
+       ret = sound_manager_get_focus_state(pMMPlayer->stream_info, &state_for_playback, &state_for_recording);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               VideoLogError("failed to get focus state error[%x]", ret);
+               }
+       if (state_for_playback != SOUND_STREAM_FOCUS_STATE_RELEASED) {
+               int error = SOUND_MANAGER_ERROR_NONE;
+               error = sound_manager_release_focus(pMMPlayer->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+               if (error != SOUND_MANAGER_ERROR_NONE) {
+                       VideoLogError("failed to release focus error[%x]", error);
+               }
+       }
 
        return TRUE;
 
@@ -1771,6 +1838,20 @@ bool vp_mm_player_pause(mm_player_handle pPlayerHandle)
                return FALSE;
        }
        VideoLogWarning("[player_pause end]");
+       sound_stream_focus_state_e state_for_playback;
+       sound_stream_focus_state_e state_for_recording;
+       int ret = -1;
+       ret = sound_manager_get_focus_state(pMMPlayer->stream_info, &state_for_playback, &state_for_recording);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               VideoLogError("failed to get focus state error[%x]", ret);
+               }
+       if (state_for_playback != SOUND_STREAM_FOCUS_STATE_RELEASED) {
+               int error = SOUND_MANAGER_ERROR_NONE;
+               error = sound_manager_release_focus(pMMPlayer->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+               if (error != SOUND_MANAGER_ERROR_NONE) {
+                       VideoLogError("failed to release focus error[%x]", error);
+               }
+       }
 
        return TRUE;
 
index f08e31c..17a312d 100644 (file)
@@ -34,15 +34,13 @@ void vp_player_focus_callback(sound_stream_info_h stream_info, sound_stream_focu
                                        const char *additional_info, void *user_data)
 {
        PlayView *pPlayView = (PlayView *)user_data;
-
        sound_stream_focus_state_e state_for_playback;
        sound_stream_focus_state_e state_for_recording;
        int ret = -1;
        ret = sound_manager_get_focus_state(pPlayView->stream_info, &state_for_playback,
                                                                                &state_for_recording);
        if (state_for_playback == SOUND_STREAM_FOCUS_STATE_RELEASED) {
-               vp_play_view_unrealize(pPlayView);
-
+               vp_play_normal_view_pause_player(pPlayView);
                if (reason_for_change != SOUND_STREAM_FOCUS_CHANGED_BY_ALARM &&
                                reason_for_change != SOUND_STREAM_FOCUS_CHANGED_BY_NOTIFICATION) {
                        sound_manager_get_focus_reacquisition(pPlayView->stream_info, &pPlayView->reacquire_state);
@@ -51,7 +49,7 @@ void vp_player_focus_callback(sound_stream_info_h stream_info, sound_stream_focu
                        }
                }
        } else {
-               ret = vp_play_view_realize(pPlayView);
+               vp_play_normal_view_play_player(pPlayView);
        }
 }
 
index e34e9b4..ca8a7fe 100644 (file)
@@ -82,6 +82,7 @@ vp_normalview_popup_style_e vp_play_normal_view_get_popup_show_state(normal_view
 bool vp_play_normal_view_set_tagbuddy_on(normal_view_handle pViewHandle, bool bTagBuddyOn);
 void vp_play_normal_view_show_volume_popup(void *pPlayview);
 void vp_play_normal_view_pause_player(void *pPlayview);
+void vp_play_normal_view_play_player(void *pPlayview);
 void vp_play_normal_view_key_create(PlayView *pPlayView, normal_view_handle pViewHandle);
 bool vp_play_normal_view_player_state_changed_get(normal_view_handle pViewHandle);
 bool vp_play_normal_view_stop_player(normal_view_handle pViewHandle);
index 9a5ba6a..11e7ded 100755 (executable)
@@ -4961,6 +4961,27 @@ void vp_play_normal_view_pause_player(void *pPlayview)
        _vp_play_normal_view_on_capture_mode(pNormalView);
 }
 
+void vp_play_normal_view_play_player(void *pPlayview)
+{
+       if (!pPlayview) {
+               VideoLogError("Invalid player View)");
+               return;
+       }
+       PlayView *vPlayview = (PlayView *)pPlayview;
+       NormalView *pNormalView = vPlayview->pNormalView;
+       vp_mm_player_state_t nState = VP_MM_PLAYER_STATE_NONE;
+
+       if (!vp_mm_player_get_state(pNormalView->pPlayerHandle, &nState)) {
+               VideoLogWarning("vp_mm_player_get_state is fail");
+       }
+       if (nState == VP_MM_PLAYER_STATE_PAUSED) {
+               vp_mm_player_play(pNormalView->pPlayerHandle);
+               pNormalView->bManualPause = FALSE;
+       }
+       _vp_play_normal_view_set_play_state(pNormalView);
+       _vp_play_normal_view_on_capture_mode(pNormalView);
+}
+
 void vp_play_normal_view_show_volume_popup(void *pPlayview)
 {
        if (!pPlayview) {
@@ -6891,6 +6912,10 @@ static bool _vp_play_normal_view_play_start(NormalView *pNormalView, bool bCheck
                VideoLogError("unable to set sound policy [%x]", nRet);
        }
 
+       if (!vp_mm_player_set_stream_info(pNormalView->pPlayerHandle, (void *)(pNormalView->pPlayView->stream_info))) {
+               VideoLogError("vp_mm_player_set_stream_info fail");
+               return FALSE;
+       }
        if (!vp_mm_player_set_user_param(pNormalView->pPlayerHandle, (void *) pNormalView)) {
                VideoLogError("vp_mm_player_set_user_param fail");
                return FALSE;
@@ -11612,7 +11637,6 @@ bool vp_play_normal_view_resume(normal_view_handle pViewHandle)
        if (pNormalView->pPlayerHandle && pNormalView->bIsRealize) {
                _vp_play_normal_view_all_close_popup(pNormalView);
        }
-
        if (pNormalView->bManualPause == FALSE && pNormalView->bSharepopup == FALSE) {
 
                vp_mm_player_state_t nState = VP_MM_PLAYER_STATE_NONE;
index cdc88c0..d7b80de 100644 (file)
@@ -1903,14 +1903,22 @@ bool vp_play_view_realize(play_view_handle pViewHandle)
        pPlayView->bVisible = TRUE;
        vp_play_normal_view_key_create(pPlayView, pPlayView->pNormalView);
        vp_play_normal_view_set_share_panel_state(pPlayView->pNormalView);
-       error = sound_manager_acquire_focus(pPlayView->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
-       if (error != SOUND_MANAGER_ERROR_NONE) {
-               VideoLogError("failed to acquire focus [%x]", error);
-       }
 
-       sound_manager_get_focus_reacquisition(pPlayView->stream_info, &pPlayView->reacquire_state);
-       if (pPlayView->reacquire_state == EINA_FALSE) {
-               sound_manager_set_focus_reacquisition(pPlayView->stream_info, EINA_TRUE);
+       sound_stream_focus_state_e state_for_playback;
+       sound_stream_focus_state_e state_for_recording;
+       int ret = -1;
+       ret = sound_manager_get_focus_state(pPlayView->stream_info, &state_for_playback, &state_for_recording);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               VideoLogError("failed to get focus state error[%x]", ret);
+               }
+       if (state_for_playback == SOUND_STREAM_FOCUS_STATE_RELEASED) {
+               error = sound_manager_acquire_focus(pPlayView->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+               if (error != SOUND_MANAGER_ERROR_NONE) {
+                       VideoLogError("failed to acquire focus [%x]", error);
+               }
+               sound_manager_get_focus_reacquisition(pPlayView->stream_info, &pPlayView->reacquire_state);
+               if (pPlayView->reacquire_state == EINA_FALSE)
+                       sound_manager_set_focus_reacquisition(pPlayView->stream_info, EINA_TRUE);
        }
        if (pPlayView->bRealized == TRUE) {
                VideoLogWarning("Already Realize state");
@@ -2055,10 +2063,19 @@ bool vp_play_view_unrealize(play_view_handle pViewHandle)
                vp_play_util_key_ungrab(pPlayView->pWin, VP_VOLUME_MUTE);
                vp_play_util_key_ungrab(pPlayView->pWin, VP_HOME_KEY);
                sound_manager_unset_current_sound_type();
-               error = sound_manager_release_focus(pPlayView->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
-               if (error != SOUND_MANAGER_ERROR_NONE) {
-               VideoLogError("failed to release focus error[%x]", error);
-               }
+               sound_stream_focus_state_e state_for_playback;
+               sound_stream_focus_state_e state_for_recording;
+               int ret = -1;
+               ret = sound_manager_get_focus_state(pPlayView->stream_info, &state_for_playback, &state_for_recording);
+               if (ret != SOUND_MANAGER_ERROR_NONE) {
+                       VideoLogError("failed to get focus state error[%x]", ret);
+               }
+               if (state_for_playback != SOUND_STREAM_FOCUS_STATE_RELEASED) {
+                       error = sound_manager_release_focus(pPlayView->stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+                       if (error != SOUND_MANAGER_ERROR_NONE) {
+                               VideoLogError("failed to release focus error[%x]", error);
+                       }
+               }
                media_key_release();
                int nDuration = 0;
                if (vp_play_normal_view_get_video_duration(pPlayView->pNormalView, &nDuration)) {