Add to stop recording from FFV
[platform/core/uifw/stt.git] / server / sttd_recorder.c
index 751ee73..4452096 100644 (file)
@@ -34,6 +34,7 @@
 #include "sttd_recorder.h"
 #include "sttd_main.h"
 #include "sttd_engine_agent.h"
+#include "sttd_client_data.h"
 
 #define STTE_AUDIO_ID_NONE             "STT_AUDIO_ID_NONE"             /**< None audio id */
 #ifdef TV_FFV_MODE
@@ -108,8 +109,20 @@ static void _bt_cb_hid_state_changed(int result, bool connected, const char *rem
 
 static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data)
 {
+       if (0 >= sttd_client_get_ref_count()) {
+               if (0 == g_buffer_count % 50) {
+                       SLOG(LOG_INFO, TAG_STTD, "[Recorder INFO] BT audio function callback is invoked, but no cliet");
+
+                       if (100000 == g_buffer_count) {
+                               g_buffer_count = 0;
+                       }
+               }
+               g_buffer_count++;
+               return;
+       }
+
        if (STTD_RECORDER_STATE_RECORDING != g_recorder_state) {
-               /* SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Exit audio reading normal func"); */
+               SLOG(LOG_INFO, TAG_STTD, "[Recorder] Exit audio reading normal func");
                return;
        }
 
@@ -155,6 +168,23 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void
 #ifdef TV_FFV_MODE
 static void _ffv_audio_function_cb(void* data, unsigned int length, void* user_data)
 {
+       if (STTD_RECORDER_STATE_RECORDING != g_recorder_state) {
+               SLOG(LOG_INFO, TAG_STTD, "[Recorder] Exit audio reading normal func");
+               return;
+       }
+
+       if (0 >= sttd_client_get_ref_count()) {
+               if (0 == g_buffer_count % 50) {
+                       SLOG(LOG_INFO, TAG_STTD, "[Recorder INFO] farfield audio function callback is invoked, but no cliet");
+
+                       if (100000 == g_buffer_count) {
+                               g_buffer_count = 0;
+                       }
+               }
+               g_buffer_count++;
+               return;
+       }
+
        if (false == g_is_set_audio_type) {
                sttd_engine_agent_set_audio_type(STTE_AUDIO_ID_FFV);
                g_is_set_audio_type = true;
@@ -701,6 +731,13 @@ int sttd_recorder_stop()
        }
 #endif
 
+#ifdef TV_FFV_MODE
+       ret = farfield_voice_set_recognition_state(FARFIELD_VOICE_RECOGNITION_STOP);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to stop FFV, ret(%d)", ret);
+       }
+#endif
+
        g_recorder_state = STTD_RECORDER_STATE_READY;
 
 #ifdef BUF_SAVE_MODE