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"
23 #include "ttsd_engine_agent.h"
24 #include "ttsd_main.h"
25 #include "ttsd_network.h"
26 #include "ttsd_player.h"
27 #include "ttsd_server.h"
30 #define CLIENT_CLEAN_UP_TIME 500
37 /* If current engine exist */
38 //static bool g_is_engine;
40 static Ecore_Timer* g_check_client_timer = NULL;
41 static Ecore_Timer* g_wait_timer = NULL;
42 static Ecore_Timer* g_terminate_timer = NULL;
44 static utterance_t g_utt;
46 static GList *g_proc_list = NULL;
48 static bool g_is_paused;
51 /* Function definitions */
52 static int __synthesis(int uid, const char* credential);
54 static Eina_Bool __wait_synthesis(void *data)
56 /* get current play */
57 char* credential = (char*)data;
58 int uid = ttsd_data_get_current_playing();
61 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
65 if (TTSD_SYNTHESIS_CONTROL_DONE == ttsd_get_synth_control()) {
66 /* Start next synthesis */
67 __synthesis(uid, credential);
77 static int __synthesis(int uid, const char* credential)
79 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
81 speak_data_s* speak_data = NULL;
82 if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
83 if (NULL == speak_data) {
84 SLOG(LOG_WARN, tts_tag(), "[Server] speak data is null");
88 int pid = ttsd_data_get_pid(uid);
90 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d)", uid);
94 char appid[1024] = {0, };
95 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
96 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
99 if (NULL == speak_data->lang || NULL == speak_data->text) {
100 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
101 ttsd_server_stop(uid);
103 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
105 ttsd_data_clear_speak_data(uid, &speak_data);
111 g_utt.uttid = speak_data->utt_id;
113 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
114 SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
115 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
116 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
117 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
118 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
121 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
122 ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
124 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
126 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
128 ttsd_server_stop(uid);
130 int pid = ttsd_data_get_pid(uid);
132 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
134 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
137 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
140 ttsd_data_clear_speak_data(uid, &speak_data);
142 ttsd_data_clear_speak_data(uid, &speak_data);
145 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
151 * TTS Server Callback Functions
153 int ttsd_send_error(ttse_error_e error, const char* msg)
156 int uttid = g_utt.uttid;
157 int tmp_pid = ttsd_data_get_pid(uid);
159 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));
161 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
163 if (0 != ttsd_player_clear(uid))
164 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_clear()");
166 if (0 != ttsd_data_clear_data(uid))
167 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
170 if (0 != ttsdc_ipc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
171 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_error_message()");
174 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
175 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
178 if (0 != ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
179 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_set_state_message()");
184 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)
186 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
189 int uttid = g_utt.uttid;
191 /* Synthesis is success */
192 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
193 if (TTSE_RESULT_EVENT_START == event) {
194 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
195 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
196 uid, uttid, data, data_size, audio_type, rate);
197 } else if (TTSE_RESULT_EVENT_FINISH == event) {
198 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
199 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
200 uid, uttid, data, data_size, audio_type, rate);
202 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
206 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
207 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
208 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
209 SLOG(LOG_DEBUG, tts_tag(), "@@@");
210 return TTSD_ERROR_OPERATION_FAILED;
213 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
214 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
215 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
216 SLOG(LOG_DEBUG, tts_tag(), "@@@");
217 return TTSD_ERROR_INVALID_PARAMETER;
221 sound_data_s* temp_sound_data = NULL;
222 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
223 if (NULL == temp_sound_data) {
224 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
225 return TTSD_ERROR_OUT_OF_MEMORY;
228 temp_sound_data->data = NULL;
229 temp_sound_data->rate = 0;
230 temp_sound_data->data_size = 0;
233 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
234 if (NULL != temp_sound_data->data) {
235 memcpy(temp_sound_data->data, data, data_size);
236 temp_sound_data->data_size = data_size;
237 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
238 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
240 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
243 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
246 temp_sound_data->utt_id = uttid;
247 temp_sound_data->event = event;
248 temp_sound_data->audio_type = audio_type;
249 temp_sound_data->rate = rate;
251 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
252 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
253 if (NULL != temp_sound_data->data) {
254 free(temp_sound_data->data);
255 temp_sound_data->data = NULL;
258 free(temp_sound_data);
259 temp_sound_data = NULL;
261 return TTSD_ERROR_OPERATION_FAILED;
264 if (event == TTSE_RESULT_EVENT_FINISH) {
265 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
268 /* If the app state is paused, do not result to play */
269 if (true == g_is_paused) {
270 SLOG(LOG_DEBUG, tts_tag(), "[Server DEBUG] tts_pause is called. Do not request to play");
271 return TTSD_ERROR_NONE;
274 if (0 != ttsd_player_play(uid)) {
275 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
277 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
279 int tmp_pid = ttsd_data_get_pid(uid);
281 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] uid(%d) is already destroyed or invalid", uid);
283 /* Change ready state */
284 ttsd_server_stop(uid);
286 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
290 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
291 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
295 /*SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS RESULT CALLBACK END");
296 SLOG(LOG_DEBUG, tts_tag(), " ");*/
298 return TTSD_ERROR_NONE;
301 bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
303 /* clear client data */
304 ttsd_data_clear_data(uid);
306 if (APP_STATE_READY != state) {
307 ttsd_data_set_client_state(uid, APP_STATE_READY);
310 if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
312 ttsd_data_delete_client(uid);
319 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
322 case TTS_CONFIG_TYPE_ENGINE:
324 /* TODO - Determine the policy when engine process get engine changed cb */
325 if (NULL == str_param) {
326 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
331 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
332 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
333 ret = ttsd_engine_agent_unload_current_engine();
335 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
338 ret = ttsd_engine_agent_load_current_engine();
340 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
345 /* stop all player */
346 ttsd_player_all_stop();
348 /* send interrupt message to all clients */
349 ttsd_data_foreach_clients(__get_client_cb, NULL);
351 ttsd_engine_cancel_synthesis();
356 case TTS_CONFIG_TYPE_VOICE:
358 if (NULL == str_param) {
359 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
363 char* out_lang = NULL;
367 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
368 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
369 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
371 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
373 /* Current language is not available */
374 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
376 if (NULL != out_lang) {
383 case TTS_CONFIG_TYPE_SPEED:
385 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
386 /* set default speed */
388 ret = ttsd_engine_agent_set_default_speed(int_param);
390 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
396 case TTS_CONFIG_TYPE_PITCH:
398 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
399 /* set default speed */
401 ret = ttsd_engine_agent_set_default_pitch(int_param);
403 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
409 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
411 if (0.0 <= double_param && double_param <= 1.0) {
412 /* set default bg volume ratio */
414 ret = ttsd_player_set_background_volume_ratio(double_param);
416 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
426 bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
428 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
429 ttsd_server_finalize(uid);
433 Eina_Bool ttsd_terminate_daemon(void *data)
435 ttsd_data_foreach_clients(__terminate_client, NULL);
436 g_terminate_timer = NULL;
440 void __screen_reader_changed_cb(bool value)
442 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
443 SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
444 if (g_terminate_timer) {
445 ecore_timer_del(g_terminate_timer);
446 g_terminate_timer = NULL;
448 g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL);
450 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
455 int ttsd_send_all_stop()
457 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
459 /* stop all player */
460 ttsd_player_all_stop();
462 /* send interrupt message to all clients */
463 ttsd_data_foreach_clients(__get_client_cb, NULL);
465 return TTSD_ERROR_NONE;
471 int ttsd_initialize(ttse_request_callback_s *callback)
473 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
475 if (ttsd_config_initialize(__config_changed_cb)) {
476 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
480 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
482 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
483 int ret = ttsd_player_set_background_volume_ratio(ratio);
485 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
488 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
491 if (ttsd_player_init()) {
492 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
493 return TTSD_ERROR_OPERATION_FAILED;
496 /* Engine Agent initialize */
497 if (0 != ttsd_engine_agent_init()) {
498 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
499 return TTSD_ERROR_OPERATION_FAILED;
502 /* set current engine */
503 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
504 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
505 // g_is_engine = false;
507 // g_is_engine = true;
509 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
510 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
511 return TTSD_ERROR_OPERATION_FAILED;
514 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
516 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
517 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
520 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
521 if (NULL == g_check_client_timer) {
522 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
525 return TTSD_ERROR_NONE;
530 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
533 if (0 < g_list_length(g_proc_list)) {
534 iter = g_list_first(g_proc_list);
535 while (NULL != iter) {
536 g_proc_list = g_list_remove_link(g_proc_list, iter);
538 iter = g_list_first(g_proc_list);
542 ttsd_config_finalize();
544 ttsd_player_release();
546 ttsd_engine_agent_release();
550 ecore_timer_del(g_wait_timer);
552 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
555 if (g_terminate_timer) {
556 ecore_timer_del(g_terminate_timer);
557 g_terminate_timer = NULL;
558 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore terminating timer handle");
561 if (NULL != g_check_client_timer) {
562 ecore_timer_del(g_check_client_timer);
563 g_check_client_timer = NULL;
564 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
567 return TTSD_ERROR_NONE;
572 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
574 ttsd_terminate_daemon(NULL);
576 ttsd_ipc_close_connection();
577 ttsd_network_finalize();
580 return TTSD_ERROR_NONE;
584 * TTS Server Functions for Client
587 int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized)
589 if (-1 != ttsd_data_is_client(uid))
590 *is_initialized = true;
592 *is_initialized = false;
594 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), Uid(%d) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
595 return TTSD_ERROR_NONE;
598 int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
600 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
602 if (-1 != ttsd_data_is_client(uid) && false == ttsd_data_is_client_use_tidl(uid)) {
603 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
604 return TTSD_ERROR_NONE;
607 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
608 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
609 return TTSD_ERROR_OPERATION_FAILED;
612 if (true == *credential_needed) {
614 if (0 != app_manager_get_app_id(pid, &appid)) {
615 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
617 bool is_agreed = false;
618 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
619 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
622 return TTSD_ERROR_OPERATION_FAILED;
627 if (false == is_agreed) {
628 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
629 return TTSD_ERROR_PERMISSION_DENIED;
633 if (false == ttsd_data_is_client_use_tidl(uid)) {
634 if (0 != ttsd_data_new_client(pid, uid)) {
635 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
636 return TTSD_ERROR_OPERATION_FAILED;
640 if (0 != ttsd_player_create_instance(uid)) {
641 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
642 return TTSD_ERROR_OPERATION_FAILED;
645 return TTSD_ERROR_NONE;
648 static Eina_Bool __quit_ecore_loop(void *data)
650 ttsd_ipc_close_connection();
651 ttsd_network_finalize();
653 ecore_main_loop_quit();
659 static void __read_proc()
662 struct dirent *dirp = NULL;
666 if (0 < g_list_length(g_proc_list)) {
667 iter = g_list_first(g_proc_list);
668 while (NULL != iter) {
669 g_proc_list = g_list_remove_link(g_proc_list, iter);
671 iter = g_list_first(g_proc_list);
675 dp = opendir("/proc");
677 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
683 tmp = atoi(dirp->d_name);
684 if (0 >= tmp) continue;
685 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
687 } while (NULL != dirp);
693 bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
699 for (i = 0; i < g_list_length(g_proc_list); i++) {
700 iter = g_list_nth(g_proc_list, i);
702 if (pid == GPOINTER_TO_INT(iter->data)) {
703 SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
710 if (false == exist) {
711 SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
712 ttsd_server_finalize(uid);
717 char appid[1024] = {0, };
718 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
719 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
722 if (0 < strlen(appid)) {
723 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
725 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
728 result = ttsdc_send_hello(pid, uid);
731 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
732 ttsd_server_finalize(uid);
733 } else if (-1 == result) {
734 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
742 Eina_Bool ttsd_cleanup_client(void *data)
744 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
747 if (0 < ttsd_data_get_client_count()) {
748 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
750 ecore_timer_add(0, __quit_ecore_loop, NULL);
751 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
752 g_check_client_timer = NULL;
756 SLOG(LOG_DEBUG, tts_tag(), "@@@");
761 void __used_voice_cb(const char* lang, int type)
763 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
764 if (0 != ttsd_engine_unload_voice(lang, type)) {
765 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
769 int ttsd_server_finalize(int uid)
771 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
773 app_tts_state_e state;
774 if (0 > ttsd_data_get_client_state(uid, &state)) {
775 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
778 ttsd_server_stop(uid);
779 ttsd_player_clear(uid);
781 ttsd_player_destroy_instance(uid);
783 /* Need to unload voice when used voice is unregistered */
784 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
785 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
786 return TTSD_ERROR_OPERATION_FAILED;
789 ttsd_data_delete_client(uid);
791 /* unload engine, if ref count of client is 0 */
792 if (0 == ttsd_data_get_client_count()) {
793 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
794 ecore_timer_add(0, __quit_ecore_loop, NULL);
797 return TTSD_ERROR_NONE;
800 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
802 app_tts_state_e state;
803 if (0 > ttsd_data_get_client_state(uid, &state)) {
804 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
805 return TTSD_ERROR_INVALID_PARAMETER;
808 /* check valid voice */
809 char* temp_lang = NULL;
811 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
812 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
813 if (NULL != temp_lang) {
817 return TTSD_ERROR_INVALID_VOICE;
820 if (NULL == temp_lang) {
821 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
822 return TTSD_ERROR_INVALID_VOICE;
825 speak_data_s* speak_data = NULL;
826 speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
827 if (NULL == speak_data) {
828 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
829 if (NULL != temp_lang) {
833 return TTSD_ERROR_OPERATION_FAILED;
836 speak_data->lang = strdup(lang);
837 speak_data->vctype = voice_type;
839 speak_data->speed = speed;
840 speak_data->utt_id = utt_id;
842 speak_data->text = strdup(text);
844 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);
846 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
848 ret = ttsd_data_add_speak_data(uid, speak_data);
850 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
851 if (NULL != temp_lang) {
855 if (NULL != speak_data) {
856 if (NULL != speak_data->lang) free(speak_data->lang);
857 if (NULL != speak_data->text) free(speak_data->text);
859 speak_data->lang = NULL;
860 speak_data->text = NULL;
869 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
870 /* Request load voice */
871 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
872 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
873 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
877 if (NULL != temp_lang) {
882 if (APP_STATE_PLAYING == state) {
883 /* check if engine use network */
884 if (ttsd_engine_agent_need_network()) {
885 if (false == ttsd_network_is_connected()) {
886 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
887 return TTSD_ERROR_OPERATION_FAILED;
891 /* Check whether tts-engine is running or not */
892 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
893 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
895 __synthesis(uid, credential);
899 return TTSD_ERROR_NONE;
902 Eina_Bool __send_interrupt_client(void *data)
904 intptr_t puid = (intptr_t)data;
907 int pid = ttsd_data_get_pid(uid);
909 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d), pid(%d)", uid, pid);
913 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
914 /* send message to client about changing state */
915 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
917 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
923 int ttsd_server_play(int uid, const char* credential)
925 app_tts_state_e state;
926 if (0 > ttsd_data_get_client_state(uid, &state)) {
927 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
928 return TTSD_ERROR_INVALID_PARAMETER;
931 if (APP_STATE_PLAYING == state) {
932 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
933 return TTSD_ERROR_NONE;
936 /* check if engine use network */
937 if (ttsd_engine_agent_need_network()) {
938 if (false == ttsd_network_is_connected()) {
939 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
940 return TTSD_ERROR_OUT_OF_NETWORK;
944 /* check the current playback focus */
945 if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
946 bool is_current_interrupt = false;
947 if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
948 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
950 if (true == is_current_interrupt) {
951 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
952 ttsd_data_clear_data(uid);
953 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
958 int current_uid = ttsd_data_get_current_playing();
959 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
961 if (uid != current_uid && -1 != current_uid) {
962 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
963 /* Send interrupt message */
964 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
967 if (0 != ttsd_server_stop(current_uid)) {
968 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
971 intptr_t pcurrent_uid = (intptr_t)current_uid;
972 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
974 /* Default mode policy of interrupt is "Pause" */
976 /* Send interrupt message */
977 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
980 if (0 != ttsd_player_pause(current_uid)) {
981 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
985 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
987 intptr_t pcurrent_uid = (intptr_t)current_uid;
988 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
992 /* Change current play */
993 if (0 != ttsd_player_wait_to_play(uid)) {
994 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
997 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
998 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
999 return TTSD_ERROR_OPERATION_FAILED;
1002 if (APP_STATE_PAUSED == state) {
1003 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1005 g_is_paused = false;
1008 if (0 != ttsd_player_resume(uid)) {
1009 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1013 /* Check whether tts-engine is running or not */
1014 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
1015 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1017 __synthesis(uid, credential);
1020 return TTSD_ERROR_NONE;
1023 int ttsd_server_stop(int uid)
1025 app_tts_state_e state;
1026 if (0 > ttsd_data_get_client_state(uid, &state)) {
1027 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1028 return TTSD_ERROR_INVALID_PARAMETER;
1031 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1033 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1034 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
1035 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1038 ret = ttsd_engine_cancel_synthesis();
1040 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1042 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1045 if (0 != ttsd_player_stop(uid)) {
1046 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1049 ttsd_data_set_client_state(uid, APP_STATE_READY);
1052 /* Reset all data */
1053 ttsd_data_clear_data(uid);
1054 g_is_paused = false;
1056 return TTSD_ERROR_NONE;
1059 int ttsd_server_pause(int uid, int* utt_id)
1061 app_tts_state_e state;
1062 if (0 > ttsd_data_get_client_state(uid, &state)) {
1063 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1064 return TTSD_ERROR_INVALID_PARAMETER;
1067 if (APP_STATE_PLAYING != state) {
1068 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1069 return TTSD_ERROR_INVALID_STATE;
1074 *utt_id = g_utt.uttid;
1075 SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
1078 ret = ttsd_player_pause(uid);
1080 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1081 return TTSD_ERROR_OPERATION_FAILED;
1084 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1086 return TTSD_ERROR_NONE;
1089 int ttsd_server_get_support_voices(int uid, GList** voice_list)
1091 app_tts_state_e state;
1092 if (0 > ttsd_data_get_client_state(uid, &state)) {
1093 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1094 return TTSD_ERROR_INVALID_PARAMETER;
1098 int ret = ttsd_engine_get_voice_list(voice_list);
1100 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1104 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1106 return TTSD_ERROR_NONE;
1109 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
1111 app_tts_state_e state;
1112 if (0 > ttsd_data_get_client_state(uid, &state)) {
1113 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1114 return TTSD_ERROR_INVALID_PARAMETER;
1117 /* get current voice */
1118 int ret = ttsd_engine_get_default_voice(language, voice_type);
1120 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1124 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1126 return TTSD_ERROR_NONE;
1129 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
1131 app_tts_state_e state;
1132 if (0 > ttsd_data_get_client_state(uid, &state)) {
1133 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1134 return TTSD_ERROR_INVALID_PARAMETER;
1137 if (APP_STATE_READY != state) {
1138 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1139 return TTSD_ERROR_INVALID_STATE;
1142 int ret = ttsd_engine_set_private_data(key, data);
1144 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1146 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1152 int ttsd_server_get_private_data(int uid, const char* key, char** data)
1154 app_tts_state_e state;
1155 if (0 > ttsd_data_get_client_state(uid, &state)) {
1156 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1157 return TTSD_ERROR_INVALID_PARAMETER;
1160 if (APP_STATE_READY != state) {
1161 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1162 return TTSD_ERROR_INVALID_STATE;
1165 int ret = ttsd_engine_get_private_data(key, data);
1167 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1169 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1175 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1177 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1180 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1182 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1188 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1190 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1193 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1195 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1201 int ttsd_server_play_pcm(int uid)
1203 app_tts_state_e state;
1204 if (0 > ttsd_data_get_client_state(uid, &state)) {
1205 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
1206 return TTSD_ERROR_INVALID_PARAMETER;
1209 if (APP_STATE_PLAYING == state) {
1210 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
1211 return TTSD_ERROR_NONE;
1214 int current_uid = ttsd_data_get_current_playing();
1215 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
1217 if (uid != current_uid && -1 != current_uid) {
1218 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
1219 /* Send interrupt message */
1220 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
1223 if (0 != ttsd_server_stop(current_uid)) {
1224 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
1227 intptr_t pcurrent_uid = (intptr_t)current_uid;
1228 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1230 /* Default mode policy of interrupt is "Pause" */
1232 /* Send interrupt message */
1233 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
1236 if (0 != ttsd_player_pause(current_uid)) {
1237 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
1241 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
1243 intptr_t pcurrent_uid = (intptr_t)current_uid;
1244 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1248 /* Change current play */
1249 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1250 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1251 return TTSD_ERROR_OPERATION_FAILED;
1254 if (APP_STATE_PAUSED == state) {
1255 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1258 if (0 != ttsd_player_resume(uid)) {
1259 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1262 if (0 != ttsd_player_play_pcm(uid)) {
1263 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
1265 // Change ready state
1266 ttsd_server_stop_pcm(uid);
1268 int tmp_pid = ttsd_data_get_pid(uid);
1270 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
1272 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1277 return TTSD_ERROR_NONE;
1280 int ttsd_server_stop_pcm(int uid)
1282 app_tts_state_e state;
1283 if (0 > ttsd_data_get_client_state(uid, &state)) {
1284 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1285 return TTSD_ERROR_INVALID_PARAMETER;
1288 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1290 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
1291 ttsd_data_set_client_state(uid, APP_STATE_READY);
1294 /* Reset all data */
1295 ttsd_data_clear_data(uid);
1297 ttsd_player_stop(uid);
1300 return TTSD_ERROR_NONE;
1303 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
1305 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1309 /* Synthesis is success */
1310 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1311 if (TTSE_RESULT_EVENT_START == event) {
1312 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1313 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1314 uid, uttid, data, data_size, audio_type, rate);
1315 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1316 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1317 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1318 uid, uttid, data, data_size, audio_type, rate);
1320 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1323 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1324 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1325 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1326 return TTSD_ERROR_INVALID_PARAMETER;
1330 sound_data_s* temp_sound_data = NULL;
1331 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
1332 if (NULL == temp_sound_data) {
1333 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1334 return TTSD_ERROR_OUT_OF_MEMORY;
1337 temp_sound_data->data = NULL;
1338 temp_sound_data->rate = 0;
1339 temp_sound_data->data_size = 0;
1341 if (0 < data_size) {
1342 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
1343 if (NULL != temp_sound_data->data) {
1344 memcpy(temp_sound_data->data, data, data_size);
1345 temp_sound_data->data_size = data_size;
1346 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
1347 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
1349 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
1352 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
1355 temp_sound_data->utt_id = uttid;
1356 temp_sound_data->event = event;
1357 temp_sound_data->audio_type = audio_type;
1358 temp_sound_data->rate = rate;
1360 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
1361 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
1363 if (NULL != temp_sound_data->data) {
1364 free(temp_sound_data->data);
1365 temp_sound_data->data = NULL;
1368 free(temp_sound_data);
1369 temp_sound_data = NULL;
1372 /* if (0 != ttsd_player_play(uid)) {
1373 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
1375 // Change ready state
1376 ttsd_server_stop(uid);
1379 tmp_pid = ttsd_data_get_pid(uid);
1380 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1384 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1387 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1389 return TTSD_ERROR_NONE;