X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=server%2Fsttd_server.c;h=ccaf29d445a30e2ccc7f5072ab56c1e1a4ac06ed;hb=e2ff8a26a52b77b52f1aea40cb64699565c76a99;hp=8b91e60b529397933fcdb9a2eab6d737aa38e9b7;hpb=e3e202d463f94aa58337a5e882f0772be9840bed;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/server/sttd_server.c b/server/sttd_server.c old mode 100755 new mode 100644 index 8b91e60..ccaf29d --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -24,6 +24,10 @@ #include "sttd_recorder.h" #include "sttd_server.h" + +#define CLIENT_CLEAN_UP_TIME 500 + + static pthread_mutex_t stte_result_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t stte_result_time_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -35,6 +39,7 @@ static double g_processing_timeout = 30; static double g_recording_timeout = 60; +static Ecore_Timer* g_check_client_timer = NULL; Ecore_Timer* g_recording_timer = NULL; Ecore_Timer* g_processing_timer = NULL; @@ -47,7 +52,7 @@ static GList *g_proc_list = NULL; */ void __stop_by_silence(void *data) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Stop by silence detection"); + SLOG(LOG_INFO, TAG_STTD, "===== Stop by silence detection"); int uid = 0; @@ -74,7 +79,7 @@ void __stop_by_silence(void *data) SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] uid is NOT valid"); } - SLOG(LOG_DEBUG, TAG_STTD, "====="); + SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); return; @@ -100,6 +105,7 @@ static void __cancel_recognition_internal() } if (0 != uid && (APP_STATE_PROCESSING == state || APP_STATE_RECORDING == state)) { + SLOG(LOG_INFO, TAG_STTD, "===== cancel by internal"); /* cancel engine recognition */ ret = sttd_server_cancel(uid); if (0 != ret) { @@ -112,7 +118,7 @@ static void __cancel_recognition_internal() static void __cancel_by_error(void *data) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Cancel by error"); + SLOG(LOG_INFO, TAG_STTD, "===== Cancel by error"); __cancel_recognition_internal(); @@ -159,7 +165,7 @@ int __server_audio_recorder_callback(const void* data, const unsigned int length void __server_audio_interrupt_callback() { - SLOG(LOG_DEBUG, TAG_STTD, "===== Cancel by sound interrupt"); + SLOG(LOG_INFO, TAG_STTD, "===== Cancel by sound interrupt"); __cancel_recognition_internal(); @@ -169,7 +175,7 @@ void __server_audio_interrupt_callback() void __cancel_by_no_record(void *data) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Cancel by no record"); + SLOG(LOG_INFO, TAG_STTD, "===== Cancel by no record"); __cancel_recognition_internal(); @@ -185,7 +191,7 @@ int __server_recognition_result_callback(stte_result_event_e event, const char* // critical section pthread_mutex_lock(&stte_result_mutex); - SLOG(LOG_DEBUG, TAG_STTD, "===== RESULT event[%d] type[%s] data[%p] data_count[%d]", event, type, data, data_count); + SLOG(LOG_INFO, TAG_STTD, "===== RESULT event[%d] type[%s] data[%p] data_count[%d]", event, type, data, data_count); /* check uid */ int uid = stt_client_get_current_recognition(); @@ -199,24 +205,29 @@ int __server_recognition_result_callback(stte_result_event_e event, const char* return STTD_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event); + SLOG(LOG_INFO, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event); /* send result to client */ if (STTE_RESULT_EVENT_FINAL_RESULT == event) { if (APP_STATE_PROCESSING != state) { SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is NOT 'Processing'."); } - SLOG(LOG_DEBUG, TAG_STTD, "[Server] the size of result from engine is '%d'", data_count); + SLOG(LOG_INFO, TAG_STTD, "[Server] the size of result from engine is '%d'", data_count); /* Delete timer for processing time out */ if (NULL != g_processing_timer) { + ecore_thread_main_loop_begin(); + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); ecore_timer_del(g_processing_timer); g_processing_timer = NULL; + ecore_thread_main_loop_end(); } sttd_config_time_save(); sttd_config_time_reset(); + sttd_recorder_clear(); + sttd_client_set_state(uid, APP_STATE_READY); stt_client_unset_current_recognition(); @@ -245,7 +256,7 @@ int __server_recognition_result_callback(stte_result_event_e event, const char* // stt_client_unset_current_recognition(); } else if (STTE_RESULT_EVENT_PARTIAL_RESULT == event) { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] The partial result from engine is event[%d] data_count[%d]", event, data_count); + SLOG(LOG_INFO, TAG_STTD, "[Server] The partial result from engine is event[%d] data_count[%d]", event, data_count); sttd_config_time_save(); sttd_config_time_reset(); @@ -264,8 +275,11 @@ int __server_recognition_result_callback(stte_result_event_e event, const char* /* Delete timer for processing time out */ if (NULL != g_processing_timer) { + ecore_thread_main_loop_begin(); + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); ecore_timer_del(g_processing_timer); g_processing_timer = NULL; + ecore_thread_main_loop_end(); } sttd_config_time_reset(); @@ -297,7 +311,7 @@ int __server_recognition_result_callback(stte_result_event_e event, const char* /* nothing */ } - SLOG(LOG_DEBUG, TAG_STTD, "====="); + SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); pthread_mutex_unlock(&stte_result_mutex); @@ -308,7 +322,7 @@ bool __server_result_time_callback(int index, stte_result_time_event_e event, co { pthread_mutex_lock(&stte_result_time_mutex); - SLOG(LOG_DEBUG, TAG_STTD, "[Server] index(%d) event(%d) text(%s) start(%ld) end(%ld)", + SECURE_SLOG(LOG_INFO, TAG_STTD, "[Server] index(%d) event(%d) text(%s) start(%ld) end(%ld)", index, event, text, start_time, end_time); int ret; @@ -326,7 +340,7 @@ bool __server_result_time_callback(int index, stte_result_time_event_e event, co int __server_speech_status_callback(stte_speech_status_e status, void *user_param) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Speech status detected Callback"); + SLOG(LOG_INFO, TAG_STTD, "===== Speech status detected Callback"); int uid = stt_client_get_current_recognition(); if (0 != uid) { @@ -336,8 +350,8 @@ int __server_speech_status_callback(stte_speech_status_e status, void *user_para return STTD_ERROR_OPERATION_FAILED; } - if (APP_STATE_RECORDING != state) { - SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording"); + if (APP_STATE_RECORDING != state && APP_STATE_PROCESSING != state) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording, state(%d), status(%d)", state, status); return STTD_ERROR_INVALID_STATE; } @@ -349,10 +363,10 @@ int __server_speech_status_callback(stte_speech_status_e status, void *user_para ecore_main_loop_thread_safe_call_async(__stop_by_silence, NULL); } } else { - SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current recogntion uid is not valid "); + SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current recognition uid is not valid "); } - SLOG(LOG_DEBUG, TAG_STTD, "====="); + SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); return STTD_ERROR_NONE; @@ -360,7 +374,7 @@ int __server_speech_status_callback(stte_speech_status_e status, void *user_para int __server_error_callback(stte_error_e error, const char* msg) { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] Error Callback is called"); + SLOG(LOG_INFO, TAG_STTD, "[Server] Error Callback is called"); ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL); return STTD_ERROR_NONE; @@ -372,9 +386,10 @@ void __sttd_server_engine_changed_cb(const char* engine_id, const char* language SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Engine id is NULL"); return; } else { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] New default engine : %s", engine_id); + SLOG(LOG_INFO, TAG_STTD, "[Server] New default engine : %s", engine_id); } +#if 0 /* need to change state of app to ready */ int uid; uid = stt_client_get_current_recognition(); @@ -402,6 +417,7 @@ void __sttd_server_engine_changed_cb(const char* engine_id, const char* language ret = sttd_engine_agent_set_silence_detection(support_silence); if (0 != ret) SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to Result(%d)", ret); +#endif return; } @@ -412,7 +428,7 @@ void __sttd_server_language_changed_cb(const char* language, void* user_data) SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL"); return; } else { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] Get language changed : %s", language); + SLOG(LOG_INFO, TAG_STTD, "[Server] Get language changed : %s", language); } int ret = sttd_engine_agent_set_default_language(language); @@ -424,7 +440,7 @@ void __sttd_server_language_changed_cb(const char* language, void* user_data) void __sttd_server_silence_changed_cb(bool value, void* user_data) { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] Get silence detection changed : %s", value ? "on" : "off"); + SLOG(LOG_INFO, TAG_STTD, "[Server] Get silence detection changed : %s", value ? "on" : "off"); int ret = 0; ret = sttd_engine_agent_set_silence_detection(value); @@ -475,7 +491,12 @@ int sttd_initialize(stte_request_callback_s *callback) return ret; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] initialize"); + g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, sttd_cleanup_client, NULL); + if (NULL == g_check_client_timer) { + SLOG(LOG_WARN, TAG_STTD, "[Main Warning] Fail to create timer of client check"); + } + + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] initialize"); return 0; } @@ -505,6 +526,15 @@ int sttd_finalize() sttd_engine_agent_release(); + if (NULL != g_check_client_timer) { + ecore_timer_del(g_check_client_timer); + g_check_client_timer = NULL; + + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete ecore timer handle"); + } + + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] finalize"); + return STTD_ERROR_NONE; } @@ -557,7 +587,7 @@ Eina_Bool sttd_cleanup_client(void *data) } if (NULL != client_list) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Clean up client "); + SLOG(LOG_INFO, TAG_STTD, "===== Clean up client "); __read_proc(); @@ -597,7 +627,7 @@ Eina_Bool sttd_cleanup_client(void *data) #endif } - SLOG(LOG_DEBUG, TAG_STTD, "====="); + SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); free(client_list); @@ -614,6 +644,8 @@ int sttd_server_initialize(int pid, int uid, bool* silence, bool* credential) { int ret = STTD_ERROR_NONE; + SLOG(LOG_INFO, TAG_STTD, "[Server] server initialize"); + /* check if uid is valid */ app_state_e state; if (0 == sttd_client_get_state(uid, &state)) { @@ -640,24 +672,29 @@ int sttd_server_initialize(int pid, int uid, bool* silence, bool* credential) return ret; } + SLOG(LOG_INFO, TAG_STTD, "[Server Success] server initialize"); + return STTD_ERROR_NONE; } static Eina_Bool __quit_ecore_loop(void *data) { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] Quit"); + SLOG(LOG_INFO, TAG_STTD, "[Server] Quit"); stt_network_finalize(); sttd_finalize(); + sttd_dbus_close_connection(); ecore_main_loop_quit(); - SLOG(LOG_DEBUG, TAG_STTD, ""); + SLOG(LOG_INFO, TAG_STTD, ""); return EINA_FALSE; } int sttd_server_finalize(int uid) { + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter Finalize"); + /* check if uid is valid */ app_state_e state; if (0 != sttd_client_get_state(uid, &state)) { @@ -676,11 +713,14 @@ int sttd_server_finalize(int uid) if (APP_STATE_PROCESSING == state) { if (NULL != g_processing_timer) { + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); ecore_timer_del(g_processing_timer); g_processing_timer = NULL; } } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] stt_cancel is invoked while state is (%d)", state); + if (0 != sttd_engine_agent_recognize_cancel(uid)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel recognition"); } @@ -699,6 +739,8 @@ int sttd_server_finalize(int uid) ecore_timer_add(0, __quit_ecore_loop, NULL); } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End Finalize"); + return STTD_ERROR_NONE; } @@ -717,6 +759,8 @@ int sttd_server_get_supported_engines(int uid, GSList** engine_list) return STTD_ERROR_INVALID_STATE; } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] get supported egnines"); + int ret; ret = sttd_engine_agent_get_engine_list(engine_list); if (0 != ret) { @@ -742,6 +786,8 @@ int sttd_server_set_current_engine(int uid, const char* engine_id, bool* silence return STTD_ERROR_INVALID_STATE; } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] set current egnines, uid(%d), engine_id(%s)", uid, engine_id); + int ret; ret = sttd_engine_agent_load_current_engine(NULL); if (0 != ret) { @@ -778,6 +824,8 @@ int sttd_server_get_current_engine(int uid, char** engine_id) return STTD_ERROR_INVALID_STATE; } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] get current egnines, uid(%d)", uid); + int ret; ret = sttd_engine_agent_get_current_engine(engine_id); if (0 != ret) { @@ -803,6 +851,8 @@ int sttd_server_check_app_agreed(int uid, const char* appid, bool* available) return STTD_ERROR_INVALID_STATE; } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] check app agreed"); + /* Ask engine available */ int ret; bool temp = false; @@ -832,6 +882,8 @@ int sttd_server_get_supported_languages(int uid, GSList** lang_list) return STTD_ERROR_INVALID_PARAMETER; } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] get supported languages"); + /* get language list from engine */ int ret = sttd_engine_agent_supported_langs(lang_list); if (0 != ret) { @@ -865,7 +917,7 @@ int sttd_server_get_current_langauage(int uid, char** current_lang) return ret; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get default language"); + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] Get default language, current_lang(%s)", *current_lang); return STTD_ERROR_NONE; } @@ -892,7 +944,7 @@ int sttd_server_set_private_data(int uid, const char* key, const char* data) return ret; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Set private data"); + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] Set private data"); return STTD_ERROR_NONE; } @@ -919,7 +971,7 @@ int sttd_server_get_private_data(int uid, const char* key, char** data) return ret; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get private data, key(%s), data(%s)", key, *data); + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] Get private data, key(%s), data(%s)", key, *data); return STTD_ERROR_NONE; } @@ -947,7 +999,7 @@ int sttd_server_is_recognition_type_supported(int uid, const char* type, int* su *support = (int)temp; - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] recognition type supporting is %s", *support ? "true" : "false"); + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] recognition type supporting is %s", *support ? "true" : "false"); return STTD_ERROR_NONE; } @@ -1025,9 +1077,12 @@ Eina_Bool __check_recording_state(void *data) Eina_Bool __stop_by_recording_timeout(void *data) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Stop by timeout"); + SLOG(LOG_INFO, TAG_STTD, "===== Stop by timeout"); - g_recording_timer = NULL; + if (NULL != g_recording_timer) { + ecore_timer_del(g_recording_timer); + g_recording_timer = NULL; + } int uid = 0; uid = stt_client_get_current_recognition(); @@ -1039,7 +1094,7 @@ Eina_Bool __stop_by_recording_timeout(void *data) } } - SLOG(LOG_DEBUG, TAG_STTD, "====="); + SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); return EINA_FALSE; @@ -1062,20 +1117,26 @@ void __sttd_server_recorder_start(void* data) return; } - /* Notify uid state change */ - sttdc_send_set_state(uid, APP_STATE_RECORDING); - - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition"); + app_state_e temp_app_state; + if (0 != sttd_client_get_state(uid, &temp_app_state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return; + } + if (APP_STATE_READY != temp_app_state && 0 != stt_client_get_current_recognition()) { + /* Notify uid state change */ + sttdc_send_set_state(uid, APP_STATE_RECORDING); + SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition"); + } } void __sttd_start_sound_completed_cb(int id, void *user_data) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Start sound completed"); + SLOG(LOG_INFO, TAG_STTD, "===== Start sound completed"); /* After wav play callback, recorder start */ ecore_main_loop_thread_safe_call_async(__sttd_server_recorder_start, user_data); - SLOG(LOG_DEBUG, TAG_STTD, "====="); + SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); return; } @@ -1125,6 +1186,17 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i } } + if (NULL != g_recording_timer) { + ecore_timer_del(g_recording_timer); + g_recording_timer = NULL; + } + + if (NULL != g_processing_timer) { + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); + ecore_timer_del(g_processing_timer); + g_processing_timer = NULL; + } + char* sound = NULL; ret = sttd_client_get_start_sound(uid, &sound); if (0 != ret) { @@ -1139,10 +1211,10 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i } /* engine start recognition */ - SLOG(LOG_DEBUG, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s)", + SLOG(LOG_INFO, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s)", uid, lang, recognition_type); if (NULL != sound) - SLOG(LOG_DEBUG, TAG_STTD, "[Server] start sound : %s", sound); + SLOG(LOG_INFO, TAG_STTD, "[Server] start sound : %s", sound); /* 1. Set audio session */ ret = sttd_recorder_set_audio_session(); @@ -1159,10 +1231,20 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i if (NULL != sound) { int id = 0; intptr_t puid = (intptr_t)uid; - ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_start_sound_completed_cb, (void*)puid, &id); - if (WAV_PLAYER_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav"); + sound_stream_info_h wav_stream_info_h; + if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &wav_stream_info_h)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to create stream info for playing wav"); is_sound_done = true; + } else { + ret = wav_player_start_new(sound, wav_stream_info_h, __sttd_start_sound_completed_cb, (void*)puid, &id); + if (WAV_PLAYER_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav"); + is_sound_done = true; + } + + if (0 != sound_manager_destroy_stream_information(wav_stream_info_h)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stream info for playing wav"); + } } free(sound); sound = NULL; @@ -1188,8 +1270,10 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i g_recording_log_count = 0; + app_state_e temp_app_state; + if (true == is_sound_done) { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] No sound play"); + SLOG(LOG_INFO, TAG_STTD, "[Server] No sound play"); ret = sttd_engine_agent_recognize_start_recorder(uid); if (0 != ret) { @@ -1197,33 +1281,50 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i sttd_recorder_unset_audio_session(); sttd_engine_agent_recognize_cancel(); - ecore_timer_del(g_recording_timer); + if (NULL != g_recording_timer) { + ecore_timer_del(g_recording_timer); + g_recording_timer = NULL; + } sttd_client_set_state(uid, APP_STATE_READY); SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recorder : result(%d)", ret); return ret; } - /* Notify uid state change */ - sttdc_send_set_state(uid, APP_STATE_RECORDING); + if (0 != sttd_client_get_state(uid, &temp_app_state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid"); + return STTD_ERROR_INVALID_PARAMETER; + } + if (APP_STATE_READY != temp_app_state && 0 != stt_client_get_current_recognition()) { + /* Notify uid state change */ + sttdc_send_set_state(uid, APP_STATE_RECORDING); + } - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition"); + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] Start recognition"); return STTD_RESULT_STATE_DONE; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server] Wait sound finish"); + SLOG(LOG_INFO, TAG_STTD, "[Server] Wait sound finish"); return STTD_RESULT_STATE_NOT_DONE; } Eina_Bool __time_out_for_processing(void *data) { - g_processing_timer = NULL; + if (NULL != g_processing_timer) { + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); + ecore_timer_del(g_processing_timer); + g_processing_timer = NULL; + } + + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter __time_out_for_processing"); /* current uid */ int uid = stt_client_get_current_recognition(); if (0 == uid) return EINA_FALSE; + SLOG(LOG_INFO, TAG_STTD, "[Server Info] stt cancel is invoked by timeout for processing"); + /* Cancel engine */ int ret = sttd_engine_agent_recognize_cancel(); if (0 != ret) { @@ -1245,6 +1346,8 @@ Eina_Bool __time_out_for_processing(void *data) stt_client_unset_current_recognition(); + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End __time_out_for_processing"); + return EINA_FALSE; } @@ -1277,7 +1380,7 @@ void __sttd_server_engine_stop(void* data) void __sttd_stop_sound_completed_cb(int id, void *user_data) { - SLOG(LOG_DEBUG, TAG_STTD, "===== Stop sound completed"); + SLOG(LOG_INFO, TAG_STTD, "===== Stop sound completed"); /* After wav play callback, engine stop */ ecore_main_loop_thread_safe_call_async(__sttd_server_engine_stop, user_data); @@ -1307,13 +1410,19 @@ int sttd_server_stop(int uid) g_recording_timer = NULL; } + if (NULL != g_processing_timer) { + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); + ecore_timer_del(g_processing_timer); + g_processing_timer = NULL; + } + char* sound = NULL; if (0 != sttd_client_get_stop_sound(uid, &sound)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get start beep sound"); return STTD_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_STTD, "[Server] stop sound path : %s", sound); + SLOG(LOG_INFO, TAG_STTD, "[Server] stop sound path : %s", sound); int ret; /* 1. Stop recorder */ @@ -1331,20 +1440,29 @@ int sttd_server_stop(int uid) if (NULL != sound) { int id = 0; intptr_t puid = (intptr_t)uid; - ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_stop_sound_completed_cb, (void*)puid, &id); - if (WAV_PLAYER_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav"); + sound_stream_info_h wav_stream_info_h; + if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &wav_stream_info_h)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to create stream info for playing wav"); } else { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] Play wav : %s", sound); - } + ret = wav_player_start_new(sound, wav_stream_info_h, __sttd_stop_sound_completed_cb, (void*)puid, &id); + if (WAV_PLAYER_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav"); + } else { + SLOG(LOG_DEBUG, TAG_STTD, "[Server] Play wav : %s", sound); + } + if (0 != sound_manager_destroy_stream_information(wav_stream_info_h)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stream info for playing wav"); + } + } free(sound); + SLOG(LOG_INFO, TAG_STTD, "[INFO] Add g_processing_timer"); g_processing_timer = ecore_timer_add(g_processing_timeout, __time_out_for_processing, NULL); return STTD_RESULT_STATE_NOT_DONE; } else { - SLOG(LOG_DEBUG, TAG_STTD, "[Server] No sound play"); + SLOG(LOG_INFO, TAG_STTD, "[Server] No sound play"); /* Unset audio session */ ret = sttd_recorder_unset_audio_session(); @@ -1367,8 +1485,9 @@ int sttd_server_stop(int uid) /* Notify uid state change */ sttdc_send_set_state(uid, APP_STATE_PROCESSING); - SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Stop recognition"); + SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] Stop recognition"); + SLOG(LOG_INFO, TAG_STTD, "[INFO] Add g_processing_timer"); g_processing_timer = ecore_timer_add(g_processing_timeout, __time_out_for_processing, NULL); return STTD_RESULT_STATE_DONE; @@ -1379,6 +1498,182 @@ int sttd_server_stop(int uid) int sttd_server_cancel(int uid) { + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter sttd_server_cancel"); + + /* check if uid is valid */ + app_state_e state; + if (0 != sttd_client_get_state(uid, &state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* check uid state */ + if (APP_STATE_READY == state) { + SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is ready"); + return STTD_ERROR_NONE; + } + + stt_client_unset_current_recognition(); + + if (NULL != g_recording_timer) { + ecore_timer_del(g_recording_timer); + g_recording_timer = NULL; + } + + if (NULL != g_processing_timer) { + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); + ecore_timer_del(g_processing_timer); + g_processing_timer = NULL; + } + + if (APP_STATE_RECORDING == state) { + /* Unset audio session */ + int ret = sttd_recorder_unset_audio_session(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret); + return ret; + } + } + + /* change uid state */ + sttd_client_set_state(uid, APP_STATE_READY); + + SLOG(LOG_INFO, TAG_STTD, "[Server Info] stt cancel is invoked by app's request"); + + /* cancel engine recognition */ + int ret = sttd_engine_agent_recognize_cancel(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret); + return ret; + } + + /* Notify uid state change */ + sttdc_send_set_state(uid, APP_STATE_READY); + + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End sttd_server_cancel"); + + return STTD_ERROR_NONE; +} + +int sttd_server_start_file(int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential, + const char* filepath, stte_audio_type_e audio_type, int sample_rate) +{ + if (NULL == lang || NULL == recognition_type || NULL == filepath) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* check if uid is valid */ + app_state_e state; + if (0 != sttd_client_get_state(uid, &state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* check uid state */ + if (APP_STATE_READY != state) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] sttd_server_start : current state is not ready"); + return STTD_ERROR_INVALID_STATE; + } + + int ret = 0; + if (false == stt_client_get_app_agreed(uid)) { + bool temp = false; + ret = sttd_engine_agent_check_app_agreed(appid, &temp); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret); + return ret; + } + + if (false == temp) { + SLOG(LOG_ERROR, TAG_STTD, "[Server] App(%s) NOT confirmed that engine is available", appid); + return STTD_ERROR_PERMISSION_DENIED; + } + + stt_client_set_app_agreed(uid); + } + + /* check if engine use network */ + if (true == sttd_engine_agent_need_network()) { + if (false == stt_network_is_connected()) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection."); + return STTD_ERROR_OUT_OF_NETWORK; + } + } + + if (0 != stt_client_set_current_recognition(uid)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT is busy because of recording or processing"); + return STTD_ERROR_RECORDER_BUSY; + } + + /* engine start recognition */ + SLOG(LOG_DEBUG, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s), appid(%s), file(%s), audio_type(%d), sample_rate(%d)", uid, lang, recognition_type, appid, filepath, audio_type, sample_rate); + + /* 1. Set audio session */ + ret = sttd_recorder_set_audio_session(); + if (0 != ret) { + stt_client_unset_current_recognition(); + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set session : %d", ret); + return ret; + } + + /* 2. Start engine to recognize */ + ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, appid, credential, NULL); + if (0 != ret) { + stt_client_unset_current_recognition(); + sttd_recorder_unset_audio_session(); + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start engine : result(%d)", ret); + return ret; + } + + sttd_client_set_state(uid, APP_STATE_RECORDING); + sttdc_send_set_state(uid, APP_STATE_RECORDING); + + /* 3. Start to send pcm from file to engine */ + ret = sttd_engine_agent_recognize_start_file(uid, filepath); + if (0 != ret) { + stt_client_unset_current_recognition(); + sttd_recorder_unset_audio_session(); + sttd_engine_agent_recognize_cancel(); + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start file : result(%d)", ret); + return ret; + } + + /* 4. Stop to send pcm from file */ + ret = sttd_engine_agent_recognize_stop_file(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop recorder : result(%d)", ret); + stt_client_unset_current_recognition(); + sttd_recorder_unset_audio_session(); + sttd_engine_agent_recognize_cancel(); + return ret; + } + + /* 5. change & notify uid state */ + sttd_client_set_state(uid, APP_STATE_PROCESSING); + sttdc_send_set_state(uid, APP_STATE_PROCESSING); + + /* 6. Unset audio session */ + ret = sttd_recorder_unset_audio_session(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret); + stt_client_unset_current_recognition(); + return ret; + } + + /* 7. Stop engine */ + ret = sttd_engine_agent_recognize_stop_engine(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop engine : result(%d)", ret); + stt_client_unset_current_recognition(); + return ret; + } + + return STTD_ERROR_NONE; +} + +int sttd_server_cancel_file(int uid) +{ /* check if uid is valid */ app_state_e state; if (0 != sttd_client_get_state(uid, &state)) { @@ -1400,6 +1695,7 @@ int sttd_server_cancel(int uid) } if (NULL != g_processing_timer) { + SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer"); ecore_timer_del(g_processing_timer); g_processing_timer = NULL; } @@ -1428,3 +1724,4 @@ int sttd_server_cancel(int uid) return STTD_ERROR_NONE; } +