return TTS_ERROR_OPERATION_FAILED;
}
+ tts_client_set_service_out(client, false);
tts_core_notify_state_changed(client, TTS_STATE_READY);
tts_service_state_e before_state = tts_client_get_current_service_state(client);
return TTS_ERROR_OPERATION_FAILED;
}
+ tts_client_set_service_out(client, false);
tts_core_notify_state_changed(client, TTS_STATE_READY);
tts_service_state_e before_state = tts_client_get_current_service_state(client);
client->hello_timer = NULL;
}
- int ret = -1;
+ int ret = tts_ipc_stop_listening(uid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to remove match : %s", tts_core_covert_error_code(ret));
+ }
+
+ if (tts_client_is_service_out(client)) {
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Service is already out. Do not need to finalize");
+ tts_client_set_service_out(client, false);
+ return TTS_ERROR_NONE;
+ }
+
if (false == tts_core_check_screen_reader(client)) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize. Handled by screen reader");
-
- ret = tts_ipc_stop_listening(uid);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to remove match : %s", tts_core_covert_error_code(ret));
- }
} else {
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Request finalize");
return TTS_ERROR_NONE;
}
+static void set_service_out_for_each_client(gpointer data, gpointer user_data)
+{
+ tts_client_s *client = (tts_client_s *)data;
+ if (false == tts_client_is_valid_client(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
+ return;
+ }
+
+ const tts_state_e state = tts_client_get_current_state(client);
+ if (state == TTS_STATE_INVALID || state == TTS_STATE_CREATED) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not connected yet. state(%d)", state);
+ return;
+ }
+
+ tts_client_set_service_out(client, true);
+ tts_client_set_current_state(client, TTS_STATE_READY);
+ tts_core_notify_error_async(client, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
+
+ const tts_service_state_e before_state = tts_client_get_current_service_state(client);
+ tts_core_notify_service_state_changed(client, before_state, TTS_SERVICE_STATE_BLOCKED);
+}
+
int tts_core_handle_service_reset()
{
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
GList* client_list = tts_client_get_client_list();
RETVM_IF(NULL == client_list, TTS_ERROR_OPERATION_FAILED, "[ERROR] Fail to get client list");
- if (g_list_length(client_list) > 0) {
- GList *iter = g_list_first(client_list);
- while (NULL != iter) {
- tts_client_s *client = iter->data;
- if (false == tts_client_is_valid_client(client)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
- } else {
- tts_core_notify_error_async(client, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
- }
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Set service out to all clients");
+ g_list_foreach(client_list, set_service_out_for_each_client, NULL);
+ g_list_free(client_list);
- iter = g_list_next(iter);
- }
- }
+ return TTS_ERROR_NONE;
+}
- g_list_free(client_list);
+static inline void reprepare_on_demand(tts_client_s* client)
+{
+ if (false == tts_client_is_service_out(client)) {
+ return;
+ }
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
- tts_core_reprepare();
+ const unsigned int uid = tts_client_get_uid(client);
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Client is out of service. Try to reprepare. uid(%u)", uid);
- return TTS_ERROR_NONE;
+ int ret = tts_core_prepare_sync(client);
+ if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client fails to prepare. uid(%u)", uid);
+ }
}
int tts_core_add_text(tts_client_s* client, const char* text, const char* language, int voice_type, int speed, int* utt_id)
{
RETVM_IF(NULL == text || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Parameter is invalid.");
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
tts_client_set_repeat_text(client, text);
int tts_core_play(tts_client_s* client)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
return __request_play(client);
}
int tts_core_stop(tts_client_s* client)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
int tts_core_pause(tts_client_s* client)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
{
RETVM_IF(NULL == text_repeat || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Parameter is invalid.");
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
char* repeat_text = tts_client_get_repeat_text(client);
if (NULL == repeat_text) {
int tts_core_add_pcm(tts_client_s* client, int event, const void* data, unsigned int data_size, int audio_type, int rate)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
int tts_core_play_pcm(tts_client_s* client)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
int tts_core_stop_pcm(tts_client_s* client)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
int tts_core_set_private_data(tts_client_s* client, const char* key, const char* data)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
int tts_core_get_private_data(tts_client_s* client, const char* key, char** data)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;
int tts_core_get_service_state(tts_client_s* client, tts_service_state_e* service_state)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
unsigned int uid = tts_client_get_uid(client);
int ret = -1;