From cef98d131910628d5c0f5df5b611618cae653a92 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 6 Jul 2023 16:55:31 +0900 Subject: [PATCH] Refactor unused and unreachable code - Contents: This patch fixes some unused and unrechable code. Through this patch, unvaluable code is removed and also test cases covers more code and logics. Change-Id: I7ce5698cccb39491b50738d8d6e5301ae11ad098 Signed-off-by: Suyeon Hwang --- client/stt.c | 279 +++++++++++++++------------------------------ server/sttd_engine_agent.c | 44 +++---- server/sttd_recorder.c | 5 + 3 files changed, 118 insertions(+), 210 deletions(-) diff --git a/client/stt.c b/client/stt.c index b2ed49f..5b74583 100644 --- a/client/stt.c +++ b/client/stt.c @@ -61,12 +61,6 @@ static sound_stream_ducking_h g_alarm_stream_ducking; #define STT_BG_VOLUME_RATIO_NEARFIELD 0.7 #define SND_MGR_DUCKING_DURATION 500 -const char* stt_tag() -{ - //LCOV_EXCL_START - return "sttc"; - //LCOV_EXCL_STOP -} static int __stt_get_feature_enabled() { @@ -78,32 +72,33 @@ static int __stt_get_feature_enabled() } else if (-1 == g_feature_enabled) { bool stt_supported = false; bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - //LCOV_EXCL_START - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - g_feature_enabled = 0; - return STT_ERROR_NOT_SUPPORTED; - //LCOV_EXCL_STOP - } - g_feature_enabled = 1; - } else { - //LCOV_EXCL_START - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); - return STT_ERROR_NOT_SUPPORTED; - //LCOV_EXCL_STOP - } - } else { + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); return STT_ERROR_NOT_SUPPORTED; //LCOV_EXCL_STOP } + + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); + return STT_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + if (false == stt_supported || false == mic_supported) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + g_feature_enabled = 0; + return STT_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + g_feature_enabled = 1; } - return 0; + return STT_ERROR_NONE; } static int __check_privilege_initialize() @@ -136,10 +131,8 @@ static bool __check_privilege(const char* uid, const char * privilege) pid_t pid = getpid(); char *session = cynara_session_from_pid(pid); int ret = cynara_check(p_cynara, smack_label, session, uid, privilege); - if (session) { - free(session); - session = NULL; - } + free(session); + session = NULL; if (ret != CYNARA_API_ACCESS_ALLOWED) { SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(Denied)", ret); @@ -209,9 +202,9 @@ static int __stt_check_privilege_for_applaunch() return STT_ERROR_NONE; } +//LCOV_EXCL_START static const char* __stt_get_error_code(stt_error_e err) { - //LCOV_EXCL_START switch (err) { case STT_ERROR_NONE: return "STT_ERROR_NONE"; case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY"; @@ -231,12 +224,10 @@ static const char* __stt_get_error_code(stt_error_e err) default: return "Invalid error code"; } - //LCOV_EXCL_STOP } static int __stt_convert_config_error_code(stt_config_error_e code) { - //LCOV_EXCL_START if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE; if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY; if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR; @@ -249,7 +240,6 @@ static int __stt_convert_config_error_code(stt_config_error_e code) if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED; return code; - //LCOV_EXCL_STOP } void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data) @@ -364,7 +354,6 @@ void __stt_config_engine_changed_cb(const char* engine_id, const char* setting, static const char* __stt_get_state_string(stt_state_e state) { - //LCOV_EXCL_START switch (state) { case STT_STATE_CREATED: return "STT_STATE_CREATED"; case STT_STATE_READY: return "STT_STATE_READY"; @@ -373,8 +362,8 @@ static const char* __stt_get_state_string(stt_state_e state) default: return "Invalid State"; } - //LCOV_EXCL_STOP } +//LCOV_EXCL_STOP static int __stt_check_handle(stt_h stt, stt_client_s** client) { @@ -425,17 +414,18 @@ int stt_create(stt_h* stt) } } - if (0 != stt_client_new(stt)) { + stt_h new_stt = NULL; + if (STT_ERROR_NONE != stt_client_new(&new_stt)) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!"); return STT_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_STOP } - stt_client_s* client = stt_client_get(*stt); + stt_client_s* client = stt_client_get(new_stt); if (NULL == client) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client"); //LCOV_EXCL_LINE - stt_client_destroy(*stt); + stt_client_destroy(new_stt); return STT_ERROR_OPERATION_FAILED; } @@ -443,7 +433,7 @@ int stt_create(stt_h* stt) ret = __stt_convert_config_error_code(ret); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE - stt_client_destroy(*stt); + stt_client_destroy(new_stt); return ret; } @@ -451,15 +441,13 @@ int stt_create(stt_h* stt) ret = __stt_convert_config_error_code(ret); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE - stt_client_destroy(*stt); + stt_client_destroy(new_stt); return ret; } + *stt = new_stt; SLOG(LOG_INFO, TAG_STTC, "[Success] uid(%u)", client->uid); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_NONE; } @@ -614,14 +602,14 @@ int __stt_set_buxtonkey(const char* engine_id) int ret = buxton_open(&bux_cli, NULL, NULL); if (0 != ret) { - SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client"); //LCOV_EXCL_LINE + SLOG(LOG_ERROR, TAG_STTC, "[DBUS-BUXTON2] Fail to open buxton client"); //LCOV_EXCL_LINE return STT_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_open: %d", ret); + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS-BUXTON2] buxton_open: %d", ret); bux_layer = buxton_create_layer("system"); if (NULL == bux_layer) { //LCOV_EXCL_START - SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL"); + SLOG(LOG_ERROR, TAG_STTC, "[DBUS-BUXTON2] buxton_create_layer FAIL"); buxton_close(bux_cli); bux_cli = NULL; return STT_ERROR_OPERATION_FAILED; @@ -630,7 +618,7 @@ int __stt_set_buxtonkey(const char* engine_id) bux_val = buxton_value_create_string(engine_id); if (NULL == bux_val) { //LCOV_EXCL_START - SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL"); + SLOG(LOG_ERROR, TAG_STTC, "[DBUS-BUXTON2] buxton_value_create_string FAIL"); buxton_free_layer(bux_layer); buxton_close(bux_cli); bux_layer = NULL; @@ -642,7 +630,7 @@ int __stt_set_buxtonkey(const char* engine_id) ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_CUSTOM, bux_val); if (0 != ret) { //LCOV_EXCL_START - SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync"); + SLOG(LOG_ERROR, TAG_STTC, "[DBUS-BUXTON2] Fail to set value sync"); buxton_value_free(bux_val); buxton_free_layer(bux_layer); buxton_close(bux_cli); @@ -653,7 +641,7 @@ int __stt_set_buxtonkey(const char* engine_id) return STT_ERROR_OPERATION_FAILED; //LCOV_EXCL_STOP } - SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM); + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM); buxton_value_free(bux_val); buxton_free_layer(bux_layer); @@ -687,13 +675,9 @@ int stt_set_engine(stt_h stt, const char* engine_id) RETVM_IF(NULL == engine_id, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); RETVM_IF(client->current_state != STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); - if (NULL != client->current_engine_id) { - free(client->current_engine_id); - client->current_engine_id = NULL; - } - SLOG(LOG_INFO, TAG_STTC, "===== engined_id(%s)", engine_id); + free(client->current_engine_id); client->current_engine_id = strdup(engine_id); /* Set vconfkey */ @@ -722,10 +706,7 @@ int stt_set_credential(stt_h stt, const char* credential) RETVM_IF(client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); - if (NULL != client->credential) { - free(client->credential); - client->credential = NULL; - } + free(client->credential); client->credential = strdup(credential); SLOG(LOG_INFO, TAG_STTC, "====="); @@ -734,6 +715,7 @@ int stt_set_credential(stt_h stt, const char* credential) return STT_ERROR_NONE; } +//LCOV_EXCL_START static bool __stt_is_necessary_to_retry_dbus_request(int count, int return_value) { bool ret = true; @@ -749,6 +731,7 @@ static bool __stt_is_necessary_to_retry_dbus_request(int count, int return_value } return ret; } +//LCOV_EXCL_STOP int stt_set_private_data(stt_h stt, const char* key, const char* data) { @@ -763,7 +746,7 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data) SLOG(LOG_INFO, TAG_STTC, "===== Set private data"); if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); return STT_ERROR_INVALID_PARAMETER; } @@ -786,8 +769,8 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data) SLOG(LOG_DEBUG, TAG_STTC, ""); return STT_ERROR_NONE; - } + int stt_get_private_data(stt_h stt, const char* key, char** data) { stt_client_s* client = NULL; @@ -826,7 +809,6 @@ int stt_get_private_data(stt_h stt, const char* key, char** data) return STT_ERROR_NONE; } -//LCOV_EXCL_START int stt_set_server_stt(stt_h stt, const char* key, char* user_data) { int ret = -1; @@ -840,46 +822,23 @@ int stt_set_server_stt(stt_h stt, const char* key, char* user_data) RETVM_IF(NULL == key || NULL == user_data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter"); - if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) { + if (STT_STATE_READY != client->current_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state); return STT_ERROR_INVALID_STATE; } - client->internal = true; - - char* private_key = NULL; - private_key = strdup(key); - if (NULL == private_key) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)"); - return STT_ERROR_OUT_OF_MEMORY; - } - - char* data = NULL; - data = strdup(user_data); - if (NULL == data) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)"); - free(private_key); - private_key = NULL; - return STT_ERROR_OUT_OF_MEMORY; - } - - ret = stt_set_private_data(stt, private_key, data); + ret = stt_set_private_data(stt, key, user_data); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, key); + return ret; } - free(data); - data = NULL; - free(private_key); - private_key = NULL; - SLOG(LOG_INFO, TAG_STTC, "======"); SLOG(LOG_DEBUG, TAG_STTC, " "); return ret; } -//LCOV_EXCL_STOP static Eina_Bool __stt_connect_daemon(void *data) { @@ -928,11 +887,10 @@ static Eina_Bool __stt_connect_daemon(void *data) if (STT_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE - client->reason = STT_ERROR_ENGINE_NOT_FOUND; - ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client); - - return EINA_FALSE; + client->reason = STT_ERROR_ENGINE_NOT_FOUND; //LCOV_EXCL_LINE + ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client); //LCOV_EXCL_LINE + return EINA_FALSE; //LCOV_EXCL_LINE } else if (STT_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect"); //LCOV_EXCL_LINE return EINA_TRUE; @@ -943,34 +901,6 @@ static Eina_Bool __stt_connect_daemon(void *data) SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need"); } -//LCOV_EXCL_START -#ifdef __UNUSED_CODES__ - if (NULL != client->current_engine_id) { - ret = -1; - int count = 0; - silence_supported = false; - credential_needed = false; - SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id); - - while (0 != ret) { - ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed); - if (0 != ret) { - if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret)); - return ret; - } - count++; - } else { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id); - - /* success to change engine */ - client->silence_supported = silence_supported; - SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need"); - } - } - } -#endif -//LCOV_EXCL_STOP SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] uid(%u)", client->uid); client->before_state = client->current_state; @@ -1134,10 +1064,8 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE } - if (NULL != current_engine_id) { - free(current_engine_id); - current_engine_id = NULL; - } + free(current_engine_id); + current_engine_id = NULL; client->supported_lang_cb = NULL; client->supported_lang_user_data = NULL; @@ -1191,7 +1119,7 @@ int stt_get_state(stt_h stt, stt_state_e* state) case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break; case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break; case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break; - default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break; + default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break; //LCOV_EXCL_LINE } return STT_ERROR_NONE; @@ -1209,13 +1137,13 @@ int stt_get_error_message(stt_h stt, char** err_msg) if (NULL != client->err_msg) { *err_msg = strdup(client->err_msg); - SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); //LCOV_EXCL_LINE + SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); } else { SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (NULL)"); //LCOV_EXCL_LINE } - SLOG(LOG_INFO, TAG_STTC, "====="); //LCOV_EXCL_LINE - SLOG(LOG_DEBUG, TAG_STTC, " "); //LCOV_EXCL_LINE + SLOG(LOG_INFO, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); return STT_ERROR_NONE; } @@ -1456,20 +1384,18 @@ int stt_start(stt_h stt, const char* language, const char* type) SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid); } - char* temp = NULL; + const char* temp = NULL; if (NULL == language) { - temp = strdup("default"); + temp = "default"; } else { - temp = strdup(language); + temp = language; } RETVM_IF(NULL == temp, STT_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory"); if (true == client->credential_needed && NULL == client->credential) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE - free(temp); - temp = NULL; - return STT_ERROR_PERMISSION_DENIED; + return STT_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE } client->internal_state = STT_INTERNAL_STATE_STARTING; @@ -1482,9 +1408,6 @@ int stt_start(stt_h stt, const char* language, const char* type) client->is_streaming = false; } - free(temp); - temp = NULL; - SLOG(LOG_INFO, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -1500,14 +1423,11 @@ int stt_stop(stt_h stt) SLOG(LOG_INFO, TAG_STTC, "===== STT STOP"); - if (STT_INTERNAL_STATE_STARTING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE - return STT_ERROR_IN_PROGRESS_TO_RECORDING; - } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE + if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_READY; } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_PROCESSING; } @@ -1554,7 +1474,7 @@ int stt_start_audio_streaming(stt_h stt, const char* language, const char* type) const char* language_param = NULL == language ? "default" : language; if (true == client->credential_needed && NULL == client->credential) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE - return STT_ERROR_PERMISSION_DENIED; + return STT_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE } client->internal_state = STT_INTERNAL_STATE_STARTING; @@ -1580,14 +1500,11 @@ int stt_send_audio_streaming(stt_h stt, const char* data, size_t data_size) SLOG(LOG_INFO, TAG_STTC, "===== STT SEND AUDIO STREAMING"); - if (STT_INTERNAL_STATE_STARTING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE - return STT_ERROR_IN_PROGRESS_TO_RECORDING; - } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE + if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_READY; } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_PROCESSING; } @@ -1616,14 +1533,11 @@ int stt_stop_audio_streaming(stt_h stt) SLOG(LOG_INFO, TAG_STTC, "===== STT STOP AUDIO STREAMING"); - if (STT_INTERNAL_STATE_STARTING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE - return STT_ERROR_IN_PROGRESS_TO_RECORDING; - } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE + if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_READY; } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_PROCESSING; } @@ -1660,14 +1574,11 @@ int stt_cancel(stt_h stt) return STT_ERROR_INVALID_STATE; } - if (STT_INTERNAL_STATE_STARTING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE - return STT_ERROR_IN_PROGRESS_TO_RECORDING; - } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE + if (STT_INTERNAL_STATE_STOPPING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_PROCESSING; } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); return STT_ERROR_IN_PROGRESS_TO_READY; } @@ -1686,23 +1597,20 @@ int stt_cancel(stt_h stt) return ret; } +//LCOV_EXCL_START int __stt_cb_set_volume(unsigned int uid, float volume) { stt_client_s* client = NULL; client = stt_client_get_by_uid(uid); if (NULL == client) { - //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); return STT_ERROR_INVALID_PARAMETER; - //LCOV_EXCL_STOP } if (STT_STATE_RECORDING != client->current_state) { - //LCOV_EXCL_START SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); return STT_ERROR_INVALID_STATE; - //LCOV_EXCL_STOP } g_volume_db = volume; @@ -1710,6 +1618,7 @@ int __stt_cb_set_volume(unsigned int uid, float volume) return 0; } +//LCOV_EXCL_STOP int stt_get_recording_volume(stt_h stt, float* volume) { @@ -1802,13 +1711,10 @@ static void __stt_notify_error(void *data) } else { SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); //LCOV_EXCL_LINE } - - return; } int __stt_cb_error(unsigned int uid, int reason, char* err_msg) { - //LCOV_EXCL_START if (-1 == uid) { GList* client_list = NULL; client_list = stt_client_get_client_list(); @@ -1825,10 +1731,10 @@ int __stt_cb_error(unsigned int uid, int reason, char* err_msg) data->reason = reason; data->internal_state = STT_INTERNAL_STATE_NONE; - if (NULL != data->err_msg) { - free(data->err_msg); - data->err_msg = NULL; - } + + free(data->err_msg); + data->err_msg = NULL; + if (NULL != err_msg) data->err_msg = strdup(err_msg); @@ -1853,8 +1759,8 @@ int __stt_cb_error(unsigned int uid, int reason, char* err_msg) iter = g_list_next(iter); } } - //LCOV_EXCL_STOP } else { + //LCOV_EXCL_START stt_client_s* client = stt_client_get_by_uid(uid); if (NULL == client) { SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE @@ -1863,10 +1769,10 @@ int __stt_cb_error(unsigned int uid, int reason, char* err_msg) client->reason = reason; client->internal_state = STT_INTERNAL_STATE_NONE; - if (NULL != client->err_msg) { - free(client->err_msg); - client->err_msg = NULL; - } + + free(client->err_msg); + client->err_msg = NULL; + if (NULL != err_msg) client->err_msg = strdup(err_msg); @@ -1886,6 +1792,7 @@ int __stt_cb_error(unsigned int uid, int reason, char* err_msg) SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare"); //LCOV_EXCL_LINE } } + //LCOV_EXCL_STOP } return 0; @@ -1984,6 +1891,7 @@ int __stt_cb_set_state(unsigned int uid, int state) return 0; } +//LCOV_EXCL_START static void __stt_notify_speech_status(void *data) { stt_client_s* client = (stt_client_s*)data; @@ -2017,6 +1925,7 @@ int __stt_cb_speech_status(unsigned int uid, int status) ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client); return 0; } +//LCOV_EXCL_STOP int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data) { @@ -2183,7 +2092,6 @@ int stt_unset_engine_changed_cb(stt_h stt) return 0; } -//LCOV_EXCL_START int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data) { stt_client_s* client = NULL; @@ -2217,6 +2125,7 @@ int stt_unset_speech_status_cb(stt_h stt) return 0; } +//LCOV_EXCL_START int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath) { stt_client_s* client = NULL; @@ -2318,6 +2227,7 @@ int stt_cancel_file(stt_h stt) return ret; } +//LCOV_EXCL_STOP void __sound_stream_ducking_state_changed_cb(sound_stream_ducking_h stream_ducking, bool is_ducked, void *user_data) { @@ -2452,6 +2362,11 @@ int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event) if (STT_ERROR_NONE != temp) return temp; + RETVM_IF((STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD > volume_event || STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD < volume_event), + STT_ERROR_INVALID_PARAMETER, + "[ERROR] Invalid volume event (%d)", + volume_event); + /* check state */ if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state); @@ -2550,11 +2465,7 @@ int stt_set_audio_type(stt_h stt, const char *audio_id) SLOG(LOG_INFO, TAG_STTC, "[INFO] Set audio type(%s)", audio_id); - if (NULL != client->audio_id) { - free(client->audio_id); - client->audio_id = NULL; - } - + free(client->audio_id); client->audio_id = strdup(audio_id); return STT_ERROR_NONE; @@ -2575,5 +2486,3 @@ int stt_get_audio_type(stt_h stt, char **audio_id) return STT_ERROR_NONE; } - -//LCOV_EXCL_STOP diff --git a/server/sttd_engine_agent.c b/server/sttd_engine_agent.c index 880a24b..c06eb8d 100644 --- a/server/sttd_engine_agent.c +++ b/server/sttd_engine_agent.c @@ -659,27 +659,6 @@ int sttd_engine_agent_recognize_start_engine(unsigned int uid, const char* lang, return ret; } -#ifdef AUDIO_CREATE_ON_START - /* Ready recorder */ - stte_audio_type_e atype; - int rate; - int channels; - - ret = stt_engine_get_audio_format(&atype, &rate, &channels); - if (0 != ret) { - SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio format : %s", g_engine_info->engine_name); - return ret; - } - - SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Create recorder"); - - ret = sttd_recorder_create(atype, channels, rate); - if (0 != ret) { - SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create format : %s", g_engine_info->engine_name); - return ret; - } -#endif - #if 0 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder(%d)", uid); @@ -700,18 +679,33 @@ int sttd_engine_agent_recognize_start_recorder(unsigned int uid, const char* app if (STTD_ERROR_NONE != tmp) return tmp; - SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Start recorder"); + stte_audio_type_e atype; + int rate; + int channels; - int ret; + int ret = stt_engine_get_audio_format(&atype, &rate, &channels); + if (STTE_ERROR_NONE != ret) { + SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio format : %s", g_engine_info->engine_name); + return ret; + } + + SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Create recorder"); + ret = sttd_recorder_create(atype, channels, rate); + if (STTD_ERROR_NONE != ret) { + SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create format : %s", g_engine_info->engine_name); + return ret; + } + + SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Start recorder"); ret = sttd_recorder_start(uid, appid); - if (0 != ret) { + if (STTD_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret); stt_engine_recognize_cancel(); sttd_recorder_stop(); return ret; } - return 0; + return STTD_ERROR_NONE; } int sttd_engine_agent_recognize_start_file(unsigned int uid, const char* filepath) diff --git a/server/sttd_recorder.c b/server/sttd_recorder.c index 36577e6..38e2981 100644 --- a/server/sttd_recorder.c +++ b/server/sttd_recorder.c @@ -838,6 +838,11 @@ static int stop_recording_with_audio_fw() int sttd_recorder_stop() { + if (STTD_RECORDER_STATE_NONE == g_recorder_state) { + SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Recorder is not created yet"); + return STTD_ERROR_NONE; + } + if (STTD_RECORDER_STATE_READY == g_recorder_state) return 0; -- 2.7.4