Change MediaChannel to have a Role parameter

This allows MediaChannel to know whether it's being used
for sending, receiving, or both. This is a preparatory CL
for landing the split of MediaChannel usage into sending and
receiving objects.

Bug: webrtc:13931
Change-Id: If518c8b53d5256771200a42e1b5f2b3321d26d8c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/292860
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39283}
diff --git a/pc/channel_unittest.cc b/pc/channel_unittest.cc
index 27ad96a..1635ea5 100644
--- a/pc/channel_unittest.cc
+++ b/pc/channel_unittest.cc
@@ -151,9 +151,11 @@
 
   void CreateChannels(int flags1, int flags2) {
     CreateChannels(std::make_unique<typename T::MediaChannel>(
-                       nullptr, typename T::Options(), network_thread_),
+                       cricket::MediaChannel::Role::kBoth, nullptr,
+                       typename T::Options(), network_thread_),
                    std::make_unique<typename T::MediaChannel>(
-                       nullptr, typename T::Options(), network_thread_),
+                       cricket::MediaChannel::Role::kBoth, nullptr,
+                       typename T::Options(), network_thread_),
                    flags1, flags2);
   }
   void CreateChannels(std::unique_ptr<typename T::MediaChannel> ch1,
diff --git a/pc/rtp_sender_receiver_unittest.cc b/pc/rtp_sender_receiver_unittest.cc
index 0404343..bcca2da 100644
--- a/pc/rtp_sender_receiver_unittest.cc
+++ b/pc/rtp_sender_receiver_unittest.cc
@@ -119,11 +119,13 @@
     // Create the channels, discard the result; we get them later.
     // Fake media channels are owned by the media engine.
     media_engine_->voice().CreateMediaChannel(
-        &fake_call_, cricket::MediaConfig(), cricket::AudioOptions(),
-        webrtc::CryptoOptions());
+        cricket::MediaChannel::Role::kBoth, &fake_call_, cricket::MediaConfig(),
+        cricket::AudioOptions(), webrtc::CryptoOptions());
     media_engine_->video().CreateMediaChannel(
-        &fake_call_, cricket::MediaConfig(), cricket::VideoOptions(),
-        webrtc::CryptoOptions(), video_bitrate_allocator_factory_.get());
+        cricket::MediaChannel::Role::kBoth, &fake_call_, cricket::MediaConfig(),
+        cricket::VideoOptions(), webrtc::CryptoOptions(),
+        video_bitrate_allocator_factory_.get());
+    // TODO(hta): Split into sender and receiver channels
 
     voice_media_channel_ = absl::WrapUnique(media_engine_->GetVoiceChannel(0));
     video_media_channel_ = absl::WrapUnique(media_engine_->GetVideoChannel(0));
diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc
index 76549d1..791eb8c 100644
--- a/pc/rtp_transceiver.cc
+++ b/pc/rtp_transceiver.cc
@@ -211,7 +211,8 @@
 
       cricket::VoiceMediaChannel* media_channel =
           media_engine()->voice().CreateMediaChannel(
-              call_ptr, media_config, audio_options, crypto_options);
+              cricket::MediaChannel::Role::kBoth, call_ptr, media_config,
+              audio_options, crypto_options);
       if (!media_channel) {
         return;
       }
@@ -231,8 +232,8 @@
       RTC_DCHECK_RUN_ON(context()->worker_thread());
       cricket::VideoMediaChannel* media_channel =
           media_engine()->video().CreateMediaChannel(
-              call_ptr, media_config, video_options, crypto_options,
-              video_bitrate_allocator_factory);
+              cricket::MediaChannel::Role::kBoth, call_ptr, media_config,
+              video_options, crypto_options, video_bitrate_allocator_factory);
       if (!media_channel) {
         return;
       }
