Use the VideoMediaChannelShim for all cases

This allows us to decouple implementation classes from the
MediaChannel class.

Bug: webrtc:13931
Change-Id: I22f166cac17c344f943a0382048e8086a193affa
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/307000
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40179}
diff --git a/media/base/media_channel_shim.h b/media/base/media_channel_shim.h
index 458d2a0..c50c5b1 100644
--- a/media/base/media_channel_shim.h
+++ b/media/base/media_channel_shim.h
@@ -195,8 +195,11 @@
   void SetSendCodecChangedCallback(
       absl::AnyInvocable<void()> callback) override {
     // This callback is used internally by the shim, so should not be called by
-    // users.
-    RTC_CHECK_NOTREACHED();
+    // users for the "both" case.
+    if (send_impl_ && receive_impl_) {
+      RTC_CHECK_NOTREACHED();
+    }
+    send_impl()->SetSendCodecChangedCallback(std::move(callback));
   }
 
   // Implementation of Delayable
diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc
index bf547b7..9f7219d 100644
--- a/media/engine/webrtc_video_engine.cc
+++ b/media/engine/webrtc_video_engine.cc
@@ -627,22 +627,25 @@
     const webrtc::CryptoOptions& crypto_options,
     webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) {
   RTC_LOG(LS_INFO) << "CreateMediaChannel. Options: " << options.ToString();
-  if (role == MediaChannel::Role::kBoth) {
-    auto send_channel = std::make_unique<WebRtcVideoChannel>(
+  std::unique_ptr<VideoMediaSendChannelInterface> send_channel;
+  std::unique_ptr<VideoMediaReceiveChannelInterface> receive_channel;
+  if (role == MediaChannel::Role::kSend || role == MediaChannel::Role::kBoth) {
+    send_channel = std::make_unique<WebRtcVideoChannel>(
         MediaChannel::Role::kSend, call, config, options, crypto_options,
         encoder_factory_.get(), decoder_factory_.get(),
         video_bitrate_allocator_factory);
-    auto receive_channel = std::make_unique<WebRtcVideoChannel>(
+  }
+  if (role == MediaChannel::Role::kReceive ||
+      role == MediaChannel::Role::kBoth) {
+    receive_channel = std::make_unique<WebRtcVideoChannel>(
         MediaChannel::Role::kReceive, call, config, options, crypto_options,
         encoder_factory_.get(), decoder_factory_.get(),
         video_bitrate_allocator_factory);
-    return new VideoMediaShimChannel(std::move(send_channel),
-                                     std::move(receive_channel));
   }
-  return new WebRtcVideoChannel(role, call, config, options, crypto_options,
-                                encoder_factory_.get(), decoder_factory_.get(),
-                                video_bitrate_allocator_factory);
+  return new VideoMediaShimChannel(std::move(send_channel),
+                                   std::move(receive_channel));
 }
+
 std::vector<VideoCodec> WebRtcVideoEngine::send_codecs(bool include_rtx) const {
   return GetPayloadTypesAndDefaultCodecs(encoder_factory_.get(),
                                          /*is_decoder_factory=*/false,