Bug 1344556 - Part 4: Fix bug where direction on negotiated extmaps was recorded backwards. r?drno draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 08 Mar 2017 14:13:44 -0600
changeset 551895 a0c504bafd8bfe32f16f08054a276c1d0e2936be
parent 551894 e2026e2633b725a3a1f11933254692055d999747
child 551896 192421c4036d3508ded0ab6deb1391635e95fc4e
push id51186
push userbcampen@mozilla.com
push dateMon, 27 Mar 2017 16:29:37 +0000
reviewersdrno
bugs1344556
milestone55.0a1
Bug 1344556 - Part 4: Fix bug where direction on negotiated extmaps was recorded backwards. r?drno MozReview-Commit-ID: BFQ2WcNs4OH
media/webrtc/signaling/src/sdp/SdpHelper.cpp
--- a/media/webrtc/signaling/src/sdp/SdpHelper.cpp
+++ b/media/webrtc/signaling/src/sdp/SdpHelper.cpp
@@ -742,45 +742,38 @@ SdpHelper::AddCommonExtmaps(
 {
   if (!remoteMsection.GetAttributeList().HasAttribute(
         SdpAttribute::kExtmapAttribute)) {
     return;
   }
 
   UniquePtr<SdpExtmapAttributeList> localExtmap(new SdpExtmapAttributeList);
   auto& theirExtmap = remoteMsection.GetAttributeList().GetExtmap().mExtmaps;
-  for (auto i = theirExtmap.begin(); i != theirExtmap.end(); ++i) {
-    for (auto j = localExtensions.begin(); j != localExtensions.end(); ++j) {
-      // verify we have a valid combination of directions.  For kInactive
-      // we'll just not add the response
-      if (i->extensionname == j->extensionname &&
-          (((i->direction == SdpDirectionAttribute::Direction::kSendrecv ||
-             i->direction == SdpDirectionAttribute::Direction::kSendonly) &&
-            (j->direction == SdpDirectionAttribute::Direction::kSendrecv ||
-             j->direction == SdpDirectionAttribute::Direction::kRecvonly)) ||
+  for (const auto& theirExt : theirExtmap) {
+    for (const auto& ourExt : localExtensions) {
+      if (theirExt.extensionname != ourExt.extensionname) {
+        continue;
+      }
+
+      auto negotiatedExt = theirExt;
 
-           ((i->direction == SdpDirectionAttribute::Direction::kSendrecv ||
-             i->direction == SdpDirectionAttribute::Direction::kRecvonly) &&
-            (j->direction == SdpDirectionAttribute::Direction::kSendrecv ||
-             j->direction == SdpDirectionAttribute::Direction::kSendonly)))) {
-        auto k = *i; // we need to modify it
-        if (j->direction == SdpDirectionAttribute::Direction::kSendonly) {
-          k.direction = SdpDirectionAttribute::Direction::kRecvonly;
-        } else if (j->direction == SdpDirectionAttribute::Direction::kRecvonly) {
-          k.direction = SdpDirectionAttribute::Direction::kSendonly;
-        }
-        localExtmap->mExtmaps.push_back(k);
+      negotiatedExt.direction = ~negotiatedExt.direction & ourExt.direction;
+      if (negotiatedExt.direction ==
+            SdpDirectionAttribute::Direction::kInactive) {
+        continue;
+      }
 
-        // RFC 5285 says that ids >= 4096 can be used by the offerer to
-        // force the answerer to pick, otherwise the value in the offer is
-        // used.
-        if (localExtmap->mExtmaps.back().entry >= 4096) {
-          localExtmap->mExtmaps.back().entry = j->entry;
-        }
+      // RFC 5285 says that ids >= 4096 can be used by the offerer to
+      // force the answerer to pick, otherwise the value in the offer is
+      // used.
+      if (negotiatedExt.entry >= 4096) {
+        negotiatedExt.entry = ourExt.entry;
       }
+
+      localExtmap->mExtmaps.push_back(negotiatedExt);
     }
   }
 
   if (!localExtmap->mExtmaps.empty()) {
     localMsection->GetAttributeList().SetAttribute(localExtmap.release());
   }
 }