Move the payload type picker to call/

Since media/ and pc/ both have to use this, and both
depend on call/, this seems to be the right place to put it.

Also factor out the interface that media will use in a separate
interface class.

Bug: webrtc:360058654
Change-Id: I34acbecc618f23e19542ce4b0110d0e8ed9e55ee
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/361281
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Auto-Submit: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42933}
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 1094b48..a74e8ac 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -38,6 +38,8 @@
 
   deps = [
     ":audio_sender_interface",
+    ":payload_type",
+    ":payload_type",
     ":receive_stream_interface",
     ":rtp_interfaces",
     ":video_stream_api",
@@ -307,6 +309,9 @@
     ":bitrate_allocator",
     ":call_interfaces",
     ":fake_network",
+    ":payload_type",
+    ":payload_type",
+    ":payload_type_picker",
     ":receive_stream_interface",
     ":rtp_interfaces",
     ":rtp_receiver",
@@ -317,6 +322,7 @@
     "../api:array_view",
     "../api:fec_controller_api",
     "../api:field_trials_view",
+    "../api:rtc_error",
     "../api:rtp_headers",
     "../api:rtp_parameters",
     "../api:scoped_refptr",
@@ -340,6 +346,7 @@
     "../logging:rtc_event_rtp_rtcp",
     "../logging:rtc_event_video",
     "../logging:rtc_stream_config",
+    "../media:codec",
     "../modules/congestion_controller",
     "../modules/pacing",
     "../modules/rtp_rtcp",
@@ -374,6 +381,32 @@
   ]
 }
 
+rtc_library("payload_type_picker") {
+  sources = [
+    "payload_type_picker.cc",
+    "payload_type_picker.h",
+  ]
+  deps = [
+    ":payload_type",
+    "../api:rtc_error",
+    "../api/audio_codecs:audio_codecs_api",
+    "../media:codec",
+    "../media:media_constants",
+    "../rtc_base:logging",
+    "../rtc_base:strong_alias",
+    "//third_party/abseil-cpp/absl/strings",
+  ]
+}
+
+rtc_source_set("payload_type") {
+  sources = [ "payload_type.h" ]
+  deps = [
+    "../api:rtc_error",
+    "../media:codec",
+    "../rtc_base:strong_alias",
+  ]
+}
+
 rtc_source_set("receive_stream_interface") {
   sources = [ "receive_stream.h" ]
   deps = [
@@ -472,6 +505,7 @@
         "bitrate_estimator_tests.cc",
         "call_unittest.cc",
         "flexfec_receive_stream_unittest.cc",
+        "payload_type_picker_unittest.cc",
         "receive_time_calculator_unittest.cc",
         "rtp_bitrate_configurator_unittest.cc",
         "rtp_demuxer_unittest.cc",
@@ -485,6 +519,8 @@
         ":call",
         ":call_interfaces",
         ":mock_rtp_interfaces",
+        ":payload_type",
+        ":payload_type_picker",
         ":rtp_interfaces",
         ":rtp_receiver",
         ":rtp_sender",
@@ -527,6 +563,8 @@
         "../audio",
         "../common_video:frame_counts",
         "../common_video/generic_frame_descriptor",
+        "../media:codec",
+        "../media:media_constants",
         "../modules/audio_device:mock_audio_device",
         "../modules/audio_mixer",
         "../modules/audio_mixer:audio_mixer_impl",
diff --git a/call/DEPS b/call/DEPS
index daff3e9..1fe352d 100644
--- a/call/DEPS
+++ b/call/DEPS
@@ -52,4 +52,22 @@
     "+common_video/frame_counts.h",
     "+common_video/generic_frame_descriptor",
   ],
+  "payload_type\.h": [
+    "+media/base/codec.h",
+  ],
+  "payload_type_picker\.h": [
+    "+media/base/codec.h",
+    "+media/base/media_constants.h",
+  ],
+  "payload_type_picker\.cc": [
+    "+media/base/codec.h",
+    "+media/base/media_constants.h",
+  ],
+  "payload_type_picker_unittest\.cc": [
+    "+media/base/codec.h",
+    "+media/base/media_constants.h",
+  ],
+  "call\.cc": [
+    "+media/base/codec.h",
+  ]
 }
