Fix to get the maximum text size from the engine meta data 11/126011/3
authorsooyeon.kim <sooyeon.kim@samsung.com>
Thu, 20 Apr 2017 00:49:47 +0000 (09:49 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Fri, 21 Apr 2017 02:00:17 +0000 (11:00 +0900)
Change-Id: Ib5e794e053133e77d68465ddd66f57a39474dbf0
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/tts.c [changed mode: 0755->0644]
common/tts_config_mgr.c
common/tts_config_mgr.h
common/tts_config_parser.c
common/tts_config_parser.h
common/tts_defs.h
engine-parser/src/tts-engine-parser.c

old mode 100755 (executable)
new mode 100644 (file)
index 1caaf58..5ca6f36
@@ -34,6 +34,8 @@ static int g_feature_enabled = -1;
 
 static bool g_err_callback_status = false;
 
+static int g_max_text_size = -1;
+
 /* Function definition */
 static Eina_Bool __tts_notify_state_changed(void *data);
 static Eina_Bool __tts_notify_error(void *data);
@@ -137,6 +139,33 @@ void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_typ
        return;
 }
 
+static Eina_Bool __reconnect_by_engine_changed(void* data)
+{
+       tts_h tts = (tts_h)data;
+
+       tts_client_s* client = tts_client_get(tts);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (TTS_STATE_READY != client->current_state) {
+               usleep(10000);
+               return EINA_TRUE;
+       }
+
+       int ret = tts_unprepare(tts);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+       }
+       ret = tts_prepare(tts);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+       }
+
+       return EINA_FALSE;
+}
+
 void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
 {
        tts_h tts = (tts_h)user_data;
@@ -160,14 +189,8 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
                if (0 != ret) {
                        SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
                }
-               ret = tts_unprepare(tts);
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
-               }
-               ret = tts_prepare(tts);
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
-               }
+
+               ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
        } else if (TTS_STATE_READY == client->current_state) {
                ret = tts_unprepare(tts);
                if (0 != ret) {
@@ -229,7 +252,7 @@ int tts_create(tts_h* tts)
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL);
+       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, client->tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_client_destroy(*tts);
@@ -866,7 +889,13 @@ int tts_get_max_text_size(tts_h tts, unsigned int* size)
                return TTS_ERROR_INVALID_STATE;
        }
 
-       *size = TTS_MAX_TEXT_SIZE;
+//     *size = TTS_MAX_TEXT_SIZE;
+       if (0 != tts_config_mgr_get_max_text_size(size)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       g_max_text_size = (int)*size;
 
        SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
        return TTS_ERROR_NONE;
@@ -1001,11 +1030,29 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                return TTS_ERROR_INVALID_STATE;
        }
 
-       if (TTS_MAX_TEXT_SIZE < strlen(text) || strlen(text) <= 0) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
-               return TTS_ERROR_INVALID_PARAMETER;
+       if (-1 == g_max_text_size) {
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
+               if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (0 == g_max_text_size) {
+               if (strlen(text) <= 0) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
+                       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+                       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
+       } else {
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
+               if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
+                       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+                       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
        }
 
        if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
@@ -1026,36 +1073,23 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        }
 
        /* check valid utf8 */
-       iconv_t *ict;
-       ict = iconv_open("utf-8", "");
-       if ((iconv_t)-1 == ict) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init for text check");
-               return TTS_ERROR_OPERATION_FAILED;
-       }
+       bool valid = false;
 
-       size_t len = strlen(text);
-       char *in_tmp = NULL;
-       char in_buf[TTS_MAX_TEXT_SIZE];
-       char *out_tmp = NULL;
-       char out_buf[TTS_MAX_TEXT_SIZE];
-       size_t len_tmp = sizeof(out_buf);
+       DBusError err;
+       dbus_error_init(&err);
 
-       memset(in_buf, 0, TTS_MAX_TEXT_SIZE);
-       snprintf(in_buf, TTS_MAX_TEXT_SIZE, "%s", text);
-       in_tmp = in_buf;
-
-       memset(out_buf, 0, TTS_MAX_TEXT_SIZE);
-       out_tmp = out_buf;
+       valid = dbus_validate_utf8(text, &err);
+       if (dbus_error_is_set(&err)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
+               dbus_error_free(&err);
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
 
-       size_t st;
-       st = iconv(ict, &in_tmp, &len, &out_tmp, &len_tmp);
-       if ((size_t)-1 == st) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", in_buf);
-               iconv_close(ict);
+       if (valid != true) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
                return TTS_ERROR_INVALID_PARAMETER;
        }
-       iconv_close(ict);
-       SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - Converted text is '%s'", out_buf);
+       SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
 
        /* change default language value */
        char* temp = NULL;
@@ -1074,7 +1108,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        int ret = -1;
        int count = 0;
        while (0 != ret) {
-               ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential);
+               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) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
index 8ad002b..fd09c2d 100644 (file)
@@ -1044,6 +1044,12 @@ int tts_config_mgr_initialize(int uid)
                        return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
                }
                temp_client->uid = uid;
+               temp_client->engine_cb = NULL;
+               temp_client->voice_cb = NULL;
+               temp_client->speech_cb = NULL;
+               temp_client->pitch_cb = NULL;
+               temp_client->screen_cb = NULL;
+               temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
 
