Add waiting for engine buffering 50/171250/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Thu, 25 Jan 2018 02:29:52 +0000 (11:29 +0900)
committerSooyeon Kim <sooyeon.kim@samsung.com>
Wed, 28 Feb 2018 02:37:24 +0000 (02:37 +0000)
Change-Id: I9cdaf09b60ea9345b824857acf0ada264f5cb3dd
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 9bf5d363bdd83858fa3a5bcb042d7cfa8aa8469d)

server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_player.c
server/ttsd_server.c

index a9bc5e7..1056101 100644 (file)
@@ -44,6 +44,9 @@ static vector<app_data_s> g_app_list;
 static pthread_mutex_t g_speak_data_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t g_sound_data_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+/* If engine is running */
+static ttsd_synthesis_control_e        g_synth_control;
+
 /*
 * functions for debug
 */
@@ -135,6 +138,17 @@ int __data_show_used_voice_list(int index)
 * ttsd data functions
 */
 
+int ttsd_set_synth_control(ttsd_synthesis_control_e control)
+{
+       g_synth_control = control;
+       return 0;
+}
+
+ttsd_synthesis_control_e ttsd_get_synth_control()
+{
+       return g_synth_control;
+}
+
 int ttsd_data_new_client(int pid, int uid)
 {
        if( -1 != ttsd_data_is_client(uid) ) {
index 23478a9..3acbf22 100644 (file)
@@ -29,6 +29,12 @@ typedef enum {
        APP_STATE_PAUSED
 } app_tts_state_e;
 
+typedef enum {
+       TTSD_SYNTHESIS_CONTROL_DOING    = 0,
+       TTSD_SYNTHESIS_CONTROL_DONE     = 1,
+       TTSD_SYNTHESIS_CONTROL_EXPIRED  = 2
+} ttsd_synthesis_control_e;
+
 typedef struct {
        int     utt_id; 
        char*   text;
@@ -48,6 +54,10 @@ typedef struct {
        int                     channels;
 } sound_data_s;
 
+int ttsd_set_synth_control(ttsd_synthesis_control_e control);
+
+ttsd_synthesis_control_e ttsd_get_synth_control();
+
 typedef void (* ttsd_used_voice_cb)(const char* lang, int type);
 
 int ttsd_data_new_client(int pid, int uid);
index a2d2e26..0c7679d 100644 (file)
@@ -428,17 +428,6 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        if (0 != ret || NULL == sound_data) {
                                /* empty queue */
                                SLOG(LOG_DEBUG, tts_tag(), "[Player] No sound data. Waiting mode");
-                               /* release audio & recover session */
-                               ret = audio_out_unprepare(g_audio_h);
-                               if (AUDIO_IO_ERROR_NONE != ret) {
-                                       SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
-                               } else {
-                                       SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
-                               }
-                               g_audio_state = AUDIO_STATE_READY;
-
-                               /* unset volume policy, volume will be 100% */
-                               __unset_policy_for_playing();
 
                                /* wait for new audio data come */
                                while (1) {
@@ -446,18 +435,50 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        if (NULL == g_playing_info) {
                                                /* current playing uid is replaced */
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread");
+                                               if (AUDIO_STATE_PLAY == g_audio_state) {
+                                                       /* release audio & recover session */
+                                                       ret = audio_out_unprepare(g_audio_h);
+                                                       if (AUDIO_IO_ERROR_NONE != ret) {
+                                                               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
+                                                       } else {
+                                                               SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
+                                                       }
+                                                       g_audio_state = AUDIO_STATE_READY;
+
+                                                       /* unset volume policy, volume will be 100% */
+                                                       __unset_policy_for_playing();
+                                               }
                                                return;
                                        } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
                                                /* new audio data come */
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread");
                                                break;
                                        }
+
+                                       /* If engine is not on processing */
+                                       if (TTSD_SYNTHESIS_CONTROL_DOING != ttsd_get_synth_control()) {
+                                               if (AUDIO_STATE_PLAY == g_audio_state) {
+                                                       /* release audio & recover session */
+                                                       ret = audio_out_unprepare(g_audio_h);
+                                                       if (AUDIO_IO_ERROR_NONE != ret) {
+                                                               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
+                                                       } else {
+                                                               SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
+                                                       }
+                                                       g_audio_state = AUDIO_STATE_READY;
+
+                                                       /* unset volume policy, volume will be 100% */
+                                                       __unset_policy_for_playing();
+                                               }
+                                       }
                                }
 
                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
 
-                               /* set volume policy as 40%, when resume play thread*/
-                               __set_policy_for_playing(40);
+                               if (AUDIO_STATE_READY == g_audio_state) {
+                                       /* set volume policy as 40%, when resume play thread*/
+                                       __set_policy_for_playing(40);
+                               }
 
                                /* resume play thread */
                                player->state = APP_STATE_PLAYING;
index 0731597..72cee8f 100644 (file)
 
 #define CLIENT_CLEAN_UP_TIME 500
 
-
-typedef enum {
-       TTSD_SYNTHESIS_CONTROL_DOING    = 0,
-       TTSD_SYNTHESIS_CONTROL_DONE     = 1,
-       TTSD_SYNTHESIS_CONTROL_EXPIRED  = 2
-} ttsd_synthesis_control_e;
-
 typedef struct {
        int uid;
        int uttid;
@@ -43,9 +36,6 @@ typedef struct {
 /* If current engine exist */
 //static bool  g_is_engine;
 
-/* If engine is running */
-static ttsd_synthesis_control_e        g_synth_control;
-
 static Ecore_Timer* g_check_client_timer = NULL;
 static Ecore_Timer* g_wait_timer = NULL;
 
@@ -56,17 +46,6 @@ static GList *g_proc_list = NULL;
 /* Function definitions */
 static int __synthesis(int uid, const char* credential);
 
-static int __server_set_synth_control(ttsd_synthesis_control_e control)
-{
-       g_synth_control = control;
-       return 0;
-}
-
-static ttsd_synthesis_control_e __server_get_synth_control()
-{
-       return g_synth_control;
-}
-
 static Eina_Bool __wait_synthesis(void *data)
 {
        /* get current play */
@@ -74,11 +53,11 @@ static Eina_Bool __wait_synthesis(void *data)
        int uid = ttsd_data_get_current_playing();
 
        if (uid > 0) {
-               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
                        return EINA_TRUE;
                } else {
                        g_wait_timer = NULL;
-                       if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
+                       if (TTSD_SYNTHESIS_CONTROL_DONE == ttsd_get_synth_control()) {
                                /* Start next synthesis */
                                __synthesis(uid, credential);
                        }
@@ -129,12 +108,12 @@ static int __synthesis(int uid, const char* credential)
                SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
 
                int ret = 0;
-               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
+               ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
                ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
                if (0 != ret) {
                        SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
 
-                       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+                       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
 
                        ttsd_server_stop(uid);
 
@@ -165,7 +144,7 @@ int ttsd_send_error(ttse_error_e error, const char* msg)
 
        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%d), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg));
 
-       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
 
        if (0 != ttsd_player_clear(uid))
                SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
@@ -208,14 +187,14 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
 
 
                if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
-                       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+                       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
                        SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_OPERATION_FAILED;
                }
 
                if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
-                       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+                       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
                        SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_INVALID_PARAMETER;
@@ -257,7 +236,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                }
 
                if (event == TTSE_RESULT_EVENT_FINISH) {
-                       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+                       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                }
 
                if (0 != ttsd_player_play(uid)) {
@@ -272,7 +251,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                }
        } else {
                SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
-               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+               ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
        }
 
 
@@ -450,7 +429,7 @@ int ttsd_initialize(ttse_request_callback_s *callback)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
 
        if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
                ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
@@ -787,7 +766,7 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
                }
 
                /* Check whether tts-engine is running or not */
-               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
                } else {
                        __synthesis(uid, credential);
@@ -901,7 +880,7 @@ int ttsd_server_play(int uid, const char* credential)
        }
 
        /* Check whether tts-engine is running or not */
-       if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+       if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
                SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
        } else {
                __synthesis(uid, credential);
@@ -921,7 +900,7 @@ int ttsd_server_stop(int uid)
        SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
 
        if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
-               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control() && uid == ttsd_data_get_current_playing()) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
                        SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
 
                        int ret = 0;
@@ -930,7 +909,7 @@ int ttsd_server_stop(int uid)
                                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
                }
 
-               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+               ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
 
                if (0 != ttsd_player_clear(uid))
                        SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");