diff --git a/call/call.cc b/call/call.cc
index 0b1ca6f..cf94cb8 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -30,6 +30,7 @@
 #include "api/fec_controller.h"
 #include "api/field_trials_view.h"
 #include "api/media_types.h"
+#include "api/rtc_error.h"
 #include "api/rtc_event_log/rtc_event_log.h"
 #include "api/rtp_headers.h"
 #include "api/scoped_refptr.h"
@@ -52,6 +53,8 @@
 #include "call/flexfec_receive_stream.h"
 #include "call/flexfec_receive_stream_impl.h"
 #include "call/packet_receiver.h"
+#include "call/payload_type.h"
+#include "call/payload_type_picker.h"
 #include "call/receive_stream.h"
 #include "call/receive_time_calculator.h"
 #include "call/rtp_config.h"
@@ -66,6 +69,7 @@
 #include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
 #include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
 #include "logging/rtc_event_log/rtc_stream_config.h"
+#include "media/base/codec.h"
 #include "modules/congestion_controller/include/receive_side_congestion_controller.h"
 #include "modules/rtp_rtcp/include/flexfec_receiver.h"
 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@@ -100,6 +104,21 @@
 
 namespace {
 
+// In normal operation, the PTS comes from the PeerConnection.
+// However, it is too much of a bother to insert it in all tests,
+// so defaulting here.
+class PayloadTypeSuggesterForTests : public PayloadTypeSuggester {
+ public:
+  PayloadTypeSuggesterForTests() = default;
+  RTCErrorOr<PayloadType> SuggestPayloadType(const std::string& mid,
+                                             cricket::Codec codec) override {
+    return payload_type_picker_.SuggestMapping(codec, nullptr);
+  }
+
+ private:
+  PayloadTypePicker payload_type_picker_;
+};
+
 const int* FindKeyByValue(const std::map<int, int>& m, int v) {
   for (const auto& kv : m) {
     if (kv.second == v)
@@ -249,6 +268,9 @@
 
   RtpTransportControllerSendInterface* GetTransportControllerSend() override;
 
+  PayloadTypeSuggester* GetPayloadTypeSuggester() override;
+  void SetPayloadTypeSuggester(PayloadTypeSuggester* suggester) override;
+
   Stats GetStats() const override;
 
   const FieldTrialsView& trials() const override;
@@ -465,17 +487,21 @@
   // https://bugs.chromium.org/p/chromium/issues/detail?id=992640
   RtpTransportControllerSendInterface* const transport_send_ptr_
       RTC_GUARDED_BY(send_transport_sequence_checker_);
-  // Declared last since it will issue callbacks from a task queue. Declaring it
-  // last ensures that it is destroyed first and any running tasks are finished.
-  const std::unique_ptr<RtpTransportControllerSendInterface> transport_send_;
 
   bool is_started_ RTC_GUARDED_BY(worker_thread_) = false;
 
+  // Mechanism for proposing payload types in RTP mappings.
+  PayloadTypeSuggester* pt_suggester_ = nullptr;
+  std::unique_ptr<PayloadTypeSuggesterForTests> owned_pt_suggester_;
+
   // Sequence checker for outgoing network traffic. Could be the network thread.
   // Could also be a pacer owned thread or TQ such as the TaskQueueSender.
   RTC_NO_UNIQUE_ADDRESS SequenceChecker sent_packet_sequence_checker_;
   std::optional<rtc::SentPacket> last_sent_packet_
       RTC_GUARDED_BY(sent_packet_sequence_checker_);
+  // Declared last since it will issue callbacks from a task queue. Declaring it
+  // last ensures that it is destroyed first and any running tasks are finished.
+  const std::unique_ptr<RtpTransportControllerSendInterface> transport_send_;
 };
 }  // namespace internal
 
@@ -1119,6 +1145,24 @@
   return transport_send_.get();
 }
 
