AudioFlinger: Add more Thread interfaces
Add interfaces
IAfDirectOutputThread
IAfDuplicatingThread
IAfRecordThread
Test: atest audiorecord_tests audiotrack_tests audiorouting_tests trackplayerbase_tests audiosystem_tests
Test: atest AudioTrackTest AudioRecordTest
Test: YouTube Camera
Bug: 288339104
Bug: 289233517
Change-Id: Ibd46b7de4c4264294b645d0df2a69825513a1426
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index 2a33991..c9cfd14 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -2118,21 +2118,21 @@
/* static */
sp<IAfEffectChain> IAfEffectChain::create(
- const wp<Thread /*ThreadBase*/>& wThread, // TODO(b/288339104) update type
+ const wp<IAfThreadBase>& wThread,
audio_session_t sessionId)
{
// TODO(b/288339104) no weak pointer cast.
- return sp<EffectChain>::make(sp<AudioFlinger::ThreadBase>::cast(wThread.promote()), sessionId);
+ return sp<EffectChain>::make(wThread, sessionId);
}
-EffectChain::EffectChain(const wp<AudioFlinger::ThreadBase>& thread,
+EffectChain::EffectChain(const wp<IAfThreadBase>& thread,
audio_session_t sessionId)
: mSessionId(sessionId), mActiveTrackCnt(0), mTrackCnt(0), mTailBufferCount(0),
mVolumeCtrlIdx(-1), mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX),
mNewLeftVolume(UINT_MAX), mNewRightVolume(UINT_MAX),
mEffectCallback(new EffectCallback(wp<EffectChain>(this), thread))
{
- sp<AudioFlinger::ThreadBase> p = thread.promote();
+ const sp<IAfThreadBase> p = thread.promote();
if (p == nullptr) {
return;
}
@@ -2145,7 +2145,7 @@
{
}
-// getEffectFromDesc_l() must be called with AudioFlinger::ThreadBase::mLock held
+// getEffectFromDesc_l() must be called with IAfThreadBase::mutex() held
sp<IAfEffectModule> EffectChain::getEffectFromDesc_l(
effect_descriptor_t *descriptor) const
{
@@ -2159,7 +2159,7 @@
return 0;
}
-// getEffectFromId_l() must be called with AudioFlinger::ThreadBase::mLock held
+// getEffectFromId_l() must be called with IAfThreadBase::mutex() held
sp<IAfEffectModule> EffectChain::getEffectFromId_l(int id) const
{
size_t size = mEffects.size();
@@ -2173,7 +2173,7 @@
return 0;
}
-// getEffectFromType_l() must be called with AudioFlinger::ThreadBase::mLock held
+// getEffectFromType_l() must be called with IAfThreadBase::mutex() held
sp<IAfEffectModule> EffectChain::getEffectFromType_l(
const effect_uuid_t *type) const
{
@@ -2268,7 +2268,7 @@
}
}
-// createEffect_l() must be called with AudioFlinger::ThreadBase::mLock held
+// createEffect_l() must be called with IAfThreadBase::mutex() held
status_t EffectChain::createEffect_l(sp<IAfEffectModule>& effect,
effect_descriptor_t *desc,
int id,
@@ -2287,13 +2287,13 @@
return lStatus;
}
-// addEffect_l() must be called with AudioFlinger::ThreadBase::mLock held
+// addEffect_l() must be called with IAfThreadBase::mutex() held
status_t EffectChain::addEffect_l(const sp<IAfEffectModule>& effect)
{
Mutex::Autolock _l(mLock);
return addEffect_ll(effect);
}
-// addEffect_l() must be called with AudioFlinger::ThreadBase::mLock and EffectChain::mLock held
+// addEffect_l() must be called with IAfThreadBase::mLock and EffectChain::mutex() held
status_t EffectChain::addEffect_ll(const sp<IAfEffectModule>& effect)
{
effect->setCallback(mEffectCallback);
@@ -2447,7 +2447,7 @@
return idx_insert;
}
-// removeEffect_l() must be called with AudioFlinger::ThreadBase::mLock held
+// removeEffect_l() must be called with IAfThreadBase::mutex() held
size_t EffectChain::removeEffect_l(const sp<IAfEffectModule>& effect,
bool release)
{
@@ -2495,7 +2495,7 @@
return mEffects.size();
}
-// setDevices_l() must be called with AudioFlinger::ThreadBase::mLock held
+// setDevices_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setDevices_l(const AudioDeviceTypeAddrVector &devices)
{
size_t size = mEffects.size();
@@ -2504,7 +2504,7 @@
}
}
-// setInputDevice_l() must be called with AudioFlinger::ThreadBase::mLock held
+// setInputDevice_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setInputDevice_l(const AudioDeviceTypeAddr &device)
{
size_t size = mEffects.size();
@@ -2513,7 +2513,7 @@
}
}
-// setMode_l() must be called with AudioFlinger::ThreadBase::mLock held
+// setMode_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setMode_l(audio_mode_t mode)
{
size_t size = mEffects.size();
@@ -2522,7 +2522,7 @@
}
}
-// setAudioSource_l() must be called with AudioFlinger::ThreadBase::mLock held
+// setAudioSource_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setAudioSource_l(audio_source_t source)
{
size_t size = mEffects.size();
@@ -2538,7 +2538,7 @@
return false;
}
-// setVolume_l() must be called with AudioFlinger::ThreadBase::mLock or EffectChain::mLock held
+// setVolume_l() must be called with IAfThreadBase::mLock or EffectChain::mLock held
bool EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
{
uint32_t newLeft = *left;
@@ -2605,7 +2605,7 @@
return hasControl;
}
-// resetVolume_l() must be called with AudioFlinger::ThreadBase::mLock or EffectChain::mLock held
+// resetVolume_l() must be called with IAfThreadBase::mutex() or EffectChain::mLock held
void EffectChain::resetVolume_l()
{
if ((mLeftVolume != UINT_MAX) && (mRightVolume != UINT_MAX)) {
@@ -2616,7 +2616,7 @@
}
// containsHapticGeneratingEffect_l must be called with
-// AudioFlinger::ThreadBase::mLock or EffectChain::mLock held
+// IAfThreadBase::mutex() or EffectChain::mLock held
bool EffectChain::containsHapticGeneratingEffect_l()
{
for (size_t i = 0; i < mEffects.size(); ++i) {
@@ -2685,7 +2685,7 @@
}
}
-// must be called with AudioFlinger::ThreadBase::mLock held
+// must be called with IAfThreadBase::mutex() held
void EffectChain::setEffectSuspended_l(
const effect_uuid_t *type, bool suspend)
{
@@ -2741,7 +2741,7 @@
}
}
-// must be called with AudioFlinger::ThreadBase::mLock held
+// must be called with IAfThreadBase::mutex() held
void EffectChain::setEffectSuspendedAll_l(bool suspend)
{
sp<SuspendedEffectDesc> desc;
@@ -2897,7 +2897,7 @@
return false;
}
-void EffectChain::setThread(const sp<AudioFlinger::ThreadBase>& thread)
+void EffectChain::setThread(const sp<IAfThreadBase>& thread)
{
Mutex::Autolock _l(mLock);
mEffectCallback->setThread(thread);
@@ -2964,7 +2964,7 @@
}
// isCompatibleWithThread_l() must be called with thread->mLock held
-bool EffectChain::isCompatibleWithThread_l(const sp<AudioFlinger::ThreadBase>& thread) const
+bool EffectChain::isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const
{
Mutex::Autolock _l(mLock);
for (size_t i = 0; i < mEffects.size(); i++) {
@@ -3002,7 +3002,7 @@
status_t EffectChain::EffectCallback::addEffectToHal(
const sp<EffectHalInterface>& effect) {
status_t result = NO_INIT;
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return result;
}
@@ -3018,7 +3018,7 @@
status_t EffectChain::EffectCallback::removeEffectFromHal(
const sp<EffectHalInterface>& effect) {
status_t result = NO_INIT;
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return result;
}
@@ -3032,7 +3032,7 @@
}
audio_io_handle_t EffectChain::EffectCallback::io() const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return AUDIO_IO_HANDLE_NONE;
}
@@ -3040,7 +3040,7 @@
}
bool EffectChain::EffectCallback::isOutput() const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return true;
}
@@ -3048,19 +3048,19 @@
}
bool EffectChain::EffectCallback::isOffload() const {
- return mThreadType == AudioFlinger::ThreadBase::OFFLOAD;
+ return mThreadType == IAfThreadBase::OFFLOAD;
}
bool EffectChain::EffectCallback::isOffloadOrDirect() const {
- return mThreadType == AudioFlinger::ThreadBase::OFFLOAD
- || mThreadType == AudioFlinger::ThreadBase::DIRECT;
+ return mThreadType == IAfThreadBase::OFFLOAD
+ || mThreadType == IAfThreadBase::DIRECT;
}
bool EffectChain::EffectCallback::isOffloadOrMmap() const {
switch (mThreadType) {
- case AudioFlinger::ThreadBase::OFFLOAD:
- case AudioFlinger::ThreadBase::MMAP_PLAYBACK:
- case AudioFlinger::ThreadBase::MMAP_CAPTURE:
+ case IAfThreadBase::OFFLOAD:
+ case IAfThreadBase::MMAP_PLAYBACK:
+ case IAfThreadBase::MMAP_CAPTURE:
return true;
default:
return false;
@@ -3068,11 +3068,11 @@
}
bool EffectChain::EffectCallback::isSpatializer() const {
- return mThreadType == AudioFlinger::ThreadBase::SPATIALIZER;
+ return mThreadType == IAfThreadBase::SPATIALIZER;
}
uint32_t EffectChain::EffectCallback::sampleRate() const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return 0;
}
@@ -3080,7 +3080,7 @@
}
audio_channel_mask_t EffectChain::EffectCallback::inChannelMask(int id) const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return AUDIO_CHANNEL_NONE;
}
@@ -3089,7 +3089,7 @@
return AUDIO_CHANNEL_NONE;
}
- if (mThreadType == AudioFlinger::ThreadBase::SPATIALIZER) {
+ if (mThreadType == IAfThreadBase::SPATIALIZER) {
if (c->sessionId() == AUDIO_SESSION_OUTPUT_STAGE) {
if (c->isFirstEffect(id)) {
return t->mixerChannelMask();
@@ -3098,7 +3098,7 @@
}
} else if (!audio_is_global_session(c->sessionId())) {
if ((t->hasAudioSession_l(c->sessionId())
- & AudioFlinger::ThreadBase::SPATIALIZED_SESSION) != 0) {
+ & IAfThreadBase::SPATIALIZED_SESSION) != 0) {
return t->mixerChannelMask();
} else {
return t->channelMask();
@@ -3116,7 +3116,7 @@
}
audio_channel_mask_t EffectChain::EffectCallback::outChannelMask() const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return AUDIO_CHANNEL_NONE;
}
@@ -3125,10 +3125,10 @@
return AUDIO_CHANNEL_NONE;
}
- if (mThreadType == AudioFlinger::ThreadBase::SPATIALIZER) {
+ if (mThreadType == IAfThreadBase::SPATIALIZER) {
if (!audio_is_global_session(c->sessionId())) {
if ((t->hasAudioSession_l(c->sessionId())
- & AudioFlinger::ThreadBase::SPATIALIZED_SESSION) != 0) {
+ & IAfThreadBase::SPATIALIZED_SESSION) != 0) {
return t->mixerChannelMask();
} else {
return t->channelMask();
@@ -3146,7 +3146,7 @@
}
audio_channel_mask_t EffectChain::EffectCallback::hapticChannelMask() const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return AUDIO_CHANNEL_NONE;
}
@@ -3154,7 +3154,7 @@
}
size_t EffectChain::EffectCallback::frameCount() const {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return 0;
}
@@ -3164,7 +3164,7 @@
uint32_t EffectChain::EffectCallback::latency() const
NO_THREAD_SAFETY_ANALYSIS // latency_l() access
{
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return 0;
}
@@ -3175,7 +3175,7 @@
void EffectChain::EffectCallback::setVolumeForOutput(float left, float right) const
NO_THREAD_SAFETY_ANALYSIS // setVolumeForOutput_l() access
{
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return;
}
@@ -3184,7 +3184,7 @@
void EffectChain::EffectCallback::checkSuspendOnEffectEnabled(
const sp<IAfEffectBase>& effect, bool enabled, bool threadLocked) {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return;
}
@@ -3199,7 +3199,7 @@
}
void EffectChain::EffectCallback::onEffectEnable(const sp<IAfEffectBase>& effect) {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return;
}
@@ -3210,7 +3210,7 @@
void EffectChain::EffectCallback::onEffectDisable(const sp<IAfEffectBase>& effect) {
checkSuspendOnEffectEnabled(effect, false, false /*threadLocked*/);
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return;
}
@@ -3219,7 +3219,7 @@
bool EffectChain::EffectCallback::disconnectEffectHandle(IAfEffectHandle *handle,
bool unpinIfLast) {
- sp<AudioFlinger::ThreadBase> t = thread().promote();
+ const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
return false;
}
@@ -3401,7 +3401,7 @@
mDevicePort.id = AUDIO_PORT_HANDLE_NONE;
}
} else if (patch.isSoftware() || patch.thread().promote() != nullptr) {
- sp <AudioFlinger::ThreadBase> thread;
+ sp<IAfThreadBase> thread;
if (audio_port_config_has_input_direction(port)) {
if (patch.isSoftware()) {
thread = patch.mRecord.thread();