Move ownership of RTPSenderAudio to ChannelSend.

This change takes out responsibility for packetization from the
RtpRtcp class, and deletes the method RtpRtcp::SendOutgoingData.

Video packetization was similarly moved in cl
https://webrtc-review.googlesource.com/c/src/+/123187

Bug: webrtc:7135
Change-Id: I0953125a5ca22a2ce51761b83693e0bb8ea74cd8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125721
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27000}
diff --git a/modules/rtp_rtcp/include/rtp_rtcp.h b/modules/rtp_rtcp/include/rtp_rtcp.h
index 8e1f98b..34ccfeb 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp.h
+++ b/modules/rtp_rtcp/include/rtp_rtcp.h
@@ -146,11 +146,6 @@
   // FEC/ULP/RED overhead (when FEC is enabled).
   virtual size_t MaxRtpPacketSize() const = 0;
 
-  virtual void RegisterAudioSendPayload(int payload_type,
-                                        absl::string_view payload_name,
-                                        int frequency,
-                                        int channels,
-                                        int rate) = 0;
   virtual void RegisterSendPayloadFrequency(int payload_type,
                                             int payload_frequency) = 0;
 
@@ -257,27 +252,6 @@
   virtual RTPSender* RtpSender() = 0;
   virtual const RTPSender* RtpSender() const = 0;
 
-  // Used by the codec module to deliver a video or audio frame for
-  // packetization.
-  // |frame_type|    - type of frame to send
-  // |payload_type|  - payload type of frame to send
-  // |timestamp|     - timestamp of frame to send
-  // |payload_data|  - payload buffer of frame to send
-  // |payload_size|  - size of payload buffer to send
-  // |fragmentation| - fragmentation offset data for fragmented frames such
-  //                   as layers or RED
-  // |transport_frame_id_out| - set to RTP timestamp.
-  // Returns true on success.
-  virtual bool SendOutgoingData(FrameType frame_type,
-                                int8_t payload_type,
-                                uint32_t timestamp,
-                                int64_t capture_time_ms,
-                                const uint8_t* payload_data,
-                                size_t payload_size,
-                                const RTPFragmentationHeader* fragmentation,
-                                const RTPVideoHeader* rtp_video_header,
-                                uint32_t* transport_frame_id_out) = 0;
-
   // Record that a frame is about to be sent. Returns true on success, and false
   // if the module isn't ready to send.
   virtual bool OnSendingRtpFrame(uint32_t timestamp,
@@ -432,23 +406,6 @@
       const VideoBitrateAllocation& bitrate) = 0;
 
   // **************************************************************************
-  // Audio
-  // **************************************************************************
-
-  // Sends a TelephoneEvent tone using RFC 2833 (4733).
-  // Returns -1 on failure else 0.
-  virtual int32_t SendTelephoneEventOutband(uint8_t key,
-                                            uint16_t time_ms,
-                                            uint8_t level) = 0;
-
-  // Store the audio level in dBov for header-extension-for-audio-level-
-  // indication.
-  // This API shall be called before transmision of an RTP packet to ensure
-  // that the |level| part of the extended RTP header is updated.
-  // return -1 on failure else 0.
-  virtual int32_t SetAudioLevel(uint8_t level_dbov) = 0;
-
-  // **************************************************************************
   // Video
   // **************************************************************************
 
diff --git a/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h
index 7d4f0f1..668d527 100644
--- a/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h
+++ b/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h
@@ -37,12 +37,6 @@
   MOCK_METHOD1(SetRemoteSSRC, void(uint32_t ssrc));
   MOCK_METHOD1(SetMaxRtpPacketSize, void(size_t size));
   MOCK_CONST_METHOD0(MaxRtpPacketSize, size_t());
-  MOCK_METHOD5(RegisterAudioSendPayload,
-               void(int payload_type,
-                    absl::string_view payload_name,
-                    int frequency,
-                    int channels,
-                    int rate));
   MOCK_METHOD2(RegisterSendPayloadFrequency,
                void(int payload_type, int frequency));
   MOCK_METHOD1(DeRegisterSendPayload, int32_t(int8_t payload_type));
@@ -87,16 +81,6 @@
                           uint32_t* nack_rate));
   MOCK_CONST_METHOD1(EstimatedReceiveBandwidth,
                      int(uint32_t* available_bandwidth));
