Bug 1193495 - Part 1: Test case. r=mt
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 12 Aug 2015 10:00:28 -0500
changeset 258945 2d2b71f2c970ca20bb2ea65f0c919b347db6864e
parent 258944 332b56e301156802f269ded2a557f50b762b3ef2
child 258946 8a585b9dd1db7df42fe01374a7631dbd82b52122
push id64086
push userryanvm@gmail.com
push dateSun, 23 Aug 2015 22:17:19 +0000
treeherdermozilla-inbound@8a585b9dd1db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmt
bugs1193495
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1193495 - Part 1: Test case. r=mt
media/webrtc/signaling/test/jsep_session_unittest.cpp
--- a/media/webrtc/signaling/test/jsep_session_unittest.cpp
+++ b/media/webrtc/signaling/test/jsep_session_unittest.cpp
@@ -378,16 +378,28 @@ protected:
     for (auto* codec : session.Codecs()) {
       if (codec->mName == codecName) {
         codec->mDefaultPt = payloadType;
       }
     }
   }
 
   void
+  SetCodecEnabled(JsepSession& session,
+                  const std::string& codecName,
+                  bool enabled)
+  {
+    for (auto* codec : session.Codecs()) {
+      if (codec->mName == codecName) {
+        codec->mEnabled = enabled;
+      }
+    }
+  }
+
+  void
   EnsureNegotiationFailure(SdpMediaSection::MediaType type,
                            const std::string& codecName)
   {
     for (auto i = mSessionOff.Codecs().begin(); i != mSessionOff.Codecs().end();
          ++i) {
       auto* codec = *i;
       if (codec->mType == type && codec->mName != codecName) {
         codec->mEnabled = false;
@@ -2869,27 +2881,34 @@ static void ReplaceAll(const std::string
                        const std::string& with,
                        std::string* in)
 {
   while (in->find(toReplace) != std::string::npos) {
     Replace(toReplace, with, in);
   }
 }
 
+typedef enum
+{
+  kSending,
+  kReceiving
+} Direction;
+
 static void
 GetCodec(JsepSession& session,
          size_t pairIndex,
-         bool sending,
+         Direction direction,
          size_t codecIndex,
          const JsepCodecDescription** codecOut)
 {
   *codecOut = nullptr;
   ASSERT_LT(pairIndex, session.GetNegotiatedTrackPairs().size());
   JsepTrackPair pair(session.GetNegotiatedTrackPairs().front());
-  RefPtr<JsepTrack> track(sending ? pair.mSending : pair.mReceiving);
+  RefPtr<JsepTrack> track(
+      (direction == kSending) ? pair.mSending : pair.mReceiving);
   ASSERT_TRUE(track);
   ASSERT_TRUE(track->GetNegotiatedDetails());
   ASSERT_LT(codecIndex, track->GetNegotiatedDetails()->GetCodecCount());
   ASSERT_EQ(NS_OK,
             track->GetNegotiatedDetails()->GetCodec(codecIndex, codecOut));
 }
 
 static void
@@ -2919,40 +2938,40 @@ TEST_F(JsepSessionTest, TestH264Negotiat
 
   SetRemoteOffer(offer, CHECK_SUCCESS);
   std::string answer(CreateAnswer());
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   const JsepCodecDescription* offererSendCodec;
-  GetCodec(mSessionOff, 0, true, 0, &offererSendCodec);
+  GetCodec(mSessionOff, 0, kSending, 0, &offererSendCodec);
   ASSERT_TRUE(offererSendCodec);
   ASSERT_EQ("H264", offererSendCodec->mName);
   const JsepVideoCodecDescription* offererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(offererSendCodec));
   ASSERT_EQ((uint32_t)0x42e00d, offererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* offererRecvCodec;
-  GetCodec(mSessionOff, 0, false, 0, &offererRecvCodec);
+  GetCodec(mSessionOff, 0, kReceiving, 0, &offererRecvCodec);
   ASSERT_EQ("H264", offererRecvCodec->mName);
   const JsepVideoCodecDescription* offererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(offererRecvCodec));
   ASSERT_EQ((uint32_t)0x42e00b, offererVideoRecvCodec->mProfileLevelId);
 
   const JsepCodecDescription* answererSendCodec;
-  GetCodec(mSessionAns, 0, true, 0, &answererSendCodec);
+  GetCodec(mSessionAns, 0, kSending, 0, &answererSendCodec);
   ASSERT_TRUE(answererSendCodec);
   ASSERT_EQ("H264", answererSendCodec->mName);
   const JsepVideoCodecDescription* answererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(answererSendCodec));
   ASSERT_EQ((uint32_t)0x42e00b, answererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* answererRecvCodec;
-  GetCodec(mSessionAns, 0, false, 0, &answererRecvCodec);
+  GetCodec(mSessionAns, 0, kReceiving, 0, &answererRecvCodec);
   ASSERT_EQ("H264", answererRecvCodec->mName);
   const JsepVideoCodecDescription* answererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(answererRecvCodec));
   ASSERT_EQ((uint32_t)0x42e00d, answererVideoRecvCodec->mProfileLevelId);
 }
 
 TEST_F(JsepSessionTest, TestH264NegotiationFails)
 {
@@ -2992,17 +3011,17 @@ TEST_F(JsepSessionTest, TestH264Negotiat
 
   SetRemoteOffer(offer, CHECK_SUCCESS);
   std::string answer(CreateAnswer());
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   const JsepCodecDescription* answererSendCodec;
-  GetCodec(mSessionAns, 0, true, 0, &answererSendCodec);
+  GetCodec(mSessionAns, 0, kSending, 0, &answererSendCodec);
   ASSERT_TRUE(answererSendCodec);
   ASSERT_EQ("H264", answererSendCodec->mName);
   const JsepVideoCodecDescription* answererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(answererSendCodec));
   ASSERT_EQ((uint32_t)0x420010, answererVideoSendCodec->mProfileLevelId);
 }
 
 TEST_F(JsepSessionTest, TestH264NegotiationOffererNoFmtp)
@@ -3020,25 +3039,25 @@ TEST_F(JsepSessionTest, TestH264Negotiat
 
   SetRemoteOffer(offer, CHECK_SUCCESS);
   std::string answer(CreateAnswer());
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   const JsepCodecDescription* answererSendCodec;
-  GetCodec(mSessionAns, 0, true, 0, &answererSendCodec);
+  GetCodec(mSessionAns, 0, kSending, 0, &answererSendCodec);
   ASSERT_TRUE(answererSendCodec);
   ASSERT_EQ("H264", answererSendCodec->mName);
   const JsepVideoCodecDescription* answererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(answererSendCodec));
   ASSERT_EQ((uint32_t)0x420010, answererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* answererRecvCodec;
-  GetCodec(mSessionAns, 0, false, 0, &answererRecvCodec);
+  GetCodec(mSessionAns, 0, kReceiving, 0, &answererRecvCodec);
   ASSERT_EQ("H264", answererRecvCodec->mName);
   const JsepVideoCodecDescription* answererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(answererRecvCodec));
   ASSERT_EQ((uint32_t)0x420010, answererVideoRecvCodec->mProfileLevelId);
 }
 
 TEST_F(JsepSessionTest, TestH264LevelAsymmetryDisallowedByOffererWithLowLevel)
 {
@@ -3060,25 +3079,25 @@ TEST_F(JsepSessionTest, TestH264LevelAsy
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   // Offerer doesn't know about the shenanigans we've pulled here, so will
   // behave normally, and we test the normal behavior elsewhere.
 
   const JsepCodecDescription* answererSendCodec;
-  GetCodec(mSessionAns, 0, true, 0, &answererSendCodec);
+  GetCodec(mSessionAns, 0, kSending, 0, &answererSendCodec);
   ASSERT_TRUE(answererSendCodec);
   ASSERT_EQ("H264", answererSendCodec->mName);
   const JsepVideoCodecDescription* answererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(answererSendCodec));
   ASSERT_EQ((uint32_t)0x42e00b, answererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* answererRecvCodec;
-  GetCodec(mSessionAns, 0, false, 0, &answererRecvCodec);
+  GetCodec(mSessionAns, 0, kReceiving, 0, &answererRecvCodec);
   ASSERT_EQ("H264", answererRecvCodec->mName);
   const JsepVideoCodecDescription* answererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(answererRecvCodec));
   ASSERT_EQ((uint32_t)0x42e00b, answererVideoRecvCodec->mProfileLevelId);
 }
 
 TEST_F(JsepSessionTest, TestH264LevelAsymmetryDisallowedByOffererWithHighLevel)
 {
@@ -3100,25 +3119,25 @@ TEST_F(JsepSessionTest, TestH264LevelAsy
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   // Offerer doesn't know about the shenanigans we've pulled here, so will
   // behave normally, and we test the normal behavior elsewhere.
 
   const JsepCodecDescription* answererSendCodec;
-  GetCodec(mSessionAns, 0, true, 0, &answererSendCodec);
+  GetCodec(mSessionAns, 0, kSending, 0, &answererSendCodec);
   ASSERT_TRUE(answererSendCodec);
   ASSERT_EQ("H264", answererSendCodec->mName);
   const JsepVideoCodecDescription* answererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(answererSendCodec));
   ASSERT_EQ((uint32_t)0x42e00b, answererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* answererRecvCodec;
-  GetCodec(mSessionAns, 0, false, 0, &answererRecvCodec);
+  GetCodec(mSessionAns, 0, kReceiving, 0, &answererRecvCodec);
   ASSERT_EQ("H264", answererRecvCodec->mName);
   const JsepVideoCodecDescription* answererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(answererRecvCodec));
   ASSERT_EQ((uint32_t)0x42e00b, answererVideoRecvCodec->mProfileLevelId);
 }
 
 TEST_F(JsepSessionTest, TestH264LevelAsymmetryDisallowedByAnswererWithLowLevel)
 {
@@ -3136,25 +3155,25 @@ TEST_F(JsepSessionTest, TestH264LevelAsy
   Replace("level-asymmetry-allowed=1",
           "level-asymmetry-allowed=0",
           &answer);
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   const JsepCodecDescription* offererSendCodec;
-  GetCodec(mSessionOff, 0, true, 0, &offererSendCodec);
+  GetCodec(mSessionOff, 0, kSending, 0, &offererSendCodec);
   ASSERT_TRUE(offererSendCodec);
   ASSERT_EQ("H264", offererSendCodec->mName);
   const JsepVideoCodecDescription* offererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(offererSendCodec));
   ASSERT_EQ((uint32_t)0x42e00b, offererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* offererRecvCodec;
-  GetCodec(mSessionOff, 0, false, 0, &offererRecvCodec);
+  GetCodec(mSessionOff, 0, kReceiving, 0, &offererRecvCodec);
   ASSERT_EQ("H264", offererRecvCodec->mName);
   const JsepVideoCodecDescription* offererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(offererRecvCodec));
   ASSERT_EQ((uint32_t)0x42e00b, offererVideoRecvCodec->mProfileLevelId);
 
   // Answerer doesn't know we've pulled these shenanigans, it should act as if
   // it did not set level-asymmetry-required, and we already check that
   // elsewhere
@@ -3176,25 +3195,25 @@ TEST_F(JsepSessionTest, TestH264LevelAsy
   Replace("level-asymmetry-allowed=1",
           "level-asymmetry-allowed=0",
           &answer);
 
   SetRemoteAnswer(answer, CHECK_SUCCESS);
   SetLocalAnswer(answer, CHECK_SUCCESS);
 
   const JsepCodecDescription* offererSendCodec;
-  GetCodec(mSessionOff, 0, true, 0, &offererSendCodec);
+  GetCodec(mSessionOff, 0, kSending, 0, &offererSendCodec);
   ASSERT_TRUE(offererSendCodec);
   ASSERT_EQ("H264", offererSendCodec->mName);
   const JsepVideoCodecDescription* offererVideoSendCodec(
       static_cast<const JsepVideoCodecDescription*>(offererSendCodec));
   ASSERT_EQ((uint32_t)0x42e00b, offererVideoSendCodec->mProfileLevelId);
 
   const JsepCodecDescription* offererRecvCodec;
-  GetCodec(mSessionOff, 0, false, 0, &offererRecvCodec);
+  GetCodec(mSessionOff, 0, kReceiving, 0, &offererRecvCodec);
   ASSERT_EQ("H264", offererRecvCodec->mName);
   const JsepVideoCodecDescription* offererVideoRecvCodec(
       static_cast<const JsepVideoCodecDescription*>(offererRecvCodec));
   ASSERT_EQ((uint32_t)0x42e00b, offererVideoRecvCodec->mProfileLevelId);
 
   // Answerer doesn't know we've pulled these shenanigans, it should act as if
   // it did not set level-asymmetry-required, and we already check that
   // elsewhere
@@ -3509,41 +3528,72 @@ TEST_F(JsepSessionTest, StronglyPreferre
 
   types.push_back(SdpMediaSection::kVideo);
   AddTracks(mSessionOff, "video");
   AddTracks(mSessionAns, "video");
 
   OfferAnswer();
 
   const JsepCodecDescription* codec;
-  GetCodec(mSessionAns, 0, true, 0, &codec); // sending
+  GetCodec(mSessionAns, 0, kSending, 0, &codec);
   ASSERT_TRUE(codec);
   ASSERT_EQ("H264", codec->mName);
-  GetCodec(mSessionAns, 0, false, 0, &codec); // receiving
+  GetCodec(mSessionAns, 0, kReceiving, 0, &codec);
   ASSERT_TRUE(codec);
   ASSERT_EQ("H264", codec->mName);
 }
 
 TEST_F(JsepSessionTest, LowDynamicPayloadType)
 {
   SetPayloadTypeNumber(mSessionOff, "opus", "12");
   types.push_back(SdpMediaSection::kAudio);
   AddTracks(mSessionOff, "audio");
   AddTracks(mSessionAns, "audio");
 
   OfferAnswer();
   const JsepCodecDescription* codec;
-  GetCodec(mSessionAns, 0, true, 0, &codec); // sending
+  GetCodec(mSessionAns, 0, kSending, 0, &codec);
+  ASSERT_TRUE(codec);
+  ASSERT_EQ("opus", codec->mName);
+  ASSERT_EQ("12", codec->mDefaultPt);
+  GetCodec(mSessionAns, 0, kReceiving, 0, &codec);
   ASSERT_TRUE(codec);
   ASSERT_EQ("opus", codec->mName);
   ASSERT_EQ("12", codec->mDefaultPt);
-  GetCodec(mSessionAns, 0, false, 0, &codec); // receiving
+}
+
+TEST_F(JsepSessionTest, PayloadTypeClash)
+{
+  // Disable this so mSessionOff doesn't have a duplicate
+  SetCodecEnabled(mSessionOff, "PCMU", false);
+  SetPayloadTypeNumber(mSessionOff, "opus", "0");
+  SetPayloadTypeNumber(mSessionAns, "PCMU", "0");
+  types.push_back(SdpMediaSection::kAudio);
+  AddTracks(mSessionOff, "audio");
+  AddTracks(mSessionAns, "audio");
+
+  OfferAnswer();
+  const JsepCodecDescription* codec;
+  GetCodec(mSessionAns, 0, kSending, 0, &codec);
   ASSERT_TRUE(codec);
   ASSERT_EQ("opus", codec->mName);
-  ASSERT_EQ("12", codec->mDefaultPt);
+  ASSERT_EQ("0", codec->mDefaultPt);
+  GetCodec(mSessionAns, 0, kReceiving, 0, &codec);
+  ASSERT_TRUE(codec);
+  ASSERT_EQ("opus", codec->mName);
+  ASSERT_EQ("0", codec->mDefaultPt);
+
+  // Now, make sure that mSessionAns does not put a=rtpmap:0 PCMU in a reoffer,
+  // since pt 0 is taken for opus (the answerer still supports PCMU, and will
+  // reoffer it, but it should choose a new payload type for it)
+  JsepOfferOptions options;
+  std::string reoffer;
+  nsresult rv = mSessionAns.CreateOffer(options, &reoffer);
+  ASSERT_EQ(NS_OK, rv);
+  ASSERT_EQ(std::string::npos, reoffer.find("a=rtpmap:0 PCMU")) << reoffer;
 }
 
 TEST_P(JsepSessionTest, TestGlareRollback)
 {
   AddTracks(mSessionOff);
   AddTracks(mSessionAns);
   JsepOfferOptions options;