+PayloadTypeSuggester* Call::GetPayloadTypeSuggester() {
+  // TODO: https://issues.webrtc.org/360058654 - make mandatory at
+  // initialization. Currently, only some channels use it.
+  RTC_DCHECK_RUN_ON(worker_thread_);
+  if (!pt_suggester_) {
+    // Make something that will work most of the time for testing.
+    owned_pt_suggester_ = std::make_unique<PayloadTypeSuggesterForTests>();
+    SetPayloadTypeSuggester(owned_pt_suggester_.get());
+  }
+  return pt_suggester_;
+}
+
+void Call::SetPayloadTypeSuggester(PayloadTypeSuggester* suggester) {
+  RTC_CHECK(!pt_suggester_)
+      << "SetPayloadTypeSuggester can be called only once";
+  pt_suggester_ = suggester;
+}
+
 Call::Stats Call::GetStats() const {
   RTC_DCHECK_RUN_ON(worker_thread_);
 
diff --git a/call/call.h b/call/call.h
index 6c6bc46..313e8a8 100644
--- a/call/call.h
+++ b/call/call.h
@@ -28,9 +28,11 @@
 #include "call/call_config.h"
 #include "call/flexfec_receive_stream.h"
 #include "call/packet_receiver.h"
+#include "call/payload_type.h"
 #include "call/rtp_transport_controller_send_interface.h"
 #include "call/video_receive_stream.h"
 #include "call/video_send_stream.h"
+#include "rtc_base/checks.h"
 #include "rtc_base/network/sent_packet.h"
 #include "video/config/video_encoder_config.h"
 
@@ -109,6 +111,18 @@
   // remove this method interface.
   virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
 
+  // A class that keeps track of payload types on the transport(s), and
+  // suggests new ones when needed.
+  virtual PayloadTypeSuggester* GetPayloadTypeSuggester() {
+    // TODO: https://issues.webrtc.org/360058654 - make pure virtual
+    RTC_CHECK_NOTREACHED();
+    return nullptr;
+  }
+  virtual void SetPayloadTypeSuggester(PayloadTypeSuggester* suggester) {
+    // TODO: https://issues.webrtc.org/360058654 - make pure virtual
+    RTC_CHECK_NOTREACHED();
+  }
+
   // Returns the call statistics, such as estimated send and receive bandwidth,
   // pacing delay, etc.
   virtual Stats GetStats() const = 0;
diff --git a/call/payload_type.h b/call/payload_type.h
new file mode 100644
index 0000000..428096b
--- /dev/null
+++ b/call/payload_type.h
@@ -0,0 +1,44 @@
+/*
+ *  Copyright 2024 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 CALL_PAYLOAD_TYPE_H_
+#define CALL_PAYLOAD_TYPE_H_
+
+#include <cstdint>
+#include <string>
+
+#include "api/rtc_error.h"
+#include "media/base/codec.h"
+#include "rtc_base/strong_alias.h"
+
+namespace webrtc {
+
+class PayloadType : public StrongAlias<class PayloadTypeTag, uint8_t> {
+ public:
+  // Non-explicit conversions from and to ints are to be deprecated and
+  // removed once calling code is upgraded.
+  PayloadType(uint8_t pt) { value_ = pt; }                // NOLINT: explicit
+  constexpr operator uint8_t() const& { return value_; }  // NOLINT: Explicit
+};
+
+class PayloadTypeSuggester {
+ public:
+  virtual ~PayloadTypeSuggester() = default;
+  // Suggest a payload type for a given codec on a given media section.
+  // Media section is indicated by MID.
+  // The function will either return a PT already in use on the connection
+  // or a newly suggested one.
+  virtual RTCErrorOr<PayloadType> SuggestPayloadType(const std::string& mid,
+                                                     cricket::Codec codec) = 0;
+};
+
+}  // namespace webrtc
+
+#endif  // CALL_PAYLOAD_TYPE_H_
diff --git a/pc/payload_type_picker.cc b/call/payload_type_picker.cc
similarity index 97%
rename from pc/payload_type_picker.cc
rename to call/payload_type_picker.cc
index 8720b20..4c5936b 100644
--- a/pc/payload_type_picker.cc
+++ b/call/payload_type_picker.cc
@@ -8,15 +8,20 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "pc/payload_type_picker.h"
+#include "call/payload_type_picker.h"
 
 #include <algorithm>
+#include <set>
 #include <utility>
 #include <vector>
 
 #include "absl/strings/match.h"
+#include "api/audio_codecs/audio_format.h"
 #include "api/rtc_error.h"
+#include "call/payload_type.h"
 #include "media/base/codec.h"
+#include "media/base/media_constants.h"
+#include "rtc_base/logging.h"
 
 namespace webrtc {
 
diff --git a/pc/payload_type_picker.h b/call/payload_type_picker.h
similarity index 82%
rename from pc/payload_type_picker.h
rename to call/payload_type_picker.h
index 4726a31..0b2141c 100644
--- a/pc/payload_type_picker.h
+++ b/call/payload_type_picker.h
@@ -8,8 +8,8 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#ifndef PC_PAYLOAD_TYPE_PICKER_H_
-#define PC_PAYLOAD_TYPE_PICKER_H_
+#ifndef CALL_PAYLOAD_TYPE_PICKER_H_
+#define CALL_PAYLOAD_TYPE_PICKER_H_
 
 #include <map>
 #include <set>
@@ -18,18 +18,10 @@
 
 #include "api/rtc_error.h"
 #include "media/base/codec.h"
-#include "rtc_base/strong_alias.h"
+#include "call/payload_type.h"
 
 namespace webrtc {
 
-class PayloadType : public StrongAlias<class PayloadTypeTag, uint8_t> {
- public:
-  // Non-explicit conversions from and to ints are to be deprecated and
-  // removed once calling code is upgraded.
-  PayloadType(uint8_t pt) { value_ = pt; }                // NOLINT: explicit
-  constexpr operator uint8_t() const& { return value_; }  // NOLINT: Explicit
-};
-
 class PayloadTypeRecorder;
 
 class PayloadTypePicker {
@@ -84,4 +76,4 @@
 
 }  // namespace webrtc
 
-#endif  //  PC_PAYLOAD_TYPE_PICKER_H_
+#endif  //  CALL_PAYLOAD_TYPE_PICKER_H_
diff --git a/pc/payload_type_picker_unittest.cc b/call/payload_type_picker_unittest.cc
similarity index 97%
rename from pc/payload_type_picker_unittest.cc
rename to call/payload_type_picker_unittest.cc
index 71a3383..e1704cf 100644
--- a/pc/payload_type_picker_unittest.cc
+++ b/call/payload_type_picker_unittest.cc
@@ -8,9 +8,11 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "pc/payload_type_picker.h"
+#include "call/payload_type_picker.h"
 
+#include "call/payload_type.h"
 #include "media/base/codec.h"
+#include "media/base/media_constants.h"
 #include "test/gtest.h"
 
 namespace webrtc {
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 584ef91..32af232 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -231,9 +231,15 @@
     ":media_channel",
     ":media_channel_impl",
     ":rtc_media_config",
+    ":stream_params",
     ":video_common",
+    "../api:array_view",
+    "../api:audio_options_api",
     "../api:field_trials_view",
+    "../api:rtc_error",
     "../api:rtp_parameters",
+    "../api:scoped_refptr",
+    "../api/audio:audio_device",
     "../api/audio_codecs:audio_codecs_api",
     "../api/crypto:options",
     "../api/video:video_bitrate_allocation",
diff --git a/media/DEPS b/media/DEPS
index 7fbbc0f..bcdbcac 100644
--- a/media/DEPS
+++ b/media/DEPS
@@ -34,4 +34,8 @@
   ".*fake_webrtc_call\.cc": [
     "+video/config",
   ],
+  # temporary
+  ".*webrtc_voice_engine\.cc": [
+    "+pc/payload_type_picker.h",
+  ],
 }
diff --git a/media/base/media_engine.h b/media/base/media_engine.h
index b13d7df..780bac0 100644
--- a/media/base/media_engine.h
+++ b/media/base/media_engine.h
@@ -11,22 +11,27 @@
 #ifndef MEDIA_BASE_MEDIA_ENGINE_H_
 #define MEDIA_BASE_MEDIA_ENGINE_H_
 
+#include <cstdint>
 #include <memory>
-#include <string>
+#include <optional>
 #include <vector>
 
-#include "api/audio_codecs/audio_decoder_factory.h"
-#include "api/audio_codecs/audio_encoder_factory.h"
+#include "api/array_view.h"
+#include "api/audio/audio_device.h"
+#include "api/audio_codecs/audio_codec_pair_id.h"
+#include "api/audio_options.h"
 #include "api/crypto/crypto_options.h"
 #include "api/field_trials_view.h"
+#include "api/rtc_error.h"
 #include "api/rtp_parameters.h"
+#include "api/scoped_refptr.h"
 #include "api/video/video_bitrate_allocator_factory.h"
 #include "call/audio_state.h"
 #include "media/base/codec.h"
 #include "media/base/media_channel.h"
-#include "media/base/media_channel_impl.h"
 #include "media/base/media_config.h"
-#include "media/base/video_common.h"
+#include "media/base/stream_params.h"
+#include "rtc_base/checks.h"
 #include "rtc_base/system/file_wrapper.h"
 
 namespace webrtc {
@@ -121,6 +126,10 @@
     return nullptr;
   }
 
+  // Legacy: Retrieve list of supported codecs.
+  // + protection codecs, and assigns PT numbers that may have to be
+  // reassigned.
+  // TODO: https://issues.webrtc.org/360058654 - deprecate and remove.
   virtual const std::vector<Codec>& send_codecs() const = 0;
   virtual const std::vector<Codec>& recv_codecs() const = 0;
 
@@ -166,7 +175,10 @@
     return nullptr;
   }
 
-  // Retrieve list of supported codecs.
+  // Legacy: Retrieve list of supported codecs.
+  // + protection codecs, and assigns PT numbers that may have to be
+  // reassigned.
+  // TODO: https://issues.webrtc.org/360058654 - deprecate and remove.
   virtual std::vector<Codec> send_codecs() const = 0;
   virtual std::vector<Codec> recv_codecs() const = 0;
   // As above, but if include_rtx is false, don't include RTX codecs.
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index c4aa4de..5e11f04 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -145,7 +145,10 @@
 }
 
 rtc_source_set("dtls_transport") {
-  visibility = [ ":*" ]
+  visibility = [
+    ":*",
+    "../test/*",
+  ]
   sources = [
     "dtls_transport.cc",
     "dtls_transport.h",
@@ -210,7 +213,6 @@
   deps = [
     ":dtls_srtp_transport",
     ":dtls_transport",
-    ":payload_type_picker",
     ":rtcp_mux_filter",
     ":rtp_transport",
     ":rtp_transport_internal",
@@ -226,6 +228,7 @@
     "../api:scoped_refptr",
     "../api:sequence_checker",
     "../api/transport:datagram_transport_interface",
+    "../call:payload_type_picker",
     "../media:rtc_data_sctp_transport_internal",
     "../p2p:dtls_transport",
     "../p2p:dtls_transport_internal",
@@ -304,7 +307,11 @@
     "../api/transport:datagram_transport_interface",
     "../api/transport:enums",
     "../api/transport:sctp_transport_factory_interface",
+    "../call:payload_type",
+    "../call:payload_type_picker",
+    "../media:codec",
     "../media:rtc_data_sctp_transport_internal",
+    "../modules/rtp_rtcp:rtp_rtcp_format",
     "../p2p:connection",
     "../p2p:dtls_transport",
     "../p2p:dtls_transport_factory",
@@ -331,6 +338,7 @@
     "../rtc_base/third_party/sigslot",
     "//third_party/abseil-cpp/absl/algorithm:container",
     "//third_party/abseil-cpp/absl/functional:any_invocable",
+    "//third_party/abseil-cpp/absl/strings:string_view",
   ]
 }
 
@@ -406,19 +414,6 @@
   ]
 }
 
-rtc_library("payload_type_picker") {
-  sources = [
-    "payload_type_picker.cc",
-    "payload_type_picker.h",
-  ]
-  deps = [
-    "../api:rtc_error",
-    "../media:codec",
-    "../rtc_base:strong_alias",
-    "//third_party/abseil-cpp/absl/strings",
-  ]
-}
-
 rtc_source_set("peer_connection_factory_proxy") {
   visibility = [ ":*" ]
   sources = [ "peer_connection_factory_proxy.h" ]
@@ -1084,7 +1079,6 @@
     ":ice_server_parsing",
     ":jsep_transport_controller",
     ":legacy_stats_collector",
-    ":payload_type_picker",
     ":peer_connection_internal",
     ":peer_connection_message_handler",
     ":rtc_stats_collector",
@@ -1130,6 +1124,7 @@
     "../api/transport:enums",
     "../api/video:video_codec_constants",
     "../call:call_interfaces",
+    "../call:payload_type_picker",
     "../media:media_channel",
     "../media:media_engine",
     "../media:rid_description",
@@ -1953,7 +1948,6 @@
       "jsep_transport_controller_unittest.cc",
       "jsep_transport_unittest.cc",
       "media_session_unittest.cc",
-      "payload_type_picker_unittest.cc",
       "rtcp_mux_filter_unittest.cc",
       "rtp_transport_unittest.cc",
       "sctp_transport_unittest.cc",
@@ -1981,7 +1975,6 @@
       ":libjingle_peerconnection",
       ":media_protocol_names",
       ":media_session",
-      ":payload_type_picker",
       ":pc_test_utils",
       ":rtc_pc",
       ":rtcp_mux_filter",
@@ -2017,6 +2010,7 @@
       "../api/video:builtin_video_bitrate_allocator_factory",
       "../api/video:recordable_encoded_frame",
       "../api/video/test:mock_recordable_encoded_frame",
+      "../call:payload_type_picker",
       "../call:rtp_interfaces",
       "../call:rtp_receiver",
       "../media:codec",
diff --git a/pc/jsep_transport.h b/pc/jsep_transport.h
index 005e606..56840a3 100644
--- a/pc/jsep_transport.h
+++ b/pc/jsep_transport.h
@@ -12,7 +12,6 @@
 #define PC_JSEP_TRANSPORT_H_
 
 #include <functional>
-#include <map>
 #include <memory>
 #include <optional>
 #include <string>
@@ -25,16 +24,13 @@
 #include "api/scoped_refptr.h"
 #include "api/sequence_checker.h"
 #include "api/transport/data_channel_transport_interface.h"
+#include "call/payload_type_picker.h"
 #include "media/sctp/sctp_transport_internal.h"
-#include "p2p/base/dtls_transport.h"
 #include "p2p/base/dtls_transport_internal.h"
 #include "p2p/base/ice_transport_internal.h"
-#include "p2p/base/p2p_constants.h"
 #include "p2p/base/transport_description.h"
-#include "p2p/base/transport_info.h"
 #include "pc/dtls_srtp_transport.h"
 #include "pc/dtls_transport.h"
-#include "pc/payload_type_picker.h"
 #include "pc/rtcp_mux_filter.h"
 #include "pc/rtp_transport.h"
 #include "pc/rtp_transport_internal.h"
@@ -42,7 +38,6 @@
 #include "pc/session_description.h"
 #include "pc/srtp_transport.h"
 #include "pc/transport_stats.h"
-#include "rtc_base/checks.h"
 #include "rtc_base/rtc_certificate.h"
 #include "rtc_base/ssl_fingerprint.h"
 #include "rtc_base/ssl_stream_adapter.h"
diff --git a/pc/jsep_transport_controller.h b/pc/jsep_transport_controller.h
index d18a375..2846dab 100644
--- a/pc/jsep_transport_controller.h
+++ b/pc/jsep_transport_controller.h
@@ -18,11 +18,11 @@
 #include <memory>
 #include <optional>
 #include <string>
-#include <type_traits>
 #include <utility>
 #include <vector>
 
 #include "absl/functional/any_invocable.h"
+#include "absl/strings/string_view.h"
 #include "api/async_dns_resolver.h"
 #include "api/candidate.h"
 #include "api/crypto/crypto_options.h"
@@ -37,7 +37,10 @@
 #include "api/sequence_checker.h"
 #include "api/transport/data_channel_transport_interface.h"
 #include "api/transport/sctp_transport_factory_interface.h"
-#include "media/sctp/sctp_transport_internal.h"
+#include "call/payload_type.h"
+#include "call/payload_type_picker.h"
+#include "media/base/codec.h"
+#include "modules/rtp_rtcp/source/rtp_packet_received.h"
 #include "p2p/base/dtls_transport.h"
 #include "p2p/base/dtls_transport_factory.h"
 #include "p2p/base/dtls_transport_internal.h"
@@ -59,9 +62,7 @@
 #include "pc/srtp_transport.h"
 #include "pc/transport_stats.h"
 #include "rtc_base/callback_list.h"
-#include "rtc_base/checks.h"
 #include "rtc_base/copy_on_write_buffer.h"
-#include "rtc_base/crypto_random.h"
 #include "rtc_base/rtc_certificate.h"
 #include "rtc_base/ssl_certificate.h"
 #include "rtc_base/ssl_stream_adapter.h"
@@ -76,7 +77,8 @@
 
 namespace webrtc {
 
-class JsepTransportController : public sigslot::has_slots<> {
+class JsepTransportController : public PayloadTypeSuggester,
+                                public sigslot::has_slots<> {
  public:
   // Used when the RtpTransport/DtlsTransport of the m= section is changed
   // because the section is rejected or BUNDLE is enabled.
@@ -240,7 +242,7 @@
   // The function will either return a PT already in use on the connection
   // or a newly suggested one.
   RTCErrorOr<PayloadType> SuggestPayloadType(const std::string& mid,
-                                             cricket::Codec codec);
+                                             cricket::Codec codec) override;
 
   // TODO(deadbeef): GetStats isn't const because all the way down to
   // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
diff --git a/test/peer_scenario/BUILD.gn b/test/peer_scenario/BUILD.gn
index dda6345..bf17818 100644
--- a/test/peer_scenario/BUILD.gn
+++ b/test/peer_scenario/BUILD.gn
@@ -27,17 +27,23 @@
       "..:fileutils",
       "..:frame_generator_capturer",
       "..:test_support",
+      "../../api:array_view",
       "../../api:candidate",
       "../../api:create_time_controller",
       "../../api:libjingle_peerconnection_api",
       "../../api:network_emulation_manager_api",
       "../../api:rtc_stats_api",
+      "../../api:scoped_refptr",
+      "../../api:sequence_checker",
       "../../api:time_controller",
       "../../api/audio_codecs:builtin_audio_decoder_factory",
       "../../api/audio_codecs:builtin_audio_encoder_factory",
       "../../api/environment",
       "../../api/rtc_event_log:rtc_event_log_factory",
       "../../api/task_queue:default_task_queue_factory",
+      "../../api/test/network_emulation",
+      "../../api/transport:datagram_transport_interface",
+      "../../api/transport:enums",
       "../../api/transport:field_trial_based_config",
       "../../api/video_codecs:video_decoder_factory_template",
       "../../api/video_codecs:video_decoder_factory_template_dav1d_adapter",
@@ -49,6 +55,9 @@
       "../../api/video_codecs:video_encoder_factory_template_libvpx_vp8_adapter",
       "../../api/video_codecs:video_encoder_factory_template_libvpx_vp9_adapter",
       "../../api/video_codecs:video_encoder_factory_template_open_h264_adapter",
+      "../../call:payload_type_picker",
+      "../../call:rtp_interfaces",
+      "../../call:rtp_receiver",
       "../../media:rtc_audio_video",
       "../../media:rtp_utils",
       "../../modules/audio_device:test_audio_device_module",
@@ -57,13 +66,19 @@
       "../../p2p:rtc_p2p",
       "../../p2p:transport_description",
       "../../pc:channel",
+      "../../pc:dtls_transport",
       "../../pc:jsep_transport_controller",
       "../../pc:pc_test_utils",
       "../../pc:rtp_transport_internal",
       "../../pc:session_description",
+      "../../rtc_base:checks",
+      "../../rtc_base:crypto_random",
+      "../../rtc_base:macromagic",
       "../../rtc_base:null_socket_server",
+      "../../rtc_base:ssl",
       "../../rtc_base:stringutils",
       "../../rtc_base:task_queue_for_test",
+      "../../rtc_base/third_party/sigslot",
       "../../test:explicit_key_value_config",
       "../../test:scoped_key_value_config",
       "../logging:log_writer",
diff --git a/test/peer_scenario/scenario_connection.cc b/test/peer_scenario/scenario_connection.cc
index db3a290..856a092 100644
--- a/test/peer_scenario/scenario_connection.cc
+++ b/test/peer_scenario/scenario_connection.cc
@@ -9,15 +9,46 @@
  */
 #include "test/peer_scenario/scenario_connection.h"
 
-#include "absl/memory/memory.h"
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "api/array_view.h"
+#include "api/candidate.h"
+#include "api/environment/environment.h"
+#include "api/jsep.h"
+#include "api/peer_connection_interface.h"
+#include "api/scoped_refptr.h"
+#include "api/sequence_checker.h"
+#include "api/test/network_emulation/network_emulation_interfaces.h"
+#include "api/test/network_emulation_manager.h"
+#include "api/transport/data_channel_transport_interface.h"
+#include "api/transport/enums.h"
+#include "call/payload_type_picker.h"
+#include "call/rtp_demuxer.h"
+#include "call/rtp_packet_sink_interface.h"
 #include "media/base/rtp_utils.h"
 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
+#include "p2p/base/dtls_transport_internal.h"
+#include "p2p/base/p2p_constants.h"
+#include "p2p/base/port_allocator.h"
+#include "p2p/base/transport_description.h"
 #include "p2p/client/basic_port_allocator.h"
-#include "pc/channel.h"
+#include "pc/dtls_transport.h"
 #include "pc/jsep_transport_controller.h"
 #include "pc/rtp_transport_internal.h"
 #include "pc/session_description.h"
+#include "rtc_base/checks.h"
+#include "rtc_base/crypto_random.h"
+#include "rtc_base/rtc_certificate.h"
+#include "rtc_base/ssl_fingerprint.h"
+#include "rtc_base/ssl_identity.h"
 #include "rtc_base/task_queue_for_test.h"
+#include "rtc_base/third_party/sigslot/sigslot.h"
+#include "rtc_base/thread_annotations.h"
+#include "test/network/network_emulation_manager.h"
 
 namespace webrtc {
 class ScenarioIceConnectionImpl : public ScenarioIceConnection,