From 5c8cf18b19de1a7a6850a81bdc1f25fc9db81f39 Mon Sep 17 00:00:00 2001 From: sooyeon Date: Tue, 9 Jul 2024 17:19:00 +0900 Subject: [PATCH] Make ttse_set_personal_tts_id_cb optional callback Change-Id: I6ac487d6d79aa8ab3b55a50c7df68402cbf67e9e Signed-off-by: sooyeon --- include/ttse.h | 23 ++++++++++++++++++++--- server/ttsd_engine_agent.c | 17 +++++++++++++++++ server/ttsd_engine_agent.h | 1 + server/ttsd_main.h | 2 +- server/ttsd_server.c | 10 ++++++++++ server/ttsd_server.h | 3 +++ server/ttse.c | 24 ++++++++++++++++++++++++ 7 files changed, 76 insertions(+), 4 deletions(-) diff --git a/include/ttse.h b/include/ttse.h index 1e5b0a48..df897fa0 100755 --- a/include/ttse.h +++ b/include/ttse.h @@ -210,7 +210,7 @@ typedef int (*ttse_set_pitch_cb)(int pitch); /** * @brief Called when the engine service user sets the personal tts id of TTS engine. * @since_tizen 9.0 -* @remarks This callback function is mandatory and must be registered using ttse_main(). +* @remarks This callback function is optional and is registered using ttse_set_personal_tts_id_set_cb(). * @param[in] ptts_id The personal tts id * @return @c 0 on success, * otherwise a negative error value @@ -219,7 +219,7 @@ typedef int (*ttse_set_pitch_cb)(int pitch); * @retval #TTSE_ERROR_INVALID_STATE Not initialized * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure */ -typedef int (*ttse_set_personal_tts_id)(const char* ptts_id); +typedef int (*ttse_set_personal_tts_id_cb)(const char* ptts_id); /** @@ -432,7 +432,6 @@ typedef struct { ttse_foreach_supported_voices_cb foreach_voices; /**< Called when the engine service user gets the whole supported voice list */ ttse_is_valid_voice_cb is_valid_voice; /**< Called when the engine service user checks whether the voice is valid or not in TTS engine */ ttse_set_pitch_cb set_pitch; /**< Called when the engine service user sets the default pitch of TTS engine */ - ttse_set_personal_tts_id set_personal_tts_id; /**< Called when the engine service user sets the personal tts of TTS engine */ ttse_load_voice_cb load_voice; /**< Called when the engine service user requests to load the corresponding voice type for the first time */ ttse_unload_voice_cb unload_voice; /**< Called when the engine service user requests to unload the corresponding voice type or to stop using voice */ @@ -703,6 +702,24 @@ int ttse_get_activated_mode(int* activated_mode); int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback); +/** +* @brief Sets a callback function to be called when a personal TTS id is set. +* @since_tizen 9.0 +* @remarks The ttse_set_personal_tts_id_cb() function is called when the activated TTS modes are changed. +* @param[in] callback ttse_activated_mode_changed event callback function +* @return @c 0 on success, +* otherwise a negative error value +* @retval #TTSE_ERROR_NONE Successful +* @retval #TTSE_ERROR_NOT_SUPPORTED TTS NOT supported +* @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #TTSE_ERROR_INVALID_STATE Not initialized +* @pre The ttse_main() function should be invoked before this function is called. +* @see ttse_activated_mode_changed_cb() +* @see ttse_get_activated_mode() +*/ +int ttse_set_personal_tts_id_set_cb(ttse_set_personal_tts_id_cb callback); + + #ifdef __cplusplus } #endif diff --git a/server/ttsd_engine_agent.c b/server/ttsd_engine_agent.c index 169c96df..92426e75 100644 --- a/server/ttsd_engine_agent.c +++ b/server/ttsd_engine_agent.c @@ -824,6 +824,11 @@ int ttsd_engine_agent_set_personal_tts_id(const char* ptts_id) return ret; } + if (NULL == g_engine_info->callbacks->set_personal_tts_id) { + SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Personal tts is not supported. Fail to set personal tts id."); + return TTSD_ERROR_NOT_SUPPORTED_FEATURE; + } + ret = g_engine_info->callbacks->set_personal_tts_id(ptts_id); if (0 != ret) { SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to set personal tts id : ptts_id(%s), result(%s)", @@ -1322,3 +1327,15 @@ int ttsd_engine_agent_set_activated_mode_changed_cb(ttse_activated_mode_changed_ return TTSD_ERROR_NONE; } + +int ttsd_engine_agent_set_personal_tts_id_set_cb(ttse_set_personal_tts_id_cb callback) +{ + if (false == __is_agent_initialized()) { + SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized"); + return TTSD_ERROR_INVALID_STATE; + } + + g_engine_info->callbacks->set_personal_tts_id = callback; + + return TTSD_ERROR_NONE; +} \ No newline at end of file diff --git a/server/ttsd_engine_agent.h b/server/ttsd_engine_agent.h index 1376a3e0..a84ccbfb 100644 --- a/server/ttsd_engine_agent.h +++ b/server/ttsd_engine_agent.h @@ -40,6 +40,7 @@ int ttsd_engine_agent_load_current_engine(); int ttsd_engine_agent_set_private_data_set_cb(ttse_private_data_set_cb callback); int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_cb callback); int ttsd_engine_agent_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback); +int ttsd_engine_agent_set_personal_tts_id_set_cb(ttse_set_personal_tts_id_cb callback); /** Unload current engine */ int ttsd_engine_agent_unload_current_engine(); diff --git a/server/ttsd_main.h b/server/ttsd_main.h index 7fa915ac..8d85c89d 100644 --- a/server/ttsd_main.h +++ b/server/ttsd_main.h @@ -100,7 +100,7 @@ typedef struct { ttse_foreach_supported_voices_cb foreach_voices; ttse_is_valid_voice_cb is_valid_voice; ttse_set_pitch_cb set_pitch; - ttse_set_personal_tts_id set_personal_tts_id; + ttse_set_personal_tts_id_cb set_personal_tts_id; ttse_load_voice_cb load_voice; ttse_unload_voice_cb unload_voice; diff --git a/server/ttsd_server.c b/server/ttsd_server.c index ea6c7462..ed7bfca7 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -1604,6 +1604,16 @@ int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback) return ret; } +int ttsd_set_personal_tts_id_set_cb(ttse_set_personal_tts_id_cb callback) +{ + int ret = ttsd_engine_agent_set_personal_tts_id_set_cb(callback); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set personal tts id set cb : ret(%d)", ret); + } + + return ret; +} + int ttsd_server_play_pcm(unsigned int uid) { app_tts_state_e state = ttsd_data_get_client_state(uid); diff --git a/server/ttsd_server.h b/server/ttsd_server.h index f04998c6..ea20c7b7 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -43,6 +43,9 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback); int ttsd_get_activated_mode(int* activated_mode); int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback); +int ttsd_set_personal_tts_id_set_cb(ttse_set_personal_tts_id_cb callback); + + /* * Server API for client */ diff --git a/server/ttse.c b/server/ttse.c index ba01bc00..67a159bd 100755 --- a/server/ttse.c +++ b/server/ttse.c @@ -352,3 +352,27 @@ int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback) return ret; } + +int ttse_set_personal_tts_id_set_cb(ttse_set_personal_tts_id_cb callback) +{ + if (false == is_feature_enabled()) { + return TTSE_ERROR_NOT_SUPPORTED; + } + + if (NULL == callback) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter"); + return TTSE_ERROR_INVALID_PARAMETER; + } + + if (false == g_is_started) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is not started."); + return TTSE_ERROR_INVALID_STATE; + } + + int ret = ttsd_set_personal_tts_id_set_cb(callback); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set personal tts id set cb. ret(%d/%s)", ret, get_error_message(ret)); + } + + return ret; +} -- 2.34.1