Pass Environment into audio ChannelSend

To make it available for creating AudioEncoders in follow ups

Bug: webrtc:343086059
Change-Id: I24bb8f7e0494e392210cb1001ea0421030d2766b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/352601
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42396}
This commit is contained in:
Danil Chapovalov 2024-05-28 18:16:53 +02:00 committed by WebRTC LUCI CQ
parent 14ee26cb80
commit c157f29216
8 changed files with 62 additions and 104 deletions

View File

@ -58,6 +58,7 @@ rtc_library("audio") {
"../api/crypto:frame_decryptor_interface",
"../api/crypto:frame_encryptor_interface",
"../api/crypto:options",
"../api/environment",
"../api/neteq:neteq_api",
"../api/rtc_event_log",
"../api/task_queue",
@ -109,7 +110,6 @@ rtc_library("audio") {
"../rtc_base/system:no_unique_address",
"../rtc_base/task_utils:repeating_task",
"../system_wrappers",
"../system_wrappers:field_trial",
"../system_wrappers:metrics",
"utility:audio_frame_operations",
"//third_party/abseil-cpp/absl/functional:any_invocable",

View File

@ -44,7 +44,7 @@
namespace webrtc {
namespace {
void UpdateEventLogStreamConfig(RtcEventLog* event_log,
void UpdateEventLogStreamConfig(RtcEventLog& event_log,
const AudioSendStream::Config& config,
const AudioSendStream::Config* old_config) {
using SendCodecSpec = AudioSendStream::Config::SendCodecSpec;
@ -72,7 +72,7 @@ void UpdateEventLogStreamConfig(RtcEventLog* event_log,
rtclog_config->codecs.emplace_back(config.send_codec_spec->format.name,
config.send_codec_spec->payload_type, 0);
}
event_log->Log(std::make_unique<RtcEventAudioSendStreamConfig>(
event_log.Log(std::make_unique<RtcEventAudioSendStreamConfig>(
std::move(rtclog_config)));
}
@ -100,65 +100,51 @@ AudioAllocationConfig::AudioAllocationConfig(
namespace internal {
AudioSendStream::AudioSendStream(
Clock* clock,
const Environment& env,
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
TaskQueueFactory* task_queue_factory,
RtpTransportControllerSendInterface* rtp_transport,
BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log,
RtcpRttStats* rtcp_rtt_stats,
const absl::optional<RtpState>& suspended_rtp_state,
const FieldTrialsView& field_trials)
: AudioSendStream(clock,
const absl::optional<RtpState>& suspended_rtp_state)
: AudioSendStream(env,
config,
audio_state,
task_queue_factory,
rtp_transport,
bitrate_allocator,
event_log,
suspended_rtp_state,
voe::CreateChannelSend(clock,
task_queue_factory,
voe::CreateChannelSend(env,
config.send_transport,
rtcp_rtt_stats,
event_log,
config.frame_encryptor.get(),
config.crypto_options,
config.rtp.extmap_allow_mixed,
config.rtcp_report_interval_ms,
config.rtp.ssrc,
config.frame_transformer,
rtp_transport,
field_trials),
field_trials) {}
rtp_transport)) {}
AudioSendStream::AudioSendStream(
Clock* clock,
const Environment& env,
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
TaskQueueFactory* task_queue_factory,
RtpTransportControllerSendInterface* rtp_transport,
BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log,
const absl::optional<RtpState>& suspended_rtp_state,
std::unique_ptr<voe::ChannelSendInterface> channel_send,
const FieldTrialsView& field_trials)
: clock_(clock),
field_trials_(field_trials),
std::unique_ptr<voe::ChannelSendInterface> channel_send)
: env_(env),
allocate_audio_without_feedback_(
field_trials_.IsEnabled("WebRTC-Audio-ABWENoTWCC")),
env_.field_trials().IsEnabled("WebRTC-Audio-ABWENoTWCC")),
enable_audio_alr_probing_(
!field_trials_.IsDisabled("WebRTC-Audio-AlrProbing")),
allocation_settings_(field_trials_),
!env_.field_trials().IsDisabled("WebRTC-Audio-AlrProbing")),
allocation_settings_(env_.field_trials()),
config_(Config(/*send_transport=*/nullptr)),
audio_state_(audio_state),
channel_send_(std::move(channel_send)),
event_log_(event_log),
use_legacy_overhead_calculation_(
field_trials_.IsEnabled("WebRTC-Audio-LegacyOverhead")),
env_.field_trials().IsEnabled("WebRTC-Audio-LegacyOverhead")),
enable_priority_bitrate_(
!field_trials_.IsDisabled("WebRTC-Audio-PriorityBitrate")),
!env_.field_trials().IsDisabled("WebRTC-Audio-PriorityBitrate")),
bitrate_allocator_(bitrate_allocator),
rtp_transport_(rtp_transport),
rtp_rtcp_module_(channel_send_->GetRtpRtcp()),
@ -227,7 +213,7 @@ void AudioSendStream::ConfigureStream(
SetParametersCallback callback) {
RTC_LOG(LS_INFO) << "AudioSendStream::ConfigureStream: "
<< new_config.ToString();
UpdateEventLogStreamConfig(event_log_, new_config,
UpdateEventLogStreamConfig(env_.event_log(), new_config,
first_time ? nullptr : &config_);
const auto& old_config = config_;
@ -591,7 +577,7 @@ bool AudioSendStream::SetupSendCodec(const Config& new_config) {
// Enable ANA if configured (currently only used by Opus).
if (new_config.audio_network_adaptor_config) {
if (encoder->EnableAudioNetworkAdaptor(
*new_config.audio_network_adaptor_config, event_log_)) {
*new_config.audio_network_adaptor_config, &env_.event_log())) {
RTC_LOG(LS_INFO) << "Audio network adaptor enabled on SSRC "
<< new_config.rtp.ssrc;
} else {
@ -620,7 +606,7 @@ bool AudioSendStream::SetupSendCodec(const Config& new_config) {
red_config.payload_type = *spec.red_payload_type;
red_config.speech_encoder = std::move(encoder);
encoder = std::make_unique<AudioEncoderCopyRed>(std::move(red_config),
field_trials_);
env_.field_trials());
format.name = cricket::kRedCodecName;
}
@ -692,7 +678,7 @@ void AudioSendStream::ReconfigureANA(const Config& new_config) {
channel_send_->CallEncoder([&](AudioEncoder* encoder) {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
if (encoder->EnableAudioNetworkAdaptor(
*new_config.audio_network_adaptor_config, event_log_)) {
*new_config.audio_network_adaptor_config, &env_.event_log())) {
RTC_LOG(LS_INFO) << "Audio network adaptor enabled on SSRC "
<< new_config.rtp.ssrc;
if (overhead_per_packet_ > 0) {

View File

@ -16,6 +16,7 @@
#include <vector>
#include "absl/functional/any_invocable.h"
#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "api/sequence_checker.h"
#include "api/task_queue/task_queue_base.h"
@ -30,7 +31,6 @@
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
class RtcEventLog;
class RtcpRttStats;
class RtpTransportControllerSendInterface;
@ -55,27 +55,21 @@ class AudioState;
class AudioSendStream final : public webrtc::AudioSendStream,
public webrtc::BitrateAllocatorObserver {
public:
AudioSendStream(Clock* clock,
AudioSendStream(const Environment& env,
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
TaskQueueFactory* task_queue_factory,
RtpTransportControllerSendInterface* rtp_transport,
BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log,
RtcpRttStats* rtcp_rtt_stats,
const absl::optional<RtpState>& suspended_rtp_state,
const FieldTrialsView& field_trials);
const absl::optional<RtpState>& suspended_rtp_state);
// For unit tests, which need to supply a mock ChannelSend.
AudioSendStream(Clock* clock,
AudioSendStream(const Environment& env,
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
TaskQueueFactory* task_queue_factory,
RtpTransportControllerSendInterface* rtp_transport,
BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log,
const absl::optional<RtpState>& suspended_rtp_state,
std::unique_ptr<voe::ChannelSendInterface> channel_send,
const FieldTrialsView& field_trials);
std::unique_ptr<voe::ChannelSendInterface> channel_send);
AudioSendStream() = delete;
AudioSendStream(const AudioSendStream&) = delete;
@ -156,8 +150,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
void RegisterCngPayloadType(int payload_type, int clockrate_hz)
RTC_RUN_ON(worker_thread_checker_);
Clock* clock_;
const FieldTrialsView& field_trials_;
const Environment env_;
SequenceChecker worker_thread_checker_;
rtc::RaceChecker audio_capture_race_checker_;
@ -171,7 +164,6 @@ class AudioSendStream final : public webrtc::AudioSendStream,
RTC_GUARDED_BY(worker_thread_checker_);
rtc::scoped_refptr<webrtc::AudioState> audio_state_;
const std::unique_ptr<voe::ChannelSendInterface> channel_send_;
RtcEventLog* const event_log_;
const bool use_legacy_overhead_calculation_;
const bool enable_priority_bitrate_;

View File

@ -17,14 +17,13 @@
#include <vector>
#include "api/audio/audio_processing_statistics.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/environment/environment_factory.h"
#include "api/test/mock_frame_encryptor.h"
#include "audio/audio_state.h"
#include "audio/conversion.h"
#include "audio/mock_voe_channel_proxy.h"
#include "call/test/mock_bitrate_allocator.h"
#include "call/test/mock_rtp_transport_controller_send.h"
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "modules/audio_device/include/mock_audio_device.h"
#include "modules/audio_mixer/audio_mixer_impl.h"
#include "modules/audio_mixer/sine_wave_generator.h"
@ -186,13 +185,12 @@ struct ConfigHelper {
}
std::unique_ptr<internal::AudioSendStream> CreateAudioSendStream() {
return std::unique_ptr<internal::AudioSendStream>(
new internal::AudioSendStream(
time_controller_.GetClock(), stream_config_, audio_state_,
time_controller_.GetTaskQueueFactory(), &rtp_transport_,
&bitrate_allocator_, &event_log_, absl::nullopt,
std::unique_ptr<voe::ChannelSendInterface>(channel_send_),
field_trials));
return std::make_unique<internal::AudioSendStream>(
CreateEnvironment(&field_trials, time_controller_.GetClock(),
time_controller_.GetTaskQueueFactory()),
stream_config_, audio_state_, &rtp_transport_, &bitrate_allocator_,
absl::nullopt,
std::unique_ptr<voe::ChannelSendInterface>(channel_send_));
}
AudioSendStream::Config& config() { return stream_config_; }
@ -325,7 +323,6 @@ struct ConfigHelper {
rtc::scoped_refptr<MockAudioProcessing> audio_processing_;
AudioProcessingStats audio_processing_stats_;
::testing::StrictMock<MockNetworkLinkRtcpObserver> rtcp_observer_;
::testing::NiceMock<MockRtcEventLog> event_log_;
::testing::NiceMock<MockRtpTransportControllerSend> rtp_transport_;
::testing::NiceMock<MockRtpRtcpInterface> rtp_rtcp_;
::testing::NiceMock<MockLimitObserver> limit_observer_;

View File

@ -62,19 +62,16 @@ class ChannelSend : public ChannelSendInterface,
public RtcpPacketTypeCounterObserver,
public ReportBlockDataObserver {
public:
ChannelSend(Clock* clock,
TaskQueueFactory* task_queue_factory,
ChannelSend(const Environment& env,
Transport* rtp_transport,
RtcpRttStats* rtcp_rtt_stats,
RtcEventLog* rtc_event_log,
FrameEncryptorInterface* frame_encryptor,
const webrtc::CryptoOptions& crypto_options,
bool extmap_allow_mixed,
int rtcp_report_interval_ms,
uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
RtpTransportControllerSendInterface* transport_controller,
const FieldTrialsView& field_trials);
RtpTransportControllerSendInterface* transport_controller);
~ChannelSend() override;
@ -179,6 +176,8 @@ class ChannelSend : public ChannelSendInterface,
void InitFrameTransformerDelegate(
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
const Environment env_;
// Thread checkers document and lock usage of some methods on voe::Channel to
// specific threads we know about. The goal is to eventually split up
// voe::Channel into parts with single-threaded semantics, and thereby reduce
@ -195,8 +194,6 @@ class ChannelSend : public ChannelSendInterface,
const uint32_t ssrc_;
bool sending_ RTC_GUARDED_BY(&worker_thread_checker_) = false;
RtcEventLog* const event_log_;
std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_;
std::unique_ptr<RTPSenderAudio> rtp_sender_audio_;
@ -390,27 +387,24 @@ int32_t ChannelSend::SendRtpAudio(AudioFrameType frameType,
}
ChannelSend::ChannelSend(
Clock* clock,
TaskQueueFactory* task_queue_factory,
const Environment& env,
Transport* rtp_transport,
RtcpRttStats* rtcp_rtt_stats,
RtcEventLog* rtc_event_log,
FrameEncryptorInterface* frame_encryptor,
const webrtc::CryptoOptions& crypto_options,
bool extmap_allow_mixed,
int rtcp_report_interval_ms,
uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
RtpTransportControllerSendInterface* transport_controller,
const FieldTrialsView& field_trials)
: ssrc_(ssrc),
event_log_(rtc_event_log),
RtpTransportControllerSendInterface* transport_controller)
: env_(env),
ssrc_(ssrc),
rtp_packet_pacer_proxy_(new RtpPacketSenderProxy()),
retransmission_rate_limiter_(
new RateLimiter(clock, kMaxRetransmissionWindowMs)),
new RateLimiter(&env_.clock(), kMaxRetransmissionWindowMs)),
frame_encryptor_(frame_encryptor),
crypto_options_(crypto_options),
encoder_queue_(task_queue_factory->CreateTaskQueue(
encoder_queue_(env_.task_queue_factory().CreateTaskQueue(
"AudioEncoder",
TaskQueueFactory::Priority::NORMAL)),
encoder_queue_checker_(encoder_queue_.get()),
@ -421,15 +415,15 @@ ChannelSend::ChannelSend(
configuration.report_block_data_observer = this;
configuration.network_link_rtcp_observer =
transport_controller->GetRtcpObserver();
configuration.clock = (clock ? clock : Clock::GetRealTimeClock());
configuration.clock = &env_.clock();
configuration.audio = true;
configuration.outgoing_transport = rtp_transport;
configuration.paced_sender = rtp_packet_pacer_proxy_.get();
configuration.event_log = event_log_;
configuration.event_log = &env_.event_log();
configuration.rtt_stats = rtcp_rtt_stats;
if (field_trials.IsDisabled("WebRTC-DisableRtxRateLimiter")) {
if (env_.field_trials().IsDisabled("WebRTC-DisableRtxRateLimiter")) {
configuration.retransmission_rate_limiter =
retransmission_rate_limiter_.get();
}
@ -438,7 +432,7 @@ ChannelSend::ChannelSend(
configuration.rtcp_packet_type_counter_observer = this;
configuration.local_media_ssrc = ssrc;
configuration.field_trials = &field_trials;
configuration.field_trials = &env_.field_trials();
rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(configuration);
rtp_rtcp_->SetSendingMediaStatus(false);
@ -892,24 +886,20 @@ void ChannelSend::InitFrameTransformerDelegate(
} // namespace
std::unique_ptr<ChannelSendInterface> CreateChannelSend(
Clock* clock,
TaskQueueFactory* task_queue_factory,
const Environment& env,
Transport* rtp_transport,
RtcpRttStats* rtcp_rtt_stats,
RtcEventLog* rtc_event_log,
FrameEncryptorInterface* frame_encryptor,
const webrtc::CryptoOptions& crypto_options,
bool extmap_allow_mixed,
int rtcp_report_interval_ms,
uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
RtpTransportControllerSendInterface* transport_controller,
const FieldTrialsView& field_trials) {
RtpTransportControllerSendInterface* transport_controller) {
return std::make_unique<ChannelSend>(
clock, task_queue_factory, rtp_transport, rtcp_rtt_stats, rtc_event_log,
frame_encryptor, crypto_options, extmap_allow_mixed,
rtcp_report_interval_ms, ssrc, std::move(frame_transformer),
transport_controller, field_trials);
env, rtp_transport, rtcp_rtt_stats, frame_encryptor, crypto_options,
extmap_allow_mixed, rtcp_report_interval_ms, ssrc,
std::move(frame_transformer), transport_controller);
}
} // namespace voe

View File

@ -18,10 +18,9 @@
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/audio_encoder.h"
#include "api/crypto/crypto_options.h"
#include "api/field_trials_view.h"
#include "api/environment/environment.h"
#include "api/frame_transformer_interface.h"
#include "api/function_view.h"
#include "api/task_queue/task_queue_factory.h"
#include "modules/rtp_rtcp/include/report_block_data.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
#include "modules/rtp_rtcp/source/rtp_sender_audio.h"
@ -29,7 +28,6 @@
namespace webrtc {
class FrameEncryptorInterface;
class RtcEventLog;
class RtpTransportControllerSendInterface;
struct CallSendStatistics {
@ -115,19 +113,16 @@ class ChannelSendInterface {
};
std::unique_ptr<ChannelSendInterface> CreateChannelSend(
Clock* clock,
TaskQueueFactory* task_queue_factory,
const Environment& env,
Transport* rtp_transport,
RtcpRttStats* rtcp_rtt_stats,
RtcEventLog* rtc_event_log,
FrameEncryptorInterface* frame_encryptor,
const webrtc::CryptoOptions& crypto_options,
bool extmap_allow_mixed,
int rtcp_report_interval_ms,
uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
RtpTransportControllerSendInterface* transport_controller,
const FieldTrialsView& field_trials);
RtpTransportControllerSendInterface* transport_controller);
} // namespace voe
} // namespace webrtc

View File

@ -61,11 +61,9 @@ class ChannelSendTest : public ::testing::Test {
transport_controller_(
RtpTransportConfig{.env = env_,
.bitrate_config = GetBitrateConfig()}) {
channel_ = voe::CreateChannelSend(
time_controller_.GetClock(), time_controller_.GetTaskQueueFactory(),
&transport_, nullptr, &env_.event_log(), nullptr, crypto_options_,
false, kRtcpIntervalMs, kSsrc, nullptr, &transport_controller_,
env_.field_trials());
channel_ = voe::CreateChannelSend(env_, &transport_, nullptr, nullptr,
crypto_options_, false, kRtcpIntervalMs,
kSsrc, nullptr, &transport_controller_);
encoder_factory_ = CreateBuiltinAudioEncoderFactory();
SdpAudioFormat opus = SdpAudioFormat("opus", kRtpRateHz, 2);
std::unique_ptr<AudioEncoder> encoder =

View File

@ -757,10 +757,10 @@ webrtc::AudioSendStream* Call::CreateAudioSendStream(
}
}
AudioSendStream* send_stream = new AudioSendStream(
&env_.clock(), config, config_.audio_state, &env_.task_queue_factory(),
transport_send_.get(), bitrate_allocator_.get(), &env_.event_log(),
call_stats_->AsRtcpRttStats(), suspended_rtp_state, trials());
AudioSendStream* send_stream =
new AudioSendStream(env_, config, config_.audio_state,
transport_send_.get(), bitrate_allocator_.get(),
call_stats_->AsRtcpRttStats(), suspended_rtp_state);
RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
audio_send_ssrcs_.end());
audio_send_ssrcs_[config.rtp.ssrc] = send_stream;