WebRTC-DeprecateGlobalFieldTrialString/Enabled/ - part 7/inf

Convert audio/ and collateral (audio encoder copy red).

Bug: webrtc:10335
Change-Id: Iac54c0cfd2f62f4402f3deec35ae2725ec35b81a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/255820
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36229}
This commit is contained in:
Jonas Oreland
2022-03-16 13:50:58 +01:00
committed by WebRTC LUCI CQ
parent e72f4bc524
commit a943e730b2
13 changed files with 117 additions and 82 deletions

View File

@ -49,6 +49,7 @@ rtc_library("audio") {
"../api:scoped_refptr", "../api:scoped_refptr",
"../api:sequence_checker", "../api:sequence_checker",
"../api:transport_api", "../api:transport_api",
"../api:webrtc_key_value_config",
"../api/audio:aec3_factory", "../api/audio:aec3_factory",
"../api/audio:audio_frame_api", "../api/audio:audio_frame_api",
"../api/audio:audio_frame_processor", "../api/audio:audio_frame_processor",
@ -190,6 +191,7 @@ if (rtc_include_tests) {
"../test:mock_transformable_frame", "../test:mock_transformable_frame",
"../test:mock_transport", "../test:mock_transport",
"../test:rtp_test_utils", "../test:rtp_test_utils",
"../test:scoped_key_value_config",
"../test:test_common", "../test:test_common",
"../test:test_support", "../test:test_support",
"utility:utility_tests", "utility:utility_tests",

View File

@ -39,7 +39,6 @@
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/strings/audio_format_to_string.h" #include "rtc_base/strings/audio_format_to_string.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "system_wrappers/include/field_trial.h"
namespace webrtc { namespace webrtc {
namespace { namespace {
@ -88,8 +87,9 @@ std::unique_ptr<StructParametersParser> AudioAllocationConfig::Parser() {
"rate_prio", &bitrate_priority); "rate_prio", &bitrate_priority);
} }
AudioAllocationConfig::AudioAllocationConfig() { AudioAllocationConfig::AudioAllocationConfig(
Parser()->Parse(field_trial::FindFullName(kKey)); const WebRtcKeyValueConfig& field_trials) {
Parser()->Parse(field_trials.Lookup(kKey));
if (priority_bitrate_raw && !priority_bitrate.IsZero()) { if (priority_bitrate_raw && !priority_bitrate.IsZero()) {
RTC_LOG(LS_WARNING) << "'priority_bitrate' and '_raw' are mutually " RTC_LOG(LS_WARNING) << "'priority_bitrate' and '_raw' are mutually "
"exclusive but both were configured."; "exclusive but both were configured.";
@ -106,28 +106,31 @@ AudioSendStream::AudioSendStream(
BitrateAllocatorInterface* bitrate_allocator, BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log, RtcEventLog* event_log,
RtcpRttStats* rtcp_rtt_stats, RtcpRttStats* rtcp_rtt_stats,
const absl::optional<RtpState>& suspended_rtp_state) const absl::optional<RtpState>& suspended_rtp_state,
: AudioSendStream(clock, const WebRtcKeyValueConfig& field_trials)
config, : AudioSendStream(
audio_state, clock,
task_queue_factory, config,
rtp_transport, audio_state,
bitrate_allocator, task_queue_factory,
event_log, rtp_transport,
suspended_rtp_state, bitrate_allocator,
voe::CreateChannelSend( event_log,
clock, suspended_rtp_state,
task_queue_factory, voe::CreateChannelSend(clock,
config.send_transport, task_queue_factory,
rtcp_rtt_stats, config.send_transport,
event_log, rtcp_rtt_stats,
config.frame_encryptor, event_log,
config.crypto_options, config.frame_encryptor,
config.rtp.extmap_allow_mixed, config.crypto_options,
config.rtcp_report_interval_ms, config.rtp.extmap_allow_mixed,
config.rtp.ssrc, config.rtcp_report_interval_ms,
config.frame_transformer, config.rtp.ssrc,
rtp_transport->transport_feedback_observer())) {} config.frame_transformer,
rtp_transport->transport_feedback_observer(),
field_trials),
field_trials) {}
AudioSendStream::AudioSendStream( AudioSendStream::AudioSendStream(
Clock* clock, Clock* clock,
@ -138,21 +141,24 @@ AudioSendStream::AudioSendStream(
BitrateAllocatorInterface* bitrate_allocator, BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log, RtcEventLog* event_log,
const absl::optional<RtpState>& suspended_rtp_state, const absl::optional<RtpState>& suspended_rtp_state,
std::unique_ptr<voe::ChannelSendInterface> channel_send) std::unique_ptr<voe::ChannelSendInterface> channel_send,
const WebRtcKeyValueConfig& field_trials)
: clock_(clock), : clock_(clock),
field_trials_(field_trials),
rtp_transport_queue_(rtp_transport->GetWorkerQueue()), rtp_transport_queue_(rtp_transport->GetWorkerQueue()),
allocate_audio_without_feedback_( allocate_audio_without_feedback_(
field_trial::IsEnabled("WebRTC-Audio-ABWENoTWCC")), field_trials_.IsEnabled("WebRTC-Audio-ABWENoTWCC")),
enable_audio_alr_probing_( enable_audio_alr_probing_(
!field_trial::IsDisabled("WebRTC-Audio-AlrProbing")), !field_trials_.IsDisabled("WebRTC-Audio-AlrProbing")),
send_side_bwe_with_overhead_( send_side_bwe_with_overhead_(
!field_trial::IsDisabled("WebRTC-SendSideBwe-WithOverhead")), !field_trials_.IsDisabled("WebRTC-SendSideBwe-WithOverhead")),
allocation_settings_(field_trials_),
config_(Config(/*send_transport=*/nullptr)), config_(Config(/*send_transport=*/nullptr)),
audio_state_(audio_state), audio_state_(audio_state),
channel_send_(std::move(channel_send)), channel_send_(std::move(channel_send)),
event_log_(event_log), event_log_(event_log),
use_legacy_overhead_calculation_( use_legacy_overhead_calculation_(
field_trial::IsEnabled("WebRTC-Audio-LegacyOverhead")), field_trials_.IsEnabled("WebRTC-Audio-LegacyOverhead")),
bitrate_allocator_(bitrate_allocator), bitrate_allocator_(bitrate_allocator),
rtp_transport_(rtp_transport), rtp_transport_(rtp_transport),
rtp_rtcp_module_(channel_send_->GetRtpRtcp()), rtp_rtcp_module_(channel_send_->GetRtpRtcp()),
@ -640,7 +646,8 @@ bool AudioSendStream::SetupSendCodec(const Config& new_config) {
AudioEncoderCopyRed::Config red_config; AudioEncoderCopyRed::Config red_config;
red_config.payload_type = *spec.red_payload_type; red_config.payload_type = *spec.red_payload_type;
red_config.speech_encoder = std::move(encoder); red_config.speech_encoder = std::move(encoder);
encoder = std::make_unique<AudioEncoderCopyRed>(std::move(red_config)); encoder = std::make_unique<AudioEncoderCopyRed>(std::move(red_config),
field_trials_);
} }
// Set currently known overhead (used in ANA, opus only). // Set currently known overhead (used in ANA, opus only).

View File

@ -16,6 +16,7 @@
#include <vector> #include <vector>
#include "api/sequence_checker.h" #include "api/sequence_checker.h"
#include "api/webrtc_key_value_config.h"
#include "audio/audio_level.h" #include "audio/audio_level.h"
#include "audio/channel_send.h" #include "audio/channel_send.h"
#include "call/audio_send_stream.h" #include "call/audio_send_stream.h"
@ -46,7 +47,7 @@ struct AudioAllocationConfig {
absl::optional<double> bitrate_priority; absl::optional<double> bitrate_priority;
std::unique_ptr<StructParametersParser> Parser(); std::unique_ptr<StructParametersParser> Parser();
AudioAllocationConfig(); explicit AudioAllocationConfig(const WebRtcKeyValueConfig& field_trials);
}; };
namespace internal { namespace internal {
class AudioState; class AudioState;
@ -62,7 +63,8 @@ class AudioSendStream final : public webrtc::AudioSendStream,
BitrateAllocatorInterface* bitrate_allocator, BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log, RtcEventLog* event_log,
RtcpRttStats* rtcp_rtt_stats, RtcpRttStats* rtcp_rtt_stats,
const absl::optional<RtpState>& suspended_rtp_state); const absl::optional<RtpState>& suspended_rtp_state,
const WebRtcKeyValueConfig& field_trials);
// For unit tests, which need to supply a mock ChannelSend. // For unit tests, which need to supply a mock ChannelSend.
AudioSendStream(Clock* clock, AudioSendStream(Clock* clock,
const webrtc::AudioSendStream::Config& config, const webrtc::AudioSendStream::Config& config,
@ -72,7 +74,8 @@ class AudioSendStream final : public webrtc::AudioSendStream,
BitrateAllocatorInterface* bitrate_allocator, BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log, RtcEventLog* event_log,
const absl::optional<RtpState>& suspended_rtp_state, const absl::optional<RtpState>& suspended_rtp_state,
std::unique_ptr<voe::ChannelSendInterface> channel_send); std::unique_ptr<voe::ChannelSendInterface> channel_send,
const WebRtcKeyValueConfig& field_trials);
AudioSendStream() = delete; AudioSendStream() = delete;
AudioSendStream(const AudioSendStream&) = delete; AudioSendStream(const AudioSendStream&) = delete;
@ -160,6 +163,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
RTC_RUN_ON(worker_thread_checker_); RTC_RUN_ON(worker_thread_checker_);
Clock* clock_; Clock* clock_;
const WebRtcKeyValueConfig& field_trials_;
SequenceChecker worker_thread_checker_; SequenceChecker worker_thread_checker_;
SequenceChecker pacer_thread_checker_; SequenceChecker pacer_thread_checker_;

View File

@ -32,10 +32,10 @@
#include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" #include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
#include "rtc_base/task_queue_for_test.h" #include "rtc_base/task_queue_for_test.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "test/field_trial.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/mock_audio_encoder.h" #include "test/mock_audio_encoder.h"
#include "test/mock_audio_encoder_factory.h" #include "test/mock_audio_encoder_factory.h"
#include "test/scoped_key_value_config.h"
namespace webrtc { namespace webrtc {
namespace test { namespace test {
@ -196,7 +196,8 @@ struct ConfigHelper {
Clock::GetRealTimeClock(), stream_config_, audio_state_, Clock::GetRealTimeClock(), stream_config_, audio_state_,
task_queue_factory_.get(), &rtp_transport_, &bitrate_allocator_, task_queue_factory_.get(), &rtp_transport_, &bitrate_allocator_,
&event_log_, absl::nullopt, &event_log_, absl::nullopt,
std::unique_ptr<voe::ChannelSendInterface>(channel_send_))); std::unique_ptr<voe::ChannelSendInterface>(channel_send_),
field_trials));
} }
AudioSendStream::Config& config() { return stream_config_; } AudioSendStream::Config& config() { return stream_config_; }
@ -321,6 +322,8 @@ struct ConfigHelper {
TaskQueueForTest* worker() { return &worker_queue_; } TaskQueueForTest* worker() { return &worker_queue_; }
test::ScopedKeyValueConfig field_trials;
private: private:
SimulatedClock clock_; SimulatedClock clock_;
std::unique_ptr<TaskQueueFactory> task_queue_factory_; std::unique_ptr<TaskQueueFactory> task_queue_factory_;
@ -659,10 +662,10 @@ TEST(AudioSendStreamTest, SSBweTargetInRangeRespected) {
} }
TEST(AudioSendStreamTest, SSBweFieldTrialMinRespected) { TEST(AudioSendStreamTest, SSBweFieldTrialMinRespected) {
ScopedFieldTrials field_trials(
"WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
for (bool use_null_audio_processing : {false, true}) { for (bool use_null_audio_processing : {false, true}) {
ConfigHelper helper(true, true, use_null_audio_processing); ConfigHelper helper(true, true, use_null_audio_processing);
ScopedKeyValueConfig field_trials(
helper.field_trials, "WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
auto send_stream = helper.CreateAudioSendStream(); auto send_stream = helper.CreateAudioSendStream();
EXPECT_CALL( EXPECT_CALL(
*helper.channel_send(), *helper.channel_send(),
@ -676,10 +679,10 @@ TEST(AudioSendStreamTest, SSBweFieldTrialMinRespected) {
} }
TEST(AudioSendStreamTest, SSBweFieldTrialMaxRespected) { TEST(AudioSendStreamTest, SSBweFieldTrialMaxRespected) {
ScopedFieldTrials field_trials(
"WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
for (bool use_null_audio_processing : {false, true}) { for (bool use_null_audio_processing : {false, true}) {
ConfigHelper helper(true, true, use_null_audio_processing); ConfigHelper helper(true, true, use_null_audio_processing);
ScopedKeyValueConfig field_trials(
helper.field_trials, "WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
auto send_stream = helper.CreateAudioSendStream(); auto send_stream = helper.CreateAudioSendStream();
EXPECT_CALL( EXPECT_CALL(
*helper.channel_send(), *helper.channel_send(),
@ -693,10 +696,10 @@ TEST(AudioSendStreamTest, SSBweFieldTrialMaxRespected) {
} }
TEST(AudioSendStreamTest, SSBweWithOverhead) { TEST(AudioSendStreamTest, SSBweWithOverhead) {
ScopedFieldTrials field_trials(
"WebRTC-Audio-LegacyOverhead/Disabled/");
for (bool use_null_audio_processing : {false, true}) { for (bool use_null_audio_processing : {false, true}) {
ConfigHelper helper(true, true, use_null_audio_processing); ConfigHelper helper(true, true, use_null_audio_processing);
ScopedKeyValueConfig field_trials(helper.field_trials,
"WebRTC-Audio-LegacyOverhead/Disabled/");
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead) EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
.WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>())); .WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>()));
auto send_stream = helper.CreateAudioSendStream(); auto send_stream = helper.CreateAudioSendStream();
@ -714,11 +717,12 @@ TEST(AudioSendStreamTest, SSBweWithOverhead) {
} }
TEST(AudioSendStreamTest, SSBweWithOverheadMinRespected) { TEST(AudioSendStreamTest, SSBweWithOverheadMinRespected) {
ScopedFieldTrials field_trials(
"WebRTC-Audio-LegacyOverhead/Disabled/"
"WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
for (bool use_null_audio_processing : {false, true}) { for (bool use_null_audio_processing : {false, true}) {
ConfigHelper helper(true, true, use_null_audio_processing); ConfigHelper helper(true, true, use_null_audio_processing);
ScopedKeyValueConfig field_trials(
helper.field_trials,
"WebRTC-Audio-LegacyOverhead/Disabled/"
"WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead) EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
.WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>())); .WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>()));
auto send_stream = helper.CreateAudioSendStream(); auto send_stream = helper.CreateAudioSendStream();
@ -734,11 +738,12 @@ TEST(AudioSendStreamTest, SSBweWithOverheadMinRespected) {
} }
TEST(AudioSendStreamTest, SSBweWithOverheadMaxRespected) { TEST(AudioSendStreamTest, SSBweWithOverheadMaxRespected) {
ScopedFieldTrials field_trials(
"WebRTC-Audio-LegacyOverhead/Disabled/"
"WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
for (bool use_null_audio_processing : {false, true}) { for (bool use_null_audio_processing : {false, true}) {
ConfigHelper helper(true, true, use_null_audio_processing); ConfigHelper helper(true, true, use_null_audio_processing);
ScopedKeyValueConfig field_trials(
helper.field_trials,
"WebRTC-Audio-LegacyOverhead/Disabled/"
"WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead) EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
.WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>())); .WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>()));
auto send_stream = helper.CreateAudioSendStream(); auto send_stream = helper.CreateAudioSendStream();

View File

@ -43,7 +43,6 @@
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/metrics.h" #include "system_wrappers/include/metrics.h"
namespace webrtc { namespace webrtc {
@ -78,7 +77,8 @@ class ChannelSend : public ChannelSendInterface,
int rtcp_report_interval_ms, int rtcp_report_interval_ms,
uint32_t ssrc, uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
TransportFeedbackObserver* feedback_observer); TransportFeedbackObserver* feedback_observer,
const WebRtcKeyValueConfig& field_trials);
~ChannelSend() override; ~ChannelSend() override;
@ -458,7 +458,8 @@ ChannelSend::ChannelSend(
int rtcp_report_interval_ms, int rtcp_report_interval_ms,
uint32_t ssrc, uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
TransportFeedbackObserver* feedback_observer) TransportFeedbackObserver* feedback_observer,
const WebRtcKeyValueConfig& field_trials)
: ssrc_(ssrc), : ssrc_(ssrc),
event_log_(rtc_event_log), event_log_(rtc_event_log),
_timeStamp(0), // This is just an offset, RTP module will add it's own _timeStamp(0), // This is just an offset, RTP module will add it's own
@ -477,7 +478,7 @@ ChannelSend::ChannelSend(
"AudioEncoder", "AudioEncoder",
TaskQueueFactory::Priority::NORMAL)), TaskQueueFactory::Priority::NORMAL)),
fixing_timestamp_stall_( fixing_timestamp_stall_(
!field_trial::IsDisabled("WebRTC-Audio-FixTimestampStall")) { field_trials.IsDisabled("WebRTC-Audio-FixTimestampStall")) {
audio_coding_.reset(AudioCodingModule::Create(AudioCodingModule::Config())); audio_coding_.reset(AudioCodingModule::Create(AudioCodingModule::Config()));
RtpRtcpInterface::Configuration configuration; RtpRtcpInterface::Configuration configuration;
@ -948,12 +949,13 @@ std::unique_ptr<ChannelSendInterface> CreateChannelSend(
int rtcp_report_interval_ms, int rtcp_report_interval_ms,
uint32_t ssrc, uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
TransportFeedbackObserver* feedback_observer) { TransportFeedbackObserver* feedback_observer,
const WebRtcKeyValueConfig& field_trials) {
return std::make_unique<ChannelSend>( return std::make_unique<ChannelSend>(
clock, task_queue_factory, rtp_transport, rtcp_rtt_stats, rtc_event_log, clock, task_queue_factory, rtp_transport, rtcp_rtt_stats, rtc_event_log,
frame_encryptor, crypto_options, extmap_allow_mixed, frame_encryptor, crypto_options, extmap_allow_mixed,
rtcp_report_interval_ms, ssrc, std::move(frame_transformer), rtcp_report_interval_ms, ssrc, std::move(frame_transformer),
feedback_observer); feedback_observer, field_trials);
} }
} // namespace voe } // namespace voe

View File

@ -21,6 +21,7 @@
#include "api/frame_transformer_interface.h" #include "api/frame_transformer_interface.h"
#include "api/function_view.h" #include "api/function_view.h"
#include "api/task_queue/task_queue_factory.h" #include "api/task_queue/task_queue_factory.h"
#include "api/webrtc_key_value_config.h"
#include "modules/rtp_rtcp/include/report_block_data.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_rtcp_interface.h"
#include "modules/rtp_rtcp/source/rtp_sender_audio.h" #include "modules/rtp_rtcp/source/rtp_sender_audio.h"
@ -135,7 +136,8 @@ std::unique_ptr<ChannelSendInterface> CreateChannelSend(
int rtcp_report_interval_ms, int rtcp_report_interval_ms,
uint32_t ssrc, uint32_t ssrc,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
TransportFeedbackObserver* feedback_observer); TransportFeedbackObserver* feedback_observer,
const WebRtcKeyValueConfig& field_trials);
} // namespace voe } // namespace voe
} // namespace webrtc } // namespace webrtc

View File

@ -915,7 +915,7 @@ webrtc::AudioSendStream* Call::CreateAudioSendStream(
AudioSendStream* send_stream = new AudioSendStream( AudioSendStream* send_stream = new AudioSendStream(
clock_, config, config_.audio_state, task_queue_factory_, clock_, config, config_.audio_state, task_queue_factory_,
transport_send_.get(), bitrate_allocator_.get(), event_log_, transport_send_.get(), bitrate_allocator_.get(), event_log_,
call_stats_->AsRtcpRttStats(), suspended_rtp_state); call_stats_->AsRtcpRttStats(), suspended_rtp_state, trials());
RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
audio_send_ssrcs_.end()); audio_send_ssrcs_.end());
audio_send_ssrcs_[config.rtp.ssrc] = send_stream; audio_send_ssrcs_[config.rtp.ssrc] = send_stream;

View File

@ -118,12 +118,12 @@ rtc_library("red") {
deps = [ deps = [
"../../api:array_view", "../../api:array_view",
"../../api:webrtc_key_value_config",
"../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs:audio_codecs_api",
"../../api/units:time_delta", "../../api/units:time_delta",
"../../common_audio", "../../common_audio",
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base:rtc_base_approved", "../../rtc_base:rtc_base_approved",
"../../system_wrappers:field_trial",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
} }
@ -2079,6 +2079,7 @@ if (rtc_include_tests) {
"../../test:fileutils", "../../test:fileutils",
"../../test:rtc_expect_death", "../../test:rtc_expect_death",
"../../test:rtp_test_utils", "../../test:rtp_test_utils",
"../../test:scoped_key_value_config",
"../../test:test_common", "../../test:test_common",
"../../test:test_support", "../../test:test_support",
"codecs/opus/test", "codecs/opus/test",

View File

@ -18,7 +18,6 @@
#include "rtc_base/byte_order.h" #include "rtc_base/byte_order.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "system_wrappers/include/field_trial.h"
namespace webrtc { namespace webrtc {
static constexpr const int kRedMaxPacketSize = static constexpr const int kRedMaxPacketSize =
@ -40,9 +39,10 @@ AudioEncoderCopyRed::Config::Config() = default;
AudioEncoderCopyRed::Config::Config(Config&&) = default; AudioEncoderCopyRed::Config::Config(Config&&) = default;
AudioEncoderCopyRed::Config::~Config() = default; AudioEncoderCopyRed::Config::~Config() = default;
size_t GetMaxRedundancyFromFieldTrial() { size_t GetMaxRedundancyFromFieldTrial(
const WebRtcKeyValueConfig& field_trials) {
const std::string red_trial = const std::string red_trial =
webrtc::field_trial::FindFullName("WebRTC-Audio-Red-For-Opus"); field_trials.Lookup("WebRTC-Audio-Red-For-Opus");
size_t redundancy = 0; size_t redundancy = 0;
if (sscanf(red_trial.c_str(), "Enabled-%zu", &redundancy) != 1 || if (sscanf(red_trial.c_str(), "Enabled-%zu", &redundancy) != 1 ||
redundancy > 9) { redundancy > 9) {
@ -51,14 +51,17 @@ size_t GetMaxRedundancyFromFieldTrial() {
return redundancy; return redundancy;
} }
AudioEncoderCopyRed::AudioEncoderCopyRed(Config&& config) AudioEncoderCopyRed::AudioEncoderCopyRed(
Config&& config,
const WebRtcKeyValueConfig& field_trials)
: speech_encoder_(std::move(config.speech_encoder)), : speech_encoder_(std::move(config.speech_encoder)),
primary_encoded_(0, kAudioMaxRtpPacketLen), primary_encoded_(0, kAudioMaxRtpPacketLen),
max_packet_length_(kAudioMaxRtpPacketLen), max_packet_length_(kAudioMaxRtpPacketLen),
red_payload_type_(config.payload_type) { red_payload_type_(config.payload_type) {
RTC_CHECK(speech_encoder_) << "Speech encoder not provided."; RTC_CHECK(speech_encoder_) << "Speech encoder not provided.";
auto number_of_redundant_encodings = GetMaxRedundancyFromFieldTrial(); auto number_of_redundant_encodings =
GetMaxRedundancyFromFieldTrial(field_trials);
for (size_t i = 0; i < number_of_redundant_encodings; i++) { for (size_t i = 0; i < number_of_redundant_encodings; i++) {
std::pair<EncodedInfo, rtc::Buffer> redundant; std::pair<EncodedInfo, rtc::Buffer> redundant;
redundant.second.EnsureCapacity(kAudioMaxRtpPacketLen); redundant.second.EnsureCapacity(kAudioMaxRtpPacketLen);

View File

@ -22,6 +22,7 @@
#include "api/array_view.h" #include "api/array_view.h"
#include "api/audio_codecs/audio_encoder.h" #include "api/audio_codecs/audio_encoder.h"
#include "api/units/time_delta.h" #include "api/units/time_delta.h"
#include "api/webrtc_key_value_config.h"
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
namespace webrtc { namespace webrtc {
@ -42,7 +43,8 @@ class AudioEncoderCopyRed final : public AudioEncoder {
std::unique_ptr<AudioEncoder> speech_encoder; std::unique_ptr<AudioEncoder> speech_encoder;
}; };
explicit AudioEncoderCopyRed(Config&& config); AudioEncoderCopyRed(Config&& config,
const WebRtcKeyValueConfig& field_trials);
~AudioEncoderCopyRed() override; ~AudioEncoderCopyRed() override;

View File

@ -18,6 +18,7 @@
#include "test/field_trial.h" #include "test/field_trial.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/mock_audio_encoder.h" #include "test/mock_audio_encoder.h"
#include "test/scoped_key_value_config.h"
#include "test/testsupport/rtc_expect_death.h" #include "test/testsupport/rtc_expect_death.h"
using ::testing::_; using ::testing::_;
@ -49,7 +50,7 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type_; config.payload_type = red_payload_type_;
config.speech_encoder = std::unique_ptr<AudioEncoder>(mock_encoder_); config.speech_encoder = std::unique_ptr<AudioEncoder>(mock_encoder_);
red_.reset(new AudioEncoderCopyRed(std::move(config))); red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_));
memset(audio_, 0, sizeof(audio_)); memset(audio_, 0, sizeof(audio_));
EXPECT_CALL(*mock_encoder_, NumChannels()).WillRepeatedly(Return(1U)); EXPECT_CALL(*mock_encoder_, NumChannels()).WillRepeatedly(Return(1U));
EXPECT_CALL(*mock_encoder_, SampleRateHz()) EXPECT_CALL(*mock_encoder_, SampleRateHz())
@ -68,6 +69,7 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
timestamp_ += rtc::checked_cast<uint32_t>(num_audio_samples_10ms); timestamp_ += rtc::checked_cast<uint32_t>(num_audio_samples_10ms);
} }
test::ScopedKeyValueConfig field_trials_;
MockAudioEncoder* mock_encoder_; MockAudioEncoder* mock_encoder_;
std::unique_ptr<AudioEncoderCopyRed> red_; std::unique_ptr<AudioEncoderCopyRed> red_;
uint32_t timestamp_; uint32_t timestamp_;
@ -198,13 +200,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes1) {
// Checks that the correct payload sizes are populated into the redundancy // Checks that the correct payload sizes are populated into the redundancy
// information for a redundancy level of 0. // information for a redundancy level of 0.
TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes0) { TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes0) {
webrtc::test::ScopedFieldTrials field_trials( webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-Audio-Red-For-Opus/Enabled-0/"); field_trials_, "WebRTC-Audio-Red-For-Opus/Enabled-0/");
// Recreate the RED encoder to take the new field trial setting into account. // Recreate the RED encoder to take the new field trial setting into account.
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type_; config.payload_type = red_payload_type_;
config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]);
red_.reset(new AudioEncoderCopyRed(std::move(config))); red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials));
// Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence
// of calls. // of calls.
@ -224,13 +226,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes0) {
// Checks that the correct payload sizes are populated into the redundancy // Checks that the correct payload sizes are populated into the redundancy
// information for a redundancy level of 2. // information for a redundancy level of 2.
TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes2) { TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes2) {
webrtc::test::ScopedFieldTrials field_trials( webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-Audio-Red-For-Opus/Enabled-2/"); field_trials_, "WebRTC-Audio-Red-For-Opus/Enabled-2/");
// Recreate the RED encoder to take the new field trial setting into account. // Recreate the RED encoder to take the new field trial setting into account.
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type_; config.payload_type = red_payload_type_;
config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]);
red_.reset(new AudioEncoderCopyRed(std::move(config))); red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials));
// Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence
// of calls. // of calls.
@ -266,13 +268,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes2) {
// Checks that the correct payload sizes are populated into the redundancy // Checks that the correct payload sizes are populated into the redundancy
// information for a redundancy level of 3. // information for a redundancy level of 3.
TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes3) { TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes3) {
webrtc::test::ScopedFieldTrials field_trials( webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-Audio-Red-For-Opus/Enabled-3/"); field_trials_, "WebRTC-Audio-Red-For-Opus/Enabled-3/");
// Recreate the RED encoder to take the new field trial setting into account. // Recreate the RED encoder to take the new field trial setting into account.
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type_; config.payload_type = red_payload_type_;
config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]);
red_.reset(new AudioEncoderCopyRed(std::move(config))); red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_));
// Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence
// of calls. // of calls.
@ -463,13 +465,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header) {
// Variant with a redundancy of 0. // Variant with a redundancy of 0.
TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header0) { TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header0) {
webrtc::test::ScopedFieldTrials field_trials( webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-Audio-Red-For-Opus/Enabled-0/"); field_trials_, "WebRTC-Audio-Red-For-Opus/Enabled-0/");
// Recreate the RED encoder to take the new field trial setting into account. // Recreate the RED encoder to take the new field trial setting into account.
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type_; config.payload_type = red_payload_type_;
config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]);
red_.reset(new AudioEncoderCopyRed(std::move(config))); red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials));
const int primary_payload_type = red_payload_type_ + 1; const int primary_payload_type = red_payload_type_ + 1;
AudioEncoder::EncodedInfo info; AudioEncoder::EncodedInfo info;
@ -491,13 +493,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header0) {
} }
// Variant with a redundancy of 2. // Variant with a redundancy of 2.
TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header2) { TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header2) {
webrtc::test::ScopedFieldTrials field_trials( webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-Audio-Red-For-Opus/Enabled-2/"); field_trials_, "WebRTC-Audio-Red-For-Opus/Enabled-2/");
// Recreate the RED encoder to take the new field trial setting into account. // Recreate the RED encoder to take the new field trial setting into account.
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type_; config.payload_type = red_payload_type_;
config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]);
red_.reset(new AudioEncoderCopyRed(std::move(config))); red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials));
const int primary_payload_type = red_payload_type_ + 1; const int primary_payload_type = red_payload_type_ + 1;
AudioEncoder::EncodedInfo info; AudioEncoder::EncodedInfo info;
@ -623,11 +625,13 @@ TEST_F(AudioEncoderCopyRedDeathTest, WrongFrameSize) {
} }
TEST_F(AudioEncoderCopyRedDeathTest, NullSpeechEncoder) { TEST_F(AudioEncoderCopyRedDeathTest, NullSpeechEncoder) {
test::ScopedKeyValueConfig field_trials;
AudioEncoderCopyRed* red = NULL; AudioEncoderCopyRed* red = NULL;
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.speech_encoder = NULL; config.speech_encoder = NULL;
RTC_EXPECT_DEATH(red = new AudioEncoderCopyRed(std::move(config)), RTC_EXPECT_DEATH(
"Speech encoder not provided."); red = new AudioEncoderCopyRed(std::move(config), field_trials),
"Speech encoder not provided.");
// The delete operation is needed to avoid leak reports from memcheck. // The delete operation is needed to avoid leak reports from memcheck.
delete red; delete red;
} }

View File

@ -190,7 +190,8 @@ void TestRedFec::RegisterSendCodec(
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type; config.payload_type = red_payload_type;
config.speech_encoder = std::move(encoder); config.speech_encoder = std::move(encoder);
encoder = std::make_unique<AudioEncoderCopyRed>(std::move(config)); encoder = std::make_unique<AudioEncoderCopyRed>(std::move(config),
field_trials_);
receive_codecs.emplace( receive_codecs.emplace(
std::make_pair(red_payload_type, std::make_pair(red_payload_type,
SdpAudioFormat("red", codec_format.clockrate_hz, 1))); SdpAudioFormat("red", codec_format.clockrate_hz, 1)));

View File

@ -19,6 +19,7 @@
#include "common_audio/vad/include/vad.h" #include "common_audio/vad/include/vad.h"
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/test/Channel.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "test/scoped_key_value_config.h"
namespace webrtc { namespace webrtc {
@ -37,6 +38,7 @@ class TestRedFec {
void Run(); void Run();
void OpenOutFile(int16_t testNumber); void OpenOutFile(int16_t testNumber);
test::ScopedKeyValueConfig field_trials_;
const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_; const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
std::unique_ptr<AudioCodingModule> _acmA; std::unique_ptr<AudioCodingModule> _acmA;