From: Kwangyoun Kim Date: Wed, 20 Mar 2013 09:08:40 +0000 (+0900) Subject: Fix bug on resume tts and add code for file message(IPC) X-Git-Tag: submit/tizen_2.1/20130424.234321~9^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af3c28bef954884542e62e4db31e06016a2f0e64;p=platform%2Fcore%2Fuifw%2Ftts.git Fix bug on resume tts and add code for file message(IPC) Change-Id: I7e4e3d6c0c33f74dece0c26b58b2be5ccdfa1e3f --- diff --git a/changelog b/changelog old mode 100755 new mode 100644 index dfbfb49d..0cbfdc12 --- a/changelog +++ b/changelog @@ -1,3 +1,32 @@ +tts (0.1.56) -- Wed, 20 Mar 2013 + + * Release version (Dongyeol Lee ) + +tts (0.1.55-2) -- Wed, 20 Mar 2013 + + * Fix bug not to resume tts in 'pause' state (Dongyeol Lee ) + +tts (0.1.55-1) -- Wed, 20 Mar 2013 + + * File message(IPC) is applied (Kwangyoun Kim ) + * Fix prevent issue (Kwangyoun Kim ) + +tts (0.1.1-54) + + * Fix code for synthesis by dbus + + -- Kwangyoun Kim Mon, 4 Mar 2013 + +tts (0.1.1-53) + + * Update smack rule + + -- Kwangyoun Kim Wed, 27 Feb 2013 + tts (0.1.1-52) * Improve high CPU share diff --git a/client/tts.c b/client/tts.c index 6d1bbddb..0a0f5e97 100755 --- a/client/tts.c +++ b/client/tts.c @@ -22,7 +22,7 @@ #include "tts_client.h" #include "tts_dbus.h" -#define MAX_TEXT_COUNT 1000 +#define MAX_TEXT_COUNT 2000 static bool g_is_daemon_started = false; @@ -111,8 +111,9 @@ int tts_destroy(tts_h tts) case TTS_STATE_READY: /* Request Finalize */ ret = tts_dbus_request_finalize(client->uid); - if (0 != ret) - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request finalize"); + if (0 != ret) { + SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to request finalize"); + } if (TTS_MODE_SCREEN_READER == client->mode) g_is_sr_daemon_started = false; @@ -121,6 +122,19 @@ int tts_destroy(tts_h tts) else g_is_daemon_started = false; + client->before_state = client->current_state; + client->current_state = TTS_STATE_CREATED; + + ecore_timer_add(0, __tts_notify_state_changed, (void*)tts); + + /* Close file message connection */ + if (0 == tts_client_get_connected_client_count()) { + SLOG(LOG_DEBUG, TAG_TTSC, "Close file msg connection"); + ret = tts_file_msg_close_connection(); + if (0 != ret) + SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to close file message connection"); + } + case TTS_STATE_CREATED: if (NULL != g_connect_timer) { SLOG(LOG_DEBUG, TAG_TTSC, "Connect Timer is deleted"); @@ -279,6 +293,16 @@ static Eina_Bool __tts_connect_daemon(void *data) /* success to connect tts-daemon */ } + if (0 == tts_client_get_connected_client_count()) { + SLOG(LOG_DEBUG, TAG_TTSC, "Open file msg connection"); + ret = tts_file_msg_open_connection(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open file message connection"); + ecore_timer_add(0, __tts_notify_error, (void*)client->tts); + return EINA_FALSE; + } + } + client->before_state = client->current_state; client->current_state = TTS_STATE_READY; @@ -343,8 +367,10 @@ int tts_unprepare(tts_h tts) SLOG(LOG_DEBUG, TAG_TTSC, " "); return TTS_ERROR_INVALID_STATE; } + + int ret; - int ret = tts_dbus_request_finalize(client->uid); + ret = tts_dbus_request_finalize(client->uid); if (0 != ret) { SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to request finalize"); } @@ -356,12 +382,19 @@ int tts_unprepare(tts_h tts) else g_is_daemon_started = false; - client->before_state = client->current_state; client->current_state = TTS_STATE_CREATED; ecore_timer_add(0, __tts_notify_state_changed, (void*)tts); + /* Close file message connection */ + if (0 == tts_client_get_connected_client_count()) { + SLOG(LOG_DEBUG, TAG_TTSC, "Close file msg connection"); + ret = tts_file_msg_close_connection(); + if (0 != ret) + SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to close file message connection"); + } + SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); diff --git a/client/tts_client.c b/client/tts_client.c index 501bfbff..574e0955 100755 --- a/client/tts_client.c +++ b/client/tts_client.c @@ -193,4 +193,27 @@ int tts_client_not_use_callback(tts_client_s* client) int tts_client_get_use_callback(tts_client_s* client) { return client->cb_ref_count; +} + +int tts_client_get_connected_client_count() +{ + GList *iter = NULL; + tts_client_s *data = NULL; + int number = 0; + + if (g_list_length(g_client_list) > 0) { + /* Get a first item */ + iter = g_list_first(g_client_list); + + while (NULL != iter) { + data = iter->data; + if (0 < data->current_state) { + number++; + } + + /* Next item */ + iter = g_list_next(iter); + } + } + return number; } \ No newline at end of file diff --git a/client/tts_client.h b/client/tts_client.h index e8eb89a3..17909774 100755 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -69,6 +69,8 @@ int tts_client_not_use_callback(tts_client_s* client); int tts_client_get_use_callback(tts_client_s* client); +int tts_client_get_connected_client_count(); + #ifdef __cplusplus } #endif diff --git a/client/tts_dbus.c b/client/tts_dbus.c index 7f5eca1d..eb5690ef 100755 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -13,6 +13,8 @@ #include +#include + #include "tts_main.h" #include "tts_dbus.h" #include "tts_defs.h" @@ -21,10 +23,15 @@ #define INIT_WAITING_TIME 5000 #define WAITING_TIME 1000 +#define BUFFER_SIZE 20 + static Ecore_Fd_Handler* g_fd_handler = NULL; static DBusConnection* g_conn = NULL; +static Ecore_Fd_Handler* g_fd_handler_noti = NULL; +static int g_fd_noti; +static int g_wd_noti; extern int __tts_cb_error(int uid, tts_error_e reason, int utt_id); @@ -100,6 +107,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_DEBUG, TAG_TTSC, " "); } /* TTSD_METHOD_HELLO */ +#if 0 else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_UTTERANCE_STARTED)) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Get utterance started"); int uid, uttid; @@ -160,6 +168,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); } /* TTSD_METHOD_SET_STATE */ +#endif else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_ERROR)) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Get error callback"); @@ -192,7 +201,6 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle return ECORE_CALLBACK_PASS_ON; } - int tts_dbus_open_connection() { if (NULL != g_conn) { @@ -295,7 +303,7 @@ int tts_dbus_close_connection() int tts_dbus_reconnect() { bool connected = dbus_connection_get_is_connected(g_conn); - SLOG(LOG_DEBUG, "[DBUS] %s\n", connected ? "Connected" : "Not connected"); + SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] %s\n", connected ? "Connected" : "Not connected"); if (false == connected) { tts_dbus_close_connection(); @@ -682,7 +690,6 @@ int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e* return result; } - int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid) { if (NULL == text || NULL == lang) { @@ -940,3 +947,130 @@ int tts_dbus_request_pause(int uid) return result; } + + +static Eina_Bool inotify_event_callback(void* data, Ecore_Fd_Handler *fd_handler) +{ + SLOG(LOG_DEBUG, TAG_TTSC, "===== [File message] Inotify event call"); + + int length; + + char buffer[sizeof(struct inotify_event) * BUFFER_SIZE]; + + length = read(g_fd_noti, buffer, (sizeof(struct inotify_event) * BUFFER_SIZE)); + if (0 > length) { + SLOG(LOG_ERROR, TAG_TTSC, "[File message] Empty Inotify event"); + SLOG(LOG_DEBUG, TAG_TTSC, "====="); + SLOG(LOG_DEBUG, TAG_TTSC, " "); + return ECORE_CALLBACK_RENEW; + } + + bool is_empty_file = true; + + char filename[64]; + memset(filename, 0, 64); + snprintf(filename, 64, "%s_%d", MESSAGE_FILE_PATH, getpid()); + FILE *fp; + + int i = 0; + while (i < length) { + char text[256]; + char msg[256]; + int uid, send_data; + + struct inotify_event *event = (struct inotify_event *)&buffer[i]; + i = i + sizeof(struct inotify_event) + event->len; + + if (IN_CLOSE_WRITE == event->mask) { + + fp = fopen(filename, "r"); + if (NULL == fp) { + SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] open file failed"); + SLOG(LOG_DEBUG, TAG_TTSC, "====="); + SLOG(LOG_DEBUG, TAG_TTSC, " "); + return ECORE_CALLBACK_RENEW; + } + + while (NULL != fgets(text, 256, fp)) { + if (0 > sscanf(text, "%s %d %d", msg, &uid, &send_data)) { + SLOG(LOG_ERROR, TAG_TTSC, "[File message] sscanf failed"); + continue; + } + SLOG(LOG_DEBUG, TAG_TTSC, "[File message] message - %s, uid - %d, send_data - %d", msg, uid, send_data); + is_empty_file = false; + + int uttid; + if (!strcmp(TTSD_METHOD_UTTERANCE_STARTED, msg)) { + uttid = send_data; + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance started message : uid(%d), uttid(%d) \n", uid, uttid); + __tts_cb_utt_started(uid, uttid); + } else if (!strcmp(TTSD_METHOD_UTTERANCE_COMPLETED, msg)) { + uttid = send_data; + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance completed message : uid(%d), uttid(%d) \n", uid, uttid); + __tts_cb_utt_completed(uid, uttid); + + } else if (!strcmp(TTSD_METHOD_SET_STATE, msg)) { + int state = send_data; + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get state change : uid(%d) , state(%d)", uid, state); + __tts_cb_set_state(uid, state); + } + } + fclose(fp); + } else { + SLOG(LOG_ERROR, TAG_TTSC, "[File message] Undefined event"); + } + } + + if (true == is_empty_file) + return ECORE_CALLBACK_PASS_ON; + + fp = fopen(filename, "w+"); + if (NULL == fp) { + SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] open file failed"); + } else { + fclose(fp); + } + + SLOG(LOG_DEBUG, TAG_TTSC, "====="); + SLOG(LOG_DEBUG, TAG_TTSC, " "); + + return ECORE_CALLBACK_PASS_ON; +} + +int tts_file_msg_open_connection() +{ + /* get file notification handler */ + int fd; + int wd; + + fd = inotify_init(); + if (fd < 0) { + SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] Fail get inotify_fd"); + return -1; + } + g_fd_noti = fd; + + int pid = getpid(); + char path[64]; + memset(path, 0, 64); + snprintf(path, 64, "%s_%d", MESSAGE_FILE_PATH, pid); + + wd = inotify_add_watch(fd, path, IN_CLOSE_WRITE); + g_wd_noti = wd; + g_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)inotify_event_callback, NULL, NULL, NULL); + if (NULL == g_fd_handler_noti) { + SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] Fail to get handler_noti"); + return -1; + } + return 0; +} + +int tts_file_msg_close_connection() +{ + /* del inotify variable */ + ecore_main_fd_handler_del(g_fd_handler_noti); + inotify_rm_watch(g_fd_noti, g_wd_noti); + close(g_fd_noti); + + return 0; +} \ No newline at end of file diff --git a/client/tts_dbus.h b/client/tts_dbus.h index 9993bc2b..3636e8f3 100755 --- a/client/tts_dbus.h +++ b/client/tts_dbus.h @@ -46,6 +46,11 @@ int tts_dbus_request_stop(int uid); int tts_dbus_request_pause(int uid); + +int tts_file_msg_open_connection(); + +int tts_file_msg_close_connection(); + #ifdef __cplusplus } #endif diff --git a/common/tts_defs.h b/common/tts_defs.h index 2396dc1d..6f65a1c5 100755 --- a/common/tts_defs.h +++ b/common/tts_defs.h @@ -63,6 +63,8 @@ extern "C" { #define TTSD_METHOD_ERROR "ttsd_method_error" #define TTSD_METHOD_SET_STATE "ttsd_method_set_state" #define TTSD_METHOD_GET_STATE "ttsd_method_get_state" + +#define MESSAGE_FILE_PATH "/opt/home/app/.voice/tts" /****************************************************************************************** * Message Definition for Setting @@ -82,11 +84,13 @@ extern "C" { #define TTS_SETTING_METHOD_GET_ENGINE_SETTING "tts_setting_method_get_engine_setting" #define TTS_SETTING_METHOD_SET_ENGINE_SETTING "tts_setting_method_set_engine_setting" +#if 0 /****************************************************************************************** * Message Definition for tts-daemon internal *******************************************************************************************/ #define TTSD_SIGNAL_NEXT_SYNTHESIS "ttsd_signal_start_synthesis" +#endif #ifdef __cplusplus } diff --git a/packaging/tts.spec b/packaging/tts.spec index e917be93..e642a8d0 100755 --- a/packaging/tts.spec +++ b/packaging/tts.spec @@ -1,6 +1,6 @@ Name: tts Summary: Text To Speech client library and daemon -Version: 0.1.1 +Version: 0.1.56 Release: 1 Group: libs License: Samsung diff --git a/server/ttsd_config.c b/server/ttsd_config.c index c51f4d99..dcda3176 100755 --- a/server/ttsd_config.c +++ b/server/ttsd_config.c @@ -215,7 +215,7 @@ int ttsd_config_initialize(ttsd_config_lang_changed_cb callback) __ttsd_config_load(); /* Register system language changed callback */ - int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, __system_language_changed_cb, NULL); + int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, __system_language_changed_cb, NULL); if (0 != ret) { SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to register callback : %d", ret); return TTSD_ERROR_OPERATION_FAILED; @@ -246,15 +246,19 @@ int ttsd_config_update_language() SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret); return -1; } else { - SLOG(LOG_DEBUG, get_tag(), "[Config] System language : %s", value); + if (NULL == value) { + SLOG(LOG_ERROR, get_tag(), "[Config] Fail to get system language"); + return -1; + } else { + SLOG(LOG_DEBUG, get_tag(), "[Config] System language : %s", value); + + if (0 != strcmp(value, g_language)) { + if (NULL != g_callback) + g_callback(value, g_vc_type); + } - if (0 != strcmp(value, g_language)) { - if (NULL != g_callback) - g_callback(value, g_vc_type); - } - - if (NULL != value) free(value); + } } } @@ -334,14 +338,26 @@ int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, con if (TTSD_MODE_NOTIFICATION == ttsd_get_mode()) { err_file = (char*)malloc(strlen(CONFIG_DIRECTORY) + strlen(NOTI_ERROR_FILE_NAME) + 1); + if (NULL == err_file) { + SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to get error file name"); + return -1; + } strcpy(err_file, CONFIG_DIRECTORY); strcat(err_file, NOTI_ERROR_FILE_NAME); } else if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) { err_file = (char*)malloc(strlen(CONFIG_DIRECTORY) + strlen(SR_ERROR_FILE_NAME) + 1); + if (NULL == err_file) { + SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to get error file name"); + return -1; + } strcpy(err_file, CONFIG_DIRECTORY); strcat(err_file, SR_ERROR_FILE_NAME); } else { err_file = (char*)malloc(strlen(CONFIG_DIRECTORY) + strlen(DEFAULT_ERROR_FILE_NAME) + 1); + if (NULL == err_file) { + SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to get error file name"); + return -1; + } strcpy(err_file, CONFIG_DIRECTORY); strcat(err_file, DEFAULT_ERROR_FILE_NAME); } @@ -350,6 +366,7 @@ int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, con err_fp = fopen(err_file, "w+"); if (NULL == err_fp) { SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to open error file (%s)", err_file); + free(err_file); return -1; } SLOG(LOG_DEBUG, get_tag(), "Save Error File (%s)", err_file); @@ -400,6 +417,8 @@ int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, con /* get data */ ttsd_data_save_error_log(uid, err_fp); + free(err_file); + fclose(err_fp); return 0; diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 88191ddf..7979d982 100755 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -576,4 +576,18 @@ int ttsd_data_save_error_log(int uid, FILE* fp) fprintf(fp, "---------------------"); return 0; +} + +int ttsd_data_get_same_pid_client_count(int pid) +{ + int vsize = g_app_list.size(); + int number = 0; + + for (int i=0; i>>> Fail to make message for 'start next synthesis'"); + return -1; + } + + if (!dbus_connection_send(g_conn, msg, NULL)) { + SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] >>>> Fail to send message for 'start next synthesis'"); + return -1; + } + + SLOG(LOG_DEBUG, get_tag(), "[Dbus] >>>> Send message for 'start next synthesis'"); + + dbus_connection_flush(g_conn); + dbus_message_unref(msg); + + return 0; +} +#endif static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { @@ -221,10 +287,11 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PAUSE)) ttsd_dbus_server_pause(conn, msg); - +#if 0 /* daemon internal event*/ else if (dbus_message_is_signal(msg, g_service_interface, TTSD_SIGNAL_NEXT_SYNTHESIS)) ttsd_dbus_server_start_next_synthesis(); +#endif /* setting event */ else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_HELLO)) @@ -390,27 +457,35 @@ int ttsd_dbus_close_connection() return 0; } -int ttsd_send_start_next_synthesis() +int ttsd_file_msg_open_connection(int pid) { - DBusMessage* msg; - - msg = dbus_message_new_signal( - g_service_object, /* object name of the signal */ - g_service_interface, /* interface name of the signal */ - TTSD_SIGNAL_NEXT_SYNTHESIS); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] >>>> Fail to make message for 'start next synthesis'"); + /* Make file for Inotify */ + char send_filename[64]; + memset(send_filename, 0, 64); + snprintf(send_filename, 64, "%s_%d", MESSAGE_FILE_PATH, pid); + + FILE* fp; + fp = fopen(send_filename, "a+"); + if (NULL == fp) { + SLOG(LOG_ERROR, get_tag(), "[File message ERROR] Fail to make message file"); return -1; } + SLOG(LOG_DEBUG, get_tag(), "[File message] Make message file"); + fclose(fp); + return 0; +} - if (!dbus_connection_send(g_conn, msg, NULL)) { - SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] >>>> Fail to send message for 'start next synthesis'"); - return -1; +int ttsd_file_msg_close_connection(int pid) +{ + /* delete inotify file */ + char path[64]; + memset(path, 0, 64); + snprintf(path, 64, "%s_%d", MESSAGE_FILE_PATH, pid); + if (0 == access(path, R_OK)) { + if (0 != remove(path)) { + SLOG(LOG_WARN, get_tag(), "[File message WARN] Fail to remove message file"); + } } - - dbus_connection_flush(g_conn); - dbus_message_unref(msg); - + SLOG(LOG_DEBUG, get_tag(), "[File message] Delete message file"); return 0; } diff --git a/server/ttsd_dbus.h b/server/ttsd_dbus.h index 30b4ab2f..2862afd6 100755 --- a/server/ttsd_dbus.h +++ b/server/ttsd_dbus.h @@ -23,6 +23,9 @@ int ttsd_dbus_open_connection(); int ttsd_dbus_close_connection(); +int ttsd_file_msg_open_connection(int pid); + +int ttsd_file_msg_close_connection(int pid); int ttsdc_send_hello(int pid, int uid); @@ -34,7 +37,9 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason); int ttsdc_send_set_state_message(int pid, int uid, int state); +#if 0 int ttsd_send_start_next_synthesis(); +#endif #ifdef __cplusplus } diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index 2681f275..1662200d 100755 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -119,6 +119,7 @@ int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg) } else { SLOG(LOG_DEBUG, get_tag(), "[IN] tts finalize : uid(%d) \n", uid); + ret = ttsd_server_finalize(uid); } @@ -506,6 +507,7 @@ int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg) return 0; } +#if 0 /* * Dbus Server functions for tts daemon internal */ @@ -513,6 +515,7 @@ int ttsd_dbus_server_start_next_synthesis() { return ttsd_server_start_next_synthesis(); } +#endif /* * Dbus Setting-Daemon Server diff --git a/server/ttsd_dbus_server.h b/server/ttsd_dbus_server.h index aa627cf5..d1e2affb 100755 --- a/server/ttsd_dbus_server.h +++ b/server/ttsd_dbus_server.h @@ -43,10 +43,12 @@ int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg); int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg); +#if 0 /* * Dbus Server functions for tts daemon internal */ int ttsd_dbus_server_start_next_synthesis(); +#endif /* * Dbus Server functions for Setting diff --git a/server/ttsd_engine_agent.c b/server/ttsd_engine_agent.c index e873ba11..2afe31b7 100755 --- a/server/ttsd_engine_agent.c +++ b/server/ttsd_engine_agent.c @@ -933,7 +933,10 @@ int ttsd_engine_agent_set_default_voice(const char* language, ttsp_voice_type_e g_cur_engine.default_lang, g_cur_engine.default_vctype); } else { SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to write default voice to config (%d)", ret); + return TTSD_ERROR_OPERATION_FAILED; } + + return 0; } /****************************************************************************************** diff --git a/server/ttsd_main_noti.c b/server/ttsd_main_noti.c index 523ec2ea..9186ee06 100755 --- a/server/ttsd_main_noti.c +++ b/server/ttsd_main_noti.c @@ -47,7 +47,7 @@ int main() SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to initialize tts-daemon-noti"); return EXIT_FAILURE; } - + if (0 != ttsd_dbus_open_connection()) { printf("Fail to initialize IPC connection \n"); SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to open dbus connection"); diff --git a/server/ttsd_main_sr.c b/server/ttsd_main_sr.c index 0add23dd..3442e606 100755 --- a/server/ttsd_main_sr.c +++ b/server/ttsd_main_sr.c @@ -46,7 +46,7 @@ int main() SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to initialize tts-daemon-sr"); return EXIT_FAILURE; } - + if (0 != ttsd_dbus_open_connection()) { printf("Fail to initialize IPC connection \n"); SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to open dbus connection"); diff --git a/server/ttsd_player.c b/server/ttsd_player.c old mode 100755 new mode 100644 index 6caaa423..dcd3cbb1 --- a/server/ttsd_player.c +++ b/server/ttsd_player.c @@ -95,7 +95,7 @@ static int g_paused_uid; player_s* __player_get_item(int uid); -int __save_file(const int uid, const int index, const sound_data_s data, char** filename); +int __save_file(int uid, int index, sound_data_s data, char** filename); int __set_and_start(player_s* player); @@ -147,7 +147,7 @@ int ttsd_player_release(void) return 0; } -int ttsd_player_create_instance(const int uid) +int ttsd_player_create_instance(int uid) { if (false == g_player_init) { SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" ); @@ -183,7 +183,6 @@ int ttsd_player_create_instance(const int uid) return 0; } - int ttsd_player_destroy_instance(int uid) { if (false == g_player_init) { @@ -262,7 +261,7 @@ int ttsd_player_destroy_instance(int uid) return 0; } -int ttsd_player_play(const int uid) +int ttsd_player_play(int uid) { SLOG(LOG_DEBUG, get_tag(), "[Player] start play : uid(%d)", uid ); @@ -401,7 +400,7 @@ int ttsd_player_next_play(int uid) } -int ttsd_player_stop(const int uid) +int ttsd_player_stop(int uid) { SLOG(LOG_DEBUG, get_tag(), "[Player] stop player : uid(%d)", uid ); @@ -459,7 +458,7 @@ int ttsd_player_stop(const int uid) return 0; } -int ttsd_player_pause(const int uid) +int ttsd_player_pause(int uid) { SLOG(LOG_DEBUG, get_tag(), "[Player] pause player : uid(%d)", uid ); @@ -505,7 +504,7 @@ int ttsd_player_pause(const int uid) return 0; } -int ttsd_player_resume(const int uid) +int ttsd_player_resume(int uid) { SLOG(LOG_DEBUG, get_tag(), "[Player] Resume player : uid(%d)", uid ); @@ -564,6 +563,49 @@ int ttsd_player_resume(const int uid) return 0; } +int ttsd_player_get_state(int uid, ttsd_player_state_e* state) +{ + if (false == g_player_init) { + SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" ); + return -1; + } + + player_s* current; + current = __player_get_item(uid); + if (NULL == current) { + SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); + return -1; + } + + MMPlayerStateType player_state; + mm_player_get_state(current->player_handle, &player_state); + + SLOG(LOG_DEBUG, get_tag(), "[PLAYER] State changed : state(%d)", player_state); + + int ret = -1; + /* destroy player */ + switch (player_state) { + case MM_PLAYER_STATE_PLAYING: + *state = TTSD_PLAYER_STATE_PLAYING; + break; + case MM_PLAYER_STATE_PAUSED: + *state = TTSD_PLAYER_STATE_PAUSED; + break; + + case MM_PLAYER_STATE_NULL: + *state = TTSD_PLAYER_STATE_NULL; + break; + + case MM_PLAYER_STATE_READY: + default: + SLOG(LOG_ERROR, get_tag(), "[Player ERROR] player state of uid(%d) is not valid", uid); + return -1; + break; + } + + return 0; +} + int ttsd_player_get_current_client() { if (false == g_player_init) { @@ -579,7 +621,7 @@ int ttsd_player_get_current_client() return 0; } -int ttsd_player_get_current_utterance_id(const int uid) +int ttsd_player_get_current_utterance_id(int uid) { SLOG(LOG_DEBUG, get_tag(), "[Player] get current utt id : uid(%d)", uid ); @@ -838,7 +880,7 @@ player_s* __player_get_item(int uid) return NULL; } -int __save_file(const int uid, const int index, const sound_data_s data, char** filename) +int __save_file(int uid, int index, sound_data_s data, char** filename) { char postfix[5]; memset(postfix, '\0', 5); @@ -1024,12 +1066,12 @@ int __set_and_start(player_s* player) return -1; } - //if (TTSD_MODE_DEFAULT != ttsd_get_mode()) { - // ret = mm_player_ignore_session(player->player_handle); - // if (MM_ERROR_NONE != ret) { - // SLOG(LOG_WARN, get_tag(), "[Player WARNING] fail mm_player_ignore_session() : %x", ret); - // } - //} + if (TTSD_MODE_DEFAULT != ttsd_get_mode()) { + ret = mm_player_ignore_session(player->player_handle); + if (MM_ERROR_NONE != ret) { + SLOG(LOG_WARN, get_tag(), "[Player WARNING] fail mm_player_ignore_session() : %x", ret); + } + } /* realize and start mm player */ ret = mm_player_realize(player->player_handle); diff --git a/server/ttsd_player.h b/server/ttsd_player.h old mode 100755 new mode 100644 index 9a37340b..cc8d2f1d --- a/server/ttsd_player.h +++ b/server/ttsd_player.h @@ -25,6 +25,12 @@ typedef enum { PLAYER_ERROR }player_event_e; +typedef enum { + TTSD_PLAYER_STATE_NULL, + TTSD_PLAYER_STATE_PAUSED, + TTSD_PLAYER_STATE_PLAYING +}ttsd_player_state_e; + typedef int (*player_result_callback_func)(player_event_e event, int uid, int utt_id); /* @@ -35,23 +41,25 @@ int ttsd_player_init(player_result_callback_func result_cb); int ttsd_player_release(void); -int ttsd_player_create_instance(const int uid); +int ttsd_player_create_instance(int uid); -int ttsd_player_destroy_instance(const int uid); +int ttsd_player_destroy_instance(int uid); -int ttsd_player_play(const int uid); +int ttsd_player_play(int uid); int ttsd_player_next_play(int uid); -int ttsd_player_stop(const int uid); +int ttsd_player_stop(int uid); + +int ttsd_player_pause(int uid); -int ttsd_player_pause(const int uid); +int ttsd_player_resume(int uid); -int ttsd_player_resume(const int uid); +int ttsd_player_get_state(int uid, ttsd_player_state_e* state); int ttsd_player_get_current_client(); -int ttsd_player_get_current_utterance_id(const int uid); +int ttsd_player_get_current_utterance_id(int uid); int ttsd_player_all_stop(); diff --git a/server/ttsd_server.c b/server/ttsd_server.c old mode 100755 new mode 100644 index 4575d12e..10dc01ee --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -23,45 +23,38 @@ #include "ttsd_config.h" #include "ttsd_network.h" +typedef enum { + TTSD_SYNTHESIS_CONTROL_DOING = 0, + TTSD_SYNTHESIS_CONTROL_DONE = 1, + TTSD_SYNTHESIS_CONTROL_EXPIRED = 2 +}ttsd_synthesis_control_e; typedef struct { int uid; int uttid; -} utterance_t; +}utterance_t; /* If current engine exist */ static bool g_is_engine; /* If engine is running */ -static bool g_is_synthesizing; +static ttsd_synthesis_control_e g_synth_control; -/* If the daemon get the result */ -static bool g_is_next_synthesis = false; +static Ecore_Timer* g_wait_timer = NULL; /* Function definitions */ int __server_next_synthesis(int uid); -int __server_set_is_synthesizing(bool flag) +int __server_set_synth_control(ttsd_synthesis_control_e control) { - g_is_synthesizing = flag; + g_synth_control = control; return 0; } -bool __server_get_is_synthesizing() +ttsd_synthesis_control_e __server_get_synth_control() { - return g_is_synthesizing; -} - -int __server_set_is_next_synthesis(bool flag) -{ - g_is_next_synthesis = flag; - return 0; -} - -bool __server_get_is_next_synthesis() -{ - return g_is_next_synthesis; + return g_synth_control; } int __server_send_error(int uid, int utt_id, int error_code) @@ -76,124 +69,32 @@ int __server_send_error(int uid, int utt_id, int error_code) return 0; } -int __server_start_synthesis(int uid, int mode) +Eina_Bool __wait_synthesis(void *data) { - int result = 0; - - /* check if tts-engine is running */ - if (true == __server_get_is_synthesizing()) { - SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running "); - } else { - speak_data_s sdata; - if (0 == ttsd_data_get_speak_data(uid, &sdata)) { - utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t)); - - if (NULL == utt) { - SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Out of memory : utterance "); - return TTSD_ERROR_OUT_OF_MEMORY; - } - - utt->uid = uid; - utt->uttid = sdata.utt_id; - - SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------"); - SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid ); - SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed); - SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text); - SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------"); - - __server_set_is_synthesizing(true); - int ret = 0; - ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt); - if (0 != ret) { - SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__); - - __server_set_is_synthesizing(false); - - result = TTSD_ERROR_OPERATION_FAILED; - - g_free(utt); - - /* mode 2 : Add text in playing state */ - if (2 == mode) { - __server_send_error(uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED); - ttsd_config_save_error(utt->uid, utt->uttid, sdata.lang, sdata.vctype, sdata.text, __FUNCTION__, __LINE__, "fail to start synthesis (mode=2)"); - - ttsd_server_stop(uid); - - int pid = ttsd_data_get_pid(uid); - ttsdc_send_set_state_message(pid, uid, APP_STATE_READY); - } - } else { - SLOG(LOG_DEBUG, get_tag(), "[Server] SUCCESS to start synthesis"); - } - - if(sdata.text != NULL) - g_free(sdata.text); + /* get current play */ + int uid = ttsd_data_is_current_playing(); + if (uid > 0) { + if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { + return EINA_TRUE; } else { - SLOG(LOG_DEBUG, get_tag(), "[Server] Text List is EMPTY!! "); - } - } - - return result; -} - -int __server_play_internal(int uid, app_state_e state) -{ - /* precondition */ - /* - uid is valid */ - /* - input uid is current play */ - - int ret = 0; - - if (APP_STATE_PAUSED == state) { - SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid); - - /* resume player and start speech synthesis */ - if (0 != ttsd_player_resume(uid)) { - SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()"); - } - - /* mode 1 for play */ - ret = __server_start_synthesis(uid, 1); - - } else if(APP_STATE_READY == state) { - SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Ready' state : Next step is start synthesis ", uid); - - /* mode 1 for play */ - ret = __server_start_synthesis(uid, 1); + g_wait_timer = NULL; + if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) { + /* Start next synthesis */ + __server_next_synthesis(uid); + } + } } else { - /* NO this case */ + g_wait_timer = NULL; } - return ret; + return EINA_FALSE; } -int __server_next_synthesis(int uid) +int __synthesis(int uid) { - SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START"); - - /* get current playing client */ - int current_uid = ttsd_data_get_current_playing(); - - if (0 > current_uid) { - SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid"); - SLOG(LOG_DEBUG, get_tag(), "====="); - SLOG(LOG_DEBUG, get_tag(), " "); - return 0; - } - - if (true == __server_get_is_synthesizing()) { - SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. "); - SLOG(LOG_DEBUG, get_tag(), "====="); - SLOG(LOG_DEBUG, get_tag(), " "); - return 0; - } - - /* synthesize next text */ speak_data_s sdata; - if (0 == ttsd_data_get_speak_data(current_uid, &sdata)) { + if (0 == ttsd_data_get_speak_data(uid, &sdata)) { utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t)); @@ -202,7 +103,7 @@ int __server_next_synthesis(int uid) return TTSD_ERROR_OUT_OF_MEMORY; } - utt->uid = current_uid; + utt->uid = uid; utt->uttid = sdata.utt_id; SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------"); @@ -211,24 +112,24 @@ int __server_next_synthesis(int uid) SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text); SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------"); - __server_set_is_synthesizing(true); - int ret = 0; + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING); ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt); if (0 != ret) { SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__); - __server_set_is_synthesizing(false); + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); - __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED); ttsd_config_save_error(utt->uid, utt->uttid, sdata.lang, sdata.vctype, sdata.text, __FUNCTION__, __LINE__, "fail to start synthesis"); g_free(utt); - ttsd_server_stop(current_uid); + ttsd_server_stop(uid); - int pid = ttsd_data_get_pid(current_uid); - ttsdc_send_set_state_message(pid, current_uid, APP_STATE_READY); + int pid = ttsd_data_get_pid(uid); + ttsdc_send_set_state_message(pid, uid, APP_STATE_READY); + } else { + g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL); } if(sdata.text != NULL) @@ -239,8 +140,34 @@ int __server_next_synthesis(int uid) SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------"); } + return 0; +} + +int __server_next_synthesis(int uid) +{ + SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START"); + + /* get current playing client */ + int current_uid = ttsd_data_get_current_playing(); + + if (0 > current_uid) { + SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid"); + SLOG(LOG_DEBUG, get_tag(), "====="); + SLOG(LOG_DEBUG, get_tag(), " "); + return 0; + } + + if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { + SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. "); + SLOG(LOG_DEBUG, get_tag(), "====="); + SLOG(LOG_DEBUG, get_tag(), " "); + return 0; + } + + __synthesis(current_uid); + if (0 != ttsd_player_play(current_uid)) { - SLOG(LOG_WARN, get_tag(), "[Server WARNING] __server_next_synthesis : fail ttsd_player_play() "); + SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() "); } else { /* success playing */ SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player"); @@ -263,11 +190,10 @@ int __player_result_callback(player_event_e event, int uid, int utt_id) SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR][%s] player result error", __FUNCTION__); __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED); ttsd_config_save_error(uid, utt_id, NULL, -1, NULL, __FUNCTION__, __LINE__, "PLAYER_ERROR"); - // break; case PLAYER_EMPTY_SOUND_QUEUE: /* check whether synthesis is running */ - if (false == __server_get_is_synthesizing()) { + if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) { /* check text queue is empty */ if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) { SLOG(LOG_DEBUG, get_tag(), "[SERVER Callback] all play completed "); @@ -346,17 +272,14 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns } if (event == TTSP_RESULT_EVENT_FINISH) { - __server_set_is_synthesizing(false); - __server_set_is_next_synthesis(true); + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); } } else if (event == TTSP_RESULT_EVENT_CANCEL) { SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL"); - __server_set_is_synthesizing(false); - __server_set_is_next_synthesis(true); + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); } else { - SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event ERROR"); - __server_set_is_synthesizing(false); - __server_set_is_next_synthesis(true); + SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_ERROR"); + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); } if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) { @@ -367,6 +290,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK END"); SLOG(LOG_DEBUG, get_tag(), " "); +#if 0 if (true == __server_get_is_next_synthesis()) { __server_set_is_next_synthesis(false); @@ -374,6 +298,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns /* need to send dbus message event */ ttsd_send_start_next_synthesis(); } +#endif return 0; } @@ -400,7 +325,7 @@ void __config_lang_changed_cb(const char* language, int type) int ret = -1; if (true == ttsd_engine_select_valid_voice(language, type, &out_lang, &out_type)) { - SLOG(LOG_ERROR, get_tag(), "[Server] vaild language : lang(%s), type(%d)", out_lang, out_type); + SLOG(LOG_ERROR, get_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type); ret = ttsd_engine_setting_set_default_voice(out_lang, out_type); if (0 != ret) SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type); @@ -412,7 +337,7 @@ void __config_lang_changed_cb(const char* language, int type) if (true == ttsd_engine_select_valid_voice("en_US", type, &out_lang, &out_type)) { ret = ttsd_engine_setting_set_default_voice(out_lang, out_type); if (0 != ret) - SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type); + SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type); if (NULL == out_lang) free(out_lang); @@ -424,7 +349,7 @@ void __config_lang_changed_cb(const char* language, int type) /* -* Daemon init +* Server APIs */ int ttsd_initialize() @@ -452,6 +377,8 @@ int ttsd_initialize() } else g_is_engine = true; + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); + return TTSD_ERROR_NONE; } @@ -520,11 +447,18 @@ int ttsd_server_initialize(int pid, int uid) SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine "); return TTSD_ERROR_OPERATION_FAILED; } - /* Check system language */ ttsd_config_update_language(); } + if (0 == ttsd_data_get_same_pid_client_count(pid)) { + SLOG(LOG_DEBUG, get_tag(), "[Server] open file msg connection"); + if (0 != ttsd_file_msg_open_connection(pid)) { + SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to open file message connection"); + return TTSD_ERROR_OPERATION_FAILED; + } + } + if (0 != ttsd_data_new_client(pid, uid)) { SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info "); return TTSD_ERROR_OPERATION_FAILED; @@ -557,8 +491,15 @@ int ttsd_server_finalize(int uid) ttsd_player_destroy_instance(uid); + int pid = ttsd_data_get_pid(uid); + ttsd_data_delete_client(uid); + if (0 == ttsd_data_get_same_pid_client_count(pid)) { + SLOG(LOG_DEBUG, get_tag(), "[Sever] File msg close connection"); + ttsd_file_msg_close_connection(pid); + } + /* unload engine, if ref count of client is 0 */ if (0 == ttsd_data_get_client_count()) { ecore_timer_add(0, __quit_ecore_loop, NULL); @@ -611,10 +552,11 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice } } - /* mode 2 for add text */ - if (0 != __server_start_synthesis(uid, 2)) { - SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to schedule synthesis : uid(%d)", uid); - return TTSD_ERROR_OPERATION_FAILED; + /* Check whether tts-engine is running or not */ + if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { + SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running."); + } else { + __synthesis(uid); } } @@ -680,9 +622,41 @@ int ttsd_server_play(int uid) return TTSD_ERROR_OPERATION_FAILED; } - if (0 != __server_play_internal(uid, state)) { - SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to start synthesis : uid(%d)", uid); - return TTSD_ERROR_OPERATION_FAILED; + if (APP_STATE_PAUSED == state) { + SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid); + + ttsd_player_state_e state; + if (0 != ttsd_player_get_state(uid, &state)) { + SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get player state : uid(%d)", uid); + return TTSD_ERROR_OPERATION_FAILED; + } + + if (TTSD_PLAYER_STATE_PAUSED == state) { + /* Resume player */ + if (0 != ttsd_player_resume(uid)) { + SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()"); + } + } else if (TTSD_PLAYER_STATE_NULL == state) { + if (0 != ttsd_player_play(uid)) { + SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() "); + + /* Need to wait synthesis */ + if (NULL == g_wait_timer) + g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL); + } else { + /* success playing */ + SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player"); + } + } else { + /* error */ + } + } + + /* Check whether tts-engine is running or not */ + if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { + SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running."); + } else { + __synthesis(uid); } return TTSD_ERROR_NONE; @@ -706,16 +680,21 @@ int ttsd_server_stop(int uid) if (0 != ttsd_player_stop(uid)) SLOG(LOG_WARN, get_tag(), "[Server] Fail to ttsd_player_stop()"); - if (true == __server_get_is_synthesizing()) { + if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running "); int ret = 0; ret = ttsd_engine_cancel_synthesis(); if (0 != ret) SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret); + } - __server_set_is_synthesizing(false); - } + if (NULL != g_wait_timer) { + SLOG(LOG_DEBUG, get_tag(), "Wait timer is deleted"); + ecore_timer_del(g_wait_timer); + } + + __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); } else { SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is 'ready' "); } @@ -787,10 +766,10 @@ int ttsd_server_get_current_voice(int uid, char** language, int* voice_type) return TTSD_ERROR_NONE; } +#if 0 /* * Server API for Internal event */ - int ttsd_server_start_next_synthesis() { /* get current play */ @@ -802,6 +781,7 @@ int ttsd_server_start_next_synthesis() return __server_next_synthesis(uid); } +#endif /* * TTS Server Functions for Setting * diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 8eac9b94..52216687 100755 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -23,10 +23,8 @@ extern "C" { #endif /** -* Daemon init +* Server APIs */ - -/** Daemon initialize */ int ttsd_initialize(); int ttsd_finalize(); @@ -53,10 +51,12 @@ int ttsd_server_stop(int uid); int ttsd_server_pause(int uid, int* utt_id); +#if 0 /* * Server API for internal event */ int ttsd_server_start_next_synthesis(); +#endif /* * Server API for setting diff --git a/tts-server.rule b/tts-server.rule index a61eddb9..b72dfbfd 100755 --- a/tts-server.rule +++ b/tts-server.rule @@ -1,4 +1,4 @@ -tts-server system::app_logging wx +tts-server device::app_logging wx tts-server tts-engine-samsung::vdata rx tts-server system::vconf rwxat tts-server sound_server rw