Improve high CPU share
authorKwangyoun Kim <ky85.kim@samsung.com>
Thu, 21 Feb 2013 09:59:43 +0000 (18:59 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Thu, 21 Feb 2013 09:59:43 +0000 (18:59 +0900)
Change-Id: If540f078c105c0833cec537ff9384b7532d633cd

changelog
common/tts_defs.h
server/ttsd_data.h
server/ttsd_dbus.c
server/ttsd_dbus.h
server/ttsd_dbus_server.c
server/ttsd_dbus_server.h
server/ttsd_server.c
server/ttsd_server.h

index 5038cbc..dfbfb49 100755 (executable)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
+tts (0.1.1-52)
+
+  * Improve high CPU share
+
+ -- Kwangyoun Kim <ky85.kim@samsung.com>  Thu, 21 Feb 2013
+
 tts (0.1.1-51)
 
   * Update smack rule
index 32eb0a2..2396dc1 100755 (executable)
@@ -82,6 +82,12 @@ 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"
 
+/******************************************************************************************
+* Message Definition for tts-daemon internal
+*******************************************************************************************/
+
+#define TTSD_SIGNAL_NEXT_SYNTHESIS     "ttsd_signal_start_synthesis"
+
 #ifdef __cplusplus
 }
 #endif
index 83539ff..7cb4be9 100755 (executable)
 #ifndef __TTSD_DATA_H_
 #define __TTSD_DATA_H_
 
-//#include <vector>
 #include "ttsp.h"
 
-//using namespace std;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
index 3e98f97..62bbb95 100755 (executable)
@@ -26,6 +26,7 @@ static DBusConnection* g_conn;
 static int g_waiting_time = 3000;
 
 static char *g_service_name;
+static char *g_service_object;
 static char *g_service_interface;
 
 int ttsdc_send_hello(int pid, int uid)
@@ -221,6 +222,10 @@ 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);
 
+       /* daemon internal event*/
+       else if (dbus_message_is_signal(msg, g_service_interface, TTSD_SIGNAL_NEXT_SYNTHESIS)) 
+               ttsd_dbus_server_start_next_synthesis();
+
        /* setting event */
        else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_HELLO))
                ttsd_dbus_server_hello(conn, msg);
@@ -268,7 +273,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        return ECORE_CALLBACK_RENEW;
 }
 
-int ttsd_dbus_open_connection(ttsd_mode_e mode)
+int ttsd_dbus_open_connection()
 {
        DBusError err;
        dbus_error_init(&err);
@@ -290,21 +295,27 @@ int ttsd_dbus_open_connection(ttsd_mode_e mode)
 
        if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
                g_service_name = (char*)malloc(sizeof(char) * strlen(TTS_SR_SERVER_SERVICE_NAME) + 1);
+               g_service_object = (char*)malloc(sizeof(char) * strlen(TTS_SR_SERVER_SERVICE_OBJECT_PATH) + 1);
                g_service_interface = (char*)malloc(sizeof(char) * strlen(TTS_SR_SERVER_SERVICE_INTERFACE) + 1);
 
                strcpy(g_service_name, TTS_SR_SERVER_SERVICE_NAME);
+               strcpy(g_service_object, TTS_SR_SERVER_SERVICE_OBJECT_PATH);
                strcpy(g_service_interface, TTS_SR_SERVER_SERVICE_INTERFACE);
        } else if (TTSD_MODE_NOTIFICATION == ttsd_get_mode()) {
                g_service_name = (char*)malloc(sizeof(char) * strlen(TTS_NOTI_SERVER_SERVICE_NAME) + 1);
+               g_service_object = (char*)malloc(sizeof(char) * strlen(TTS_NOTI_SERVER_SERVICE_OBJECT_PATH) + 1);
                g_service_interface = (char*)malloc(sizeof(char) * strlen(TTS_NOTI_SERVER_SERVICE_INTERFACE) + 1);
 
                strcpy(g_service_name, TTS_NOTI_SERVER_SERVICE_NAME);
+               strcpy(g_service_object, TTS_NOTI_SERVER_SERVICE_OBJECT_PATH);
                strcpy(g_service_interface, TTS_NOTI_SERVER_SERVICE_INTERFACE);
        } else {
                g_service_name = (char*)malloc(sizeof(char) * strlen(TTS_SERVER_SERVICE_NAME) + 1);
+               g_service_object = (char*)malloc(sizeof(char) * strlen(TTS_SERVER_SERVICE_OBJECT_PATH) + 1);
                g_service_interface = (char*)malloc(sizeof(char) * strlen(TTS_SERVER_SERVICE_INTERFACE) + 1);
 
                strcpy(g_service_name, TTS_SERVER_SERVICE_NAME);
+               strcpy(g_service_object, TTS_SERVER_SERVICE_OBJECT_PATH);
                strcpy(g_service_interface, TTS_SERVER_SERVICE_INTERFACE);
        }
 
@@ -368,6 +379,9 @@ int ttsd_dbus_close_connection()
        if (NULL != g_service_name)
                free(g_service_name);
 
