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}
This commit is contained in:
Tim Na 2020-01-10 10:33:05 -08:00 committed by Commit Bot
parent 8234b92ba3
commit b8c775aeaf
7 changed files with 64 additions and 26 deletions

View file

@ -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",

View file

@ -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::SetStereoChannelSwapping(bool enable) {
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() {

View file

@ -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<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 @@ void AudioTransportImpl::PullRenderData(int bits_per_sample,
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;
}

View file

@ -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<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 @@ class AudioTransportImpl : public AudioTransport {
// 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;

View file

@ -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") {

View file

@ -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<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 @@ class AudioSendStream {
virtual Stats GetStats() const = 0;
virtual Stats GetStats(bool has_remote_tracks) const = 0;
};
} // namespace webrtc
#endif // CALL_AUDIO_SEND_STREAM_H_

30
call/audio_sender.h Normal file
View file

@ -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_