private:
void recorder_thread_func(void);
void streaming_speech_data_thread_func();
+ void streaming_previous_speech_data_thread_func();
void streaming_background_data_thread_func(long start_time);
vector<IAudioEventObserver*> mObservers;
thread mStreamingThread;
atomic_bool mStopStreamingThread{false};
+ thread mStreamingPreviousThread;
+ atomic_bool mStopStreamingPreviousThread{false};
static constexpr long mBackgroundRecordingDurationMilliseconds = 10 * 1000;
typedef struct {
long time;
}
}
+/* Need to consider adapting conventional producer-consumer model */
+void CAudioManager::streaming_previous_speech_data_thread_func()
+{
+ MWR_LOGD("[ENTER]");
+
+ unique_lock<mutex> lock(mMutex, defer_lock);
+
+ while (!(mStopStreamingThread.load())) {
+ int ret = -1;
+ int cnt = 0;
+
+ /* get feedback data */
+ size_t speech_data_size = 0;
+ lock.lock();
+ speech_data_size = mPreviousSpeechData.size();
+ lock.unlock();
+ /* waiting */
+ while (0 >= speech_data_size) {
+ /* empty queue */
+ MWR_LOGD("[DEBUG] No feedback data. Waiting mode : %d", ret);
+ this_thread::sleep_for(chrono::milliseconds(10));
+ lock.lock();
+ speech_data_size = mSpeechData.size();
+ lock.unlock();
+ if (0 < speech_data_size) {
+ MWR_LOGI("[INFO] Resume thread");
+ break;
+ }
+ cnt++;
+ }
+ MWR_LOGI("[INFO] Finish to wait for new feedback data come");
+
+ lock.lock();
+ for (int index = 0; index < speech_data_size; index++) {
+ wakeup_speech_data& speech_data = mPreviousSpeechData.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;
+ }
+ }
+ }
+ lock.unlock();
+ }
+}
+
void CAudioManager::streaming_background_data_thread_func(long start_time)
{
MWR_LOGD("[ENTER]");
void CAudioManager::start_streaming_previous_utterance_data()
{
+ if (mStreamingPreviousThread.joinable()) {
+ MWR_LOGE("ERROR : mStreamingPreviousThread is joinable, will not start a new thread");
+ return;
+ }
+ mStreamingPreviousThread = thread(&CAudioManager::streaming_previous_speech_data_thread_func, this);
}
void CAudioManager::stop_streaming_previous_utterance_data()
{
+ if (mStreamingPreviousThread.joinable()) {
+ MWR_LOGD("mStreamingPreviousThread is joinable, trying join()");
+ mStopStreamingPreviousThread.store(true);
+ mStreamingPreviousThread.join();
+ }
+ mStopStreamingThread.store(false);
}
void CAudioManager::start_streaming_follow_up_data()