Bug 1208371 - Add DOMMediaStream::GetTrackById/GetOwnedTrackById. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:23 +0800
changeset 342099 2c66000b3727a25f0405abf8f339cfbe19c3f782
parent 342098 9507814f939cb50936a54d63cb6d3989d2d62bd0
child 342100 476f3891ead7c5cc065427d3ce0eefdb24eb3e12
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersjib
bugs1208371
milestone47.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
@@ -579,16 +579,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.
    */