RtpTransceiverInterface: add header_extensions_to_offer()

This change adds exposure of a new transceiver method for getting
the total set of supported extensions stored as an attribute,
and their direction. If the direction is kStopped, the extension
is not signalled in Unified Plan SDP negotiation.

Note: SDP negotiation is not modified by this change.

Changes:
- RtpHeaderExtensionCapability gets a new RtpTransceiverDirection,
  indicating either kStopped (extension available but not signalled),
  or other (extension signalled).
- RtpTransceiver gets the new method as described above. The
  default value of the attribute comes from the voice and video
  engines as before.

https://chromestatus.com/feature/5680189201711104.
go/rtp-header-extension-ip
Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/65YdUi02yZk

Bug: chromium:1051821
Change-Id: I440443b474db5b1cfe8c6b25b6c10a3ff9c21a8c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170235
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30800}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index f6c28f8..8489065 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -171,6 +171,7 @@
     ":rtc_stats_api",
     ":rtp_packet_info",
     ":rtp_parameters",
+    ":rtp_transceiver_direction",
     ":scoped_refptr",
     "audio:audio_mixer_api",
     "audio_codecs:audio_codecs_api",
@@ -297,6 +298,11 @@
   sources = [ "test/track_id_stream_label_map.h" ]
 }
 
+rtc_source_set("rtp_transceiver_direction") {
+  visibility = [ "*" ]
+  sources = [ "rtp_transceiver_direction.h" ]
+}
+
 rtc_library("rtp_parameters") {
   visibility = [ "*" ]
   sources = [
@@ -307,6 +313,7 @@
   ]
   deps = [
     ":array_view",
+    ":rtp_transceiver_direction",
     "../rtc_base:checks",
     "../rtc_base:stringutils",
     "../rtc_base/system:rtc_export",
diff --git a/api/rtp_parameters.cc b/api/rtp_parameters.cc
index 9b72960..9affafb 100644
--- a/api/rtp_parameters.cc
+++ b/api/rtp_parameters.cc
@@ -38,6 +38,11 @@
     const std::string& uri,
     int preferred_id)
     : uri(uri), preferred_id(preferred_id) {}
+RtpHeaderExtensionCapability::RtpHeaderExtensionCapability(
+    const std::string& uri,
+    int preferred_id,
+    RtpTransceiverDirection direction)
+    : uri(uri), preferred_id(preferred_id), direction(direction) {}
 RtpHeaderExtensionCapability::~RtpHeaderExtensionCapability() = default;
 
 RtpExtension::RtpExtension() = default;
diff --git a/api/rtp_parameters.h b/api/rtp_parameters.h
index a22f764..ee51b01 100644
--- a/api/rtp_parameters.h
+++ b/api/rtp_parameters.h
@@ -19,6 +19,7 @@
 
 #include "absl/types/optional.h"
 #include "api/media_types.h"
+#include "api/rtp_transceiver_direction.h"
 #include "rtc_base/system/rtc_export.h"
 
 namespace webrtc {
@@ -200,7 +201,8 @@
   bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
 };
 
-// Used in RtpCapabilities; represents the capabilities/preferences of an
+// Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
+// and setup methods; represents the capabilities/preferences of an
 // implementation for a header extension.
 //
 // Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
@@ -210,7 +212,7 @@
 // Note that ORTC includes a "kind" field, but we omit this because it's
 // redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
 // you know you're getting audio capabilities.
-struct RtpHeaderExtensionCapability {
+struct RTC_EXPORT RtpHeaderExtensionCapability {
   // URI of this extension, as defined in RFC8285.
   std::string uri;
 
@@ -221,15 +223,23 @@
   // TODO(deadbeef): Not implemented.
   bool preferred_encrypt = false;
 
+  // The direction of the extension. The kStopped value is only used with
+  // RtpTransceiverInterface::header_extensions_offered() and
+  // SetOfferedRtpHeaderExtensions().
+  RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
+
   // Constructors for convenience.
   RtpHeaderExtensionCapability();
   explicit RtpHeaderExtensionCapability(const std::string& uri);
   RtpHeaderExtensionCapability(const std::string& uri, int preferred_id);
+  RtpHeaderExtensionCapability(const std::string& uri,
+                               int preferred_id,
+                               RtpTransceiverDirection direction);
   ~RtpHeaderExtensionCapability();
 
   bool operator==(const RtpHeaderExtensionCapability& o) const {
     return uri == o.uri && preferred_id == o.preferred_id &&
-           preferred_encrypt == o.preferred_encrypt;
+           preferred_encrypt == o.preferred_encrypt && direction == o.direction;
   }
   bool operator!=(const RtpHeaderExtensionCapability& o) const {
     return !(*this == o);
diff --git a/api/rtp_transceiver_direction.h b/api/rtp_transceiver_direction.h
new file mode 100644
index 0000000..3c7d4cb
--- /dev/null
+++ b/api/rtp_transceiver_direction.h
@@ -0,0 +1,27 @@
+/*
+ *  Copyright 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef API_RTP_TRANSCEIVER_DIRECTION_H_
+#define API_RTP_TRANSCEIVER_DIRECTION_H_
+
+namespace webrtc {
+
+// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection
+enum class RtpTransceiverDirection {
+  kSendRecv,
+  kSendOnly,
+  kRecvOnly,
+  kInactive,
+  kStopped,
+};
+
+}  // namespace webrtc
+
+#endif  // API_RTP_TRANSCEIVER_DIRECTION_H_
diff --git a/api/rtp_transceiver_interface.cc b/api/rtp_transceiver_interface.cc
index dc82fad..d4e2b26 100644
--- a/api/rtp_transceiver_interface.cc
+++ b/api/rtp_transceiver_interface.cc
@@ -36,4 +36,9 @@
   return {};
 }
 
+std::vector<RtpHeaderExtensionCapability>
+RtpTransceiverInterface::HeaderExtensionsToOffer() const {
+  return {};
+}
+
 }  // namespace webrtc
diff --git a/api/rtp_transceiver_interface.h b/api/rtp_transceiver_interface.h
index 2af42aa..9dbafd4 100644
--- a/api/rtp_transceiver_interface.h
+++ b/api/rtp_transceiver_interface.h
@@ -20,21 +20,13 @@
 #include "api/rtp_parameters.h"
 #include "api/rtp_receiver_interface.h"
 #include "api/rtp_sender_interface.h"
+#include "api/rtp_transceiver_direction.h"
 #include "api/scoped_refptr.h"
 #include "rtc_base/ref_count.h"
 #include "rtc_base/system/rtc_export.h"
 
 namespace webrtc {
 
-// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection
-enum class RtpTransceiverDirection {
-  kSendRecv,
-  kSendOnly,
-  kRecvOnly,
-  kInactive,
-  kStopped,
-};
-
 // Structure for initializing an RtpTransceiver in a call to
 // PeerConnectionInterface::AddTransceiver.
 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
@@ -134,6 +126,13 @@
       rtc::ArrayView<RtpCodecCapability> codecs);
   virtual std::vector<RtpCodecCapability> codec_preferences() const;
 
+  // Readonly attribute which contains the set of header extensions that was set
+  // with SetOfferedRtpHeaderExtensions, or a default set if it has not been
+  // called.
+  // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
+  virtual std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer()
+      const;
+
  protected:
   ~RtpTransceiverInterface() override = default;
 };