From 577b207b435895247c36b26a6f82f972ea33b0ef Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Tue, 24 May 2016 13:26:25 +0200 Subject: [PATCH] Bug 1274221 - Make FindOwnedDOMTrack look for (optionally) unique tracks. r=ctai MozReview-Commit-ID: 1y8YuwJWIS5 --HG-- extra : rebase_source : eb5c6a4ddd2a3d2395870d1f94751e06991fe46f extra : intermediate-source : 795bcfd6223de68845075d0987cb8f3268893918 extra : source : c2154e0e122ac3981d1c5c7e748633a64111cbf7 --- dom/media/DOMMediaStream.cpp | 17 ++++++++++------- dom/media/DOMMediaStream.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/dom/media/DOMMediaStream.cpp b/dom/media/DOMMediaStream.cpp index f16feeb6ffd4..5af32d52be5f 100644 --- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -142,7 +142,7 @@ public: } MediaStreamTrack* track = - mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID); + mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID, aTrackID); if (!track) { // Track had not been created on main thread before, create it now. NS_WARN_IF_FALSE(!mStream->mTracks.IsEmpty(), @@ -165,7 +165,8 @@ public: } } - void DoNotifyTrackEnded(MediaStream* aInputStream, TrackID aInputTrackID) + void DoNotifyTrackEnded(MediaStream* aInputStream, TrackID aInputTrackID, + TrackID aTrackID) { MOZ_ASSERT(NS_IsMainThread()); @@ -174,7 +175,7 @@ public: } RefPtr track = - mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID); + mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID, aTrackID); NS_ASSERTION(track, "Owned MediaStreamTracks must be known by the DOMMediaStream"); if (track) { LOG(LogLevel::Debug, ("DOMMediaStream %p MediaStreamTrack %p ended at the source. Marking it ended.", @@ -197,9 +198,9 @@ public: aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } else if (aTrackEvents & TRACK_EVENT_ENDED) { nsCOMPtr runnable = - NewRunnableMethod( + NewRunnableMethod( this, &OwnedStreamListener::DoNotifyTrackEnded, - aInputStream, aInputTrackID); + aInputStream, aInputTrackID, aID); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } } @@ -1064,14 +1065,16 @@ FindTrackPortAmongTracks(const MediaStreamTrack& aTrack, MediaStreamTrack* DOMMediaStream::FindOwnedDOMTrack(MediaStream* aInputStream, - TrackID aInputTrackID) const + TrackID aInputTrackID, + TrackID aTrackID) const { MOZ_RELEASE_ASSERT(mOwnedStream); for (const RefPtr& info : mOwnedTracks) { if (info->GetInputPort() && info->GetInputPort()->GetSource() == aInputStream && - info->GetTrack()->mInputTrackID == aInputTrackID) { + info->GetTrack()->mInputTrackID == aInputTrackID && + (aTrackID == TRACK_ANY || info->GetTrack()->mTrackID == aTrackID)) { // This track is owned externally but in our playback stream. return info->GetTrack(); } diff --git a/dom/media/DOMMediaStream.h b/dom/media/DOMMediaStream.h index 7f7b5aef3eb7..cd64d488234a 100644 --- a/dom/media/DOMMediaStream.h +++ b/dom/media/DOMMediaStream.h @@ -393,10 +393,17 @@ public: /** * Returns the corresponding MediaStreamTrack if it's in our mOwnedStream. - * aInputTrackID should match the track's TrackID in its input stream. + * aInputTrackID should match the track's TrackID in its input stream, + * and aTrackID the TrackID in mOwnedStream. + * + * When aTrackID is not supplied or set to TRACK_ANY, we return the first + * MediaStreamTrack that matches the given input track. Note that there may + * be multiple MediaStreamTracks matching the same input track, but that they + * in that case all share the same MediaStreamTrackSource. */ MediaStreamTrack* FindOwnedDOMTrack(MediaStream* aInputStream, - TrackID aInputTrackID) const; + TrackID aInputTrackID, + TrackID aTrackID = TRACK_ANY) const; /** * Returns the TrackPort connecting aTrack's input stream to mOwnedStream,