Bug 1208371 - Add DOMMediaStream::GetTrackById/GetOwnedTrackById. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:23 +0800
changeset 348417 e261fd0b3b9cab53ca92098b7f54a63b1864311d
parent 348416 06d9ea133491f1cb07dcef8afbf66c8b1cb4504f
child 348418 63151a0935383b3b3db4e7273bb4eb25e3420e82
push id14828
push userpehrsons@gmail.com
push dateThu, 07 Apr 2016 12:57:27 +0000
reviewersjib
bugs1208371
milestone48.0a1
Bug 1208371 - Add DOMMediaStream::GetTrackById/GetOwnedTrackById. r=jib MozReview-Commit-ID: 9qwW8CsB1eJ
dom/media/DOMMediaStream.cpp
dom/media/DOMMediaStream.h
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -586,16 +586,42 @@ DOMMediaStream::RemoveTrack(MediaStreamT
   // end.
   toRemove->BlockTrackId(aTrack.GetTrackID());
 
   DebugOnly<bool> removed = mTracks.RemoveElement(toRemove);
   MOZ_ASSERT(removed);
   LOG(LogLevel::Debug, ("DOMMediaStream %p Removed track %p", this, &aTrack));
 }
 
+MediaStreamTrack*
+DOMMediaStream::GetTrackById(const nsString& aId)
+{
+  for (const RefPtr<TrackPort>& info : mTracks) {
+    nsString id;
+    info->GetTrack()->GetId(id);
+    if (id == aId) {
+      return info->GetTrack();
+    }
+  }
+  return nullptr;
+}
+
+MediaStreamTrack*
+DOMMediaStream::GetOwnedTrackById(const nsString& aId)
+{
+  for (const RefPtr<TrackPort>& info : mOwnedTracks) {
+    nsString id;
+    info->GetTrack()->GetId(id);
+    if (id == aId) {
+      return info->GetTrack();
+    }
+  }
+  return nullptr;
+}
+
 bool
 DOMMediaStream::HasTrack(const MediaStreamTrack& aTrack) const
 {
   return !!FindPlaybackTrackPort(aTrack);
 }
 
 bool
 DOMMediaStream::OwnsTrack(const MediaStreamTrack& aTrack) const
--- a/dom/media/DOMMediaStream.h
+++ b/dom/media/DOMMediaStream.h
@@ -357,16 +357,20 @@ public:
   void GetAudioTracks(nsTArray<RefPtr<AudioStreamTrack> >& aTracks) const;
   void GetVideoTracks(nsTArray<RefPtr<VideoStreamTrack> >& aTracks) const;
   void GetTracks(nsTArray<RefPtr<MediaStreamTrack> >& aTracks) const;
   void AddTrack(MediaStreamTrack& aTrack);
   void RemoveTrack(MediaStreamTrack& aTrack);
 
   // NON-WebIDL
 
+  MediaStreamTrack* GetTrackById(const nsString& aId);
+
+  MediaStreamTrack* GetOwnedTrackById(const nsString& aId);
+
   /**
    * Returns true if this DOMMediaStream has aTrack in its mPlaybackStream.
    */
   bool HasTrack(const MediaStreamTrack& aTrack) const;
 
   /**
    * Returns true if this DOMMediaStream owns aTrack.
    */