Delete ChannelSend::RegisterTransport, replacing by construction argument

Bug: webrtc:9719
Change-Id: If3960de660cfa7a65c8bf9375ceb0af0a67d376c
Reviewed-on: https://webrtc-review.googlesource.com/c/111256
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25784}
diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc
index 082c557..75e6efb 100644
--- a/audio/audio_send_stream.cc
+++ b/audio/audio_send_stream.cc
@@ -111,6 +111,7 @@
                       voe::CreateChannelSend(worker_queue,
                                              module_process_thread,
                                              config.media_transport,
+                                             config.send_transport,
                                              rtcp_rtt_stats,
                                              event_log,
                                              config.frame_encryptor,
@@ -171,7 +172,6 @@
   RTC_DCHECK(!sending_);
   if (rtp_transport_) {
     rtp_transport_->DeRegisterPacketFeedbackObserver(this);
-    channel_send_->RegisterTransport(nullptr);
     channel_send_->ResetSenderCongestionControlObjects();
   }
 }
@@ -214,6 +214,10 @@
   const auto& channel_send = stream->channel_send_;
   const auto& old_config = stream->config_;
 
+  // Configuration parameters which cannot be changed.
+  RTC_DCHECK(first_time ||
+             old_config.send_transport == new_config.send_transport);
+
   if (first_time || old_config.rtp.ssrc != new_config.rtp.ssrc) {
     channel_send->SetLocalSSRC(new_config.rtp.ssrc);
     if (stream->suspended_rtp_state_) {
@@ -224,10 +228,6 @@
     channel_send->SetRTCP_CNAME(new_config.rtp.c_name);
   }
 
-  if (first_time || new_config.send_transport != old_config.send_transport) {
-    channel_send->RegisterTransport(new_config.send_transport);
-  }
-
   // Enable the frame encryptor if a new frame encryptor has been provided.
   if (first_time || new_config.frame_encryptor != old_config.frame_encryptor) {
     channel_send->SetFrameEncryptor(new_config.frame_encryptor);
diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc
index 13e5884..e400ada 100644
--- a/audio/audio_send_stream_unittest.cc
+++ b/audio/audio_send_stream_unittest.cc
@@ -211,7 +211,6 @@
           .Times(1);
     }
     EXPECT_CALL(*channel_send_, ResetSenderCongestionControlObjects()).Times(1);
-    EXPECT_CALL(*channel_send_, RegisterTransport(nullptr)).Times(2);
   }
 
   void SetupMockForSetupSendCodec(bool expect_set_encoder_call) {
diff --git a/audio/channel_send.cc b/audio/channel_send.cc
index 31fe25f..c458fe4 100644
--- a/audio/channel_send.cc
+++ b/audio/channel_send.cc
@@ -91,6 +91,7 @@
   ChannelSend(rtc::TaskQueue* encoder_queue,
               ProcessThread* module_process_thread,
               MediaTransportInterface* media_transport,
+              Transport* rtp_transport,
               RtcpRttStats* rtcp_rtt_stats,
               RtcEventLog* rtc_event_log,
               FrameEncryptorInterface* frame_encryptor,
@@ -115,7 +116,6 @@
   int GetBitrate() const override;
 
   // Network
-  void RegisterTransport(Transport* transport) override;
   bool ReceivedRTCPPacket(const uint8_t* data, size_t length) override;
 
   // Muting, Volume and Level.
@@ -254,7 +254,7 @@
 
   // uses
   ProcessThread* const _moduleProcessThreadPtr;
-  Transport* _transportPtr;  // WebRtc socket or external transport
+  Transport* const _transportPtr;  // WebRtc socket or external transport
   RmsLevel rms_level_ RTC_GUARDED_BY(encoder_queue_);
   bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
   bool previous_frame_muted_ RTC_GUARDED_BY(encoder_queue_);
@@ -683,6 +683,7 @@
 ChannelSend::ChannelSend(rtc::TaskQueue* encoder_queue,
                          ProcessThread* module_process_thread,
                          MediaTransportInterface* media_transport,
+                         Transport* rtp_transport,
                          RtcpRttStats* rtcp_rtt_stats,
                          RtcEventLog* rtc_event_log,
                          FrameEncryptorInterface* frame_encryptor,
@@ -694,7 +695,7 @@
                       // random offset
       send_sequence_number_(0),
       _moduleProcessThreadPtr(module_process_thread),
-      _transportPtr(NULL),
+      _transportPtr(rtp_transport),
       input_mute_(false),
       previous_frame_muted_(false),
       _includeAudioLevelIndication(false),
@@ -953,12 +954,6 @@
   });
 }
 
-void ChannelSend::RegisterTransport(Transport* transport) {
-  RTC_DCHECK_RUN_ON(&worker_thread_checker_);
-  rtc::CritScope cs(&_callbackCritSect);
-  _transportPtr = transport;
-}
-
 // TODO(nisse): Delete always-true return value.
 bool ChannelSend::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
   // May be called on either worker thread or network thread.
@@ -1344,6 +1339,7 @@
     rtc::TaskQueue* encoder_queue,
     ProcessThread* module_process_thread,
     MediaTransportInterface* media_transport,
+    Transport* rtp_transport,
     RtcpRttStats* rtcp_rtt_stats,
     RtcEventLog* rtc_event_log,
     FrameEncryptorInterface* frame_encryptor,
@@ -1351,9 +1347,9 @@
     bool extmap_allow_mixed,
     int rtcp_report_interval_ms) {
   return absl::make_unique<ChannelSend>(
-      encoder_queue, module_process_thread, media_transport, rtcp_rtt_stats,
-      rtc_event_log, frame_encryptor, crypto_options, extmap_allow_mixed,
-      rtcp_report_interval_ms);
+      encoder_queue, module_process_thread, media_transport, rtp_transport,
+      rtcp_rtt_stats, rtc_event_log, frame_encryptor, crypto_options,
+      extmap_allow_mixed, rtcp_report_interval_ms);
 }
 
 }  // namespace voe
diff --git a/audio/channel_send.h b/audio/channel_send.h
index 231fda6..083e9a6 100644
--- a/audio/channel_send.h
+++ b/audio/channel_send.h
@@ -55,7 +55,6 @@
  public:
   virtual ~ChannelSendInterface() = default;
 
-  virtual void RegisterTransport(Transport* transport) = 0;
   virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0;
 
   virtual CallSendStatistics GetRTCPStatistics() const = 0;
@@ -115,6 +114,7 @@
     rtc::TaskQueue* encoder_queue,
     ProcessThread* module_process_thread,
     MediaTransportInterface* media_transport,
+    Transport* rtp_transport,
     RtcpRttStats* rtcp_rtt_stats,
     RtcEventLog* rtc_event_log,
     FrameEncryptorInterface* frame_encryptor,
diff --git a/audio/mock_voe_channel_proxy.h b/audio/mock_voe_channel_proxy.h
index fe49359..eee25c5 100644
--- a/audio/mock_voe_channel_proxy.h
+++ b/audio/mock_voe_channel_proxy.h
@@ -90,7 +90,6 @@
   MOCK_METHOD2(SendTelephoneEventOutband, bool(int event, int duration_ms));
   MOCK_METHOD1(OnBitrateAllocation, void(BitrateAllocationUpdate update));
   MOCK_METHOD1(SetInputMute, void(bool muted));
-  MOCK_METHOD1(RegisterTransport, void(Transport* transport));
   MOCK_METHOD2(ReceivedRTCPPacket, bool(const uint8_t* packet, size_t length));
   // GMock doesn't like move-only types, like std::unique_ptr.
   virtual void ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame) {