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(&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(&speak_data);
142 ttsd_data_clear_speak_data(&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 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
192 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
193 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
194 SLOG(LOG_DEBUG, tts_tag(), "@@@");
195 return TTSD_ERROR_INVALID_PARAMETER;
198 if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) {
199 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
200 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
201 return TTSD_ERROR_INVALID_PARAMETER;
204 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
205 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
206 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
207 SLOG(LOG_DEBUG, tts_tag(), "@@@");
208 return TTSD_ERROR_INVALID_PARAMETER;
211 /* Synthesis is success */
212 if (TTSE_RESULT_EVENT_START == event) {
213 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
214 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
215 uid, uttid, data, data_size, audio_type, rate);
216 } else if (TTSE_RESULT_EVENT_FINISH == event) {
217 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
218 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
219 uid, uttid, data, data_size, audio_type, rate);
221 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
225 sound_data_s* temp_sound_data = NULL;
226 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
227 if (NULL == temp_sound_data) {
228 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
229 return TTSD_ERROR_OUT_OF_MEMORY;
232 temp_sound_data->data = NULL;
233 temp_sound_data->rate = 0;
234 temp_sound_data->data_size = 0;
236 if (NULL != data && 0 < data_size) {
237 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
238 if (NULL != temp_sound_data->data) {
239 memcpy(temp_sound_data->data, data, data_size);
240 temp_sound_data->data_size = data_size;
241 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
242 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
244 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
247 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
250 temp_sound_data->utt_id = uttid;
251 temp_sound_data->event = event;
252 temp_sound_data->audio_type = audio_type;
253 temp_sound_data->rate = rate;
255 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
256 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
257 if (NULL != temp_sound_data->data) {
258 free(temp_sound_data->data);
259 temp_sound_data->data = NULL;
262 free(temp_sound_data);
263 temp_sound_data = NULL;
265 return TTSD_ERROR_OPERATION_FAILED;
268 if (event == TTSE_RESULT_EVENT_FINISH) {
269 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
272 /* If the app state is paused, do not result to play */
273 if (true == g_is_paused) {
274 SLOG(LOG_DEBUG, tts_tag(), "[Server DEBUG] tts_pause is called. Do not request to play");
275 return TTSD_ERROR_NONE;
278 app_tts_state_e state = APP_STATE_CREATED;
279 if (0 != ttsd_data_get_client_state(uid, &state)) {
280 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
281 return TTSD_ERROR_INVALID_PARAMETER;
284 if (APP_STATE_PLAYING != state) {
285 SLOG(LOG_INFO, tts_tag(), "[Server] client state is not playing");
286 return TTSD_ERROR_NONE;
289 if (0 != ttsd_player_play(uid)) {
290 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
292 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
294 int tmp_pid = ttsd_data_get_pid(uid);
296 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] uid(%d) is already destroyed or invalid", uid);
298 /* Change ready state */
299 ttsd_server_stop(uid);
301 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
305 return TTSD_ERROR_NONE;
308 bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
310 /* clear client data */
311 ttsd_data_clear_data(uid);
313 if (APP_STATE_READY != state) {
314 ttsd_data_set_client_state(uid, APP_STATE_READY);
317 if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
319 ttsd_data_delete_client(uid);
326 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
329 case TTS_CONFIG_TYPE_ENGINE:
331 /* TODO - Determine the policy when engine process get engine changed cb */
332 if (NULL == str_param) {
333 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
338 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
339 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
340 ret = ttsd_engine_agent_unload_current_engine();
342 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
345 ret = ttsd_engine_agent_load_current_engine();
347 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
352 /* stop all player */
353 ttsd_player_all_stop();
355 /* send interrupt message to all clients */
356 ttsd_data_foreach_clients(__get_client_cb, NULL);
358 ttsd_engine_cancel_synthesis();
363 case TTS_CONFIG_TYPE_VOICE:
365 if (NULL == str_param) {
366 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
370 char* out_lang = NULL;
374 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
375 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
376 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
378 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
380 /* Current language is not available */
381 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
383 if (NULL != out_lang) {
390 case TTS_CONFIG_TYPE_SPEED:
392 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
393 /* set default speed */
395 ret = ttsd_engine_agent_set_default_speed(int_param);
397 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
403 case TTS_CONFIG_TYPE_PITCH:
405 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
406 /* set default speed */
408 ret = ttsd_engine_agent_set_default_pitch(int_param);
410 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
416 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
418 if (0.0 <= double_param && double_param <= 1.0) {
419 /* set default bg volume ratio */
421 ret = ttsd_player_set_background_volume_ratio(double_param);
423 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
433 bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
435 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
436 ttsd_server_finalize(uid);
440 Eina_Bool ttsd_terminate_daemon(void *data)
442 ttsd_data_foreach_clients(__terminate_client, NULL);
443 g_terminate_timer = NULL;
447 void __screen_reader_changed_cb(bool value)
449 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
450 SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
451 if (g_terminate_timer) {
452 ecore_timer_del(g_terminate_timer);
453 g_terminate_timer = NULL;
455 g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL);
457 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
462 int ttsd_send_all_stop()
464 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
466 /* stop all player */
467 ttsd_player_all_stop();
469 /* send interrupt message to all clients */
470 ttsd_data_foreach_clients(__get_client_cb, NULL);
472 return TTSD_ERROR_NONE;
478 int ttsd_initialize(ttse_request_callback_s *callback)
480 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
482 if (ttsd_config_initialize(__config_changed_cb)) {
483 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
487 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
489 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
490 int ret = ttsd_player_set_background_volume_ratio(ratio);
492 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
495 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
498 if (ttsd_player_init()) {
499 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
500 return TTSD_ERROR_OPERATION_FAILED;
503 /* Engine Agent initialize */
504 if (0 != ttsd_engine_agent_init()) {
505 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
506 return TTSD_ERROR_OPERATION_FAILED;
509 /* set current engine */
510 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
511 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
512 // g_is_engine = false;
514 // g_is_engine = true;
516 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
517 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
518 return TTSD_ERROR_OPERATION_FAILED;
521 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
523 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
524 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
527 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
528 if (NULL == g_check_client_timer) {
529 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
532 return TTSD_ERROR_NONE;
537 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
540 if (0 < g_list_length(g_proc_list)) {
541 iter = g_list_first(g_proc_list);
542 while (NULL != iter) {
543 g_proc_list = g_list_remove_link(g_proc_list, iter);
545 iter = g_list_first(g_proc_list);
549 ttsd_config_finalize();
551 ttsd_player_release();
553 ttsd_engine_agent_release();
557 ecore_timer_del(g_wait_timer);
559 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
562 if (g_terminate_timer) {
563 ecore_timer_del(g_terminate_timer);
564 g_terminate_timer = NULL;
565 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore terminating timer handle");
568 if (NULL != g_check_client_timer) {
569 ecore_timer_del(g_check_client_timer);
570 g_check_client_timer = NULL;
571 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
574 return TTSD_ERROR_NONE;
579 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
581 ttsd_terminate_daemon(NULL);
583 ttsd_ipc_close_connection();
584 ttsd_network_finalize();
587 return TTSD_ERROR_NONE;
591 * TTS Server Functions for Client
594 int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized)
596 if (-1 != ttsd_data_is_client(uid))
597 *is_initialized = true;
599 *is_initialized = false;
601 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), Uid(%d) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
602 return TTSD_ERROR_NONE;
605 int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* credential_needed)
607 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
609 if (-1 != ttsd_data_is_client(uid)) {
610 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
611 return TTSD_ERROR_NONE;
614 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
615 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
616 return TTSD_ERROR_OPERATION_FAILED;
619 if (true == *credential_needed) {
621 if (0 != app_manager_get_app_id(pid, &appid)) {
622 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
624 bool is_agreed = false;
625 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
626 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
629 return TTSD_ERROR_OPERATION_FAILED;
634 if (false == is_agreed) {
635 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
636 return TTSD_ERROR_PERMISSION_DENIED;
640 if (0 != ttsd_data_new_client(pid, uid)) {
641 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
642 return TTSD_ERROR_OPERATION_FAILED;
645 if (0 != ttsd_data_set_ipc_method(uid, method)) {
646 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set ipc method");
647 return TTSD_ERROR_OPERATION_FAILED;
650 if (0 != ttsd_player_create_instance(uid)) {
651 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
652 return TTSD_ERROR_OPERATION_FAILED;
655 return TTSD_ERROR_NONE;
658 static Eina_Bool __quit_ecore_loop(void *data)
660 ttsd_ipc_close_connection();
661 ttsd_network_finalize();
663 ecore_main_loop_quit();
669 static void __read_proc()
672 struct dirent *dirp = NULL;
676 if (0 < g_list_length(g_proc_list)) {
677 iter = g_list_first(g_proc_list);
678 while (NULL != iter) {
679 g_proc_list = g_list_remove_link(g_proc_list, iter);
681 iter = g_list_first(g_proc_list);
685 dp = opendir("/proc");
687 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
693 tmp = atoi(dirp->d_name);
694 if (0 >= tmp) continue;
695 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
697 } while (NULL != dirp);
703 bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
709 for (i = 0; i < g_list_length(g_proc_list); i++) {
710 iter = g_list_nth(g_proc_list, i);
712 if (pid == GPOINTER_TO_INT(iter->data)) {
713 SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
720 if (false == exist) {
721 SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
722 ttsd_server_finalize(uid);
727 char appid[1024] = {0, };
728 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
729 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
732 if (0 < strlen(appid)) {
733 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
735 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
738 result = ttsdc_send_hello(pid, uid);
741 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
742 ttsd_server_finalize(uid);
743 } else if (-1 == result) {
744 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
752 Eina_Bool ttsd_cleanup_client(void *data)
754 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
757 if (0 < ttsd_data_get_client_count()) {
758 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
760 ecore_timer_add(0, __quit_ecore_loop, NULL);
761 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
762 g_check_client_timer = NULL;
766 SLOG(LOG_DEBUG, tts_tag(), "@@@");
771 void __used_voice_cb(const char* lang, int type)
773 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
774 if (0 != ttsd_engine_unload_voice(lang, type)) {
775 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
779 int ttsd_server_finalize(int uid)
781 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
783 app_tts_state_e state;
784 if (0 > ttsd_data_get_client_state(uid, &state)) {
785 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
788 ttsd_server_stop(uid);
789 ttsd_player_clear(uid);
791 ttsd_player_destroy_instance(uid);
793 /* Need to unload voice when used voice is unregistered */
794 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
795 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
796 return TTSD_ERROR_OPERATION_FAILED;
799 ttsd_data_delete_client(uid);
801 /* unload engine, if ref count of client is 0 */
802 if (0 == ttsd_data_get_client_count()) {
803 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
804 ecore_timer_add(0, __quit_ecore_loop, NULL);
807 return TTSD_ERROR_NONE;
810 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
812 app_tts_state_e state;
813 if (0 > ttsd_data_get_client_state(uid, &state)) {
814 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
815 return TTSD_ERROR_INVALID_PARAMETER;
818 /* check valid voice */
819 char* temp_lang = NULL;
821 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
822 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
823 if (NULL != temp_lang) {
827 return TTSD_ERROR_INVALID_VOICE;
830 if (NULL == temp_lang) {
831 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
832 return TTSD_ERROR_INVALID_VOICE;
835 speak_data_s* speak_data = NULL;
836 speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
837 if (NULL == speak_data) {
838 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
839 if (NULL != temp_lang) {
843 return TTSD_ERROR_OPERATION_FAILED;
846 speak_data->lang = strdup(lang);
847 speak_data->vctype = voice_type;
849 speak_data->speed = speed;
850 speak_data->utt_id = utt_id;
852 speak_data->text = strdup(text);
854 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);
856 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
858 ret = ttsd_data_add_speak_data(uid, speak_data);
860 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
861 if (NULL != temp_lang) {
865 if (NULL != speak_data) {
866 if (NULL != speak_data->lang) free(speak_data->lang);
867 if (NULL != speak_data->text) free(speak_data->text);
869 speak_data->lang = NULL;
870 speak_data->text = NULL;
879 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
880 /* Request load voice */
881 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
882 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
883 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
887 if (NULL != temp_lang) {
892 if (APP_STATE_PLAYING == state) {
893 /* check if engine use network */
894 if (ttsd_engine_agent_need_network()) {
895 if (false == ttsd_network_is_connected()) {
896 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
897 return TTSD_ERROR_OPERATION_FAILED;
901 /* Check whether tts-engine is running or not */
902 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
903 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
905 __synthesis(uid, credential);
909 return TTSD_ERROR_NONE;
912 Eina_Bool __send_interrupt_client(void *data)
914 intptr_t puid = (intptr_t)data;
917 int pid = ttsd_data_get_pid(uid);
919 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d), pid(%d)", uid, pid);
923 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
924 /* send message to client about changing state */
925 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
927 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
933 int ttsd_server_play(int uid, const char* credential)
935 app_tts_state_e state;
936 if (0 > ttsd_data_get_client_state(uid, &state)) {
937 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
938 return TTSD_ERROR_INVALID_PARAMETER;
941 if (APP_STATE_PLAYING == state) {
942 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
943 return TTSD_ERROR_NONE;
946 /* check if engine use network */
947 if (ttsd_engine_agent_need_network()) {
948 if (false == ttsd_network_is_connected()) {
949 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
950 return TTSD_ERROR_OUT_OF_NETWORK;
954 /* check the current playback focus */
955 if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
956 bool is_current_interrupt = false;
957 if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
958 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
960 if (true == is_current_interrupt) {
961 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
962 ttsd_data_clear_data(uid);
963 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
968 int current_uid = ttsd_data_get_current_playing();
969 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
971 if (uid != current_uid && -1 != current_uid) {
972 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
973 /* Send interrupt message */
974 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
977 if (0 != ttsd_server_stop(current_uid)) {
978 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
981 intptr_t pcurrent_uid = (intptr_t)current_uid;
982 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
984 /* Default mode policy of interrupt is "Pause" */
986 /* Send interrupt message */
987 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
990 if (0 != ttsd_player_pause(current_uid)) {
991 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
995 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
997 intptr_t pcurrent_uid = (intptr_t)current_uid;
998 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1002 /* Change current play */
1003 if (0 != ttsd_player_wait_to_play(uid)) {
1004 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
1007 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1008 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1009 return TTSD_ERROR_OPERATION_FAILED;
1012 if (APP_STATE_PAUSED == state) {
1013 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1015 g_is_paused = false;
1018 if (0 != ttsd_player_resume(uid)) {
1019 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1023 /* Check whether tts-engine is running or not */
1024 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
1025 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1027 __synthesis(uid, credential);
1030 return TTSD_ERROR_NONE;
1033 int ttsd_server_stop(int uid)
1035 app_tts_state_e state;
1036 if (0 > ttsd_data_get_client_state(uid, &state)) {
1037 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1038 return TTSD_ERROR_INVALID_PARAMETER;
1041 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1043 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1044 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
1045 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1048 ret = ttsd_engine_cancel_synthesis();
1050 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1052 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1055 if (0 != ttsd_player_stop(uid)) {
1056 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1059 ttsd_data_set_client_state(uid, APP_STATE_READY);
1062 /* Reset all data */
1063 ttsd_data_clear_data(uid);
1064 g_is_paused = false;
1066 return TTSD_ERROR_NONE;
1069 int ttsd_server_pause(int uid, int* utt_id)
1071 app_tts_state_e state;
1072 if (0 > ttsd_data_get_client_state(uid, &state)) {
1073 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1074 return TTSD_ERROR_INVALID_PARAMETER;
1077 if (APP_STATE_PLAYING != state) {
1078 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1079 return TTSD_ERROR_INVALID_STATE;
1084 *utt_id = g_utt.uttid;
1085 SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
1088 ret = ttsd_player_pause(uid);
1090 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1091 return TTSD_ERROR_OPERATION_FAILED;
1094 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1096 return TTSD_ERROR_NONE;
1099 int ttsd_server_get_support_voices(int uid, GList** voice_list)
1101 app_tts_state_e state;
1102 if (0 > ttsd_data_get_client_state(uid, &state)) {
1103 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1104 return TTSD_ERROR_INVALID_PARAMETER;
1108 int ret = ttsd_engine_get_voice_list(voice_list);
1110 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1114 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1116 return TTSD_ERROR_NONE;
1119 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
1121 app_tts_state_e state;
1122 if (0 > ttsd_data_get_client_state(uid, &state)) {
1123 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1124 return TTSD_ERROR_INVALID_PARAMETER;
1127 /* get current voice */
1128 int ret = ttsd_engine_get_default_voice(language, voice_type);
1130 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1134 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1136 return TTSD_ERROR_NONE;
1139 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
1141 app_tts_state_e state;
1142 if (0 > ttsd_data_get_client_state(uid, &state)) {
1143 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1144 return TTSD_ERROR_INVALID_PARAMETER;
1147 if (APP_STATE_READY != state) {
1148 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1149 return TTSD_ERROR_INVALID_STATE;
1152 int ret = ttsd_engine_set_private_data(key, data);
1154 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1156 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1162 int ttsd_server_get_private_data(int uid, const char* key, char** data)
1164 app_tts_state_e state;
1165 if (0 > ttsd_data_get_client_state(uid, &state)) {
1166 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1167 return TTSD_ERROR_INVALID_PARAMETER;
1170 if (APP_STATE_READY != state) {
1171 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1172 return TTSD_ERROR_INVALID_STATE;
1175 int ret = ttsd_engine_get_private_data(key, data);
1177 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1179 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1185 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1187 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1190 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1192 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1198 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1200 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1203 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1205 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1211 int ttsd_server_play_pcm(int uid)
1213 app_tts_state_e state;
1214 if (0 > ttsd_data_get_client_state(uid, &state)) {
1215 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
1216 return TTSD_ERROR_INVALID_PARAMETER;
1219 if (APP_STATE_PLAYING == state) {
1220 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
1221 return TTSD_ERROR_NONE;
1224 int current_uid = ttsd_data_get_current_playing();
1225 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
1227 if (uid != current_uid && -1 != current_uid) {
1228 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
1229 /* Send interrupt message */
1230 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
1233 if (0 != ttsd_server_stop(current_uid)) {
1234 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
1237 intptr_t pcurrent_uid = (intptr_t)current_uid;
1238 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1240 /* Default mode policy of interrupt is "Pause" */
1242 /* Send interrupt message */
1243 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
1246 if (0 != ttsd_player_pause(current_uid)) {
1247 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
1251 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
1253 intptr_t pcurrent_uid = (intptr_t)current_uid;
1254 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1258 /* Change current play */
1259 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1260 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1261 return TTSD_ERROR_OPERATION_FAILED;
1264 if (APP_STATE_PAUSED == state) {
1265 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1268 if (0 != ttsd_player_resume(uid)) {
1269 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1272 if (0 != ttsd_player_play_pcm(uid)) {
1273 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
1275 // Change ready state
1276 ttsd_server_stop_pcm(uid);
1278 int tmp_pid = ttsd_data_get_pid(uid);
1280 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
1282 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1287 return TTSD_ERROR_NONE;
1290 int ttsd_server_stop_pcm(int uid)
1292 app_tts_state_e state;
1293 if (0 > ttsd_data_get_client_state(uid, &state)) {
1294 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1295 return TTSD_ERROR_INVALID_PARAMETER;
1298 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1300 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
1301 ttsd_data_set_client_state(uid, APP_STATE_READY);
1304 /* Reset all data */
1305 ttsd_data_clear_data(uid);
1307 ttsd_player_stop(uid);
1310 return TTSD_ERROR_NONE;
1313 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
1315 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1319 /* Synthesis is success */
1320 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1321 if (TTSE_RESULT_EVENT_START == event) {
1322 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1323 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1324 uid, uttid, data, data_size, audio_type, rate);
1325 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1326 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1327 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1328 uid, uttid, data, data_size, audio_type, rate);
1330 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1333 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1334 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1335 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1336 return TTSD_ERROR_INVALID_PARAMETER;
1340 sound_data_s* temp_sound_data = NULL;
1341 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
1342 if (NULL == temp_sound_data) {
1343 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1344 return TTSD_ERROR_OUT_OF_MEMORY;
1347 temp_sound_data->data = NULL;
1348 temp_sound_data->rate = 0;
1349 temp_sound_data->data_size = 0;
1351 if (0 < data_size) {
1352 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
1353 if (NULL != temp_sound_data->data) {
1354 memcpy(temp_sound_data->data, data, data_size);
1355 temp_sound_data->data_size = data_size;
1356 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
1357 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
1359 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
1362 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
1365 temp_sound_data->utt_id = uttid;
1366 temp_sound_data->event = event;
1367 temp_sound_data->audio_type = audio_type;
1368 temp_sound_data->rate = rate;
1370 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
1371 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
1373 if (NULL != temp_sound_data->data) {
1374 free(temp_sound_data->data);
1375 temp_sound_data->data = NULL;
1378 free(temp_sound_data);
1379 temp_sound_data = NULL;
1382 /* if (0 != ttsd_player_play(uid)) {
1383 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
1385 // Change ready state
1386 ttsd_server_stop(uid);
1389 tmp_pid = ttsd_data_get_pid(uid);
1390 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1394 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1397 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1399 return TTSD_ERROR_NONE;