Remove null check from ttse_send_error
[platform/core/uifw/tts.git] / server / ttsd_server.c
index 3c8f8d0..c00709c 100644 (file)
@@ -74,7 +74,6 @@ static Eina_Bool __wait_synthesis(void *data)
 
        if (uid > 0) {
                if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
-                       usleep(100000);
                        return EINA_TRUE;
                } else {
                        g_wait_timer = NULL;
@@ -92,7 +91,7 @@ static Eina_Bool __wait_synthesis(void *data)
 
 static int __synthesis(int uid, const char* credential)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== SYNTHESIS  START");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS  START");
 
        speak_data_s* speak_data = NULL;
        if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
@@ -150,7 +149,7 @@ static int __synthesis(int uid, const char* credential)
                        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, (void*)credential);
+                       g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
                }
 
                if (NULL != speak_data) {
@@ -165,8 +164,7 @@ static int __synthesis(int uid, const char* credential)
                }
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "===== SYNTHESIS  END");
-       SLOG(LOG_DEBUG, tts_tag(), "  ");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS  END");
 
        return 0;
 }
@@ -180,7 +178,7 @@ int ttsd_send_error(ttse_error_e error, const char* msg)
        int uttid = g_utt.uttid;
        int tmp_pid = ttsd_data_get_pid(uid);
 
-       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%d), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, msg);
+       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%d), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg));
 
        __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
 
@@ -204,7 +202,7 @@ int ttsd_send_error(ttse_error_e error, const char* msg)
 
 int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== SEND SYNTHESIS RESULT START");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
 
        int uid = g_utt.uid;
        int uttid = g_utt.uttid;
@@ -227,16 +225,14 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
                        __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
-                       SLOG(LOG_DEBUG, tts_tag(), "=====");
-                       SLOG(LOG_DEBUG, tts_tag(), "  ");
+                       SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_OPERATION_FAILED;
                }
 
                if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
                        __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
-                       SLOG(LOG_DEBUG, tts_tag(), "=====");
-                       SLOG(LOG_DEBUG, tts_tag(), "  ");
+                       SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_INVALID_PARAMETER;
                }
 
@@ -295,7 +291,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        }
 
 
-       /*SLOG(LOG_DEBUG, tts_tag(), "===== SYNTHESIS RESULT CALLBACK END");
+       /*SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS RESULT CALLBACK END");
        SLOG(LOG_DEBUG, tts_tag(), "  ");*/
 
        return TTSD_ERROR_NONE;
@@ -412,7 +408,7 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
 
 bool __terminate_client(int pid, int uid, app_state_e state, void* user_data)
 {
-       SLOG(LOG_INFO, tts_tag(), "=== Start to terminate client [%d] ===", uid);
+       SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
        ttsd_server_finalize(uid);
        return true;
 }
@@ -639,7 +635,7 @@ bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_d
 
 Eina_Bool ttsd_cleanup_client(void *data)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== CLEAN UP CLIENT START");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
        __read_proc();
 
        if (0 < ttsd_data_get_client_count()) {
@@ -648,8 +644,7 @@ Eina_Bool ttsd_cleanup_client(void *data)
                ecore_timer_add(0, __quit_ecore_loop, NULL);
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "=====");
-       SLOG(LOG_DEBUG, tts_tag(), "  ");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
        return EINA_TRUE;
 }
@@ -906,7 +901,7 @@ int ttsd_server_stop(int uid)
        SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
 
        if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
-               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control() && uid == ttsd_data_get_current_playing()) {
                        SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
 
                        int ret = 0;
@@ -942,7 +937,8 @@ int ttsd_server_pause(int uid, int* utt_id)
                return TTSD_ERROR_INVALID_STATE;
        }
 
-       SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), utt_id(%d)", uid, utt_id);
+       *utt_id = g_utt.uttid;
+       SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
 
        int ret = 0;
        ret = ttsd_player_pause(uid);
@@ -1152,7 +1148,7 @@ int ttsd_server_stop_pcm(int uid)
 
 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== ADD PCM");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
 
        int uttid = -1;
 
@@ -1172,8 +1168,7 @@ int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio
 
                if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
-                       SLOG(LOG_DEBUG, tts_tag(), "=====");
-                       SLOG(LOG_DEBUG, tts_tag(), "  ");
+                       SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_INVALID_PARAMETER;
                }
 
@@ -1210,6 +1205,14 @@ int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio
 
                if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
                        SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
+
+                       if (NULL != temp_sound_data->data) {
+                               free(temp_sound_data->data);
+                               temp_sound_data->data = NULL;
+                       }
+
+                       free(temp_sound_data);
+                       temp_sound_data = NULL;
                }
 
                if (0 != ttsd_player_play(uid)) {
@@ -1226,7 +1229,7 @@ int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio
                SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "=====");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
        return TTSD_ERROR_NONE;
 }