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 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;
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, bool* credential_needed)
607 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
609 if (-1 != ttsd_data_is_client(uid) && false == ttsd_data_is_client_use_tidl(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 (false == ttsd_data_is_client_use_tidl(uid)) {
641 if (0 != ttsd_data_new_client(pid, uid)) {
642 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
643 return TTSD_ERROR_OPERATION_FAILED;
647 if (0 != ttsd_player_create_instance(uid)) {
648 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
649 return TTSD_ERROR_OPERATION_FAILED;
652 return TTSD_ERROR_NONE;
655 static Eina_Bool __quit_ecore_loop(void *data)
657 ttsd_ipc_close_connection();
658 ttsd_network_finalize();
660 ecore_main_loop_quit();
666 static void __read_proc()
669 struct dirent *dirp = NULL;
673 if (0 < g_list_length(g_proc_list)) {
674 iter = g_list_first(g_proc_list);
675 while (NULL != iter) {
676 g_proc_list = g_list_remove_link(g_proc_list, iter);
678 iter = g_list_first(g_proc_list);
682 dp = opendir("/proc");
684 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
690 tmp = atoi(dirp->d_name);
691 if (0 >= tmp) continue;
692 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
694 } while (NULL != dirp);
700 bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
706 for (i = 0; i < g_list_length(g_proc_list); i++) {
707 iter = g_list_nth(g_proc_list, i);
709 if (pid == GPOINTER_TO_INT(iter->data)) {
710 SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
717 if (false == exist) {
718 SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
719 ttsd_server_finalize(uid);
724 char appid[1024] = {0, };
725 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
726 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
729 if (0 < strlen(appid)) {
730 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
732 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
735 result = ttsdc_send_hello(pid, uid);
738 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
739 ttsd_server_finalize(uid);
740 } else if (-1 == result) {
741 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
749 Eina_Bool ttsd_cleanup_client(void *data)
751 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
754 if (0 < ttsd_data_get_client_count()) {
755 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
757 ecore_timer_add(0, __quit_ecore_loop, NULL);
758 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
759 g_check_client_timer = NULL;
763 SLOG(LOG_DEBUG, tts_tag(), "@@@");
768 void __used_voice_cb(const char* lang, int type)
770 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
771 if (0 != ttsd_engine_unload_voice(lang, type)) {
772 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
776 int ttsd_server_finalize(int uid)
778 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
780 app_tts_state_e state;
781 if (0 > ttsd_data_get_client_state(uid, &state)) {
782 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
785 ttsd_server_stop(uid);
786 ttsd_player_clear(uid);
788 ttsd_player_destroy_instance(uid);
790 /* Need to unload voice when used voice is unregistered */
791 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
792 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
793 return TTSD_ERROR_OPERATION_FAILED;
796 ttsd_data_delete_client(uid);
798 /* unload engine, if ref count of client is 0 */
799 if (0 == ttsd_data_get_client_count()) {
800 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
801 ecore_timer_add(0, __quit_ecore_loop, NULL);
804 return TTSD_ERROR_NONE;
807 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
809 app_tts_state_e state;
810 if (0 > ttsd_data_get_client_state(uid, &state)) {
811 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
812 return TTSD_ERROR_INVALID_PARAMETER;
815 /* check valid voice */
816 char* temp_lang = NULL;
818 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
819 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
820 if (NULL != temp_lang) {
824 return TTSD_ERROR_INVALID_VOICE;
827 if (NULL == temp_lang) {
828 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
829 return TTSD_ERROR_INVALID_VOICE;
832 speak_data_s* speak_data = NULL;
833 speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
834 if (NULL == speak_data) {
835 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
836 if (NULL != temp_lang) {
840 return TTSD_ERROR_OPERATION_FAILED;
843 speak_data->lang = strdup(lang);
844 speak_data->vctype = voice_type;
846 speak_data->speed = speed;
847 speak_data->utt_id = utt_id;
849 speak_data->text = strdup(text);
851 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);
853 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
855 ret = ttsd_data_add_speak_data(uid, speak_data);
857 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
858 if (NULL != temp_lang) {
862 if (NULL != speak_data) {
863 if (NULL != speak_data->lang) free(speak_data->lang);
864 if (NULL != speak_data->text) free(speak_data->text);
866 speak_data->lang = NULL;
867 speak_data->text = NULL;
876 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
877 /* Request load voice */
878 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
879 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
880 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
884 if (NULL != temp_lang) {
889 if (APP_STATE_PLAYING == state) {
890 /* check if engine use network */
891 if (ttsd_engine_agent_need_network()) {
892 if (false == ttsd_network_is_connected()) {
893 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
894 return TTSD_ERROR_OPERATION_FAILED;
898 /* Check whether tts-engine is running or not */
899 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
900 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
902 __synthesis(uid, credential);
906 return TTSD_ERROR_NONE;
909 Eina_Bool __send_interrupt_client(void *data)
911 intptr_t puid = (intptr_t)data;
914 int pid = ttsd_data_get_pid(uid);
916 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d), pid(%d)", uid, pid);
920 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
921 /* send message to client about changing state */
922 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
924 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
930 int ttsd_server_play(int uid, const char* credential)
932 app_tts_state_e state;
933 if (0 > ttsd_data_get_client_state(uid, &state)) {
934 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
935 return TTSD_ERROR_INVALID_PARAMETER;
938 if (APP_STATE_PLAYING == state) {
939 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
940 return TTSD_ERROR_NONE;
943 /* check if engine use network */
944 if (ttsd_engine_agent_need_network()) {
945 if (false == ttsd_network_is_connected()) {
946 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
947 return TTSD_ERROR_OUT_OF_NETWORK;
951 /* check the current playback focus */
952 if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
953 bool is_current_interrupt = false;
954 if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
955 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
957 if (true == is_current_interrupt) {
958 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
959 ttsd_data_clear_data(uid);
960 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
965 int current_uid = ttsd_data_get_current_playing();
966 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
968 if (uid != current_uid && -1 != current_uid) {
969 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
970 /* Send interrupt message */
971 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
974 if (0 != ttsd_server_stop(current_uid)) {
975 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
978 intptr_t pcurrent_uid = (intptr_t)current_uid;
979 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
981 /* Default mode policy of interrupt is "Pause" */
983 /* Send interrupt message */
984 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
987 if (0 != ttsd_player_pause(current_uid)) {
988 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
992 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
994 intptr_t pcurrent_uid = (intptr_t)current_uid;
995 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
999 /* Change current play */
1000 if (0 != ttsd_player_wait_to_play(uid)) {
1001 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
1004 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1005 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1006 return TTSD_ERROR_OPERATION_FAILED;
1009 if (APP_STATE_PAUSED == state) {
1010 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1012 g_is_paused = false;
1015 if (0 != ttsd_player_resume(uid)) {
1016 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1020 /* Check whether tts-engine is running or not */
1021 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
1022 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1024 __synthesis(uid, credential);
1027 return TTSD_ERROR_NONE;
1030 int ttsd_server_stop(int uid)
1032 app_tts_state_e state;
1033 if (0 > ttsd_data_get_client_state(uid, &state)) {
1034 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1035 return TTSD_ERROR_INVALID_PARAMETER;
1038 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1040 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1041 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
1042 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1045 ret = ttsd_engine_cancel_synthesis();
1047 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1049 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1052 if (0 != ttsd_player_stop(uid)) {
1053 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1056 ttsd_data_set_client_state(uid, APP_STATE_READY);
1059 /* Reset all data */
1060 ttsd_data_clear_data(uid);
1061 g_is_paused = false;
1063 return TTSD_ERROR_NONE;
1066 int ttsd_server_pause(int uid, int* utt_id)
1068 app_tts_state_e state;
1069 if (0 > ttsd_data_get_client_state(uid, &state)) {
1070 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1071 return TTSD_ERROR_INVALID_PARAMETER;
1074 if (APP_STATE_PLAYING != state) {
1075 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1076 return TTSD_ERROR_INVALID_STATE;
1081 *utt_id = g_utt.uttid;
1082 SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
1085 ret = ttsd_player_pause(uid);
1087 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1088 return TTSD_ERROR_OPERATION_FAILED;
1091 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1093 return TTSD_ERROR_NONE;
1096 int ttsd_server_get_support_voices(int uid, GList** voice_list)
1098 app_tts_state_e state;
1099 if (0 > ttsd_data_get_client_state(uid, &state)) {
1100 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1101 return TTSD_ERROR_INVALID_PARAMETER;
1105 int ret = ttsd_engine_get_voice_list(voice_list);
1107 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1111 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1113 return TTSD_ERROR_NONE;
1116 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
1118 app_tts_state_e state;
1119 if (0 > ttsd_data_get_client_state(uid, &state)) {
1120 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1121 return TTSD_ERROR_INVALID_PARAMETER;
1124 /* get current voice */
1125 int ret = ttsd_engine_get_default_voice(language, voice_type);
1127 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1131 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1133 return TTSD_ERROR_NONE;
1136 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
1138 app_tts_state_e state;
1139 if (0 > ttsd_data_get_client_state(uid, &state)) {
1140 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1141 return TTSD_ERROR_INVALID_PARAMETER;
1144 if (APP_STATE_READY != state) {
1145 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1146 return TTSD_ERROR_INVALID_STATE;
1149 int ret = ttsd_engine_set_private_data(key, data);
1151 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1153 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1159 int ttsd_server_get_private_data(int uid, const char* key, char** data)
1161 app_tts_state_e state;
1162 if (0 > ttsd_data_get_client_state(uid, &state)) {
1163 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1164 return TTSD_ERROR_INVALID_PARAMETER;
1167 if (APP_STATE_READY != state) {
1168 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1169 return TTSD_ERROR_INVALID_STATE;
1172 int ret = ttsd_engine_get_private_data(key, data);
1174 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1176 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1182 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1184 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1187 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1189 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1195 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1197 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1200 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1202 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1208 int ttsd_server_play_pcm(int uid)
1210 app_tts_state_e state;
1211 if (0 > ttsd_data_get_client_state(uid, &state)) {
1212 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
1213 return TTSD_ERROR_INVALID_PARAMETER;
1216 if (APP_STATE_PLAYING == state) {
1217 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
1218 return TTSD_ERROR_NONE;
1221 int current_uid = ttsd_data_get_current_playing();
1222 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
1224 if (uid != current_uid && -1 != current_uid) {
1225 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
1226 /* Send interrupt message */
1227 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
1230 if (0 != ttsd_server_stop(current_uid)) {
1231 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
1234 intptr_t pcurrent_uid = (intptr_t)current_uid;
1235 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1237 /* Default mode policy of interrupt is "Pause" */
1239 /* Send interrupt message */
1240 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
1243 if (0 != ttsd_player_pause(current_uid)) {
1244 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
1248 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
1250 intptr_t pcurrent_uid = (intptr_t)current_uid;
1251 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1255 /* Change current play */
1256 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1257 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1258 return TTSD_ERROR_OPERATION_FAILED;
1261 if (APP_STATE_PAUSED == state) {
1262 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1265 if (0 != ttsd_player_resume(uid)) {
1266 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1269 if (0 != ttsd_player_play_pcm(uid)) {
1270 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
1272 // Change ready state
1273 ttsd_server_stop_pcm(uid);
1275 int tmp_pid = ttsd_data_get_pid(uid);
1277 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
1279 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1284 return TTSD_ERROR_NONE;
1287 int ttsd_server_stop_pcm(int uid)
1289 app_tts_state_e state;
1290 if (0 > ttsd_data_get_client_state(uid, &state)) {
1291 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1292 return TTSD_ERROR_INVALID_PARAMETER;
1295 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1297 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
1298 ttsd_data_set_client_state(uid, APP_STATE_READY);
1301 /* Reset all data */
1302 ttsd_data_clear_data(uid);
1304 ttsd_player_stop(uid);
1307 return TTSD_ERROR_NONE;
1310 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
1312 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1316 /* Synthesis is success */
1317 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1318 if (TTSE_RESULT_EVENT_START == event) {
1319 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1320 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1321 uid, uttid, data, data_size, audio_type, rate);
1322 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1323 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1324 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1325 uid, uttid, data, data_size, audio_type, rate);
1327 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1330 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1331 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1332 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1333 return TTSD_ERROR_INVALID_PARAMETER;
1337 sound_data_s* temp_sound_data = NULL;
1338 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
1339 if (NULL == temp_sound_data) {
1340 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1341 return TTSD_ERROR_OUT_OF_MEMORY;
1344 temp_sound_data->data = NULL;
1345 temp_sound_data->rate = 0;
1346 temp_sound_data->data_size = 0;
1348 if (0 < data_size) {
1349 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
1350 if (NULL != temp_sound_data->data) {
1351 memcpy(temp_sound_data->data, data, data_size);
1352 temp_sound_data->data_size = data_size;
1353 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
1354 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
1356 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
1359 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
1362 temp_sound_data->utt_id = uttid;
1363 temp_sound_data->event = event;
1364 temp_sound_data->audio_type = audio_type;
1365 temp_sound_data->rate = rate;
1367 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
1368 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
1370 if (NULL != temp_sound_data->data) {
1371 free(temp_sound_data->data);
1372 temp_sound_data->data = NULL;
1375 free(temp_sound_data);
1376 temp_sound_data = NULL;
1379 /* if (0 != ttsd_player_play(uid)) {
1380 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
1382 // Change ready state
1383 ttsd_server_stop(uid);
1386 tmp_pid = ttsd_data_get_pid(uid);
1387 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1391 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1394 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1396 return TTSD_ERROR_NONE;