@@ -1056,6 +1062,12 @@ int tts_config_mgr_initialize(int uid)
                        return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
                }
                temp_client->uid = uid;
+               temp_client->engine_cb = NULL;
+               temp_client->voice_cb = NULL;
+               temp_client->speech_cb = NULL;
+               temp_client->pitch_cb = NULL;
+               temp_client->screen_cb = NULL;
+               temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
        }
@@ -2029,3 +2041,48 @@ int __tts_config_mgr_print_engine_info()
 
        return 0;
 }
+
+int tts_config_mgr_get_max_text_size(unsigned int* size)
+{
+       if (0 >= g_slist_length(g_config_client_list)) {
+               SLOG(LOG_ERROR, tts_tag(), "Not initialized");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == size) {
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       GSList *iter = NULL;
+       tts_engine_info_s *engine_info = NULL;
+
+       if (0 >= g_slist_length(g_engine_list)) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
+               return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       /* Get a first item */
+       iter = g_slist_nth(g_engine_list, 0);
+
+       while (NULL != iter) {
+               engine_info = iter->data;
+
+               if (NULL == engine_info) {
+                       SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
+                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+               }
+
+               if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
+                       iter = g_slist_next(iter);
+                       continue;
+               }
+
+               break;
+       }
+
+       *size = engine_info->text_size;
+       SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Max text size is %d.", *size);
+
+       return 0;
+}
+
index c9eb1d7..dd6e2da 100644 (file)
@@ -114,6 +114,8 @@ bool tts_config_check_default_voice_is_valid(const char* language, int type);
 
 char* tts_config_get_message_path(int mode, int pid);
 
+int tts_config_mgr_get_max_text_size(unsigned int* size);
+
 
 #ifdef __cplusplus
 }
index b984103..135b392 100644 (file)
@@ -29,6 +29,7 @@
 #define TTS_TAG_ENGINE_VOICE           "voice"
 #define TTS_TAG_ENGINE_VOICE_TYPE      "type"
 #define TTS_TAG_ENGINE_PITCH_SUPPORT   "pitch-support"
+#define TTS_TAG_ENGINE_TEXT_SIZE       "text-size"
 
 #define TTS_TAG_CONFIG_BASE_TAG                "tts-config"
 #define TTS_TAG_CONFIG_ENGINE_ID       "engine"
@@ -106,6 +107,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
        temp->voices = NULL;
        temp->setting = NULL;
        temp->pitch_support = false;
+       temp->text_size = 0;
 
        while (cur != NULL) {
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
@@ -210,6 +212,15 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
                        }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               temp->text_size = atoi((char*)key);
+                               xmlFree(key);
+                       } else {
+                               SLOG(LOG_INFO, tts_tag(), "[INFO] text size is unlimited.");
+                               temp->text_size = 0;
+                       }
                }
                cur = cur->next;
        }
index 73165da..87ba839 100644 (file)
@@ -42,6 +42,7 @@ typedef struct {
        GSList* voices;
        bool    pitch_support;
        bool    need_credential;
+       unsigned int    text_size;
 } tts_engine_info_s;
 
 typedef struct {
index 6e803ac..75ad833 100644 (file)
@@ -97,7 +97,7 @@ extern "C" {
 #define TTS_PITCH_NORMAL       8
 #define TTS_PITCH_MAX          15
 
-#define TTS_MAX_TEXT_SIZE      2000
+//#define TTS_MAX_TEXT_SIZE    2000
 
 #define TTS_FEATURE_PATH       "tizen.org/feature/speech.synthesis"
 
index 8419722..fe4a4e5 100644 (file)
@@ -52,6 +52,7 @@
 #define TTS_TAG_ENGINE_VOICE_TYPE              "type"
 #define TTS_TAG_ENGINE_PITCH_SUPPORT           "pitch-support"
 #define TTS_TAG_ENGINE_CREDENTIAL              "credential"
+#define TTS_TAG_ENGINE_TEXT_SIZE               "text-size"
 
 #define TTS_CONFIG_BASE                tzplatform_mkpath(TZ_USER_HOME, "share/.voice")
 #define TTS_HOME               tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts")
@@ -67,6 +68,7 @@
 #define TTS_METADATA_LANGUAGE                  "http://tizen.org/metadata/tts-engine/language"
 #define TTS_METADATA_CREDENTIAL_REQUIRED       "http://tizen.org/metadata/tts-engine/credential-required"
 #define TTS_METADATA_SETTING           "http://tizen.org/metadata/tts-engine/setting"
+#define TTS_METADATA_TEXT_SIZE         "http://tizen.org/metadata/tts-engine/text-size"
 
 /* Define Macro */
 #define FREE(x)        { if (NULL != x)        { free(x);      x = NULL; } }
@@ -402,6 +404,10 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
                                cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
                                xmlNodeSetContent(cur, (const xmlChar*)md->value);
                                xmlAddChild(root, cur);
+                       } else if (!strcmp(md->key, TTS_METADATA_TEXT_SIZE)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
                        } else {
                                LOGW("[WARNING] Unknown metadata type");
                        }