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);
88 char appid[1024] = {0, };
89 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
90 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
93 if (NULL == speak_data->lang || NULL == speak_data->text) {
94 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
95 ttsd_server_stop(uid);
97 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
99 ttsd_data_clear_speak_data(uid, &speak_data);
105 g_utt.uttid = speak_data->utt_id;
107 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
108 SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
109 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
110 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
111 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
112 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
115 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
116 ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
118 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
120 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
122 ttsd_server_stop(uid);
124 int pid = ttsd_data_get_pid(uid);
125 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
127 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
130 ttsd_data_clear_speak_data(uid, &speak_data);
132 ttsd_data_clear_speak_data(uid, &speak_data);
135 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
141 * TTS Server Callback Functions
143 int ttsd_send_error(ttse_error_e error, const char* msg)
146 int uttid = g_utt.uttid;
147 int tmp_pid = ttsd_data_get_pid(uid);
149 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));
151 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
153 if (0 != ttsd_player_clear(uid))
154 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
156 if (0 != ttsd_data_clear_data(uid))
157 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
160 if (0 != ttsdc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
161 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_send_error_message()");
164 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
165 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
168 if (0 != ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
169 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_send_set_state_message()");
174 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)
176 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
179 int uttid = g_utt.uttid;
181 /* Synthesis is success */
182 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
183 if (TTSE_RESULT_EVENT_START == event) {
184 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
185 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
186 uid, uttid, data, data_size, audio_type, rate);
187 } else if (TTSE_RESULT_EVENT_FINISH == event) {
188 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
189 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
190 uid, uttid, data, data_size, audio_type, rate);
192 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
196 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
197 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
198 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
199 SLOG(LOG_DEBUG, tts_tag(), "@@@");
200 return TTSD_ERROR_OPERATION_FAILED;
203 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
204 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
205 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
206 SLOG(LOG_DEBUG, tts_tag(), "@@@");
207 return TTSD_ERROR_INVALID_PARAMETER;
211 sound_data_s* temp_sound_data = NULL;
212 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
213 if (NULL == temp_sound_data) {
214 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
215 return TTSD_ERROR_OUT_OF_MEMORY;
218 temp_sound_data->data = NULL;
219 temp_sound_data->rate = 0;
220 temp_sound_data->data_size = 0;
223 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
224 if (NULL != temp_sound_data->data) {
225 memcpy(temp_sound_data->data, data, data_size);
226 temp_sound_data->data_size = data_size;
227 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
228 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
230 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
233 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
236 temp_sound_data->utt_id = uttid;
237 temp_sound_data->event = event;
238 temp_sound_data->audio_type = audio_type;
239 temp_sound_data->rate = rate;
241 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
242 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
243 if (NULL != temp_sound_data->data) {
244 free(temp_sound_data->data);
245 temp_sound_data->data = NULL;
248 free(temp_sound_data);
249 temp_sound_data = NULL;
251 return TTSD_ERROR_OPERATION_FAILED;
254 if (event == TTSE_RESULT_EVENT_FINISH) {
255 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
258 /* If the app state is paused, do not result to play */
259 if (true == g_is_paused) {
260 SLOG(LOG_DEBUG, tts_tag(), "[Server DEBUG] tts_pause is called. Do not request to play");
261 return TTSD_ERROR_NONE;
264 if (0 != ttsd_player_play(uid)) {
265 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
267 /* Change ready state */
268 ttsd_server_stop(uid);
271 tmp_pid = ttsd_data_get_pid(uid);
272 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
275 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
276 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
280 /*SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS RESULT CALLBACK END");
281 SLOG(LOG_DEBUG, tts_tag(), " ");*/
283 return TTSD_ERROR_NONE;
286 bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
288 /* clear client data */
289 ttsd_data_clear_data(uid);
291 if (APP_STATE_READY != state) {
292 ttsd_data_set_client_state(uid, APP_STATE_READY);
295 if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
297 ttsd_data_delete_client(uid);
304 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
307 case TTS_CONFIG_TYPE_ENGINE:
309 /* TODO - Determine the policy when engine process get engine changed cb */
310 if (NULL == str_param) {
311 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
316 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
317 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
318 ret = ttsd_engine_agent_unload_current_engine();
320 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
323 ret = ttsd_engine_agent_load_current_engine();
325 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
330 /* stop all player */
331 ttsd_player_all_stop();
333 /* send interrupt message to all clients */
334 ttsd_data_foreach_clients(__get_client_cb, NULL);
336 ttsd_engine_cancel_synthesis();
341 case TTS_CONFIG_TYPE_VOICE:
343 if (NULL == str_param) {
344 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
348 char* out_lang = NULL;
352 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
353 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
354 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
356 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
358 /* Current language is not available */
359 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
361 if (NULL != out_lang) {
368 case TTS_CONFIG_TYPE_SPEED:
370 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
371 /* set default speed */
373 ret = ttsd_engine_agent_set_default_speed(int_param);
375 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
381 case TTS_CONFIG_TYPE_PITCH:
383 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
384 /* set default speed */
386 ret = ttsd_engine_agent_set_default_pitch(int_param);
388 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
394 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
396 if (0.0 <= double_param && double_param <= 1.0) {
397 /* set default bg volume ratio */
399 ret = ttsd_player_set_background_volume_ratio(double_param);
401 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
411 bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
413 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
414 ttsd_server_finalize(uid);
418 Eina_Bool ttsd_terminate_daemon(void *data)
420 ttsd_data_foreach_clients(__terminate_client, NULL);
421 g_terminate_timer = NULL;
425 void __screen_reader_changed_cb(bool value)
427 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
428 SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
429 if (g_terminate_timer) {
430 ecore_timer_del(g_terminate_timer);
431 g_terminate_timer = NULL;
433 g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL);
435 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
440 int ttsd_send_all_stop()
442 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
444 /* stop all player */
445 ttsd_player_all_stop();
447 /* send interrupt message to all clients */
448 ttsd_data_foreach_clients(__get_client_cb, NULL);
450 return TTSD_ERROR_NONE;
456 int ttsd_initialize(ttse_request_callback_s *callback)
458 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
460 if (ttsd_config_initialize(__config_changed_cb)) {
461 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
465 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
467 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
468 int ret = ttsd_player_set_background_volume_ratio(ratio);
470 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
473 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
476 if (ttsd_player_init()) {
477 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
478 return TTSD_ERROR_OPERATION_FAILED;
481 /* Engine Agent initialize */
482 if (0 != ttsd_engine_agent_init()) {
483 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
484 return TTSD_ERROR_OPERATION_FAILED;
487 /* set current engine */
488 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
489 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
490 // g_is_engine = false;
492 // g_is_engine = true;
494 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
495 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
496 return TTSD_ERROR_OPERATION_FAILED;
499 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
501 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
502 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
505 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
506 if (NULL == g_check_client_timer) {
507 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
510 return TTSD_ERROR_NONE;
515 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
518 if (0 < g_list_length(g_proc_list)) {
519 iter = g_list_first(g_proc_list);
520 while (NULL != iter) {
521 g_proc_list = g_list_remove_link(g_proc_list, iter);
523 iter = g_list_first(g_proc_list);
527 ttsd_config_finalize();
529 ttsd_player_release();
531 ttsd_engine_agent_release();
535 ecore_timer_del(g_wait_timer);
537 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
540 if (g_terminate_timer) {
541 ecore_timer_del(g_terminate_timer);
542 g_terminate_timer = NULL;
543 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore terminating timer handle");
546 if (NULL != g_check_client_timer) {
547 ecore_timer_del(g_check_client_timer);
548 g_check_client_timer = NULL;
549 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
552 return TTSD_ERROR_NONE;
557 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
559 ttsd_terminate_daemon(NULL);
561 ttsd_dbus_close_connection();
562 ttsd_network_finalize();
565 return TTSD_ERROR_NONE;
569 * TTS Server Functions for Client
572 int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized)
574 if (-1 != ttsd_data_is_client(uid))
575 *is_initialized = true;
577 *is_initialized = false;
579 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), Uid(%d) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
580 return TTSD_ERROR_NONE;
583 int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
585 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
587 if (-1 != ttsd_data_is_client(uid)) {
588 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
589 return TTSD_ERROR_NONE;
592 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
593 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
594 return TTSD_ERROR_OPERATION_FAILED;
597 if (true == *credential_needed) {
599 if (0 != app_manager_get_app_id(pid, &appid)) {
600 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
602 bool is_agreed = false;
603 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
604 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
607 return TTSD_ERROR_OPERATION_FAILED;
612 if (false == is_agreed) {
613 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
614 return TTSD_ERROR_PERMISSION_DENIED;
618 if (0 != ttsd_data_new_client(pid, uid)) {
619 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
620 return TTSD_ERROR_OPERATION_FAILED;
623 if (0 != ttsd_player_create_instance(uid)) {
624 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
625 return TTSD_ERROR_OPERATION_FAILED;
628 return TTSD_ERROR_NONE;
631 static Eina_Bool __quit_ecore_loop(void *data)
633 ttsd_dbus_close_connection();
634 ttsd_network_finalize();
636 ecore_main_loop_quit();
642 static void __read_proc()
645 struct dirent *dirp = NULL;
649 if (0 < g_list_length(g_proc_list)) {
650 iter = g_list_first(g_proc_list);
651 while (NULL != iter) {
652 g_proc_list = g_list_remove_link(g_proc_list, iter);
654 iter = g_list_first(g_proc_list);
658 dp = opendir("/proc");
660 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
666 tmp = atoi(dirp->d_name);
667 if (0 >= tmp) continue;
668 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
670 } while (NULL != dirp);
676 bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
682 for (i = 0; i < g_list_length(g_proc_list); i++) {
683 iter = g_list_nth(g_proc_list, i);
685 if (pid == GPOINTER_TO_INT(iter->data)) {
686 SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
693 if (false == exist) {
694 SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
695 ttsd_server_finalize(uid);
700 char appid[1024] = {0, };
701 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
702 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
705 if (0 < strlen(appid)) {
706 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
708 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
711 result = ttsdc_send_hello(pid, uid);
714 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
715 ttsd_server_finalize(uid);
716 } else if (-1 == result) {
717 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
725 Eina_Bool ttsd_cleanup_client(void *data)
727 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
730 if (0 < ttsd_data_get_client_count()) {
731 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
733 ecore_timer_add(0, __quit_ecore_loop, NULL);
734 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
735 g_check_client_timer = NULL;
739 SLOG(LOG_DEBUG, tts_tag(), "@@@");
744 void __used_voice_cb(const char* lang, int type)
746 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
747 if (0 != ttsd_engine_unload_voice(lang, type)) {
748 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
752 int ttsd_server_finalize(int uid)
754 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
756 app_tts_state_e state;
757 if (0 > ttsd_data_get_client_state(uid, &state)) {
758 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
761 ttsd_server_stop(uid);
762 ttsd_player_stop(uid);
764 ttsd_player_destroy_instance(uid);
766 /* Need to unload voice when used voice is unregistered */
767 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
768 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
769 return TTSD_ERROR_OPERATION_FAILED;
772 ttsd_data_delete_client(uid);
774 /* unload engine, if ref count of client is 0 */
775 if (0 == ttsd_data_get_client_count()) {
776 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
777 ecore_timer_add(0, __quit_ecore_loop, NULL);
780 return TTSD_ERROR_NONE;
783 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
785 app_tts_state_e state;
786 if (0 > ttsd_data_get_client_state(uid, &state)) {
787 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
788 return TTSD_ERROR_INVALID_PARAMETER;
791 /* check valid voice */
792 char* temp_lang = NULL;
794 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
795 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
796 if (NULL != temp_lang) {
800 return TTSD_ERROR_INVALID_VOICE;
803 if (NULL == temp_lang) {
804 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
805 return TTSD_ERROR_INVALID_VOICE;
808 speak_data_s* speak_data = NULL;
809 speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
810 if (NULL == speak_data) {
811 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
812 if (NULL != temp_lang) {
816 return TTSD_ERROR_OPERATION_FAILED;
819 speak_data->lang = strdup(lang);
820 speak_data->vctype = voice_type;
822 speak_data->speed = speed;
823 speak_data->utt_id = utt_id;
825 speak_data->text = strdup(text);
827 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);
829 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
831 ret = ttsd_data_add_speak_data(uid, speak_data);
833 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
834 if (NULL != temp_lang) {
838 if (NULL != speak_data) {
839 if (NULL != speak_data->lang) free(speak_data->lang);
840 if (NULL != speak_data->text) free(speak_data->text);
842 speak_data->lang = NULL;
843 speak_data->text = NULL;
852 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
853 /* Request load voice */
854 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
855 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
856 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
860 if (NULL != temp_lang) {
865 if (APP_STATE_PLAYING == state) {
866 /* check if engine use network */
867 if (ttsd_engine_agent_need_network()) {
868 if (false == ttsd_network_is_connected()) {
869 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
870 return TTSD_ERROR_OPERATION_FAILED;
874 /* Check whether tts-engine is running or not */
875 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
876 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
878 __synthesis(uid, credential);
882 return TTSD_ERROR_NONE;
885 Eina_Bool __send_interrupt_client(void *data)
887 intptr_t puid = (intptr_t)data;
890 int pid = ttsd_data_get_pid(uid);
893 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d), pid(%d)", uid, pid);
897 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
898 /* send message to client about changing state */
899 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
901 ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
907 int ttsd_server_play(int uid, const char* credential)
909 app_tts_state_e state;
910 if (0 > ttsd_data_get_client_state(uid, &state)) {
911 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
912 return TTSD_ERROR_INVALID_PARAMETER;
915 if (APP_STATE_PLAYING == state) {
916 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
917 return TTSD_ERROR_NONE;
920 /* check if engine use network */
921 if (ttsd_engine_agent_need_network()) {
922 if (false == ttsd_network_is_connected()) {
923 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
924 return TTSD_ERROR_OUT_OF_NETWORK;
928 /* check the current playback focus */
929 if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
930 bool is_current_interrupt = false;
931 if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
932 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
934 if (true == is_current_interrupt) {
935 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
936 ttsd_data_clear_data(uid);
937 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
942 int current_uid = ttsd_data_get_current_playing();
943 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
945 if (uid != current_uid && -1 != current_uid) {
946 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
947 /* Send interrupt message */
948 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
951 if (0 != ttsd_server_stop(current_uid)) {
952 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
954 if (0 != ttsd_player_stop(current_uid)) {
955 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to player stop : uid (%d)", current_uid);
958 intptr_t pcurrent_uid = (intptr_t)current_uid;
959 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
961 /* Default mode policy of interrupt is "Pause" */
963 /* Send interrupt message */
964 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
967 if (0 != ttsd_player_pause(current_uid)) {
968 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
972 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
974 intptr_t pcurrent_uid = (intptr_t)current_uid;
975 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
979 /* Change current play */
980 if (0 != ttsd_player_wait_to_play(uid)) {
981 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
984 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
985 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
986 return TTSD_ERROR_OPERATION_FAILED;
989 if (APP_STATE_PAUSED == state) {
990 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
995 if (0 != ttsd_player_resume(uid)) {
996 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1000 /* Check whether tts-engine is running or not */
1001 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
1002 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1004 __synthesis(uid, credential);
1007 return TTSD_ERROR_NONE;
1010 int ttsd_server_stop(int uid)
1012 app_tts_state_e state;
1013 if (0 > ttsd_data_get_client_state(uid, &state)) {
1014 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1015 return TTSD_ERROR_INVALID_PARAMETER;
1018 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1020 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1021 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
1022 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1025 ret = ttsd_engine_cancel_synthesis();
1027 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1030 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1032 if (0 != ttsd_player_clear(uid))
1033 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1035 ttsd_data_set_client_state(uid, APP_STATE_READY);
1038 /* Reset all data */
1039 ttsd_data_clear_data(uid);
1040 g_is_paused = false;
1042 return TTSD_ERROR_NONE;
1045 int ttsd_server_pause(int uid, int* utt_id)
1047 app_tts_state_e state;
1048 if (0 > ttsd_data_get_client_state(uid, &state)) {
1049 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1050 return TTSD_ERROR_INVALID_PARAMETER;
1053 if (APP_STATE_PLAYING != state) {
1054 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1055 return TTSD_ERROR_INVALID_STATE;
1060 *utt_id = g_utt.uttid;
1061 SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
1064 ret = ttsd_player_pause(uid);
1066 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1067 return TTSD_ERROR_OPERATION_FAILED;
1070 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1072 return TTSD_ERROR_NONE;
1075 int ttsd_server_get_support_voices(int uid, GList** voice_list)
1077 app_tts_state_e state;
1078 if (0 > ttsd_data_get_client_state(uid, &state)) {
1079 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1080 return TTSD_ERROR_INVALID_PARAMETER;
1084 int ret = ttsd_engine_get_voice_list(voice_list);
1086 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1090 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1092 return TTSD_ERROR_NONE;
1095 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
1097 app_tts_state_e state;
1098 if (0 > ttsd_data_get_client_state(uid, &state)) {
1099 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1100 return TTSD_ERROR_INVALID_PARAMETER;
1103 /* get current voice */
1104 int ret = ttsd_engine_get_default_voice(language, voice_type);
1106 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1110 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1112 return TTSD_ERROR_NONE;
1115 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
1117 app_tts_state_e state;
1118 if (0 > ttsd_data_get_client_state(uid, &state)) {
1119 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1120 return TTSD_ERROR_INVALID_PARAMETER;
1123 if (APP_STATE_READY != state) {
1124 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1125 return TTSD_ERROR_INVALID_STATE;
1128 int ret = ttsd_engine_set_private_data(key, data);
1130 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1132 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1138 int ttsd_server_get_private_data(int uid, const char* key, char** data)
1140 app_tts_state_e state;
1141 if (0 > ttsd_data_get_client_state(uid, &state)) {
1142 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1143 return TTSD_ERROR_INVALID_PARAMETER;
1146 if (APP_STATE_READY != state) {
1147 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1148 return TTSD_ERROR_INVALID_STATE;
1151 int ret = ttsd_engine_get_private_data(key, data);
1153 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1155 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1161 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1163 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1166 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1168 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1174 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1176 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1179 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1181 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1187 int ttsd_server_play_pcm(int uid)
1189 app_tts_state_e state;
1190 if (0 > ttsd_data_get_client_state(uid, &state)) {
1191 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
1192 return TTSD_ERROR_INVALID_PARAMETER;
1195 if (APP_STATE_PLAYING == state) {
1196 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
1197 return TTSD_ERROR_NONE;
1200 int current_uid = ttsd_data_get_current_playing();
1201 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
1203 if (uid != current_uid && -1 != current_uid) {
1204 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
1205 /* Send interrupt message */
1206 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
1209 if (0 != ttsd_server_stop(current_uid)) {
1210 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
1212 if (0 != ttsd_player_stop(current_uid)) {
1213 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to player stop : uid (%d)", current_uid);
1216 intptr_t pcurrent_uid = (intptr_t)current_uid;
1217 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1219 /* Default mode policy of interrupt is "Pause" */
1221 /* Send interrupt message */
1222 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
1225 if (0 != ttsd_player_pause(current_uid)) {
1226 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
1230 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
1232 intptr_t pcurrent_uid = (intptr_t)current_uid;
1233 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1237 /* Change current play */
1238 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1239 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1240 return TTSD_ERROR_OPERATION_FAILED;
1243 if (APP_STATE_PAUSED == state) {
1244 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1247 if (0 != ttsd_player_resume(uid)) {
1248 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1251 if (0 != ttsd_player_play_pcm(uid)) {
1252 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
1254 // Change ready state
1255 ttsd_server_stop_pcm(uid);
1258 tmp_pid = ttsd_data_get_pid(uid);
1259 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1263 return TTSD_ERROR_NONE;
1266 int ttsd_server_stop_pcm(int uid)
1268 app_tts_state_e state;
1269 if (0 > ttsd_data_get_client_state(uid, &state)) {
1270 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1271 return TTSD_ERROR_INVALID_PARAMETER;
1274 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1276 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
1277 ttsd_data_set_client_state(uid, APP_STATE_READY);
1280 /* Reset all data */
1281 ttsd_data_clear_data(uid);
1283 ttsd_player_stop(uid);
1286 return TTSD_ERROR_NONE;
1289 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
1291 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1295 /* Synthesis is success */
1296 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1297 if (TTSE_RESULT_EVENT_START == event) {
1298 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1299 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1300 uid, uttid, data, data_size, audio_type, rate);
1301 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1302 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1303 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1304 uid, uttid, data, data_size, audio_type, rate);
1306 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1309 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1310 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1311 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1312 return TTSD_ERROR_INVALID_PARAMETER;
1316 sound_data_s* temp_sound_data = NULL;
1317 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
1318 if (NULL == temp_sound_data) {
1319 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1320 return TTSD_ERROR_OUT_OF_MEMORY;
1323 temp_sound_data->data = NULL;
1324 temp_sound_data->rate = 0;
1325 temp_sound_data->data_size = 0;
1327 if (0 < data_size) {
1328 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
1329 if (NULL != temp_sound_data->data) {
1330 memcpy(temp_sound_data->data, data, data_size);
1331 temp_sound_data->data_size = data_size;
1332 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
1333 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
1335 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
1338 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
1341 temp_sound_data->utt_id = uttid;
1342 temp_sound_data->event = event;
1343 temp_sound_data->audio_type = audio_type;
1344 temp_sound_data->rate = rate;
1346 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
1347 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
1349 if (NULL != temp_sound_data->data) {
1350 free(temp_sound_data->data);
1351 temp_sound_data->data = NULL;
1354 free(temp_sound_data);
1355 temp_sound_data = NULL;
1358 /* if (0 != ttsd_player_play(uid)) {
1359 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
1361 // Change ready state
1362 ttsd_server_stop(uid);
1365 tmp_pid = ttsd_data_get_pid(uid);
1366 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1370 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1373 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1375 return TTSD_ERROR_NONE;