AudioFlinger: Extract DeviceEffectManager class
Test: atest audiorecord_tests audiotrack_tests audiorouting_tests trackplayerbase_tests audiosystem_tests
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioTrackTest AudioRecordTest
Test: YouTube Camera
Bug: 288339104
Change-Id: Ica9b4df3dc148310d1dc03d0dab86db56c20475d
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 1672658..09edb29 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -131,6 +131,7 @@
// Classes that depend on IAf* interfaces but are not cross-dependent.
#include "PatchCommandThread.h"
+#include "DeviceEffectManager.h"
namespace android {
@@ -163,6 +164,8 @@
{
friend class sp<AudioFlinger>;
friend class Client; // removeClient_l();
+ friend class DeviceEffectManager;
+ friend class DeviceEffectManagerCallback;
friend class PatchPanel;
// TODO(b/291012167) replace the Thread friends with an interface.
friend class DirectOutputThread;
@@ -579,18 +582,12 @@
void requestLogMerge();
// TODO(b/288339104) replace these forward declaration classes with interfaces.
- class DeviceEffectManager;
- // TODO(b/288339104) these should be separate files
-public:
- class DeviceEffectManagerCallback;
private:
struct TeePatch;
public:
using TeePatches = std::vector<TeePatch>;
private:
-#include "DeviceEffectManager.h"
-
#include "MelReporter.h"
// Find io handle by session id.
diff --git a/services/audioflinger/DeviceEffectManager.cpp b/services/audioflinger/DeviceEffectManager.cpp
index 480d16d..0f645cd 100644
--- a/services/audioflinger/DeviceEffectManager.cpp
+++ b/services/audioflinger/DeviceEffectManager.cpp
@@ -16,7 +16,7 @@
*/
-#define LOG_TAG "AudioFlinger::DeviceEffectManager"
+#define LOG_TAG "DeviceEffectManager"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
@@ -34,7 +34,25 @@
using detail::AudioHalVersionInfo;
using media::IEffectClient;
-void AudioFlinger::DeviceEffectManager::onCreateAudioPatch(audio_patch_handle_t handle,
+DeviceEffectManager::DeviceEffectManager(AudioFlinger& audioFlinger)
+ : mAudioFlinger(audioFlinger),
+ mMyCallback(new DeviceEffectManagerCallback(*this)) {}
+
+void DeviceEffectManager::onFirstRef() {
+ mAudioFlinger.mPatchCommandThread->addListener(this);
+}
+
+status_t DeviceEffectManager::addEffectToHal(const struct audio_port_config* device,
+ const sp<EffectHalInterface>& effect) {
+ return mAudioFlinger.addEffectToHal(device, effect);
+};
+
+status_t DeviceEffectManager::removeEffectFromHal(const struct audio_port_config* device,
+ const sp<EffectHalInterface>& effect) {
+ return mAudioFlinger.removeEffectFromHal(device, effect);
+};
+
+void DeviceEffectManager::onCreateAudioPatch(audio_patch_handle_t handle,
const IAfPatchPanel::Patch& patch) {
ALOGV("%s handle %d mHalHandle %d device sink %08x",
__func__, handle, patch.mHalHandle,
@@ -49,7 +67,7 @@
}
}
-void AudioFlinger::DeviceEffectManager::onReleaseAudioPatch(audio_patch_handle_t handle) {
+void DeviceEffectManager::onReleaseAudioPatch(audio_patch_handle_t handle) {
ALOGV("%s", __func__);
Mutex::Autolock _l(mLock);
for (auto& effectProxies : mDeviceEffects) {
@@ -59,7 +77,7 @@
}
}
-void AudioFlinger::DeviceEffectManager::onUpdateAudioPatch(audio_patch_handle_t oldHandle,
+void DeviceEffectManager::onUpdateAudioPatch(audio_patch_handle_t oldHandle,
audio_patch_handle_t newHandle, const IAfPatchPanel::Patch& patch) {
ALOGV("%s oldhandle %d newHandle %d mHalHandle %d device sink %08x",
__func__, oldHandle, newHandle, patch.mHalHandle,
@@ -75,7 +93,7 @@
}
// DeviceEffectManager::createEffect_l() must be called with AudioFlinger::mLock held
-sp<IAfEffectHandle> AudioFlinger::DeviceEffectManager::createEffect_l(
+sp<IAfEffectHandle> DeviceEffectManager::createEffect_l(
effect_descriptor_t *descriptor,
const AudioDeviceTypeAddr& device,
const sp<Client>& client,
@@ -140,7 +158,7 @@
return handle;
}
-status_t AudioFlinger::DeviceEffectManager::checkEffectCompatibility(
+status_t DeviceEffectManager::checkEffectCompatibility(
const effect_descriptor_t *desc) {
const sp<EffectsFactoryHalInterface> effectsFactory =
audioflinger::EffectConfiguration::getEffectsFactoryHal();
@@ -166,7 +184,7 @@
return NO_ERROR;
}
-status_t AudioFlinger::DeviceEffectManager::createEffectHal(
+status_t DeviceEffectManager::createEffectHal(
const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t deviceId,
sp<EffectHalInterface> *effect) {
status_t status = NO_INIT;
@@ -179,10 +197,10 @@
return status;
}
-void AudioFlinger::DeviceEffectManager::dump(int fd)
+void DeviceEffectManager::dump(int fd)
NO_THREAD_SAFETY_ANALYSIS // conditional try lock
{
- const bool locked = dumpTryLock(mLock);
+ const bool locked = AudioFlinger::dumpTryLock(mLock);
if (!locked) {
String8 result("DeviceEffectManager may be deadlocked\n");
write(fd, result.string(), result.size());
@@ -205,7 +223,7 @@
}
}
-size_t AudioFlinger::DeviceEffectManager::removeEffect(const sp<IAfDeviceEffectProxy>& effect)
+size_t DeviceEffectManager::removeEffect(const sp<IAfDeviceEffectProxy>& effect)
{
Mutex::Autolock _l(mLock);
const auto& iter = mDeviceEffects.find(effect->device());
@@ -225,7 +243,7 @@
return mDeviceEffects.size();
}
-bool AudioFlinger::DeviceEffectManagerCallback::disconnectEffectHandle(
+bool DeviceEffectManagerCallback::disconnectEffectHandle(
IAfEffectHandle *handle, bool unpinIfLast) {
sp<IAfEffectBase> effectBase = handle->effect().promote();
if (effectBase == nullptr) {
@@ -247,4 +265,12 @@
return true;
}
+bool DeviceEffectManagerCallback::isAudioPolicyReady() const {
+ return mManager.audioFlinger().isAudioPolicyReady();
+}
+
+int DeviceEffectManagerCallback::newEffectId() const {
+ return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT);
+}
+
} // namespace android
diff --git a/services/audioflinger/DeviceEffectManager.h b/services/audioflinger/DeviceEffectManager.h
index 2c71195..54b88d0 100644
--- a/services/audioflinger/DeviceEffectManager.h
+++ b/services/audioflinger/DeviceEffectManager.h
@@ -15,20 +15,18 @@
** limitations under the License.
*/
-#ifndef INCLUDING_FROM_AUDIOFLINGER_H
- #error This header file should only be included from AudioFlinger.h
-#endif
+#pragma once
+
+namespace android {
+
+class DeviceEffectManagerCallback;
// DeviceEffectManager is concealed within AudioFlinger, their lifetimes are the same.
class DeviceEffectManager : public PatchCommandThread::PatchCommandListener {
public:
- explicit DeviceEffectManager(AudioFlinger& audioFlinger)
- : mAudioFlinger(audioFlinger),
- mMyCallback(new DeviceEffectManagerCallback(*this)) {}
+ explicit DeviceEffectManager(AudioFlinger& audioFlinger);
- void onFirstRef() override {
- mAudioFlinger.mPatchCommandThread->addListener(this);
- }
+ void onFirstRef() override;
sp<IAfEffectHandle> createEffect_l(effect_descriptor_t *descriptor,
const AudioDeviceTypeAddr& device,
@@ -45,13 +43,9 @@
int32_t sessionId, int32_t deviceId,
sp<EffectHalInterface> *effect);
status_t addEffectToHal(const struct audio_port_config *device,
- const sp<EffectHalInterface>& effect) {
- return mAudioFlinger.addEffectToHal(device, effect);
- };
+ const sp<EffectHalInterface>& effect);
status_t removeEffectFromHal(const struct audio_port_config *device,
- const sp<EffectHalInterface>& effect) {
- return mAudioFlinger.removeEffectFromHal(device, effect);
- };
+ const sp<EffectHalInterface>& effect);
AudioFlinger& audioFlinger() const { return mAudioFlinger; }
@@ -60,11 +54,11 @@
// PatchCommandThread::PatchCommandListener implementation
void onCreateAudioPatch(audio_patch_handle_t handle,
- const IAfPatchPanel::Patch& patch) override;
- void onReleaseAudioPatch(audio_patch_handle_t handle) override;
+ const IAfPatchPanel::Patch& patch) final;
+ void onReleaseAudioPatch(audio_patch_handle_t handle) final;
void onUpdateAudioPatch(audio_patch_handle_t oldHandle,
audio_patch_handle_t newHandle,
- const IAfPatchPanel::Patch& patch) override;
+ const IAfPatchPanel::Patch& patch) final;
private:
status_t checkEffectCompatibility(const effect_descriptor_t *desc);
@@ -75,7 +69,6 @@
std::map<AudioDeviceTypeAddr, std::vector<sp<IAfDeviceEffectProxy>>> mDeviceEffects;
};
-public: // TODO(b/288339104) extract inner class.
class DeviceEffectManagerCallback : public EffectCallbackInterface {
public:
explicit DeviceEffectManagerCallback(DeviceEffectManager& manager)
@@ -132,11 +125,9 @@
wp<IAfEffectChain> chain() const override { return nullptr; }
- bool isAudioPolicyReady() const override {
- return mManager.audioFlinger().isAudioPolicyReady();
- }
+ bool isAudioPolicyReady() const final;
- int newEffectId() { return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); }
+ int newEffectId() const;
status_t addEffectToHal(const struct audio_port_config *device,
const sp<EffectHalInterface>& effect) {
@@ -149,4 +140,5 @@
private:
DeviceEffectManager& mManager;
};
-private:
+
+} // namespace android
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index f2fb608..b5be5a7 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -3259,11 +3259,11 @@
/* static */
sp<IAfDeviceEffectProxy> IAfDeviceEffectProxy::create(
const AudioDeviceTypeAddr& device,
- const sp</* DeviceEffectManagerCallback */ RefBase>& callback, // TODO(b/288339104) type
+ const sp<DeviceEffectManagerCallback>& callback,
effect_descriptor_t *desc, int id, bool notifyFramesProcessed)
{
return sp<DeviceEffectProxy>::make(device,
- sp<AudioFlinger::DeviceEffectManagerCallback>::cast(callback),
+ callback,
desc, id, notifyFramesProcessed);
}
diff --git a/services/audioflinger/Effects.h b/services/audioflinger/Effects.h
index dcf8237..365cd45 100644
--- a/services/audioflinger/Effects.h
+++ b/services/audioflinger/Effects.h
@@ -646,7 +646,7 @@
class DeviceEffectProxy : public IAfDeviceEffectProxy, public EffectBase {
public:
DeviceEffectProxy(const AudioDeviceTypeAddr& device,
- const sp<AudioFlinger::DeviceEffectManagerCallback>& callback,
+ const sp<DeviceEffectManagerCallback>& callback,
effect_descriptor_t *desc, int id, bool notifyFramesProcessed)
: EffectBase(callback, desc, id, AUDIO_SESSION_DEVICE, false),
mDevice(device), mManagerCallback(callback),
@@ -692,7 +692,7 @@
// Note: ctors taking a weak pointer to their owner must not promote it
// during construction (but may keep a reference for later promotion).
ProxyCallback(const wp<DeviceEffectProxy>& owner,
- const sp<AudioFlinger::DeviceEffectManagerCallback>& callback)
+ const sp<DeviceEffectManagerCallback>& callback)
: mProxy(owner), mManagerCallback(callback) {}
status_t createEffectHal(const effect_uuid_t *pEffectUuid,
@@ -743,14 +743,14 @@
private:
const wp<DeviceEffectProxy> mProxy;
- const sp<AudioFlinger::DeviceEffectManagerCallback> mManagerCallback;
+ const sp<DeviceEffectManagerCallback> mManagerCallback;
};
status_t checkPort(const IAfPatchPanel::Patch& patch,
const struct audio_port_config *port, sp<IAfEffectHandle> *handle);
const AudioDeviceTypeAddr mDevice;
- const sp<AudioFlinger::DeviceEffectManagerCallback> mManagerCallback;
+ const sp<DeviceEffectManagerCallback> mManagerCallback;
const sp<ProxyCallback> mMyCallback;
mutable Mutex mProxyLock;
diff --git a/services/audioflinger/IAfEffect.h b/services/audioflinger/IAfEffect.h
index 654e415..395340e 100644
--- a/services/audioflinger/IAfEffect.h
+++ b/services/audioflinger/IAfEffect.h
@@ -18,6 +18,7 @@
namespace android {
+class DeviceEffectManagerCallback;
class IAfDeviceEffectProxy;
class IAfEffectBase;
class IAfEffectChain;
@@ -335,9 +336,8 @@
class IAfDeviceEffectProxy : public virtual IAfEffectBase {
public:
- // TODO(b/288339104) type
static sp<IAfDeviceEffectProxy> create(const AudioDeviceTypeAddr& device,
- const sp</* DeviceEffectManagerCallback */ RefBase>& callback,
+ const sp<DeviceEffectManagerCallback>& callback,
effect_descriptor_t *desc, int id, bool notifyFramesProcessed);
virtual status_t init(