From a8f73f0f3f89f15bf04f97cda5cafab4518d2896 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 2 Sep 2019 18:48:34 +0900 Subject: [PATCH] Remove waiting loop in previous utterance streaming Change-Id: I982caca0af983a3ee3326c325ae7f955fcdff387 --- .../src/wakeup_audio_manager.cpp | 62 +++++++------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/plugins/wakeup-manager/src/wakeup_audio_manager.cpp b/plugins/wakeup-manager/src/wakeup_audio_manager.cpp index cba9f16..327190e 100644 --- a/plugins/wakeup-manager/src/wakeup_audio_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_audio_manager.cpp @@ -84,50 +84,36 @@ void CAudioManager::streaming_previous_audio_data_thread_func() unique_lock lock(mMutex, defer_lock); - while (!(mStopStreamingThread.load())) { - int ret = -1; - int cnt = 0; - - /* get feedback data */ - size_t audio_data_size = 0; - lock.lock(); - audio_data_size = mPreviousAudioData.size(); - lock.unlock(); - /* waiting */ - while (0 >= audio_data_size) { - /* empty queue */ - MWR_LOGD("[DEBUG] No feedback data. Waiting mode : %d", ret); - this_thread::sleep_for(chrono::milliseconds(10)); - lock.lock(); - audio_data_size = mPreviousAudioData.size(); - lock.unlock(); - if (0 < audio_data_size) { - MWR_LOGI("[INFO] Resume thread"); - break; - } - cnt++; - } - MWR_LOGI("[INFO] Finish to wait for new feedback data come"); + int ret = -1; + int cnt = 0; - lock.lock(); - for (int index = 0; index < audio_data_size; index++) { - wakeup_speech_data& speech_data = mPreviousAudioData.at(index).data; - for (const auto& observer : mObservers) { - if (observer) { - if (!observer->on_streaming_audio_data( - speech_data.event, speech_data.buffer, speech_data.len)) { - LOGE("[Recorder WARNING] One of the observer returned false"); - } + /* get feedback data */ + size_t audio_data_size = 0; + lock.lock(); + audio_data_size = mPreviousAudioData.size(); + for (int index = 0; index < audio_data_size; index++) { + wakeup_speech_data& speech_data = mPreviousAudioData.at(index).data; + for (const auto& observer : mObservers) { + if (observer) { + if (!observer->on_streaming_audio_data( + speech_data.event, speech_data.buffer, speech_data.len)) { + LOGE("[Recorder WARNING] One of the observer returned false"); } + } - if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == speech_data.event) { - MWR_LOGI("[INFO] Finish to send previous speech data"); - return; - } + if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == speech_data.event) { + MWR_LOGI("[INFO] Finish to send previous speech data"); + return; } } - lock.unlock(); + + if (mStopStreamingThread.load()) { + MWR_LOGI("[INFO] Stop Streaming Requested, returning"); + return; + } } + lock.unlock(); + MWR_LOGD("[EXIT]"); } -- 2.34.1