+       if (NULL != g_service_object)
+               free(g_service_object);
+
        if (NULL != g_service_interface)
                free(g_service_interface);
 
@@ -375,3 +389,28 @@ int ttsd_dbus_close_connection()
 
        return 0;
 }
+
+int ttsd_send_start_next_synthesis()
+{
+       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'"); 
+               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;
+       }
+
+       dbus_connection_flush(g_conn);
+       dbus_message_unref(msg);
+
+       return 0;
+}
index a87af79..30b4ab2 100755 (executable)
@@ -34,6 +34,8 @@ 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);
 
+int ttsd_send_start_next_synthesis();
+
 #ifdef __cplusplus
 }
 #endif
index 611ab29..2681f27 100755 (executable)
@@ -506,6 +506,13 @@ int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg)
        return 0;
 }
 
+/*
+* Dbus Server functions for tts daemon internal
+*/ 
+int ttsd_dbus_server_start_next_synthesis()
+{
+       return ttsd_server_start_next_synthesis();
+}
 
 /*
 * Dbus Setting-Daemon Server
index c47c628..aa627cf 100755 (executable)
@@ -43,6 +43,10 @@ int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg);
 
 int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg);
 
+/*
+* Dbus Server functions for tts daemon internal
+*/ 
+int ttsd_dbus_server_start_next_synthesis();
 
 /*
 * Dbus Server functions for Setting
index 6bb8512..4575d12 100755 (executable)
@@ -117,7 +117,7 @@ int __server_start_synthesis(int uid, int mode)
                                /* 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();
+                                       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);
 
@@ -221,6 +221,7 @@ int __server_next_synthesis(int uid)
                        __server_set_is_synthesizing(false);
 
                        __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);
 
@@ -261,6 +262,7 @@ int __player_result_callback(player_event_e event, int uid, int utt_id)
        case PLAYER_ERROR:
                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:
@@ -280,23 +282,6 @@ int __player_result_callback(player_event_e event, int uid, int utt_id)
        return 0;
 }
 
-Eina_Bool __start_next_synthesis(void *data)
-{
-       /* get current play */
-       int uid = ttsd_data_is_current_playing();
-
-       if (uid < 0) {
-               return EINA_FALSE;
-       }
-
-       if (true == __server_get_is_next_synthesis()) {
-               __server_set_is_next_synthesis(false);
-               __server_next_synthesis(uid);
-       }
-
-       return EINA_TRUE;       
-}
-
 int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
 {
        SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK START");
@@ -364,15 +349,11 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns
                        __server_set_is_synthesizing(false);
                        __server_set_is_next_synthesis(true);
                }
-       } 
-       
-       else if (event == TTSP_RESULT_EVENT_CANCEL) {
+       } 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);
-       } 
-       
-       else {
+       } else {
                SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event ERROR");
                __server_set_is_synthesizing(false);
                __server_set_is_next_synthesis(true);
@@ -386,6 +367,14 @@ 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 (true == __server_get_is_next_synthesis()) {
+               __server_set_is_next_synthesis(false);
+
+               /* Do NOT work ecore timer because of This function is thread callbacked */ 
+               /* need to send dbus message event */
+               ttsd_send_start_next_synthesis();
+       }
+
        return 0;
 }
 
@@ -404,7 +393,6 @@ bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
        return true;
 }
 
-
 void __config_lang_changed_cb(const char* language, int type)
 {
        char* out_lang;
@@ -697,8 +685,6 @@ int ttsd_server_play(int uid)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       ecore_timer_add(0, __start_next_synthesis, NULL);
-
        return TTSD_ERROR_NONE;
 }
 
@@ -801,6 +787,21 @@ int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
        return TTSD_ERROR_NONE;
 }
 
+/*
+* Server API for Internal event
+*/
+
+int ttsd_server_start_next_synthesis()
+{
+       /* get current play */
+       int uid = ttsd_data_is_current_playing();
+
+       if (uid < 0) {
+               return 0;
+       }
+
+       return __server_next_synthesis(uid);
+}
 
 /*
 * TTS Server Functions for Setting                                                                                                               *
@@ -909,6 +910,8 @@ int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
        /* send interrupt message to  all clients */
        ttsd_data_foreach_clients(__get_client_cb, NULL);
 
+       ttsd_engine_cancel_synthesis();
+
        /* set engine */
        int ret = 0;
        ret = ttsd_engine_setting_set_engine(engine_id);
@@ -1049,5 +1052,3 @@ int ttsd_server_setting_set_default_speed(int uid, int default_speed)
 
        return TTSD_ERROR_NONE;
 }
-
-
index 76a9d95..8eac9b9 100755 (executable)
@@ -54,6 +54,11 @@ int ttsd_server_stop(int uid);
 int ttsd_server_pause(int uid, int* utt_id);
 
 /*
+* Server API for internal event
+*/
+int ttsd_server_start_next_synthesis();
+
+/*
 * Server API for setting
 */