From: sooyeon Date: Wed, 3 Nov 2021 15:40:57 +0000 (+0900) Subject: Unify TTSD processes into two processes (default, interrupt) X-Git-Tag: submit/tizen_6.5/20211112.081028~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F82%2F265982%2F6;p=platform%2Fcore%2Fuifw%2Ftts.git Unify TTSD processes into two processes (default, interrupt) - To reduce RAM usage, unifying 3 TTSD processes (default, sr, noti) is necessary. - (server) Add a variable 'mode' into 'app_data_s' in ttsd_data. This is used when ttsd_player checks the current playing_info's mode. - (client) Make only Default mode TTSD process launched, when client's mode is default/sr/noti. Change-Id: Iba8c4ff99dd8d5b035c2804148a1b5b0803c4a27 Signed-off-by: sooyeon --- diff --git a/client/tts_core.c b/client/tts_core.c index 92b3579c..3ed28a40 100644 --- a/client/tts_core.c +++ b/client/tts_core.c @@ -64,12 +64,12 @@ static char* __get_engine_appid(int mode) { return NULL; } - if (TTS_MODE_DEFAULT == mode) { + if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) { snprintf(appid, 256, "%s", g_engine_name); - } else if (TTS_MODE_NOTIFICATION == mode) { - snprintf(appid, 256, "%s-noti", g_engine_name); - } else if (TTS_MODE_SCREEN_READER == mode) { - snprintf(appid, 256, "%s-sr", g_engine_name); +// } else if (TTS_MODE_NOTIFICATION == mode) { +// snprintf(appid, 256, "%s-noti", g_engine_name); +// } else if (TTS_MODE_SCREEN_READER == mode) { +// snprintf(appid, 256, "%s-sr", g_engine_name); } else if (TTS_MODE_INTERRUPT == mode) { snprintf(appid, 256, "%s-interrupt", g_engine_name); } else { diff --git a/client/tts_dbus.c b/client/tts_dbus.c index ac4655b6..8519d29c 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -46,12 +46,12 @@ static int __tts_dbus_add_match(int uid) } tts_mode_e mode = tts_client_get_mode(client); - if (TTS_MODE_DEFAULT == mode) { + if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_NOTIFICATION == mode) { - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_SCREEN_READER == mode) { - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); +// } else if (TTS_MODE_NOTIFICATION == mode) { +// snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); +// } else if (TTS_MODE_SCREEN_READER == mode) { +// snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); } else if (TTS_MODE_INTERRUPT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE); } @@ -81,12 +81,12 @@ static int __tts_dbus_remove_match(int mode) /* remove a rule for daemon error */ char rule_err[256] = {0, }; - if (TTS_MODE_DEFAULT == mode) { + if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_NOTIFICATION == mode) { - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_SCREEN_READER == mode) { - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); +// } else if (TTS_MODE_NOTIFICATION == mode) { +// snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); +// } else if (TTS_MODE_SCREEN_READER == mode) { +// snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); } else if (TTS_MODE_INTERRUPT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE); } @@ -152,6 +152,11 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle __tts_dbus_add_match(uid); } tts_core_receive_hello(uid, ret, credential_needed); + + tts_client_s* client = tts_client_get_by_uid(uid); + if (client) { + tts_dbus_request_set_mode(uid, tts_client_get_mode(client)); + } } SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -434,13 +439,13 @@ DBusMessage* __tts_dbus_make_message(int uid, const char* method) DBusMessage* msg; tts_mode_e mode = tts_client_get_mode(client); - if (TTS_MODE_DEFAULT == mode) { + if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) { msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, TTS_SERVER_SERVICE_OBJECT_PATH, TTS_SERVER_SERVICE_INTERFACE, method); - } else if (TTS_MODE_NOTIFICATION == mode) { +/* } else if (TTS_MODE_NOTIFICATION == mode) { msg = dbus_message_new_method_call( TTS_NOTI_SERVER_SERVICE_NAME, TTS_NOTI_SERVER_SERVICE_OBJECT_PATH, @@ -452,7 +457,7 @@ DBusMessage* __tts_dbus_make_message(int uid, const char* method) TTS_SR_SERVER_SERVICE_OBJECT_PATH, TTS_SR_SERVER_SERVICE_INTERFACE, method); - } else if (TTS_MODE_INTERRUPT == mode) { +*/ } else if (TTS_MODE_INTERRUPT == mode) { msg = dbus_message_new_method_call( TTS_INTERRUPT_SERVER_SERVICE_NAME, TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH, @@ -608,12 +613,12 @@ int tts_dbus_request_initialize(int uid, bool* credential_needed) } tts_mode_e mode = tts_client_get_mode(client); - if (TTS_MODE_DEFAULT == mode) { + if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_NOTIFICATION == mode) { - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_SCREEN_READER == mode) { - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); +// } else if (TTS_MODE_NOTIFICATION == mode) { +// snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); +// } else if (TTS_MODE_SCREEN_READER == mode) { +// snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); } else if (TTS_MODE_INTERRUPT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE); } @@ -653,12 +658,12 @@ int tts_dbus_request_finalize(int uid) /* remove a rule for daemon error */ tts_mode_e mode = tts_client_get_mode(client); SLOG(LOG_INFO, TAG_TTSC, "[INFO] Remove match, mode(%d)", mode); - if (TTS_MODE_DEFAULT == mode) { + if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) { __tts_dbus_remove_match(TTS_MODE_DEFAULT); - } else if (TTS_MODE_NOTIFICATION == mode) { - __tts_dbus_remove_match(TTS_MODE_NOTIFICATION); - } else if (TTS_MODE_SCREEN_READER == mode) { - __tts_dbus_remove_match(TTS_MODE_SCREEN_READER); +// } else if (TTS_MODE_NOTIFICATION == mode) { +// __tts_dbus_remove_match(TTS_MODE_NOTIFICATION); +// } else if (TTS_MODE_SCREEN_READER == mode) { +// __tts_dbus_remove_match(TTS_MODE_SCREEN_READER); } else if (TTS_MODE_INTERRUPT == mode) { __tts_dbus_remove_match(TTS_MODE_INTERRUPT); } @@ -714,6 +719,67 @@ int tts_dbus_request_finalize(int uid) return result; } +int tts_dbus_request_set_mode(int uid, tts_mode_e mode) +{ + DBusMessage* msg; + DBusError err; + dbus_error_init(&err); + + msg = __tts_dbus_make_message(uid, TTS_METHOD_SET_MODE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts set mode : Fail to make message"); + return TTS_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts set mode : uid(%d), mode(%d)", uid, mode); + } + + if (true != dbus_message_append_args(msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_INT32, &mode, + DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); + + return TTS_ERROR_OPERATION_FAILED; + } + + DBusMessage* result_msg; + int result = TTS_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, WAITING_TIME, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts set mode : Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = TTS_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts set mode : result(%d)", result); + } else { + SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts set mode : result(%d)", result); + } + } else { + SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + tts_dbus_reconnect(); + result = TTS_ERROR_TIMED_OUT; + } + + return result; +} + int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential) { if (NULL == text || NULL == lang) { diff --git a/client/tts_dbus.h b/client/tts_dbus.h index 6842fc3a..8c444955 100644 --- a/client/tts_dbus.h +++ b/client/tts_dbus.h @@ -35,7 +35,7 @@ int tts_dbus_request_initialize(int uid, bool* credential_needed); int tts_dbus_request_finalize(int uid); -int tts_dbus_set_sound_type(int uid, int type); +int tts_dbus_request_set_mode(int uid, tts_mode_e mode); int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential); diff --git a/client/tts_tidl.c b/client/tts_tidl.c index 0c99d388..969ab390 100644 --- a/client/tts_tidl.c +++ b/client/tts_tidl.c @@ -161,7 +161,7 @@ static void __on_connected(rpc_port_proxy_tts_h h, void *user_data) info->connected = true; info->connection_requesting = false; info->register_callback_invoked = false; - if (0 != rpc_port_proxy_tts_invoke_set_mode(info->rpc_h, tts_client_get_mode(client))) { + if (0 != rpc_port_proxy_tts_invoke_set_mode(info->rpc_h, uid, tts_client_get_mode(client))) { SLOG(LOG_ERROR, TAG_TTSC, "Failed to set mode"); return; } @@ -231,11 +231,7 @@ static void __get_engine_app_id(int mode, int size, char* app_id) } char* mode_str = ""; - if (TTS_MODE_NOTIFICATION == mode) { - mode_str = TTS_NOTI_SERVER_MODE; - } else if (TTS_MODE_SCREEN_READER == mode) { - mode_str = TTS_SR_SERVER_MODE; - } else if (TTS_MODE_INTERRUPT == mode) { + if (TTS_MODE_INTERRUPT == mode) { mode_str = TTS_INTERRUPT_SERVER_MODE; } diff --git a/common/tts_defs.h b/common/tts_defs.h index 385bad84..80c6a407 100644 --- a/common/tts_defs.h +++ b/common/tts_defs.h @@ -39,12 +39,12 @@ extern "C" { #define TTS_NOTI_SERVER_SERVICE_NAME "org.tizen.voice.ttsnotiserver" #define TTS_NOTI_SERVER_SERVICE_OBJECT_PATH "/org/tizen/voice/ttsnotiserver" #define TTS_NOTI_SERVER_SERVICE_INTERFACE "org.tizen.voice.ttsnotiserver" -#define TTS_NOTI_SERVER_MODE "-noti" +//#define TTS_NOTI_SERVER_MODE "-noti" #define TTS_SR_SERVER_SERVICE_NAME "org.tizen.voice.ttssrserver" #define TTS_SR_SERVER_SERVICE_OBJECT_PATH "/org/tizen/voice/ttssrserver" #define TTS_SR_SERVER_SERVICE_INTERFACE "org.tizen.voice.ttssrserver" -#define TTS_SR_SERVER_MODE "-sr" +//#define TTS_SR_SERVER_MODE "-sr" #define TTS_INTERRUPT_SERVER_SERVICE_NAME "org.tizen.voice.ttsinterruptserver" #define TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH "/org/tizen/voice/ttsinterruptserver" @@ -65,6 +65,7 @@ extern "C" { #define TTS_METHOD_HELLO_SYNC "tts_method_hello_sync" #define TTS_METHOD_INITIALIZE "tts_method_initialize" #define TTS_METHOD_FINALIZE "tts_method_finalilze" +#define TTS_METHOD_SET_MODE "tts_method_set_mode" #define TTS_METHOD_GET_SUPPORT_VOICES "tts_method_get_support_voices" #define TTS_METHOD_GET_CURRENT_VOICE "tts_method_get_current_voice" #define TTS_METHOD_ADD_QUEUE "tts_method_add_queue" diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 94604fac..70393bc7 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -16,7 +16,6 @@ #include #include -#include "ttsd_main.h" #include "ttsd_data.h" using namespace std; @@ -33,6 +32,7 @@ typedef struct int uid; int utt_id_stopped; app_tts_state_e state; + ttsd_mode_e mode; std::list m_speak_data; std::list m_wav_data; @@ -162,6 +162,7 @@ int ttsd_data_new_client(int pid, int uid) app.uid = uid; app.utt_id_stopped = 0; app.state = APP_STATE_READY; + app.mode = TTSD_MODE_DEFAULT; app.ipc_method = TTS_IPC_METHOD_UNDEFINED; g_app_list.push_back(app); @@ -319,6 +320,32 @@ tts_ipc_method_e ttsd_data_get_ipc_method(int uid) return app_data->ipc_method; } +int ttsd_data_set_mode(int uid, ttsd_mode_e mode) +{ + lock_guard lock(g_app_data_mutex); + app_data_s* app_data = __get_client_app_data(uid); + if (nullptr == app_data) { + SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); + return TTSD_ERROR_INVALID_PARAMETER; + } + + app_data->mode = mode; + + return TTSD_ERROR_NONE; +} + +ttsd_mode_e ttsd_data_get_mode(int uid) +{ + lock_guard lock(g_app_data_mutex); + app_data_s* app_data = __get_client_app_data(uid); + if (nullptr == app_data) { + SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); + return TTSD_MODE_DEFAULT; + } + + return app_data->mode; +} + int ttsd_data_get_speak_data_size(int uid) { lock_guard lock(g_app_data_mutex); diff --git a/server/ttsd_data.h b/server/ttsd_data.h index cdc38610..069333cb 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -18,6 +18,7 @@ #include "ttse.h" #include "ttsd_stub.h" #include "tts_ipc_method.h" +#include "ttsd_main.h" #ifdef __cplusplus extern "C" { @@ -76,6 +77,10 @@ int ttsd_data_set_ipc_method(int uid, tts_ipc_method_e method); tts_ipc_method_e ttsd_data_get_ipc_method(int uid); +int ttsd_data_set_mode(int uid, ttsd_mode_e mode); + +ttsd_mode_e ttsd_data_get_mode(int uid); + /* speak data */ int ttsd_data_add_speak_data(int uid, speak_data_s* data); diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index 9395d141..972735d5 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -227,6 +227,9 @@ 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_FINALIZE)) { ttsd_dbus_server_finalize(g_conn_listener, msg); + } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_SET_MODE)) { + ttsd_dbus_server_set_mode(g_conn_listener, msg); + } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SUPPORT_VOICES)) { ttsd_dbus_server_get_support_voices(g_conn_listener, msg); diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index c0adacf7..f6814dc4 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -190,6 +190,62 @@ int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg) return 0; } +int ttsd_dbus_server_set_mode(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int uid; + int tmp_mode; + ttsd_mode_e mode; + int ret = 0; + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_INT32, &tmp_mode, + DBUS_TYPE_INVALID); + + mode = (ttsd_mode_e)tmp_mode; + SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS set mode"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message); + dbus_error_free(&err); + ret = TTSD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, tts_tag(), "[IN] tts set mode. uid(%d), mode(%d)", uid, mode); + ret = ttsd_server_set_mode(uid, mode); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts set mode : (%d)", ret); + } else { + SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts set mode : (%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to send reply"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message"); + } + + SLOG(LOG_DEBUG, tts_tag(), "<<<<<"); + SLOG(LOG_DEBUG, tts_tag(), ""); + + return 0; +} + int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg) { DBusError err; diff --git a/server/ttsd_dbus_server.h b/server/ttsd_dbus_server.h index ec6dce1a..dad43c0e 100644 --- a/server/ttsd_dbus_server.h +++ b/server/ttsd_dbus_server.h @@ -33,6 +33,8 @@ int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg); int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg); +int ttsd_dbus_server_set_mode(DBusConnection* conn, DBusMessage* msg); + int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg); int ttsd_dbus_server_get_current_voice(DBusConnection* conn, DBusMessage* msg); diff --git a/server/ttsd_player.c b/server/ttsd_player.c index cd506eb8..76a8c8b8 100644 --- a/server/ttsd_player.c +++ b/server/ttsd_player.c @@ -191,11 +191,13 @@ static void __player_focus_state_cb(sound_stream_info_h stream_info, sound_strea return; } - switch (ttsd_get_mode()) { + int uid = g_playing_info->uid; + ttsd_mode_e mode = ttsd_data_get_mode(uid); + + switch (mode) { case TTSD_MODE_DEFAULT: - SLOG(LOG_DEBUG, tts_tag(), "[Player] Pause current player - mode(%d)", ttsd_get_mode()); + SLOG(LOG_DEBUG, tts_tag(), "[Player] Pause current player - mode(%d)", mode); g_audio_state = AUDIO_STATE_READY; - int uid = g_playing_info->uid; if (0 != ttsd_player_pause(uid)) { SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player"); @@ -214,15 +216,15 @@ static void __player_focus_state_cb(sound_stream_info_h stream_info, sound_strea break; case TTSD_MODE_NOTIFICATION: case TTSD_MODE_SCREEN_READER: - SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop current player - mode(%d)", ttsd_get_mode()); + SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop current player - mode(%d)", mode); g_audio_state = AUDIO_STATE_READY; ttsd_send_all_stop(); break; case TTSD_MODE_INTERRUPT: - SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus release - mode(%d)", ttsd_get_mode()); + SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus release - mode(%d)", mode); break; default: - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid mode - mode(%d)", ttsd_get_mode()); + SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid mode - mode(%d)", mode); break; } @@ -378,7 +380,7 @@ static void __del_timer_for_delayed_recover(void* data) } } -static void __set_policy_for_playing(int volume) +static void __set_policy_for_playing(void) { ecore_main_loop_thread_safe_call_async(__del_timer_for_delayed_recover, NULL); @@ -552,7 +554,7 @@ static void __play_thread(void *data, Ecore_Thread *thread) int idx = 0; /* set volume policy as 40% */ - __set_policy_for_playing(40); + __set_policy_for_playing(); while (1) { // 1st while(1) pthread_mutex_lock(&g_play_thread_mutex); /* check g_playing_info one more time */ @@ -679,7 +681,7 @@ static void __play_thread(void *data, Ecore_Thread *thread) if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) { /* set volume policy as 40%, when resume play thread*/ - __set_policy_for_playing(40); + __set_policy_for_playing(); } /* resume play thread */ @@ -766,7 +768,7 @@ static void __play_thread(void *data, Ecore_Thread *thread) } SLOG(LOG_INFO, tts_tag(), "[Player INFO] Success to destroy and recreate audio out"); - __set_policy_for_playing(40); + __set_policy_for_playing(); } while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) { @@ -782,7 +784,7 @@ static void __play_thread(void *data, Ecore_Thread *thread) // Check whether set_policy is done or not if (false == g_is_set_policy) { SLOG(LOG_INFO, tts_tag(), "[Player INFO] Set policy"); - __set_policy_for_playing(40); + __set_policy_for_playing(); } if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) { diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 21c3808f..c13273b0 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -450,7 +450,7 @@ Eina_Bool ttsd_terminate_daemon(void *data) void __screen_reader_changed_cb(bool value) { - if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) { +/* if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) { SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon"); if (g_terminate_timer) { ecore_timer_del(g_terminate_timer); @@ -458,8 +458,9 @@ void __screen_reader_changed_cb(bool value) } g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL); } else { +*/ SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF"); - } +// } return; } @@ -524,9 +525,9 @@ int ttsd_initialize(ttse_request_callback_s *callback) ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); - if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) { +// if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) { ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb); - } +// } g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL); if (NULL == g_check_client_timer) { @@ -827,6 +828,29 @@ int ttsd_server_finalize(int uid) return TTSD_ERROR_NONE; } +int ttsd_server_set_mode(int uid, ttsd_mode_e mode) +{ + app_tts_state_e state; + if (0 > ttsd_data_get_client_state(uid, &state)) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid); + return TTSD_ERROR_INVALID_PARAMETER; + } + + if (APP_STATE_READY != state) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid); + return TTSD_ERROR_INVALID_STATE; + } + + int ret = ttsd_data_set_mode(uid, mode); + if (0 != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set mode : ret(%d)", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Server] Set mode. uid(%d), mode(%d)", uid, mode); + } + + return ret; +} + int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential) { app_tts_state_e state; @@ -940,7 +964,8 @@ Eina_Bool __send_interrupt_client(void *data) return EINA_FALSE; } - if (TTSD_MODE_DEFAULT != ttsd_get_mode()) { + ttsd_mode_e mode = ttsd_data_get_mode(uid); + if (TTSD_MODE_DEFAULT != mode) { /* send message to client about changing state */ ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY); } else { @@ -982,7 +1007,7 @@ int ttsd_server_play(int uid, const char* credential) SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid); if (uid != current_uid && -1 != current_uid) { - if (TTSD_MODE_DEFAULT != ttsd_get_mode()) { + if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) { /* Send interrupt message */ SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid); @@ -1245,7 +1270,7 @@ int ttsd_server_play_pcm(int uid) SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid); if (uid != current_uid && -1 != current_uid) { - if (TTSD_MODE_DEFAULT != ttsd_get_mode()) { + if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) { /* Send interrupt message */ SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid); diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 4b3b771d..f2251b21 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -55,6 +55,8 @@ int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* cred int ttsd_server_finalize(int uid); +int ttsd_server_set_mode(int uid, ttsd_mode_e mode); + int ttsd_server_get_support_voices(int uid, GList** voice_list); int ttsd_server_get_current_voice(int uid, char** language, int* voice_type); diff --git a/server/ttsd_tidl.c b/server/ttsd_tidl.c index e11797b4..f73cefd4 100644 --- a/server/ttsd_tidl.c +++ b/server/ttsd_tidl.c @@ -234,10 +234,17 @@ static int __register_cb_sync(rpc_port_stub_tts_context_h context, int pid, int return TTSE_ERROR_NONE; } -static int __set_mode_cb(rpc_port_stub_tts_context_h context, int mode, void* user_data) +static int __set_mode_cb(rpc_port_stub_tts_context_h context, int uid, int mode, void* user_data) { //ttsd_set_mode(mode); - SLOG(LOG_INFO, tts_tag(), "[Server] TTSD MODE : (%d)", ttsd_get_mode()); + SLOG(LOG_INFO, tts_tag(), "[Server] Set client mode. uid (%d), mode (%d)", uid, mode); + + int ret = -1; + ret = ttsd_data_set_mode(uid, mode); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Server] Fail to set mode. uid is not invalid"); + return ret; + } return TTSE_ERROR_NONE; } diff --git a/tidl/tts.tidl b/tidl/tts.tidl index 9b0bb195..38fcf577 100644 --- a/tidl/tts.tidl +++ b/tidl/tts.tidl @@ -3,7 +3,7 @@ interface tts { void register_cb(int pid, int uid, notify_cb callback) async; int register_cb_sync(int pid, int uid, notify_cb callback); - int set_mode(int mode); + int set_mode(in int uid, in int mode); int initialize(in int pid, in int uid, out bool credential_needed); int finalize(in int uid); int add_text(int uid, string text, string lang, int vctype, int speed, int uttid, string credential);