diff options
Diffstat (limited to 'services/audioflinger')
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 8 | ||||
-rw-r--r-- | services/audioflinger/Threads.cpp | 76 | ||||
-rw-r--r-- | services/audioflinger/Threads.h | 34 | ||||
-rw-r--r-- | services/audioflinger/TrackBase.h | 11 |
4 files changed, 50 insertions, 79 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index f7dbbc057a..735885cc3c 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -224,6 +224,14 @@ AudioFlinger::~AudioFlinger() // closeOutput_nonvirtual() will remove specified entry from mPlaybackThreads closeOutput_nonvirtual(mPlaybackThreads.keyAt(0)); } + while (!mMmapThreads.isEmpty()) { + const audio_io_handle_t io = mMmapThreads.keyAt(0); + if (mMmapThreads.valueAt(0)->isOutput()) { + closeOutput_nonvirtual(io); // removes entry from mMmapThreads + } else { + closeInput_nonvirtual(io); // removes entry from mMmapThreads + } + } for (size_t i = 0; i < mAudioHwDevs.size(); i++) { // no mHardwareLock needed, as there are no other references to this diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp index 49f74a2660..3ecb37d405 100644 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -2788,28 +2788,6 @@ status_t AudioFlinger::PlaybackThread::getRenderPosition(uint32_t *halFrames, ui } } -// hasAudioSession_l() must be called with ThreadBase::mLock held -uint32_t AudioFlinger::PlaybackThread::hasAudioSession_l(audio_session_t sessionId) const -{ - uint32_t result = 0; - if (getEffectChain_l(sessionId) != 0) { - result = EFFECT_SESSION; - } - - for (size_t i = 0; i < mTracks.size(); ++i) { - sp<Track> track = mTracks[i]; - if (sessionId == track->sessionId() && !track->isInvalid()) { - result |= TRACK_SESSION; - if (track->isFastTrack()) { - result |= FAST_SESSION; - } - break; - } - } - - return result; -} - uint32_t AudioFlinger::PlaybackThread::getStrategyForSession_l(audio_session_t sessionId) { // session AUDIO_SESSION_OUTPUT_MIX is placed in same strategy as MUSIC stream so that @@ -8219,27 +8197,6 @@ uint32_t AudioFlinger::RecordThread::getInputFramesLost() return 0; } -// hasAudioSession_l() must be called with ThreadBase::mLock held -uint32_t AudioFlinger::RecordThread::hasAudioSession_l(audio_session_t sessionId) const -{ - uint32_t result = 0; - if (getEffectChain_l(sessionId) != 0) { - result = EFFECT_SESSION; - } - - for (size_t i = 0; i < mTracks.size(); ++i) { - if (sessionId == mTracks[i]->sessionId()) { - result |= TRACK_SESSION; - if (mTracks[i]->isFastTrack()) { - result |= FAST_SESSION; - } - break; - } - } - - return result; -} - KeyedVector<audio_session_t, bool> AudioFlinger::RecordThread::sessionIds() const { KeyedVector<audio_session_t, bool> ids; @@ -8747,9 +8704,11 @@ bool AudioFlinger::MmapThread::threadLoop() while (!exitPending()) { - Mutex::Autolock _l(mLock); Vector< sp<EffectChain> > effectChains; + { // under Thread lock + Mutex::Autolock _l(mLock); + if (mSignalPending) { // A signal was raised while we were unlocked mSignalPending = false; @@ -8784,10 +8743,13 @@ bool AudioFlinger::MmapThread::threadLoop() updateMetadata_l(); lockEffectChains_l(effectChains); + } // release Thread lock + for (size_t i = 0; i < effectChains.size(); i ++) { - effectChains[i]->process_l(); + effectChains[i]->process_l(); // Thread is not locked, but effect chain is locked } - // enable changes in effect chain + + // enable changes in effect chain, including moving to another thread. unlockEffectChains(effectChains); // Effect chains will be actually deleted here if they were removed from // mEffectChains list during mixing or effects processing @@ -9048,28 +9010,6 @@ size_t AudioFlinger::MmapThread::removeEffectChain_l(const sp<EffectChain>& chai return mEffectChains.size(); } -// hasAudioSession_l() must be called with ThreadBase::mLock held -uint32_t AudioFlinger::MmapThread::hasAudioSession_l(audio_session_t sessionId) const -{ - uint32_t result = 0; - if (getEffectChain_l(sessionId) != 0) { - result = EFFECT_SESSION; - } - - for (size_t i = 0; i < mActiveTracks.size(); i++) { - sp<MmapTrack> track = mActiveTracks[i]; - if (sessionId == track->sessionId()) { - result |= TRACK_SESSION; - if (track->isFastTrack()) { - result |= FAST_SESSION; - } - break; - } - } - - return result; -} - void AudioFlinger::MmapThread::threadLoop_standby() { mHalStream->standby(); diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h index 97aa9f044a..47e580bf8c 100644 --- a/services/audioflinger/Threads.h +++ b/services/audioflinger/Threads.h @@ -356,6 +356,27 @@ public: return hasAudioSession_l(sessionId); } + template <typename T> + uint32_t hasAudioSession_l(audio_session_t sessionId, const T& tracks) const { + uint32_t result = 0; + if (getEffectChain_l(sessionId) != 0) { + result = EFFECT_SESSION; + } + for (size_t i = 0; i < tracks.size(); ++i) { + const sp<TrackBase>& track = tracks[i]; + if (sessionId == track->sessionId() + && !track->isInvalid() // not yet removed from tracks. + && !track->isTerminated()) { + result |= TRACK_SESSION; + if (track->isFastTrack()) { + result |= FAST_SESSION; // caution, only represents first track. + } + break; + } + } + return result; + } + // the value returned by default implementation is not important as the // strategy is only meaningful for PlaybackThread which implements this method virtual uint32_t getStrategyForSession_l(audio_session_t sessionId __unused) @@ -810,7 +831,9 @@ public: virtual status_t addEffectChain_l(const sp<EffectChain>& chain); virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); - virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const; + uint32_t hasAudioSession_l(audio_session_t sessionId) const override { + return ThreadBase::hasAudioSession_l(sessionId, mTracks); + } virtual uint32_t getStrategyForSession_l(audio_session_t sessionId); @@ -1550,7 +1573,9 @@ public: virtual status_t addEffectChain_l(const sp<EffectChain>& chain); virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); - virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const; + uint32_t hasAudioSession_l(audio_session_t sessionId) const override { + return ThreadBase::hasAudioSession_l(sessionId, mTracks); + } // Return the set of unique session IDs across all tracks. // The keys are the session IDs, and the associated values are meaningless. @@ -1725,7 +1750,10 @@ class MmapThread : public ThreadBase virtual status_t checkEffectCompatibility_l(const effect_descriptor_t *desc, audio_session_t sessionId); - virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const; + uint32_t hasAudioSession_l(audio_session_t sessionId) const override { + // Note: using mActiveTracks as no mTracks here. + return ThreadBase::hasAudioSession_l(sessionId, mActiveTracks); + } virtual status_t setSyncEvent(const sp<SyncEvent>& event); virtual bool isValidSyncEvent(const sp<SyncEvent>& event) const; diff --git a/services/audioflinger/TrackBase.h b/services/audioflinger/TrackBase.h index e23173fd0a..4402d99314 100644 --- a/services/audioflinger/TrackBase.h +++ b/services/audioflinger/TrackBase.h @@ -94,6 +94,9 @@ public: virtual void invalidate() { mIsInvalid = true; } bool isInvalid() const { return mIsInvalid; } + void terminate() { mTerminated = true; } + bool isTerminated() const { return mTerminated; } + audio_attributes_t attributes() const { return mAttr; } #ifdef TEE_SINK @@ -228,14 +231,6 @@ protected: return mState == STOPPING_2; } - bool isTerminated() const { - return mTerminated; - } - - void terminate() { - mTerminated = true; - } - // Upper case characters are final states. // Lower case characters are transitory. const char *getTrackStateString() const { |