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_state.h"
26 #include "ttsd_server.h"
29 #define CLIENT_CLEAN_UP_TIME 500
31 /* for checking time */
32 #define TIME_DIFF(start, end) \
33 ((uint64_t)((end).tv_sec - (start).tv_sec) * 1000000 + (((end).tv_nsec - (start).tv_nsec) / 1000)) / 1000
35 static struct timespec g_request_playing, g_start_playing;
36 static double g_avg_latency;
37 static double g_min_latency;
38 static double g_max_latency;
39 static int g_file_num;
46 /* If current engine exist */
47 //static bool g_is_engine;
49 static Ecore_Timer* g_check_client_timer = NULL;
50 static Ecore_Timer* g_wait_timer = NULL;
51 static Ecore_Timer* g_quit_loop_timer = NULL;
53 static utterance_t g_utt;
55 static GList *g_proc_list = NULL;
57 static bool g_is_terminated = false;
59 static int g_activated_mode = 0;
61 /* Function definitions */
62 static int __stop_and_send_ready_state(unsigned int uid)
64 int ret = ttsd_server_stop(uid);
65 if (TTSD_ERROR_NONE != ret) {
66 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_stop() : uid(%u). ret(%d)", uid, ret);
70 int pid = ttsd_data_get_pid(uid);
72 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u)", uid);
73 return TTSD_ERROR_OPERATION_FAILED;
75 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
81 static void __synthesis(unsigned int uid);
83 static Eina_Bool __wait_synthesis(void *data)
85 /* get current play */
86 unsigned int uid = ttsd_data_get_current_playing();
89 ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
90 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
93 SLOG(LOG_INFO, tts_tag(), "[Server] synth_control(%d)", synth_control);
95 if (TTSD_SYNTHESIS_CONTROL_DONE == synth_control) {
96 /* Start next synthesis */
107 static void __synthesis(unsigned int uid)
109 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
111 speak_data_s* speak_data = NULL;
112 int ret = ttsd_data_get_speak_data(uid, &speak_data);
113 if (TTSD_ERROR_NONE != ret || NULL == speak_data) {
114 SLOG(LOG_DEBUG, tts_tag(), "@@@ Fail to get speak data. ret(%d)", ret);
115 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
119 int pid = ttsd_data_get_pid(uid);
121 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u)", uid);
122 ttsd_data_destroy_speak_data(speak_data);
127 char appid[1024] = {0, };
128 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
129 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
132 if (NULL == speak_data->lang || NULL == speak_data->text) {
133 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
134 __stop_and_send_ready_state(uid);
135 ttsd_data_destroy_speak_data(speak_data);
141 g_utt.uttid = speak_data->utt_id;
143 char* credential = ttsd_data_get_credential(uid);
145 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
146 SLOG(LOG_INFO, tts_tag(), "ID : uid (%u), uttid(%d) ", g_utt.uid, g_utt.uttid);
147 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
148 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
149 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
150 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
152 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
153 ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
154 if (TTSD_ERROR_NONE != ret) {
155 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
157 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
158 __stop_and_send_ready_state(uid);
160 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
163 if (ttsd_data_get_synth_control() == TTSD_SYNTHESIS_CONTROL_DOING && ttsd_state_get_state() == TTSD_STATE_READY) {
164 ttsd_state_set_state(TTSD_STATE_SYNTHESIZING);
169 ttsd_data_destroy_speak_data(speak_data);
171 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
177 * TTS Server Callback Functions
179 int ttsd_send_error(ttse_error_e error, const char* msg)
181 unsigned int uid = g_utt.uid;
182 int uttid = g_utt.uttid;
183 int tmp_pid = ttsd_data_get_pid(uid);
185 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));
187 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
189 if (0 != ttsd_data_clear_data(uid))
190 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
193 if (0 != ttsdc_ipc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
194 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_error_message()");
197 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
198 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
201 if (0 != ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
202 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_set_state_message()");
207 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)
209 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
211 unsigned int uid = g_utt.uid;
212 int uttid = g_utt.uttid;
214 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
215 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
216 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%u), uttid(%d)", uid, uttid);
217 SLOG(LOG_DEBUG, tts_tag(), "@@@");
218 return TTSD_ERROR_INVALID_PARAMETER;
221 if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) {
222 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
223 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
224 return TTSD_ERROR_INVALID_PARAMETER;
227 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
228 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
229 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
230 SLOG(LOG_DEBUG, tts_tag(), "@@@");
231 return TTSD_ERROR_INVALID_PARAMETER;
234 /* check the current state */
235 app_tts_state_e state = ttsd_data_get_client_state(uid);
236 if (APP_STATE_NONE == state) {
237 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
238 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
239 return TTSD_ERROR_INVALID_PARAMETER;
242 SLOG(LOG_INFO, tts_tag(), "[Server] uid(%u), current state(%d)", uid, state);
243 if (APP_STATE_CREATED == state || APP_STATE_READY == state) {
244 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
245 SLOG(LOG_WARN, tts_tag(), "[SERVER WARNING] Current state is %d. The synthesized result is ignored.", state);
246 return TTSD_ERROR_NONE;
249 /* Synthesis is success */
250 if (TTSE_RESULT_EVENT_START == event) {
251 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
252 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
253 uid, uttid, data, data_size, audio_type, rate);
255 clock_gettime(CLOCK_MONOTONIC_RAW, &g_start_playing);
256 long long int latency = (uint64_t)TIME_DIFF(g_request_playing, g_start_playing);
257 SLOG(LOG_INFO, tts_tag(), "[SERVER] Latency (Request playing ~ Get 1st synthesized results): %lld ms", latency);
258 double d_latency = (double)latency;
259 g_avg_latency += d_latency;
260 g_min_latency = (d_latency < g_min_latency) ? d_latency : g_min_latency;
261 g_max_latency = (d_latency > g_max_latency) ? d_latency : g_max_latency;
263 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);
264 } else if (TTSE_RESULT_EVENT_FINISH == event) {
265 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
266 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
267 uid, uttid, data, data_size, audio_type, rate);
269 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
273 sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
274 if (NULL == sound_data) {
275 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
276 return TTSD_ERROR_OUT_OF_MEMORY;
279 if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
280 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
281 ttsd_data_destroy_sound_data(sound_data);
283 return TTSD_ERROR_OPERATION_FAILED;
286 if (event == TTSE_RESULT_EVENT_FINISH) {
287 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
290 return TTSD_ERROR_NONE;
293 static bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
295 if (0 > ttsd_data_is_client(uid)) {
296 SLOG(LOG_ERROR, tts_tag(), "[Server] Client(%d) is not valid.", uid);
297 ttsd_data_delete_client(uid);
301 /* clear client data */
302 ttsd_data_clear_data(uid);
304 if (APP_STATE_READY != state) {
305 ttsd_data_set_client_state(uid, APP_STATE_READY);
306 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
312 static void __stop_all_client()
314 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
316 ttsd_engine_cancel_synthesis();
317 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
319 /* stop all player */
320 ttsd_player_all_stop();
322 /* send interrupt message to all clients */
323 ttsd_data_foreach_clients(__get_client_cb, NULL);
326 static 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);
356 case TTS_CONFIG_TYPE_VOICE:
358 if (NULL == str_param) {
359 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
363 char* out_lang = NULL;
367 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
368 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
369 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
371 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
373 /* Current language is not available */
374 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
376 if (NULL != out_lang) {
383 case TTS_CONFIG_TYPE_SPEED:
385 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
386 /* set default speed */
388 ret = ttsd_engine_agent_set_default_speed(int_param);
390 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
396 case TTS_CONFIG_TYPE_PITCH:
398 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
399 /* set default speed */
401 ret = ttsd_engine_agent_set_default_pitch(int_param);
403 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
409 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
411 if (0.0 <= double_param && double_param <= 1.0) {
412 /* set default bg volume ratio */
414 ret = ttsd_player_set_background_volume_ratio(double_param);
416 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
426 bool __terminate_client(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
428 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
429 ttsd_server_finalize(uid);
433 static int __terminate_server()
435 if (g_is_terminated) {
436 SLOG(LOG_INFO, tts_tag(), "[INFO] ttsd_terminate() is already invoked.");
437 return TTSD_ERROR_NONE;
440 int ret = TTSD_ERROR_NONE;
441 ret = ttsd_ipc_close_connection();
442 if (TTSD_ERROR_NONE != ret) {
443 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_ipc_close_connection(). ret(%d)", ret);
444 return TTSD_ERROR_OPERATION_FAILED;
447 ret = ttsd_finalize();
448 if (TTSD_ERROR_NONE != ret) {
449 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_finalize(). ret(%d)", ret);
450 return TTSD_ERROR_OPERATION_FAILED;
453 g_is_terminated = true;
454 return TTSD_ERROR_NONE;
457 static Eina_Bool __quit_ecore_loop(void *data)
459 __terminate_server();
460 ecore_main_loop_quit();
465 void __screen_reader_changed_cb(bool value)
467 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
471 static void __read_proc()
474 struct dirent *dirp = NULL;
478 if (0 < g_list_length(g_proc_list)) {
479 iter = g_list_first(g_proc_list);
480 while (NULL != iter) {
481 g_proc_list = g_list_remove_link(g_proc_list, iter);
483 iter = g_list_first(g_proc_list);
487 dp = opendir("/proc");
489 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
495 tmp = atoi(dirp->d_name);
496 if (0 >= tmp) continue;
497 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
499 } while (NULL != dirp);
505 bool __get_client_for_clean_up(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
511 for (i = 0; i < g_list_length(g_proc_list); i++) {
512 iter = g_list_nth(g_proc_list, i);
514 if (pid == GPOINTER_TO_INT(iter->data)) {
515 SLOG(LOG_DEBUG, tts_tag(), "uid (%u) is running", uid);
522 if (false == exist) {
523 SLOG(LOG_ERROR, tts_tag(), "uid (%u) should be removed", uid);
524 ttsd_server_finalize(uid);
530 static Eina_Bool __cleanup_client(void *data)
532 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
535 if (0 < ttsd_data_get_client_count()) {
536 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
538 if (NULL == g_quit_loop_timer) {
539 SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop");
540 g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
542 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
543 g_check_client_timer = NULL;
547 SLOG(LOG_DEBUG, tts_tag(), "@@@");
555 int ttsd_initialize(ttse_request_callback_s *callback)
557 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
558 g_is_terminated = false;
560 if (ttsd_config_initialize(__config_changed_cb)) {
561 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
564 if (TTSD_ERROR_NONE != ttsd_state_initialize(NULL)) {
565 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize state.");
569 if (ttsd_player_init()) {
570 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
571 return TTSD_ERROR_OPERATION_FAILED;
575 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
577 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
578 int ret = ttsd_player_set_background_volume_ratio(ratio);
580 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
582 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
585 /* Engine Agent initialize */
586 if (TTSD_ERROR_NONE != ttsd_engine_agent_init(callback)) {
587 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
588 return TTSD_ERROR_OPERATION_FAILED;
591 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
592 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
594 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, __cleanup_client, NULL);
595 if (NULL == g_check_client_timer) {
596 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
599 g_activated_mode = 0;
601 return TTSD_ERROR_NONE;
606 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
609 if (0 < g_list_length(g_proc_list)) {
610 iter = g_list_first(g_proc_list);
611 while (NULL != iter) {
612 g_proc_list = g_list_remove_link(g_proc_list, iter);
614 iter = g_list_first(g_proc_list);
619 ecore_timer_del(g_wait_timer);
621 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
624 if (g_check_client_timer) {
625 ecore_timer_del(g_check_client_timer);
626 g_check_client_timer = NULL;
627 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
630 if (g_quit_loop_timer) {
631 ecore_timer_del(g_quit_loop_timer);
632 g_quit_loop_timer = NULL;
633 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle");
636 ttsd_config_finalize();
637 ttsd_state_finalize();
639 int ret = TTSD_ERROR_NONE;
640 ret = ttsd_player_release();
641 if (TTSD_ERROR_NONE != ret) {
642 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_player_release(). ret(%d)", ret);
643 return TTSD_ERROR_OPERATION_FAILED;
646 ret = ttsd_engine_agent_release();
647 if (TTSD_ERROR_NONE != ret) {
648 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_engine_agent_release(). ret(%d)", ret);
649 return TTSD_ERROR_OPERATION_FAILED;
652 return TTSD_ERROR_NONE;
657 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
658 int ret = ttsd_data_foreach_clients(__terminate_client, NULL);
659 if (TTSD_ERROR_NONE != ret) {
660 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to terminate all clients. ret(%d)", ret);
661 return TTSD_ERROR_OPERATION_FAILED;
664 if (g_quit_loop_timer) {
665 ecore_timer_del(g_quit_loop_timer);
666 g_quit_loop_timer = NULL;
667 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle");
670 return __terminate_server();
674 * TTS Server Functions for Client
677 int ttsd_server_is_already_initialized(int pid, unsigned int uid, bool* is_initialized)
679 if (-1 != ttsd_data_is_client(uid))
680 *is_initialized = true;
682 *is_initialized = false;
684 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), uid(%u) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
685 return TTSD_ERROR_NONE;
688 static void __set_and_notify_activated_mode()
690 int activated_mode = ttsd_data_get_activated_mode();
691 if (g_activated_mode == activated_mode) {
695 SLOG(LOG_INFO, tts_tag(), "[Server] Activated mode is changed from(%d) to (%d)", g_activated_mode, activated_mode);
697 g_activated_mode = activated_mode;
698 int ret = ttsd_engine_notify_activated_mode_changed(g_activated_mode);
699 if (TTSD_ERROR_NONE != ret) {
700 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to notify activated mode changed event.(%d)", ret);
704 static int __check_app_agreed(int pid, unsigned int uid, bool credential_needed)
706 if (false == credential_needed) {
707 return TTSD_ERROR_NONE;
711 if (APP_MANAGER_ERROR_NONE != app_manager_get_app_id(pid, &appid)) {
712 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
715 bool is_agreed = false;
716 int ret = ttsd_engine_check_app_agreed(appid, &is_agreed);
720 if (TTSD_ERROR_NONE != ret) {
721 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
722 return TTSD_ERROR_OPERATION_FAILED;
725 if (false == is_agreed) {
726 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
727 return TTSD_ERROR_PERMISSION_DENIED;
730 return TTSD_ERROR_NONE;
733 int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_method_e method, bool* credential_needed)
735 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
737 if (-1 != ttsd_data_is_client(uid)) {
738 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
739 return TTSD_ERROR_NONE;
742 if (TTSD_ERROR_NONE != ttsd_data_new_client(pid, uid, mode, method)) {
743 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
744 return TTSD_ERROR_OPERATION_FAILED;
747 __set_and_notify_activated_mode();
749 if (TTSD_ERROR_NONE != ttsd_engine_agent_load_current_engine()) {
750 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
751 ttsd_data_delete_client(uid);
752 return TTSD_ERROR_OPERATION_FAILED;
755 bool is_needed = false;
756 if (TTSD_ERROR_NONE != ttsd_engine_agent_is_credential_needed(uid, &is_needed)) {
757 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
758 ttsd_data_delete_client(uid);
759 return TTSD_ERROR_OPERATION_FAILED;
762 int ret = __check_app_agreed(pid, uid, is_needed);
763 if (TTSD_ERROR_NONE != ret) {
764 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Checking credential is finished(%d)", ret);
765 ttsd_data_delete_client(uid);
769 *credential_needed = is_needed;
771 return TTSD_ERROR_NONE;
774 void __used_voice_cb(const char* lang, int type)
776 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
777 if (0 != ttsd_engine_unload_voice(lang, type)) {
778 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
782 int ttsd_server_finalize(unsigned int uid)
784 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
785 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);
787 if (0 > ttsd_data_is_client(uid)) {
788 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
791 int ret = ttsd_server_stop(uid);
792 if (TTSD_ERROR_NONE != ret) {
793 SLOG(LOG_ERROR, tts_tag(), "[ERROR] TTS server top(%u) fail (%d/%s) <<<<<", uid, ret, get_error_message(ret));
796 /* Need to unload voice when used voice is unregistered */
797 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
798 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
799 return TTSD_ERROR_OPERATION_FAILED;
802 ttsd_data_delete_client(uid);
803 __set_and_notify_activated_mode();
805 /* unload engine, if ref count of client is 0 */
806 if (0 == ttsd_data_get_client_count()) {
807 if (NULL == g_quit_loop_timer) {
808 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
809 g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
811 SLOG(LOG_WARN, tts_tag(), "[Server] Already called __quit_ecore_loop");
815 return TTSD_ERROR_NONE;
818 static bool __is_connected_to_network()
821 int network_status = 0;
822 int ret = vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status);
824 SLOG(LOG_WARN, tts_tag(), "[Network] Fail to get network status, ret(%d)", ret);
828 if (network_status == VCONFKEY_NETWORK_OFF) {
829 SLOG(LOG_WARN, tts_tag(), "[Network] Current network connection is OFF.");
833 SLOG(LOG_DEBUG, tts_tag(), "[Network] Network status is %d", network_status);
838 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)
840 app_tts_state_e state = ttsd_data_get_client_state(uid);
841 if (APP_STATE_NONE == state) {
842 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_text : uid is not valid");
843 return TTSD_ERROR_INVALID_PARAMETER;
846 /* check valid voice */
847 char* temp_lang = NULL;
849 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
850 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
851 if (NULL != temp_lang) {
855 return TTSD_ERROR_INVALID_VOICE;
858 if (NULL == temp_lang) {
859 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
860 return TTSD_ERROR_INVALID_VOICE;
863 speak_data_s* speak_data = ttsd_data_create_speak_data(text, lang, voice_type, speed, utt_id);
864 if (NULL == speak_data) {
865 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
866 if (NULL != temp_lang) {
871 return TTSD_ERROR_OPERATION_FAILED;
874 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);
876 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
878 ret = ttsd_data_add_speak_data(uid, speak_data);
880 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
881 if (NULL != temp_lang) {
886 ttsd_data_destroy_speak_data(speak_data);
892 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
893 /* Request load voice */
894 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
895 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
896 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
900 if (NULL != temp_lang) {
905 if (APP_STATE_PLAYING == state) {
906 /* check if engine use network */
907 if (ttsd_engine_agent_need_network()) {
908 if (false == __is_connected_to_network()) {
909 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
910 return TTSD_ERROR_OPERATION_FAILED;
914 ttsd_data_set_credential(uid, credential);
916 /* Check whether tts-engine is running or not */
917 ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
918 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
919 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
920 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
926 return TTSD_ERROR_NONE;
929 static int __interrupt_player_by_policy(unsigned int request_app_uid)
931 unsigned int playing_app_uid = ttsd_data_get_current_playing();
932 if (0 > ttsd_data_is_client(playing_app_uid)) {
933 SLOG(LOG_INFO, tts_tag(), "[Server] There is no app which is in 'Play' state");
934 return TTSD_ERROR_NONE;
937 if (request_app_uid == playing_app_uid) {
938 SLOG(LOG_WARN, tts_tag(), "[Server] This is played uid. Skip policy behavior");
939 return TTSD_ERROR_NONE;
942 ttsd_mode_e request_app_mode = ttsd_data_get_mode(request_app_uid);
943 ttsd_mode_e playing_app_mode = ttsd_data_get_mode(playing_app_uid);
944 switch (playing_app_mode) {
945 case TTSD_MODE_DEFAULT:
946 case TTSD_MODE_NOTIFICATION:
947 case TTSD_MODE_SCREEN_READER:
948 SLOG(LOG_DEBUG, tts_tag(), "[Server] Played client(%u) will be interrupted into 'Stop' state", playing_app_uid);
949 __stop_and_send_ready_state(playing_app_uid);
952 case TTSD_MODE_INTERRUPT:
953 if (TTSD_MODE_INTERRUPT != request_app_mode) {
954 SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Default, Screen reader, and Noti are prohibitted.");
955 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
958 SLOG(LOG_DEBUG, tts_tag(), "[Server] Played client(%u) will be interrupted into 'Stop' state", playing_app_uid);
959 __stop_and_send_ready_state(playing_app_uid);
963 return TTSD_ERROR_NONE;
966 int ttsd_server_play(unsigned int uid, const char* credential)
968 app_tts_state_e state = ttsd_data_get_client_state(uid);
969 if (APP_STATE_NONE == state) {
970 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
971 return TTSD_ERROR_INVALID_PARAMETER;
974 if (APP_STATE_PLAYING == state) {
975 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state of (%u) is 'PLAYING'", uid);
976 return TTSD_ERROR_NONE;
979 /* check if engine use network */
980 if (ttsd_engine_agent_need_network()) {
981 if (false == __is_connected_to_network()) {
982 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
983 return TTSD_ERROR_OUT_OF_NETWORK;
987 int ret = __interrupt_player_by_policy(uid);
988 if (TTSD_ERROR_NONE != ret) {
989 SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Cannot play default, screen reader, and noti modes.");
993 /* Change current play */
994 if (0 != ttsd_player_wait_to_play(uid)) {
995 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%u)", uid);
998 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
999 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%u)", uid);
1000 return TTSD_ERROR_OPERATION_FAILED;
1003 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
1004 ret = ttsd_player_play(uid);
1005 if (TTSD_ERROR_NONE != ret) {
1006 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
1007 ttsd_data_set_client_state(uid, state);
1008 return TTSD_ERROR_OPERATION_FAILED;
1011 ttsd_data_set_credential(uid, credential);
1013 /* Check whether tts-engine is running or not */
1014 clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing);
1015 ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
1016 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
1017 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
1018 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1022 ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_SYNTH);
1024 return TTSD_ERROR_NONE;
1027 static void __stop_engine_synthesis(unsigned int uid)
1029 ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
1030 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
1032 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) {
1033 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1035 int ret = ttsd_engine_cancel_synthesis();
1036 if (TTSD_ERROR_NONE != ret)
1037 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1040 ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1043 int ttsd_server_stop(unsigned int uid)
1045 app_tts_state_e state = ttsd_data_get_client_state(uid);
1046 if (APP_STATE_NONE == state) {
1047 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1048 return TTSD_ERROR_INVALID_PARAMETER;
1051 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, uid(%d), state(%d)", uid, state);
1053 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1054 if (TTS_APP_PLAY_TYPE_SYNTH == ttsd_data_get_play_type(uid)) {
1055 __stop_engine_synthesis(uid);
1059 ttsd_data_set_client_state(uid, APP_STATE_READY);
1060 if (TTSD_ERROR_NONE != ttsd_player_stop(uid)) {
1061 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1065 /* Reset all data */
1066 ttsd_data_clear_data(uid);
1068 return TTSD_ERROR_NONE;
1071 int ttsd_server_pause(unsigned int uid)
1073 app_tts_state_e state = ttsd_data_get_client_state(uid);
1074 if (APP_STATE_NONE == state) {
1075 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1076 return TTSD_ERROR_INVALID_PARAMETER;
1079 if (APP_STATE_PLAYING != state) {
1080 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1081 return TTSD_ERROR_INVALID_STATE;
1084 int ret = ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1085 if (TTSD_ERROR_NONE != ret) {
1086 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail set pause state() : ret(%d)", ret);
1087 return TTSD_ERROR_OPERATION_FAILED;
1090 ret = ttsd_player_pause(uid);
1091 if (TTSD_ERROR_NONE != ret) {
1092 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1093 return TTSD_ERROR_OPERATION_FAILED;
1096 return TTSD_ERROR_NONE;
1099 int ttsd_server_get_support_voices(unsigned int uid, GList** voice_list)
1101 if (0 > ttsd_data_is_client(uid)) {
1102 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1103 return TTSD_ERROR_INVALID_PARAMETER;
1107 int ret = ttsd_engine_get_voice_list(voice_list);
1109 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1113 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1115 return TTSD_ERROR_NONE;
1118 int ttsd_server_get_current_voice(unsigned int uid, char** language, int* voice_type)
1120 if (0 > ttsd_data_is_client(uid)) {
1121 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1122 return TTSD_ERROR_INVALID_PARAMETER;
1125 /* get current voice */
1126 int ret = ttsd_engine_get_default_voice(language, voice_type);
1128 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1132 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1134 return TTSD_ERROR_NONE;
1137 int ttsd_server_set_private_data(unsigned int uid, const char* key, const char* data)
1139 app_tts_state_e state = ttsd_data_get_client_state(uid);
1140 if (APP_STATE_NONE == state) {
1141 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1142 return TTSD_ERROR_INVALID_PARAMETER;
1145 if (APP_STATE_READY != state) {
1146 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state of (%u) is NOT 'READY'", uid);
1147 return TTSD_ERROR_INVALID_STATE;
1150 int ret = ttsd_engine_set_private_data(key, data);
1152 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1154 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1160 int ttsd_server_get_private_data(unsigned int uid, const char* key, char** data)
1162 app_tts_state_e state = ttsd_data_get_client_state(uid);
1163 if (APP_STATE_NONE == state) {
1164 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1165 return TTSD_ERROR_INVALID_PARAMETER;
1168 if (APP_STATE_READY != state) {
1169 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state of (%u) is NOT 'READY'", uid);
1170 return TTSD_ERROR_INVALID_STATE;
1173 char* temp_data = NULL;
1174 int ret = ttsd_engine_get_private_data(key, &temp_data);
1176 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1178 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1181 if (NULL == temp_data) {
1182 temp_data = strdup("NULL");
1189 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1191 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1194 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1196 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1202 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1204 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1207 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1209 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1215 int ttsd_get_activated_mode(int* activated_mode)
1217 if (NULL == activated_mode) {
1218 return TTSD_ERROR_INVALID_PARAMETER;
1221 *activated_mode = ttsd_data_get_activated_mode();
1222 return TTSD_ERROR_NONE;
1225 int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
1227 int ret = ttsd_engine_agent_set_activated_mode_changed_cb(callback);
1228 if (TTSD_ERROR_NONE != ret) {
1229 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1235 int ttsd_server_play_pcm(unsigned int uid)
1237 app_tts_state_e state = ttsd_data_get_client_state(uid);
1238 if (APP_STATE_NONE == state) {
1239 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1240 return TTSD_ERROR_INVALID_PARAMETER;
1243 if (APP_STATE_PLAYING == state) {
1244 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state of (%u) is 'PLAYING'", uid);
1245 return TTSD_ERROR_NONE;
1248 int ret = __interrupt_player_by_policy(uid);
1249 if (TTSD_ERROR_NONE != ret) {
1250 SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Cannot play default, screen reader, and noti modes.");
1254 /* Change current play */
1255 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1256 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%u)", uid);
1257 return TTSD_ERROR_OPERATION_FAILED;
1260 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
1261 ret = ttsd_player_play(uid);
1262 if (TTSD_ERROR_NONE != ret) {
1263 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
1264 ttsd_data_set_client_state(uid, state);
1265 return TTSD_ERROR_OPERATION_FAILED;
1268 ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_PCM);
1270 return TTSD_ERROR_NONE;
1273 int ttsd_server_add_pcm(unsigned int uid, int event, void* data, int data_size, int audio_type, int rate)
1275 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1279 /* Synthesis is success */
1280 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1281 if (TTSE_RESULT_EVENT_START == event) {
1282 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1283 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1284 uid, uttid, data, data_size, audio_type, rate);
1285 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1286 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1287 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1288 uid, uttid, data, data_size, audio_type, rate);
1290 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1293 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1294 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1295 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1296 return TTSD_ERROR_INVALID_PARAMETER;
1299 sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
1300 if (NULL == sound_data) {
1301 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1302 return TTSD_ERROR_OUT_OF_MEMORY;
1305 if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
1306 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
1307 ttsd_data_destroy_sound_data(sound_data);
1310 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1313 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1315 return TTSD_ERROR_NONE;