Add support for TransportSequenceNumberV2 in SDP negotiation

TransportSequenceNumberV2 is an experimental feature that should
not be part of the default offer. However, if we receive an offer
with this extension we should respond that we support it.

Bug: webrtc:10264
Change-Id: Id2424d421361e5d71f3a608cb8f74b63645c264a
Reviewed-on: https://webrtc-review.googlesource.com/c/123783
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26817}
diff --git a/pc/media_session.cc b/pc/media_session.cc
index 19eb769..5e6b97b 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -1091,16 +1091,41 @@
     const RtpHeaderExtensions& local_extensions,
     const RtpHeaderExtensions& offered_extensions,
     bool enable_encrypted_rtp_header_extensions,
-    RtpHeaderExtensions* negotiated_extenstions) {
+    RtpHeaderExtensions* negotiated_extensions) {
+  // TransportSequenceNumberV2 is not offered by default. The special logic for
+  // the TransportSequenceNumber extensions works as follows:
+  // Offer       Answer
+  // V1          V1 if in local_extensions.
+  // V1 and V2   V2 regardless of local_extensions.
+  // V2          V2 regardless of local_extensions.
+  const webrtc::RtpExtension* transport_sequence_number_v2_offer =
+      webrtc::RtpExtension::FindHeaderExtensionByUri(
+          offered_extensions,
+          webrtc::RtpExtension::kTransportSequenceNumberV2Uri);
+
   for (const webrtc::RtpExtension& ours : local_extensions) {
     webrtc::RtpExtension theirs;
     if (FindByUriWithEncryptionPreference(
             offered_extensions, ours, enable_encrypted_rtp_header_extensions,
             &theirs)) {
-      // We respond with their RTP header extension id.
-      negotiated_extenstions->push_back(theirs);
+      if (transport_sequence_number_v2_offer &&
+          ours.uri == webrtc::RtpExtension::kTransportSequenceNumberUri) {
+        // Don't respond to
+        // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
+        // if we get an offer including
+        // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-02
+        continue;
+      } else {
+        // We respond with their RTP header extension id.
+        negotiated_extensions->push_back(theirs);
+      }
     }
   }
+
+  if (transport_sequence_number_v2_offer) {
+    // Respond that we support kTransportSequenceNumberV2Uri.
+    negotiated_extensions->push_back(*transport_sequence_number_v2_offer);
+  }
 }
 
 static void StripCNCodecs(AudioCodecs* audio_codecs) {