From a272e6ad0a63fda87d91ba2438a2bdf40afb8b29 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 18 Aug 2016 13:45:12 +0900 Subject: [PATCH] Apply audio stream policy and add null checker Change-Id: Id81b421df77fb57a24e6f8befea445acd12b4b1e Signed-off-by: Kwangyoun Kim --- client/tts.c | 2 +- common/tts_config_parser.c | 31 ++++++++++++++++++++++++++++--- common/tts_defs.h | 1 + server/ttsd_player.c | 8 ++++---- server/ttse.c | 10 ++++++++++ 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/client/tts.c b/client/tts.c index 4065997..21f9f89 100644 --- a/client/tts.c +++ b/client/tts.c @@ -958,7 +958,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add text : %s", __tts_get_error_code(ret)); usleep(10000); count++; - if (TTS_RETRY_COUNT == count) { + if (TTS_RETRY_MIN_COUNT == count) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request"); break; } diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c index d74de97..9de67eb 100644 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -61,6 +61,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info doc = xmlParseFile(path); if (doc == NULL) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file"); return -1; } @@ -68,12 +69,14 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info if (cur == NULL) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); xmlFreeDoc(doc); + doc = NULL; return -1; } if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'"); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -81,6 +84,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info if (cur == NULL) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -154,6 +158,9 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info xmlFree(attr); } else { SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE); + free(temp_voice); + temp_voice = NULL; + continue; } key = xmlNodeGetContent(voice_node); @@ -166,6 +173,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE); if (NULL != temp_voice) { free(temp_voice); + temp_voice = NULL; } } } @@ -178,6 +186,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info temp->pitch_support = true; } xmlFree(key); + key = NULL; } else { SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT); } @@ -186,6 +195,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info } xmlFreeDoc(doc); + doc = NULL; if (NULL == temp->name || NULL == temp->uuid) { /* Invalid engine */ @@ -282,6 +292,9 @@ int tts_parser_load_config(tts_config_s** config_info) xmlChar *key; bool is_default_open = false; + /* For Thread safety */ + xmlInitParser(); + if (0 != access(TTS_CONFIG, F_OK)) { doc = xmlParseFile(TTS_DEFAULT_CONFIG); if (doc == NULL) { @@ -311,12 +324,14 @@ int tts_parser_load_config(tts_config_s** config_info) if (cur == NULL) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); xmlFreeDoc(doc); + doc = NULL; return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -324,6 +339,7 @@ int tts_parser_load_config(tts_config_s** config_info) if (cur == NULL) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -453,7 +469,10 @@ int tts_parser_load_config(tts_config_s** config_info) int tts_parser_unload_config(tts_config_s* config_info) { - if (NULL != g_config_doc) xmlFreeDoc(g_config_doc); + if (NULL != g_config_doc) { + xmlFreeDoc(g_config_doc); + g_config_doc = NULL; + } if (NULL != config_info) { if (NULL != config_info->engine_id) free(config_info->engine_id); if (NULL != config_info->setting) free(config_info->setting); @@ -767,6 +786,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic if (cur_new == NULL || cur_old == NULL) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -774,6 +794,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -782,6 +803,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic if (cur_new == NULL || cur_old == NULL) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); xmlFreeDoc(doc); + doc = NULL; return -1; } @@ -934,8 +956,11 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic cur_new = cur_new->next; cur_old = cur_old->next; } - - xmlFreeDoc(g_config_doc); + + if (NULL != g_config_doc) { + xmlFreeDoc(g_config_doc); + g_config_doc = NULL; + } g_config_doc = doc; return 0; diff --git a/common/tts_defs.h b/common/tts_defs.h index c49a75a..7d7981f 100644 --- a/common/tts_defs.h +++ b/common/tts_defs.h @@ -87,6 +87,7 @@ extern "C" { #define TTS_BASE_LANGUAGE "en_US" #define TTS_RETRY_COUNT 5 +#define TTS_RETRY_MIN_COUNT 2 #define TTS_SPEED_MIN 1 #define TTS_SPEED_NORMAL 8 diff --git a/server/ttsd_player.c b/server/ttsd_player.c index 8a6dec4..6c21cbb 100644 --- a/server/ttsd_player.c +++ b/server/ttsd_player.c @@ -211,10 +211,10 @@ static void __set_policy_for_playing(int volume) if (SOUND_MANAGER_ERROR_NONE != ret) { SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus"); } - ret = audio_out_set_stream_info(g_audio_h, g_stream_info_h); - if (AUDIO_IO_ERROR_NONE != ret) { - SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info"); - } + } + ret = audio_out_set_stream_info(g_audio_h, g_stream_info_h); + if (AUDIO_IO_ERROR_NONE != ret) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info"); } return; diff --git a/server/ttse.c b/server/ttse.c index f18c724..358d38a 100755 --- a/server/ttse.c +++ b/server/ttse.c @@ -180,6 +180,11 @@ int ttse_send_error(ttse_error_e error, const char* msg) int ttse_set_private_data_set_cb(ttse_private_data_set_cb callback_func) { + if (NULL == callback_func) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter"); + return TTSE_ERROR_INVALID_PARAMETER; + } + int ret = ttsd_set_private_data_set_cb(callback_func); if (0 != ret) { @@ -191,6 +196,11 @@ int ttse_set_private_data_set_cb(ttse_private_data_set_cb callback_func) int ttse_set_private_data_requested_cb(ttse_private_data_requested_cb callback_func) { + if (NULL == callback_func) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter"); + return TTSE_ERROR_INVALID_PARAMETER; + } + int ret = ttsd_set_private_data_requested_cb(callback_func); if (0 != ret) { -- 2.7.4