Loading services/audioflinger/AudioFlinger.cpp +7 −17 Original line number Diff line number Diff line Loading @@ -1193,26 +1193,11 @@ status_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8& String8 value; if (param.get(String8(AudioParameter::keyBtNrec), value) == NO_ERROR) { bool btNrecIsOff = (value == AudioParameter::valueOff); if (mBtNrecIsOff != btNrecIsOff) { if (mBtNrecIsOff.exchange(btNrecIsOff) != btNrecIsOff) { for (size_t i = 0; i < mRecordThreads.size(); i++) { sp<RecordThread> thread = mRecordThreads.valueAt(i); audio_devices_t device = thread->inDevice(); bool suspend = audio_is_bluetooth_sco_device(device) && btNrecIsOff; // collect all of the thread's session IDs KeyedVector<audio_session_t, bool> ids = thread->sessionIds(); // suspend effects associated with those session IDs for (size_t j = 0; j < ids.size(); ++j) { audio_session_t sessionId = ids.keyAt(j); thread->setEffectSuspended(FX_IID_AEC, suspend, sessionId); thread->setEffectSuspended(FX_IID_NS, suspend, sessionId); mRecordThreads.valueAt(i)->checkBtNrec(); } } mBtNrecIsOff = btNrecIsOff; } } String8 screenState; if (param.get(String8(AudioParameter::keyScreenState), screenState) == NO_ERROR) { Loading Loading @@ -3214,6 +3199,11 @@ void AudioFlinger::onNonOffloadableGlobalEffectEnable() status_t AudioFlinger::putOrphanEffectChain_l(const sp<AudioFlinger::EffectChain>& chain) { // clear possible suspended state before parking the chain so that it starts in default state // when attached to a new record thread chain->setEffectSuspended_l(FX_IID_AEC, false); chain->setEffectSuspended_l(FX_IID_NS, false); audio_session_t session = chain->sessionId(); ssize_t index = mOrphanEffectChains.indexOfKey(session); ALOGV("putOrphanEffectChain_l session %d index %zd", session, index); Loading services/audioflinger/AudioFlinger.h +4 −3 Original line number Diff line number Diff line Loading @@ -350,12 +350,13 @@ public: sync_event_callback_t callBack, const wp<RefBase>& cookie); bool btNrecIsOff() const { return mBtNrecIsOff.load(); } private: audio_mode_t getMode() const { return mMode; } bool btNrecIsOff() const { return mBtNrecIsOff; } AudioFlinger() ANDROID_API; virtual ~AudioFlinger(); Loading Loading @@ -781,7 +782,7 @@ private: volatile atomic_uint_fast32_t mNextUniqueIds[AUDIO_UNIQUE_ID_USE_MAX]; audio_mode_t mMode; bool mBtNrecIsOff; std::atomic_bool mBtNrecIsOff; // protected by mLock Vector<AudioSessionRef*> mAudioSessionRefs; Loading services/audioflinger/Effects.cpp +19 −3 Original line number Diff line number Diff line Loading @@ -21,10 +21,12 @@ #include "Configuration.h" #include <utils/Log.h> #include <system/audio_effects/effect_aec.h> #include <system/audio_effects/effect_ns.h> #include <system/audio_effects/effect_visualizer.h> #include <audio_utils/primitives.h> #include <media/audiohal/EffectHalInterface.h> #include <media/audiohal/EffectsFactoryHalInterface.h> #include <system/audio_effects/effect_visualizer.h> #include "AudioFlinger.h" #include "ServiceUtilities.h" Loading Loading @@ -1809,6 +1811,7 @@ status_t AudioFlinger::EffectChain::addEffect_ll(const sp<EffectModule>& effect) idx_insert); } effect->configure(); return NO_ERROR; } Loading Loading @@ -2030,6 +2033,7 @@ void AudioFlinger::EffectChain::setEffectSuspended_l( mSuspendedEffects.add(type->timeLow, desc); ALOGV("setEffectSuspended_l() add entry for %08x", type->timeLow); } if (desc->mRefCount++ == 0) { sp<EffectModule> effect = getEffectIfEnabled(type); if (effect != 0) { Loading @@ -2045,7 +2049,8 @@ void AudioFlinger::EffectChain::setEffectSuspended_l( desc = mSuspendedEffects.valueAt(index); if (desc->mRefCount <= 0) { ALOGW("setEffectSuspended_l() restore refcount should not be 0 %d", desc->mRefCount); desc->mRefCount = 1; desc->mRefCount = 0; return; } if (--desc->mRefCount == 0) { ALOGV("setEffectSuspended_l() remove entry for %08x", mSuspendedEffects.keyAt(index)); Loading Loading @@ -2123,6 +2128,17 @@ static const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6 const effect_uuid_t * const SL_IID_VOLUME = &SL_IID_VOLUME_; #endif //OPENSL_ES_H_ /* static */ bool AudioFlinger::EffectChain::isEffectEligibleForBtNrecSuspend(const effect_uuid_t *type) { // Only NS and AEC are suspended when BtNRec is off if ((memcmp(type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) || (memcmp(type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) { return true; } return false; } bool AudioFlinger::EffectChain::isEffectEligibleForSuspend(const effect_descriptor_t& desc) { // auxiliary effects and visualizer are never suspended on output mix Loading Loading @@ -2177,7 +2193,7 @@ void AudioFlinger::EffectChain::checkSuspendOnEffectEnabled(const sp<EffectModul ALOGV("checkSuspendOnEffectEnabled() enable suspending fx %08x", effect->desc().type.timeLow); sp<SuspendedEffectDesc> desc = mSuspendedEffects.valueAt(index); // if effect is requested to suspended but was not yet enabled, supend it now. // if effect is requested to suspended but was not yet enabled, suspend it now. if (desc->mEffect == 0) { desc->mEffect = effect; effect->setEnabled(false); Loading services/audioflinger/Effects.h +6 −3 Original line number Diff line number Diff line Loading @@ -331,7 +331,8 @@ public: void setStrategy(uint32_t strategy) { mStrategy = strategy; } // suspend effect of the given type // suspend or restore effects of the specified type. The number of suspend requests is counted // and restore occurs once all suspend requests are cancelled. void setEffectSuspended_l(const effect_uuid_t *type, bool suspend); // suspend all eligible effects Loading Loading @@ -372,7 +373,7 @@ private: public: SuspendedEffectDesc() : mRefCount(0) {} int mRefCount; int mRefCount; // > 0 when suspended effect_uuid_t mType; wp<EffectModule> mEffect; }; Loading @@ -388,6 +389,8 @@ private: // types or implementations from the suspend/restore mechanism. bool isEffectEligibleForSuspend(const effect_descriptor_t& desc); static bool isEffectEligibleForBtNrecSuspend(const effect_uuid_t *type); void clearInputBuffer_l(const sp<ThreadBase>& thread); void setThread(const sp<ThreadBase>& thread); Loading @@ -414,6 +417,6 @@ private: // mSuspendedEffects lists all effects currently suspended in the chain. // Use effect type UUID timelow field as key. There is no real risk of identical // timeLow fields among effect type UUIDs. // Updated by updateSuspendedSessions_l() only. // Updated by setEffectSuspended_l() and setEffectSuspendedAll_l() only. KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects; }; services/audioflinger/Threads.cpp +24 −35 Original line number Diff line number Diff line Loading @@ -991,13 +991,6 @@ void AudioFlinger::ThreadBase::PMDeathRecipient::binderDied(const wp<IBinder>& w ALOGW("power manager service died !!!"); } void AudioFlinger::ThreadBase::setEffectSuspended( const effect_uuid_t *type, bool suspend, audio_session_t sessionId) { Mutex::Autolock _l(mLock); setEffectSuspended_l(type, suspend, sessionId); } void AudioFlinger::ThreadBase::setEffectSuspended_l( const effect_uuid_t *type, bool suspend, audio_session_t sessionId) { Loading Loading @@ -1451,6 +1444,7 @@ status_t AudioFlinger::ThreadBase::addEffect_l(const sp<EffectModule>& effect) effect->setDevice(mInDevice); effect->setMode(mAudioFlinger->getMode()); effect->setAudioSource(mAudioSource); return NO_ERROR; } Loading Loading @@ -5956,6 +5950,7 @@ AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger, // mPipeMemory // mFastCaptureNBLogWriter , mFastTrackAvail(false) , mBtNrecSuspended(false) { snprintf(mThreadName, kThreadNameLength, "AudioIn_%X", id); mNBLogWriter = audioFlinger->newWriter_l(kLogSize, mThreadName); Loading Loading @@ -6721,12 +6716,6 @@ sp<AudioFlinger::RecordThread::RecordTrack> AudioFlinger::RecordThread::createRe } mTracks.add(track); // disable AEC and NS if the device is a BT SCO headset supporting those pre processings bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); setEffectSuspended_l(FX_IID_AEC, suspend, sessionId); setEffectSuspended_l(FX_IID_NS, suspend, sessionId); if ((*flags & AUDIO_INPUT_FLAG_FAST) && (tid != -1)) { pid_t callingPid = IPCThreadState::self()->getCallingPid(); // we don't have CAP_SYS_NICE, nor do we want to have it as it's too powerful, Loading Loading @@ -7100,6 +7089,26 @@ void AudioFlinger::RecordThread::ResamplerBufferProvider::releaseBuffer( buffer->frameCount = 0; } void AudioFlinger::RecordThread::checkBtNrec() { Mutex::Autolock _l(mLock); checkBtNrec_l(); } void AudioFlinger::RecordThread::checkBtNrec_l() { // disable AEC and NS if the device is a BT SCO headset supporting those // pre processings bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); if (mBtNrecSuspended.exchange(suspend) != suspend) { for (size_t i = 0; i < mEffectChains.size(); i++) { setEffectSuspended_l(FX_IID_AEC, suspend, mEffectChains[i]->sessionId()); setEffectSuspended_l(FX_IID_NS, suspend, mEffectChains[i]->sessionId()); } } } bool AudioFlinger::RecordThread::checkForNewParameter_l(const String8& keyValuePair, status_t& status) Loading Loading @@ -7172,17 +7181,7 @@ bool AudioFlinger::RecordThread::checkForNewParameter_l(const String8& keyValueP if (value != AUDIO_DEVICE_NONE) { mPrevInDevice = value; } // disable AEC and NS if the device is a BT SCO headset supporting those // pre processings if (mTracks.size() > 0) { bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); for (size_t i = 0; i < mTracks.size(); i++) { sp<RecordTrack> track = mTracks[i]; setEffectSuspended_l(FX_IID_AEC, suspend, track->sessionId()); setEffectSuspended_l(FX_IID_NS, suspend, track->sessionId()); } } checkBtNrec_l(); } } if (param.getInt(String8(AudioParameter::keyInputSource), value) == NO_ERROR && Loading Loading @@ -7415,17 +7414,7 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch mEffectChains[i]->setDevice_l(mInDevice); } // disable AEC and NS if the device is a BT SCO headset supporting those // pre processings if (mTracks.size() > 0) { bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); for (size_t i = 0; i < mTracks.size(); i++) { sp<RecordTrack> track = mTracks[i]; setEffectSuspended_l(FX_IID_AEC, suspend, track->sessionId()); setEffectSuspended_l(FX_IID_NS, suspend, track->sessionId()); } } checkBtNrec_l(); // store new source and send to effects if (mAudioSource != patch->sinks[0].ext.mix.usecase.source) { Loading Loading
services/audioflinger/AudioFlinger.cpp +7 −17 Original line number Diff line number Diff line Loading @@ -1193,26 +1193,11 @@ status_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8& String8 value; if (param.get(String8(AudioParameter::keyBtNrec), value) == NO_ERROR) { bool btNrecIsOff = (value == AudioParameter::valueOff); if (mBtNrecIsOff != btNrecIsOff) { if (mBtNrecIsOff.exchange(btNrecIsOff) != btNrecIsOff) { for (size_t i = 0; i < mRecordThreads.size(); i++) { sp<RecordThread> thread = mRecordThreads.valueAt(i); audio_devices_t device = thread->inDevice(); bool suspend = audio_is_bluetooth_sco_device(device) && btNrecIsOff; // collect all of the thread's session IDs KeyedVector<audio_session_t, bool> ids = thread->sessionIds(); // suspend effects associated with those session IDs for (size_t j = 0; j < ids.size(); ++j) { audio_session_t sessionId = ids.keyAt(j); thread->setEffectSuspended(FX_IID_AEC, suspend, sessionId); thread->setEffectSuspended(FX_IID_NS, suspend, sessionId); mRecordThreads.valueAt(i)->checkBtNrec(); } } mBtNrecIsOff = btNrecIsOff; } } String8 screenState; if (param.get(String8(AudioParameter::keyScreenState), screenState) == NO_ERROR) { Loading Loading @@ -3214,6 +3199,11 @@ void AudioFlinger::onNonOffloadableGlobalEffectEnable() status_t AudioFlinger::putOrphanEffectChain_l(const sp<AudioFlinger::EffectChain>& chain) { // clear possible suspended state before parking the chain so that it starts in default state // when attached to a new record thread chain->setEffectSuspended_l(FX_IID_AEC, false); chain->setEffectSuspended_l(FX_IID_NS, false); audio_session_t session = chain->sessionId(); ssize_t index = mOrphanEffectChains.indexOfKey(session); ALOGV("putOrphanEffectChain_l session %d index %zd", session, index); Loading
services/audioflinger/AudioFlinger.h +4 −3 Original line number Diff line number Diff line Loading @@ -350,12 +350,13 @@ public: sync_event_callback_t callBack, const wp<RefBase>& cookie); bool btNrecIsOff() const { return mBtNrecIsOff.load(); } private: audio_mode_t getMode() const { return mMode; } bool btNrecIsOff() const { return mBtNrecIsOff; } AudioFlinger() ANDROID_API; virtual ~AudioFlinger(); Loading Loading @@ -781,7 +782,7 @@ private: volatile atomic_uint_fast32_t mNextUniqueIds[AUDIO_UNIQUE_ID_USE_MAX]; audio_mode_t mMode; bool mBtNrecIsOff; std::atomic_bool mBtNrecIsOff; // protected by mLock Vector<AudioSessionRef*> mAudioSessionRefs; Loading
services/audioflinger/Effects.cpp +19 −3 Original line number Diff line number Diff line Loading @@ -21,10 +21,12 @@ #include "Configuration.h" #include <utils/Log.h> #include <system/audio_effects/effect_aec.h> #include <system/audio_effects/effect_ns.h> #include <system/audio_effects/effect_visualizer.h> #include <audio_utils/primitives.h> #include <media/audiohal/EffectHalInterface.h> #include <media/audiohal/EffectsFactoryHalInterface.h> #include <system/audio_effects/effect_visualizer.h> #include "AudioFlinger.h" #include "ServiceUtilities.h" Loading Loading @@ -1809,6 +1811,7 @@ status_t AudioFlinger::EffectChain::addEffect_ll(const sp<EffectModule>& effect) idx_insert); } effect->configure(); return NO_ERROR; } Loading Loading @@ -2030,6 +2033,7 @@ void AudioFlinger::EffectChain::setEffectSuspended_l( mSuspendedEffects.add(type->timeLow, desc); ALOGV("setEffectSuspended_l() add entry for %08x", type->timeLow); } if (desc->mRefCount++ == 0) { sp<EffectModule> effect = getEffectIfEnabled(type); if (effect != 0) { Loading @@ -2045,7 +2049,8 @@ void AudioFlinger::EffectChain::setEffectSuspended_l( desc = mSuspendedEffects.valueAt(index); if (desc->mRefCount <= 0) { ALOGW("setEffectSuspended_l() restore refcount should not be 0 %d", desc->mRefCount); desc->mRefCount = 1; desc->mRefCount = 0; return; } if (--desc->mRefCount == 0) { ALOGV("setEffectSuspended_l() remove entry for %08x", mSuspendedEffects.keyAt(index)); Loading Loading @@ -2123,6 +2128,17 @@ static const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6 const effect_uuid_t * const SL_IID_VOLUME = &SL_IID_VOLUME_; #endif //OPENSL_ES_H_ /* static */ bool AudioFlinger::EffectChain::isEffectEligibleForBtNrecSuspend(const effect_uuid_t *type) { // Only NS and AEC are suspended when BtNRec is off if ((memcmp(type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) || (memcmp(type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) { return true; } return false; } bool AudioFlinger::EffectChain::isEffectEligibleForSuspend(const effect_descriptor_t& desc) { // auxiliary effects and visualizer are never suspended on output mix Loading Loading @@ -2177,7 +2193,7 @@ void AudioFlinger::EffectChain::checkSuspendOnEffectEnabled(const sp<EffectModul ALOGV("checkSuspendOnEffectEnabled() enable suspending fx %08x", effect->desc().type.timeLow); sp<SuspendedEffectDesc> desc = mSuspendedEffects.valueAt(index); // if effect is requested to suspended but was not yet enabled, supend it now. // if effect is requested to suspended but was not yet enabled, suspend it now. if (desc->mEffect == 0) { desc->mEffect = effect; effect->setEnabled(false); Loading
services/audioflinger/Effects.h +6 −3 Original line number Diff line number Diff line Loading @@ -331,7 +331,8 @@ public: void setStrategy(uint32_t strategy) { mStrategy = strategy; } // suspend effect of the given type // suspend or restore effects of the specified type. The number of suspend requests is counted // and restore occurs once all suspend requests are cancelled. void setEffectSuspended_l(const effect_uuid_t *type, bool suspend); // suspend all eligible effects Loading Loading @@ -372,7 +373,7 @@ private: public: SuspendedEffectDesc() : mRefCount(0) {} int mRefCount; int mRefCount; // > 0 when suspended effect_uuid_t mType; wp<EffectModule> mEffect; }; Loading @@ -388,6 +389,8 @@ private: // types or implementations from the suspend/restore mechanism. bool isEffectEligibleForSuspend(const effect_descriptor_t& desc); static bool isEffectEligibleForBtNrecSuspend(const effect_uuid_t *type); void clearInputBuffer_l(const sp<ThreadBase>& thread); void setThread(const sp<ThreadBase>& thread); Loading @@ -414,6 +417,6 @@ private: // mSuspendedEffects lists all effects currently suspended in the chain. // Use effect type UUID timelow field as key. There is no real risk of identical // timeLow fields among effect type UUIDs. // Updated by updateSuspendedSessions_l() only. // Updated by setEffectSuspended_l() and setEffectSuspendedAll_l() only. KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects; };
services/audioflinger/Threads.cpp +24 −35 Original line number Diff line number Diff line Loading @@ -991,13 +991,6 @@ void AudioFlinger::ThreadBase::PMDeathRecipient::binderDied(const wp<IBinder>& w ALOGW("power manager service died !!!"); } void AudioFlinger::ThreadBase::setEffectSuspended( const effect_uuid_t *type, bool suspend, audio_session_t sessionId) { Mutex::Autolock _l(mLock); setEffectSuspended_l(type, suspend, sessionId); } void AudioFlinger::ThreadBase::setEffectSuspended_l( const effect_uuid_t *type, bool suspend, audio_session_t sessionId) { Loading Loading @@ -1451,6 +1444,7 @@ status_t AudioFlinger::ThreadBase::addEffect_l(const sp<EffectModule>& effect) effect->setDevice(mInDevice); effect->setMode(mAudioFlinger->getMode()); effect->setAudioSource(mAudioSource); return NO_ERROR; } Loading Loading @@ -5956,6 +5950,7 @@ AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger, // mPipeMemory // mFastCaptureNBLogWriter , mFastTrackAvail(false) , mBtNrecSuspended(false) { snprintf(mThreadName, kThreadNameLength, "AudioIn_%X", id); mNBLogWriter = audioFlinger->newWriter_l(kLogSize, mThreadName); Loading Loading @@ -6721,12 +6716,6 @@ sp<AudioFlinger::RecordThread::RecordTrack> AudioFlinger::RecordThread::createRe } mTracks.add(track); // disable AEC and NS if the device is a BT SCO headset supporting those pre processings bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); setEffectSuspended_l(FX_IID_AEC, suspend, sessionId); setEffectSuspended_l(FX_IID_NS, suspend, sessionId); if ((*flags & AUDIO_INPUT_FLAG_FAST) && (tid != -1)) { pid_t callingPid = IPCThreadState::self()->getCallingPid(); // we don't have CAP_SYS_NICE, nor do we want to have it as it's too powerful, Loading Loading @@ -7100,6 +7089,26 @@ void AudioFlinger::RecordThread::ResamplerBufferProvider::releaseBuffer( buffer->frameCount = 0; } void AudioFlinger::RecordThread::checkBtNrec() { Mutex::Autolock _l(mLock); checkBtNrec_l(); } void AudioFlinger::RecordThread::checkBtNrec_l() { // disable AEC and NS if the device is a BT SCO headset supporting those // pre processings bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); if (mBtNrecSuspended.exchange(suspend) != suspend) { for (size_t i = 0; i < mEffectChains.size(); i++) { setEffectSuspended_l(FX_IID_AEC, suspend, mEffectChains[i]->sessionId()); setEffectSuspended_l(FX_IID_NS, suspend, mEffectChains[i]->sessionId()); } } } bool AudioFlinger::RecordThread::checkForNewParameter_l(const String8& keyValuePair, status_t& status) Loading Loading @@ -7172,17 +7181,7 @@ bool AudioFlinger::RecordThread::checkForNewParameter_l(const String8& keyValueP if (value != AUDIO_DEVICE_NONE) { mPrevInDevice = value; } // disable AEC and NS if the device is a BT SCO headset supporting those // pre processings if (mTracks.size() > 0) { bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); for (size_t i = 0; i < mTracks.size(); i++) { sp<RecordTrack> track = mTracks[i]; setEffectSuspended_l(FX_IID_AEC, suspend, track->sessionId()); setEffectSuspended_l(FX_IID_NS, suspend, track->sessionId()); } } checkBtNrec_l(); } } if (param.getInt(String8(AudioParameter::keyInputSource), value) == NO_ERROR && Loading Loading @@ -7415,17 +7414,7 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch mEffectChains[i]->setDevice_l(mInDevice); } // disable AEC and NS if the device is a BT SCO headset supporting those // pre processings if (mTracks.size() > 0) { bool suspend = audio_is_bluetooth_sco_device(mInDevice) && mAudioFlinger->btNrecIsOff(); for (size_t i = 0; i < mTracks.size(); i++) { sp<RecordTrack> track = mTracks[i]; setEffectSuspended_l(FX_IID_AEC, suspend, track->sessionId()); setEffectSuspended_l(FX_IID_NS, suspend, track->sessionId()); } } checkBtNrec_l(); // store new source and send to effects if (mAudioSource != patch->sinks[0].ext.mix.usecase.source) { Loading