diff options
author | bryant_liu <bryant_liu@htc.com> | 2014-08-20 18:06:13 +0800 |
---|---|---|
committer | Dmitry Shmidt <dimitrysh@google.com> | 2014-08-28 17:45:55 -0700 |
commit | 890a5637b3e3eb197fd2c7f5deec816c7feb13fc (patch) | |
tree | 71a722cfba64b26c6f4d09b0e353986928d12d3d /services | |
parent | 8b250cb67d0cab6234c0e8e0e21342d03c1eca5d (diff) | |
download | frameworks_av-890a5637b3e3eb197fd2c7f5deec816c7feb13fc.zip frameworks_av-890a5637b3e3eb197fd2c7f5deec816c7feb13fc.tar.gz frameworks_av-890a5637b3e3eb197fd2c7f5deec816c7feb13fc.tar.bz2 |
frameworks: av: AudioPolicyEffect: Add refCount for each session
Audio framework stops and restarts AudioTracks on same audio session.
Sometimes the AudioTrack start() comes before a stop(). As effects
are linked to the session, they should only be created on the last
stop() related to that session.
Bug: 17201117
Change-Id: I19343e293d6b7b6b794fe05ebd0dd239ed3b075c
Diffstat (limited to 'services')
-rw-r--r-- | services/audiopolicy/AudioPolicyEffects.cpp | 36 | ||||
-rw-r--r-- | services/audiopolicy/AudioPolicyEffects.h | 4 |
2 files changed, 29 insertions, 11 deletions
diff --git a/services/audiopolicy/AudioPolicyEffects.cpp b/services/audiopolicy/AudioPolicyEffects.cpp index cc0e965..c45acd0 100644 --- a/services/audiopolicy/AudioPolicyEffects.cpp +++ b/services/audiopolicy/AudioPolicyEffects.cpp @@ -98,8 +98,12 @@ status_t AudioPolicyEffects::addInputEffects(audio_io_handle_t input, inputDesc = new EffectVector(audioSession); mInputs.add(input, inputDesc); } else { + // EffectVector is existing and we just need to increase ref count inputDesc = mInputs.valueAt(idx); } + inputDesc->mRefCount++; + + ALOGV("addInputEffects(): input: %d, refCount: %d", input, inputDesc->mRefCount); Vector <EffectDesc *> effects = mInputSources.valueAt(index)->mEffects; for (size_t i = 0; i < effects.size(); i++) { @@ -133,10 +137,14 @@ status_t AudioPolicyEffects::releaseInputEffects(audio_io_handle_t input) return status; } EffectVector *inputDesc = mInputs.valueAt(index); - setProcessorEnabled(inputDesc, false); - delete inputDesc; - mInputs.removeItemsAt(index); - ALOGV("releaseInputEffects(): all effects released"); + inputDesc->mRefCount--; + ALOGV("releaseInputEffects(): input: %d, refCount: %d", input, inputDesc->mRefCount); + if (inputDesc->mRefCount == 0) { + setProcessorEnabled(inputDesc, false); + delete inputDesc; + mInputs.removeItemsAt(index); + ALOGV("releaseInputEffects(): all effects released"); + } return status; } @@ -223,8 +231,12 @@ status_t AudioPolicyEffects::addOutputSessionEffects(audio_io_handle_t output, procDesc = new EffectVector(audioSession); mOutputSessions.add(audioSession, procDesc); } else { + // EffectVector is existing and we just need to increase ref count procDesc = mOutputSessions.valueAt(idx); } + procDesc->mRefCount++; + + ALOGV("addOutputSessionEffects(): session: %d, refCount: %d", audioSession, procDesc->mRefCount); Vector <EffectDesc *> effects = mOutputStreams.valueAt(index)->mEffects; for (size_t i = 0; i < effects.size(); i++) { @@ -262,12 +274,16 @@ status_t AudioPolicyEffects::releaseOutputSessionEffects(audio_io_handle_t outpu } EffectVector *procDesc = mOutputSessions.valueAt(index); - setProcessorEnabled(procDesc, false); - procDesc->mEffects.clear(); - delete procDesc; - mOutputSessions.removeItemsAt(index); - ALOGV("releaseOutputSessionEffects(): output processing released from session: %d", - audioSession); + procDesc->mRefCount--; + ALOGV("releaseOutputSessionEffects(): session: %d, refCount: %d", audioSession, procDesc->mRefCount); + if (procDesc->mRefCount == 0) { + setProcessorEnabled(procDesc, false); + procDesc->mEffects.clear(); + delete procDesc; + mOutputSessions.removeItemsAt(index); + ALOGV("releaseOutputSessionEffects(): output processing released from session: %d", + audioSession); + } return status; } diff --git a/services/audiopolicy/AudioPolicyEffects.h b/services/audiopolicy/AudioPolicyEffects.h index 351cb1a..dbe0d0e 100644 --- a/services/audiopolicy/AudioPolicyEffects.h +++ b/services/audiopolicy/AudioPolicyEffects.h @@ -131,9 +131,11 @@ private: // class to store voctor of AudioEffects class EffectVector { public: - EffectVector(int session) : mSessionId(session) {} + EffectVector(int session) : mSessionId(session), mRefCount(0) {} /*virtual*/ ~EffectVector() {} const int mSessionId; + // AudioPolicyManager keeps mLock, no need for lock on reference count here + int mRefCount; Vector< sp<AudioEffect> >mEffects; }; |