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"
21 #include "ttsd_dbus.h"
22 #include "ttsd_dbus_server.h"
24 #include "ttsd_engine_agent.h"
25 #include "ttsd_main.h"
26 #include "ttsd_network.h"
27 #include "ttsd_player.h"
28 #include "ttsd_server.h"
31 #define CLIENT_CLEAN_UP_TIME 500
33 /* for checking time */
34 #define TIME_DIFF(start, end) \
35 ((uint64_t)((end).tv_sec - (start).tv_sec) * 1000000 + (((end).tv_nsec - (start).tv_nsec) / 1000)) / 1000
37 static struct timespec g_request_playing, g_start_playing;
38 static double g_avg_latency;
39 static double g_min_latency;
40 static double g_max_latency;
41 static int g_file_num;
48 /* If current engine exist */
49 //static bool g_is_engine;
51 static Ecore_Timer* g_check_client_timer = NULL;
52 static Ecore_Timer* g_wait_timer = NULL;
53 static Ecore_Timer* g_terminate_timer = NULL;
55 static utterance_t g_utt;
57 static GList *g_proc_list = NULL;
59 static bool g_is_paused;
62 /* Function definitions */
63 static int __synthesis(int uid, const char* credential);
65 static Eina_Bool __wait_synthesis(void *data)
67 /* get current play */
68 char* credential = (char*)data;
69 int uid = ttsd_data_get_current_playing();
72 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
76 if (TTSD_SYNTHESIS_CONTROL_DONE == ttsd_get_synth_control()) {
77 /* Start next synthesis */
78 __synthesis(uid, credential);
88 static int __synthesis(int uid, const char* credential)
90 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
92 speak_data_s* speak_data = NULL;
93 if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
94 if (NULL == speak_data) {
95 SLOG(LOG_WARN, tts_tag(), "[Server] speak data is null");
99 int pid = ttsd_data_get_pid(uid);
101 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d)", uid);
105 char appid[1024] = {0, };
106 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
107 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
110 if (NULL == speak_data->lang || NULL == speak_data->text) {
111 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
112 ttsd_server_stop(uid);
114 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
116 ttsd_data_clear_speak_data(&speak_data);
122 g_utt.uttid = speak_data->utt_id;
124 SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
125 SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
126 SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
127 SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
128 SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
129 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);
135 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
137 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
139 ttsd_server_stop(uid);
141 int pid = ttsd_data_get_pid(uid);
143 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
145 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
148 g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
151 ttsd_data_clear_speak_data(&speak_data);
153 ttsd_data_clear_speak_data(&speak_data);
156 SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
162 * TTS Server Callback Functions
164 int ttsd_send_error(ttse_error_e error, const char* msg)
167 int uttid = g_utt.uttid;
168 int tmp_pid = ttsd_data_get_pid(uid);
170 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%d), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg));
172 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
174 if (0 != ttsd_player_clear(uid))
175 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_clear()");
177 if (0 != ttsd_data_clear_data(uid))
178 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
181 if (0 != ttsdc_ipc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
182 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_error_message()");
185 if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
186 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
189 if (0 != ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
190 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_ipc_send_set_state_message()");
195 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)
197 SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
200 int uttid = g_utt.uttid;
202 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
203 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
204 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
205 SLOG(LOG_DEBUG, tts_tag(), "@@@");
206 return TTSD_ERROR_INVALID_PARAMETER;
209 if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) {
210 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
211 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
212 return TTSD_ERROR_INVALID_PARAMETER;
215 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
216 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
217 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
218 SLOG(LOG_DEBUG, tts_tag(), "@@@");
219 return TTSD_ERROR_INVALID_PARAMETER;
222 /* check the current state */
223 app_tts_state_e state;
224 if (0 > ttsd_data_get_client_state(uid, &state)) {
225 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
226 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
227 return TTSD_ERROR_INVALID_PARAMETER;
230 SLOG(LOG_INFO, tts_tag(), "[Server] uid(%d), current state(%d)", uid, state);
231 if (APP_STATE_CREATED == state || APP_STATE_READY == state) {
232 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
233 SLOG(LOG_WARN, tts_tag(), "[SERVER WARNING] Current state is %d. The synthesized result is ignored.", state);
234 return TTSD_ERROR_NONE;
237 /* Synthesis is success */
238 if (TTSE_RESULT_EVENT_START == event) {
239 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
240 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
241 uid, uttid, data, data_size, audio_type, rate);
243 clock_gettime(CLOCK_MONOTONIC_RAW, &g_start_playing);
244 long long int latency = (uint64_t)TIME_DIFF(g_request_playing, g_start_playing);
245 SLOG(LOG_INFO, tts_tag(), "[SERVER] Latency (Request playing ~ Get 1st synthesized results): %lld ms", latency);
246 double d_latency = (double)latency;
247 g_avg_latency += d_latency;
248 g_min_latency = (d_latency < g_min_latency) ? d_latency : g_min_latency;
249 g_max_latency = (d_latency > g_max_latency) ? d_latency : g_max_latency;
251 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);
252 } else if (TTSE_RESULT_EVENT_FINISH == event) {
253 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
254 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
255 uid, uttid, data, data_size, audio_type, rate);
257 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
261 sound_data_s* temp_sound_data = NULL;
262 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
263 if (NULL == temp_sound_data) {
264 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
265 return TTSD_ERROR_OUT_OF_MEMORY;
268 temp_sound_data->data = NULL;
269 temp_sound_data->rate = 0;
270 temp_sound_data->data_size = 0;
272 if (NULL != data && 0 < data_size) {
273 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
274 if (NULL != temp_sound_data->data) {
275 memcpy(temp_sound_data->data, data, data_size);
276 temp_sound_data->data_size = data_size;
277 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
278 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
280 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
283 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
286 temp_sound_data->utt_id = uttid;
287 temp_sound_data->event = event;
288 temp_sound_data->audio_type = audio_type;
289 temp_sound_data->rate = rate;
291 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
292 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
293 if (NULL != temp_sound_data->data) {
294 free(temp_sound_data->data);
295 temp_sound_data->data = NULL;
298 free(temp_sound_data);
299 temp_sound_data = NULL;
301 return TTSD_ERROR_OPERATION_FAILED;
304 if (event == TTSE_RESULT_EVENT_FINISH) {
305 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
308 return TTSD_ERROR_NONE;
311 bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
313 /* clear client data */
314 ttsd_data_clear_data(uid);
316 if (APP_STATE_READY != state) {
317 ttsd_data_set_client_state(uid, APP_STATE_READY);
320 if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
322 ttsd_data_delete_client(uid);
329 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
332 case TTS_CONFIG_TYPE_ENGINE:
334 /* TODO - Determine the policy when engine process get engine changed cb */
335 if (NULL == str_param) {
336 SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
341 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
342 SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
343 ret = ttsd_engine_agent_unload_current_engine();
345 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
348 ret = ttsd_engine_agent_load_current_engine();
350 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
355 /* stop all player */
356 ttsd_player_all_stop();
358 /* send interrupt message to all clients */
359 ttsd_data_foreach_clients(__get_client_cb, NULL);
361 ttsd_engine_cancel_synthesis();
366 case TTS_CONFIG_TYPE_VOICE:
368 if (NULL == str_param) {
369 SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
373 char* out_lang = NULL;
377 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
378 SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
379 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
381 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
383 /* Current language is not available */
384 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
386 if (NULL != out_lang) {
393 case TTS_CONFIG_TYPE_SPEED:
395 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
396 /* set default speed */
398 ret = ttsd_engine_agent_set_default_speed(int_param);
400 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
406 case TTS_CONFIG_TYPE_PITCH:
408 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
409 /* set default speed */
411 ret = ttsd_engine_agent_set_default_pitch(int_param);
413 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
419 case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
421 if (0.0 <= double_param && double_param <= 1.0) {
422 /* set default bg volume ratio */
424 ret = ttsd_player_set_background_volume_ratio(double_param);
426 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
436 bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
438 SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
439 ttsd_server_finalize(uid);
443 Eina_Bool ttsd_terminate_daemon(void *data)
445 ttsd_data_foreach_clients(__terminate_client, NULL);
446 g_terminate_timer = NULL;
450 void __screen_reader_changed_cb(bool value)
452 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
453 SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
454 if (g_terminate_timer) {
455 ecore_timer_del(g_terminate_timer);
456 g_terminate_timer = NULL;
458 g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL);
460 SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
465 int ttsd_send_all_stop()
467 SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
469 /* stop all player */
470 ttsd_player_all_stop();
472 /* send interrupt message to all clients */
473 ttsd_data_foreach_clients(__get_client_cb, NULL);
475 return TTSD_ERROR_NONE;
481 int ttsd_initialize(ttse_request_callback_s *callback)
483 SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
485 if (ttsd_config_initialize(__config_changed_cb)) {
486 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
490 if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
492 SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
493 int ret = ttsd_player_set_background_volume_ratio(ratio);
495 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
498 SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
501 if (ttsd_player_init()) {
502 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
503 return TTSD_ERROR_OPERATION_FAILED;
506 /* Engine Agent initialize */
507 if (0 != ttsd_engine_agent_init()) {
508 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
509 return TTSD_ERROR_OPERATION_FAILED;
512 /* set current engine */
513 //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
514 // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
515 // g_is_engine = false;
517 // g_is_engine = true;
519 if (0 != ttsd_engine_agent_load_current_engine(callback)) {
520 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
521 return TTSD_ERROR_OPERATION_FAILED;
524 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
526 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
527 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
530 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
531 if (NULL == g_check_client_timer) {
532 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
535 return TTSD_ERROR_NONE;
540 SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
543 if (0 < g_list_length(g_proc_list)) {
544 iter = g_list_first(g_proc_list);
545 while (NULL != iter) {
546 g_proc_list = g_list_remove_link(g_proc_list, iter);
548 iter = g_list_first(g_proc_list);
552 ttsd_config_finalize();
554 ttsd_player_release();
556 ttsd_engine_agent_release();
560 ecore_timer_del(g_wait_timer);
562 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore waiting timer handle");
565 if (g_terminate_timer) {
566 ecore_timer_del(g_terminate_timer);
567 g_terminate_timer = NULL;
568 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore terminating timer handle");
571 if (NULL != g_check_client_timer) {
572 ecore_timer_del(g_check_client_timer);
573 g_check_client_timer = NULL;
574 SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore checking client timer handle");
577 return TTSD_ERROR_NONE;
582 SLOG(LOG_INFO, tts_tag(), "[Server] Terminate");
584 ttsd_terminate_daemon(NULL);
586 return TTSD_ERROR_NONE;
590 * TTS Server Functions for Client
593 int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized)
595 if (-1 != ttsd_data_is_client(uid))
596 *is_initialized = true;
598 *is_initialized = false;
600 SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), Uid(%d) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet");
601 return TTSD_ERROR_NONE;
604 int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* credential_needed)
606 SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
608 if (-1 != ttsd_data_is_client(uid)) {
609 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
610 return TTSD_ERROR_NONE;
613 if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
614 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
615 return TTSD_ERROR_OPERATION_FAILED;
618 if (true == *credential_needed) {
620 if (0 != app_manager_get_app_id(pid, &appid)) {
621 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
623 bool is_agreed = false;
624 if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
625 SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
628 return TTSD_ERROR_OPERATION_FAILED;
633 if (false == is_agreed) {
634 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
635 return TTSD_ERROR_PERMISSION_DENIED;
639 if (0 != ttsd_data_new_client(pid, uid)) {
640 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
641 return TTSD_ERROR_OPERATION_FAILED;
644 if (0 != ttsd_data_set_ipc_method(uid, method)) {
645 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set ipc method");
646 return TTSD_ERROR_OPERATION_FAILED;
649 if (0 != ttsd_player_create_instance(uid)) {
650 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
651 return TTSD_ERROR_OPERATION_FAILED;
655 g_min_latency = 10000.0;
660 return TTSD_ERROR_NONE;
663 static Eina_Bool __quit_ecore_loop(void *data)
665 ttsd_ipc_close_connection();
666 ttsd_network_finalize();
668 ecore_main_loop_quit();
674 static void __read_proc()
677 struct dirent *dirp = NULL;
681 if (0 < g_list_length(g_proc_list)) {
682 iter = g_list_first(g_proc_list);
683 while (NULL != iter) {
684 g_proc_list = g_list_remove_link(g_proc_list, iter);
686 iter = g_list_first(g_proc_list);
690 dp = opendir("/proc");
692 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
698 tmp = atoi(dirp->d_name);
699 if (0 >= tmp) continue;
700 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
702 } while (NULL != dirp);
708 bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
714 for (i = 0; i < g_list_length(g_proc_list); i++) {
715 iter = g_list_nth(g_proc_list, i);
717 if (pid == GPOINTER_TO_INT(iter->data)) {
718 SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
725 if (false == exist) {
726 SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
727 ttsd_server_finalize(uid);
732 char appid[1024] = {0, };
733 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
734 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
737 if (0 < strlen(appid)) {
738 SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
740 SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
743 result = ttsdc_send_hello(pid, uid);
746 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
747 ttsd_server_finalize(uid);
748 } else if (-1 == result) {
749 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
757 Eina_Bool ttsd_cleanup_client(void *data)
759 SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
762 if (0 < ttsd_data_get_client_count()) {
763 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
765 ecore_timer_add(0, __quit_ecore_loop, NULL);
766 SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
767 g_check_client_timer = NULL;
771 SLOG(LOG_DEBUG, tts_tag(), "@@@");
776 void __used_voice_cb(const char* lang, int type)
778 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
779 if (0 != ttsd_engine_unload_voice(lang, type)) {
780 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
784 int ttsd_server_finalize(int uid)
786 SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
787 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);
789 app_tts_state_e state;
790 if (0 > ttsd_data_get_client_state(uid, &state)) {
791 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
794 ttsd_server_stop(uid);
795 ttsd_player_clear(uid);
797 ttsd_player_destroy_instance(uid);
799 /* Need to unload voice when used voice is unregistered */
800 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
801 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
802 return TTSD_ERROR_OPERATION_FAILED;
805 ttsd_data_delete_client(uid);
807 /* unload engine, if ref count of client is 0 */
808 if (0 == ttsd_data_get_client_count()) {
809 SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
810 ecore_timer_add(0, __quit_ecore_loop, NULL);
813 return TTSD_ERROR_NONE;
816 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
818 app_tts_state_e state;
819 if (0 > ttsd_data_get_client_state(uid, &state)) {
820 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
821 return TTSD_ERROR_INVALID_PARAMETER;
824 /* check valid voice */
825 char* temp_lang = NULL;
827 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
828 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
829 if (NULL != temp_lang) {
833 return TTSD_ERROR_INVALID_VOICE;
836 if (NULL == temp_lang) {
837 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
838 return TTSD_ERROR_INVALID_VOICE;
841 speak_data_s* speak_data = NULL;
842 speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
843 if (NULL == speak_data) {
844 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
845 if (NULL != temp_lang) {
849 return TTSD_ERROR_OPERATION_FAILED;
852 speak_data->lang = strdup(lang);
853 speak_data->vctype = voice_type;
855 speak_data->speed = speed;
856 speak_data->utt_id = utt_id;
858 speak_data->text = strdup(text);
860 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);
862 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
864 ret = ttsd_data_add_speak_data(uid, speak_data);
866 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
867 if (NULL != temp_lang) {
871 if (NULL != speak_data) {
872 if (NULL != speak_data->lang) free(speak_data->lang);
873 if (NULL != speak_data->text) free(speak_data->text);
875 speak_data->lang = NULL;
876 speak_data->text = NULL;
885 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
886 /* Request load voice */
887 SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
888 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
889 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
893 if (NULL != temp_lang) {
898 if (APP_STATE_PLAYING == state) {
899 /* check if engine use network */
900 if (ttsd_engine_agent_need_network()) {
901 if (false == ttsd_network_is_connected()) {
902 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
903 return TTSD_ERROR_OPERATION_FAILED;
907 /* Check whether tts-engine is running or not */
908 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
909 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
911 __synthesis(uid, credential);
915 return TTSD_ERROR_NONE;
918 Eina_Bool __send_interrupt_client(void *data)
920 intptr_t puid = (intptr_t)data;
923 int pid = ttsd_data_get_pid(uid);
925 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%d), pid(%d)", uid, pid);
929 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
930 /* send message to client about changing state */
931 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
933 ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
939 int ttsd_server_play(int uid, const char* credential)
941 app_tts_state_e state;
942 if (0 > ttsd_data_get_client_state(uid, &state)) {
943 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
944 return TTSD_ERROR_INVALID_PARAMETER;
947 if (APP_STATE_PLAYING == state) {
948 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
949 return TTSD_ERROR_NONE;
952 /* check if engine use network */
953 if (ttsd_engine_agent_need_network()) {
954 if (false == ttsd_network_is_connected()) {
955 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
956 return TTSD_ERROR_OUT_OF_NETWORK;
960 /* check the current playback focus */
961 if (TTSD_MODE_INTERRUPT != ttsd_get_mode() && ttsd_player_does_interrupt_have_playback_focus()) {
962 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
963 ttsd_data_clear_data(uid);
964 return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
967 int current_uid = ttsd_data_get_current_playing();
968 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
970 if (uid != current_uid && -1 != current_uid) {
971 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
972 /* Send interrupt message */
973 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
976 if (0 != ttsd_server_stop(current_uid)) {
977 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
980 intptr_t pcurrent_uid = (intptr_t)current_uid;
981 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
983 /* Default mode policy of interrupt is "Pause" */
985 /* Send interrupt message */
986 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
989 if (0 != ttsd_player_pause(current_uid)) {
990 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
994 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
996 intptr_t pcurrent_uid = (intptr_t)current_uid;
997 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1001 /* Change current play */
1002 if (0 != ttsd_player_wait_to_play(uid)) {
1003 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
1006 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1007 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1008 return TTSD_ERROR_OPERATION_FAILED;
1011 if (APP_STATE_PAUSED == state) {
1012 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1014 g_is_paused = false;
1017 if (0 != ttsd_player_resume(uid)) {
1018 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1021 SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%d)", uid);
1023 if (0 != ttsd_player_play(uid)) {
1024 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_play()");
1028 /* Check whether tts-engine is running or not */
1029 clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing);
1030 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) {
1031 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
1033 __synthesis(uid, credential);
1036 return TTSD_ERROR_NONE;
1039 int ttsd_server_stop(int uid)
1041 app_tts_state_e state;
1042 if (0 > ttsd_data_get_client_state(uid, &state)) {
1043 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1044 return TTSD_ERROR_INVALID_PARAMETER;
1047 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1049 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1050 if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control() && uid == ttsd_data_get_current_playing()) {
1051 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
1054 ret = ttsd_engine_cancel_synthesis();
1056 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
1058 ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
1061 if (0 != ttsd_player_stop(uid)) {
1062 SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
1065 ttsd_data_set_client_state(uid, APP_STATE_READY);
1068 /* Reset all data */
1069 ttsd_data_clear_data(uid);
1070 g_is_paused = false;
1072 return TTSD_ERROR_NONE;
1075 int ttsd_server_pause(int uid, int* utt_id)
1077 app_tts_state_e state;
1078 if (0 > ttsd_data_get_client_state(uid, &state)) {
1079 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
1080 return TTSD_ERROR_INVALID_PARAMETER;
1083 if (APP_STATE_PLAYING != state) {
1084 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
1085 return TTSD_ERROR_INVALID_STATE;
1090 *utt_id = g_utt.uttid;
1091 SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
1094 ret = ttsd_player_pause(uid);
1096 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
1097 return TTSD_ERROR_OPERATION_FAILED;
1100 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
1102 return TTSD_ERROR_NONE;
1105 int ttsd_server_get_support_voices(int uid, GList** voice_list)
1107 app_tts_state_e state;
1108 if (0 > ttsd_data_get_client_state(uid, &state)) {
1109 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1110 return TTSD_ERROR_INVALID_PARAMETER;
1114 int ret = ttsd_engine_get_voice_list(voice_list);
1116 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1120 SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
1122 return TTSD_ERROR_NONE;
1125 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
1127 app_tts_state_e state;
1128 if (0 > ttsd_data_get_client_state(uid, &state)) {
1129 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
1130 return TTSD_ERROR_INVALID_PARAMETER;
1133 /* get current voice */
1134 int ret = ttsd_engine_get_default_voice(language, voice_type);
1136 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
1140 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
1142 return TTSD_ERROR_NONE;
1145 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
1147 app_tts_state_e state;
1148 if (0 > ttsd_data_get_client_state(uid, &state)) {
1149 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1150 return TTSD_ERROR_INVALID_PARAMETER;
1153 if (APP_STATE_READY != state) {
1154 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1155 return TTSD_ERROR_INVALID_STATE;
1158 int ret = ttsd_engine_set_private_data(key, data);
1160 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
1162 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
1168 int ttsd_server_get_private_data(int uid, const char* key, char** data)
1170 app_tts_state_e state;
1171 if (0 > ttsd_data_get_client_state(uid, &state)) {
1172 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
1173 return TTSD_ERROR_INVALID_PARAMETER;
1176 if (APP_STATE_READY != state) {
1177 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
1178 return TTSD_ERROR_INVALID_STATE;
1181 int ret = ttsd_engine_get_private_data(key, data);
1183 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
1185 SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
1191 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
1193 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
1196 ret = ttsd_engine_agent_set_private_data_set_cb(callback);
1198 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
1204 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
1206 SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
1209 ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
1211 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
1217 int ttsd_server_play_pcm(int uid)
1219 app_tts_state_e state;
1220 if (0 > ttsd_data_get_client_state(uid, &state)) {
1221 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
1222 return TTSD_ERROR_INVALID_PARAMETER;
1225 if (APP_STATE_PLAYING == state) {
1226 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
1227 return TTSD_ERROR_NONE;
1230 int current_uid = ttsd_data_get_current_playing();
1231 SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
1233 if (uid != current_uid && -1 != current_uid) {
1234 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
1235 /* Send interrupt message */
1236 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
1239 if (0 != ttsd_server_stop(current_uid)) {
1240 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%d)", current_uid);
1243 intptr_t pcurrent_uid = (intptr_t)current_uid;
1244 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1246 /* Default mode policy of interrupt is "Pause" */
1248 /* Send interrupt message */
1249 SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
1252 if (0 != ttsd_player_pause(current_uid)) {
1253 SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
1257 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
1259 intptr_t pcurrent_uid = (intptr_t)current_uid;
1260 ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
1264 /* Change current play */
1265 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
1266 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
1267 return TTSD_ERROR_OPERATION_FAILED;
1270 if (APP_STATE_PAUSED == state) {
1271 SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
1274 if (0 != ttsd_player_resume(uid)) {
1275 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
1278 if (0 != ttsd_player_play(uid)) {
1279 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
1281 // Change ready state
1282 ttsd_server_stop_pcm(uid);
1284 int tmp_pid = ttsd_data_get_pid(uid);
1286 SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%d)", uid);
1288 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1293 return TTSD_ERROR_NONE;
1296 int ttsd_server_stop_pcm(int uid)
1298 app_tts_state_e state;
1299 if (0 > ttsd_data_get_client_state(uid, &state)) {
1300 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
1301 return TTSD_ERROR_INVALID_PARAMETER;
1304 SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
1306 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
1307 ttsd_data_set_client_state(uid, APP_STATE_READY);
1310 /* Reset all data */
1311 ttsd_data_clear_data(uid);
1313 ttsd_player_stop(uid);
1316 return TTSD_ERROR_NONE;
1319 int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
1321 SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
1325 /* Synthesis is success */
1326 if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
1327 if (TTSE_RESULT_EVENT_START == event) {
1328 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
1329 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1330 uid, uttid, data, data_size, audio_type, rate);
1331 } else if (TTSE_RESULT_EVENT_FINISH == event) {
1332 SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
1333 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
1334 uid, uttid, data, data_size, audio_type, rate);
1336 /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
1339 if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
1340 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
1341 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1342 return TTSD_ERROR_INVALID_PARAMETER;
1346 sound_data_s* temp_sound_data = NULL;
1347 temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
1348 if (NULL == temp_sound_data) {
1349 SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
1350 return TTSD_ERROR_OUT_OF_MEMORY;
1353 temp_sound_data->data = NULL;
1354 temp_sound_data->rate = 0;
1355 temp_sound_data->data_size = 0;
1357 if (0 < data_size) {
1358 temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
1359 if (NULL != temp_sound_data->data) {
1360 memcpy(temp_sound_data->data, data, data_size);
1361 temp_sound_data->data_size = data_size;
1362 SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
1363 uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
1365 SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
1368 SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
1371 temp_sound_data->utt_id = uttid;
1372 temp_sound_data->event = event;
1373 temp_sound_data->audio_type = audio_type;
1374 temp_sound_data->rate = rate;
1376 if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
1377 SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
1379 if (NULL != temp_sound_data->data) {
1380 free(temp_sound_data->data);
1381 temp_sound_data->data = NULL;
1384 free(temp_sound_data);
1385 temp_sound_data = NULL;
1388 /* if (0 != ttsd_player_play(uid)) {
1389 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
1391 // Change ready state
1392 ttsd_server_stop(uid);
1395 tmp_pid = ttsd_data_get_pid(uid);
1396 ttsdc_ipc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
1400 SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
1403 SLOG(LOG_DEBUG, tts_tag(), "@@@");
1405 return TTSD_ERROR_NONE;