Change RtpReceivers to interact with the media channel directly

Currently, the RtpReceivers take a BaseChannel which is (mostly)
just used for proxying calls to the MediaChannel. This change
removes the extra layer and moves the proxying logic to RtpReceiver.

Bug: webrtc:8587
Change-Id: I01b0e3d57b4629e43d9d148cc94d6dd2941d320e
Reviewed-on: https://webrtc-review.googlesource.com/38120
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21562}
diff --git a/pc/rtptransceiver.cc b/pc/rtptransceiver.cc
index 61ebdc7..0dfc8b5 100644
--- a/pc/rtptransceiver.cc
+++ b/pc/rtptransceiver.cc
@@ -46,7 +46,18 @@
   if (channel) {
     RTC_DCHECK_EQ(media_type(), channel->media_type());
   }
+
+  if (channel_) {
+    channel_->SignalFirstPacketReceived.disconnect(this);
+  }
+
   channel_ = channel;
+
+  if (channel_) {
+    channel_->SignalFirstPacketReceived.connect(
+        this, &RtpTransceiver::OnFirstPacketReceived);
+  }
+
   for (auto sender : senders_) {
     if (media_type() == cricket::MEDIA_TYPE_AUDIO) {
       static_cast<AudioRtpSender*>(sender->internal())
@@ -56,16 +67,21 @@
           ->SetChannel(static_cast<cricket::VideoChannel*>(channel));
     }
   }
+
   for (auto receiver : receivers_) {
     if (!channel) {
       receiver->internal()->Stop();
     }
     if (media_type() == cricket::MEDIA_TYPE_AUDIO) {
+      auto* voice_channel = static_cast<cricket::VoiceChannel*>(channel);
       static_cast<AudioRtpReceiver*>(receiver->internal())
-          ->SetChannel(static_cast<cricket::VoiceChannel*>(channel));
+          ->SetMediaChannel(voice_channel ? voice_channel->media_channel()
+                                          : nullptr);
     } else {
+      auto* video_channel = static_cast<cricket::VideoChannel*>(channel);
       static_cast<VideoRtpReceiver*>(receiver->internal())
-          ->SetChannel(static_cast<cricket::VideoChannel*>(channel));
+          ->SetMediaChannel(video_channel ? video_channel->media_channel()
+                                          : nullptr);
     }
   }
 }
@@ -136,6 +152,12 @@
   return mid_;
 }
 
+void RtpTransceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) {
+  for (auto receiver : receivers_) {
+    receiver->internal()->NotifyFirstPacketReceived();
+  }
+}
+
 rtc::scoped_refptr<RtpSenderInterface> RtpTransceiver::sender() const {
   RTC_DCHECK(unified_plan_);
   RTC_CHECK_EQ(1u, senders_.size());