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>
19 #include "ttsd_config.h"
20 #include "ttsd_data.h"
22 #include "ttsd_engine_agent.h"
23 #include "ttsd_main.h"
24 #include "ttsd_player.h"
25 #include "ttsd_server.h"
28 #define CLIENT_CLEAN_UP_TIME 500
30 /* for checking time */
31 #define TIME_DIFF(start, end) \
32 ((uint64_t)((end).tv_sec - (start).tv_sec) * 1000000 + (((end).tv_nsec - (start).tv_nsec) / 1000)) / 1000
34 static struct timespec g_request_playing, g_start_playing;
35 static double g_avg_latency;
36 static double g_min_latency;
37 static double g_max_latency;
38 static int g_file_num;
45 /* If current engine exist */
46 //static bool g_is_engine;
48 static Ecore_Timer* g_check_client_timer = NULL;
49 static Ecore_Timer* g_wait_timer = NULL;
50 static Ecore_Timer* g_quit_loop_timer = NULL;
52 static utterance_t g_utt;
54 static GList *g_proc_list = NULL;
56 static bool g_is_terminated = false;
59 /* Function definitions */
60 static int __stop_and_send_ready_state(unsigned int uid)
62 int ret = ttsd_server_stop(uid);
63 if (TTSD_ERROR_NONE != ret) {
64 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_stop() : uid(%u). ret(%d)", uid, ret);
68 int pid = ttsd_data_get_pid(uid);
70 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u)", uid);
71 return TTSD_ERROR_OPERATION_FAILED;
73 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
79 static void __synthesis(unsigned int uid);
81 static Eina_Bool __wait_synthesis(void *data)
83 /* get current play */
84 unsigned int uid = ttsd_data_get_current_playing();
87 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
88 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
91 SLOG(LOG_INFO, tts_tag(), "[Server] synth_control(%d)", synth_control);
93 if (TTSD_SYNTHESIS_CONTROL_DONE == synth_control) {
94 /* Start next synthesis */
105 static void __synthesis(unsigned int uid)
107 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
109 speak_data_s* speak_data = NULL;
110 int ret = ttsd_data_get_speak_data(uid, &speak_data);
111 if (TTSD_ERROR_NONE != ret || NULL == speak_data) {
112 SLOG(LOG_DEBUG, tts_tag(), "@@@ Fail to get speak data. ret(%d)", ret);
113 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
117 int pid = ttsd_data_get_pid(uid);
119 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u)", uid);
120 ttsd_data_destroy_speak_data(speak_data);
125 char appid[1024] = {0, };
126 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
127 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
130 if (NULL == speak_data->lang || NULL == speak_data->text) {
131 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
132 __stop_and_send_ready_state(uid);
133 ttsd_data_destroy_speak_data(speak_data);
139 g_utt.uttid = speak_data->utt_id;
141 char* credential = ttsd_data_get_credential(uid);
143 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
144 SLOG(LOG_INFO, tts_tag(), "ID : uid (%u), uttid(%d) ", g_utt.uid, g_utt.uttid);
145 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
146 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
147 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
148 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
150 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
151 ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
152 if (TTSD_ERROR_NONE != ret) {
153 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
155 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
156 __stop_and_send_ready_state(uid);
158 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
163 ttsd_data_destroy_speak_data(speak_data);
165 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
171 * TTS Server Callback Functions
173 int ttsd_send_error(ttse_error_e error, const char* msg)
175 unsigned int uid = g_utt.uid;
176 int uttid = g_utt.uttid;
177 int tmp_pid = ttsd_data_get_pid(uid);
179 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%u), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg));
181 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
183 if (0 != ttsd_data_clear_data(uid))
184 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
187 if (0 != ttsdc_ipc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
188 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_error_message()");
191 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
192 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
195 if (0 != ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
196 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_set_state_message()");
201 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)
203 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
205 unsigned int uid = g_utt.uid;
206 int uttid = g_utt.uttid;
208 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
209 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
210 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%u), uttid(%d)", uid, uttid);
211 SLOG(LOG_DEBUG, tts_tag(), "@@@");
212 return TTSD_ERROR_INVALID_PARAMETER;
215 if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) {
216 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
217 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
218 return TTSD_ERROR_INVALID_PARAMETER;
221 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
222 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
223 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
224 SLOG(LOG_DEBUG, tts_tag(), "@@@");
225 return TTSD_ERROR_INVALID_PARAMETER;
228 /* check the current state */
229 app_tts_state_e state = ttsd_data_get_client_state(uid);
230 if (APP_STATE_NONE == state) {
231 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
232 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
233 return TTSD_ERROR_INVALID_PARAMETER;
236 SLOG(LOG_INFO, tts_tag(), "[Server] uid(%u), current state(%d)", uid, state);
237 if (APP_STATE_CREATED == state || APP_STATE_READY == state) {
238 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
239 SLOG(LOG_WARN, tts_tag(), "[SERVER WARNING] Current state is %d. The synthesized result is ignored.", state);
240 return TTSD_ERROR_NONE;
243 /* Synthesis is success */
244 if (TTSE_RESULT_EVENT_START == event) {
245 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
246 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
247 uid, uttid, data, data_size, audio_type, rate);
249 clock_gettime(CLOCK_MONOTONIC_RAW, &g_start_playing);
250 long long int latency = (uint64_t)TIME_DIFF(g_request_playing, g_start_playing);
251 SLOG(LOG_INFO, tts_tag(), "[SERVER] Latency (Request playing ~ Get 1st synthesized results): %lld ms", latency);
252 double d_latency = (double)latency;
253 g_avg_latency += d_latency;
254 g_min_latency = (d_latency < g_min_latency) ? d_latency : g_min_latency;
255 g_max_latency = (d_latency > g_max_latency) ? d_latency : g_max_latency;
257 SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency);
258 } else if (TTSE_RESULT_EVENT_FINISH == event) {
259 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
260 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
261 uid, uttid, data, data_size, audio_type, rate);
263 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
267 sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
268 if (NULL == sound_data) {
269 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
270 return TTSD_ERROR_OUT_OF_MEMORY;
273 if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
274 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
275 ttsd_data_destroy_sound_data(sound_data);
277 return TTSD_ERROR_OPERATION_FAILED;
280 if (event == TTSE_RESULT_EVENT_FINISH) {
281 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
284 return TTSD_ERROR_NONE;
287 bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
289 /* clear client data */
290 ttsd_data_clear_data(uid);
292 if (APP_STATE_READY != state) {
293 ttsd_data_set_client_state(uid, APP_STATE_READY);
296 if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
298 ttsd_data_delete_client(uid);
305 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
308 case TTS_CONFIG_TYPE_ENGINE:
310 /* TODO - Determine the policy when engine process get engine changed cb */
311 if (NULL == str_param) {
312 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
317 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
318 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
319 ret = ttsd_engine_agent_unload_current_engine();
321 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
324 ret = ttsd_engine_agent_load_current_engine();
326 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
331 /* stop all player */
332 ttsd_player_all_stop();
334 /* send interrupt message to all clients */
335 ttsd_data_foreach_clients(__get_client_cb, NULL);
337 ttsd_engine_cancel_synthesis();
342 case TTS_CONFIG_TYPE_VOICE:
344 if (NULL == str_param) {
345 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
349 char* out_lang = NULL;
353 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
354 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
355 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
357 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
359 /* Current language is not available */
360 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
362 if (NULL != out_lang) {
369 case TTS_CONFIG_TYPE_SPEED:
371 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
372 /* set default speed */
374 ret = ttsd_engine_agent_set_default_speed(int_param);
376 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
382 case TTS_CONFIG_TYPE_PITCH:
384 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
385 /* set default speed */
387 ret = ttsd_engine_agent_set_default_pitch(int_param);
389 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
395 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
397 if (0.0 <= double_param && double_param <= 1.0) {
398 /* set default bg volume ratio */
400 ret = ttsd_player_set_background_volume_ratio(double_param);
402 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
412 bool __terminate_client(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
414 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
415 ttsd_server_finalize(uid);
419 static int __terminate_server()
421 if (g_is_terminated) {
422 SLOG(LOG_INFO, tts_tag(), "[INFO] ttsd_terminate() is already invoked.");
423 return TTSD_ERROR_NONE;
426 int ret = TTSD_ERROR_NONE;
427 ret = ttsd_ipc_close_connection();
428 if (TTSD_ERROR_NONE != ret) {
429 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_ipc_close_connection(). ret(%d)", ret);
430 return TTSD_ERROR_OPERATION_FAILED;
433 ret = ttsd_finalize();
434 if (TTSD_ERROR_NONE != ret) {
435 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_finalize(). ret(%d)", ret);
436 return TTSD_ERROR_OPERATION_FAILED;
439 g_is_terminated = true;
440 return TTSD_ERROR_NONE;
443 static Eina_Bool __quit_ecore_loop(void *data)
445 __terminate_server();
446 ecore_main_loop_quit();
451 void __screen_reader_changed_cb(bool value)
453 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
457 int ttsd_send_all_stop()
459 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
461 /* stop all player */
462 ttsd_player_all_stop();
464 /* send interrupt message to all clients */
465 ttsd_data_foreach_clients(__get_client_cb, NULL);
467 return TTSD_ERROR_NONE;
473 int ttsd_initialize(ttse_request_callback_s *callback)
475 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
476 g_is_terminated = false;
478 if (ttsd_config_initialize(__config_changed_cb)) {
479 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
483 if (ttsd_player_init()) {
484 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
485 return TTSD_ERROR_OPERATION_FAILED;
489 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
491 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
492 int ret = ttsd_player_set_background_volume_ratio(ratio);
494 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
496 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
499 /* Engine Agent initialize */
500 if (0 != ttsd_engine_agent_init()) {
501 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
502 return TTSD_ERROR_OPERATION_FAILED;
505 /* set current engine */
506 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
507 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
508 // g_is_engine = false;
510 // g_is_engine = true;
512 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
513 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
514 return TTSD_ERROR_OPERATION_FAILED;
517 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
518 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);
543 ecore_timer_del(g_wait_timer);
545 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
548 if (g_check_client_timer) {
549 ecore_timer_del(g_check_client_timer);
550 g_check_client_timer = NULL;
551 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
554 if (g_quit_loop_timer) {
555 ecore_timer_del(g_quit_loop_timer);
556 g_quit_loop_timer = NULL;
557 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle");
560 ttsd_config_finalize();
562 int ret = TTSD_ERROR_NONE;
563 ret = ttsd_player_release();
564 if (TTSD_ERROR_NONE != ret) {
565 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_player_release(). ret(%d)", ret);
566 return TTSD_ERROR_OPERATION_FAILED;
569 ret = ttsd_engine_agent_release();
570 if (TTSD_ERROR_NONE != ret) {
571 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_engine_agent_release(). ret(%d)", ret);
572 return TTSD_ERROR_OPERATION_FAILED;
575 return TTSD_ERROR_NONE;
580 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
581 int ret = ttsd_data_foreach_clients(__terminate_client, NULL);
582 if (TTSD_ERROR_NONE != ret) {
583 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to terminate all clients. ret(%d)", ret);
584 return TTSD_ERROR_OPERATION_FAILED;
587 if (g_quit_loop_timer) {
588 ecore_timer_del(g_quit_loop_timer);
589 g_quit_loop_timer = NULL;
590 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle");
593 return __terminate_server();
597 * TTS Server Functions for Client
600 int ttsd_server_is_already_initialized(int pid, unsigned int uid, bool* is_initialized)
602 if (-1 != ttsd_data_is_client(uid))
603 *is_initialized = true;
605 *is_initialized = false;
607 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), uid(%u) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
608 return TTSD_ERROR_NONE;
611 int ttsd_server_initialize(int pid, unsigned int uid, tts_ipc_method_e method, bool* credential_needed)
613 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
615 if (-1 != ttsd_data_is_client(uid)) {
616 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
617 return TTSD_ERROR_NONE;
620 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
621 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
622 return TTSD_ERROR_OPERATION_FAILED;
625 if (true == *credential_needed) {
627 if (0 != app_manager_get_app_id(pid, &appid)) {
628 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
630 bool is_agreed = false;
631 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
632 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
635 return TTSD_ERROR_OPERATION_FAILED;
640 if (false == is_agreed) {
641 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
642 return TTSD_ERROR_PERMISSION_DENIED;
646 if (0 != ttsd_data_new_client(pid, uid)) {
647 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
648 return TTSD_ERROR_OPERATION_FAILED;
651 if (0 != ttsd_data_set_ipc_method(uid, method)) {
652 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set ipc method");
653 return TTSD_ERROR_OPERATION_FAILED;
656 return TTSD_ERROR_NONE;
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, unsigned 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 (%u) is running", uid);
710 if (false == exist) {
711 SLOG(LOG_ERROR, tts_tag(), "uid (%u) 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(%u) 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 if (NULL == g_quit_loop_timer) {
751 SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop");
752 g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
754 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
755 g_check_client_timer = NULL;
759 SLOG(LOG_DEBUG, tts_tag(), "@@@");
764 void __used_voice_cb(const char* lang, int type)
766 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
767 if (0 != ttsd_engine_unload_voice(lang, type)) {
768 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
772 int ttsd_server_finalize(unsigned int uid)
774 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
775 SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency);
777 if (0 > ttsd_data_is_client(uid)) {
778 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
781 ttsd_server_stop(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 if (NULL == g_quit_loop_timer) {
794 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
795 g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
797 SLOG(LOG_WARN, tts_tag(), "[Server] Already called __quit_ecore_loop");
801 return TTSD_ERROR_NONE;
804 int ttsd_server_set_mode(unsigned int uid, ttsd_mode_e mode)
806 app_tts_state_e state = ttsd_data_get_client_state(uid);
807 if (APP_STATE_NONE == state) {
808 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
809 return TTSD_ERROR_INVALID_PARAMETER;
812 if (APP_STATE_READY != state) {
813 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
814 return TTSD_ERROR_INVALID_STATE;
817 int ret = ttsd_data_set_mode(uid, mode);
819 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set mode : ret(%d)", ret);
821 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set mode. uid(%u), mode(%d)", uid, mode);
827 static bool __is_connected_to_network()
830 int network_status = 0;
831 int ret = vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status);
833 SLOG(LOG_WARN, tts_tag(), "[Network] Fail to get network status, ret(%d)", ret);
837 if (network_status == VCONFKEY_NETWORK_OFF) {
838 SLOG(LOG_WARN, tts_tag(), "[Network] Current network connection is OFF.");
842 SLOG(LOG_DEBUG, tts_tag(), "[Network] Network status is %d", network_status);
847 int ttsd_server_add_text(unsigned int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
849 app_tts_state_e state = ttsd_data_get_client_state(uid);
850 if (APP_STATE_NONE == state) {
851 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_text : uid is not valid");
852 return TTSD_ERROR_INVALID_PARAMETER;
855 /* check valid voice */
856 char* temp_lang = NULL;
858 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
859 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
860 if (NULL != temp_lang) {
864 return TTSD_ERROR_INVALID_VOICE;
867 if (NULL == temp_lang) {
868 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
869 return TTSD_ERROR_INVALID_VOICE;
872 speak_data_s* speak_data = ttsd_data_create_speak_data(text, lang, voice_type, speed, utt_id);
873 if (NULL == speak_data) {
874 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
875 if (NULL != temp_lang) {
880 return TTSD_ERROR_OPERATION_FAILED;
883 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);
885 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
887 ret = ttsd_data_add_speak_data(uid, speak_data);
889 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
890 if (NULL != temp_lang) {
895 ttsd_data_destroy_speak_data(speak_data);
901 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
902 /* Request load voice */
903 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
904 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
905 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
909 if (NULL != temp_lang) {
914 if (APP_STATE_PLAYING == state) {
915 /* check if engine use network */
916 if (ttsd_engine_agent_need_network()) {
917 if (false == __is_connected_to_network()) {
918 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
919 return TTSD_ERROR_OPERATION_FAILED;
923 ttsd_data_set_credential(uid, credential);
925 /* Check whether tts-engine is running or not */
926 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
927 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
928 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
929 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
935 return TTSD_ERROR_NONE;
938 static int __interrupt_player_by_policy(unsigned int request_app_uid)
940 unsigned int playing_app_uid = ttsd_data_get_current_playing();
941 if (0 > ttsd_data_is_client(playing_app_uid)) {
942 SLOG(LOG_INFO, tts_tag(), "[Server] There is no app which is in 'Play' state");
943 return TTSD_ERROR_NONE;
946 if (request_app_uid == playing_app_uid) {
947 SLOG(LOG_WARN, tts_tag(), "[Server] This is played uid. Skip policy behavior");
948 return TTSD_ERROR_NONE;
951 ttsd_mode_e request_app_mode = ttsd_data_get_mode(request_app_uid);
952 ttsd_mode_e playing_app_mode = ttsd_data_get_mode(playing_app_uid);
953 switch (playing_app_mode) {
954 case TTSD_MODE_DEFAULT:
955 case TTSD_MODE_NOTIFICATION:
956 case TTSD_MODE_SCREEN_READER:
957 SLOG(LOG_DEBUG, tts_tag(), "[Server] Played client(%u) will be interrupted into 'Stop' state", playing_app_uid);
958 __stop_and_send_ready_state(playing_app_uid);
961 case TTSD_MODE_INTERRUPT:
962 if (TTSD_MODE_INTERRUPT != request_app_mode) {
963 SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Default, Screen reader, and Noti are prohibitted.");
964 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
967 SLOG(LOG_DEBUG, tts_tag(), "[Server] Played client(%u) will be interrupted into 'Stop' state", playing_app_uid);
968 __stop_and_send_ready_state(playing_app_uid);
972 return TTSD_ERROR_NONE;
975 int ttsd_server_play(unsigned int uid, const char* credential)
977 app_tts_state_e state = ttsd_data_get_client_state(uid);
978 if (APP_STATE_NONE == state) {
979 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
980 return TTSD_ERROR_INVALID_PARAMETER;
983 if (APP_STATE_PLAYING == state) {
984 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state of (%u) is 'PLAYING'", uid);
985 return TTSD_ERROR_NONE;
988 /* check if engine use network */
989 if (ttsd_engine_agent_need_network()) {
990 if (false == __is_connected_to_network()) {
991 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
992 return TTSD_ERROR_OUT_OF_NETWORK;
996 int ret = __interrupt_player_by_policy(uid);
997 if (TTSD_ERROR_NONE != ret) {
998 SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Cannot play default, screen reader, and noti modes.");
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(%u)", 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(%u)", uid);
1009 return TTSD_ERROR_OPERATION_FAILED;
1012 if (APP_STATE_PAUSED == state) {
1013 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid);
1014 ret = ttsd_player_resume(uid);
1016 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
1017 ret = ttsd_player_play(uid);
1020 if (TTSD_ERROR_NONE != ret) {
1021 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
1022 ttsd_data_set_client_state(uid, state);
1023 return TTSD_ERROR_OPERATION_FAILED;
1026 ttsd_data_set_credential(uid, credential);
1028 /* Check whether tts-engine is running or not */
1029 clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing);
1030 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
1031 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
1032 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
1033 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1037 ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_SYNTH);
1039 return TTSD_ERROR_NONE;
1042 static void __stop_engine_synthesis(unsigned int uid)
1044 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
1045 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
1047 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) {
1048 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1050 int ret = ttsd_engine_cancel_synthesis();
1051 if (TTSD_ERROR_NONE != ret)
1052 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1055 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1058 int ttsd_server_stop(unsigned int uid)
1060 app_tts_state_e state = ttsd_data_get_client_state(uid);
1061 if (APP_STATE_NONE == state) {
1062 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1063 return TTSD_ERROR_INVALID_PARAMETER;
1066 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, uid(%d), state(%d)", uid, state);
1068 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1069 if (TTS_APP_PLAY_TYPE_SYNTH == ttsd_data_get_play_type(uid)) {
1070 __stop_engine_synthesis(uid);
1074 ttsd_data_set_client_state(uid, APP_STATE_READY);
1075 if (TTSD_ERROR_NONE != ttsd_player_stop(uid)) {
1076 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1080 /* Reset all data */
1081 ttsd_data_clear_data(uid);
1083 return TTSD_ERROR_NONE;
1086 int ttsd_server_pause(unsigned int uid)
1088 app_tts_state_e state = ttsd_data_get_client_state(uid);
1089 if (APP_STATE_NONE == state) {
1090 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1091 return TTSD_ERROR_INVALID_PARAMETER;
1094 if (APP_STATE_PLAYING != state) {
1095 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1096 return TTSD_ERROR_INVALID_STATE;
1099 int ret = ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1100 if (TTSD_ERROR_NONE != ret) {
1101 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail set pause state() : ret(%d)", ret);
1102 return TTSD_ERROR_OPERATION_FAILED;
1105 ret = ttsd_player_pause(uid);
1106 if (TTSD_ERROR_NONE != ret) {
1107 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1108 return TTSD_ERROR_OPERATION_FAILED;
1111 return TTSD_ERROR_NONE;
1114 int ttsd_server_get_support_voices(unsigned int uid, GList** voice_list)
1116 if (0 > ttsd_data_is_client(uid)) {
1117 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1118 return TTSD_ERROR_INVALID_PARAMETER;
1122 int ret = ttsd_engine_get_voice_list(voice_list);
1124 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1128 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1130 return TTSD_ERROR_NONE;
1133 int ttsd_server_get_current_voice(unsigned int uid, char** language, int* voice_type)
1135 if (0 > ttsd_data_is_client(uid)) {
1136 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1137 return TTSD_ERROR_INVALID_PARAMETER;
1140 /* get current voice */
1141 int ret = ttsd_engine_get_default_voice(language, voice_type);
1143 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1147 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1149 return TTSD_ERROR_NONE;
1152 int ttsd_server_set_private_data(unsigned int uid, const char* key, const char* data)
1154 app_tts_state_e state = ttsd_data_get_client_state(uid);
1155 if (APP_STATE_NONE == state) {
1156 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1157 return TTSD_ERROR_INVALID_PARAMETER;
1160 if (APP_STATE_READY != state) {
1161 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state of (%u) is NOT 'READY'", uid);
1162 return TTSD_ERROR_INVALID_STATE;
1165 int ret = ttsd_engine_set_private_data(key, data);
1167 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1169 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1175 int ttsd_server_get_private_data(unsigned int uid, const char* key, char** data)
1177 app_tts_state_e state = ttsd_data_get_client_state(uid);
1178 if (APP_STATE_NONE == state) {
1179 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1180 return TTSD_ERROR_INVALID_PARAMETER;
1183 if (APP_STATE_READY != state) {
1184 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state of (%u) is NOT 'READY'", uid);
1185 return TTSD_ERROR_INVALID_STATE;
1188 int ret = ttsd_engine_get_private_data(key, data);
1190 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1192 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1198 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1200 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1203 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1205 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1211 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1213 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1216 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1218 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1224 int ttsd_server_play_pcm(unsigned int uid)
1226 app_tts_state_e state = ttsd_data_get_client_state(uid);
1227 if (APP_STATE_NONE == state) {
1228 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1229 return TTSD_ERROR_INVALID_PARAMETER;
1232 if (APP_STATE_PLAYING == state) {
1233 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state of (%u) is 'PLAYING'", uid);
1234 return TTSD_ERROR_NONE;
1237 int ret = __interrupt_player_by_policy(uid);
1238 if (TTSD_ERROR_NONE != ret) {
1239 SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Cannot play default, screen reader, and noti modes.");
1243 /* Change current play */
1244 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1245 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%u)", uid);
1246 return TTSD_ERROR_OPERATION_FAILED;
1249 if (APP_STATE_PAUSED == state) {
1250 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid);
1251 ret = ttsd_player_resume(uid);
1253 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
1254 ret = ttsd_player_play(uid);
1257 if (TTSD_ERROR_NONE != ret) {
1258 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
1259 ttsd_data_set_client_state(uid, state);
1260 return TTSD_ERROR_OPERATION_FAILED;
1263 ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_PCM);
1265 return TTSD_ERROR_NONE;
1268 int ttsd_server_add_pcm(unsigned int uid, int event, void* data, int data_size, int audio_type, int rate)
1270 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1274 /* Synthesis is success */
1275 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1276 if (TTSE_RESULT_EVENT_START == event) {
1277 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1278 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1279 uid, uttid, data, data_size, audio_type, rate);
1280 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1281 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1282 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1283 uid, uttid, data, data_size, audio_type, rate);
1285 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1288 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1289 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1290 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1291 return TTSD_ERROR_INVALID_PARAMETER;
1294 sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
1295 if (NULL == sound_data) {
1296 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1297 return TTSD_ERROR_OUT_OF_MEMORY;
1300 if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
1301 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
1302 ttsd_data_destroy_sound_data(sound_data);
1305 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1308 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1310 return TTSD_ERROR_NONE;