Add EventFlag for effect HAL thread processing
Bug: 261129656
Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit
Change-Id: Ibe6052a8c2a182b33e6fe727b8606431dd2f5355
diff --git a/audio/aidl/default/include/effect-impl/EffectContext.h b/audio/aidl/default/include/effect-impl/EffectContext.h
index 8b4a7d2..22cdb6b 100644
--- a/audio/aidl/default/include/effect-impl/EffectContext.h
+++ b/audio/aidl/default/include/effect-impl/EffectContext.h
@@ -54,6 +54,7 @@
size_t inBufferSizeInFloat = input.frameCount * mInputFrameSize / sizeof(float);
size_t outBufferSizeInFloat = output.frameCount * mOutputFrameSize / sizeof(float);
+ // only status FMQ use the EventFlag
mStatusMQ = std::make_shared<StatusMQ>(statusDepth, true /*configureEventFlagWord*/);
mInputMQ = std::make_shared<DataMQ>(inBufferSizeInFloat);
mOutputMQ = std::make_shared<DataMQ>(outBufferSizeInFloat);
@@ -127,7 +128,7 @@
return RetCode::SUCCESS;
}
virtual Parameter::Common getCommon() {
- LOG(INFO) << __func__ << mCommon.toString();
+ LOG(DEBUG) << __func__ << mCommon.toString();
return mCommon;
}
diff --git a/audio/aidl/default/include/effect-impl/EffectThread.h b/audio/aidl/default/include/effect-impl/EffectThread.h
index f9c6a31..ae51ef7 100644
--- a/audio/aidl/default/include/effect-impl/EffectThread.h
+++ b/audio/aidl/default/include/effect-impl/EffectThread.h
@@ -16,10 +16,12 @@
#pragma once
#include <atomic>
+#include <memory>
#include <string>
#include <thread>
#include <android-base/thread_annotations.h>
+#include <fmq/EventFlag.h>
#include <system/thread_defs.h>
#include "effect-impl/EffectContext.h"
@@ -35,7 +37,7 @@
// called by effect implementation.
RetCode createThread(std::shared_ptr<EffectContext> context, const std::string& name,
- int priority = ANDROID_PRIORITY_URGENT_AUDIO, int sleepUs = kSleepTimeUs);
+ int priority = ANDROID_PRIORITY_URGENT_AUDIO);
RetCode destroyThread();
RetCode startThread();
RetCode stopThread();
@@ -73,17 +75,23 @@
private:
static constexpr int kMaxTaskNameLen = 15;
- static constexpr int kSleepTimeUs = 2000; // in micro-second
+
std::mutex mThreadMutex;
std::condition_variable mCv;
- bool mExit GUARDED_BY(mThreadMutex) = false;
bool mStop GUARDED_BY(mThreadMutex) = true;
+ bool mExit GUARDED_BY(mThreadMutex) = false;
std::shared_ptr<EffectContext> mThreadContext GUARDED_BY(mThreadMutex);
+
+ struct EventFlagDeleter {
+ void operator()(::android::hardware::EventFlag* flag) const {
+ if (flag) {
+ ::android::hardware::EventFlag::deleteEventFlag(&flag);
+ }
+ }
+ };
+ std::unique_ptr<::android::hardware::EventFlag, EventFlagDeleter> mEfGroup;
std::thread mThread;
int mPriority;
- int mSleepTimeUs = kSleepTimeUs; // sleep time in micro-second
std::string mName;
-
- RetCode handleStartStop(bool stop);
};
} // namespace aidl::android::hardware::audio::effect