Try to prepare when dbus call is requested earlier while a tts engine is reset 44/167944/1
authorWonnam Jang <wn.jang@samsung.com>
Tue, 5 Dec 2017 10:47:05 +0000 (19:47 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 23 Jan 2018 05:32:22 +0000 (05:32 +0000)
Change-Id: I7c489d1cfff1a662408d27e0b2419ad4d2558983
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
(cherry picked from commit 7d7e378d83e2ae30c7f4114ed8acd23bdf841504)

client/tts.c
common/tts_defs.h
include/tts_internal.h

index e6385b4..f08165b 100644 (file)
@@ -687,6 +687,45 @@ int tts_prepare(tts_h tts)
        return TTS_ERROR_NONE;
 }
 
+int tts_prepare_sync(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
+
+       tts_client_s* client = tts_client_get(tts);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check state */
+       if (client->current_state != TTS_STATE_CREATED) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       int cnt = 0;
+       while (EINA_TRUE == __tts_connect_daemon(NULL) && TTS_CONNECTION_RETRY_COUNT > cnt) {
+               cnt++;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       if (TTS_CONNECTION_RETRY_COUNT == cnt) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect daemon");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       return TTS_ERROR_NONE;
+}
+
 int tts_unprepare(tts_h tts)
 {
        if (0 != __tts_get_feature_enabled()) {
@@ -721,11 +760,17 @@ int tts_unprepare(tts_h tts)
                g_screen_reader = (bool)screen_reader;
        }
 
+       bool is_prepared = false;
        if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
                do {
                        ret = tts_dbus_request_finalize(client->uid);
                        if (0 != ret) {
-                               if (TTS_ERROR_TIMED_OUT != ret) {
+                               if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                                       if (0 == tts_prepare_sync(tts)) {
+                                               is_prepared = true;
+                                               SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                                       }
+                               } else if (TTS_ERROR_TIMED_OUT != ret) {
                                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                        break;
                                } else {
@@ -1104,10 +1149,16 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        /* do request */
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1147,10 +1198,16 @@ static void __tts_play_async(void *data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_play(client->uid, client->credential);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1274,10 +1331,16 @@ int tts_play(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_play(client->uid, client->credential);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1320,10 +1383,16 @@ static void __tts_stop_async(void *data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_stop(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1436,10 +1505,16 @@ int tts_stop(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_stop(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1482,10 +1557,16 @@ static void __tts_pause_async(void *data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_pause(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1600,10 +1681,16 @@ int tts_pause(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_pause(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1670,10 +1757,16 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_set_private_data(client->uid, key, data);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1725,10 +1818,16 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_get_private_data(client->uid, key, data);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -2371,10 +2470,16 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size,
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -2428,10 +2533,16 @@ int tts_play_pcm(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_play_pcm(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -2495,10 +2606,16 @@ int tts_stop_pcm(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_stop_pcm(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
index c0f57fa..bd83eea 100644 (file)
@@ -89,8 +89,9 @@ extern "C" {
 
 #define TTS_BASE_LANGUAGE              "en_US"
 
-#define TTS_RETRY_COUNT                5
-#define TTS_RETRY_MIN_COUNT    2
+#define TTS_RETRY_COUNT                        5
+#define TTS_RETRY_MIN_COUNT            2
+#define TTS_CONNECTION_RETRY_COUNT     10
 
 #define TTS_SPEED_MIN          1
 #define TTS_SPEED_NORMAL       8
index 29ea810..2b0560b 100644 (file)
@@ -115,6 +115,25 @@ int tts_play_pcm(tts_h tts);
 */
 int tts_stop_pcm(tts_h tts);
 
+
+/**
+ * @brief Connects the daemon asynchronously.
+ * @since_tizen 5.0
+ * @param[in] tts The TTS handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @pre The state should be #TTS_STATE_CREATED.
+ * @post If this function is successful, the TTS state will be #TTS_STATE_READY.
+ *       If this function is failed, the error callback is called. (e.g. #TTS_ERROR_ENGINE_NOT_FOUND)
+ * @see tts_unprepare()
+*/
+int tts_prepare_sync(tts_h tts);
+
+
 #ifdef __cplusplus
 }
 #endif