#include "tts_dbus.h"
#include "tts_main.h"
+#include "tts_internal.h"
static bool g_screen_reader;
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);
client->credential = strdup(credential);
if (NULL == client->credential) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+ if (NULL != key) {
+ free(key);
+ key = NULL;
+ }
return TTS_ERROR_OUT_OF_MEMORY;
}
} else {
int pid = getpid();
char* appid = NULL;
int ret = app_manager_get_app_id(pid, &appid);
- if (0 != ret) {
+ if (0 != ret || NULL == appid) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
free(key);
key = NULL;
+ if (NULL != appid) {
+ free(appid);
+ appid = NULL;
+ }
return TTS_ERROR_OPERATION_FAILED;
}
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
free(key);
key = NULL;
+ free(appid);
+ appid = NULL;
return ret;
}
return TTS_ERROR_INVALID_STATE;
}
- client->conn_timer = ecore_timer_add(0, __tts_connect_daemon, (void*)tts);
+ client->conn_timer = ecore_timer_add(0.02, __tts_connect_daemon, (void*)tts);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
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 {
return TTS_ERROR_INVALID_STATE;
}
-// *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;
/* 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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
return TTS_ERROR_INVALID_PARAMETER;
}
- if (TTS_STATE_PLAYING != client->current_state) {
+ if (TTS_STATE_CREATED == client->current_state) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
return TTS_ERROR_INVALID_STATE;
}
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 {
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 {
return TTS_ERROR_INVALID_PARAMETER;
}
- if (TTS_STATE_PLAYING != client->current_state) {
+ if (TTS_STATE_CREATED == client->current_state) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
return TTS_ERROR_INVALID_STATE;
}
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 {