Revert "RtpTransceiverInterface: introduce SetOfferedRtpHeaderExtensions."

This reverts commit 71db9acc4019b8c9c13b14e6a022cbb3b4255b09.

Reason for revert: breaks downstream project.
Reason for force push: win bot broken.

Original change's description:
> RtpTransceiverInterface: introduce SetOfferedRtpHeaderExtensions.
>
> This change adds exposure of a new transceiver method for
> modifying the extensions offered in the next SDP negotiation,
> following spec details in https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface.
>
> Features:
> - The interface allows to control the negotiated direction as
>   per https://tools.ietf.org/html/rfc5285#page-7.
> - The interface allows to remove an extension from SDP
>   negotiation by modifying the direction to
>   RtpTransceiverDirection::kStopped.
>
> Note: support for signalling directionality of header extensions
> in the SDP isn't implemented yet.
>
> https://chromestatus.com/feature/5680189201711104.
> Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/65YdUi02yZk
>
> Bug: chromium:1051821
> Change-Id: Iaabc34446f038c46d93c442e90c2a77f77d542d4
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176408
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Commit-Queue: Markus Handell <handellm@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31487}

TBR=hta@webrtc.org,handellm@webrtc.org

# Not skipping CQ checks because original CL landed > 1 day ago.

No-Try: true
Bug: chromium:1051821
Change-Id: I70e1a07225d7eeec7480fa5577d8ff647eba6902
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/177103
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31516}
diff --git a/pc/media_session.cc b/pc/media_session.cc
index 68733a4..6bf3136 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -55,29 +55,6 @@
   }
 }
 
-cricket::RtpHeaderExtensions RtpHeaderExtensionsFromCapabilities(
-    const std::vector<webrtc::RtpHeaderExtensionCapability>& capabilities) {
-  cricket::RtpHeaderExtensions exts;
-  for (const auto& extension_with_direction : capabilities) {
-    exts.emplace_back(extension_with_direction.uri,
-                      extension_with_direction.preferred_id.value_or(1));
-  }
-  return exts;
-}
-
-std::vector<webrtc::RtpHeaderExtensionCapability>
-UnstoppedRtpHeaderExtensionCapabilities(
-    std::vector<webrtc::RtpHeaderExtensionCapability> capabilities) {
-  capabilities.erase(
-      std::remove_if(
-          capabilities.begin(), capabilities.end(),
-          [](const webrtc::RtpHeaderExtensionCapability& capability) {
-            return capability.direction == RtpTransceiverDirection::kStopped;
-          }),
-      capabilities.end());
-  return capabilities;
-}
-
 }  // namespace
 
 namespace cricket {
@@ -656,22 +633,7 @@
   if (offer->type() == cricket::MEDIA_TYPE_VIDEO) {
     offer->set_rtcp_reduced_size(true);
   }
-
-  // Build the vector of header extensions with directions for this
-  // media_description's options.
-  RtpHeaderExtensions extensions;
-  for (auto extension_with_id : rtp_extensions) {
-    for (const auto& extension : UnstoppedRtpHeaderExtensionCapabilities(
-             media_description_options.header_extensions)) {
-      if (extension_with_id.uri == extension.uri) {
-        // TODO(crbug.com/1051821): Configure the extension direction from
-        // the information in the media_description_options extension
-        // capability.
-        extensions.push_back(extension_with_id);
-      }
-    }
-  }
-  offer->set_rtp_header_extensions(extensions);
+  offer->set_rtp_header_extensions(rtp_extensions);
 
   AddSimulcastToMediaDescription(media_description_options, offer);
 
@@ -1203,7 +1165,7 @@
     const MediaSessionOptions& session_options,
     const SecurePolicy& sdes_policy,
     const CryptoParamsVec* current_cryptos,
-    const RtpHeaderExtensions& local_rtp_extensions,
+    const RtpHeaderExtensions& local_rtp_extenstions,
     UniqueRandomIdGenerator* ssrc_generator,
     bool enable_encrypted_rtp_header_extensions,
     StreamParamsVec* current_streams,
@@ -1212,7 +1174,7 @@
   answer->set_extmap_allow_mixed_enum(offer->extmap_allow_mixed_enum());
   RtpHeaderExtensions negotiated_rtp_extensions;
   NegotiateRtpHeaderExtensions(
-      local_rtp_extensions, offer->rtp_header_extensions(),
+      local_rtp_extenstions, offer->rtp_header_extensions(),
       enable_encrypted_rtp_header_extensions, &negotiated_rtp_extensions);
   answer->set_rtp_header_extensions(negotiated_rtp_extensions);
 
@@ -1390,8 +1352,12 @@
     : MediaSessionDescriptionFactory(transport_desc_factory, ssrc_generator) {
   channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_);
   channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_);
