Merge "Isolate references to outputTracks/mOutputTracks"
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index fe068af..608fc71 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2074,17 +2074,7 @@
 
             }
 
-if (mType == DUPLICATING) {
-#if 0   // see earlier FIXME
-            // Now that this is a field instead of local variable,
-            // clear it so it is empty the first time through the loop,
-            // and later an assignment could combine the clear with the loop below
-            outputTracks.clear();
-#endif
-            for (size_t i = 0; i < mOutputTracks.size(); i++) {
-                outputTracks.add(mOutputTracks[i]);
-            }
-}
+            saveOutputTracks();
 
             // put audio hardware into standby after short delay
             if (CC_UNLIKELY((!mActiveTracks.size() && systemTime() > standbyTime) ||
@@ -2101,9 +2091,7 @@
                     // we're about to wait, flush the binder command buffer
                     IPCThreadState::self()->flushCommands();
 
-if (mType == DUPLICATING) {
-                    outputTracks.clear();
-}
+                    clearOutputTracks();
 
                     if (exitPending()) break;
 
@@ -2212,9 +2200,10 @@
 if (mType == DIRECT) {
         activeTrack.clear();
 }
-if (mType == DUPLICATING) {
-        outputTracks.clear();
-}
+        // FIXME I don't understand the need for this here;
+        //       it was in the original code but maybe the
+        //       assignment in saveOutputTracks() makes this unnecessary?
+        clearOutputTracks();
 
         // Effect chains will be actually deleted here if they were removed from
         // mEffectChains list during mixing or effects processing
@@ -3168,6 +3157,16 @@
     }
 }
 
+void AudioFlinger::DuplicatingThread::saveOutputTracks()
+{
+    outputTracks = mOutputTracks;
+}
+
+void AudioFlinger::DuplicatingThread::clearOutputTracks()
+{
+    outputTracks.clear();
+}
+
 void AudioFlinger::DuplicatingThread::addOutputTrack(MixerThread *thread)
 {
     Mutex::Autolock _l(mLock);
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 8ca4f89..518a99c 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -920,6 +920,10 @@
         // Code snippets that are temporarily lifted up out of threadLoop() until the merge
                     void        checkSilentMode_l();
 
+        // Non-trivial for DUPLICATING only
+        virtual     void        saveOutputTracks() { }
+        virtual     void        clearOutputTracks() { }
+
     private:
 
         friend class AudioFlinger;
@@ -972,9 +976,7 @@
         // activeTrack was local to the while !exitingPending loop
         sp<Track>                       activeTrack;
         // DUPLICATING only
-        SortedVector < sp<OutputTrack> >  outputTracks;
         uint32_t                        writeFrames;
-        SortedVector < sp<OutputTrack> >  mOutputTracks;
     };
 
     class MixerThread : public PlaybackThread {
@@ -1070,9 +1072,13 @@
 
         // called from threadLoop, addOutputTrack, removeOutputTrack
         virtual     void        updateWaitTime_l();
+        virtual     void        saveOutputTracks();
+        virtual     void        clearOutputTracks();
     private:
 
                     uint32_t    mWaitTimeMs;
+        SortedVector < sp<OutputTrack> >  outputTracks;
+        SortedVector < sp<OutputTrack> >  mOutputTracks;
     };
 
               PlaybackThread *checkPlaybackThread_l(audio_io_handle_t output) const;