Bug 1208371 - Fix DOMMediaStream::OwnsTrack. r?roc draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:25 +0800
changeset 342116 67770eae8a882d170a56d2906b8a3b8907a1ca1e
parent 342115 1d84aea4dfc5986fe319a00e8b6dfdde58495151
child 342117 9acdab4e4bb1c643b5e2f9dc7f18251e0e253c28
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersroc
bugs1208371
milestone47.0a1
Bug 1208371 - Fix DOMMediaStream::OwnsTrack. r?roc MozReview-Commit-ID: 3uPqOYJZq2k
dom/media/DOMMediaStream.cpp
dom/media/DOMMediaStream.h
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -621,17 +621,17 @@ bool
 DOMMediaStream::HasTrack(const MediaStreamTrack& aTrack) const
 {
   return !!FindPlaybackTrackPort(aTrack);
 }
 
 bool
 DOMMediaStream::OwnsTrack(const MediaStreamTrack& aTrack) const
 {
-  return (aTrack.GetStream() == this) && HasTrack(aTrack);
+  return !!FindOwnedTrackPort(aTrack);
 }
 
 bool
 DOMMediaStream::IsFinished()
 {
   return !mPlaybackStream || mPlaybackStream->IsFinished();
 }
 
@@ -883,16 +883,28 @@ DOMMediaStream::FindOwnedDOMTrack(MediaS
         info->GetTrack()->GetInputTrackID() == aInputTrackID) {
       // This track is owned externally but in our playback stream.
       return info->GetTrack();
     }
   }
   return nullptr;
 }
 
+DOMMediaStream::TrackPort*
+DOMMediaStream::FindOwnedTrackPort(const MediaStreamTrack& aTrack) const
+{
+  for (const RefPtr<TrackPort>& info : mOwnedTracks) {
+    if (info->GetTrack() == &aTrack) {
+      return info;
+    }
+  }
+  return nullptr;
+}
+
+
 MediaStreamTrack*
 DOMMediaStream::FindPlaybackDOMTrack(MediaStream* aInputStream, TrackID aInputTrackID) const
 {
   MOZ_RELEASE_ASSERT(mPlaybackStream);
 
   for (const RefPtr<TrackPort>& info : mTracks) {
     if (info->GetInputPort() == mPlaybackPort &&
         aInputStream == mOwnedStream &&
--- a/dom/media/DOMMediaStream.h
+++ b/dom/media/DOMMediaStream.h
@@ -381,16 +381,22 @@ public:
   /**
    * Returns the corresponding MediaStreamTrack if it's in our mOwnedStream.
    * aInputTrackID should match the track's TrackID in its input stream.
    */
   MediaStreamTrack* FindOwnedDOMTrack(MediaStream* aOwningStream,
                                       TrackID aInputTrackID) const;
 
   /**
+   * Returns the TrackPort connecting aTrack's input stream to mOwnedStream,
+   * or nullptr if aTrack is not owned by this DOMMediaStream.
+   */
+  TrackPort* FindOwnedTrackPort(const MediaStreamTrack& aTrack) const;
+
+  /**
    * Returns the corresponding MediaStreamTrack if it's in our mPlaybackStream.
    * aInputTrackID should match the track's TrackID in its owned stream.
    */
   MediaStreamTrack* FindPlaybackDOMTrack(MediaStream* aOwningStream,
                                          TrackID aInputTrackID) const;
 
   /**
    * Returns the TrackPort connecting mOwnedStream to mPlaybackStream for aTrack.