Start play thread only when 'ttsd_server_play()' is called 88/264188/3
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 13 Sep 2021 11:18:07 +0000 (20:18 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 12 Oct 2021 05:36:19 +0000 (14:36 +0900)
Previous code calls 'ttsd_player_play()' repeatedly when 'ttsd_send_result()' is called.
This logic can skip the stop request by player policy, so this patch changes the logic.

By this patch 'ttsd_player_play()' is only called when 'ttsd_server_play()' is called.

Change-Id: I8b1cfa888fc9049c7b17bf900f728eaa6062819f
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_player.c
server/ttsd_player.h
server/ttsd_server.c

index 06e1a1c..498b577 100644 (file)
@@ -1340,13 +1340,6 @@ int ttsd_player_play(int uid)
 
        SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
 
-       /* Check sound queue size */
-       if (0 == ttsd_data_get_sound_data_size(uid)) {
-               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
-               pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
-       }
-
        /* Check uid */
        player_s* current;
        current = __player_get_item(uid);
@@ -1361,11 +1354,8 @@ int ttsd_player_play(int uid)
        g_playing_info = current;
 
        SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
-
-       if (0 < ttsd_data_get_sound_data_size(current->uid)) {
-               SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
-               ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
-       }
+       SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
+       ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
 
        pthread_mutex_unlock(&g_player_control_mutex);
        return 0;
@@ -1571,59 +1561,6 @@ int ttsd_player_all_stop()
        return 0;
 }
 
-int ttsd_player_play_pcm(int uid)
-{
-       pthread_mutex_lock(&g_player_control_mutex);
-       if (false == g_player_init) {
-               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
-               pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
-       }
-
-       if (NULL != g_playing_info) {
-               if (uid == g_playing_info->uid) {
-                       SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
-                       pthread_mutex_unlock(&g_player_control_mutex);
-                       return 0;
-               } else {
-                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
-                       pthread_mutex_unlock(&g_player_control_mutex);
-                       ttsd_player_stop(g_playing_info->uid);
-                       pthread_mutex_lock(&g_player_control_mutex);
-               }
-       }
-
-       SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
-
-       /* Check sound queue size */
-       if (0 == ttsd_data_get_sound_data_size(uid)) {
-               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
-       }
-
-       /* Check uid */
-       player_s* current;
-       current = __player_get_item(uid);
-       if (NULL == current) {
-               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
-               pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
-       }
-
-       current->state = APP_STATE_PLAYING;
-
-       g_playing_info = current;
-
-       SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
-
-       if (0 <= ttsd_data_get_sound_data_size(current->uid)) {
-               SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
-               ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
-       }
-
-       pthread_mutex_unlock(&g_player_control_mutex);
-       return 0;
-}
-
 int ttsd_player_get_background_volume_ratio(double* ratio)
 {
        if (NULL == ratio)
index cd78eb4..d206539 100644 (file)
@@ -55,8 +55,6 @@ int ttsd_player_resume(int uid);
 
 int ttsd_player_all_stop();
 
-int ttsd_player_play_pcm(int uid);
-
 bool ttsd_player_does_interrupt_have_playback_focus();
 
 int ttsd_player_set_background_volume_ratio(double ratio);
index ed98b31..6901f08 100644 (file)
@@ -290,39 +290,6 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
        }
 
-       /* If the app state is paused, do not result to play */
-       if (true == g_is_paused) {
-               SLOG(LOG_DEBUG, tts_tag(), "[Server DEBUG] tts_pause is called. Do not request to play");
-               return TTSD_ERROR_NONE;
-       }
-
-       app_tts_state_e state = APP_STATE_CREATED;
-       if (0 != ttsd_data_get_client_state(uid, &state)) {
-               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
-               return TTSD_ERROR_INVALID_PARAMETER;
-       }
-
-       if (APP_STATE_PLAYING != state) {
-               SLOG(LOG_INFO, tts_tag(), "[Server] client state is not playing");
-               return TTSD_ERROR_NONE;
-       }
-
-       if (0 != ttsd_player_play(uid)) {
-               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
-
-               ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
-
-               int tmp_pid = ttsd_data_get_pid(uid);
-               if (tmp_pid <= 0) {
-                       SLOG(LOG_WARN, tts_tag(), "[Server WARNING] uid(%d) is already destroyed or invalid", uid);
-               } else {
-                       /* Change ready state */
-                       ttsd_server_stop(uid);
-
-                       ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
-               }
-       }
-
        return TTSD_ERROR_NONE;
 }
 
@@ -1039,6 +1006,12 @@ int ttsd_server_play(int uid, const char* credential)
                if (0 != ttsd_player_resume(uid)) {
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
                }
+       } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%d)", uid);
+
+               if (0 != ttsd_player_play(uid)) {
+                       SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_play()");
+               }
        }
 
        /* Check whether tts-engine is running or not */
@@ -1291,7 +1264,7 @@ int ttsd_server_play_pcm(int uid)
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
                }
        } else {
-               if (0 != ttsd_player_play_pcm(uid)) {
+               if (0 != ttsd_player_play(uid)) {
                        SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
 
                        // Change ready state