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;
+static Ecore_Timer *g_check_client_timer = NULL;
+static Ecore_Timer *g_recording_timer = NULL;
+static Ecore_Timer *g_processing_timer = NULL;
static Ecore_Timer *g_stop_by_silence_timer = NULL;
static int g_recording_log_count = 0;
*/
static void __cancel_recognition_internal();
-Eina_Bool __stop_by_silence(void *data)
+static Eina_Bool __stop_by_silence(void *data)
{
SLOG(LOG_INFO, TAG_STTD, "===== Stop by silence detection");
return;
}
-int __server_audio_recorder_callback(const void* data, const unsigned int length)
+static int __server_audio_recorder_callback(const void* data, const unsigned int length)
{
int ret;
return 0;
}
-void __server_audio_interrupt_callback()
+static void __server_audio_interrupt_callback()
{
SLOG(LOG_INFO, TAG_STTD, "===== Cancel by sound interrupt");
SLOG(LOG_DEBUG, TAG_STTD, " ");
}
-void __cancel_by_no_record(void *data)
-{
- SLOG(LOG_INFO, TAG_STTD, "===== Cancel by no record");
-
- __cancel_recognition_internal();
-
- SLOG(LOG_DEBUG, TAG_STTD, "=====");
- SLOG(LOG_DEBUG, TAG_STTD, " ");
-
- return;
-}
-
-int __server_recognition_result_callback(stte_result_event_e event, const char* type,
+static int __server_recognition_result_callback(stte_result_event_e event, const char* type,
const char** data, int data_count, const char* msg, void *user_data)
{
// critical section
SLOG(LOG_INFO, TAG_STTD, "[Server] the size of result from engine is '%d'", data_count);
/* Delete timer for processing time out */
+ ecore_thread_main_loop_begin();
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();
}
+ ecore_thread_main_loop_end();
sttd_config_time_save();
sttd_config_time_reset();
}
}
- /* change state of uid */
-// sttd_client_set_state(uid, APP_STATE_READY);
-// stt_client_unset_current_recognition();
-
} else if (STTE_RESULT_EVENT_PARTIAL_RESULT == event) {
SLOG(LOG_INFO, TAG_STTD, "[Server] The partial result from engine is event[%d] data_count[%d]", event, data_count);
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] The event of recognition result is ERROR");
/* Delete timer for processing time out */
+ ecore_thread_main_loop_begin();
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();
}
+ ecore_thread_main_loop_end();
sttd_config_time_reset();
int ret = 0;
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info ");
}
}
-
- /* change state of uid */
-// sttd_client_set_state(uid, APP_STATE_READY);
-// stt_client_unset_current_recognition();
} else {
/* nothing */
}
return STTD_ERROR_NONE;
}
-bool __server_result_time_callback(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
+static bool __server_result_time_callback(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
{
pthread_mutex_lock(&stte_result_time_mutex);
return true;
}
-int __server_speech_status_callback(stte_speech_status_e status, void *user_param)
+static int __server_speech_status_callback(stte_speech_status_e status, void *user_param)
{
SLOG(LOG_INFO, TAG_STTD, "===== Speech status detected Callback");
return STTD_ERROR_NONE;
}
-int __server_error_callback(stte_error_e error, const char* msg)
+static int __server_error_callback(stte_error_e error, const char* msg)
{
SLOG(LOG_ERROR, TAG_STTD, "[Server] Error Callback is called, error(%d), err_msg(%s)", error, msg);
ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
return STTD_ERROR_NONE;
}
-void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data)
+static void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data)
{
if (NULL == engine_id) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Engine id is NULL");
SLOG(LOG_INFO, TAG_STTD, "[Server] New default engine : %s", engine_id);
}
-#if 0
- /* need to change state of app to ready */
- unsigned int uid;
- uid = stt_client_get_current_recognition();
-
- if (0 != uid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server] Set ready state of uid(%u)", uid);
-
- sttd_server_cancel(uid);
- sttdc_send_set_state(uid, (int)APP_STATE_READY);
-
- stt_client_unset_current_recognition();
- }
-
- /* set engine */
- int ret = sttd_engine_agent_set_default_engine(engine_id);
- if (0 != ret)
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine : result(%d)", ret);
-
- if (NULL != language) {
- ret = sttd_engine_agent_set_default_language(language);
- if (0 != ret)
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set default lang : result(%d)", ret);
- }
-
- 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;
}
-void __sttd_server_language_changed_cb(const char* language, void* user_data)
+static void __sttd_server_language_changed_cb(const char* language, void* user_data)
{
if (NULL == language) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL");
return;
}
-void __sttd_server_silence_changed_cb(bool value, void* user_data)
+static void __sttd_server_silence_changed_cb(bool value, void* user_data)
{
SLOG(LOG_INFO, TAG_STTD, "[Server] Get silence detection changed : %s", value ? "on" : "off");
SLOG(LOG_ERROR, TAG_STTD, "uid (%u) should be removed", client_list[i]);
sttd_server_finalize(client_list[i]);
}
-#if 0
- result = sttdc_send_hello(client_list[i]);
-
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid(%u) should be removed.", client_list[i]);
- sttd_server_finalize(client_list[i]);
- } else if (-1 == result) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Hello result has error");
- }
-#endif
}
SLOG(LOG_INFO, TAG_STTD, "=====");
return EINA_FALSE;
}
+static void delete_timers_related_to_recording_session()
+{
+ 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 (NULL != g_stop_by_silence_timer) {
+ ecore_timer_del(g_stop_by_silence_timer);
+ g_stop_by_silence_timer = NULL;
+ }
+}
+
int sttd_server_finalize(unsigned int uid)
{
SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter Finalize");
/* release recorder */
if (APP_STATE_RECORDING == state || APP_STATE_PROCESSING == state) {
- if (APP_STATE_RECORDING == state) {
- if (NULL != g_recording_timer) {
- ecore_timer_del(g_recording_timer);
- g_recording_timer = NULL;
- }
- }
-
- 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;
- }
- }
-
- if (NULL != g_stop_by_silence_timer) {
- ecore_timer_del(g_stop_by_silence_timer);
- g_stop_by_silence_timer = NULL;
- }
+ delete_timers_related_to_recording_session();
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");
}
/* unload engine, if ref count of client is 0 */
if (0 == sttd_client_get_ref_count()) {
-// sttd_dbus_close_connection();
ecore_timer_add(0, __quit_ecore_loop, NULL);
}
return 0;
}
-#if 0
-Eina_Bool __check_recording_state(void *data)
-{
- /* current uid */
- unsigned int uid = stt_client_get_current_recognition();
- if (0 == uid)
- return EINA_FALSE;
-
- app_state_e state;
- if (0 != sttdc_send_get_state(uid, (int*)&state)) {
- /* client is removed */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid(%u) should be removed.", uid);
- sttd_server_finalize(uid);
- return EINA_FALSE;
- }
-
- if (APP_STATE_READY == state) {
- /* Cancel stt */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%u) is 'Ready'. The STT service should cancel recording", uid);
- sttd_server_cancel(uid);
- } else if (APP_STATE_PROCESSING == state) {
- /* Cancel stt and send change state */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%u) is 'Processing'. The STT service should cancel recording", uid);
- sttd_server_cancel(uid);
- sttdc_send_set_state(uid, (int)APP_STATE_READY);
- } else {
- /* Normal state */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] The states of STT service and client are identical");
- return EINA_TRUE;
- }
-
- return EINA_FALSE;
-}
-#endif
-
-Eina_Bool __stop_by_recording_timeout(void *data)
+static Eina_Bool __stop_by_recording_timeout(void *data)
{
SLOG(LOG_INFO, TAG_STTD, "===== Stop by timeout");
-
- if (NULL != g_recording_timer) {
- ecore_timer_del(g_recording_timer);
- g_recording_timer = NULL;
- }
+ g_recording_timer = NULL;
unsigned int uid = stt_client_get_current_recognition();
if (STT_INVALID_UID != uid) {
return EINA_FALSE;
}
-void __sttd_server_recorder_start(void* data)
+static void __sttd_server_recorder_start(void* data)
{
uintptr_t puid = (uintptr_t)data;
unsigned int uid = (unsigned int)puid;
}
}
-void __sttd_start_sound_completed_cb(int id, void *user_data)
+static void __sttd_start_sound_completed_cb(int id, void *user_data)
{
SLOG(LOG_INFO, TAG_STTD, "===== Start sound completed");
return STTD_ERROR_RECORDER_BUSY;
}
- 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 (NULL != g_stop_by_silence_timer) {
- ecore_timer_del(g_stop_by_silence_timer);
- g_stop_by_silence_timer = NULL;
- }
+ delete_timers_related_to_recording_session();
char* sound = NULL;
ret = sttd_client_get_start_sound(uid, &sound);
}
if (0 != strcmp(STTE_RECOGNITION_TYPE_FREE_PARTIAL, recognition_type)) {
- g_recording_timer = ecore_timer_add(g_recording_timeout, __stop_by_recording_timeout, NULL);
+ if (NULL == g_processing_timer) {
+ g_recording_timer = ecore_timer_add(g_recording_timeout, __stop_by_recording_timeout, NULL);
+ }
}
/* change uid state */
return STTD_ERROR_NONE;
}
-Eina_Bool __time_out_for_processing(void *data)
+static Eina_Bool __time_out_for_processing(void *data)
{
- 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;
- }
-
+ g_processing_timer = NULL;
SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter __time_out_for_processing");
/* current uid */
return EINA_FALSE;
}
-void __sttd_server_engine_stop(void* data)
+static void __sttd_server_engine_stop(void* data)
{
uintptr_t puid = (uintptr_t)data;
unsigned int uid = (unsigned int)puid;
SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Stop recognition");
}
-void __sttd_stop_sound_completed_cb(int id, void *user_data)
+static void __sttd_stop_sound_completed_cb(int id, void *user_data)
{
SLOG(LOG_INFO, TAG_STTD, "===== Stop sound completed");
return STTD_ERROR_INVALID_STATE;
}
- 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 (NULL != g_stop_by_silence_timer) {
- ecore_timer_del(g_stop_by_silence_timer);
- g_stop_by_silence_timer = NULL;
- }
+ delete_timers_related_to_recording_session();
char* sound = NULL;
if (0 != sttd_client_get_stop_sound(uid, &sound)) {
}
}
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);
} else {
SLOG(LOG_INFO, TAG_STTD, "[Server] No sound play");
sttdc_send_set_state(uid, APP_STATE_PROCESSING);
SLOG(LOG_INFO, TAG_STTD, "[Server SUCCESS] Stop recognition");
+ }
- SLOG(LOG_INFO, TAG_STTD, "[INFO] Add g_processing_timer");
+ SLOG(LOG_INFO, TAG_STTD, "[INFO] Add g_processing_timer");
+ if (NULL == g_processing_timer) {
g_processing_timer = ecore_timer_add(g_processing_timeout, __time_out_for_processing, NULL);
}
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 (NULL != g_stop_by_silence_timer) {
- ecore_timer_del(g_stop_by_silence_timer);
- g_stop_by_silence_timer = NULL;
- }
+ delete_timers_related_to_recording_session();
if (APP_STATE_RECORDING == state) {
/* Unset audio session */