From 0b9f19a6f4d30f36fbdc8473a8e64714b1da159e Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 14 Jan 2022 18:03:36 +0900 Subject: [PATCH] Make play type to identify the method to stop playing Change-Id: Ief42fe91d71fc74db33fd3bea79b1419a9be7a5b Signed-off-by: Suyeon Hwang --- server/ttsd_data.cpp | 27 ++++++++++++++++++++++ server/ttsd_data.h | 9 ++++++++ server/ttsd_dbus_server.c | 2 +- server/ttsd_server.c | 57 +++++++++++++++++------------------------------ server/ttsd_server.h | 2 -- server/ttsd_tidl.c | 2 +- 6 files changed, 58 insertions(+), 41 deletions(-) diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 119cb03..367f60a 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -33,6 +33,7 @@ typedef struct unsigned int uid; int utt_id_stopped; app_tts_state_e state; + tts_app_play_type_e type; ttsd_mode_e mode; ttse_result_event_e result_event; @@ -798,6 +799,32 @@ int ttsd_data_set_client_state(unsigned int uid, app_tts_state_e state) return TTSD_ERROR_NONE; } +tts_app_play_type_e ttsd_data_get_play_type(unsigned int uid) +{ + lock_guard lock(g_app_data_mutex); + app_data_s* app_data = __get_client_app_data(uid); + if (nullptr == app_data) { + SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid); + return TTS_APP_PLAY_TYPE_SYNTH; + } + + return app_data->type; +} + +int ttsd_data_set_play_type(unsigned int uid, tts_app_play_type_e type) +{ + lock_guard lock(g_app_data_mutex); + app_data_s* app_data = __get_client_app_data(uid); + if (nullptr == app_data) { + SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid); + return TTSD_ERROR_INVALID_PARAMETER; + } + + app_data->type = type; + + return TTSD_ERROR_NONE; +} + int ttsd_data_set_paused_data_existing(unsigned int uid, bool is_paused_data_existing) { lock_guard lock(g_app_data_mutex); diff --git a/server/ttsd_data.h b/server/ttsd_data.h index ce7de2e..feff8d7 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -33,6 +33,11 @@ typedef enum { } app_tts_state_e; typedef enum { + TTS_APP_PLAY_TYPE_SYNTH = 0, + TTS_APP_PLAY_TYPE_PCM = 1 +} tts_app_play_type_e; + +typedef enum { TTSD_SYNTHESIS_CONTROL_DOING = 0, TTSD_SYNTHESIS_CONTROL_DONE = 1, TTSD_SYNTHESIS_CONTROL_EXPIRED = 2 @@ -126,6 +131,10 @@ app_tts_state_e ttsd_data_get_client_state(unsigned int uid); int ttsd_data_set_client_state(unsigned int uid, app_tts_state_e state); +tts_app_play_type_e ttsd_data_get_play_type(unsigned int uid); + +int ttsd_data_set_play_type(unsigned int uid, tts_app_play_type_e type); + int ttsd_data_set_paused_data_existing(unsigned int uid, bool is_paused_data_existing); bool ttsd_data_is_paused_data_existing(unsigned int uid); diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index 51a0ed3..0b9fddf 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -788,7 +788,7 @@ int ttsd_dbus_server_stop_pcm(DBusConnection* conn, DBusMessage* msg) ret = TTSD_ERROR_OPERATION_FAILED; } else { SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts stop pcm : uid(%u)", uid); - ret = ttsd_server_stop_pcm(uid); + ret = ttsd_server_stop(uid); } DBusMessage* reply; diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 36f3165..9324431 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -53,8 +53,6 @@ static utterance_t g_utt; static GList *g_proc_list = NULL; -static bool g_is_paused; - static bool g_is_terminated = false; @@ -1017,7 +1015,6 @@ int ttsd_server_play(unsigned int uid, const char* credential) int ret = TTSD_ERROR_NONE; if (APP_STATE_PAUSED == state) { SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid); - g_is_paused = false; ret = ttsd_player_resume(uid); } else { SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid); @@ -1041,10 +1038,27 @@ int ttsd_server_play(unsigned int uid, const char* credential) } else { __synthesis(uid); } + ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_SYNTH); return TTSD_ERROR_NONE; } +static void __stop_engine_synthesis(unsigned int uid) +{ + ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); + + if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) { + SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running"); + + int ret = ttsd_engine_cancel_synthesis(); + if (TTSD_ERROR_NONE != ret) + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret); + } + + ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); +} + int ttsd_server_stop(unsigned int uid) { app_tts_state_e state = ttsd_data_get_client_state(uid); @@ -1056,16 +1070,9 @@ int ttsd_server_stop(unsigned int uid) SLOG(LOG_INFO, tts_tag(), "[Server] server stop, uid(%d), state(%d)", uid, state); if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) { - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); - SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); - if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) { - SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running"); - - int ret = ttsd_engine_cancel_synthesis(); - if (TTSD_ERROR_NONE != ret) - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret); + if (TTS_APP_PLAY_TYPE_SYNTH == ttsd_data_get_play_type(uid)) { + __stop_engine_synthesis(uid); } - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); /* stop player */ ttsd_data_set_client_state(uid, APP_STATE_READY); @@ -1076,7 +1083,6 @@ int ttsd_server_stop(unsigned int uid) /* Reset all data */ ttsd_data_clear_data(uid); - g_is_paused = false; return TTSD_ERROR_NONE; } @@ -1106,8 +1112,6 @@ int ttsd_server_pause(unsigned int uid) return TTSD_ERROR_OPERATION_FAILED; } - g_is_paused = true; - return TTSD_ERROR_NONE; } @@ -1270,7 +1274,6 @@ int ttsd_server_play_pcm(unsigned int uid) int ret = TTSD_ERROR_NONE; if (APP_STATE_PAUSED == state) { SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid); - g_is_paused = false; ret = ttsd_player_resume(uid); } else { SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid); @@ -1283,27 +1286,7 @@ int ttsd_server_play_pcm(unsigned int uid) return TTSD_ERROR_OPERATION_FAILED; } - return TTSD_ERROR_NONE; -} - -int ttsd_server_stop_pcm(unsigned int uid) -{ - app_tts_state_e state = ttsd_data_get_client_state(uid); - if (APP_STATE_NONE == 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); + ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_PCM); return TTSD_ERROR_NONE; } diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 726b085..dea4c04 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -75,8 +75,6 @@ int ttsd_server_get_private_data(unsigned int uid, const char* key, char** data) int ttsd_server_play_pcm(unsigned int uid); -int ttsd_server_stop_pcm(unsigned int uid); - int ttsd_server_add_pcm(unsigned int uid, int event, void* data, int data_size, int audio_type, int rate); #ifdef __cplusplus diff --git a/server/ttsd_tidl.c b/server/ttsd_tidl.c index 00f1ba0..281134e 100644 --- a/server/ttsd_tidl.c +++ b/server/ttsd_tidl.c @@ -390,7 +390,7 @@ static int __stop_pcm_cb(rpc_port_stub_tts_context_h context, int uid, void *use unsigned int u_uid = (unsigned int)uid; SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS STOP PCM (%u)", u_uid); - int ret = ttsd_server_stop_pcm(u_uid); + int ret = ttsd_server_stop(u_uid); if (TTSD_ERROR_NONE != ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] TTS STOP PCM (%u) fail (%d/%s) <<<<<", u_uid, ret, get_error_message(ret)); return ret; -- 2.7.4