Assert effect hal interface not null before access
Also add debugging information to assert
Bug: 315995877
Test: atest CtsMediaAudioTestCases
Change-Id: Ic43c375bb57b64bb169eece8f7be28f011ecebc0
Merged-In: Ic43c375bb57b64bb169eece8f7be28f011ecebc0
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index e85329d..0d35c82 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -562,12 +562,9 @@
#undef LOG_TAG
#define LOG_TAG "EffectModule"
-EffectModule::EffectModule(const sp<EffectCallbackInterface>& callback,
- effect_descriptor_t *desc,
- int id,
- audio_session_t sessionId,
- bool pinned,
- audio_port_handle_t deviceId)
+EffectModule::EffectModule(const sp<EffectCallbackInterface>& callback, effect_descriptor_t* desc,
+ int id, audio_session_t sessionId, bool pinned,
+ audio_port_handle_t deviceId)
: EffectBase(callback, desc, id, sessionId, pinned),
// clear mConfig to ensure consistent initial value of buffer framecount
// in case buffers are associated by setInBuffer() or setOutBuffer()
@@ -577,9 +574,9 @@
mMaxDisableWaitCnt(1), // set by configure_l(), should be >= 1
mDisableWaitCnt(0), // set by process() and updateState()
mOffloaded(false),
- mIsOutput(false)
- , mSupportsFloat(false)
-{
+ mIsOutput(false),
+ mSupportsFloat(false),
+ mEffectInterfaceDebug(desc->name) {
ALOGV("Constructor %p pinned %d", this, pinned);
int lStatus;
@@ -587,6 +584,7 @@
mStatus = callback->createEffectHal(
&desc->uuid, sessionId, deviceId, &mEffectInterface);
if (mStatus != NO_ERROR) {
+ ALOGE("%s createEffectHal failed: %d", __func__, mStatus);
return;
}
lStatus = init_l();
@@ -596,12 +594,14 @@
}
setOffloaded_l(callback->isOffload(), callback->io());
- ALOGV("Constructor success name %s, Interface %p", mDescriptor.name, mEffectInterface.get());
+ ALOGV("%s Constructor success name %s, Interface %p", __func__, mDescriptor.name,
+ mEffectInterface.get());
return;
Error:
mEffectInterface.clear();
- ALOGV("Constructor Error %d", mStatus);
+ mEffectInterfaceDebug += " init failed:" + std::to_string(lStatus);
+ ALOGE("%s Constructor Error %d", __func__, mStatus);
}
EffectModule::~EffectModule()
@@ -612,7 +612,7 @@
AudioEffect::guidToString(&mDescriptor.uuid, uuidStr, sizeof(uuidStr));
ALOGW("EffectModule %p destructor called with unreleased interface, effect %s",
this, uuidStr);
- release_l();
+ release_l("~EffectModule");
}
}
@@ -1129,13 +1129,14 @@
}
// must be called with EffectChain::mutex() held
-void EffectModule::release_l()
+void EffectModule::release_l(const std::string& from)
{
if (mEffectInterface != 0) {
removeEffectFromHal_l();
// release effect engine
mEffectInterface->close();
mEffectInterface.clear();
+ mEffectInterfaceDebug += " released by: " + from;
}
}
@@ -1388,6 +1389,7 @@
*right = mReturnedVolume.value()[1];
return NO_ERROR;
}
+ LOG_ALWAYS_FATAL_IF(mEffectInterface == nullptr, "%s", mEffectInterfaceDebug.c_str());
uint32_t volume[2] = {*left, *right};
uint32_t* pVolume = isVolumeControl() ? volume : nullptr;
uint32_t size = sizeof(volume);
@@ -2534,7 +2536,7 @@
mEffects[i]->stop_l();
}
if (release) {
- mEffects[i]->release_l();
+ mEffects[i]->release_l("EffectChain::removeEffect");
}
// Skip operation when no thread attached (could lead to sigfpe as framecount is 0...)
if (hasThreadAttached && type != EFFECT_FLAG_TYPE_AUXILIARY) {
@@ -3581,7 +3583,7 @@
{
audio_utils::lock_guard _l(proxyMutex());
if (effect == mHalEffect) {
- mHalEffect->release_l();
+ mHalEffect->release_l("DeviceEffectProxy::removeEffect");
mHalEffect.clear();
mDevicePort.id = AUDIO_PORT_HANDLE_NONE;
}