diff --git a/pc/test/fake_peer_connection_for_stats.h b/pc/test/fake_peer_connection_for_stats.h
index b771d45..d1914fd 100644
--- a/pc/test/fake_peer_connection_for_stats.h
+++ b/pc/test/fake_peer_connection_for_stats.h
@@ -30,7 +30,8 @@
 class FakeVoiceMediaChannelForStats : public cricket::FakeVoiceMediaChannel {
  public:
   explicit FakeVoiceMediaChannelForStats(TaskQueueBase* network_thread)
-      : cricket::FakeVoiceMediaChannel(nullptr,
+      : cricket::FakeVoiceMediaChannel(MediaChannel::Role::kBoth,
+                                       nullptr,
                                        cricket::AudioOptions(),
                                        network_thread) {}
 
@@ -70,7 +71,8 @@
 class FakeVideoMediaChannelForStats : public cricket::FakeVideoMediaChannel {
  public:
   explicit FakeVideoMediaChannelForStats(TaskQueueBase* network_thread)
-      : cricket::FakeVideoMediaChannel(nullptr,
+      : cricket::FakeVideoMediaChannel(MediaChannel::Role::kBoth,
+                                       nullptr,
                                        cricket::VideoOptions(),
                                        network_thread) {}
 
diff --git a/pc/test/mock_voice_media_channel.h b/pc/test/mock_voice_media_channel.h
index 2e5a8b5..71f7a18 100644
--- a/pc/test/mock_voice_media_channel.h
+++ b/pc/test/mock_voice_media_channel.h
@@ -29,7 +29,7 @@
 class MockVoiceMediaChannel : public VoiceMediaChannel {
  public:
   explicit MockVoiceMediaChannel(webrtc::TaskQueueBase* network_thread)
-      : VoiceMediaChannel(network_thread) {}
+      : VoiceMediaChannel(MediaChannel::Role::kBoth, network_thread) {}
 
   MOCK_METHOD(void,
               SetInterface,
@@ -49,6 +49,9 @@
               (absl::string_view transport_name,
                const rtc::NetworkRoute& network_route),
               (override));
+  MOCK_METHOD(void, SetExtmapAllowMixed, (bool extmap_allow_mixed), (override));
+  MOCK_METHOD(bool, ExtmapAllowMixed, (), (const, override));
+  MOCK_METHOD(bool, HasNetworkInterface, (), (const, override));
   MOCK_METHOD(bool, AddSendStream, (const StreamParams& sp), (override));
   MOCK_METHOD(bool, RemoveSendStream, (uint32_t ssrc), (override));
   MOCK_METHOD(bool, AddRecvStream, (const StreamParams& sp), (override));
@@ -58,6 +61,7 @@
               GetUnsignaledSsrc,
               (),
               (const, override));
+  MOCK_METHOD(bool, SetLocalSsrc, (const StreamParams& sp), (override));
   MOCK_METHOD(void, OnDemuxerCriteriaUpdatePending, (), (override));
   MOCK_METHOD(void, OnDemuxerCriteriaUpdateComplete, (), (override));
   MOCK_METHOD(int, GetRtpSendTimeExtnId, (), (const, override));
diff --git a/pc/video_rtp_receiver_unittest.cc b/pc/video_rtp_receiver_unittest.cc
index 3ec9a28..5efd6df 100644
--- a/pc/video_rtp_receiver_unittest.cc
+++ b/pc/video_rtp_receiver_unittest.cc
@@ -40,7 +40,10 @@
         cricket::FakeVideoEngine* engine,
         const cricket::VideoOptions& options,
         TaskQueueBase* network_thread = rtc::Thread::Current())
-        : FakeVideoMediaChannel(engine, options, network_thread) {}
+        : FakeVideoMediaChannel(cricket::MediaChannel::Role::kBoth,
+                                engine,
+                                options,
+                                network_thread) {}
     MOCK_METHOD(void,
                 SetRecordableEncodedFrameCallback,
                 (uint32_t, std::function<void(const RecordableEncodedFrame&)>),