Bug 1495569: Create answers with a=mid even if the offer did not have a=mid r=mjf,jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 17 Oct 2018 18:50:45 +0000
changeset 490146 19b1ad6ceade3ce4ce42e9b4dd793f03e5e81be9
parent 490145 8eab3320b8c5fdda47ceb1c45e59628c7439f76d
child 490147 6191777b6e40eab703c643088e6ad265cf960d32
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersmid, mid, mjf, jib
bugs1495569
milestone64.0a1
Bug 1495569: Create answers with a=mid even if the offer did not have a=mid r=mjf,jib Bug 1495569 - Part 0: web-platform-test that verifies handling of offer without mid. Bug 1495569 - Part 1: Ensure that answers are created with the transceiver's mid when the offer did not have a mid. Differential Revision: https://phabricator.services.mozilla.com/D8853
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
testing/web-platform/tests/webrtc/RTCRtpTransceiver.https.html
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -647,16 +647,25 @@ JsepSessionImpl::CreateAnswerMsection(co
 
   if (mSdpHelper.MsectionIsDisabled(remoteMsection) ||
       // JS might have stopped this
       transceiver.IsStopped()) {
     SdpHelper::DisableMsection(sdp, &msection);
     return NS_OK;
   }
 
+  MOZ_ASSERT(transceiver.IsAssociated());
+  if (msection.GetAttributeList().GetMid().empty()) {
+    msection.GetAttributeList().SetAttribute(
+        new SdpStringAttribute(SdpAttribute::kMidAttribute,
+          transceiver.GetMid()));
+  }
+
+  MOZ_ASSERT(transceiver.GetMid() == msection.GetAttributeList().GetMid());
+
   SdpSetupAttribute::Role role;
   rv = DetermineAnswererSetupRole(remoteMsection, &role);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = AddTransportAttributes(&msection, role);
   NS_ENSURE_SUCCESS(rv, rv);
 
   transceiver.mSendTrack.AddToAnswer(remoteMsection, mSsrcGenerator, &msection);
--- a/testing/web-platform/tests/webrtc/RTCRtpTransceiver.https.html
+++ b/testing/web-platform/tests/webrtc/RTCRtpTransceiver.https.html
@@ -501,16 +501,50 @@
       } else {
         assert_true(false, 'addTransceiver("foo") throws a TypeError');
       }
     }
 
     hasProps(pc.getTransceivers(), []);
   };
 
+  const checkNoMidOffer = async t => {
+    const pc1 = new RTCPeerConnection();
+    const pc2 = new RTCPeerConnection();
+    t.add_cleanup(() => pc1.close());
+    t.add_cleanup(() => pc2.close());
+
+    const stream = await navigator.mediaDevices.getUserMedia({audio: true});
+    t.add_cleanup(() => stopTracks(stream));
+    const track = stream.getAudioTracks()[0];
+    pc1.addTrack(track, stream);
+
+    const offer = await pc1.createOffer();
+    await pc1.setLocalDescription(offer);
+
+    // Remove mid attr
+    offer.sdp = offer.sdp.replace("a=mid:", "a=unknownattr:");
+    await pc2.setRemoteDescription(offer);
+
+    hasPropsAndUniqueMids(pc2.getTransceivers(),
+      [
+        {
+          receiver: {track: {kind: "audio"}},
+          sender: {track: null},
+          direction: "recvonly",
+          currentDirection: null,
+          stopped: false
+        }
+      ]);
+
+    const answer = await pc2.createAnswer();
+    await pc2.setLocalDescription(answer);
+    await pc1.setRemoteDescription(answer);
+  };
+
   const checkAddTransceiverNoTrackDoesntPair = async t => {
     const pc1 = new RTCPeerConnection();
     const pc2 = new RTCPeerConnection();
     t.add_cleanup(() => pc1.close());
     t.add_cleanup(() => pc2.close());
 
     pc1.addTransceiver("audio");
     pc2.addTransceiver("audio");
@@ -2207,16 +2241,17 @@ const tests = [
     return checkAddTransceiverWithOfferToReceive(t, ["video"]);
   },
   function checkAddTransceiverWithOfferToReceiveBoth(t) {
     return checkAddTransceiverWithOfferToReceive(t, ["audio", "video"]);
   },
   checkAddTransceiverWithSetRemoteOfferSending,
   checkAddTransceiverWithSetRemoteOfferNoSend,
   checkAddTransceiverBadKind,
+  checkNoMidOffer,
   checkSetDirection,
   checkCurrentDirection,
   checkSendrecvWithNoSendTrack,
   checkSendrecvWithTracklessStream,
   checkAddTransceiverNoTrackDoesntPair,
   checkAddTransceiverWithTrackDoesntPair,
   checkAddTransceiverThenReplaceTrackDoesntPair,
   checkAddTransceiverThenAddTrackPairs,