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 void __synthesis(unsigned int uid);
62 static Eina_Bool __wait_synthesis(void *data)
64 /* get current play */
65 unsigned int uid = ttsd_data_get_current_playing();
68 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
69 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
72 SLOG(LOG_INFO, tts_tag(), "[Server] synth_control(%d)", synth_control);
74 if (TTSD_SYNTHESIS_CONTROL_DONE == synth_control) {
75 /* Start next synthesis */
86 static void __synthesis(unsigned int uid)
88 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
90 speak_data_s* speak_data = NULL;
91 int ret = ttsd_data_get_speak_data(uid, &speak_data);
92 if (TTSD_ERROR_NONE != ret || NULL == speak_data) {
93 SLOG(LOG_DEBUG, tts_tag(), "@@@ Fail to get speak data. ret(%d)", ret);
94 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
98 int pid = ttsd_data_get_pid(uid);
100 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u)", uid);
101 ttsd_data_destroy_speak_data(speak_data);
106 char appid[1024] = {0, };
107 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
108 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
111 if (NULL == speak_data->lang || NULL == speak_data->text) {
112 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
113 ttsd_server_stop(uid);
114 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
115 ttsd_data_destroy_speak_data(speak_data);
121 g_utt.uttid = speak_data->utt_id;
123 char* credential = ttsd_data_get_credential(uid);
125 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
126 SLOG(LOG_INFO, tts_tag(), "ID : uid (%u), uttid(%d) ", g_utt.uid, g_utt.uttid);
127 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
128 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
129 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
130 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
132 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
133 ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
134 if (TTSD_ERROR_NONE != ret) {
135 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
137 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
138 ttsd_server_stop(uid);
140 int pid = ttsd_data_get_pid(uid);
142 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%u)", uid);
144 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
147 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
152 ttsd_data_destroy_speak_data(speak_data);
154 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
160 * TTS Server Callback Functions
162 int ttsd_send_error(ttse_error_e error, const char* msg)
164 unsigned int uid = g_utt.uid;
165 int uttid = g_utt.uttid;
166 int tmp_pid = ttsd_data_get_pid(uid);
168 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));
170 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
172 if (0 != ttsd_data_clear_data(uid))
173 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
176 if (0 != ttsdc_ipc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
177 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_error_message()");
180 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
181 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
184 if (0 != ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
185 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_set_state_message()");
190 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)
192 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
194 unsigned int uid = g_utt.uid;
195 int uttid = g_utt.uttid;
197 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
198 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
199 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%u), uttid(%d)", uid, uttid);
200 SLOG(LOG_DEBUG, tts_tag(), "@@@");
201 return TTSD_ERROR_INVALID_PARAMETER;
204 if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) {
205 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
206 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
207 return TTSD_ERROR_INVALID_PARAMETER;
210 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
211 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
212 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
213 SLOG(LOG_DEBUG, tts_tag(), "@@@");
214 return TTSD_ERROR_INVALID_PARAMETER;
217 /* check the current state */
218 app_tts_state_e state = ttsd_data_get_client_state(uid);
219 if (APP_STATE_NONE == state) {
220 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
221 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
222 return TTSD_ERROR_INVALID_PARAMETER;
225 SLOG(LOG_INFO, tts_tag(), "[Server] uid(%u), current state(%d)", uid, state);
226 if (APP_STATE_CREATED == state || APP_STATE_READY == state) {
227 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
228 SLOG(LOG_WARN, tts_tag(), "[SERVER WARNING] Current state is %d. The synthesized result is ignored.", state);
229 return TTSD_ERROR_NONE;
232 /* Synthesis is success */
233 if (TTSE_RESULT_EVENT_START == event) {
234 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
235 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
236 uid, uttid, data, data_size, audio_type, rate);
238 clock_gettime(CLOCK_MONOTONIC_RAW, &g_start_playing);
239 long long int latency = (uint64_t)TIME_DIFF(g_request_playing, g_start_playing);
240 SLOG(LOG_INFO, tts_tag(), "[SERVER] Latency (Request playing ~ Get 1st synthesized results): %lld ms", latency);
241 double d_latency = (double)latency;
242 g_avg_latency += d_latency;
243 g_min_latency = (d_latency < g_min_latency) ? d_latency : g_min_latency;
244 g_max_latency = (d_latency > g_max_latency) ? d_latency : g_max_latency;
246 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);
247 } else if (TTSE_RESULT_EVENT_FINISH == event) {
248 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
249 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
250 uid, uttid, data, data_size, audio_type, rate);
252 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
256 sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
257 if (NULL == sound_data) {
258 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
259 return TTSD_ERROR_OUT_OF_MEMORY;
262 if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
263 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
264 ttsd_data_destroy_sound_data(sound_data);
266 return TTSD_ERROR_OPERATION_FAILED;
269 if (event == TTSE_RESULT_EVENT_FINISH) {
270 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
273 return TTSD_ERROR_NONE;
276 bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
278 /* clear client data */
279 ttsd_data_clear_data(uid);
281 if (APP_STATE_READY != state) {
282 ttsd_data_set_client_state(uid, APP_STATE_READY);
285 if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
287 ttsd_data_delete_client(uid);
294 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
297 case TTS_CONFIG_TYPE_ENGINE:
299 /* TODO - Determine the policy when engine process get engine changed cb */
300 if (NULL == str_param) {
301 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
306 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
307 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
308 ret = ttsd_engine_agent_unload_current_engine();
310 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
313 ret = ttsd_engine_agent_load_current_engine();
315 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
320 /* stop all player */
321 ttsd_player_all_stop();
323 /* send interrupt message to all clients */
324 ttsd_data_foreach_clients(__get_client_cb, NULL);
326 ttsd_engine_cancel_synthesis();
331 case TTS_CONFIG_TYPE_VOICE:
333 if (NULL == str_param) {
334 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
338 char* out_lang = NULL;
342 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
343 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
344 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
346 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
348 /* Current language is not available */
349 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
351 if (NULL != out_lang) {
358 case TTS_CONFIG_TYPE_SPEED:
360 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
361 /* set default speed */
363 ret = ttsd_engine_agent_set_default_speed(int_param);
365 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
371 case TTS_CONFIG_TYPE_PITCH:
373 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
374 /* set default speed */
376 ret = ttsd_engine_agent_set_default_pitch(int_param);
378 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
384 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
386 if (0.0 <= double_param && double_param <= 1.0) {
387 /* set default bg volume ratio */
389 ret = ttsd_player_set_background_volume_ratio(double_param);
391 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
401 bool __terminate_client(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
403 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
404 ttsd_server_finalize(uid);
408 static int __terminate_server()
410 if (g_is_terminated) {
411 SLOG(LOG_INFO, tts_tag(), "[INFO] ttsd_terminate() is already invoked.");
412 return TTSD_ERROR_NONE;
415 int ret = TTSD_ERROR_NONE;
416 ret = ttsd_ipc_close_connection();
417 if (TTSD_ERROR_NONE != ret) {
418 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_ipc_close_connection(). ret(%d)", ret);
419 return TTSD_ERROR_OPERATION_FAILED;
422 ret = ttsd_finalize();
423 if (TTSD_ERROR_NONE != ret) {
424 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_finalize(). ret(%d)", ret);
425 return TTSD_ERROR_OPERATION_FAILED;
428 g_is_terminated = true;
429 return TTSD_ERROR_NONE;
432 static Eina_Bool __quit_ecore_loop(void *data)
434 __terminate_server();
435 ecore_main_loop_quit();
440 void __screen_reader_changed_cb(bool value)
442 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
446 int ttsd_send_all_stop()
448 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
450 /* stop all player */
451 ttsd_player_all_stop();
453 /* send interrupt message to all clients */
454 ttsd_data_foreach_clients(__get_client_cb, NULL);
456 return TTSD_ERROR_NONE;
462 int ttsd_initialize(ttse_request_callback_s *callback)
464 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
465 g_is_terminated = false;
467 if (ttsd_config_initialize(__config_changed_cb)) {
468 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
472 if (ttsd_player_init()) {
473 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
474 return TTSD_ERROR_OPERATION_FAILED;
478 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
480 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
481 int ret = ttsd_player_set_background_volume_ratio(ratio);
483 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
485 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
488 /* Engine Agent initialize */
489 if (0 != ttsd_engine_agent_init()) {
490 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
491 return TTSD_ERROR_OPERATION_FAILED;
494 /* set current engine */
495 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
496 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
497 // g_is_engine = false;
499 // g_is_engine = true;
501 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
502 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
503 return TTSD_ERROR_OPERATION_FAILED;
506 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
508 // if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
509 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
512 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
513 if (NULL == g_check_client_timer) {
514 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
517 return TTSD_ERROR_NONE;
522 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
525 if (0 < g_list_length(g_proc_list)) {
526 iter = g_list_first(g_proc_list);
527 while (NULL != iter) {
528 g_proc_list = g_list_remove_link(g_proc_list, iter);
530 iter = g_list_first(g_proc_list);
535 ecore_timer_del(g_wait_timer);
537 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
540 if (g_check_client_timer) {
541 ecore_timer_del(g_check_client_timer);
542 g_check_client_timer = NULL;
543 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
546 if (g_quit_loop_timer) {
547 ecore_timer_del(g_quit_loop_timer);
548 g_quit_loop_timer = NULL;
549 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle");
552 ttsd_config_finalize();
554 int ret = TTSD_ERROR_NONE;
555 ret = ttsd_player_release();
556 if (TTSD_ERROR_NONE != ret) {
557 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_player_release(). ret(%d)", ret);
558 return TTSD_ERROR_OPERATION_FAILED;
561 ret = ttsd_engine_agent_release();
562 if (TTSD_ERROR_NONE != ret) {
563 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_engine_agent_release(). ret(%d)", ret);
564 return TTSD_ERROR_OPERATION_FAILED;
567 return TTSD_ERROR_NONE;
572 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
573 int ret = ttsd_data_foreach_clients(__terminate_client, NULL);
574 if (TTSD_ERROR_NONE != ret) {
575 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to terminate all clients. ret(%d)", ret);
576 return TTSD_ERROR_OPERATION_FAILED;
579 if (g_quit_loop_timer) {
580 ecore_timer_del(g_quit_loop_timer);
581 g_quit_loop_timer = NULL;
582 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle");
585 return __terminate_server();
589 * TTS Server Functions for Client
592 int ttsd_server_is_already_initialized(int pid, unsigned int uid, bool* is_initialized)
594 if (-1 != ttsd_data_is_client(uid))
595 *is_initialized = true;
597 *is_initialized = false;
599 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), uid(%u) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
600 return TTSD_ERROR_NONE;
603 int ttsd_server_initialize(int pid, unsigned int uid, tts_ipc_method_e method, bool* credential_needed)
605 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
607 if (-1 != ttsd_data_is_client(uid)) {
608 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
609 return TTSD_ERROR_NONE;
612 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
613 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
614 return TTSD_ERROR_OPERATION_FAILED;
617 if (true == *credential_needed) {
619 if (0 != app_manager_get_app_id(pid, &appid)) {
620 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
622 bool is_agreed = false;
623 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
624 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
627 return TTSD_ERROR_OPERATION_FAILED;
632 if (false == is_agreed) {
633 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
634 return TTSD_ERROR_PERMISSION_DENIED;
638 if (0 != ttsd_data_new_client(pid, uid)) {
639 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
640 return TTSD_ERROR_OPERATION_FAILED;
643 if (0 != ttsd_data_set_ipc_method(uid, method)) {
644 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set ipc method");
645 return TTSD_ERROR_OPERATION_FAILED;
648 return TTSD_ERROR_NONE;
651 static void __read_proc()
654 struct dirent *dirp = NULL;
658 if (0 < g_list_length(g_proc_list)) {
659 iter = g_list_first(g_proc_list);
660 while (NULL != iter) {
661 g_proc_list = g_list_remove_link(g_proc_list, iter);
663 iter = g_list_first(g_proc_list);
667 dp = opendir("/proc");
669 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
675 tmp = atoi(dirp->d_name);
676 if (0 >= tmp) continue;
677 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
679 } while (NULL != dirp);
685 bool __get_client_for_clean_up(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
691 for (i = 0; i < g_list_length(g_proc_list); i++) {
692 iter = g_list_nth(g_proc_list, i);
694 if (pid == GPOINTER_TO_INT(iter->data)) {
695 SLOG(LOG_DEBUG, tts_tag(), "uid (%u) is running", uid);
702 if (false == exist) {
703 SLOG(LOG_ERROR, tts_tag(), "uid (%u) should be removed", uid);
704 ttsd_server_finalize(uid);
709 char appid[1024] = {0, };
710 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
711 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
714 if (0 < strlen(appid)) {
715 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
717 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
720 result = ttsdc_send_hello(pid, uid);
723 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) should be removed.", uid);
724 ttsd_server_finalize(uid);
725 } else if (-1 == result) {
726 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
734 Eina_Bool ttsd_cleanup_client(void *data)
736 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
739 if (0 < ttsd_data_get_client_count()) {
740 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
742 if (NULL == g_quit_loop_timer) {
743 SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop");
744 g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
746 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
747 g_check_client_timer = NULL;
751 SLOG(LOG_DEBUG, tts_tag(), "@@@");
756 void __used_voice_cb(const char* lang, int type)
758 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
759 if (0 != ttsd_engine_unload_voice(lang, type)) {
760 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
764 int ttsd_server_finalize(unsigned int uid)
766 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
767 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);
769 if (0 > ttsd_data_is_client(uid)) {
770 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
773 ttsd_server_stop(uid);
775 /* Need to unload voice when used voice is unregistered */
776 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
777 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
778 return TTSD_ERROR_OPERATION_FAILED;
781 ttsd_data_delete_client(uid);
783 /* unload engine, if ref count of client is 0 */
784 if (0 == ttsd_data_get_client_count()) {
785 if (NULL == g_quit_loop_timer) {
786 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
787 g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
789 SLOG(LOG_WARN, tts_tag(), "[Server] Already called __quit_ecore_loop");
793 return TTSD_ERROR_NONE;
796 int ttsd_server_set_mode(unsigned int uid, ttsd_mode_e mode)
798 app_tts_state_e state = ttsd_data_get_client_state(uid);
799 if (APP_STATE_NONE == state) {
800 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
801 return TTSD_ERROR_INVALID_PARAMETER;
804 if (APP_STATE_READY != state) {
805 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
806 return TTSD_ERROR_INVALID_STATE;
809 int ret = ttsd_data_set_mode(uid, mode);
811 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set mode : ret(%d)", ret);
813 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set mode. uid(%u), mode(%d)", uid, mode);
819 static bool __is_connected_to_network()
822 int network_status = 0;
823 int ret = vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status);
825 SLOG(LOG_WARN, tts_tag(), "[Network] Fail to get network status, ret(%d)", ret);
829 if (network_status == VCONFKEY_NETWORK_OFF) {
830 SLOG(LOG_WARN, tts_tag(), "[Network] Current network connection is OFF.");
834 SLOG(LOG_DEBUG, tts_tag(), "[Network] Network status is %d", network_status);
839 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)
841 app_tts_state_e state = ttsd_data_get_client_state(uid);
842 if (APP_STATE_NONE == state) {
843 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_text : uid is not valid");
844 return TTSD_ERROR_INVALID_PARAMETER;
847 /* check valid voice */
848 char* temp_lang = NULL;
850 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
851 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
852 if (NULL != temp_lang) {
856 return TTSD_ERROR_INVALID_VOICE;
859 if (NULL == temp_lang) {
860 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
861 return TTSD_ERROR_INVALID_VOICE;
864 speak_data_s* speak_data = ttsd_data_create_speak_data(text, lang, voice_type, speed, utt_id);
865 if (NULL == speak_data) {
866 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
867 if (NULL != temp_lang) {
872 return TTSD_ERROR_OPERATION_FAILED;
875 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);
877 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
879 ret = ttsd_data_add_speak_data(uid, speak_data);
881 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
882 if (NULL != temp_lang) {
887 ttsd_data_destroy_speak_data(speak_data);
893 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
894 /* Request load voice */
895 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
896 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
897 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
901 if (NULL != temp_lang) {
906 if (APP_STATE_PLAYING == state) {
907 /* check if engine use network */
908 if (ttsd_engine_agent_need_network()) {
909 if (false == __is_connected_to_network()) {
910 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
911 return TTSD_ERROR_OPERATION_FAILED;
915 ttsd_data_set_credential(uid, credential);
917 /* Check whether tts-engine is running or not */
918 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
919 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
920 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
921 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
927 return TTSD_ERROR_NONE;
930 void __send_interrupt_client(unsigned int uid)
932 SLOG(LOG_INFO, tts_tag(), "[Server] Send new state by policy. uid(%u)", uid);
933 int pid = ttsd_data_get_pid(uid);
935 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u), pid(%d)", uid, pid);
939 app_tts_state_e state = ttsd_data_get_client_state(uid);
940 if (APP_STATE_NONE == state) {
941 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get state. uid(%u), pid(%d)", uid, pid);
945 ttsdc_ipc_send_set_state_message(pid, uid, state);
946 SLOG(LOG_INFO, tts_tag(), "[Server] Finish to send new state by policy. uid(%u)", uid);
950 int ttsd_server_play(unsigned int uid, const char* credential)
952 app_tts_state_e state = ttsd_data_get_client_state(uid);
953 if (APP_STATE_NONE == state) {
954 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
955 return TTSD_ERROR_INVALID_PARAMETER;
958 if (APP_STATE_PLAYING == state) {
959 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state of (%u) is 'PLAYING'", uid);
960 return TTSD_ERROR_NONE;
963 /* check if engine use network */
964 if (ttsd_engine_agent_need_network()) {
965 if (false == __is_connected_to_network()) {
966 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
967 return TTSD_ERROR_OUT_OF_NETWORK;
971 /* check the current playback focus */
972 if (TTSD_MODE_INTERRUPT != ttsd_get_mode() && ttsd_player_does_interrupt_have_playback_focus()) {
973 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
974 ttsd_data_clear_data(uid);
975 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
978 unsigned int current_uid = ttsd_data_get_current_playing();
979 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%u)", current_uid);
981 if (uid != current_uid && 0 <= ttsd_data_is_client(current_uid)) {
982 if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) {
983 /* Send interrupt message */
984 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Stop' state ", current_uid);
987 if (0 != ttsd_server_stop(current_uid)) {
988 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%u)", current_uid);
991 /* Default mode policy of interrupt is "Pause" */
993 /* Send interrupt message */
994 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Pause' state ", current_uid);
997 if (0 != ttsd_server_pause(current_uid)) {
998 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_pause() : uid (%u)", current_uid);
1002 __send_interrupt_client(current_uid);
1005 /* Change current play */
1006 if (0 != ttsd_player_wait_to_play(uid)) {
1007 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%u)", uid);
1010 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1011 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%u)", uid);
1012 return TTSD_ERROR_OPERATION_FAILED;
1015 int ret = TTSD_ERROR_NONE;
1016 if (APP_STATE_PAUSED == state) {
1017 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid);
1018 ret = ttsd_player_resume(uid);
1020 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
1021 ret = ttsd_player_play(uid);
1024 if (TTSD_ERROR_NONE != ret) {
1025 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
1026 ttsd_data_set_client_state(uid, state);
1027 return TTSD_ERROR_OPERATION_FAILED;
1030 ttsd_data_set_credential(uid, credential);
1032 /* Check whether tts-engine is running or not */
1033 clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing);
1034 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
1035 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
1036 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
1037 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1041 ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_SYNTH);
1043 return TTSD_ERROR_NONE;
1046 static void __stop_engine_synthesis(unsigned int uid)
1048 ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
1049 SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
1051 if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) {
1052 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1054 int ret = ttsd_engine_cancel_synthesis();
1055 if (TTSD_ERROR_NONE != ret)
1056 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1059 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1062 int ttsd_server_stop(unsigned int uid)
1064 app_tts_state_e state = ttsd_data_get_client_state(uid);
1065 if (APP_STATE_NONE == state) {
1066 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1067 return TTSD_ERROR_INVALID_PARAMETER;
1070 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, uid(%d), state(%d)", uid, state);
1072 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1073 if (TTS_APP_PLAY_TYPE_SYNTH == ttsd_data_get_play_type(uid)) {
1074 __stop_engine_synthesis(uid);
1078 ttsd_data_set_client_state(uid, APP_STATE_READY);
1079 if (TTSD_ERROR_NONE != ttsd_player_stop(uid)) {
1080 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1084 /* Reset all data */
1085 ttsd_data_clear_data(uid);
1087 return TTSD_ERROR_NONE;
1090 int ttsd_server_pause(unsigned int uid)
1092 app_tts_state_e state = ttsd_data_get_client_state(uid);
1093 if (APP_STATE_NONE == state) {
1094 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1095 return TTSD_ERROR_INVALID_PARAMETER;
1098 if (APP_STATE_PLAYING != state) {
1099 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1100 return TTSD_ERROR_INVALID_STATE;
1103 int ret = ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1104 if (TTSD_ERROR_NONE != ret) {
1105 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail set pause state() : ret(%d)", ret);
1106 return TTSD_ERROR_OPERATION_FAILED;
1109 ret = ttsd_player_pause(uid);
1110 if (TTSD_ERROR_NONE != ret) {
1111 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1112 return TTSD_ERROR_OPERATION_FAILED;
1115 return TTSD_ERROR_NONE;
1118 int ttsd_server_get_support_voices(unsigned int uid, GList** voice_list)
1120 if (0 > ttsd_data_is_client(uid)) {
1121 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1122 return TTSD_ERROR_INVALID_PARAMETER;
1126 int ret = ttsd_engine_get_voice_list(voice_list);
1128 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1132 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1134 return TTSD_ERROR_NONE;
1137 int ttsd_server_get_current_voice(unsigned int uid, char** language, int* voice_type)
1139 if (0 > ttsd_data_is_client(uid)) {
1140 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1141 return TTSD_ERROR_INVALID_PARAMETER;
1144 /* get current voice */
1145 int ret = ttsd_engine_get_default_voice(language, voice_type);
1147 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1151 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1153 return TTSD_ERROR_NONE;
1156 int ttsd_server_set_private_data(unsigned int uid, const char* key, const char* data)
1158 app_tts_state_e state = ttsd_data_get_client_state(uid);
1159 if (APP_STATE_NONE == state) {
1160 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1161 return TTSD_ERROR_INVALID_PARAMETER;
1164 if (APP_STATE_READY != state) {
1165 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state of (%u) is NOT 'READY'", uid);
1166 return TTSD_ERROR_INVALID_STATE;
1169 int ret = ttsd_engine_set_private_data(key, data);
1171 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1173 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1179 int ttsd_server_get_private_data(unsigned int uid, const char* key, char** data)
1181 app_tts_state_e state = ttsd_data_get_client_state(uid);
1182 if (APP_STATE_NONE == state) {
1183 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1184 return TTSD_ERROR_INVALID_PARAMETER;
1187 if (APP_STATE_READY != state) {
1188 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state of (%u) is NOT 'READY'", uid);
1189 return TTSD_ERROR_INVALID_STATE;
1192 int ret = ttsd_engine_get_private_data(key, data);
1194 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1196 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1202 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1204 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1207 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1209 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1215 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1217 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1220 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1222 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1228 int ttsd_server_play_pcm(unsigned int uid)
1230 app_tts_state_e state = ttsd_data_get_client_state(uid);
1231 if (APP_STATE_NONE == state) {
1232 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
1233 return TTSD_ERROR_INVALID_PARAMETER;
1236 if (APP_STATE_PLAYING == state) {
1237 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state of (%u) is 'PLAYING'", uid);
1238 return TTSD_ERROR_NONE;
1241 unsigned int current_uid = ttsd_data_get_current_playing();
1242 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%u)", current_uid);
1244 if (uid != current_uid && 0 <= ttsd_data_is_client(current_uid)) {
1245 if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) {
1246 /* Send interrupt message */
1247 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Stop' state ", current_uid);
1250 if (0 != ttsd_server_stop(current_uid)) {
1251 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%u)", current_uid);
1254 /* Default mode policy of interrupt is "Pause" */
1256 /* Send interrupt message */
1257 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Pause' state ", current_uid);
1260 if (0 != ttsd_server_pause(current_uid)) {
1261 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_pause() : uid (%u)", current_uid);
1265 __send_interrupt_client(current_uid);
1268 /* Change current play */
1269 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1270 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%u)", uid);
1271 return TTSD_ERROR_OPERATION_FAILED;
1274 int ret = TTSD_ERROR_NONE;
1275 if (APP_STATE_PAUSED == state) {
1276 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid);
1277 ret = ttsd_player_resume(uid);
1279 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
1280 ret = ttsd_player_play(uid);
1283 if (TTSD_ERROR_NONE != ret) {
1284 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
1285 ttsd_data_set_client_state(uid, state);
1286 return TTSD_ERROR_OPERATION_FAILED;
1289 ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_PCM);
1291 return TTSD_ERROR_NONE;
1294 int ttsd_server_add_pcm(unsigned int uid, int event, void* data, int data_size, int audio_type, int rate)
1296 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1300 /* Synthesis is success */
1301 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1302 if (TTSE_RESULT_EVENT_START == event) {
1303 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1304 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1305 uid, uttid, data, data_size, audio_type, rate);
1306 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1307 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1308 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1309 uid, uttid, data, data_size, audio_type, rate);
1311 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1314 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1315 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1316 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1317 return TTSD_ERROR_INVALID_PARAMETER;
1320 sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
1321 if (NULL == sound_data) {
1322 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1323 return TTSD_ERROR_OUT_OF_MEMORY;
1326 if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
1327 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
1328 ttsd_data_destroy_sound_data(sound_data);
1331 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1334 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1336 return TTSD_ERROR_NONE;