+int ttsd_server_play_pcm(int 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 (APP_STATE_PLAYING == state) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
+ return TTSD_ERROR_NONE;
+ }
+
+ 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) {
+ 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, 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);
+ }
+ }
+
+ /* 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;
+ }
+
+ if (APP_STATE_PAUSED == state) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
+
+ /* 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);
+
+ // Change ready state
+ ttsd_server_stop_pcm(uid);
+
+ int tmp_pid;
+ tmp_pid = ttsd_data_get_pid(uid);
+ ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+ }
+ }
+
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_server_stop_pcm(int 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;
+ }
+
+ 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);
+ }
+
+ /* Reset all data */
+ ttsd_data_clear_data(uid);
+
+ ttsd_player_stop(uid);
+
+
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
+
+ int uttid = -1;
+
+ /* 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");*/
+ }
+
+ 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;