-  MOCK_METHOD9(SendOutgoingData,
-               bool(FrameType frame_type,
-                    int8_t payload_type,
-                    uint32_t timestamp,
-                    int64_t capture_time_ms,
-                    const uint8_t* payload_data,
-                    size_t payload_size,
-                    const RTPFragmentationHeader* fragmentation,
-                    const RTPVideoHeader* rtp_video_header,
-                    uint32_t* frame_id_out));
   MOCK_METHOD4(OnSendingRtpFrame, bool(uint32_t, int64_t, int, bool));
   MOCK_METHOD5(TimeToSendPacket,
                bool(uint32_t ssrc,
@@ -162,9 +146,6 @@
   MOCK_METHOD1(RegisterRtcpStatisticsCallback, void(RtcpStatisticsCallback*));
   MOCK_METHOD0(GetRtcpStatisticsCallback, RtcpStatisticsCallback*());
   MOCK_METHOD1(SendFeedbackPacket, bool(const rtcp::TransportFeedback& packet));
-  MOCK_METHOD3(SendTelephoneEventOutband,
-               int32_t(uint8_t key, uint16_t time_ms, uint8_t level));
-  MOCK_METHOD1(SetAudioLevel, int32_t(uint8_t level_dbov));
   MOCK_METHOD1(SetTargetSendBitrate, void(uint32_t bitrate_bps));
   MOCK_METHOD1(SetKeyFrameRequestMethod, int32_t(KeyFrameRequestMethod method));
   MOCK_METHOD0(RequestKeyFrame, int32_t());
diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
index 4e06002..6d1c9e2 100644
--- a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
+++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
@@ -116,9 +116,7 @@
         configuration.extmap_allow_mixed,
         configuration.field_trials ? *configuration.field_trials
                                    : default_trials));
-    if (configuration.audio) {
-      audio_ = absl::make_unique<RTPSenderAudio>(clock_, rtp_sender_.get());
-    }
+
     // Make sure rtcp sender use same timestamp offset as rtp sender.
     rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset());
 
@@ -270,17 +268,6 @@
   rtcp_receiver_.IncomingPacket(rtcp_packet, length);
 }
 
-void ModuleRtpRtcpImpl::RegisterAudioSendPayload(int payload_type,
-                                                 absl::string_view payload_name,
-                                                 int frequency,
-                                                 int channels,
-                                                 int rate) {
-  RTC_DCHECK(audio_);
-  rtcp_sender_.SetRtpClockRate(payload_type, frequency);
-  RTC_CHECK_EQ(0, audio_->RegisterAudioPayload(payload_name, payload_type,
-                                               frequency, channels, rate));
-}
-
 void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type,
                                                      int payload_frequency) {
   rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency);
@@ -425,30 +412,6 @@
   rtp_sender_->SetAsPartOfAllocation(part_of_allocation);
 }
 
-bool ModuleRtpRtcpImpl::SendOutgoingData(
-    FrameType frame_type,
-    int8_t payload_type,
-    uint32_t time_stamp,
-    int64_t capture_time_ms,
-    const uint8_t* payload_data,
-    size_t payload_size,
-    const RTPFragmentationHeader* fragmentation,
-    const RTPVideoHeader* rtp_video_header,
-    uint32_t* transport_frame_id_out) {
-  OnSendingRtpFrame(time_stamp, capture_time_ms, payload_type,
-                    kVideoFrameKey == frame_type);
-
-  const uint32_t rtp_timestamp = time_stamp + rtp_sender_->TimestampOffset();
-  if (transport_frame_id_out)
-    *transport_frame_id_out = rtp_timestamp;
-
-  RTC_DCHECK(audio_);
-  RTC_DCHECK(fragmentation == nullptr);
-
-  return audio_->SendAudio(frame_type, payload_type, rtp_timestamp,
-                           payload_data, payload_size);
-}
-
 bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp,
                                           int64_t capture_time_ms,
                                           int payload_type,
@@ -787,17 +750,6 @@
   return rtcp_sender_.SendFeedbackPacket(packet);
 }
 
