AudioFlinger: Create Thread callback
Test: atest AudioTrackTest AudioRecordTest
Test: Camera YouTube
Bug: 291012167
Bug: 291319167
Change-Id: I82024cc2bebe56282224efb4ffda1f5dcc513702
diff --git a/services/audioflinger/Effects.h b/services/audioflinger/Effects.h
index 365cd45..dfa199e 100644
--- a/services/audioflinger/Effects.h
+++ b/services/audioflinger/Effects.h
@@ -382,8 +382,7 @@
// it also provide it's own input buffer used by the track as accumulation buffer.
class EffectChain : public IAfEffectChain {
public:
- EffectChain(const wp<IAfThreadBase>& wThread, audio_session_t sessionId);
- ~EffectChain() override;
+ EffectChain(const sp<IAfThreadBase>& thread, audio_session_t sessionId);
void process_l() final;
@@ -516,16 +515,11 @@
// Note: ctors taking a weak pointer to their owner must not promote it
// during construction (but may keep a reference for later promotion).
EffectCallback(const wp<EffectChain>& owner,
- const wp<IAfThreadBase>& thread)
+ const sp<IAfThreadBase>& thread) // we take a sp<> but store a wp<>.
: mChain(owner)
- , mThread(thread)
- , mAudioFlinger(*AudioFlinger::gAudioFlinger) {
- const sp<IAfThreadBase> base = thread.promote();
- if (base != nullptr) {
- mThreadType = base->type();
- } else {
- mThreadType = IAfThreadBase::MIXER; // assure a consistent value.
- }
+ , mThread(thread) {
+ mThreadType = thread->type();
+ mAfThreadCallback = thread->afThreadCallback();
}
status_t createEffectHal(const effect_uuid_t *pEffectUuid,
@@ -566,7 +560,7 @@
wp<IAfEffectChain> chain() const final { return mChain; }
bool isAudioPolicyReady() const final {
- return mAudioFlinger.isAudioPolicyReady();
+ return mAfThreadCallback->isAudioPolicyReady();
}
wp<IAfThreadBase> thread() const { return mThread.load(); }
@@ -574,12 +568,13 @@
void setThread(const sp<IAfThreadBase>& thread) {
mThread = thread;
mThreadType = thread->type();
+ mAfThreadCallback = thread->afThreadCallback();
}
private:
const wp<IAfEffectChain> mChain;
mediautils::atomic_wp<IAfThreadBase> mThread;
- AudioFlinger &mAudioFlinger; // implementation detail: outer instance always exists.
+ sp<IAfThreadCallback> mAfThreadCallback;
IAfThreadBase::type_t mThreadType;
};