Add offer_extmap_allow_mixed to RTCConfiguration

Bug: webrtc:9986
Change-Id: I346e03a46f35c7d59d3ae769842e3aeec9d2d50d
Reviewed-on: https://webrtc-review.googlesource.com/c/110501
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25596}
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index 80c3091..044a480 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -597,6 +597,14 @@
     // settings set in PeerConnectionFactory (which is deprecated).
     absl::optional<CryptoOptions> crypto_options;
 
+    // Configure if we should include the SDP attribute extmap-allow-mixed in
+    // our offer. Although we currently do support this, it's not included in
+    // our offer by default due to a previous bug that caused the SDP parser to
+    // abort parsing if this attribute was present. This is fixed in Chrome 71.
+    // TODO(webrtc:9985): Change default to true once sufficient time has
+    // passed.
+    bool offer_extmap_allow_mixed = false;
+
     //
     // Don't forget to update operator== if adding something.
     //
diff --git a/pc/mediasession.cc b/pc/mediasession.cc
index b9afca0..7239af8 100644
--- a/pc/mediasession.cc
+++ b/pc/mediasession.cc
@@ -1378,6 +1378,8 @@
     offer->set_msid_signaling(cricket::kMsidSignalingSsrcAttribute);
   }
 
+  offer->set_extmap_allow_mixed(session_options.offer_extmap_allow_mixed);
+
   return offer.release();
 }
 
diff --git a/pc/mediasession.h b/pc/mediasession.h
index b1df1db..5904605 100644
--- a/pc/mediasession.h
+++ b/pc/mediasession.h
@@ -94,6 +94,7 @@
   bool rtcp_mux_enabled = true;
   bool bundle_enabled = false;
   bool is_unified_plan = false;
+  bool offer_extmap_allow_mixed = false;
   std::string rtcp_cname = kDefaultRtcpCname;
   webrtc::CryptoOptions crypto_options;
   // List of media description options in the same order that the media
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index 54ef677..3fa5ca5 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -737,6 +737,7 @@
     bool use_media_transport;
     bool use_media_transport_for_data_channels;
     absl::optional<CryptoOptions> crypto_options;
+    bool offer_extmap_allow_mixed;
   };
   static_assert(sizeof(stuff_being_tested_for_equality) == sizeof(*this),
                 "Did you add something to RTCConfiguration and forget to "
@@ -788,7 +789,8 @@
          use_media_transport == o.use_media_transport &&
          use_media_transport_for_data_channels ==
              o.use_media_transport_for_data_channels &&
-         crypto_options == o.crypto_options;
+         crypto_options == o.crypto_options &&
+         offer_extmap_allow_mixed == o.offer_extmap_allow_mixed;
 }
 
 bool PeerConnectionInterface::RTCConfiguration::operator!=(
@@ -3808,6 +3810,8 @@
           RTC_FROM_HERE,
           rtc::Bind(&cricket::PortAllocator::GetPooledIceCredentials,
                     port_allocator_.get()));
+  session_options->offer_extmap_allow_mixed =
+      configuration_.offer_extmap_allow_mixed;
 }
 
 void PeerConnection::GetOptionsForPlanBOffer(
diff --git a/pc/peerconnectioninterface_unittest.cc b/pc/peerconnectioninterface_unittest.cc
index 12d192e..362c851 100644
--- a/pc/peerconnectioninterface_unittest.cc
+++ b/pc/peerconnectioninterface_unittest.cc
@@ -3944,6 +3944,21 @@
   EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
 }
 
+TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
+  RTCConfiguration config;
+  // Default behavior is false.
+  CreatePeerConnection(config);
+  std::unique_ptr<SessionDescriptionInterface> offer;
+  ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
+  EXPECT_FALSE(offer->description()->extmap_allow_mixed());
+  // Possible to set to true.
+  config.offer_extmap_allow_mixed = true;
+  CreatePeerConnection(config);
+  offer.release();
+  ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
+  EXPECT_TRUE(offer->description()->extmap_allow_mixed());
+}
+
 INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
                         PeerConnectionInterfaceTest,
                         Values(SdpSemantics::kPlanB,
diff --git a/pc/sessiondescription.h b/pc/sessiondescription.h
index b887b18..3829148 100644
--- a/pc/sessiondescription.h
+++ b/pc/sessiondescription.h
@@ -500,10 +500,11 @@
   // Default to what Plan B would do.
   // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
   int msid_signaling_ = kMsidSignalingSsrcAttribute;
-  // TODO(kron): Activate mixed one- and two-byte header extension in offer at
-  // session level. It's currently not included in offer by default because
-  // clients prior to https://bugs.webrtc.org/9712 cannot parse this correctly.
-  // If it's included in offer to us we will respond that we support it.
+  // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
+  // offer at session level. It's currently not included in offer by default
+  // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
+  // correctly. If it's included in offer to us we will respond that we support
+  // it.
   bool extmap_allow_mixed_ = false;
 };