+  audio_rtp_extensions_ =
+      channel_manager->GetDefaultEnabledAudioRtpHeaderExtensions();
   channel_manager->GetSupportedVideoSendCodecs(&video_send_codecs_);
   channel_manager->GetSupportedVideoReceiveCodecs(&video_recv_codecs_);
+  video_rtp_extensions_ =
+      channel_manager->GetDefaultEnabledVideoRtpHeaderExtensions();
   channel_manager->GetSupportedDataCodecs(&rtp_data_codecs_);
   ComputeAudioCodecsIntersectionAndUnion();
   ComputeVideoCodecsIntersectionAndUnion();
@@ -1454,11 +1420,22 @@
 }
 
 RtpHeaderExtensions
-MediaSessionDescriptionFactory::filtered_rtp_header_extensions(
-    RtpHeaderExtensions extensions) const {
+MediaSessionDescriptionFactory::audio_rtp_header_extensions() const {
+  RtpHeaderExtensions extensions = audio_rtp_extensions_;
   if (!is_unified_plan_) {
     RemoveUnifiedPlanExtensions(&extensions);
   }
+
+  return extensions;
+}
+
+RtpHeaderExtensions
+MediaSessionDescriptionFactory::video_rtp_header_extensions() const {
+  RtpHeaderExtensions extensions = video_rtp_extensions_;
+  if (!is_unified_plan_) {
+    RemoveUnifiedPlanExtensions(&extensions);
+  }
+
   return extensions;
 }
 
@@ -1494,10 +1471,11 @@
     StripCNCodecs(&offer_audio_codecs);
   }
 
-  AudioVideoRtpHeaderExtensions extensions_with_ids =
-      GetOfferedRtpHeaderExtensionsWithIds(
-          current_active_contents, session_options.offer_extmap_allow_mixed,
-          session_options.media_description_options);
+  RtpHeaderExtensions audio_rtp_extensions;
+  RtpHeaderExtensions video_rtp_extensions;
+  GetRtpHdrExtsToOffer(current_active_contents,
+                       session_options.offer_extmap_allow_mixed,
+                       &audio_rtp_extensions, &video_rtp_extensions);
 
   auto offer = std::make_unique<SessionDescription>();
 
