Fix recorder crash 49/203449/4 accepted/tizen/unified/20190509.041013 submit/tizen/20190508.063609
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 15 Apr 2019 01:27:16 +0000 (10:27 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Thu, 2 May 2019 04:48:54 +0000 (13:48 +0900)
Change-Id: I18e17fb1f56bf6cd571222aed0300a247f128489
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
common/stt_config_mgr.c
server/sttd_recorder.c
server/sttd_server.c

index 6f3c474..be6c113 100644 (file)
@@ -394,6 +394,7 @@ int __stt_config_set_auto_language()
 
                if (NULL != before_lang) {
                        free(before_lang);
+                       before_lang = NULL;
                }
        } else {
                /* Candidate language is not valid */
@@ -410,6 +411,7 @@ int __stt_config_set_auto_language()
 
                if (0 != stt_parser_set_language(tmp_language)) {
                        free(tmp_language);
+                       tmp_language = NULL;
                        SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to save config");
                        return -1;
                }
index b861494..ccab86d 100644 (file)
 #include "sttd_main.h"
 
 
-#define FRAME_LENGTH 160
+#define FRAME_LENGTH 320
 #define BUFFER_LENGTH FRAME_LENGTH * 2
 
 static pthread_mutex_t sttd_audio_in_handle_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+static Ecore_Timer* g_audio_timer = NULL;
+
 typedef enum {
        STTD_RECORDER_STATE_NONE = -1,
        STTD_RECORDER_STATE_READY = 0,  /**< Recorder is ready to start */
@@ -389,7 +391,7 @@ int sttd_recorder_destroy()
        return 0;
 }
 
-static float get_volume_decibel(char* data, int size, stte_audio_type_e type)
+float get_volume_decibel(char* data, int size, stte_audio_type_e type)
 {
        #define MAX_AMPLITUDE_MEAN_16   32768
        #define MAX_AMPLITUDE_MEAN_08   128
@@ -461,7 +463,10 @@ Eina_Bool __read_audio_func(void *data)
                return EINA_FALSE;
        }
 
-       if (0 == g_buffer_count % 30) {
+       if (NULL == g_recorder)
+               SLOG(LOG_WARN, TAG_STTD, "[Recorder] g_recorder is NULL. It is already stopped and destroyed.");
+
+       if (0 == g_buffer_count % 30 && NULL != g_recorder) {
                float vol_db = get_volume_decibel(g_buffer, BUFFER_LENGTH, g_recorder->audio_type);
                if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
@@ -513,7 +518,16 @@ int sttd_recorder_start(int uid)
        }
 
        /* Add ecore timer to read audio data */
-       ecore_timer_add(0, __read_audio_func, NULL);
+       if (NULL != g_audio_timer) {
+               ecore_timer_del(g_audio_timer);
+               g_audio_timer = NULL;
+       }
+
+       g_audio_timer = ecore_timer_add(0, __read_audio_func, NULL);
+       if (NULL == g_audio_timer) {
+               SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail to create timer of read_audio");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
 #endif
 
        g_recorder_state = STTD_RECORDER_STATE_RECORDING;
@@ -574,6 +588,11 @@ int sttd_recorder_stop()
 
        int ret = -1;
 #ifndef TV_BT_MODE
+       if (NULL != g_audio_timer) {
+               ecore_timer_del(g_audio_timer);
+               g_audio_timer = NULL;
+       }
+
        ret = audio_in_unprepare(g_recorder->audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
index ccaf29d..06c8c25 100644 (file)
@@ -50,7 +50,9 @@ static GList *g_proc_list = NULL;
 /*
 * STT Server Callback Functions
 */
-void __stop_by_silence(void *data)
+static void __cancel_recognition_internal();
+
+Eina_Bool __stop_by_silence(void *data)
 {
        SLOG(LOG_INFO, TAG_STTD, "===== Stop by silence detection");
 
@@ -62,7 +64,8 @@ void __stop_by_silence(void *data)
        if (0 != uid) {
                ret = sttd_server_stop(uid);
                if (0 > ret) {
-                       return;
+                       __cancel_recognition_internal();
+                       return EINA_FALSE;
                }
 
                if (STTD_RESULT_STATE_DONE == ret) {
@@ -82,7 +85,7 @@ void __stop_by_silence(void *data)
        SLOG(LOG_INFO, TAG_STTD, "=====");
        SLOG(LOG_DEBUG, TAG_STTD, "  ");
 
-       return;
+       return EINA_FALSE;
 }
 
 static void __cancel_recognition_internal()
@@ -360,7 +363,9 @@ int __server_speech_status_callback(stte_speech_status_e status, void *user_para
                        sttdc_send_speech_status(uid, status);
                } else if (STTE_SPEECH_STATUS_END_POINT_DETECTED == status) {
                        SLOG(LOG_DEBUG, TAG_STTD, "End Speech detected");
-                       ecore_main_loop_thread_safe_call_async(__stop_by_silence, NULL);
+                       ecore_thread_main_loop_begin();
+                       ecore_timer_add(0, __stop_by_silence, NULL);
+                       ecore_thread_main_loop_end();
                }
        } else {
                SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current recognition uid is not valid ");