Bug 1208371 - Let MediaStreamTracks know their TrackID at the source. r=roc
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:22 +0800
changeset 292069 f65172114712e7d1831ea234340126f9d29134a1
parent 292068 f7580ab5826a4c17eef0ec8b632b36d8ba4e04fa
child 292070 f738214b89b34ea17ca198c727f11d8b4d61c41f
push id18587
push userkwierso@gmail.com
push dateThu, 07 Apr 2016 20:50:13 +0000
treeherderfx-team@dfd17abadcdf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1208371
milestone48.0a1
Bug 1208371 - Let MediaStreamTracks know their TrackID at the source. r=roc For original tracks, the input TrackID is the same as in its owned stream. For cloned tracks, the input TrackID comes from the original track, since no guarantees about TrackIDs in a cloned DOMMediaStream's owned stream can be given (imagine e.g., `new MediaStream([trackID1FromStreamX, trackID1FromStreamY]).clone()`). MozReview-Commit-ID: 9iulggncBZ7
dom/camera/DOMCameraControl.cpp
dom/media/AudioStreamTrack.h
dom/media/DOMMediaStream.cpp
dom/media/MediaStreamTrack.cpp
dom/media/MediaStreamTrack.h
dom/media/VideoStreamTrack.h
--- a/dom/camera/DOMCameraControl.cpp
+++ b/dom/camera/DOMCameraControl.cpp
@@ -524,17 +524,17 @@ nsDOMCameraControl::GetCameraStream() co
   return mInput;
 }
 
 void
 nsDOMCameraControl::TrackCreated(TrackID aTrackID) {
   // This track is not connected through a port.
   MediaInputPort* inputPort = nullptr;
   dom::VideoStreamTrack* track =
-    new dom::VideoStreamTrack(this, aTrackID, nsString(),
+    new dom::VideoStreamTrack(this, aTrackID, aTrackID, nsString(),
                               new BasicUnstoppableTrackSource());
   RefPtr<TrackPort> port =
     new TrackPort(inputPort, track,
                   TrackPort::InputPortOwnership::OWNED);
   mTracks.AppendElement(port.forget());
   NotifyTrackAdded(track);
 }
 
--- a/dom/media/AudioStreamTrack.h
+++ b/dom/media/AudioStreamTrack.h
@@ -10,18 +10,19 @@
 #include "DOMMediaStream.h"
 
 namespace mozilla {
 namespace dom {
 
 class AudioStreamTrack : public MediaStreamTrack {
 public:
   AudioStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
-                   const nsString& aLabel, MediaStreamTrackSource* aSource)
-    : MediaStreamTrack(aStream, aTrackID, aLabel, aSource) {}
+                   TrackID aInputTrackID, const nsString& aLabel,
+                   MediaStreamTrackSource* aSource)
+    : MediaStreamTrack(aStream, aTrackID, aInputTrackID, aLabel, aSource) {}
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   AudioStreamTrack* AsAudioStreamTrack() override { return this; }
 
   // WebIDL
   void GetKind(nsAString& aKind) override { aKind.AssignLiteral("audio"); }
 };
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -808,20 +808,20 @@ DOMMediaStream::CreateOwnDOMTrack(TrackI
   MOZ_RELEASE_ASSERT(mInputStream);
   MOZ_RELEASE_ASSERT(mOwnedStream);
 
   MOZ_ASSERT(FindOwnedDOMTrack(GetOwnedStream(), aTrackID) == nullptr);
 
   MediaStreamTrack* track;
   switch (aType) {
   case MediaSegment::AUDIO:
-    track = new AudioStreamTrack(this, aTrackID, aLabel, aSource);
+    track = new AudioStreamTrack(this, aTrackID, aTrackID, aLabel, aSource);
     break;
   case MediaSegment::VIDEO:
-    track = new VideoStreamTrack(this, aTrackID, aLabel, aSource);
+    track = new VideoStreamTrack(this, aTrackID, aTrackID, aLabel, aSource);
     break;
   default:
     MOZ_CRASH("Unhandled track type");
   }
 
   LOG(LogLevel::Debug, ("DOMMediaStream %p Created new track %p with ID %u", this, track, aTrackID));
 
   RefPtr<TrackPort> ownedTrackPort =
@@ -856,17 +856,17 @@ DOMMediaStream::FindOwnedDOMTrack(MediaS
 MediaStreamTrack*
 DOMMediaStream::FindPlaybackDOMTrack(MediaStream* aInputStream, TrackID aInputTrackID) const
 {
   MOZ_RELEASE_ASSERT(mPlaybackStream);
 
   for (const RefPtr<TrackPort>& info : mTracks) {
     if (info->GetInputPort() == mPlaybackPort &&
         aInputStream == mOwnedStream &&
-        aInputTrackID == info->GetTrack()->GetTrackID()) {
+        info->GetTrack()->GetInputTrackID() == aInputTrackID) {
       // This track is in our owned and playback streams.
       return info->GetTrack();
     }
     if (info->GetInputPort() &&
         info->GetInputPort()->GetSource() == aInputStream &&
         info->GetSourceTrackId() == aInputTrackID) {
       // This track is owned externally but in our playback stream.
       MOZ_ASSERT(aInputTrackID != TRACK_NONE);
--- a/dom/media/MediaStreamTrack.cpp
+++ b/dom/media/MediaStreamTrack.cpp
@@ -22,19 +22,20 @@ namespace dom {
 NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamTrackSource)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamTrackSource)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamTrackSource)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 NS_IMPL_CYCLE_COLLECTION_0(MediaStreamTrackSource)
 
 MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
-                                   const nsString& aLabel,
+                                   TrackID aInputTrackID, const nsString& aLabel,
                                    MediaStreamTrackSource* aSource)
-  : mOwningStream(aStream), mTrackID(aTrackID), mLabel(aLabel), mSource(aSource),
+  : mOwningStream(aStream), mTrackID(aTrackID),
+    mInputTrackID(aInputTrackID), mSource(aSource), mLabel(aLabel),
     mEnded(false), mEnabled(true), mRemote(aSource->IsRemote()), mStopped(false)
 {
 
   if (!gMediaStreamTrackLog) {
     gMediaStreamTrackLog = PR_NewLogModule("MediaStreamTrack");
   }
 
   MOZ_RELEASE_ASSERT(mSource);
--- a/dom/media/MediaStreamTrack.h
+++ b/dom/media/MediaStreamTrack.h
@@ -133,17 +133,17 @@ protected:
  */
 class MediaStreamTrack : public DOMEventTargetHelper {
 public:
   /**
    * aTrackID is the MediaStreamGraph track ID for the track in the
    * MediaStream owned by aStream.
    */
   MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
-                   const nsString& aLabel,
+                   TrackID aInputTrackID, const nsString& aLabel,
                    MediaStreamTrackSource* aSource);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrack,
                                            DOMEventTargetHelper)
 
   DOMMediaStream* GetParentObject() const { return mOwningStream; }
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override = 0;
@@ -153,16 +153,22 @@ public:
    */
   DOMMediaStream* GetStream() const { return mOwningStream; }
 
   /**
    * Returns the TrackID this stream has in its owning DOMMediaStream's Owned
    * stream.
    */
   TrackID GetTrackID() const { return mTrackID; }
+
+  /**
+   * Returns the TrackID this MediaStreamTrack has in its input MSG-MediaStream.
+   */
+  TrackID GetInputTrackID() const { return mInputTrackID; }
+
   virtual AudioStreamTrack* AsAudioStreamTrack() { return nullptr; }
   virtual VideoStreamTrack* AsVideoStreamTrack() { return nullptr; }
 
   // WebIDL
   virtual void GetKind(nsAString& aKind) = 0;
   void GetId(nsAString& aID) const;
   void GetLabel(nsAString& aLabel) { aLabel.Assign(mLabel); }
   bool Enabled() { return mEnabled; }
--- a/dom/media/VideoStreamTrack.h
+++ b/dom/media/VideoStreamTrack.h
@@ -10,19 +10,19 @@
 #include "DOMMediaStream.h"
 
 namespace mozilla {
 namespace dom {
 
 class VideoStreamTrack : public MediaStreamTrack {
 public:
   VideoStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
-                   const nsString& aLabel,
+                   TrackID aInputTrackID, const nsString& aLabel,
                    MediaStreamTrackSource* aSource)
-    : MediaStreamTrack(aStream, aTrackID, aLabel, aSource) {}
+    : MediaStreamTrack(aStream, aTrackID, aInputTrackID, aLabel, aSource) {}
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   VideoStreamTrack* AsVideoStreamTrack() override { return this; }
 
   // WebIDL
   void GetKind(nsAString& aKind) override { aKind.AssignLiteral("video"); }
 };