@@ -1517,20 +1495,18 @@
     }
     switch (media_description_options.type) {
       case MEDIA_TYPE_AUDIO:
-        if (!AddAudioContentForOffer(media_description_options, session_options,
-                                     current_content, current_description,
-                                     extensions_with_ids.audio,
-                                     offer_audio_codecs, &current_streams,
-                                     offer.get(), &ice_credentials)) {
+        if (!AddAudioContentForOffer(
+                media_description_options, session_options, current_content,
+                current_description, audio_rtp_extensions, offer_audio_codecs,
+                &current_streams, offer.get(), &ice_credentials)) {
           return nullptr;
         }
         break;
       case MEDIA_TYPE_VIDEO:
-        if (!AddVideoContentForOffer(media_description_options, session_options,
-                                     current_content, current_description,
-                                     extensions_with_ids.video,
-                                     offer_video_codecs, &current_streams,
-                                     offer.get(), &ice_credentials)) {
+        if (!AddVideoContentForOffer(
+                media_description_options, session_options, current_content,
+                current_description, video_rtp_extensions, offer_video_codecs,
+                &current_streams, offer.get(), &ice_credentials)) {
           return nullptr;
         }
         break;
@@ -1665,16 +1641,13 @@
         msection_index < current_description->contents().size()) {
       current_content = &current_description->contents()[msection_index];
     }
-    RtpHeaderExtensions header_extensions = RtpHeaderExtensionsFromCapabilities(
-        UnstoppedRtpHeaderExtensionCapabilities(
-            media_description_options.header_extensions));
     switch (media_description_options.type) {
       case MEDIA_TYPE_AUDIO:
         if (!AddAudioContentForAnswer(
                 media_description_options, session_options, offer_content,
                 offer, current_content, current_description,
-                bundle_transport.get(), answer_audio_codecs, header_extensions,
-                &current_streams, answer.get(), &ice_credentials)) {
+                bundle_transport.get(), answer_audio_codecs, &current_streams,
+                answer.get(), &ice_credentials)) {
           return nullptr;
         }
         break;
@@ -1682,8 +1655,8 @@
         if (!AddVideoContentForAnswer(
                 media_description_options, session_options, offer_content,
                 offer, current_content, current_description,
-                bundle_transport.get(), answer_video_codecs, header_extensions,
-                &current_streams, answer.get(), &ice_credentials)) {
+                bundle_transport.get(), answer_video_codecs, &current_streams,
+                answer.get(), &ice_credentials)) {
           return nullptr;
         }
         break;
@@ -1976,12 +1949,11 @@
                          &used_pltypes);
 }
 
