X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=server%2Fsttd_recorder.c;h=445209633b87a7d7afdb07357e65ae6d5e4d3d7a;hb=f15bdb6227899d8a91d5ea3edb5c94da7bad31c5;hp=90639b2b31d070ef5502735354e4ed07f63b8945;hpb=cc0728043aa79ebabf5fd7b0c7572660515c4656;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/server/sttd_recorder.c b/server/sttd_recorder.c index 90639b2..4452096 100644 --- a/server/sttd_recorder.c +++ b/server/sttd_recorder.c @@ -33,7 +33,13 @@ #include "sttd_dbus.h" #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 +#define STTE_AUDIO_ID_FFV "STT_FARFIELD_VOICE_VD" +#endif #define FRAME_LENGTH 320 #define BUFFER_LENGTH FRAME_LENGTH * 2 @@ -70,6 +76,8 @@ static int g_buffer_count; static int g_stream_focus_id; +static bool g_is_set_audio_type = false; + #ifdef TV_FFV_MODE farfield_voice_h g_farfieldvoice_h = NULL; #endif @@ -101,12 +109,29 @@ 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; } if (NULL != g_audio_cb) { + if (false == g_is_set_audio_type) { + sttd_engine_agent_set_audio_type(STTE_AUDIO_ID_BLUETOOTH); + g_is_set_audio_type = true; + } + if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) { SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to read audio"); sttd_recorder_stop(); @@ -143,6 +168,28 @@ 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; + } + if (0 == g_buffer_count % 50) { SLOG(LOG_INFO, TAG_STTD, "[Recorder INFO] farfield audio function callback is invoked"); @@ -637,6 +684,9 @@ int sttd_recorder_stop() SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section"); pthread_mutex_lock(&sttd_audio_in_handle_mutex); + g_is_set_audio_type = false; + sttd_engine_agent_set_audio_type(STTE_AUDIO_ID_NONE); + /* Check engine id is valid */ if (NULL == g_recorder) { SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid"); @@ -681,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