Remove waiting loop in previous utterance streaming
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 2 Sep 2019 09:48:34 +0000 (18:48 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 2 Sep 2019 09:57:47 +0000 (18:57 +0900)
Change-Id: I982caca0af983a3ee3326c325ae7f955fcdff387

plugins/wakeup-manager/src/wakeup_audio_manager.cpp

index cba9f16..327190e 100644 (file)
@@ -84,50 +84,36 @@ void CAudioManager::streaming_previous_audio_data_thread_func()
 
        unique_lock<mutex> 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]");
 }