Bug 1208371 - Let MediaStreamTracks know their TrackID at the source. r?roc draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 05 Nov 2015 15:42:22 +0800
changeset 306642 04e4136978cd87274327cbb79a142aca199b3aaf
parent 306641 39f30ac191a51ae57aa2b99c437f3c8bcb1e9ef4
child 306643 766aa4f77b8d5cb067237f4ae694576ffad4ad81
push id7183
push userpehrsons@gmail.com
push dateThu, 05 Nov 2015 07:42:40 +0000
reviewersroc
bugs1208371
milestone45.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()`).
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,
+    new dom::VideoStreamTrack(this, aTrackID, aTrackID,
                               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,
+                   TrackID aInputTrackID,
                    MediaStreamTrackSource* aSource)
-    : MediaStreamTrack(aStream, aTrackID, aSource) {}
+    : MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource) {}
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   virtual AudioStreamTrack* AsAudioStreamTrack() override { return this; }
 
   // WebIDL
   virtual void GetKind(nsAString& aKind) override { aKind.AssignLiteral("audio"); }
 };
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -785,20 +785,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, aSource);
+    track = new AudioStreamTrack(this, aTrackID, aTrackID, aSource);
     break;
   case MediaSegment::VIDEO:
-    track = new VideoStreamTrack(this, aTrackID, aSource);
+    track = new VideoStreamTrack(this, aTrackID, aTrackID, 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 =
@@ -833,17 +833,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
@@ -15,18 +15,20 @@
 
 static PRLogModuleInfo* gMediaStreamTrackLog;
 #define LOG(type, msg) MOZ_LOG(gMediaStreamTrackLog, type, msg)
 
 namespace mozilla {
 namespace dom {
 
 MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
+                                   TrackID aInputTrackID,
                                    MediaStreamTrackSource* aSource)
-  : mOwningStream(aStream), mTrackID(aTrackID), mSource(aSource),
+  : mOwningStream(aStream), mTrackID(aTrackID),
+    mInputTrackID(aInputTrackID), mSource(aSource),
     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
@@ -130,16 +130,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,
+                   TrackID aInputTrackID,
                    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;
@@ -149,16 +150,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.Truncate(); }
   bool Enabled() { return mEnabled; }
@@ -181,16 +188,17 @@ public:
   // need to surface this to content.
   void AssignId(const nsAString& aID) { mID = aID; }
 
 protected:
   virtual ~MediaStreamTrack();
 
   RefPtr<DOMMediaStream> mOwningStream;
   TrackID mTrackID;
+  TrackID mInputTrackID;
   const RefPtr<MediaStreamTrackSource> mSource;
   RefPtr<MediaStreamTrack> mOriginalTrack;
   nsString mID;
   bool mEnded;
   bool mEnabled;
   const bool mRemote;
   bool mStopped;
 };
--- a/dom/media/VideoStreamTrack.h
+++ b/dom/media/VideoStreamTrack.h
@@ -10,18 +10,19 @@
 #include "DOMMediaStream.h"
 
 namespace mozilla {
 namespace dom {
 
 class VideoStreamTrack : public MediaStreamTrack {
 public:
   VideoStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
+                   TrackID aInputTrackID,
                    MediaStreamTrackSource* aSource)
-    : MediaStreamTrack(aStream, aTrackID, aSource) {}
+    : MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource) {}
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   virtual VideoStreamTrack* AsVideoStreamTrack() override { return this; }
 
   // WebIDL
   virtual void GetKind(nsAString& aKind) override { aKind.AssignLiteral("video"); }
 };