Bug 1057955: Adjust TrackUnion TrackID mapping to be 1:1 whenever possible with source tracks r=jesup
☠☠ backed out by e9c509681fed ☠ ☠
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 27 Aug 2014 01:03:49 -0400
changeset 223527 a7e4ef74441d2531e3be0003a655f364ccc92737
parent 223526 66a14139b597ba9b92c286803b400b3812050cf9
child 223528 ef1c321a4a3212a9147c248ea4eef698baadb77c
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1057955
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1057955: Adjust TrackUnion TrackID mapping to be 1:1 whenever possible with source tracks r=jesup
content/media/TrackUnionStream.h
--- a/content/media/TrackUnionStream.h
+++ b/content/media/TrackUnionStream.h
@@ -21,18 +21,18 @@ namespace mozilla {
  * See MediaStreamGraph::CreateTrackUnionStream.
  * This file is only included by MediaStreamGraph.cpp so it's OK to put the
  * entire implementation in this header file.
  */
 class TrackUnionStream : public ProcessedMediaStream {
 public:
   TrackUnionStream(DOMMediaStream* aWrapper) :
     ProcessedMediaStream(aWrapper),
-    mFilterCallback(nullptr),
-    mMaxTrackID(0) {}
+    mFilterCallback(nullptr)
+  {}
 
   virtual void RemoveInput(MediaInputPort* aPort) MOZ_OVERRIDE
   {
     for (int32_t i = mTrackMap.Length() - 1; i >= 0; --i) {
       if (mTrackMap[i].mInputPort == aPort) {
         EndTrack(i);
         mTrackMap.RemoveElementAt(i);
       }
@@ -158,20 +158,31 @@ protected:
     TrackID mInputTrackID;
     TrackID mOutputTrackID;
     nsAutoPtr<MediaSegment> mSegment;
   };
 
   uint32_t AddTrack(MediaInputPort* aPort, StreamBuffer::Track* aTrack,
                     GraphTime aFrom)
   {
-    // Use the ID of the source track if we can, otherwise allocate a new
-    // unique ID
-    TrackID id = std::max(mMaxTrackID + 1, aTrack->GetID());
-    mMaxTrackID = id;
+    // Use the ID of the source track if it's not already assigned to a track,
+    // otherwise allocate a new unique ID.
+    TrackID id = aTrack->GetID();
+    TrackID maxTrackID = 0;
+    bool found = false;
+    for (uint32_t i = 0; i < mTrackMap.Length(); ++i) {
+      TrackID outID = mTrackMap[i].mOutputTrackID;
+      if (outID == id) {
+        found = true;
+      }
+      maxTrackID = std::max(maxTrackID, outID);
+    }
+    if (found) {
+      id = maxTrackID + 1;
+    }
 
     TrackRate rate = aTrack->GetRate();
     // Round up the track start time so the track, if anything, starts a
     // little later than the true time. This means we'll have enough
     // samples in our input stream to go just beyond the destination time.
     TrackTicks outputStart = TimeToTicksRoundUp(rate, GraphTimeToStreamTime(aFrom));
 
     nsAutoPtr<MediaSegment> segment;
@@ -338,14 +349,13 @@ protected:
                                     outputTrack->GetRate(), startTicks, 0,
                                     *segment);
       }
       outputTrack->GetSegment()->AppendFrom(segment);
     }
   }
 
   nsTArray<TrackMapEntry> mTrackMap;
-  TrackID mMaxTrackID;
 };
 
 }
 
 #endif /* MOZILLA_MEDIASTREAMGRAPH_H_ */