Fix to mix screen-reader and interrupt mode by adding internal app state 33/224433/1 submit/tizen/20200220.060827 submit/tizen/20200221.052406
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 20 Nov 2019 12:19:15 +0000 (21:19 +0900)
committerSooyeon Kim <sooyeon.kim@samsung.com>
Mon, 10 Feb 2020 12:07:22 +0000 (12:07 +0000)
Change-Id: I575c801f78584ad1b20ed1eadaff10c11a8347b0
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 72a6660fe20050c183ff9c0c2c7c61e17206045c)

server/ttsd_player.c
server/ttsd_player.h
server/ttsd_server.c
server/ttsd_server.h

index 5f7c043..07d99f0 100644 (file)
@@ -31,6 +31,7 @@
 typedef enum {
        AUDIO_STATE_NONE = 0,
        AUDIO_STATE_READY,
+       AUDIO_STATE_WAIT_FOR_PLAYING,
        AUDIO_STATE_PLAY
 } audio_state_e;
 
@@ -134,26 +135,28 @@ void __player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus
        }
        SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d) and extra info(%s)", (int)focus_state, (int)reason_for_change, extra_info);
 
-       if (NULL == g_playing_info) {
-               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
-               return;
-       }
-
-       if (APP_STATE_PLAYING == g_playing_info->state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
+       if ((AUDIO_STATE_PLAY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
                if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
                        g_audio_state = AUDIO_STATE_READY;
 
-                       int uid = g_playing_info->uid;
-
-                       if (0 != ttsd_player_pause(uid)) {
-                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
+                       if (NULL == g_playing_info) {
+                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
                                return;
                        }
 
-                       ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
-                       int pid = ttsd_data_get_pid(uid);
-                       /* send message to client about changing state */
-                       ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
+                       if (APP_STATE_PLAYING == g_playing_info->state) {
+                               int uid = g_playing_info->uid;
+
+                               if (0 != ttsd_player_pause(uid)) {
+                                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
+                                       return;
+                               }
+
+                               ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
+                               int pid = ttsd_data_get_pid(uid);
+                               /* send message to client about changing state */
+                               ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
+                       }
                } else {
                        SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
                }
@@ -205,33 +208,41 @@ void __player_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask,
                return;
        }
 
-       if (NULL == g_playing_info) {
-               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
-               return;
-       }
+       if (SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason && NULL != extra_info && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) {
+               /* If the focus is changed by "Interrupt" mode and current players of "SR" and "Noti" modes are on going, please stop all players. */
+               SLOG(LOG_INFO, tts_tag(), "[Player INFO] All stop the playing or the request to play. audio state(%d)", g_audio_state);
 
-       if (APP_STATE_PLAYING == g_playing_info->state && SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason && 
-                       NULL != extra_info && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) {
-               /* If the focus is changed by "Interrupt" mode and current players of "SR" and "Noti" modes are on going, please stop the current players. */
+//             if (AUDIO_STATE_PLAY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state)
                g_audio_state = AUDIO_STATE_READY;
 
-               int uid = g_playing_info->uid;
+               ttsd_send_all_stop();
 
-               if (0 != ttsd_server_stop(uid)) {
-                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop TTS server");
-                       return;
-               }
-               if (0 != ttsd_player_stop(uid)) {
-                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop the player");
+/*             if (NULL == g_playing_info) {
+                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
                        return;
                }
 
-               ttsd_data_set_client_state(uid, APP_STATE_READY);
-               int pid = ttsd_data_get_pid(uid);
-               /* send message to client about changing state */
-               ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
-       } else {
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] Extra info is not Interrupt mode(%s) or not playing state(%d).", extra_info, g_playing_info->state);
+               if (APP_STATE_PLAYING == g_playing_info->state) {
+                       int uid = g_playing_info->uid;
+
+                       if (0 != ttsd_server_stop(uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop TTS server");
+                               return;
+                       }
+                       if (0 != ttsd_player_stop(uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop the player");
+                               return;
+                       }
+
+                       ttsd_data_set_client_state(uid, APP_STATE_READY);
+                       int pid = ttsd_data_get_pid(uid);
+                       // send message to client about changing state
+                       ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
+               } else {
+                       SLOG(LOG_DEBUG, tts_tag(), "[Player] Not playing state");
+               }
+*/     } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] Extra info is not Interrupt mode(%s) or not playing state(%d).", (NULL == extra_info) ? "NULL" : extra_info, g_audio_state);
        }
 
        return;
@@ -607,7 +618,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
 
                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
 
-                               if (AUDIO_STATE_READY == g_audio_state) {
+                               if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) {
                                        /* set volume policy as 40%, when resume play thread*/
                                        __set_policy_for_playing(40);
                                }
@@ -704,7 +715,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                len = SOUND_BUFFER_LENGTH;
                        }
 
-                       if (AUDIO_STATE_READY == g_audio_state) {
+                       if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) {
                                /* Request prepare */
                                ret = audio_out_prepare(g_audio_h);
                                if (AUDIO_IO_ERROR_NONE != ret) {
@@ -1474,3 +1485,12 @@ int ttsd_player_set_background_volume_ratio(double ratio)
        g_bg_volume_ratio = ratio;
        return TTSD_ERROR_NONE;
 }
+
+int ttsd_player_wait_to_play(int uid)
+{
+       SLOG(LOG_INFO, tts_tag(), "[Player INFO] wait to play (%d)", uid);
+
+       g_audio_state = AUDIO_STATE_WAIT_FOR_PLAYING;
+
+       return TTSD_ERROR_NONE;
+}
index 1221d93..de80ad9 100644 (file)
@@ -61,6 +61,8 @@ int ttsd_player_check_current_playback_focus(bool *is_current_interrupt);
 
 int ttsd_player_set_background_volume_ratio(double ratio);
 
+int ttsd_player_wait_to_play(int uid);
+
 #ifdef __cplusplus
 }
 #endif
index d90380a..27488ce 100644 (file)
@@ -287,12 +287,15 @@ bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        /* clear client data */
        ttsd_data_clear_data(uid);
-       ttsd_data_set_client_state(uid, APP_STATE_READY);
 
-       /* send message */
-       if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
-               /* remove client */
-               ttsd_data_delete_client(uid);
+       if (APP_STATE_READY != state) {
+               ttsd_data_set_client_state(uid, APP_STATE_READY);
+
+               /* send message */
+               if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
+                       /* remove client */
+                       ttsd_data_delete_client(uid);
+               }
        }
 
        return true;
@@ -434,6 +437,19 @@ void __screen_reader_changed_cb(bool value)
        return;
 }
 
+int ttsd_send_all_stop()
+{
+       SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
+
+       /* stop all player */ 
+       ttsd_player_all_stop();
+
+       /* send interrupt message to  all clients */
+       ttsd_data_foreach_clients(__get_client_cb, NULL);
+
+       return TTSD_ERROR_NONE;
+}
+
 /*
 * Server APIs
 */
@@ -960,6 +976,10 @@ int ttsd_server_play(int uid, const char* credential)
        }
 
        /* Change current play */
+       if (0 != ttsd_player_wait_to_play(uid)) {
+               SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
+       }
+
        if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
                return TTSD_ERROR_OPERATION_FAILED;
index d67d227..58ef698 100644 (file)
@@ -39,6 +39,7 @@ Eina_Bool ttsd_get_daemon_exist();
 
 int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data);
 int ttsd_send_error(ttse_error_e error, const char* msg);
+int ttsd_send_all_stop();
 
 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback);
 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback);