Fix mini-controller play/pause button updation when video is playing 72/253472/1 submit/tizen/20210210.123650
authorJagrat Patidar <j1.patidar@samsung.com>
Wed, 10 Feb 2021 11:39:17 +0000 (17:09 +0530)
committerJagrat Patidar <j1.patidar@samsung.com>
Wed, 10 Feb 2021 12:23:45 +0000 (12:23 +0000)
Change-Id: I0a1e53d4414cab4d767319ecc5b460f31bd7a739
(cherry picked from commit 978c8e6f45047c798b117f762db52b4b714bfffa)

src/core/mp-player-mgr.c

index de4fb9c96f0dc4cfb7b17e4c0c4ee67a32b370c2..88ec7138769d9b7f1866f05691e190a21aa5b5da 100755 (executable)
@@ -958,6 +958,9 @@ bool mp_player_mgr_pause(void *data)
        MP_CHECK_FALSE(ad);
        int err = -1;
        int error = SOUND_MANAGER_ERROR_NONE;
+       sound_stream_focus_state_e state_for_playback;
+       sound_stream_focus_state_e state_for_recording;
+       int ret = -1;
 
        mp_util_release_cpu();
 
@@ -967,7 +970,16 @@ bool mp_player_mgr_pause(void *data)
 
        PLAYER_ENTER_LOG("pause");
        err = g_player_apis.pause(_player);
-       if (ad->stream_info) {
+
+       ret =
+               sound_manager_get_focus_state(ad->stream_info,
+                                                                         &state_for_playback,
+                                                                         &state_for_recording);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               DEBUG_TRACE("failed to get focus state error[%x]", ret);
+       }
+
+       if (ad->stream_info && state_for_playback != SOUND_STREAM_FOCUS_STATE_RELEASED) {
                error =
                        sound_manager_release_focus(ad->stream_info,
                                                                                SOUND_STREAM_FOCUS_FOR_PLAYBACK,
@@ -976,6 +988,7 @@ bool mp_player_mgr_pause(void *data)
                        ERROR_TRACE("failed to release focus error[%x]", error);
                }
        }
+
        PLAYER_LEAVE_LOG("pause");
 
        if (err != PLAYER_ERROR_NONE) {
@@ -1165,6 +1178,17 @@ int mp_player_mgr_safety_volume_set(int foreground)
        return 0;
 }
 
+static void mp_player_pause_main_thread_callback(void *user_data) {
+       DEBUG_TRACE("Main loop thread safe pause callback called");
+       mp_player_mgr_pause(user_data);
+}
+
+static void mp_player_control_play_pause_main_thread_callback(void *user_data) {
+       DEBUG_TRACE("Main loop thread safe control-play-pause callback called");
+       struct appdata *ad = user_data;
+       mp_play_control_play_pause(ad, true);
+}
+
 void mp_player_focus_callback(sound_stream_info_h stream_info,
                                                          sound_stream_focus_mask_e focus_mask,
                                                          sound_stream_focus_state_e focus_state,
@@ -1177,8 +1201,11 @@ void mp_player_focus_callback(sound_stream_info_h stream_info,
 
        if (focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK
                && focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED) {
-               mp_player_mgr_pause(ad);
-
+               // this callback is called from internal thread of sound manager not from main thread
+               // elementry api need to be called from main thread to work
+               // so we can't update ui in this thread.
+               // we need to add main loop callback to update ui.
+               ecore_main_loop_thread_safe_call_sync(mp_player_pause_main_thread_callback, ad);
                sound_manager_get_focus_reacquisition(ad->stream_info,
                                                                                          &reacquire_state);
                DEBUG_TRACE("reason for change is %d", reason_for_change);
@@ -1205,7 +1232,11 @@ void mp_player_focus_callback(sound_stream_info_h stream_info,
                                                                                                EINA_TRUE);
                }
        } else {
-               mp_play_control_play_pause(ad, true);
+               // this callback is called from internal thread of sound manager not from main thread
+               // elementry api need to be called from main thread to work
+               // so we can't update ui in this thread.
+               // we need to add main loop callback to update ui.
+               ecore_main_loop_thread_safe_call_sync(mp_player_control_play_pause_main_thread_callback, ad);
        }
 }