Bug 1259236 - throw NotSupportedError on pc.addTrack of track in constructed stream. r=bwc a=ritu
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 24 Mar 2016 12:45:22 -0400
changeset 326106 648ee3ba5ceda38cf6d5f279360a978ddc03d283
parent 326105 0d955f56f084c40fd8e6f59e5ffe8efddd12ce40
child 326107 1e4b52390f6d5bc905a0c06207d9a06772e159e4
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc, ritu
bugs1259236
milestone47.0
Bug 1259236 - throw NotSupportedError on pc.addTrack of track in constructed stream. r=bwc a=ritu MozReview-Commit-ID: LBP9CybRmrI
dom/media/PeerConnection.js
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/test/FakeMediaStreams.h
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1048,17 +1048,23 @@ RTCPeerConnection.prototype = {
     }
     this._checkClosed();
     this._senders.forEach(sender => {
       if (sender.track == track) {
         throw new this._win.DOMException("already added.",
                                          "InvalidParameterError");
       }
     });
-    this._impl.addTrack(track, stream);
+    try {
+      this._impl.addTrack(track, stream);
+    } catch (e if (e.result == Cr.NS_ERROR_NOT_IMPLEMENTED)) {
+      throw new this._win.DOMException(
+          "track in constructed stream not yet supported (see Bug 1259236).",
+          "NotSupportedError");
+    }
     let sender = this._win.RTCRtpSender._create(this._win,
                                                 new RTCRtpSender(this, track,
                                                                  stream));
     this._senders.push(sender);
     return sender;
   },
 
   removeTrack: function(sender) {
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -2203,16 +2203,20 @@ PeerConnectionImpl::AddTrack(MediaStream
 nsresult
 PeerConnectionImpl::AddTrack(MediaStreamTrack& aTrack,
                              DOMMediaStream& aMediaStream)
 {
   if (!aMediaStream.HasTrack(aTrack)) {
     CSFLogError(logTag, "%s: Track is not in stream", __FUNCTION__);
     return NS_ERROR_FAILURE;
   }
+  if (!aMediaStream.OwnsTrack(aTrack)) {
+    CSFLogError(logTag, "%s: Track is not in owned stream (Bug 1259236)", __FUNCTION__);
+    return NS_ERROR_NOT_IMPLEMENTED;
+  }
   uint32_t num = mMedia->LocalStreamsLength();
 
   std::string streamId = PeerConnectionImpl::GetStreamId(aMediaStream);
   std::string trackId = PeerConnectionImpl::GetTrackId(aTrack);
   nsresult res = mMedia->AddTrack(&aMediaStream, streamId, trackId);
   if (NS_FAILED(res)) {
     return res;
   }
--- a/media/webrtc/signaling/test/FakeMediaStreams.h
+++ b/media/webrtc/signaling/test/FakeMediaStreams.h
@@ -409,16 +409,22 @@ public:
 
   bool
   HasTrack(const Fake_MediaStreamTrack& aTrack) const
   {
     return ((mHintContents & HINT_CONTENTS_AUDIO) && aTrack.AsAudioStreamTrack()) ||
            ((mHintContents & HINT_CONTENTS_VIDEO) && aTrack.AsVideoStreamTrack());
   }
 
+  bool
+  OwnsTrack(const Fake_MediaStreamTrack& aTrack) const
+  {
+    return HasTrack(aTrack);
+  }
+
   void SetTrackEnabled(mozilla::TrackID aTrackID, bool aEnabled) {}
 
   Fake_MediaStreamTrack*
   CreateOwnDOMTrack(mozilla::TrackID aTrackID, mozilla::MediaSegment::Type aType)
   {
     switch(aType) {
       case mozilla::MediaSegment::AUDIO: {
         return mAudioTrack;