Effects: Update to audio_utils mutex
Test: atest AudioTrackTest AudioRecordTest
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioPlaybackCaptureTest
Test: Camera YouTube
Bug: 298534151
Change-Id: I2ff0b2748110b56da238db7dd74b3c6692ffce39
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index aab076c..2657fcc 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -109,7 +109,7 @@
{
}
-// must be called with EffectModule::mLock held
+// must be called with EffectModule::mutex() held
status_t EffectBase::setEnabled_l(bool enabled)
{
@@ -155,7 +155,7 @@
{
status_t status;
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
status = setEnabled_l(enabled);
}
if (fromHandle) {
@@ -190,13 +190,13 @@
void EffectBase::setSuspended(bool suspended)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
mSuspended = suspended;
}
bool EffectBase::suspended() const
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
return mSuspended;
}
@@ -204,7 +204,7 @@
{
status_t status;
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
int priority = handle->priority();
size_t size = mHandles.size();
IAfEffectHandle *controlHandle = nullptr;
@@ -250,7 +250,7 @@
product_strategy_t strategy = PRODUCT_STRATEGY_NONE;
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if ((isInternal_l() && !mPolicyRegistered)
|| !getCallback()->isAudioPolicyReady()) {
@@ -284,7 +284,7 @@
return NO_ERROR;
}
}
- mPolicyLock.lock();
+ policyMutex().lock();
ALOGV("%s name %s id %d session %d doRegister %d registered %d doEnable %d enabled %d",
__func__, mDescriptor.name, mId, mSessionId, doRegister, registered, doEnable, enabled);
if (doRegister) {
@@ -302,7 +302,7 @@
if (registered && doEnable) {
status = AudioSystem::setEffectEnabled(mId, enabled);
}
- mPolicyLock.unlock();
+ policyMutex().unlock();
return status;
}
@@ -310,7 +310,7 @@
ssize_t EffectBase::removeHandle(IAfEffectHandle *handle)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
return removeHandle_l(handle);
}
@@ -348,7 +348,7 @@
return mHandles.size();
}
-// must be called with EffectModule::mLock held
+// must be called with EffectModule::mutex() held
IAfEffectHandle *EffectBase::controlHandle_l()
{
// the first valid handle in the list has control over the module
@@ -371,12 +371,12 @@
return mHandles.size();
}
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
ssize_t numHandles = removeHandle_l(handle);
if ((numHandles == 0) && (!mPinned || unpinIfLast)) {
- mLock.unlock();
+ mutex().unlock();
callback->updateOrphanEffectChains(this);
- mLock.lock();
+ mutex().lock();
}
return numHandles;
}
@@ -384,7 +384,7 @@
bool EffectBase::purgeHandles()
{
bool enabled = false;
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
IAfEffectHandle *handle = controlHandle_l();
if (handle != NULL) {
enabled = handle->enabled();
@@ -509,7 +509,7 @@
result.appendFormat("\tEffect ID %d:\n", mId);
- const bool locked = afutils::dumpTryLock(mLock);
+ const bool locked = afutils::dumpTryLock(mutex());
// failed to lock - AudioFlinger is probably deadlocked
if (!locked) {
result.append("\t\tCould not lock Fx mutex:\n");
@@ -548,7 +548,7 @@
}
}
if (locked) {
- mLock.unlock();
+ mutex().unlock();
}
write(fd, result.c_str(), result.length());
@@ -617,7 +617,7 @@
}
bool EffectModule::updateState() {
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
bool started = false;
switch (mState) {
@@ -673,7 +673,7 @@
void EffectModule::process()
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mState == DESTROYED || mEffectInterface == 0 || mInBuffer == 0 || mOutBuffer == 0) {
return;
@@ -1015,7 +1015,7 @@
status_t EffectModule::init()
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mEffectInterface == 0) {
return NO_INIT;
}
@@ -1045,12 +1045,12 @@
}
}
-// start() must be called with PlaybackThread::mLock or EffectChain::mLock held
+// start() must be called with PlaybackThread::mutex() or EffectChain::mutex() held
status_t EffectModule::start()
{
status_t status;
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
status = start_l();
}
if (status == NO_ERROR) {
@@ -1085,7 +1085,7 @@
status_t EffectModule::stop()
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
return stop_l();
}
@@ -1122,7 +1122,7 @@
return status;
}
-// must be called with EffectChain::mLock held
+// must be called with EffectChain::mutex() held
void EffectModule::release_l()
{
if (mEffectInterface != 0) {
@@ -1158,7 +1158,7 @@
int32_t maxReplySize,
std::vector<uint8_t>* reply)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
ALOGVV("command(), cmdCode: %d, mEffectInterface: %p", cmdCode, mEffectInterface.get());
if (mState == DESTROYED || mEffectInterface == 0) {
@@ -1355,7 +1355,7 @@
status_t EffectModule::setVolume(uint32_t *left, uint32_t *right, bool controller)
{
- AutoLockReentrant _l(mLock, mSetVolumeReentrantTid);
+ AutoLockReentrant _l(mutex(), mSetVolumeReentrantTid);
if (mStatus != NO_ERROR) {
return mStatus;
}
@@ -1409,7 +1409,7 @@
return NO_ERROR;
}
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mStatus != NO_ERROR) {
return mStatus;
}
@@ -1439,7 +1439,7 @@
status_t EffectModule::setMode(audio_mode_t mode)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mStatus != NO_ERROR) {
return mStatus;
}
@@ -1461,7 +1461,7 @@
status_t EffectModule::setAudioSource(audio_source_t source)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mStatus != NO_ERROR) {
return mStatus;
}
@@ -1479,7 +1479,7 @@
status_t EffectModule::setOffloaded(bool offloaded, audio_io_handle_t io)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mStatus != NO_ERROR) {
return mStatus;
}
@@ -1512,7 +1512,7 @@
bool EffectModule::isOffloaded() const
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
return mOffloaded;
}
@@ -1583,7 +1583,7 @@
status_t EffectModule::getConfigs(
audio_config_base_t* inputCfg, audio_config_base_t* outputCfg, bool* isOutput) const {
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
if (mConfig.inputCfg.mask == 0 || mConfig.outputCfg.mask == 0) {
return NO_INIT;
}
@@ -1618,7 +1618,7 @@
EffectBase::dump(fd, args);
String8 result;
- const bool locked = afutils::dumpTryLock(mLock);
+ const bool locked = afutils::dumpTryLock(mutex());
result.append("\t\tStatus Engine:\n");
result.appendFormat("\t\t%03d %p\n",
@@ -1661,7 +1661,7 @@
}
if (locked) {
- mLock.unlock();
+ mutex().unlock();
}
}
@@ -1784,7 +1784,7 @@
Status EffectHandle::enable(int32_t* _aidl_return)
{
- AutoMutex _l(mLock);
+ audio_utils::lock_guard _l(mutex());
ALOGV("enable %p", this);
sp<IAfEffectBase> effect = mEffect.promote();
if (effect == 0 || mDisconnected) {
@@ -1823,7 +1823,7 @@
Status EffectHandle::disable(int32_t* _aidl_return)
{
ALOGV("disable %p", this);
- AutoMutex _l(mLock);
+ audio_utils::lock_guard _l(mutex());
sp<IAfEffectBase> effect = mEffect.promote();
if (effect == 0 || mDisconnected) {
RETURN(DEAD_OBJECT);
@@ -1856,7 +1856,7 @@
void EffectHandle::disconnect(bool unpinIfLast)
{
- AutoMutex _l(mLock);
+ audio_utils::lock_guard _l(mutex());
ALOGV("disconnect(%s) %p", unpinIfLast ? "true" : "false", this);
if (mDisconnected) {
if (unpinIfLast) {
@@ -1895,7 +1895,7 @@
Status EffectHandle::getConfig(
media::EffectConfig* _config, int32_t* _aidl_return) {
- AutoMutex _l(mLock);
+ audio_utils::lock_guard _l(mutex());
sp<IAfEffectBase> effect = mEffect.promote();
if (effect == nullptr || mDisconnected) {
RETURN(DEAD_OBJECT);
@@ -1962,7 +1962,7 @@
return disable(_aidl_return);
}
- AutoMutex _l(mLock);
+ audio_utils::lock_guard _l(mutex());
sp<IAfEffectBase> effect = mEffect.promote();
if (effect == 0 || mDisconnected) {
RETURN(DEAD_OBJECT);
@@ -2176,7 +2176,7 @@
std::vector<int> EffectChain::getEffectIds() const
{
std::vector<int> ids;
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (size_t i = 0; i < mEffects.size(); i++) {
ids.push_back(mEffects[i]->id());
}
@@ -2185,11 +2185,11 @@
void EffectChain::clearInputBuffer()
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
clearInputBuffer_l();
}
-// Must be called with EffectChain::mLock locked
+// Must be called with EffectChain::mutex() locked
void EffectChain::clearInputBuffer_l()
{
if (mInBuffer == NULL) {
@@ -2202,7 +2202,7 @@
mInBuffer->commit();
}
-// Must be called with EffectChain::mLock locked
+// Must be called with EffectChain::mutex() locked
void EffectChain::process_l()
{
// never process effects when:
@@ -2261,7 +2261,7 @@
audio_session_t sessionId,
bool pinned)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
effect = new EffectModule(mEffectCallback, desc, id, sessionId, pinned, AUDIO_PORT_HANDLE_NONE);
status_t lStatus = effect->status();
if (lStatus == NO_ERROR) {
@@ -2276,10 +2276,10 @@
// addEffect_l() must be called with IAfThreadBase::mutex() held
status_t EffectChain::addEffect_l(const sp<IAfEffectModule>& effect)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
return addEffect_ll(effect);
}
-// addEffect_l() must be called with IAfThreadBase::mLock and EffectChain::mutex() held
+// addEffect_l() must be called with IAfThreadBase::mutex() and EffectChain::mutex() held
status_t EffectChain::addEffect_ll(const sp<IAfEffectModule>& effect)
{
effect->setCallback(mEffectCallback);
@@ -2446,7 +2446,7 @@
size_t EffectChain::removeEffect_l(const sp<IAfEffectModule>& effect,
bool release)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
size_t size = mEffects.size();
uint32_t type = effect->desc().flags & EFFECT_FLAG_TYPE_MASK;
@@ -2533,7 +2533,7 @@
return false;
}
-// setVolume_l() must be called with IAfThreadBase::mLock or EffectChain::mLock held
+// setVolume_l() must be called with IAfThreadBase::mutex() or EffectChain::mutex() held
bool EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
{
uint32_t newLeft = *left;
@@ -2609,7 +2609,7 @@
return volumeControlIndex.has_value();
}
-// resetVolume_l() must be called with IAfThreadBase::mutex() or EffectChain::mLock held
+// resetVolume_l() must be called with IAfThreadBase::mutex() or EffectChain::mutex() held
void EffectChain::resetVolume_l()
{
if ((mLeftVolume != UINT_MAX) && (mRightVolume != UINT_MAX)) {
@@ -2620,7 +2620,7 @@
}
// containsHapticGeneratingEffect_l must be called with
-// IAfThreadBase::mutex() or EffectChain::mLock held
+// IAfThreadBase::mutex() or EffectChain::mutex() held
bool EffectChain::containsHapticGeneratingEffect_l()
{
for (size_t i = 0; i < mEffects.size(); ++i) {
@@ -2633,7 +2633,7 @@
void EffectChain::setHapticIntensity_l(int id, os::HapticScale intensity)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (size_t i = 0; i < mEffects.size(); ++i) {
mEffects[i]->setHapticIntensity(id, intensity);
}
@@ -2641,7 +2641,7 @@
void EffectChain::syncHalEffectsState()
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (size_t i = 0; i < mEffects.size(); i++) {
if (mEffects[i]->state() == EffectModule::ACTIVE ||
mEffects[i]->state() == EffectModule::STOPPING) {
@@ -2659,7 +2659,7 @@
result.appendFormat(" %zu effects for session %d\n", numEffects, mSessionId);
if (numEffects) {
- const bool locked = afutils::dumpTryLock(mLock);
+ const bool locked = afutils::dumpTryLock(mutex());
// failed to lock - AudioFlinger is probably deadlocked
if (!locked) {
result.append("\tCould not lock mutex:\n");
@@ -2682,7 +2682,7 @@
}
if (locked) {
- mLock.unlock();
+ mutex().unlock();
}
} else {
write(fd, result.c_str(), result.size());
@@ -2731,12 +2731,12 @@
sp<IAfEffectModule> effect = desc->mEffect.promote();
if (effect != 0) {
effect->setSuspended(false);
- effect->lock();
+ effect->mutex().lock();
IAfEffectHandle *handle = effect->controlHandle_l();
if (handle != NULL && !handle->disconnected()) {
effect->setEnabled_l(handle->enabled());
}
- effect->unlock();
+ effect->mutex().unlock();
}
desc->mEffect.clear();
}
@@ -2886,7 +2886,7 @@
bool EffectChain::isNonOffloadableEnabled() const
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
return isNonOffloadableEnabled_l();
}
@@ -2903,7 +2903,7 @@
void EffectChain::setThread(const sp<IAfThreadBase>& thread)
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
mEffectCallback->setThread(thread);
}
@@ -2932,7 +2932,7 @@
bool EffectChain::isRawCompatible() const
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (const auto &effect : mEffects) {
if (effect->isProcessImplemented()) {
return false;
@@ -2944,7 +2944,7 @@
bool EffectChain::isFastCompatible() const
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (const auto &effect : mEffects) {
if (effect->isProcessImplemented()
&& effect->isImplementationSoftware()) {
@@ -2956,7 +2956,7 @@
}
bool EffectChain::isBitPerfectCompatible() const {
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (const auto &effect : mEffects) {
if (effect->isProcessImplemented()
&& effect->isImplementationSoftware()) {
@@ -2967,10 +2967,10 @@
return true;
}
-// isCompatibleWithThread_l() must be called with thread->mLock held
+// isCompatibleWithThread_l() must be called with thread->mutex() held
bool EffectChain::isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const
{
- Mutex::Autolock _l(mLock);
+ audio_utils::lock_guard _l(mutex());
for (size_t i = 0; i < mEffects.size(); i++) {
if (thread->checkEffectCompatibility_l(&(mEffects[i]->desc()), mSessionId) != NO_ERROR) {
return false;
@@ -3274,7 +3274,7 @@
status_t DeviceEffectProxy::setEnabled(bool enabled, bool fromHandle)
{
status_t status = EffectBase::setEnabled(enabled, fromHandle);
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
if (status == NO_ERROR) {
for (auto& handle : mEffectHandles) {
Status bs;
@@ -3320,7 +3320,7 @@
const IAfPatchPanel::Patch& /* patch */) {
status_t status = NAME_NOT_FOUND;
ALOGV("%s", __func__);
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
if (mEffectHandles.find(oldPatchHandle) != mEffectHandles.end()) {
ALOGV("%s replacing effect from handle %d to handle %d", __func__, oldPatchHandle,
newPatchHandle);
@@ -3344,7 +3344,7 @@
ALOGV("%s sink %d checkPort status %d", __func__, i, status);
}
if (status == NO_ERROR || status == ALREADY_EXISTS) {
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
size_t erasedHandle = mEffectHandles.erase(patchHandle);
ALOGV("%s %s effecthandle %p for patch %d",
__func__, (erasedHandle == 0 ? "adding" : "replacing"), handle.get(), patchHandle);
@@ -3379,7 +3379,7 @@
status_t status = NAME_NOT_FOUND;
if (mDescriptor.flags & EFFECT_FLAG_HW_ACC_TUNNEL) {
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
if (mHalEffect != nullptr && mDevicePort.id == port->id) {
ALOGV("%s reusing HAL effect", __func__);
} else {
@@ -3446,7 +3446,7 @@
void DeviceEffectProxy::onReleasePatch(audio_patch_handle_t patchHandle) {
sp<IAfEffectHandle> effect;
{
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
if (mEffectHandles.find(patchHandle) != mEffectHandles.end()) {
effect = mEffectHandles.at(patchHandle);
mEffectHandles.erase(patchHandle);
@@ -3457,7 +3457,7 @@
size_t DeviceEffectProxy::removeEffect(const sp<IAfEffectModule>& effect)
{
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
if (effect == mHalEffect) {
mHalEffect->release_l();
mHalEffect.clear();
@@ -3485,7 +3485,7 @@
status_t DeviceEffectProxy::command(
int32_t cmdCode, const std::vector<uint8_t>& cmdData, int32_t maxReplySize,
std::vector<uint8_t>* reply) {
- Mutex::Autolock _l(mProxyLock);
+ audio_utils::lock_guard _l(proxyMutex());
status_t status = EffectBase::command(cmdCode, cmdData, maxReplySize, reply);
if (status == NO_ERROR) {
for (auto& handle : mEffectHandles) {
@@ -3535,7 +3535,7 @@
const Vector<String16> args;
EffectBase::dump(fd, args);
- const bool locked = afutils::dumpTryLock(mProxyLock);
+ const bool locked = afutils::dumpTryLock(proxyMutex());
if (!locked) {
String8 result("DeviceEffectProxy may be deadlocked\n");
write(fd, result.c_str(), result.size());
@@ -3565,7 +3565,7 @@
}
if (locked) {
- mProxyLock.unlock();
+ proxyMutex().unlock();
}
}