From b8c775aeaf41d796a85402116e7353efb3fb2202 Mon Sep 17 00:00:00 2001 From: Tim Na Date: Fri, 10 Jan 2020 10:33:05 -0800 Subject: [PATCH] Refactoring AudioSender api out of AudioSendStream for more abstraction to reuse AudioTransportImpl for voip api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:11251 Change-Id: Id3b6ff1814931d8250c4aaac59e494521fbe93ec Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/164560 Reviewed-by: Oskar Sundbom Reviewed-by: Patrik Höglund Reviewed-by: Mirko Bonadei Commit-Queue: Tim Na Cr-Commit-Position: refs/heads/master@{#30238} --- audio/BUILD.gn | 1 + audio/audio_state.cc | 9 +++++---- audio/audio_transport_impl.cc | 19 +++++++++---------- audio/audio_transport_impl.h | 10 +++++----- call/BUILD.gn | 11 +++++++++++ call/audio_send_stream.h | 10 +++------- call/audio_sender.h | 30 ++++++++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 call/audio_sender.h diff --git a/audio/BUILD.gn b/audio/BUILD.gn index a6d7ed40a4..6f815f3fd3 100644 --- a/audio/BUILD.gn +++ b/audio/BUILD.gn @@ -54,6 +54,7 @@ rtc_library("audio") { "../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 3ca1dd70b5..1a4fd77ed2 100644 --- a/audio/audio_state.cc +++ b/audio/audio_state.cc @@ -16,6 +16,7 @@ #include #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::SetStereoChannelSwapping(bool enable) { void AudioState::UpdateAudioTransportWithSendingStreams() { RTC_DCHECK(thread_checker_.IsCurrent()); - std::vector sending_streams; + std::vector 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 aca6f9baf6..347e86b532 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 @@ int32_t AudioTransportImpl::RecordedDataIsAvailable( 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 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 @@ void AudioTransportImpl::PullRenderData(int bits_per_sample, RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames); } -void AudioTransportImpl::UpdateSendingStreams( - std::vector streams, - int send_sample_rate_hz, - size_t send_num_channels) { +void AudioTransportImpl::UpdateAudioSenders(std::vector 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 8a74d98adf..2d9b4cf3a1 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 @@ class AudioTransportImpl : public AudioTransport { int64_t* elapsed_time_ms, int64_t* ntp_time_ms) override; - void UpdateSendingStreams(std::vector streams, - int send_sample_rate_hz, - size_t send_num_channels); + void UpdateAudioSenders(std::vector senders, + int send_sample_rate_hz, + size_t send_num_channels); void SetStereoChannelSwapping(bool enable); bool typing_noise_detected() const; @@ -72,7 +72,7 @@ class AudioTransportImpl : public AudioTransport { // Capture side. rtc::CriticalSection capture_lock_; - std::vector sending_streams_ RTC_GUARDED_BY(capture_lock_); + std::vector 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 e0a31144e4..388ff0608d 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -28,6 +28,7 @@ rtc_library("call_interfaces") { sources += [ "audio_send_stream.cc" ] } deps = [ + ":audio_sender_interface", ":rtp_interfaces", ":video_stream_api", "../api:fec_controller_api", @@ -63,6 +64,16 @@ rtc_library("call_interfaces") { ] } +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 734be307f1..e60bfcdc12 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 @@ class AudioSendStream { // 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 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 @@ class AudioSendStream { 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 0000000000..daab070879 --- /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 + +#include "api/audio/audio_frame.h" + +namespace webrtc { + +class AudioSender { + public: + // Encode and send audio. + virtual void SendAudioData(std::unique_ptr audio_frame) = 0; + + virtual ~AudioSender() = default; +}; + +} // namespace webrtc + +#endif // CALL_AUDIO_SENDER_H_