Refactoring AudioSender api out of AudioSendStream for more abstraction to reuse AudioTransportImpl for voip api

Bug: webrtc:11251
Change-Id: Id3b6ff1814931d8250c4aaac59e494521fbe93ec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/164560
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Tim Na <natim@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30238}
diff --git a/audio/BUILD.gn b/audio/BUILD.gn
index a6d7ed4..6f815f3 100644
--- a/audio/BUILD.gn
+++ b/audio/BUILD.gn
@@ -54,6 +54,7 @@
     "../api/rtc_event_log",
     "../api/task_queue",
     "../api/transport/rtp:rtp_source",
+    "../call:audio_sender_interface",
     "../call:bitrate_allocator",
     "../call:call_interfaces",
     "../call:rtp_interfaces",
diff --git a/audio/audio_state.cc b/audio/audio_state.cc
index 3ca1dd7..1a4fd77 100644
--- a/audio/audio_state.cc
+++ b/audio/audio_state.cc
@@ -16,6 +16,7 @@
 #include <vector>
 
 #include "audio/audio_receive_stream.h"
+#include "audio/audio_send_stream.h"
 #include "modules/audio_device/include/audio_device.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
@@ -159,16 +160,16 @@
 
 void AudioState::UpdateAudioTransportWithSendingStreams() {
   RTC_DCHECK(thread_checker_.IsCurrent());
-  std::vector<webrtc::AudioSendStream*> sending_streams;
+  std::vector<AudioSender*> audio_senders;
   int max_sample_rate_hz = 8000;
   size_t max_num_channels = 1;
   for (const auto& kv : sending_streams_) {
-    sending_streams.push_back(kv.first);
+    audio_senders.push_back(kv.first);
     max_sample_rate_hz = std::max(max_sample_rate_hz, kv.second.sample_rate_hz);
     max_num_channels = std::max(max_num_channels, kv.second.num_channels);
   }
-  audio_transport_.UpdateSendingStreams(std::move(sending_streams),
-                                        max_sample_rate_hz, max_num_channels);
+  audio_transport_.UpdateAudioSenders(std::move(audio_senders),
+                                      max_sample_rate_hz, max_num_channels);
 }
 
 void AudioState::UpdateNullAudioPollerState() {
diff --git a/audio/audio_transport_impl.cc b/audio/audio_transport_impl.cc
index aca6f9b..347e86b 100644
--- a/audio/audio_transport_impl.cc
+++ b/audio/audio_transport_impl.cc
@@ -16,7 +16,7 @@
 
 #include "audio/remix_resample.h"
 #include "audio/utility/audio_frame_operations.h"
-#include "call/audio_send_stream.h"
+#include "call/audio_sender.h"
 #include "rtc_base/checks.h"
 
 namespace webrtc {
@@ -149,15 +149,15 @@
     typing_noise_detected_ = typing_detected;
 
     RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0);
-    if (!sending_streams_.empty()) {
-      auto it = sending_streams_.begin();
-      while (++it != sending_streams_.end()) {
+    if (!audio_senders_.empty()) {
+      auto it = audio_senders_.begin();
+      while (++it != audio_senders_.end()) {
         std::unique_ptr<AudioFrame> audio_frame_copy(new AudioFrame());
         audio_frame_copy->CopyFrom(*audio_frame);
         (*it)->SendAudioData(std::move(audio_frame_copy));
       }
       // Send the original frame to the first stream w/o copying.
-      (*sending_streams_.begin())->SendAudioData(std::move(audio_frame));
+      (*audio_senders_.begin())->SendAudioData(std::move(audio_frame));
     }
   }
 
@@ -227,12 +227,11 @@
   RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames);
 }
 