-// Send a TelephoneEvent tone using RFC 2833 (4733).
-int32_t ModuleRtpRtcpImpl::SendTelephoneEventOutband(const uint8_t key,
-                                                     const uint16_t time_ms,
-                                                     const uint8_t level) {
-  return audio_ ? audio_->SendTelephoneEvent(key, time_ms, level) : -1;
-}
-
-int32_t ModuleRtpRtcpImpl::SetAudioLevel(const uint8_t level_d_bov) {
-  return audio_ ? audio_->SetAudioLevel(level_d_bov) : -1;
-}
-
 int32_t ModuleRtpRtcpImpl::SetKeyFrameRequestMethod(
     const KeyFrameRequestMethod method) {
   key_frame_req_method_ = method;
diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/modules/rtp_rtcp/source/rtp_rtcp_impl.h
index 20eb179..4b1c927 100644
--- a/modules/rtp_rtcp/source/rtp_rtcp_impl.h
+++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.h
@@ -32,8 +32,6 @@
 #include "modules/rtp_rtcp/source/rtcp_receiver.h"
 #include "modules/rtp_rtcp/source/rtcp_sender.h"
 #include "modules/rtp_rtcp/source/rtp_sender.h"
-#include "modules/rtp_rtcp/source/rtp_sender_audio.h"
-#include "modules/rtp_rtcp/source/rtp_sender_video.h"
 #include "rtc_base/critical_section.h"
 #include "rtc_base/gtest_prod_util.h"
 
@@ -64,12 +62,6 @@
   void SetRemoteSSRC(uint32_t ssrc) override;
 
   // Sender part.
-
-  void RegisterAudioSendPayload(int payload_type,
-                                absl::string_view payload_name,
-                                int frequency,
-                                int channels,
-                                int rate) override;
   void RegisterSendPayloadFrequency(int payload_type,
                                     int payload_frequency) override;
 
@@ -137,18 +129,6 @@
 
   void SetAsPartOfAllocation(bool part_of_allocation) override;
 
-  // Used by the codec module to deliver a video or audio frame for
-  // packetization.
-  bool SendOutgoingData(FrameType frame_type,
-                        int8_t payload_type,
-                        uint32_t time_stamp,
-                        int64_t capture_time_ms,
-                        const uint8_t* payload_data,
-                        size_t payload_size,
-                        const RTPFragmentationHeader* fragmentation,
-                        const RTPVideoHeader* rtp_video_header,
-                        uint32_t* transport_frame_id_out) override;
-
   bool OnSendingRtpFrame(uint32_t timestamp,
                          int64_t capture_time_ms,
                          int payload_type,
@@ -270,17 +250,6 @@
 
   bool RtcpXrRrtrStatus() const override;
 
-  // Audio part.
-
-  // Send a TelephoneEvent tone using RFC 2833 (4733).
-  int32_t SendTelephoneEventOutband(uint8_t key,
-                                    uint16_t time_ms,
-                                    uint8_t level) override;
-
-  // Store the audio level in d_bov for header-extension-for-audio-level-
-  // indication.
-  int32_t SetAudioLevel(uint8_t level_d_bov) override;
-
   // Video part.
 
   // Set method for requesting a new key frame.
@@ -346,7 +315,6 @@
   bool TimeToSendFullNackList(int64_t now) const;
 
   std::unique_ptr<RTPSender> rtp_sender_;
-  std::unique_ptr<RTPSenderAudio> audio_;
   RTCPSender rtcp_sender_;
   RTCPReceiver rtcp_receiver_;
 
diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
index da541a5..98067b2 100644
--- a/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
+++ b/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
@@ -22,6 +22,7 @@
 #include "modules/rtp_rtcp/source/rtcp_packet/nack.h"
 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
 #include "modules/rtp_rtcp/source/rtp_rtcp_impl.h"
+#include "modules/rtp_rtcp/source/rtp_sender_video.h"
 #include "rtc_base/rate_limiter.h"
 #include "test/gmock.h"
 #include "test/gtest.h"
diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc
index 56d0884..c049530 100644
--- a/modules/rtp_rtcp/source/rtp_sender_audio.cc
+++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc
@@ -47,7 +47,9 @@
 }  // namespace
 
 RTPSenderAudio::RTPSenderAudio(Clock* clock, RTPSender* rtp_sender)
-    : clock_(clock), rtp_sender_(rtp_sender) {}
+    : clock_(clock), rtp_sender_(rtp_sender) {
+  RTC_DCHECK(clock_);
+}
 
 RTPSenderAudio::~RTPSenderAudio() {}