2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
14 #include <app_manager.h>
18 #include "ttsd_config.h"
19 #include "ttsd_data.h"
20 #include "ttsd_dbus.h"
21 #include "ttsd_dbus_server.h"
22 #include "ttsd_engine_agent.h"
23 #include "ttsd_main.h"
24 #include "ttsd_network.h"
25 #include "ttsd_player.h"
26 #include "ttsd_server.h"
29 #define CLIENT_CLEAN_UP_TIME 500
36 /* If current engine exist */
37 //static bool g_is_engine;
39 static Ecore_Timer* g_check_client_timer = NULL;
40 static Ecore_Timer* g_wait_timer = NULL;
41 static Ecore_Timer* g_terminate_timer = NULL;
43 static utterance_t g_utt;
45 static GList *g_proc_list = NULL;
47 static bool g_is_paused;
50 /* Function definitions */
51 static int __synthesis(int uid, const char* credential);
53 static Eina_Bool __wait_synthesis(void *data)
55 /* get current play */
56 char* credential = (char*)data;
57 int uid = ttsd_data_get_current_playing();
60 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
64 if (TTSD_SYNTHESIS_CONTROL_DONE == ttsd_get_synth_control()) {
65 /* Start next synthesis */
66 __synthesis(uid, credential);
76 static int __synthesis(int uid, const char* credential)
78 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
80 speak_data_s* speak_data = NULL;
81 if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
82 if (NULL == speak_data) {
83 SLOG(LOG_WARN, tts_tag(), "[Server] speak data is null");
87 int pid = ttsd_data_get_pid(uid);
89 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d)", uid);
93 char appid[1024] = {0, };
94 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
95 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
98 if (NULL == speak_data->lang || NULL == speak_data->text) {
99 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
100 ttsd_server_stop(uid);
102 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
104 ttsd_data_clear_speak_data(uid, &speak_data);
110 g_utt.uttid = speak_data->utt_id;
112 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
113 SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
114 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
115 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
116 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
117 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
120 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
121 ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
123 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
125 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
127 ttsd_server_stop(uid);
129 int pid = ttsd_data_get_pid(uid);
131 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
133 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
136 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
139 ttsd_data_clear_speak_data(uid, &speak_data);
141 ttsd_data_clear_speak_data(uid, &speak_data);
144 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
150 * TTS Server Callback Functions
152 int ttsd_send_error(ttse_error_e error, const char* msg)
155 int uttid = g_utt.uttid;
156 int tmp_pid = ttsd_data_get_pid(uid);
158 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));
160 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
162 if (0 != ttsd_player_clear(uid))
163 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_clear()");
165 if (0 != ttsd_data_clear_data(uid))
166 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
169 if (0 != ttsdc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
170 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_send_error_message()");
173 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
174 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
177 if (0 != ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
178 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_send_set_state_message()");
183 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)
185 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
188 int uttid = g_utt.uttid;
190 /* Synthesis is success */
191 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
192 if (TTSE_RESULT_EVENT_START == event) {
193 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
194 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
195 uid, uttid, data, data_size, audio_type, rate);
196 } else if (TTSE_RESULT_EVENT_FINISH == event) {
197 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
198 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
199 uid, uttid, data, data_size, audio_type, rate);
201 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
205 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
206 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
207 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
208 SLOG(LOG_DEBUG, tts_tag(), "@@@");
209 return TTSD_ERROR_OPERATION_FAILED;
212 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
213 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
214 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
215 SLOG(LOG_DEBUG, tts_tag(), "@@@");
216 return TTSD_ERROR_INVALID_PARAMETER;
220 sound_data_s* temp_sound_data = NULL;
221 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
222 if (NULL == temp_sound_data) {
223 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
224 return TTSD_ERROR_OUT_OF_MEMORY;
227 temp_sound_data->data = NULL;
228 temp_sound_data->rate = 0;
229 temp_sound_data->data_size = 0;
232 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
233 if (NULL != temp_sound_data->data) {
234 memcpy(temp_sound_data->data, data, data_size);
235 temp_sound_data->data_size = data_size;
236 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
237 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
239 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
242 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
245 temp_sound_data->utt_id = uttid;
246 temp_sound_data->event = event;
247 temp_sound_data->audio_type = audio_type;
248 temp_sound_data->rate = rate;
250 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
251 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
252 if (NULL != temp_sound_data->data) {
253 free(temp_sound_data->data);
254 temp_sound_data->data = NULL;
257 free(temp_sound_data);
258 temp_sound_data = NULL;
260 return TTSD_ERROR_OPERATION_FAILED;
263 if (event == TTSE_RESULT_EVENT_FINISH) {
264 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
267 /* If the app state is paused, do not result to play */
268 if (true == g_is_paused) {
269 SLOG(LOG_DEBUG, tts_tag(), "[Server DEBUG] tts_pause is called. Do not request to play");
270 return TTSD_ERROR_NONE;
273 if (0 != ttsd_player_play(uid)) {
274 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
276 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
278 int tmp_pid = ttsd_data_get_pid(uid);
280 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] uid(%d) is already destroyed or invalid", uid);
282 /* Change ready state */
283 ttsd_server_stop(uid);
285 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
289 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
290 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
294 /*SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS RESULT CALLBACK END");
295 SLOG(LOG_DEBUG, tts_tag(), " ");*/
297 return TTSD_ERROR_NONE;
300 bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
302 /* clear client data */
303 ttsd_data_clear_data(uid);
305 if (APP_STATE_READY != state) {
306 ttsd_data_set_client_state(uid, APP_STATE_READY);
309 if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
311 ttsd_data_delete_client(uid);
318 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
321 case TTS_CONFIG_TYPE_ENGINE:
323 /* TODO - Determine the policy when engine process get engine changed cb */
324 if (NULL == str_param) {
325 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
330 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
331 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
332 ret = ttsd_engine_agent_unload_current_engine();
334 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
337 ret = ttsd_engine_agent_load_current_engine();
339 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
344 /* stop all player */
345 ttsd_player_all_stop();
347 /* send interrupt message to all clients */
348 ttsd_data_foreach_clients(__get_client_cb, NULL);
350 ttsd_engine_cancel_synthesis();
355 case TTS_CONFIG_TYPE_VOICE:
357 if (NULL == str_param) {
358 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
362 char* out_lang = NULL;
366 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
367 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
368 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
370 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
372 /* Current language is not available */
373 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
375 if (NULL != out_lang) {
382 case TTS_CONFIG_TYPE_SPEED:
384 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
385 /* set default speed */
387 ret = ttsd_engine_agent_set_default_speed(int_param);
389 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
395 case TTS_CONFIG_TYPE_PITCH:
397 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
398 /* set default speed */
400 ret = ttsd_engine_agent_set_default_pitch(int_param);
402 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
408 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
410 if (0.0 <= double_param && double_param <= 1.0) {
411 /* set default bg volume ratio */
413 ret = ttsd_player_set_background_volume_ratio(double_param);
415 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
425 bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
427 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
428 ttsd_server_finalize(uid);
432 Eina_Bool ttsd_terminate_daemon(void *data)
434 ttsd_data_foreach_clients(__terminate_client, NULL);
435 g_terminate_timer = NULL;
439 void __screen_reader_changed_cb(bool value)
441 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
442 SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
443 if (g_terminate_timer) {
444 ecore_timer_del(g_terminate_timer);
445 g_terminate_timer = NULL;
447 g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL);
449 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
454 int ttsd_send_all_stop()
456 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
458 /* stop all player */
459 ttsd_player_all_stop();
461 /* send interrupt message to all clients */
462 ttsd_data_foreach_clients(__get_client_cb, NULL);
464 return TTSD_ERROR_NONE;
470 int ttsd_initialize(ttse_request_callback_s *callback)
472 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
474 if (ttsd_config_initialize(__config_changed_cb)) {
475 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
479 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
481 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
482 int ret = ttsd_player_set_background_volume_ratio(ratio);
484 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
487 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
490 if (ttsd_player_init()) {
491 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
492 return TTSD_ERROR_OPERATION_FAILED;
495 /* Engine Agent initialize */
496 if (0 != ttsd_engine_agent_init()) {
497 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
498 return TTSD_ERROR_OPERATION_FAILED;
501 /* set current engine */
502 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
503 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
504 // g_is_engine = false;
506 // g_is_engine = true;
508 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
509 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
510 return TTSD_ERROR_OPERATION_FAILED;
513 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
515 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
516 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
519 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
520 if (NULL == g_check_client_timer) {
521 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
524 return TTSD_ERROR_NONE;
529 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
532 if (0 < g_list_length(g_proc_list)) {
533 iter = g_list_first(g_proc_list);
534 while (NULL != iter) {
535 g_proc_list = g_list_remove_link(g_proc_list, iter);
537 iter = g_list_first(g_proc_list);
541 ttsd_config_finalize();
543 ttsd_player_release();
545 ttsd_engine_agent_release();
549 ecore_timer_del(g_wait_timer);
551 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
554 if (g_terminate_timer) {
555 ecore_timer_del(g_terminate_timer);
556 g_terminate_timer = NULL;
557 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore terminating timer handle");
560 if (NULL != g_check_client_timer) {
561 ecore_timer_del(g_check_client_timer);
562 g_check_client_timer = NULL;
563 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
566 return TTSD_ERROR_NONE;
571 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
573 ttsd_terminate_daemon(NULL);
575 ttsd_dbus_close_connection();
576 ttsd_network_finalize();
579 return TTSD_ERROR_NONE;
583 * TTS Server Functions for Client
586 int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized)
588 if (-1 != ttsd_data_is_client(uid))
589 *is_initialized = true;
591 *is_initialized = false;
593 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), Uid(%d) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
594 return TTSD_ERROR_NONE;
597 int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
599 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
601 if (-1 != ttsd_data_is_client(uid)) {
602 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
603 return TTSD_ERROR_NONE;
606 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
607 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
608 return TTSD_ERROR_OPERATION_FAILED;
611 if (true == *credential_needed) {
613 if (0 != app_manager_get_app_id(pid, &appid)) {
614 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
616 bool is_agreed = false;
617 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
618 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
621 return TTSD_ERROR_OPERATION_FAILED;
626 if (false == is_agreed) {
627 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
628 return TTSD_ERROR_PERMISSION_DENIED;
632 if (0 != ttsd_data_new_client(pid, uid)) {
633 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
634 return TTSD_ERROR_OPERATION_FAILED;
637 if (0 != ttsd_player_create_instance(uid)) {
638 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
639 return TTSD_ERROR_OPERATION_FAILED;
642 return TTSD_ERROR_NONE;
645 static Eina_Bool __quit_ecore_loop(void *data)
647 ttsd_dbus_close_connection();
648 ttsd_network_finalize();
650 ecore_main_loop_quit();
656 static void __read_proc()
659 struct dirent *dirp = NULL;
663 if (0 < g_list_length(g_proc_list)) {
664 iter = g_list_first(g_proc_list);
665 while (NULL != iter) {
666 g_proc_list = g_list_remove_link(g_proc_list, iter);
668 iter = g_list_first(g_proc_list);
672 dp = opendir("/proc");
674 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
680 tmp = atoi(dirp->d_name);
681 if (0 >= tmp) continue;
682 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
684 } while (NULL != dirp);
690 bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
696 for (i = 0; i < g_list_length(g_proc_list); i++) {
697 iter = g_list_nth(g_proc_list, i);
699 if (pid == GPOINTER_TO_INT(iter->data)) {
700 SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
707 if (false == exist) {
708 SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
709 ttsd_server_finalize(uid);
714 char appid[1024] = {0, };
715 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
716 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
719 if (0 < strlen(appid)) {
720 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
722 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
725 result = ttsdc_send_hello(pid, uid);
728 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
729 ttsd_server_finalize(uid);
730 } else if (-1 == result) {
731 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
739 Eina_Bool ttsd_cleanup_client(void *data)
741 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
744 if (0 < ttsd_data_get_client_count()) {
745 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
747 ecore_timer_add(0, __quit_ecore_loop, NULL);
748 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
749 g_check_client_timer = NULL;
753 SLOG(LOG_DEBUG, tts_tag(), "@@@");
758 void __used_voice_cb(const char* lang, int type)
760 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
761 if (0 != ttsd_engine_unload_voice(lang, type)) {
762 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
766 int ttsd_server_finalize(int uid)
768 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
770 app_tts_state_e state;
771 if (0 > ttsd_data_get_client_state(uid, &state)) {
772 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
775 ttsd_server_stop(uid);
776 ttsd_player_clear(uid);
778 ttsd_player_destroy_instance(uid);
780 /* Need to unload voice when used voice is unregistered */
781 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
782 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
783 return TTSD_ERROR_OPERATION_FAILED;
786 ttsd_data_delete_client(uid);
788 /* unload engine, if ref count of client is 0 */
789 if (0 == ttsd_data_get_client_count()) {
790 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
791 ecore_timer_add(0, __quit_ecore_loop, NULL);
794 return TTSD_ERROR_NONE;
797 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
799 app_tts_state_e state;
800 if (0 > ttsd_data_get_client_state(uid, &state)) {
801 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
802 return TTSD_ERROR_INVALID_PARAMETER;
805 /* check valid voice */
806 char* temp_lang = NULL;
808 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
809 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
810 if (NULL != temp_lang) {
814 return TTSD_ERROR_INVALID_VOICE;
817 if (NULL == temp_lang) {
818 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
819 return TTSD_ERROR_INVALID_VOICE;
822 speak_data_s* speak_data = NULL;
823 speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
824 if (NULL == speak_data) {
825 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
826 if (NULL != temp_lang) {
830 return TTSD_ERROR_OPERATION_FAILED;
833 speak_data->lang = strdup(lang);
834 speak_data->vctype = voice_type;
836 speak_data->speed = speed;
837 speak_data->utt_id = utt_id;
839 speak_data->text = strdup(text);
841 SLOG(LOG_INFO, tts_tag(), "[Server] Add queue, lang(%s), vctype(%d), speed(%d), uttid(%d), credential(%s)", lang, voice_type, speed, utt_id, credential);
843 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
845 ret = ttsd_data_add_speak_data(uid, speak_data);
847 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
848 if (NULL != temp_lang) {
852 if (NULL != speak_data) {
853 if (NULL != speak_data->lang) free(speak_data->lang);
854 if (NULL != speak_data->text) free(speak_data->text);
856 speak_data->lang = NULL;
857 speak_data->text = NULL;
866 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
867 /* Request load voice */
868 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
869 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
870 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
874 if (NULL != temp_lang) {
879 if (APP_STATE_PLAYING == state) {
880 /* check if engine use network */
881 if (ttsd_engine_agent_need_network()) {
882 if (false == ttsd_network_is_connected()) {
883 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
884 return TTSD_ERROR_OPERATION_FAILED;
888 /* Check whether tts-engine is running or not */
889 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
890 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
892 __synthesis(uid, credential);
896 return TTSD_ERROR_NONE;
899 Eina_Bool __send_interrupt_client(void *data)
901 intptr_t puid = (intptr_t)data;
904 int pid = ttsd_data_get_pid(uid);
906 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d), pid(%d)", uid, pid);
910 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
911 /* send message to client about changing state */
912 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
914 ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
920 int ttsd_server_play(int uid, const char* credential)
922 app_tts_state_e state;
923 if (0 > ttsd_data_get_client_state(uid, &state)) {
924 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
925 return TTSD_ERROR_INVALID_PARAMETER;
928 if (APP_STATE_PLAYING == state) {
929 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
930 return TTSD_ERROR_NONE;
933 /* check if engine use network */
934 if (ttsd_engine_agent_need_network()) {
935 if (false == ttsd_network_is_connected()) {
936 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
937 return TTSD_ERROR_OUT_OF_NETWORK;
941 /* check the current playback focus */
942 if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
943 bool is_current_interrupt = false;
944 if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
945 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
947 if (true == is_current_interrupt) {
948 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
949 ttsd_data_clear_data(uid);
950 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
955 int current_uid = ttsd_data_get_current_playing();
956 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
958 if (uid != current_uid && -1 != current_uid) {
959 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
960 /* Send interrupt message */
961 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
964 if (0 != ttsd_server_stop(current_uid)) {
965 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
968 intptr_t pcurrent_uid = (intptr_t)current_uid;
969 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
971 /* Default mode policy of interrupt is "Pause" */
973 /* Send interrupt message */
974 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
977 if (0 != ttsd_player_pause(current_uid)) {
978 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
982 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
984 intptr_t pcurrent_uid = (intptr_t)current_uid;
985 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
989 /* Change current play */
990 if (0 != ttsd_player_wait_to_play(uid)) {
991 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
994 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
995 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
996 return TTSD_ERROR_OPERATION_FAILED;
999 if (APP_STATE_PAUSED == state) {
1000 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1002 g_is_paused = false;
1005 if (0 != ttsd_player_resume(uid)) {
1006 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1010 /* Check whether tts-engine is running or not */
1011 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
1012 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1014 __synthesis(uid, credential);
1017 return TTSD_ERROR_NONE;
1020 int ttsd_server_stop(int uid)
1022 app_tts_state_e state;
1023 if (0 > ttsd_data_get_client_state(uid, &state)) {
1024 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1025 return TTSD_ERROR_INVALID_PARAMETER;
1028 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1030 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1031 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
1032 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1035 ret = ttsd_engine_cancel_synthesis();
1037 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1039 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1042 if (0 != ttsd_player_stop(uid)) {
1043 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1046 ttsd_data_set_client_state(uid, APP_STATE_READY);
1049 /* Reset all data */
1050 ttsd_data_clear_data(uid);
1051 g_is_paused = false;
1053 return TTSD_ERROR_NONE;
1056 int ttsd_server_pause(int uid, int* utt_id)
1058 app_tts_state_e state;
1059 if (0 > ttsd_data_get_client_state(uid, &state)) {
1060 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1061 return TTSD_ERROR_INVALID_PARAMETER;
1064 if (APP_STATE_PLAYING != state) {
1065 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1066 return TTSD_ERROR_INVALID_STATE;
1071 *utt_id = g_utt.uttid;
1072 SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
1075 ret = ttsd_player_pause(uid);
1077 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1078 return TTSD_ERROR_OPERATION_FAILED;
1081 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1083 return TTSD_ERROR_NONE;
1086 int ttsd_server_get_support_voices(int uid, GList** voice_list)
1088 app_tts_state_e state;
1089 if (0 > ttsd_data_get_client_state(uid, &state)) {
1090 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1091 return TTSD_ERROR_INVALID_PARAMETER;
1095 int ret = ttsd_engine_get_voice_list(voice_list);
1097 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1101 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1103 return TTSD_ERROR_NONE;
1106 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
1108 app_tts_state_e state;
1109 if (0 > ttsd_data_get_client_state(uid, &state)) {
1110 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1111 return TTSD_ERROR_INVALID_PARAMETER;
1114 /* get current voice */
1115 int ret = ttsd_engine_get_default_voice(language, voice_type);
1117 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1121 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1123 return TTSD_ERROR_NONE;
1126 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
1128 app_tts_state_e state;
1129 if (0 > ttsd_data_get_client_state(uid, &state)) {
1130 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1131 return TTSD_ERROR_INVALID_PARAMETER;
1134 if (APP_STATE_READY != state) {
1135 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1136 return TTSD_ERROR_INVALID_STATE;
1139 int ret = ttsd_engine_set_private_data(key, data);
1141 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1143 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1149 int ttsd_server_get_private_data(int uid, const char* key, char** data)
1151 app_tts_state_e state;
1152 if (0 > ttsd_data_get_client_state(uid, &state)) {
1153 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1154 return TTSD_ERROR_INVALID_PARAMETER;
1157 if (APP_STATE_READY != state) {
1158 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1159 return TTSD_ERROR_INVALID_STATE;
1162 int ret = ttsd_engine_get_private_data(key, data);
1164 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1166 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1172 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1174 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1177 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1179 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1185 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1187 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1190 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1192 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1198 int ttsd_server_play_pcm(int uid)
1200 app_tts_state_e state;
1201 if (0 > ttsd_data_get_client_state(uid, &state)) {
1202 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
1203 return TTSD_ERROR_INVALID_PARAMETER;
1206 if (APP_STATE_PLAYING == state) {
1207 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
1208 return TTSD_ERROR_NONE;
1211 int current_uid = ttsd_data_get_current_playing();
1212 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
1214 if (uid != current_uid && -1 != current_uid) {
1215 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
1216 /* Send interrupt message */
1217 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
1220 if (0 != ttsd_server_stop(current_uid)) {
1221 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
1224 intptr_t pcurrent_uid = (intptr_t)current_uid;
1225 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1227 /* Default mode policy of interrupt is "Pause" */
1229 /* Send interrupt message */
1230 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
1233 if (0 != ttsd_player_pause(current_uid)) {
1234 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
1238 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
1240 intptr_t pcurrent_uid = (intptr_t)current_uid;
1241 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1245 /* Change current play */
1246 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1247 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1248 return TTSD_ERROR_OPERATION_FAILED;
1251 if (APP_STATE_PAUSED == state) {
1252 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1255 if (0 != ttsd_player_resume(uid)) {
1256 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1259 if (0 != ttsd_player_play_pcm(uid)) {
1260 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
1262 // Change ready state
1263 ttsd_server_stop_pcm(uid);
1265 int tmp_pid = ttsd_data_get_pid(uid);
1267 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
1269 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1274 return TTSD_ERROR_NONE;
1277 int ttsd_server_stop_pcm(int uid)
1279 app_tts_state_e state;
1280 if (0 > ttsd_data_get_client_state(uid, &state)) {
1281 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1282 return TTSD_ERROR_INVALID_PARAMETER;
1285 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1287 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
1288 ttsd_data_set_client_state(uid, APP_STATE_READY);
1291 /* Reset all data */
1292 ttsd_data_clear_data(uid);
1294 ttsd_player_stop(uid);
1297 return TTSD_ERROR_NONE;
1300 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
1302 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1306 /* Synthesis is success */
1307 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1308 if (TTSE_RESULT_EVENT_START == event) {
1309 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1310 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1311 uid, uttid, data, data_size, audio_type, rate);
1312 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1313 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1314 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1315 uid, uttid, data, data_size, audio_type, rate);
1317 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1320 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1321 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1322 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1323 return TTSD_ERROR_INVALID_PARAMETER;
1327 sound_data_s* temp_sound_data = NULL;
1328 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
1329 if (NULL == temp_sound_data) {
1330 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1331 return TTSD_ERROR_OUT_OF_MEMORY;
1334 temp_sound_data->data = NULL;
1335 temp_sound_data->rate = 0;
1336 temp_sound_data->data_size = 0;
1338 if (0 < data_size) {
1339 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
1340 if (NULL != temp_sound_data->data) {
1341 memcpy(temp_sound_data->data, data, data_size);
1342 temp_sound_data->data_size = data_size;
1343 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
1344 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
1346 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
1349 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
1352 temp_sound_data->utt_id = uttid;
1353 temp_sound_data->event = event;
1354 temp_sound_data->audio_type = audio_type;
1355 temp_sound_data->rate = rate;
1357 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
1358 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
1360 if (NULL != temp_sound_data->data) {
1361 free(temp_sound_data->data);
1362 temp_sound_data->data = NULL;
1365 free(temp_sound_data);
1366 temp_sound_data = NULL;
1369 /* if (0 != ttsd_player_play(uid)) {
1370 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
1372 // Change ready state
1373 ttsd_server_stop(uid);
1376 tmp_pid = ttsd_data_get_pid(uid);
1377 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1381 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1384 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1386 return TTSD_ERROR_NONE;