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
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 @@
     // 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;
     };