Merge "Try to prepare when dbus call is requested earlier while a tts engine is reset...
authorSooyeon Kim <sooyeon.kim@samsung.com>
Tue, 23 Jan 2018 05:33:32 +0000 (05:33 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Tue, 23 Jan 2018 05:33:33 +0000 (05:33 +0000)
1  2 
client/tts.c
common/tts_defs.h
include/tts_internal.h

diff --combined client/tts.c
@@@ -27,7 -27,6 +27,7 @@@
  #include "tts_dbus.h"
  #include "tts_main.h"
  
 +#include "tts_internal.h"
  
  static bool g_screen_reader;
  
@@@ -392,7 -391,7 +392,7 @@@ int tts_set_mode(tts_h tts, tts_mode_e 
                return TTS_ERROR_INVALID_STATE;
        }
  
 -      if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_SCREEN_READER) {
 +      if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_INTERRUPT) {
                client->mode = mode;
        } else {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
@@@ -688,6 -687,45 +688,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()) {
                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 {
@@@ -1105,10 -1149,16 +1150,16 @@@ int tts_add_text(tts_h tts, const char
        /* 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 {
@@@ -1148,10 -1198,16 +1199,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 {
@@@ -1275,10 -1331,16 +1332,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 {
@@@ -1321,10 -1383,16 +1384,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 {
@@@ -1437,10 -1505,16 +1506,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 {
@@@ -1483,10 -1557,16 +1558,16 @@@ static void __tts_pause_async(void *dat
  
        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 {
@@@ -1601,10 -1681,16 +1682,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 {
@@@ -1671,10 -1757,16 +1758,16 @@@ int tts_set_private_data(tts_h tts, con
  
        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 {
@@@ -1726,10 -1818,16 +1819,16 @@@ int tts_get_private_data(tts_h tts, con
  
        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 {
@@@ -2372,10 -2470,16 +2471,16 @@@ int tts_add_pcm(tts_h tts, int event, c
  
        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 {
@@@ -2429,10 -2533,16 +2534,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 {
@@@ -2496,10 -2606,16 +2607,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 {
diff --combined common/tts_defs.h
@@@ -43,10 -43,6 +43,10 @@@ extern "C" 
  #define TTS_SR_SERVER_SERVICE_OBJECT_PATH     "/org/tizen/voice/ttssrserver"
  #define TTS_SR_SERVER_SERVICE_INTERFACE               "org.tizen.voice.ttssrserver"
  
 +#define TTS_INTERRUPT_SERVER_SERVICE_NAME             "org.tizen.voice.ttsinterruptserver"
 +#define TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH      "/org/tizen/voice/ttsinterruptserver"
 +#define TTS_INTERRUPT_SERVER_SERVICE_INTERFACE                "org.tizen.voice.ttsinterruptserver"
 +
  /******************************************************************************************
  * Message Definition for APIs
  *******************************************************************************************/
  * Defines for configuration
  *******************************************************************************************/
  
 -#define TTS_CONFIG_BASE                       tzplatform_mkpath(TZ_USER_HOME, "/share/.voice")
 -#define TTS_CONFIG                    tzplatform_mkpath(TZ_USER_HOME, "/share/.voice/tts-config.xml")
 -#define TTS_DEFAULT_CONFIG            tzplatform_mkpath(TZ_SYS_RO_SHARE, "/voice/tts/1.0/tts-config.xml")
 +#define TTS_CONFIG_BASE                       tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "/share/.voice")
 +#define TTS_CONFIG                    tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "/share/.voice/tts-config.xml")
 +#define TTS_DEFAULT_CONFIG            tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "/voice/tts/1.0/tts-config.xml")
  
 -#define TTS_DEFAULT_ENGINE            tzplatform_mkpath(TZ_SYS_RO_SHARE, "/voice/tts/1.0/engine")
 -#define TTS_DEFAULT_ENGINE_INFO               tzplatform_mkpath(TZ_SYS_RO_SHARE, "/voice/tts/1.0/engine-info")
 -#define TTS_DEFAULT_ENGINE_SETTING    tzplatform_mkpath(TZ_SYS_RO_SHARE, "/voice/tts/1.0/engine-setting")
 +#define TTS_DEFAULT_ENGINE            tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "/voice/tts/1.0/engine")
 +#define TTS_DEFAULT_ENGINE_INFO               tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "/voice/tts/1.0/engine-info")
 +#define TTS_DEFAULT_ENGINE_SETTING    tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "/voice/tts/1.0/engine-setting")
  
 -#define TTS_HOME                      tzplatform_mkpath(TZ_USER_HOME, "/share/.voice/tts")
 -#define TTS_DOWNLOAD_BASE             tzplatform_mkpath(TZ_USER_HOME, "/share/.voice/tts/1.0")
 -#define TTS_DOWNLOAD_ENGINE_INFO      tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts/1.0/engine-info")
 +#define TTS_HOME                      tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "/share/.voice/tts")
 +#define TTS_DOWNLOAD_BASE             tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "/share/.voice/tts/1.0")
 +#define TTS_DOWNLOAD_ENGINE_INFO      tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "share/.voice/tts/1.0/engine-info")
  
  #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
diff --combined include/tts_internal.h
@@@ -28,11 -28,6 +28,11 @@@ extern "C
  #endif
  
  /**
 + * @brief Definition for TTS interrupt mode
 + */
 +#define TTS_MODE_INTERRUPT            3
 +
 +/**
   * @brief Sets server tts.
   * @details Using this API, the application can ask server tts with a credential.
   *  The credential is a key to verify the authorization about using the engine based on server, not embeded engine.
@@@ -120,6 -115,25 +120,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