-void AudioTransportImpl::UpdateSendingStreams(
-    std::vector<AudioSendStream*> streams,
-    int send_sample_rate_hz,
-    size_t send_num_channels) {
+void AudioTransportImpl::UpdateAudioSenders(std::vector<AudioSender*> senders,
+                                            int send_sample_rate_hz,
+                                            size_t send_num_channels) {
   rtc::CritScope lock(&capture_lock_);
-  sending_streams_ = std::move(streams);
+  audio_senders_ = std::move(senders);
   send_sample_rate_hz_ = send_sample_rate_hz;
   send_num_channels_ = send_num_channels;
 }
diff --git a/audio/audio_transport_impl.h b/audio/audio_transport_impl.h
index 8a74d98..2d9b4cf 100644
--- a/audio/audio_transport_impl.h
+++ b/audio/audio_transport_impl.h
@@ -25,7 +25,7 @@
 
 namespace webrtc {
 
-class AudioSendStream;
+class AudioSender;
 
 class AudioTransportImpl : public AudioTransport {
  public:
@@ -60,9 +60,9 @@
                       int64_t* elapsed_time_ms,
                       int64_t* ntp_time_ms) override;
 
-  void UpdateSendingStreams(std::vector<AudioSendStream*> streams,
-                            int send_sample_rate_hz,
-                            size_t send_num_channels);
+  void UpdateAudioSenders(std::vector<AudioSender*> senders,
+                          int send_sample_rate_hz,
+                          size_t send_num_channels);
   void SetStereoChannelSwapping(bool enable);
   bool typing_noise_detected() const;
 
@@ -72,7 +72,7 @@
 
   // Capture side.
   rtc::CriticalSection capture_lock_;
-  std::vector<AudioSendStream*> sending_streams_ RTC_GUARDED_BY(capture_lock_);
+  std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
   int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
   size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
   bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false;
diff --git a/call/BUILD.gn b/call/BUILD.gn
index e0a3114..388ff06 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -28,6 +28,7 @@
     sources += [ "audio_send_stream.cc" ]
   }
   deps = [
+    ":audio_sender_interface",
     ":rtp_interfaces",
     ":video_stream_api",
     "../api:fec_controller_api",
@@ -63,6 +64,16 @@
   ]
 }
 
+rtc_source_set("audio_sender_interface") {
+  visibility = [ "*" ]
+  sources = [
+    "audio_sender.h",
+  ]
+  deps = [
+    "../api/audio:audio_frame_api",
+  ]
+}
+
 # TODO(nisse): These RTP targets should be moved elsewhere
 # when interfaces have stabilized. See also TODO for |mock_rtp_interfaces|.
 rtc_library("rtp_interfaces") {
diff --git a/call/audio_send_stream.h b/call/audio_send_stream.h
index 734be30..e60bfcd 100644
--- a/call/audio_send_stream.h
+++ b/call/audio_send_stream.h
@@ -25,15 +25,14 @@
 #include "api/crypto/frame_encryptor_interface.h"
 #include "api/rtp_parameters.h"
 #include "api/scoped_refptr.h"
+#include "call/audio_sender.h"
 #include "call/rtp_config.h"
 #include "modules/audio_processing/include/audio_processing_statistics.h"
 #include "modules/rtp_rtcp/include/report_block_data.h"
 
 namespace webrtc {
 
-class AudioFrame;
-
-class AudioSendStream {
+class AudioSendStream : public AudioSender {
  public:
   struct Stats {
     Stats();
@@ -174,10 +173,6 @@
   // When a stream is stopped, it can't receive, process or deliver packets.
   virtual void Stop() = 0;
 
-  // Encode and send audio.
-  virtual void SendAudioData(
-      std::unique_ptr<webrtc::AudioFrame> audio_frame) = 0;
-
   // TODO(solenberg): Make payload_type a config property instead.
   virtual bool SendTelephoneEvent(int payload_type,
                                   int payload_frequency,
@@ -189,6 +184,7 @@
   virtual Stats GetStats() const = 0;
   virtual Stats GetStats(bool has_remote_tracks) const = 0;
 };
+
 }  // namespace webrtc
 
 #endif  // CALL_AUDIO_SEND_STREAM_H_
diff --git a/call/audio_sender.h b/call/audio_sender.h
new file mode 100644
index 0000000..daab070
--- /dev/null
+++ b/call/audio_sender.h
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef CALL_AUDIO_SENDER_H_
+#define CALL_AUDIO_SENDER_H_
+
+#include <memory>
+
+#include "api/audio/audio_frame.h"
+
+namespace webrtc {
+
+class AudioSender {
+ public:
+  // Encode and send audio.
+  virtual void SendAudioData(std::unique_ptr<AudioFrame> audio_frame) = 0;
+
+  virtual ~AudioSender() = default;
+};
+
+}  // namespace webrtc
+
+#endif  // CALL_AUDIO_SENDER_H_