-MediaSessionDescriptionFactory::AudioVideoRtpHeaderExtensions
-MediaSessionDescriptionFactory::GetOfferedRtpHeaderExtensionsWithIds(
+void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer(
     const std::vector<const ContentInfo*>& current_active_contents,
     bool extmap_allow_mixed,
-    const std::vector<MediaDescriptionOptions>& media_description_options)
-    const {
+    RtpHeaderExtensions* offer_audio_extensions,
+    RtpHeaderExtensions* offer_video_extensions) const {
   // All header extensions allocated from the same range to avoid potential
   // issues when using BUNDLE.
 
@@ -1995,7 +1967,6 @@
   RtpHeaderExtensions all_regular_extensions;
   RtpHeaderExtensions all_encrypted_extensions;
 
-  AudioVideoRtpHeaderExtensions offered_extensions;
   // First - get all extensions from the current description if the media type
   // is used.
   // Add them to |used_ids| so the local ids are not reused if a new media
@@ -2004,42 +1975,36 @@
     if (IsMediaContentOfType(content, MEDIA_TYPE_AUDIO)) {
       const AudioContentDescription* audio =
           content->media_description()->as_audio();
-      MergeRtpHdrExts(audio->rtp_header_extensions(), &offered_extensions.audio,
+      MergeRtpHdrExts(audio->rtp_header_extensions(), offer_audio_extensions,
                       &all_regular_extensions, &all_encrypted_extensions,
                       &used_ids);
     } else if (IsMediaContentOfType(content, MEDIA_TYPE_VIDEO)) {
       const VideoContentDescription* video =
           content->media_description()->as_video();
-      MergeRtpHdrExts(video->rtp_header_extensions(), &offered_extensions.video,
+      MergeRtpHdrExts(video->rtp_header_extensions(), offer_video_extensions,
                       &all_regular_extensions, &all_encrypted_extensions,
                       &used_ids);
     }
   }
 
-  // Add all encountered header extensions in the media description options that
-  // are not in the current description.
-  for (const auto& entry : media_description_options) {
-    RtpHeaderExtensions filtered_extensions = filtered_rtp_header_extensions(
-        RtpHeaderExtensionsFromCapabilities(entry.header_extensions));
-    if (entry.type == MEDIA_TYPE_AUDIO)
-      MergeRtpHdrExts(filtered_extensions, &offered_extensions.audio,
-                      &all_regular_extensions, &all_encrypted_extensions,
-                      &used_ids);
-    else if (entry.type == MEDIA_TYPE_VIDEO)
-      MergeRtpHdrExts(filtered_extensions, &offered_extensions.video,
-                      &all_regular_extensions, &all_encrypted_extensions,
-                      &used_ids);
-  }
+  // Add our default RTP header extensions that are not in the current
+  // description.
+  MergeRtpHdrExts(audio_rtp_header_extensions(), offer_audio_extensions,
+                  &all_regular_extensions, &all_encrypted_extensions,
+                  &used_ids);
+  MergeRtpHdrExts(video_rtp_header_extensions(), offer_video_extensions,
+                  &all_regular_extensions, &all_encrypted_extensions,
+                  &used_ids);
+
   // TODO(jbauch): Support adding encrypted header extensions to existing
   // sessions.
   if (enable_encrypted_rtp_header_extensions_ &&
       current_active_contents.empty()) {
-    AddEncryptedVersionsOfHdrExts(&offered_extensions.audio,
+    AddEncryptedVersionsOfHdrExts(offer_audio_extensions,
                                   &all_encrypted_extensions, &used_ids);
-    AddEncryptedVersionsOfHdrExts(&offered_extensions.video,
+    AddEncryptedVersionsOfHdrExts(offer_video_extensions,
                                   &all_encrypted_extensions, &used_ids);
   }
-  return offered_extensions;
 }
 
 bool MediaSessionDescriptionFactory::AddTransportOffer(
@@ -2414,7 +2379,6 @@
     const SessionDescription* current_description,
     const TransportInfo* bundle_transport,
     const AudioCodecs& audio_codecs,
-    const RtpHeaderExtensions& default_audio_rtp_header_extensions,
     StreamParamsVec* current_streams,
     SessionDescription* answer,
     IceCredentialsIterator* ice_credentials) const {
@@ -2487,9 +2451,9 @@
   if (!CreateMediaContentAnswer(
           offer_audio_description, media_description_options, session_options,
           sdes_policy, GetCryptos(current_content),
-          filtered_rtp_header_extensions(default_audio_rtp_header_extensions),
-          ssrc_generator_, enable_encrypted_rtp_header_extensions_,
-          current_streams, bundle_enabled, audio_answer.get())) {
+          audio_rtp_header_extensions(), ssrc_generator_,
+          enable_encrypted_rtp_header_extensions_, current_streams,
+          bundle_enabled, audio_answer.get())) {
     return false;  // Fails the session setup.
   }
 
@@ -2525,7 +2489,6 @@
     const SessionDescription* current_description,
     const TransportInfo* bundle_transport,
     const VideoCodecs& video_codecs,
-    const RtpHeaderExtensions& default_video_rtp_header_extensions,
     StreamParamsVec* current_streams,
     SessionDescription* answer,
     IceCredentialsIterator* ice_credentials) const {
@@ -2606,9 +2569,9 @@
   if (!CreateMediaContentAnswer(
           offer_video_description, media_description_options, session_options,
           sdes_policy, GetCryptos(current_content),
-          filtered_rtp_header_extensions(default_video_rtp_header_extensions),
-          ssrc_generator_, enable_encrypted_rtp_header_extensions_,
-          current_streams, bundle_enabled, video_answer.get())) {
+          video_rtp_header_extensions(), ssrc_generator_,
+          enable_encrypted_rtp_header_extensions_, current_streams,
+          bundle_enabled, video_answer.get())) {
     return false;  // Failed the sessin setup.
   }
   bool secure = bundle_transport ? bundle_transport->description.secure()