/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* limitations under the License.
*/
+#include <app_manager.h>
+#include <aul.h>
#include <Ecore.h>
-#include "ttsd_main.h"
-#include "ttsd_player.h"
+
+#include "ttsd_config.h"
#include "ttsd_data.h"
-#include "ttsd_engine_agent.h"
-#include "ttsd_server.h"
-#include "ttsd_dbus_server.h"
-#include "ttsp.h"
#include "ttsd_dbus.h"
-#include "ttsd_config.h"
+#include "ttsd_dbus_server.h"
+#include "ttsd_engine_agent.h"
+#include "ttsd_main.h"
#include "ttsd_network.h"
+#include "ttsd_player.h"
+#include "ttsd_server.h"
+
+
+#define CLIENT_CLEAN_UP_TIME 500
+
typedef enum {
TTSD_SYNTHESIS_CONTROL_DOING = 0,
TTSD_SYNTHESIS_CONTROL_DONE = 1,
TTSD_SYNTHESIS_CONTROL_EXPIRED = 2
-}ttsd_synthesis_control_e;
+} ttsd_synthesis_control_e;
typedef struct {
int uid;
int uttid;
-}utterance_t;
+} utterance_t;
/* If current engine exist */
-static bool g_is_engine;
+//static bool g_is_engine;
/* If engine is running */
static ttsd_synthesis_control_e g_synth_control;
+static Ecore_Timer* g_check_client_timer = NULL;
static Ecore_Timer* g_wait_timer = NULL;
-/* Function definitions */
-int __server_next_synthesis(int uid);
+static utterance_t g_utt;
+static GList *g_proc_list = NULL;
+
+/* Function definitions */
+static int __synthesis(int uid, const char* credential);
-int __server_set_synth_control(ttsd_synthesis_control_e control)
+static int __server_set_synth_control(ttsd_synthesis_control_e control)
{
g_synth_control = control;
return 0;
}
-ttsd_synthesis_control_e __server_get_synth_control()
+static ttsd_synthesis_control_e __server_get_synth_control()
{
return g_synth_control;
}
-int __server_send_error(int uid, int utt_id, int error_code)
-{
- int pid = ttsd_data_get_pid(uid);
-
- /* send error */
- if ( 0 != ttsdc_send_error_message(pid, uid, utt_id, error_code)) {
- ttsd_data_delete_client(uid);
- }
-
- return 0;
-}
-
-Eina_Bool __wait_synthesis(void *data)
+static Eina_Bool __wait_synthesis(void *data)
{
/* get current play */
- int uid = ttsd_data_is_current_playing();
+ char* credential = (char*)data;
+ int uid = ttsd_data_get_current_playing();
if (uid > 0) {
if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
g_wait_timer = NULL;
if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
/* Start next synthesis */
- __server_next_synthesis(uid);
+ __synthesis(uid, credential);
}
- }
+ }
} else {
g_wait_timer = NULL;
}
return EINA_FALSE;
}
-int __synthesis(int uid)
+static int __synthesis(int uid, const char* credential)
{
- speak_data_s sdata;
- if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS START");
- utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
+ speak_data_s* speak_data = NULL;
+ if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
+ if (NULL == speak_data) {
+ SLOG(LOG_WARN, tts_tag(), "[Server] speak data is null");
+ return 0;
+ }
- if (NULL == utt) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] fail to allocate memory : utterance ", __FUNCTION__);
- return TTSD_ERROR_OUT_OF_MEMORY;
+ int pid = ttsd_data_get_pid(uid);
+ char appid[1024] = {0, };
+ if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
}
- utt->uid = uid;
- utt->uttid = sdata.utt_id;
+ if (NULL == speak_data->lang || NULL == speak_data->text) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
+ ttsd_server_stop(uid);
+
+ ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
+
+ if (NULL != speak_data) {
+ if (NULL != speak_data->lang) free(speak_data->lang);
+ if (NULL != speak_data->text) free(speak_data->text);
+
+ speak_data->lang = NULL;
+ speak_data->text = NULL;
+
+ free(speak_data);
+ speak_data = NULL;
+ }
- SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
- SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
- SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
- SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text);
- SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
+ return 0;
+ }
+
+ g_utt.uid = uid;
+ g_utt.uttid = speak_data->utt_id;
+
+ SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
+ SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
+ SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
+ SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
+ SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
+ SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
int ret = 0;
__server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
- ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
+ ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
__server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
- ttsd_config_save_error(utt->uid, utt->uttid, sdata.lang, sdata.vctype, sdata.text, __FUNCTION__, __LINE__, "fail to start synthesis");
-
- g_free(utt);
-
ttsd_server_stop(uid);
int pid = ttsd_data_get_pid(uid);
ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
} else {
- g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
+ g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
}
- if(sdata.text != NULL)
- g_free(sdata.text);
- } else {
- SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
- SLOG(LOG_DEBUG, get_tag(), "[Server] Text queue is empty.");
- SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
+ if (NULL != speak_data) {
+ if (NULL != speak_data->lang) free(speak_data->lang);
+ if (NULL != speak_data->text) free(speak_data->text);
+
+ speak_data->lang = NULL;
+ speak_data->text = NULL;
+
+ free(speak_data);
+ speak_data = NULL;
+ }
}
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS END");
+
return 0;
}
-int __server_next_synthesis(int uid)
+/*
+* TTS Server Callback Functions
+*/
+int ttsd_send_error(ttse_error_e error, const char* msg)
{
- SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START");
-
- /* get current playing client */
- int current_uid = ttsd_data_get_current_playing();
+ int uid = g_utt.uid;
+ int uttid = g_utt.uttid;
+ int tmp_pid = ttsd_data_get_pid(uid);
- if (0 > current_uid) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid");
- SLOG(LOG_DEBUG, get_tag(), "=====");
- SLOG(LOG_DEBUG, get_tag(), " ");
- return 0;
- }
+ 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));
- if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. ");
- SLOG(LOG_DEBUG, get_tag(), "=====");
- SLOG(LOG_DEBUG, get_tag(), " ");
- return 0;
- }
-
- __synthesis(current_uid);
+ __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
- if (0 != ttsd_player_play(current_uid)) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() ");
- } else {
- /* success playing */
- SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
- }
+ if (0 != ttsd_player_clear(uid))
+ SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
- SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY END");
- SLOG(LOG_DEBUG, get_tag(), " ");
+ if (0 != ttsd_data_clear_data(uid))
+ SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
- return 0;
-}
+ if (0 != ttsdc_send_error_message(tmp_pid, uid, uttid, error, (char*)msg))
+ SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_send_error_message()");
-/*
-* TTS Server Callback Functions
-*/
+ if (0 != ttsd_data_set_client_state(uid, APP_STATE_READY))
+ SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_set_client_state()");
-int __player_result_callback(player_event_e event, int uid, int utt_id)
-{
- switch(event) {
- case PLAYER_ERROR:
- SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR][%s] player result error", __FUNCTION__);
- __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED);
- ttsd_config_save_error(uid, utt_id, NULL, -1, NULL, __FUNCTION__, __LINE__, "PLAYER_ERROR");
-
- case PLAYER_EMPTY_SOUND_QUEUE:
- /* check whether synthesis is running */
- if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
- /* check text queue is empty */
- if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) {
- SLOG(LOG_DEBUG, get_tag(), "[SERVER Callback] all play completed ");
- }
- }
- break;
-
- case PLAYER_END_OF_PLAYING:
- break;
- }
+ if (0 != ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY))
+ SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsdc_send_set_state_message()");
return 0;
}
-int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
+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)
{
- SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK START");
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
- utterance_t* utt_get_param;
- utt_get_param = (utterance_t*)user_data;
-
- if (NULL == utt_get_param) {
- SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] User data is NULL " );
- SLOG(LOG_DEBUG, get_tag(), "=====");
- SLOG(LOG_DEBUG, get_tag(), " ");
- return -1;
- }
-
- int uid = utt_get_param->uid;
- int uttid = utt_get_param->uttid;
+ int uid = g_utt.uid;
+ int uttid = g_utt.uttid;
/* Synthesis is success */
- if (TTSP_RESULT_EVENT_START == event || TTSP_RESULT_EVENT_CONTINUE == event || TTSP_RESULT_EVENT_FINISH == event) {
-
- if (TTSP_RESULT_EVENT_START == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_START");
- if (TTSP_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CONTINUE");
- if (TTSP_RESULT_EVENT_FINISH == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_FINISH");
+ if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
+ if (TTSE_RESULT_EVENT_START == event) {
+ SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
+ uid, uttid, data, data_size, audio_type, rate);
+ } else if (TTSE_RESULT_EVENT_FINISH == event) {
+ SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
+ uid, uttid, data, data_size, audio_type, rate);
+ } else {
+ /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
+ }
- if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
- SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
- SLOG(LOG_DEBUG, get_tag(), "=====");
- SLOG(LOG_DEBUG, get_tag(), " ");
- return 0;
+ if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
+ __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
+ return TTSD_ERROR_OPERATION_FAILED;
}
- SLOG(LOG_DEBUG, get_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) ",
- uid, uttid, data, data_size);
+ if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
+ __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
+ return TTSD_ERROR_INVALID_PARAMETER;
+ }
/* add wav data */
- sound_data_s temp_data;
- temp_data.data = (char*)g_malloc0( sizeof(char) * data_size );
- memcpy(temp_data.data, data, data_size);
-
- temp_data.data_size = data_size;
- temp_data.utt_id = utt_get_param->uttid;
- temp_data.event = event;
-
- ttsp_audio_type_e audio_type;
- int rate;
- int channels;
-
- if (ttsd_engine_get_audio_format(&audio_type, &rate, &channels)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get audio format ");
- SLOG(LOG_DEBUG, get_tag(), "=====");
- SLOG(LOG_DEBUG, get_tag(), " ");
- return -1;
+ sound_data_s* temp_sound_data = NULL;
+ temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
+ if (NULL == temp_sound_data) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
+ return TTSD_ERROR_OUT_OF_MEMORY;
}
-
- temp_data.audio_type = audio_type;
- temp_data.rate = rate;
- temp_data.channels = channels;
-
- if (0 != ttsd_data_add_sound_data(uid, temp_data)) {
- SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", utt_get_param->uid);
+
+ temp_sound_data->data = NULL;
+ temp_sound_data->rate = 0;
+ temp_sound_data->data_size = 0;
+
+ if (0 < data_size) {
+ temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
+ if (NULL != temp_sound_data->data) {
+ memcpy(temp_sound_data->data, data, data_size);
+ temp_sound_data->data_size = data_size;
+ SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
+ uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
+ }
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
}
- if (event == TTSP_RESULT_EVENT_FINISH) {
+ temp_sound_data->utt_id = uttid;
+ temp_sound_data->event = event;
+ temp_sound_data->audio_type = audio_type;
+ temp_sound_data->rate = rate;
+
+ if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
+ SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
+ }
+
+ if (event == TTSE_RESULT_EVENT_FINISH) {
__server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
}
- } else if (event == TTSP_RESULT_EVENT_CANCEL) {
- SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL");
- __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+
+ if (0 != ttsd_player_play(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
+
+ /* Change ready state */
+ ttsd_server_stop(uid);
+
+ int tmp_pid;
+ tmp_pid = ttsd_data_get_pid(uid);
+ ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+ }
} else {
- SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_ERROR");
+ SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
__server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
- }
-
- if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) {
- if (NULL != utt_get_param)
- free(utt_get_param);
}
- SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK END");
- SLOG(LOG_DEBUG, get_tag(), " ");
-#if 0
- if (true == __server_get_is_next_synthesis()) {
- __server_set_is_next_synthesis(false);
+ /*SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS RESULT CALLBACK END");
+ SLOG(LOG_DEBUG, tts_tag(), " ");*/
- /* Do NOT work ecore timer because of This function is thread callbacked */
- /* need to send dbus message event */
- ttsd_send_start_next_synthesis();
- }
-#endif
-
- return 0;
+ return TTSD_ERROR_NONE;
}
-bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
{
/* clear client data */
- ttsd_data_clear_data(uid);
+ ttsd_data_clear_data(uid);
ttsd_data_set_client_state(uid, APP_STATE_READY);
/* send message */
- if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
+ if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
/* remove client */
ttsd_data_delete_client(uid);
- }
+ }
return true;
}
void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param)
{
- switch(type) {
+ switch (type) {
case TTS_CONFIG_TYPE_ENGINE:
{
+ /* TODO - Determine the policy when engine process get engine changed cb */
if (NULL == str_param) {
- SLOG(LOG_ERROR, get_tag(), "[Server] engine id from config is NULL");
+ SLOG(LOG_ERROR, tts_tag(), "[Server] engine id from config is NULL");
return;
}
+ int ret = 0;
if (true == ttsd_engine_agent_is_same_engine(str_param)) {
- SLOG(LOG_DEBUG, get_tag(), "[Server Setting] new engine is the same as current engine ");
+ SLOG(LOG_DEBUG, tts_tag(), "[Server Setting] new engine is the same as current engine");
+ ret = ttsd_engine_agent_unload_current_engine();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
+ }
+
+ ret = ttsd_engine_agent_load_current_engine();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
+ }
return;
}
ttsd_engine_cancel_synthesis();
- /* set engine */
- int ret = 0;
- ret = ttsd_engine_setting_set_engine(str_param);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
- }
-
break;
}
-
+
case TTS_CONFIG_TYPE_VOICE:
{
if (NULL == str_param) {
- SLOG(LOG_ERROR, get_tag(), "[Server] language from config is NULL");
+ SLOG(LOG_ERROR, tts_tag(), "[Server] language from config is NULL");
return;
}
- char* out_lang;
- ttsp_voice_type_e out_type;
+ char* out_lang = NULL;
+ int out_type;
int ret = -1;
if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
- SLOG(LOG_ERROR, get_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
- ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
+ SLOG(LOG_ERROR, tts_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
+ ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
if (0 != ret)
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
-
- if (NULL == out_lang)
- free(out_lang);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
} else {
/* Current language is not available */
- if (true == ttsd_engine_select_valid_voice("en_US", 2, &out_lang, &out_type)) {
- ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
- if (0 != ret)
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
-
- if (NULL == out_lang)
- free(out_lang);
- }
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
+ }
+ if (NULL != out_lang) {
+ free(out_lang);
+ out_lang = NULL;
}
break;
}
-
+
case TTS_CONFIG_TYPE_SPEED:
{
- if (TTSP_SPEED_VERY_SLOW <= int_param && int_param <= TTSP_SPEED_VERY_FAST) {
+ if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
/* set default speed */
int ret = 0;
- ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)int_param);
+ ret = ttsd_engine_agent_set_default_speed(int_param);
if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to set default speed : result(%d)", ret);
- }
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
+ }
}
break;
}
-
- default:
+
+ case TTS_CONFIG_TYPE_PITCH:
+ {
+ if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
+ /* set default speed */
+ int ret = 0;
+ ret = ttsd_engine_agent_set_default_pitch(int_param);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
+ }
+ }
break;
}
-
+ }
+
return;
}
+bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
+{
+ SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
+ ttsd_server_finalize(uid);
+ return true;
+}
+
+Eina_Bool ttsd_terminate_daemon(void *data)
+{
+ ttsd_data_foreach_clients(__terminate_client, NULL);
+ return EINA_FALSE;
+}
+
+void __screen_reader_changed_cb(bool value)
+{
+ if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
+ SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
+ ecore_timer_add(1, ttsd_terminate_daemon, NULL);
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
+ }
+ return;
+}
/*
* Server APIs
*/
-
-int ttsd_initialize()
+int ttsd_initialize(ttse_request_callback_s *callback)
{
+ SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
+
if (ttsd_config_initialize(__config_changed_cb)) {
- SLOG(LOG_ERROR, get_tag(), "[Server WARNING] Fail to initialize config.");
+ SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
}
/* player init */
- if (ttsd_player_init(__player_result_callback)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to initialize player init.");
+ if (ttsd_player_init()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
return TTSD_ERROR_OPERATION_FAILED;
}
/* Engine Agent initialize */
- if (0 != ttsd_engine_agent_init(__synthesis_result_callback)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to engine agent initialize.");
+ if (0 != ttsd_engine_agent_init()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
return TTSD_ERROR_OPERATION_FAILED;
}
/* set current engine */
- if (0 != ttsd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!!" );
- g_is_engine = false;
- } else
- g_is_engine = true;
-
+ //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
+ // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
+ // g_is_engine = false;
+ //} else
+ // g_is_engine = true;
+
+ if (0 != ttsd_engine_agent_load_current_engine(callback)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+
__server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+ if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
+ ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
+ }
+
+ g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
+ if (NULL == g_check_client_timer) {
+ SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
+ }
+
return TTSD_ERROR_NONE;
}
int ttsd_finalize()
{
+ SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
+
+ GList *iter = NULL;
+ if (0 < g_list_length(g_proc_list)) {
+ iter = g_list_first(g_proc_list);
+ while (NULL != iter) {
+ g_proc_list = g_list_remove_link(g_proc_list, iter);
+ g_list_free(iter);
+ iter = g_list_first(g_proc_list);
+ }
+ }
+
ttsd_config_finalize();
-
+
ttsd_player_release();
ttsd_engine_agent_release();
- return TTSD_ERROR_NONE;
-}
-
-bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
-{
- int result = 1;
-
- result = ttsdc_send_hello(pid, uid);
+ if (NULL != g_check_client_timer) {
+ ecore_timer_del(g_check_client_timer);
+ g_check_client_timer = NULL;
- if (0 == result) {
- SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) should be removed.", uid);
- ttsd_server_finalize(uid);
- } else if (-1 == result) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Hello result has error");
+ SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore timer handle");
}
- return true;
-}
-
-
-Eina_Bool ttsd_cleanup_client(void *data)
-{
- SLOG(LOG_DEBUG, get_tag(), "===== CLEAN UP CLIENT START");
- ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
- SLOG(LOG_DEBUG, get_tag(), "=====");
- SLOG(LOG_DEBUG, get_tag(), " ");
-
- return EINA_TRUE;
+ return TTSD_ERROR_NONE;
}
/*
* TTS Server Functions for Client
*/
-int ttsd_server_initialize(int pid, int uid)
+int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
{
- if (false == g_is_engine) {
- if (0 != ttsd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!! " );
- g_is_engine = false;
+ SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- } else {
- g_is_engine = true;
- }
+ if (-1 != ttsd_data_is_client(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
+ return TTSD_ERROR_NONE;
}
- if (-1 != ttsd_data_is_client(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Uid has already been registered ");
- return TTSD_ERROR_INVALID_PARAMETER;
+ if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
+ return TTSD_ERROR_OPERATION_FAILED;
}
- if (0 == ttsd_data_get_client_count()) {
- if (0 != ttsd_engine_agent_load_current_engine()) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine ");
+ if (true == *credential_needed) {
+ char* appid = NULL;
+ if (0 != app_manager_get_app_id(pid, &appid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
+ }
+ bool is_agreed = false;
+ if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
+ SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
+ if (!appid)
+ free(appid);
return TTSD_ERROR_OPERATION_FAILED;
}
- /* Check system language */
- ttsd_config_update_language();
- }
+ if (!appid)
+ free(appid);
- if (0 == ttsd_data_get_same_pid_client_count(pid)) {
- SLOG(LOG_DEBUG, get_tag(), "[Server] open file msg connection");
- if (0 != ttsd_file_msg_open_connection(pid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to open file message connection");
- return TTSD_ERROR_OPERATION_FAILED;
+ if (false == is_agreed) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+ return TTSD_ERROR_PERMISSION_DENIED;
}
}
if (0 != ttsd_data_new_client(pid, uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
return TTSD_ERROR_OPERATION_FAILED;
}
if (0 != ttsd_player_create_instance(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to create player ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
return TTSD_ERROR_OPERATION_FAILED;
}
static Eina_Bool __quit_ecore_loop(void *data)
{
+ ttsd_dbus_close_connection();
+ ttsd_network_finalize();
+ ttsd_finalize();
ecore_main_loop_quit();
- SLOG(LOG_DEBUG, get_tag(), "[Server] quit ecore main loop");
+
return EINA_FALSE;
}
+
+static void __read_proc()
+{
+ DIR *dp = NULL;
+ struct dirent *dirp = NULL;
+ int tmp;
+
+ GList *iter = NULL;
+ if (0 < g_list_length(g_proc_list)) {
+ iter = g_list_first(g_proc_list);
+ while (NULL != iter) {
+ g_proc_list = g_list_remove_link(g_proc_list, iter);
+ g_list_free(iter);
+ iter = g_list_first(g_proc_list);
+ }
+ }
+
+ dp = opendir("/proc");
+ if (NULL == dp) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
+ } else {
+ do {
+ dirp = readdir(dp);
+
+ if (NULL != dirp) {
+ tmp = atoi(dirp->d_name);
+ if (0 >= tmp) continue;
+ g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
+ }
+ } while (NULL != dirp);
+ closedir(dp);
+ }
+ return;
+}
+
+bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
+{
+ bool exist = false;
+ int i = 0;
+
+ GList *iter = NULL;
+ for (i = 0; i < g_list_length(g_proc_list); i++) {
+ iter = g_list_nth(g_proc_list, i);
+ if (NULL != iter) {
+ if (pid == GPOINTER_TO_INT(iter->data)) {
+ SLOG(LOG_DEBUG, tts_tag(), "uid (%d) is running", uid);
+ exist = true;
+ break;
+ }
+ }
+ }
+
+ if (false == exist) {
+ SLOG(LOG_ERROR, tts_tag(), "uid (%d) should be removed", uid);
+ ttsd_server_finalize(uid);
+ }
+
+ return true;
+#if 0
+ char appid[1024] = {0, };
+ if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
+ }
+
+ if (0 < strlen(appid)) {
+ SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
+
+ int result = 1;
+ result = ttsdc_send_hello(pid, uid);
+
+ if (0 == result) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) should be removed.", uid);
+ ttsd_server_finalize(uid);
+ } else if (-1 == result) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
+ }
+ }
+ return true;
+#endif
+}
+
+
+Eina_Bool ttsd_cleanup_client(void *data)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
+ __read_proc();
+
+ if (0 < ttsd_data_get_client_count()) {
+ ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
+ } else {
+ ecore_timer_add(0, __quit_ecore_loop, NULL);
+ }
+
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
+
+ return EINA_TRUE;
+}
+
+void __used_voice_cb(const char* lang, int type)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
+ if (0 != ttsd_engine_unload_voice(lang, type)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to unload voice");
+ }
+}
+
int ttsd_server_finalize(int uid)
{
- app_state_e state;
+ SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
+
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid ");
- return TTSD_ERROR_INVALID_PARAMETER;
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
}
ttsd_server_stop(uid);
-
+ ttsd_player_stop(uid);
+
ttsd_player_destroy_instance(uid);
- int pid = ttsd_data_get_pid(uid);
+ /* Need to unload voice when used voice is unregistered */
+ if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set used voice");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
ttsd_data_delete_client(uid);
- if (0 == ttsd_data_get_same_pid_client_count(pid)) {
- SLOG(LOG_DEBUG, get_tag(), "[Sever] File msg close connection");
- ttsd_file_msg_close_connection(pid);
- }
-
/* unload engine, if ref count of client is 0 */
if (0 == ttsd_data_get_client_count()) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Quit main loop");
ecore_timer_add(0, __quit_ecore_loop, NULL);
}
return TTSD_ERROR_NONE;
}
-int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
+int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
{
- app_state_e state;
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
/* check valid voice */
char* temp_lang = NULL;
- ttsp_voice_type_e temp_type;
- if (true != ttsd_engine_select_valid_voice((const char*)lang, (const ttsp_voice_type_e)voice_type, &temp_lang, &temp_type)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to select valid voice ");
+ int temp_type;
+ if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
+ if (NULL != temp_lang) {
+ free(temp_lang);
+ temp_lang = NULL;
+ }
+ return TTSD_ERROR_INVALID_VOICE;
+ }
+
+ if (NULL == temp_lang) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
return TTSD_ERROR_INVALID_VOICE;
- } else {
- if (NULL == temp_lang)
+ }
+
+ speak_data_s* speak_data = NULL;
+ speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
+ if (NULL == speak_data) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
+ if (NULL != temp_lang) {
free(temp_lang);
+ temp_lang = NULL;
+ }
+ return TTSD_ERROR_OPERATION_FAILED;
}
-
- speak_data_s data;
- data.lang = strdup(lang);
- data.vctype = (ttsp_voice_type_e)voice_type;
+ speak_data->lang = strdup(lang);
+ speak_data->vctype = voice_type;
- data.speed = (ttsp_speed_e)speed;
- data.utt_id = utt_id;
-
- data.text = strdup(text);
+ speak_data->speed = speed;
+ speak_data->utt_id = utt_id;
+
+ speak_data->text = strdup(text);
+
+ 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);
/* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
- if (0 != ttsd_data_add_speak_data(uid, data)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : Current state of uid is not 'ready' ");
- return TTSD_ERROR_OPERATION_FAILED;
+ int ret = -1;
+ ret = ttsd_data_add_speak_data(uid, speak_data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
+ if (NULL != temp_lang) {
+ free(temp_lang);
+ temp_lang = NULL;
+ }
+ if (NULL != speak_data) {
+ if (NULL != speak_data->lang) free(speak_data->lang);
+ if (NULL != speak_data->text) free(speak_data->text);
+
+ speak_data->lang = NULL;
+ speak_data->text = NULL;
+
+ free(speak_data);
+ speak_data = NULL;
+ }
+
+ return ret;
+ }
+
+ if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
+ /* Request load voice */
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to load voice");
+ if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load voice");
+ }
+ }
+
+ if (NULL != temp_lang) {
+ free(temp_lang);
+ temp_lang = NULL;
}
if (APP_STATE_PLAYING == state) {
/* check if engine use network */
if (ttsd_engine_agent_need_network()) {
if (false == ttsd_network_is_connected()) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
return TTSD_ERROR_OPERATION_FAILED;
}
}
/* Check whether tts-engine is running or not */
if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
} else {
- __synthesis(uid);
+ __synthesis(uid, credential);
}
}
Eina_Bool __send_interrupt_client(void *data)
{
- int* uid = (int*)data;
-
- if (NULL != uid) {
- int pid = ttsd_data_get_pid(*uid);
+ intptr_t puid = (intptr_t)data;
+ int uid = (int)puid;
+
+ int pid = ttsd_data_get_pid(uid);
+
+ if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
/* send message to client about changing state */
- ttsdc_send_set_state_message (pid, *uid, APP_STATE_PAUSED);
- free(uid);
+ ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
+ } else {
+ ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
}
+
return EINA_FALSE;
}
-int ttsd_server_play(int uid)
+int ttsd_server_play(int uid, const char* credential)
{
- app_state_e state;
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
-
+
if (APP_STATE_PLAYING == state) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
return TTSD_ERROR_NONE;
}
/* check if engine use network */
if (ttsd_engine_agent_need_network()) {
if (false == ttsd_network_is_connected()) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
return TTSD_ERROR_OUT_OF_NETWORK;
}
}
+ /* check the current playback focus */
+ if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
+ bool is_current_interrupt = false;
+ if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
+ } else {
+ if (true == is_current_interrupt) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
+ return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
+ }
+ }
+ }
+
int current_uid = ttsd_data_get_current_playing();
+ SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
if (uid != current_uid && -1 != current_uid) {
- /* Send interrupt message */
- SLOG(LOG_DEBUG, get_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
+ if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+ /* Send interrupt message */
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
+
+ /* pause player */
+ if (0 != ttsd_server_stop(current_uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
+ }
+ if (0 != ttsd_player_stop(current_uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to player stop : uid (%d)", current_uid);
+ }
+
+ intptr_t pcurrent_uid = (intptr_t)current_uid;
+ ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+ } else {
+ /* Default mode policy of interrupt is "Pause" */
+
+ /* Send interrupt message */
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
- /* pause player */
- if (0 != ttsd_player_pause(current_uid)) {
- SLOG(LOG_WARN, get_tag(), "[Server ERROR] fail to ttsd_player_pause() : uid (%d)", current_uid);
- }
+ /* pause player */
+ if (0 != ttsd_player_pause(current_uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
+ }
- /* change state */
- ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
+ /* change state */
+ ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
- int* temp_uid = (int*)malloc(sizeof(int));
- *temp_uid = current_uid;
- ecore_timer_add(0, __send_interrupt_client, temp_uid);
+ intptr_t pcurrent_uid = (intptr_t)current_uid;
+ ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+ }
}
-
+
/* Change current play */
if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
return TTSD_ERROR_OPERATION_FAILED;
}
if (APP_STATE_PAUSED == state) {
- SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid);
-
- ttsd_player_state_e state;
- if (0 != ttsd_player_get_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get player state : uid(%d)", uid);
- return TTSD_ERROR_OPERATION_FAILED;
- }
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
- if (TTSD_PLAYER_STATE_PAUSED == state) {
- /* Resume player */
- if (0 != ttsd_player_resume(uid)) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()");
- }
- } else if (TTSD_PLAYER_STATE_NULL == state) {
- if (0 != ttsd_player_play(uid)) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() ");
-
- /* Need to wait synthesis */
- if (NULL == g_wait_timer)
- g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
- } else {
- /* success playing */
- SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
- }
- } else {
- /* error */
+ /* Resume player */
+ if (0 != ttsd_player_resume(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
}
}
/* Check whether tts-engine is running or not */
if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
} else {
- __synthesis(uid);
+ __synthesis(uid, credential);
}
return TTSD_ERROR_NONE;
}
-
int ttsd_server_stop(int uid)
{
- app_state_e state;
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
- /* Reset all data */
- ttsd_data_clear_data(uid);
+ SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
- ttsd_data_set_client_state(uid, APP_STATE_READY);
-
- if (0 != ttsd_player_stop(uid))
- SLOG(LOG_WARN, get_tag(), "[Server] Fail to ttsd_player_stop()");
-
- if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
- SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running ");
+ if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control() && uid == ttsd_data_get_current_playing()) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
int ret = 0;
ret = ttsd_engine_cancel_synthesis();
if (0 != ret)
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
- }
-
- if (NULL != g_wait_timer) {
- SLOG(LOG_DEBUG, get_tag(), "Wait timer is deleted");
- ecore_timer_del(g_wait_timer);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
}
__server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
- } else {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is 'ready' ");
+
+ if (0 != ttsd_player_clear(uid))
+ SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
+
+ ttsd_data_set_client_state(uid, APP_STATE_READY);
}
+ /* Reset all data */
+ ttsd_data_clear_data(uid);
+
return TTSD_ERROR_NONE;
}
int ttsd_server_pause(int uid, int* utt_id)
{
- app_state_e state;
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
if (APP_STATE_PLAYING != state) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is not 'play' ");
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state is not 'play'");
return TTSD_ERROR_INVALID_STATE;
}
+ *utt_id = g_utt.uttid;
+ SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
+
int ret = 0;
ret = ttsd_player_pause(uid);
if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail player_pause() : ret(%d)", ret);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
return TTSD_ERROR_OPERATION_FAILED;
}
int ttsd_server_get_support_voices(int uid, GList** voice_list)
{
- app_state_e state;
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
/* get voice list*/
- if (0 != ttsd_engine_get_voice_list(voice_list)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() ");
- return TTSD_ERROR_OPERATION_FAILED;
+ int ret = ttsd_engine_get_voice_list(voice_list);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
+ return ret;
}
- SLOG(LOG_DEBUG, get_tag(), "[Server SUCCESS] Get supported voices ");
+ SLOG(LOG_DEBUG, tts_tag(), "[Server SUCCESS] Get supported voices");
return TTSD_ERROR_NONE;
}
int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
{
- app_state_e state;
+ app_tts_state_e state;
if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
- }
+ }
/* get current voice */
- int ret = ttsd_engine_get_default_voice(language, (ttsp_voice_type_e*)voice_type);
+ int ret = ttsd_engine_get_default_voice(language, voice_type);
if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail ttsd_server_get_support_voices() ");
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() : ret(%d)", ret);
return ret;
}
- SLOG(LOG_DEBUG, get_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
return TTSD_ERROR_NONE;
}
-#if 0
-/*
-* Server API for Internal event
-*/
-int ttsd_server_start_next_synthesis()
+int ttsd_server_set_private_data(int uid, const char* key, const char* data)
{
- /* get current play */
- int uid = ttsd_data_is_current_playing();
-
- if (uid < 0) {
- return 0;
- }
-
- return __server_next_synthesis(uid);
-}
-#endif
-
-/*
-* TTS Server Functions for Setting *
-*/
-
-int ttsd_server_setting_initialize(int uid)
-{
- if (false == g_is_engine) {
- if (0 != ttsd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_WARN, get_tag(), "[Server Setting WARNING] No Engine !!! " );
- g_is_engine = false;
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- } else {
- g_is_engine = true;
- }
- }
-
- if (-1 != ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] pid has already been registered ");
+ app_tts_state_e state;
+ if (0 > ttsd_data_get_client_state(uid, &state)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
- if (0 == ttsd_data_get_client_count()) {
- if( 0 != ttsd_engine_agent_load_current_engine() ) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to load current engine ");
- return TTSD_ERROR_OPERATION_FAILED;
- }
+ if (APP_STATE_READY != state) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
+ return TTSD_ERROR_INVALID_STATE;
}
- /* register pid */
- if (0 != ttsd_setting_data_add(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to add client info ");
- return TTSD_ERROR_OPERATION_FAILED;
+ int ret = ttsd_engine_set_private_data(key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
}
- return TTSD_ERROR_NONE;
+ return ret;
}
-int ttsd_server_setting_finalize(int uid)
+int ttsd_server_get_private_data(int uid, const char* key, char** data)
{
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
+ app_tts_state_e state;
+ if (0 > ttsd_data_get_client_state(uid, &state)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
- ttsd_setting_data_delete(uid);
+ if (APP_STATE_READY != state) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
+ return TTSD_ERROR_INVALID_STATE;
+ }
- /* unload engine, if ref count of client is 0 */
- if (0 == ttsd_data_get_client_count()) {
- ecore_timer_add(0, __quit_ecore_loop, NULL);
+ int ret = ttsd_engine_get_private_data(key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
}
- return TTSD_ERROR_NONE;
+ return ret;
}
-int ttsd_server_setting_get_engine_list(int uid, GList** engine_list)
+int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback)
{
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
- }
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data set cb");
int ret = 0;
- ret = ttsd_engine_setting_get_engine_list(engine_list);
+ ret = ttsd_engine_agent_set_private_data_set_cb(callback);
if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get engine list : result(%d)", ret);
- return ret;
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
}
- return TTSD_ERROR_NONE;
+ return ret;
}
-int ttsd_server_setting_get_current_engine(int uid, char** engine_id)
+int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
{
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
- }
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data requested cb");
int ret = 0;
- ret = ttsd_engine_setting_get_engine(engine_id);
+ ret = ttsd_engine_agent_set_private_data_requested_cb(callback);
if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get current engine : result(%d) ", ret);
- return ret;
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
}
- return TTSD_ERROR_NONE;
+ return ret;
}
-int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
+int ttsd_server_play_pcm(int uid)
{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
+ app_tts_state_e state;
+ if (0 > ttsd_data_get_client_state(uid, &state)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
- if (true == ttsd_engine_agent_is_same_engine(engine_id)) {
- SLOG(LOG_DEBUG, get_tag(), "[Server Setting] new engine is the same as current engine ");
+ if (APP_STATE_PLAYING == state) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
return TTSD_ERROR_NONE;
}
- /* stop all player */
- ttsd_player_all_stop();
+ int current_uid = ttsd_data_get_current_playing();
+ SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
- /* send interrupt message to all clients */
- ttsd_data_foreach_clients(__get_client_cb, NULL);
+ if (uid != current_uid && -1 != current_uid) {
+ if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+ /* Send interrupt message */
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
- ttsd_engine_cancel_synthesis();
+ /* pause player */
+ if (0 != ttsd_server_stop(current_uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
+ }
+ if (0 != ttsd_player_stop(current_uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to player stop : uid (%d)", current_uid);
+ }
- /* set engine */
- int ret = 0;
- ret = ttsd_engine_setting_set_engine(engine_id);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
- return ret;
- }
+ intptr_t pcurrent_uid = (intptr_t)current_uid;
+ ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+ } else {
+ /* Default mode policy of interrupt is "Pause" */
- return TTSD_ERROR_NONE;
-}
+ /* Send interrupt message */
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
-int ttsd_server_setting_get_voice_list(int uid, char** engine_id, GList** voice_list)
-{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
+ /* pause player */
+ if (0 != ttsd_player_pause(current_uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
+ }
+
+ /* change state */
+ ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
+
+ intptr_t pcurrent_uid = (intptr_t)current_uid;
+ ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+ }
}
- /* get language list from engine */
- int ret = 0;
- ret = ttsd_engine_setting_get_voice_list(engine_id, voice_list);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get voice list : result(%d)", ret);
- return ret;
+ /* Change current play */
+ if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
+ return TTSD_ERROR_OPERATION_FAILED;
}
- return TTSD_ERROR_NONE;
-}
+ if (APP_STATE_PAUSED == state) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
-int ttsd_server_setting_get_default_voice(int uid, char** language, ttsp_voice_type_e* vctype)
-{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
- }
-
- int ret = 0;
- ret = ttsd_engine_setting_get_default_voice(language, vctype);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get default voice : result(%d) ", ret);
- return ret;
- }
+ /* Resume player */
+ if (0 != ttsd_player_resume(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
+ }
+ } else {
+ if (0 != ttsd_player_play_pcm(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
- return TTSD_ERROR_NONE;
-}
+ // Change ready state
+ ttsd_server_stop_pcm(uid);
-int ttsd_server_setting_set_default_voice(int uid, const char* language, int vctype)
-{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
+ int tmp_pid;
+ tmp_pid = ttsd_data_get_pid(uid);
+ ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+ }
}
- /* set current language */
- int ret = 0;
- ret = ttsd_engine_setting_set_default_voice((const char*)language, (const ttsp_voice_type_e)vctype);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set default voice : result(%d) ", ret);
- return ret;
- }
-
return TTSD_ERROR_NONE;
}
-int ttsd_server_setting_get_engine_setting(int uid, char** engine_id, GList** engine_setting_list)
+int ttsd_server_stop_pcm(int uid)
{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
+ app_tts_state_e state;
+ if (0 > ttsd_data_get_client_state(uid, &state)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
- int ret = 0;
- ret = ttsd_engine_setting_get_engine_setting_info(engine_id, engine_setting_list);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get engine setting info : result(%d)", ret);
- return ret;
+ SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
+
+ if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
+ ttsd_data_set_client_state(uid, APP_STATE_READY);
}
- return TTSD_ERROR_NONE;
-}
+ /* Reset all data */
+ ttsd_data_clear_data(uid);
-int ttsd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
-{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
- }
+ ttsd_player_stop(uid);
- int ret = 0;
- ret = ttsd_engine_setting_set_engine_setting(key, value);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set engine setting info : result(%d)", ret);
- return ret;
- }
return TTSD_ERROR_NONE;
}
-int ttsd_server_setting_get_default_speed(int uid, int* default_speed)
+int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
- }
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
- /* get current speed */
- int ret = 0;
- ret = ttsd_engine_setting_get_default_speed((ttsp_speed_e*)default_speed);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get default speed : result(%d)", ret);
- return ret;
- }
+ int uttid = -1;
- return TTSD_ERROR_NONE;
-}
+ /* Synthesis is success */
+ if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
+ if (TTSE_RESULT_EVENT_START == event) {
+ SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
+ uid, uttid, data, data_size, audio_type, rate);
+ } else if (TTSE_RESULT_EVENT_FINISH == event) {
+ SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
+ uid, uttid, data, data_size, audio_type, rate);
+ } else {
+ /*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
+ }
-int ttsd_server_setting_set_default_speed(int uid, int default_speed)
-{
- /* check if uid is valid */
- if (-1 == ttsd_setting_data_is_setting(uid)) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
+ if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
+ return TTSD_ERROR_INVALID_PARAMETER;
+ }
+
+ /* add wav data */
+ sound_data_s* temp_sound_data = NULL;
+ temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
+ if (NULL == temp_sound_data) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
+
+ temp_sound_data->data = NULL;
+ temp_sound_data->rate = 0;
+ temp_sound_data->data_size = 0;
+
+ if (0 < data_size) {
+ temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
+ if (NULL != temp_sound_data->data) {
+ memcpy(temp_sound_data->data, data, data_size);
+ temp_sound_data->data_size = data_size;
+ SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)",
+ uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
+ }
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
+ }
+
+ temp_sound_data->utt_id = uttid;
+ temp_sound_data->event = event;
+ temp_sound_data->audio_type = audio_type;
+ temp_sound_data->rate = rate;
+
+ if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
+ SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
+
+ if (NULL != temp_sound_data->data) {
+ free(temp_sound_data->data);
+ temp_sound_data->data = NULL;
+ }
+
+ free(temp_sound_data);
+ temp_sound_data = NULL;
+ }
+
+/* if (0 != ttsd_player_play(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
+
+ // Change ready state
+ ttsd_server_stop(uid);
+
+ int tmp_pid;
+ tmp_pid = ttsd_data_get_pid(uid);
+ ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+ }
+*/
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
}
- /* set default speed */
- int ret = 0;
- ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)default_speed);
- if (0 != ret) {
- SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set default speed : result(%d)", ret);
- return ret;
- }
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
return TTSD_ERROR_NONE;
}