Optional: Use nullopt and implicit construction in /modules/audio_coding
Changes places where we explicitly construct an Optional to instead use nullopt or the requisite value type only. This CL was uploaded by git cl split. R=kwiberg@webrtc.org Bug: None Change-Id: I055411a3e521964c81100869a197dd92f5608f1b Reviewed-on: https://webrtc-review.googlesource.com/23619 Commit-Queue: Oskar Sundbom <ossu@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Elad Alon <eladalon@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20728}
This commit is contained in:
committed by
Commit Bot
parent
f715c53bca
commit
12ab00b4d8
@ -103,7 +103,7 @@ int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
|
||||
last_audio_decoder_ = ci;
|
||||
last_audio_format_ = neteq_->GetDecoderFormat(ci->pltype);
|
||||
RTC_DCHECK(last_audio_format_);
|
||||
last_packet_sample_rate_hz_ = rtc::Optional<int>(ci->plfreq);
|
||||
last_packet_sample_rate_hz_ = ci->plfreq;
|
||||
}
|
||||
} // |crit_sect_| is released.
|
||||
|
||||
@ -272,9 +272,9 @@ void AcmReceiver::FlushBuffers() {
|
||||
void AcmReceiver::RemoveAllCodecs() {
|
||||
rtc::CritScope lock(&crit_sect_);
|
||||
neteq_->RemoveAllPayloadTypes();
|
||||
last_audio_decoder_ = rtc::Optional<CodecInst>();
|
||||
last_audio_format_ = rtc::Optional<SdpAudioFormat>();
|
||||
last_packet_sample_rate_hz_ = rtc::Optional<int>();
|
||||
last_audio_decoder_ = rtc::nullopt;
|
||||
last_audio_format_ = rtc::nullopt;
|
||||
last_packet_sample_rate_hz_ = rtc::nullopt;
|
||||
}
|
||||
|
||||
int AcmReceiver::RemoveCodec(uint8_t payload_type) {
|
||||
@ -285,9 +285,9 @@ int AcmReceiver::RemoveCodec(uint8_t payload_type) {
|
||||
return -1;
|
||||
}
|
||||
if (last_audio_decoder_ && payload_type == last_audio_decoder_->pltype) {
|
||||
last_audio_decoder_ = rtc::Optional<CodecInst>();
|
||||
last_audio_format_ = rtc::Optional<SdpAudioFormat>();
|
||||
last_packet_sample_rate_hz_ = rtc::Optional<int>();
|
||||
last_audio_decoder_ = rtc::nullopt;
|
||||
last_audio_format_ = rtc::nullopt;
|
||||
last_packet_sample_rate_hz_ = rtc::nullopt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -483,8 +483,7 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
|
||||
// of type "speech."
|
||||
ASSERT_TRUE(packet_sent_);
|
||||
ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
|
||||
EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq),
|
||||
receiver_->last_packet_sample_rate_hz());
|
||||
EXPECT_EQ(c.inst.plfreq, receiver_->last_packet_sample_rate_hz());
|
||||
|
||||
// Set VAD on to send DTX. Then check if the "Last Audio codec" returns
|
||||
// the expected codec.
|
||||
@ -496,8 +495,7 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
|
||||
InsertOnePacketOfSilence(c.id);
|
||||
ASSERT_TRUE(packet_sent_);
|
||||
}
|
||||
EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq),
|
||||
receiver_->last_packet_sample_rate_hz());
|
||||
EXPECT_EQ(c.inst.plfreq, receiver_->last_packet_sample_rate_hz());
|
||||
EXPECT_EQ(0, receiver_->LastAudioCodec(&codec));
|
||||
EXPECT_TRUE(CodecsEqual(c.inst, codec));
|
||||
}
|
||||
|
||||
@ -606,21 +606,20 @@ rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const {
|
||||
if (encoder_factory_) {
|
||||
auto* ci = encoder_factory_->codec_manager.GetCodecInst();
|
||||
if (ci) {
|
||||
return rtc::Optional<CodecInst>(*ci);
|
||||
return *ci;
|
||||
}
|
||||
CreateSpeechEncoderIfNecessary(encoder_factory_.get());
|
||||
const std::unique_ptr<AudioEncoder>& enc =
|
||||
encoder_factory_->codec_manager.GetStackParams()->speech_encoder;
|
||||
if (enc) {
|
||||
return rtc::Optional<CodecInst>(
|
||||
acm2::CodecManager::ForgeCodecInst(enc.get()));
|
||||
return acm2::CodecManager::ForgeCodecInst(enc.get());
|
||||
}
|
||||
return rtc::Optional<CodecInst>();
|
||||
return rtc::nullopt;
|
||||
} else {
|
||||
return encoder_stack_
|
||||
? rtc::Optional<CodecInst>(
|
||||
acm2::CodecManager::ForgeCodecInst(encoder_stack_.get()))
|
||||
: rtc::Optional<CodecInst>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -639,8 +638,7 @@ int AudioCodingModuleImpl::SendFrequency() const {
|
||||
void AudioCodingModuleImpl::SetBitRate(int bitrate_bps) {
|
||||
rtc::CritScope lock(&acm_crit_sect_);
|
||||
if (encoder_stack_) {
|
||||
encoder_stack_->OnReceivedUplinkBandwidth(bitrate_bps,
|
||||
rtc::Optional<int64_t>());
|
||||
encoder_stack_->OnReceivedUplinkBandwidth(bitrate_bps, rtc::nullopt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -184,8 +184,7 @@ class AudioCodingModuleTestOldApi : public ::testing::Test {
|
||||
|
||||
// Set up L16 codec.
|
||||
virtual void SetUpL16Codec() {
|
||||
audio_format_ =
|
||||
rtc::Optional<SdpAudioFormat>(SdpAudioFormat("L16", kSampleRateHz, 1));
|
||||
audio_format_ = SdpAudioFormat("L16", kSampleRateHz, 1);
|
||||
ASSERT_EQ(0, AudioCodingModule::Codec("L16", &codec_, kSampleRateHz, 1));
|
||||
codec_.pltype = kPayloadType;
|
||||
}
|
||||
@ -660,8 +659,7 @@ class AcmIsacMtTestOldApi : public AudioCodingModuleMtTestOldApi {
|
||||
|
||||
void RegisterCodec() override {
|
||||
static_assert(kSampleRateHz == 16000, "test designed for iSAC 16 kHz");
|
||||
audio_format_ =
|
||||
rtc::Optional<SdpAudioFormat>(SdpAudioFormat("isac", kSampleRateHz, 1));
|
||||
audio_format_ = SdpAudioFormat("isac", kSampleRateHz, 1);
|
||||
AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1);
|
||||
codec_.pltype = kPayloadType;
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ bool CodecManager::RegisterEncoder(const CodecInst& send_codec) {
|
||||
codec_stack_params_.use_cng = false;
|
||||
}
|
||||
|
||||
send_codec_inst_ = rtc::Optional<CodecInst>(send_codec);
|
||||
send_codec_inst_ = send_codec;
|
||||
recreate_encoder_ = true; // Caller must recreate it.
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class CodecManager final {
|
||||
return send_codec_inst_ ? &*send_codec_inst_ : nullptr;
|
||||
}
|
||||
|
||||
void UnsetCodecInst() { send_codec_inst_ = rtc::Optional<CodecInst>(); }
|
||||
void UnsetCodecInst() { send_codec_inst_ = rtc::nullopt; }
|
||||
|
||||
const RentACodec::StackParameters* GetStackParams() const {
|
||||
return &codec_stack_params_;
|
||||
|
||||
@ -55,7 +55,7 @@ rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
|
||||
rtc::Optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) {
|
||||
rtc::Optional<int> mi = CodecIndexFromId(codec_id);
|
||||
return mi ? rtc::Optional<CodecInst>(Database()[*mi])
|
||||
: rtc::Optional<CodecInst>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByInst(
|
||||
@ -69,7 +69,7 @@ rtc::Optional<CodecInst> RentACodec::CodecInstByParams(const char* payload_name,
|
||||
rtc::Optional<CodecId> codec_id =
|
||||
CodecIdByParams(payload_name, sampling_freq_hz, channels);
|
||||
if (!codec_id)
|
||||
return rtc::Optional<CodecInst>();
|
||||
return rtc::nullopt;
|
||||
rtc::Optional<CodecInst> ci = CodecInstById(*codec_id);
|
||||
RTC_DCHECK(ci);
|
||||
|
||||
@ -90,7 +90,7 @@ rtc::Optional<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id,
|
||||
return i ? rtc::Optional<bool>(
|
||||
ACMCodecDB::codec_settings_[*i].channel_support >=
|
||||
num_channels)
|
||||
: rtc::Optional<bool>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
rtc::ArrayView<const CodecInst> RentACodec::Database() {
|
||||
@ -103,12 +103,11 @@ rtc::Optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
|
||||
size_t num_channels) {
|
||||
rtc::Optional<int> i = CodecIndexFromId(codec_id);
|
||||
if (!i)
|
||||
return rtc::Optional<NetEqDecoder>();
|
||||
return rtc::nullopt;
|
||||
const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i];
|
||||
return rtc::Optional<NetEqDecoder>(
|
||||
(ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
|
||||
? NetEqDecoder::kDecoderOpus_2ch
|
||||
: ned);
|
||||
return (ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
|
||||
? NetEqDecoder::kDecoderOpus_2ch
|
||||
: ned;
|
||||
}
|
||||
|
||||
RentACodec::RegistrationResult RentACodec::RegisterCngPayloadType(
|
||||
@ -277,7 +276,7 @@ std::unique_ptr<AudioEncoder> RentACodec::RentEncoderStack(
|
||||
|
||||
auto pt = [¶m](const std::map<int, int>& m) {
|
||||
auto it = m.find(param->speech_encoder->SampleRateHz());
|
||||
return it == m.end() ? rtc::Optional<int>()
|
||||
return it == m.end() ? rtc::nullopt
|
||||
: rtc::Optional<int>(it->second);
|
||||
};
|
||||
auto cng_pt = pt(param->cng_payload_types);
|
||||
|
||||
@ -111,14 +111,14 @@ class RentACodec {
|
||||
const int i = static_cast<int>(codec_id);
|
||||
return i >= 0 && i < static_cast<int>(NumberOfCodecs())
|
||||
? rtc::Optional<int>(i)
|
||||
: rtc::Optional<int>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
static inline rtc::Optional<CodecId> CodecIdFromIndex(int codec_index) {
|
||||
return static_cast<size_t>(codec_index) < NumberOfCodecs()
|
||||
? rtc::Optional<RentACodec::CodecId>(
|
||||
static_cast<RentACodec::CodecId>(codec_index))
|
||||
: rtc::Optional<RentACodec::CodecId>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
static rtc::Optional<CodecId> CodecIdByParams(const char* payload_name,
|
||||
|
||||
@ -58,68 +58,61 @@ AudioNetworkAdaptorImpl::AudioNetworkAdaptorImpl(
|
||||
AudioNetworkAdaptorImpl::~AudioNetworkAdaptorImpl() = default;
|
||||
|
||||
void AudioNetworkAdaptorImpl::SetUplinkBandwidth(int uplink_bandwidth_bps) {
|
||||
last_metrics_.uplink_bandwidth_bps = rtc::Optional<int>(uplink_bandwidth_bps);
|
||||
last_metrics_.uplink_bandwidth_bps = uplink_bandwidth_bps;
|
||||
DumpNetworkMetrics();
|
||||
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.uplink_bandwidth_bps =
|
||||
rtc::Optional<int>(uplink_bandwidth_bps);
|
||||
network_metrics.uplink_bandwidth_bps = uplink_bandwidth_bps;
|
||||
UpdateNetworkMetrics(network_metrics);
|
||||
}
|
||||
|
||||
void AudioNetworkAdaptorImpl::SetUplinkPacketLossFraction(
|
||||
float uplink_packet_loss_fraction) {
|
||||
last_metrics_.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(uplink_packet_loss_fraction);
|
||||
last_metrics_.uplink_packet_loss_fraction = uplink_packet_loss_fraction;
|
||||
DumpNetworkMetrics();
|
||||
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(uplink_packet_loss_fraction);
|
||||
network_metrics.uplink_packet_loss_fraction = uplink_packet_loss_fraction;
|
||||
UpdateNetworkMetrics(network_metrics);
|
||||
}
|
||||
|
||||
void AudioNetworkAdaptorImpl::SetUplinkRecoverablePacketLossFraction(
|
||||
float uplink_recoverable_packet_loss_fraction) {
|
||||
last_metrics_.uplink_recoverable_packet_loss_fraction =
|
||||
rtc::Optional<float>(uplink_recoverable_packet_loss_fraction);
|
||||
uplink_recoverable_packet_loss_fraction;
|
||||
DumpNetworkMetrics();
|
||||
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.uplink_recoverable_packet_loss_fraction =
|
||||
rtc::Optional<float>(uplink_recoverable_packet_loss_fraction);
|
||||
uplink_recoverable_packet_loss_fraction;
|
||||
UpdateNetworkMetrics(network_metrics);
|
||||
}
|
||||
|
||||
void AudioNetworkAdaptorImpl::SetRtt(int rtt_ms) {
|
||||
last_metrics_.rtt_ms = rtc::Optional<int>(rtt_ms);
|
||||
last_metrics_.rtt_ms = rtt_ms;
|
||||
DumpNetworkMetrics();
|
||||
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.rtt_ms = rtc::Optional<int>(rtt_ms);
|
||||
network_metrics.rtt_ms = rtt_ms;
|
||||
UpdateNetworkMetrics(network_metrics);
|
||||
}
|
||||
|
||||
void AudioNetworkAdaptorImpl::SetTargetAudioBitrate(
|
||||
int target_audio_bitrate_bps) {
|
||||
last_metrics_.target_audio_bitrate_bps =
|
||||
rtc::Optional<int>(target_audio_bitrate_bps);
|
||||
last_metrics_.target_audio_bitrate_bps = target_audio_bitrate_bps;
|
||||
DumpNetworkMetrics();
|
||||
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.target_audio_bitrate_bps =
|
||||
rtc::Optional<int>(target_audio_bitrate_bps);
|
||||
network_metrics.target_audio_bitrate_bps = target_audio_bitrate_bps;
|
||||
UpdateNetworkMetrics(network_metrics);
|
||||
}
|
||||
|
||||
void AudioNetworkAdaptorImpl::SetOverhead(size_t overhead_bytes_per_packet) {
|
||||
last_metrics_.overhead_bytes_per_packet =
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet);
|
||||
last_metrics_.overhead_bytes_per_packet = overhead_bytes_per_packet;
|
||||
DumpNetworkMetrics();
|
||||
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.overhead_bytes_per_packet =
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet);
|
||||
network_metrics.overhead_bytes_per_packet = overhead_bytes_per_packet;
|
||||
UpdateNetworkMetrics(network_metrics);
|
||||
}
|
||||
|
||||
@ -131,7 +124,7 @@ AudioEncoderRuntimeConfig AudioNetworkAdaptorImpl::GetEncoderRuntimeConfig() {
|
||||
|
||||
// Update ANA stats.
|
||||
auto increment_opt = [](rtc::Optional<uint32_t>& a) {
|
||||
a = rtc::Optional<uint32_t>(a.value_or(0) + 1);
|
||||
a = a.value_or(0) + 1;
|
||||
};
|
||||
if (prev_config_) {
|
||||
if (config.bitrate_bps != prev_config_->bitrate_bps) {
|
||||
@ -154,11 +147,10 @@ AudioEncoderRuntimeConfig AudioNetworkAdaptorImpl::GetEncoderRuntimeConfig() {
|
||||
increment_opt(stats_.channel_action_counter);
|
||||
}
|
||||
if (config.uplink_packet_loss_fraction) {
|
||||
stats_.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(*config.uplink_packet_loss_fraction);
|
||||
stats_.uplink_packet_loss_fraction = *config.uplink_packet_loss_fraction;
|
||||
}
|
||||
}
|
||||
prev_config_ = rtc::Optional<AudioEncoderRuntimeConfig>(config);
|
||||
prev_config_ = config;
|
||||
|
||||
// Prevent certain controllers from taking action (determined by field trials)
|
||||
if (!enable_bitrate_adaptation_ && config.bitrate_bps) {
|
||||
|
||||
@ -124,7 +124,7 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
constexpr int kBandwidth = 16000;
|
||||
Controller::NetworkMetrics check;
|
||||
check.uplink_bandwidth_bps = rtc::Optional<int>(kBandwidth);
|
||||
check.uplink_bandwidth_bps = kBandwidth;
|
||||
SetExpectCallToUpdateNetworkMetrics(states.mock_controllers, check);
|
||||
states.audio_network_adaptor->SetUplinkBandwidth(kBandwidth);
|
||||
}
|
||||
@ -134,7 +134,7 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
constexpr float kPacketLoss = 0.7f;
|
||||
Controller::NetworkMetrics check;
|
||||
check.uplink_packet_loss_fraction = rtc::Optional<float>(kPacketLoss);
|
||||
check.uplink_packet_loss_fraction = kPacketLoss;
|
||||
SetExpectCallToUpdateNetworkMetrics(states.mock_controllers, check);
|
||||
states.audio_network_adaptor->SetUplinkPacketLossFraction(kPacketLoss);
|
||||
}
|
||||
@ -144,8 +144,7 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
constexpr float kRecoverablePacketLoss = 0.1f;
|
||||
Controller::NetworkMetrics check;
|
||||
check.uplink_recoverable_packet_loss_fraction =
|
||||
rtc::Optional<float>(kRecoverablePacketLoss);
|
||||
check.uplink_recoverable_packet_loss_fraction = kRecoverablePacketLoss;
|
||||
SetExpectCallToUpdateNetworkMetrics(states.mock_controllers, check);
|
||||
states.audio_network_adaptor->SetUplinkRecoverablePacketLossFraction(
|
||||
kRecoverablePacketLoss);
|
||||
@ -155,7 +154,7 @@ TEST(AudioNetworkAdaptorImplTest, UpdateNetworkMetricsIsCalledOnSetRtt) {
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
constexpr int kRtt = 100;
|
||||
Controller::NetworkMetrics check;
|
||||
check.rtt_ms = rtc::Optional<int>(kRtt);
|
||||
check.rtt_ms = kRtt;
|
||||
SetExpectCallToUpdateNetworkMetrics(states.mock_controllers, check);
|
||||
states.audio_network_adaptor->SetRtt(kRtt);
|
||||
}
|
||||
@ -165,7 +164,7 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
constexpr int kTargetAudioBitrate = 15000;
|
||||
Controller::NetworkMetrics check;
|
||||
check.target_audio_bitrate_bps = rtc::Optional<int>(kTargetAudioBitrate);
|
||||
check.target_audio_bitrate_bps = kTargetAudioBitrate;
|
||||
SetExpectCallToUpdateNetworkMetrics(states.mock_controllers, check);
|
||||
states.audio_network_adaptor->SetTargetAudioBitrate(kTargetAudioBitrate);
|
||||
}
|
||||
@ -174,7 +173,7 @@ TEST(AudioNetworkAdaptorImplTest, UpdateNetworkMetricsIsCalledOnSetOverhead) {
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
constexpr size_t kOverhead = 64;
|
||||
Controller::NetworkMetrics check;
|
||||
check.overhead_bytes_per_packet = rtc::Optional<size_t>(kOverhead);
|
||||
check.overhead_bytes_per_packet = kOverhead;
|
||||
SetExpectCallToUpdateNetworkMetrics(states.mock_controllers, check);
|
||||
states.audio_network_adaptor->SetOverhead(kOverhead);
|
||||
}
|
||||
@ -196,8 +195,8 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kClockInitialTimeMs));
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
AudioEncoderRuntimeConfig config;
|
||||
config.bitrate_bps = rtc::Optional<int>(32000);
|
||||
config.enable_fec = rtc::Optional<bool>(true);
|
||||
config.bitrate_bps = 32000;
|
||||
config.enable_fec = true;
|
||||
|
||||
EXPECT_CALL(*states.mock_controllers[0], MakeDecision(_))
|
||||
.WillOnce(SetArgPointee<0>(config));
|
||||
@ -223,7 +222,7 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
constexpr size_t kOverhead = 64;
|
||||
|
||||
Controller::NetworkMetrics check;
|
||||
check.uplink_bandwidth_bps = rtc::Optional<int>(kBandwidth);
|
||||
check.uplink_bandwidth_bps = kBandwidth;
|
||||
int64_t timestamp_check = kClockInitialTimeMs;
|
||||
|
||||
EXPECT_CALL(*states.mock_debug_dump_writer,
|
||||
@ -232,15 +231,14 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
|
||||
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(100));
|
||||
timestamp_check += 100;
|
||||
check.uplink_packet_loss_fraction = rtc::Optional<float>(kPacketLoss);
|
||||
check.uplink_packet_loss_fraction = kPacketLoss;
|
||||
EXPECT_CALL(*states.mock_debug_dump_writer,
|
||||
DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check));
|
||||
states.audio_network_adaptor->SetUplinkPacketLossFraction(kPacketLoss);
|
||||
|
||||
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(50));
|
||||
timestamp_check += 50;
|
||||
check.uplink_recoverable_packet_loss_fraction =
|
||||
rtc::Optional<float>(kRecoverablePacketLoss);
|
||||
check.uplink_recoverable_packet_loss_fraction = kRecoverablePacketLoss;
|
||||
EXPECT_CALL(*states.mock_debug_dump_writer,
|
||||
DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check));
|
||||
states.audio_network_adaptor->SetUplinkRecoverablePacketLossFraction(
|
||||
@ -248,21 +246,21 @@ TEST(AudioNetworkAdaptorImplTest,
|
||||
|
||||
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
|
||||
timestamp_check += 200;
|
||||
check.rtt_ms = rtc::Optional<int>(kRtt);
|
||||
check.rtt_ms = kRtt;
|
||||
EXPECT_CALL(*states.mock_debug_dump_writer,
|
||||
DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check));
|
||||
states.audio_network_adaptor->SetRtt(kRtt);
|
||||
|
||||
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(150));
|
||||
timestamp_check += 150;
|
||||
check.target_audio_bitrate_bps = rtc::Optional<int>(kTargetAudioBitrate);
|
||||
check.target_audio_bitrate_bps = kTargetAudioBitrate;
|
||||
EXPECT_CALL(*states.mock_debug_dump_writer,
|
||||
DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check));
|
||||
states.audio_network_adaptor->SetTargetAudioBitrate(kTargetAudioBitrate);
|
||||
|
||||
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(50));
|
||||
timestamp_check += 50;
|
||||
check.overhead_bytes_per_packet = rtc::Optional<size_t>(kOverhead);
|
||||
check.overhead_bytes_per_packet = kOverhead;
|
||||
EXPECT_CALL(*states.mock_debug_dump_writer,
|
||||
DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check));
|
||||
states.audio_network_adaptor->SetOverhead(kOverhead);
|
||||
@ -275,8 +273,8 @@ TEST(AudioNetworkAdaptorImplTest, LogRuntimeConfigOnGetEncoderRuntimeConfig) {
|
||||
auto states = CreateAudioNetworkAdaptor();
|
||||
|
||||
AudioEncoderRuntimeConfig config;
|
||||
config.bitrate_bps = rtc::Optional<int>(32000);
|
||||
config.enable_fec = rtc::Optional<bool>(true);
|
||||
config.bitrate_bps = 32000;
|
||||
config.enable_fec = true;
|
||||
|
||||
EXPECT_CALL(*states.mock_controllers[0], MakeDecision(_))
|
||||
.WillOnce(SetArgPointee<0>(config));
|
||||
@ -291,18 +289,18 @@ TEST(AudioNetworkAdaptorImplTest, TestANAStats) {
|
||||
|
||||
// Simulate some adaptation, otherwise the stats will not show anything.
|
||||
AudioEncoderRuntimeConfig config1, config2;
|
||||
config1.bitrate_bps = rtc::Optional<int>(32000);
|
||||
config1.num_channels = rtc::Optional<size_t>(2);
|
||||
config1.enable_fec = rtc::Optional<bool>(true);
|
||||
config1.enable_dtx = rtc::Optional<bool>(true);
|
||||
config1.frame_length_ms = rtc::Optional<int>(120);
|
||||
config1.uplink_packet_loss_fraction = rtc::Optional<float>(0.1f);
|
||||
config2.bitrate_bps = rtc::Optional<int>(16000);
|
||||
config2.num_channels = rtc::Optional<size_t>(1);
|
||||
config2.enable_fec = rtc::Optional<bool>(false);
|
||||
config2.enable_dtx = rtc::Optional<bool>(false);
|
||||
config2.frame_length_ms = rtc::Optional<int>(60);
|
||||
config1.uplink_packet_loss_fraction = rtc::Optional<float>(0.1f);
|
||||
config1.bitrate_bps = 32000;
|
||||
config1.num_channels = 2;
|
||||
config1.enable_fec = true;
|
||||
config1.enable_dtx = true;
|
||||
config1.frame_length_ms = 120;
|
||||
config1.uplink_packet_loss_fraction = 0.1f;
|
||||
config2.bitrate_bps = 16000;
|
||||
config2.num_channels = 1;
|
||||
config2.enable_fec = false;
|
||||
config2.enable_dtx = false;
|
||||
config2.frame_length_ms = 60;
|
||||
config1.uplink_packet_loss_fraction = 0.1f;
|
||||
|
||||
EXPECT_CALL(*states.mock_controllers[0], MakeDecision(_))
|
||||
.WillOnce(SetArgPointee<0>(config1));
|
||||
|
||||
@ -69,7 +69,7 @@ void BitrateController::MakeDecision(AudioEncoderRuntimeConfig* config) {
|
||||
(*overhead_bytes_per_packet_ + offset) * 8 * 1000 / frame_length_ms_);
|
||||
bitrate_bps_ = std::max(0, *target_audio_bitrate_bps_ - overhead_rate_bps);
|
||||
}
|
||||
config->bitrate_bps = rtc::Optional<int>(bitrate_bps_);
|
||||
config->bitrate_bps = bitrate_bps_;
|
||||
}
|
||||
|
||||
} // namespace audio_network_adaptor
|
||||
|
||||
@ -43,7 +43,7 @@ void CheckDecision(BitrateController* controller,
|
||||
AudioEncoderRuntimeConfig config;
|
||||
config.frame_length_ms = frame_length_ms;
|
||||
controller->MakeDecision(&config);
|
||||
EXPECT_EQ(rtc::Optional<int>(expected_bitrate_bps), config.bitrate_bps);
|
||||
EXPECT_EQ(expected_bitrate_bps, config.bitrate_bps);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -58,10 +58,8 @@ TEST(AnaBitrateControllerTest, OutputInitValueWhenTargetBitrateUnknown) {
|
||||
constexpr size_t kOverheadBytesPerPacket = 64;
|
||||
BitrateController controller(BitrateController::Config(
|
||||
kInitialBitrateBps, kInitialFrameLengthMs, 0, 0));
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs * 2),
|
||||
kInitialBitrateBps);
|
||||
UpdateNetworkMetrics(&controller, rtc::nullopt, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, kInitialFrameLengthMs * 2, kInitialBitrateBps);
|
||||
}
|
||||
|
||||
TEST(AnaBitrateControllerTest, OutputInitValueWhenOverheadUnknown) {
|
||||
@ -70,10 +68,8 @@ TEST(AnaBitrateControllerTest, OutputInitValueWhenOverheadUnknown) {
|
||||
constexpr int kTargetBitrateBps = 48000;
|
||||
BitrateController controller(BitrateController::Config(
|
||||
kInitialBitrateBps, kInitialFrameLengthMs, 0, 0));
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>());
|
||||
CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs * 2),
|
||||
kInitialBitrateBps);
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, rtc::nullopt);
|
||||
CheckDecision(&controller, kInitialFrameLengthMs * 2, kInitialBitrateBps);
|
||||
}
|
||||
|
||||
TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) {
|
||||
@ -89,10 +85,8 @@ TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) {
|
||||
kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
|
||||
// Frame length unchanged, bitrate changes in accordance with
|
||||
// |metrics.target_audio_bitrate_bps| and |metrics.overhead_bytes_per_packet|.
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs),
|
||||
kBitrateBps);
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, kInitialFrameLengthMs, kBitrateBps);
|
||||
}
|
||||
|
||||
TEST(AnaBitrateControllerTest, UpdateMultipleNetworkMetricsAtOnce) {
|
||||
@ -114,13 +108,10 @@ TEST(AnaBitrateControllerTest, UpdateMultipleNetworkMetricsAtOnce) {
|
||||
kTargetBitrateBps -
|
||||
kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.target_audio_bitrate_bps =
|
||||
rtc::Optional<int>(kTargetBitrateBps);
|
||||
network_metrics.overhead_bytes_per_packet =
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket);
|
||||
network_metrics.target_audio_bitrate_bps = kTargetBitrateBps;
|
||||
network_metrics.overhead_bytes_per_packet = kOverheadBytesPerPacket;
|
||||
controller.UpdateNetworkMetrics(network_metrics);
|
||||
CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs),
|
||||
kBitrateBps);
|
||||
CheckDecision(&controller, kInitialFrameLengthMs, kBitrateBps);
|
||||
}
|
||||
|
||||
TEST(AnaBitrateControllerTest, TreatUnknownFrameLengthAsFrameLengthUnchanged) {
|
||||
@ -134,9 +125,8 @@ TEST(AnaBitrateControllerTest, TreatUnknownFrameLengthAsFrameLengthUnchanged) {
|
||||
constexpr int kBitrateBps =
|
||||
kTargetBitrateBps -
|
||||
kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps);
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, rtc::nullopt, kBitrateBps);
|
||||
}
|
||||
|
||||
TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) {
|
||||
@ -151,17 +141,15 @@ TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) {
|
||||
constexpr int kBitrateBps =
|
||||
kTargetBitrateBps -
|
||||
kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps);
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, rtc::nullopt, kBitrateBps);
|
||||
|
||||
constexpr int kFrameLengthMs = 60;
|
||||
constexpr size_t kPacketOverheadRateDiff =
|
||||
kOverheadBytesPerPacket * 8 * 1000 / 20 -
|
||||
kOverheadBytesPerPacket * 8 * 1000 / 60;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs),
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, kFrameLengthMs,
|
||||
kBitrateBps + kPacketOverheadRateDiff);
|
||||
}
|
||||
|
||||
@ -177,17 +165,15 @@ TEST(AnaBitrateControllerTest, DecreaseBitrateOnFrameLengthDecreased) {
|
||||
constexpr int kBitrateBps =
|
||||
kTargetBitrateBps -
|
||||
kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps);
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, rtc::nullopt, kBitrateBps);
|
||||
|
||||
constexpr int kFrameLengthMs = 20;
|
||||
constexpr size_t kPacketOverheadRateDiff =
|
||||
kOverheadBytesPerPacket * 8 * 1000 / 20 -
|
||||
kOverheadBytesPerPacket * 8 * 1000 / 60;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs),
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, kFrameLengthMs,
|
||||
kBitrateBps - kPacketOverheadRateDiff);
|
||||
}
|
||||
|
||||
@ -200,9 +186,8 @@ TEST(AnaBitrateControllerTest, BitrateNeverBecomesNegative) {
|
||||
// Set a target rate smaller than overhead rate, the bitrate is bounded by 0.
|
||||
constexpr int kTargetBitrateBps =
|
||||
kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs), 0);
|
||||
UpdateNetworkMetrics(&controller, kTargetBitrateBps, kOverheadBytesPerPacket);
|
||||
CheckDecision(&controller, kFrameLengthMs, 0);
|
||||
}
|
||||
|
||||
TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
|
||||
@ -217,46 +202,36 @@ TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
|
||||
int current_bitrate = rtc::checked_cast<int>(
|
||||
overall_bitrate - overhead_bytes_per_packet * 8 * 1000 / frame_length_ms);
|
||||
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet));
|
||||
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
|
||||
current_bitrate);
|
||||
UpdateNetworkMetrics(&controller, overall_bitrate, overhead_bytes_per_packet);
|
||||
CheckDecision(&controller, frame_length_ms, current_bitrate);
|
||||
|
||||
// Next: increase overall bitrate.
|
||||
overall_bitrate += 100;
|
||||
current_bitrate += 100;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet));
|
||||
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
|
||||
current_bitrate);
|
||||
UpdateNetworkMetrics(&controller, overall_bitrate, overhead_bytes_per_packet);
|
||||
CheckDecision(&controller, frame_length_ms, current_bitrate);
|
||||
|
||||
// Next: change frame length.
|
||||
frame_length_ms = 60;
|
||||
current_bitrate += rtc::checked_cast<int>(
|
||||
overhead_bytes_per_packet * 8 * 1000 / 20 -
|
||||
overhead_bytes_per_packet * 8 * 1000 / 60);
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet));
|
||||
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
|
||||
current_bitrate);
|
||||
UpdateNetworkMetrics(&controller, overall_bitrate, overhead_bytes_per_packet);
|
||||
CheckDecision(&controller, frame_length_ms, current_bitrate);
|
||||
|
||||
// Next: change overhead.
|
||||
overhead_bytes_per_packet -= 30;
|
||||
current_bitrate += 30 * 8 * 1000 / frame_length_ms;
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet));
|
||||
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
|
||||
current_bitrate);
|
||||
UpdateNetworkMetrics(&controller, overall_bitrate, overhead_bytes_per_packet);
|
||||
CheckDecision(&controller, frame_length_ms, current_bitrate);
|
||||
|
||||
// Next: change frame length.
|
||||
frame_length_ms = 20;
|
||||
current_bitrate -= rtc::checked_cast<int>(
|
||||
overhead_bytes_per_packet * 8 * 1000 / 20 -
|
||||
overhead_bytes_per_packet * 8 * 1000 / 60);
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet));
|
||||
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
|
||||
current_bitrate);
|
||||
UpdateNetworkMetrics(&controller, overall_bitrate, overhead_bytes_per_packet);
|
||||
CheckDecision(&controller, frame_length_ms, current_bitrate);
|
||||
|
||||
// Next: decrease overall bitrate and frame length.
|
||||
overall_bitrate -= 100;
|
||||
@ -266,10 +241,8 @@ TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
|
||||
overhead_bytes_per_packet * 8 * 1000 / 20 -
|
||||
overhead_bytes_per_packet * 8 * 1000 / 60);
|
||||
|
||||
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet));
|
||||
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
|
||||
current_bitrate);
|
||||
UpdateNetworkMetrics(&controller, overall_bitrate, overhead_bytes_per_packet);
|
||||
CheckDecision(&controller, frame_length_ms, current_bitrate);
|
||||
}
|
||||
|
||||
} // namespace audio_network_adaptor
|
||||
|
||||
@ -55,7 +55,7 @@ void ChannelController::MakeDecision(AudioEncoderRuntimeConfig* config) {
|
||||
std::min(static_cast<size_t>(2), config_.num_encoder_channels);
|
||||
}
|
||||
}
|
||||
config->num_channels = rtc::Optional<size_t>(channels_to_encode_);
|
||||
config->num_channels = channels_to_encode_;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -41,7 +41,7 @@ void CheckDecision(ChannelController* controller,
|
||||
}
|
||||
AudioEncoderRuntimeConfig config;
|
||||
controller->MakeDecision(&config);
|
||||
EXPECT_EQ(rtc::Optional<size_t>(expected_num_channels), config.num_channels);
|
||||
EXPECT_EQ(expected_num_channels, config.num_channels);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -49,37 +49,35 @@ void CheckDecision(ChannelController* controller,
|
||||
TEST(ChannelControllerTest, OutputInitValueWhenUplinkBandwidthUnknown) {
|
||||
constexpr int kInitChannels = 2;
|
||||
auto controller = CreateChannelController(kInitChannels);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), kInitChannels);
|
||||
CheckDecision(controller.get(), rtc::nullopt, kInitChannels);
|
||||
}
|
||||
|
||||
TEST(ChannelControllerTest, SwitchTo2ChannelsOnHighUplinkBandwidth) {
|
||||
constexpr int kInitChannels = 1;
|
||||
auto controller = CreateChannelController(kInitChannels);
|
||||
// Use high bandwidth to check output switch to 2.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kChannel1To2BandwidthBps),
|
||||
2);
|
||||
CheckDecision(controller.get(), kChannel1To2BandwidthBps, 2);
|
||||
}
|
||||
|
||||
TEST(ChannelControllerTest, SwitchTo1ChannelOnLowUplinkBandwidth) {
|
||||
constexpr int kInitChannels = 2;
|
||||
auto controller = CreateChannelController(kInitChannels);
|
||||
// Use low bandwidth to check output switch to 1.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kChannel2To1BandwidthBps),
|
||||
1);
|
||||
CheckDecision(controller.get(), kChannel2To1BandwidthBps, 1);
|
||||
}
|
||||
|
||||
TEST(ChannelControllerTest, Maintain1ChannelOnMediumUplinkBandwidth) {
|
||||
constexpr int kInitChannels = 1;
|
||||
auto controller = CreateChannelController(kInitChannels);
|
||||
// Use between-thresholds bandwidth to check output remains at 1.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps), 1);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, 1);
|
||||
}
|
||||
|
||||
TEST(ChannelControllerTest, Maintain2ChannelsOnMediumUplinkBandwidth) {
|
||||
constexpr int kInitChannels = 2;
|
||||
auto controller = CreateChannelController(kInitChannels);
|
||||
// Use between-thresholds bandwidth to check output remains at 2.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps), 2);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, 2);
|
||||
}
|
||||
|
||||
TEST(ChannelControllerTest, CheckBehaviorOnChangingUplinkBandwidth) {
|
||||
@ -87,18 +85,16 @@ TEST(ChannelControllerTest, CheckBehaviorOnChangingUplinkBandwidth) {
|
||||
auto controller = CreateChannelController(kInitChannels);
|
||||
|
||||
// Use between-thresholds bandwidth to check output remains at 1.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps), 1);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, 1);
|
||||
|
||||
// Use high bandwidth to check output switch to 2.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kChannel1To2BandwidthBps),
|
||||
2);
|
||||
CheckDecision(controller.get(), kChannel1To2BandwidthBps, 2);
|
||||
|
||||
// Use between-thresholds bandwidth to check output remains at 2.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps), 2);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, 2);
|
||||
|
||||
// Use low bandwidth to check output switch to 1.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kChannel2To1BandwidthBps),
|
||||
1);
|
||||
CheckDecision(controller.get(), kChannel2To1BandwidthBps, 1);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -327,7 +327,7 @@ ControllerManagerImpl::ControllerManagerImpl(
|
||||
const std::map<const Controller*, std::pair<int, float>>& scoring_points)
|
||||
: config_(config),
|
||||
controllers_(std::move(controllers)),
|
||||
last_reordering_time_ms_(rtc::Optional<int64_t>()),
|
||||
last_reordering_time_ms_(rtc::nullopt),
|
||||
last_scoring_point_(0, 0.0) {
|
||||
for (auto& controller : controllers_)
|
||||
default_sorted_controllers_.push_back(controller.get());
|
||||
@ -389,7 +389,7 @@ std::vector<Controller*> ControllerManagerImpl::GetSortedControllers(
|
||||
|
||||
if (sorted_controllers_ != sorted_controllers) {
|
||||
sorted_controllers_ = sorted_controllers;
|
||||
last_reordering_time_ms_ = rtc::Optional<int64_t>(now_ms);
|
||||
last_reordering_time_ms_ = now_ms;
|
||||
last_scoring_point_ = scoring_point;
|
||||
}
|
||||
return sorted_controllers_;
|
||||
|
||||
@ -124,41 +124,38 @@ TEST(ControllerManagerTest, ControllersInDefaultOrderOnEmptyNetworkMetrics) {
|
||||
auto states = CreateControllerManager();
|
||||
// |network_metrics| are empty, and the controllers are supposed to follow the
|
||||
// default order.
|
||||
CheckControllersOrder(&states, rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
CheckControllersOrder(&states, rtc::nullopt, rtc::nullopt,
|
||||
{0, 1, 2, 3});
|
||||
}
|
||||
|
||||
TEST(ControllerManagerTest, ControllersWithoutCharPointAtEndAndInDefaultOrder) {
|
||||
auto states = CreateControllerManager();
|
||||
CheckControllersOrder(&states, rtc::Optional<int>(0),
|
||||
rtc::Optional<float>(0.0),
|
||||
CheckControllersOrder(&states, 0,
|
||||
0.0,
|
||||
{kNumControllers - 2, kNumControllers - 1, -1, -1});
|
||||
}
|
||||
|
||||
TEST(ControllerManagerTest, ControllersWithCharPointDependOnNetworkMetrics) {
|
||||
auto states = CreateControllerManager();
|
||||
CheckControllersOrder(
|
||||
&states, rtc::Optional<int>(kChracteristicBandwithBps[1]),
|
||||
rtc::Optional<float>(kChracteristicPacketLossFraction[1]),
|
||||
{kNumControllers - 2, kNumControllers - 1, 1, 0});
|
||||
CheckControllersOrder(&states, kChracteristicBandwithBps[1],
|
||||
kChracteristicPacketLossFraction[1],
|
||||
{kNumControllers - 2, kNumControllers - 1, 1, 0});
|
||||
}
|
||||
|
||||
TEST(ControllerManagerTest, DoNotReorderBeforeMinReordingTime) {
|
||||
rtc::ScopedFakeClock fake_clock;
|
||||
auto states = CreateControllerManager();
|
||||
CheckControllersOrder(
|
||||
&states, rtc::Optional<int>(kChracteristicBandwithBps[0]),
|
||||
rtc::Optional<float>(kChracteristicPacketLossFraction[0]),
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
CheckControllersOrder(&states, kChracteristicBandwithBps[0],
|
||||
kChracteristicPacketLossFraction[0],
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
fake_clock.AdvanceTime(
|
||||
rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs - 1));
|
||||
// Move uplink bandwidth and packet loss fraction to the other controller's
|
||||
// characteristic point, which would cause controller manager to reorder the
|
||||
// controllers if time had reached min reordering time.
|
||||
CheckControllersOrder(
|
||||
&states, rtc::Optional<int>(kChracteristicBandwithBps[1]),
|
||||
rtc::Optional<float>(kChracteristicPacketLossFraction[1]),
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
CheckControllersOrder(&states, kChracteristicBandwithBps[1],
|
||||
kChracteristicPacketLossFraction[1],
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
}
|
||||
|
||||
TEST(ControllerManagerTest, ReorderBeyondMinReordingTimeAndMinDistance) {
|
||||
@ -171,16 +168,14 @@ TEST(ControllerManagerTest, ReorderBeyondMinReordingTimeAndMinDistance) {
|
||||
2.0f;
|
||||
// Set network metrics to be in the middle between the characteristic points
|
||||
// of two controllers.
|
||||
CheckControllersOrder(&states, rtc::Optional<int>(kBandwidthBps),
|
||||
rtc::Optional<float>(kPacketLossFraction),
|
||||
CheckControllersOrder(&states, kBandwidthBps, kPacketLossFraction,
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
fake_clock.AdvanceTime(
|
||||
rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs));
|
||||
// Then let network metrics move a little towards the other controller.
|
||||
CheckControllersOrder(
|
||||
&states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps - 1),
|
||||
rtc::Optional<float>(kPacketLossFraction),
|
||||
{kNumControllers - 2, kNumControllers - 1, 1, 0});
|
||||
CheckControllersOrder(&states, kBandwidthBps - kMinBandwithChangeBps - 1,
|
||||
kPacketLossFraction,
|
||||
{kNumControllers - 2, kNumControllers - 1, 1, 0});
|
||||
}
|
||||
|
||||
TEST(ControllerManagerTest, DoNotReorderIfNetworkMetricsChangeTooSmall) {
|
||||
@ -193,16 +188,14 @@ TEST(ControllerManagerTest, DoNotReorderIfNetworkMetricsChangeTooSmall) {
|
||||
2.0f;
|
||||
// Set network metrics to be in the middle between the characteristic points
|
||||
// of two controllers.
|
||||
CheckControllersOrder(&states, rtc::Optional<int>(kBandwidthBps),
|
||||
rtc::Optional<float>(kPacketLossFraction),
|
||||
CheckControllersOrder(&states, kBandwidthBps, kPacketLossFraction,
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
fake_clock.AdvanceTime(
|
||||
rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs));
|
||||
// Then let network metrics move a little towards the other controller.
|
||||
CheckControllersOrder(
|
||||
&states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps + 1),
|
||||
rtc::Optional<float>(kPacketLossFraction),
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
CheckControllersOrder(&states, kBandwidthBps - kMinBandwithChangeBps + 1,
|
||||
kPacketLossFraction,
|
||||
{kNumControllers - 2, kNumControllers - 1, 0, 1});
|
||||
}
|
||||
|
||||
#if WEBRTC_ENABLE_PROTOBUF
|
||||
@ -312,24 +305,19 @@ void CheckControllersOrder(const std::vector<Controller*>& controllers,
|
||||
// initial values.
|
||||
switch (expected_types[i]) {
|
||||
case ControllerType::FEC:
|
||||
EXPECT_EQ(rtc::Optional<bool>(kInitialFecEnabled),
|
||||
encoder_config.enable_fec);
|
||||
EXPECT_EQ(kInitialFecEnabled, encoder_config.enable_fec);
|
||||
break;
|
||||
case ControllerType::CHANNEL:
|
||||
EXPECT_EQ(rtc::Optional<size_t>(kIntialChannelsToEncode),
|
||||
encoder_config.num_channels);
|
||||
EXPECT_EQ(kIntialChannelsToEncode, encoder_config.num_channels);
|
||||
break;
|
||||
case ControllerType::DTX:
|
||||
EXPECT_EQ(rtc::Optional<bool>(kInitialDtxEnabled),
|
||||
encoder_config.enable_dtx);
|
||||
EXPECT_EQ(kInitialDtxEnabled, encoder_config.enable_dtx);
|
||||
break;
|
||||
case ControllerType::FRAME_LENGTH:
|
||||
EXPECT_EQ(rtc::Optional<int>(kInitialFrameLengthMs),
|
||||
encoder_config.frame_length_ms);
|
||||
EXPECT_EQ(kInitialFrameLengthMs, encoder_config.frame_length_ms);
|
||||
break;
|
||||
case ControllerType::BIT_RATE:
|
||||
EXPECT_EQ(rtc::Optional<int>(kInitialBitrateBps),
|
||||
encoder_config.bitrate_bps);
|
||||
EXPECT_EQ(kInitialBitrateBps, encoder_config.bitrate_bps);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,10 +436,8 @@ TEST(ControllerManagerTest, CreateFromConfigStringAndCheckReordering) {
|
||||
auto states = CreateControllerManager(config_string);
|
||||
|
||||
Controller::NetworkMetrics metrics;
|
||||
metrics.uplink_bandwidth_bps =
|
||||
rtc::Optional<int>(kChracteristicBandwithBps[0]);
|
||||
metrics.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(kChracteristicPacketLossFraction[0]);
|
||||
metrics.uplink_bandwidth_bps = kChracteristicBandwithBps[0];
|
||||
metrics.uplink_packet_loss_fraction = kChracteristicPacketLossFraction[0];
|
||||
|
||||
auto controllers = states.controller_manager->GetSortedControllers(metrics);
|
||||
CheckControllersOrder(controllers,
|
||||
@ -460,10 +446,8 @@ TEST(ControllerManagerTest, CreateFromConfigStringAndCheckReordering) {
|
||||
ControllerType::CHANNEL, ControllerType::DTX,
|
||||
ControllerType::BIT_RATE});
|
||||
|
||||
metrics.uplink_bandwidth_bps =
|
||||
rtc::Optional<int>(kChracteristicBandwithBps[1]);
|
||||
metrics.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(kChracteristicPacketLossFraction[1]);
|
||||
metrics.uplink_bandwidth_bps = kChracteristicBandwithBps[1];
|
||||
metrics.uplink_packet_loss_fraction = kChracteristicPacketLossFraction[1];
|
||||
fake_clock.AdvanceTime(
|
||||
rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs - 1));
|
||||
controllers = states.controller_manager->GetSortedControllers(metrics);
|
||||
|
||||
@ -44,7 +44,7 @@ void DtxController::MakeDecision(AudioEncoderRuntimeConfig* config) {
|
||||
dtx_enabled_ = true;
|
||||
}
|
||||
}
|
||||
config->enable_dtx = rtc::Optional<bool>(dtx_enabled_);
|
||||
config->enable_dtx = dtx_enabled_;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -39,7 +39,7 @@ void CheckDecision(DtxController* controller,
|
||||
}
|
||||
AudioEncoderRuntimeConfig config;
|
||||
controller->MakeDecision(&config);
|
||||
EXPECT_EQ(rtc::Optional<bool>(expected_dtx_enabled), config.enable_dtx);
|
||||
EXPECT_EQ(expected_dtx_enabled, config.enable_dtx);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -47,43 +47,35 @@ void CheckDecision(DtxController* controller,
|
||||
TEST(DtxControllerTest, OutputInitValueWhenUplinkBandwidthUnknown) {
|
||||
constexpr bool kInitialDtxEnabled = true;
|
||||
auto controller = CreateController(kInitialDtxEnabled);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), kInitialDtxEnabled);
|
||||
CheckDecision(controller.get(), rtc::nullopt, kInitialDtxEnabled);
|
||||
}
|
||||
|
||||
TEST(DtxControllerTest, TurnOnDtxForLowUplinkBandwidth) {
|
||||
auto controller = CreateController(false);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kDtxEnablingBandwidthBps),
|
||||
true);
|
||||
CheckDecision(controller.get(), kDtxEnablingBandwidthBps, true);
|
||||
}
|
||||
|
||||
TEST(DtxControllerTest, TurnOffDtxForHighUplinkBandwidth) {
|
||||
auto controller = CreateController(true);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kDtxDisablingBandwidthBps),
|
||||
false);
|
||||
CheckDecision(controller.get(), kDtxDisablingBandwidthBps, false);
|
||||
}
|
||||
|
||||
TEST(DtxControllerTest, MaintainDtxOffForMediumUplinkBandwidth) {
|
||||
auto controller = CreateController(false);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
false);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, false);
|
||||
}
|
||||
|
||||
TEST(DtxControllerTest, MaintainDtxOnForMediumUplinkBandwidth) {
|
||||
auto controller = CreateController(true);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
true);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, true);
|
||||
}
|
||||
|
||||
TEST(DtxControllerTest, CheckBehaviorOnChangingUplinkBandwidth) {
|
||||
auto controller = CreateController(false);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
false);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kDtxEnablingBandwidthBps),
|
||||
true);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
true);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kDtxDisablingBandwidthBps),
|
||||
false);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, false);
|
||||
CheckDecision(controller.get(), kDtxEnablingBandwidthBps, true);
|
||||
CheckDecision(controller.get(), kMediumBandwidthBps, true);
|
||||
CheckDecision(controller.get(), kDtxDisablingBandwidthBps, false);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -51,13 +51,12 @@ EventLogWriterStates CreateEventLogWriter() {
|
||||
state.event_log_writer.reset(new EventLogWriter(
|
||||
state.event_log.get(), kMinBitrateChangeBps, kMinBitrateChangeFraction,
|
||||
kMinPacketLossChangeFraction));
|
||||
state.runtime_config.bitrate_bps = rtc::Optional<int>(kHighBitrateBps);
|
||||
state.runtime_config.frame_length_ms = rtc::Optional<int>(kFrameLengthMs);
|
||||
state.runtime_config.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(kPacketLossFraction);
|
||||
state.runtime_config.enable_fec = rtc::Optional<bool>(kEnableFec);
|
||||
state.runtime_config.enable_dtx = rtc::Optional<bool>(kEnableDtx);
|
||||
state.runtime_config.num_channels = rtc::Optional<size_t>(kNumChannels);
|
||||
state.runtime_config.bitrate_bps = kHighBitrateBps;
|
||||
state.runtime_config.frame_length_ms = kFrameLengthMs;
|
||||
state.runtime_config.uplink_packet_loss_fraction = kPacketLossFraction;
|
||||
state.runtime_config.enable_fec = kEnableFec;
|
||||
state.runtime_config.enable_dtx = kEnableDtx;
|
||||
state.runtime_config.num_channels = kNumChannels;
|
||||
return state;
|
||||
}
|
||||
} // namespace
|
||||
@ -86,7 +85,7 @@ TEST(EventLogWriterTest, LogFecStateChange) {
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
|
||||
state.runtime_config.enable_fec = rtc::Optional<bool>(!kEnableFec);
|
||||
state.runtime_config.enable_fec = !kEnableFec;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -100,7 +99,7 @@ TEST(EventLogWriterTest, LogDtxStateChange) {
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
|
||||
state.runtime_config.enable_dtx = rtc::Optional<bool>(!kEnableDtx);
|
||||
state.runtime_config.enable_dtx = !kEnableDtx;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -114,7 +113,7 @@ TEST(EventLogWriterTest, LogChannelChange) {
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
|
||||
state.runtime_config.num_channels = rtc::Optional<size_t>(kNumChannels + 1);
|
||||
state.runtime_config.num_channels = kNumChannels + 1;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -128,7 +127,7 @@ TEST(EventLogWriterTest, LogFrameLengthChange) {
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
|
||||
state.runtime_config.frame_length_ms = rtc::Optional<int>(20);
|
||||
state.runtime_config.frame_length_ms = 20;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -141,8 +140,7 @@ TEST(EventLogWriterTest, DoNotLogSmallBitrateChange) {
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
state.runtime_config.bitrate_bps =
|
||||
rtc::Optional<int>(kHighBitrateBps + kMinBitrateChangeBps - 1);
|
||||
state.runtime_config.bitrate_bps = kHighBitrateBps + kMinBitrateChangeBps - 1;
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
}
|
||||
|
||||
@ -156,8 +154,7 @@ TEST(EventLogWriterTest, LogLargeBitrateChange) {
|
||||
// min change rule. We make sure that the min change rule applies.
|
||||
RTC_DCHECK_GT(kHighBitrateBps * kMinBitrateChangeFraction,
|
||||
kMinBitrateChangeBps);
|
||||
state.runtime_config.bitrate_bps =
|
||||
rtc::Optional<int>(kHighBitrateBps + kMinBitrateChangeBps);
|
||||
state.runtime_config.bitrate_bps = kHighBitrateBps + kMinBitrateChangeBps;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -166,15 +163,15 @@ TEST(EventLogWriterTest, LogLargeBitrateChange) {
|
||||
|
||||
TEST(EventLogWriterTest, LogMinBitrateChangeFractionOnLowBitrateChange) {
|
||||
auto state = CreateEventLogWriter();
|
||||
state.runtime_config.bitrate_bps = rtc::Optional<int>(kLowBitrateBps);
|
||||
state.runtime_config.bitrate_bps = kLowBitrateBps;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
// At high bitrate, the min change rule requires a larger change than the min
|
||||
// fraction rule. We make sure that the min fraction rule applies.
|
||||
state.runtime_config.bitrate_bps = rtc::Optional<int>(
|
||||
kLowBitrateBps + kLowBitrateBps * kMinBitrateChangeFraction);
|
||||
state.runtime_config.bitrate_bps =
|
||||
kLowBitrateBps + kLowBitrateBps * kMinBitrateChangeFraction;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -187,9 +184,9 @@ TEST(EventLogWriterTest, DoNotLogSmallPacketLossFractionChange) {
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
|
||||
state.runtime_config.uplink_packet_loss_fraction =
|
||||
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction -
|
||||
0.001f);
|
||||
0.001f;
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
}
|
||||
|
||||
@ -199,8 +196,8 @@ TEST(EventLogWriterTest, LogLargePacketLossFractionChange) {
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
|
||||
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction);
|
||||
state.runtime_config.uplink_packet_loss_fraction =
|
||||
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -213,9 +210,9 @@ TEST(EventLogWriterTest, LogJustOnceOnMultipleChanges) {
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
|
||||
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction);
|
||||
state.runtime_config.frame_length_ms = rtc::Optional<int>(20);
|
||||
state.runtime_config.uplink_packet_loss_fraction =
|
||||
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction;
|
||||
state.runtime_config.frame_length_ms = 20;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
@ -228,14 +225,13 @@ TEST(EventLogWriterTest, LogAfterGradualChange) {
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
state.runtime_config.bitrate_bps =
|
||||
rtc::Optional<int>(kHighBitrateBps + kMinBitrateChangeBps);
|
||||
state.runtime_config.bitrate_bps = kHighBitrateBps + kMinBitrateChangeBps;
|
||||
EXPECT_CALL(*state.event_log,
|
||||
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
|
||||
.Times(1);
|
||||
for (int bitrate_bps = kHighBitrateBps;
|
||||
bitrate_bps <= kHighBitrateBps + kMinBitrateChangeBps; bitrate_bps++) {
|
||||
state.runtime_config.bitrate_bps = rtc::Optional<int>(bitrate_bps);
|
||||
state.runtime_config.bitrate_bps = bitrate_bps;
|
||||
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,9 +21,7 @@ namespace webrtc {
|
||||
namespace {
|
||||
class NullSmoothingFilter final : public SmoothingFilter {
|
||||
public:
|
||||
void AddSample(float sample) override {
|
||||
last_sample_ = rtc::Optional<float>(sample);
|
||||
}
|
||||
void AddSample(float sample) override { last_sample_ = sample; }
|
||||
|
||||
rtc::Optional<float> GetAverage() override { return last_sample_; }
|
||||
|
||||
@ -85,10 +83,9 @@ void FecControllerPlrBased::MakeDecision(AudioEncoderRuntimeConfig* config) {
|
||||
fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(packet_loss)
|
||||
: FecEnablingDecision(packet_loss);
|
||||
|
||||
config->enable_fec = rtc::Optional<bool>(fec_enabled_);
|
||||
config->enable_fec = fec_enabled_;
|
||||
|
||||
config->uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(packet_loss ? *packet_loss : 0.0);
|
||||
config->uplink_packet_loss_fraction = packet_loss ? *packet_loss : 0.0;
|
||||
}
|
||||
|
||||
bool FecControllerPlrBased::FecEnablingDecision(
|
||||
|
||||
@ -95,17 +95,10 @@ void UpdateNetworkMetrics(FecControllerPlrBasedTestStates* states,
|
||||
states->controller->UpdateNetworkMetrics(network_metrics);
|
||||
// This is called during CheckDecision().
|
||||
EXPECT_CALL(*states->packet_loss_smoother, GetAverage())
|
||||
.WillOnce(Return(rtc::Optional<float>(*uplink_packet_loss)));
|
||||
.WillOnce(Return(*uplink_packet_loss));
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateNetworkMetrics(FecControllerPlrBasedTestStates* states,
|
||||
int uplink_bandwidth_bps,
|
||||
float uplink_packet_loss) {
|
||||
UpdateNetworkMetrics(states, rtc::Optional<int>(uplink_bandwidth_bps),
|
||||
rtc::Optional<float>(uplink_packet_loss));
|
||||
}
|
||||
|
||||
// Checks that the FEC decision and |uplink_packet_loss_fraction| given by
|
||||
// |states->controller->MakeDecision| matches |expected_enable_fec| and
|
||||
// |expected_uplink_packet_loss_fraction|, respectively.
|
||||
@ -114,8 +107,8 @@ void CheckDecision(FecControllerPlrBasedTestStates* states,
|
||||
float expected_uplink_packet_loss_fraction) {
|
||||
AudioEncoderRuntimeConfig config;
|
||||
states->controller->MakeDecision(&config);
|
||||
EXPECT_EQ(rtc::Optional<bool>(expected_enable_fec), config.enable_fec);
|
||||
EXPECT_EQ(rtc::Optional<float>(expected_uplink_packet_loss_fraction),
|
||||
EXPECT_EQ(expected_enable_fec, config.enable_fec);
|
||||
EXPECT_EQ(expected_uplink_packet_loss_fraction,
|
||||
config.uplink_packet_loss_fraction);
|
||||
}
|
||||
|
||||
@ -138,8 +131,7 @@ TEST(FecControllerPlrBasedTest, OutputInitValueWhenUplinkBandwidthUnknown) {
|
||||
kEnablingPacketLossAtLowBw - kEpsilon, kEnablingPacketLossAtLowBw,
|
||||
kEnablingPacketLossAtLowBw + kEpsilon}) {
|
||||
auto states = CreateFecControllerPlrBased(initial_fec_enabled);
|
||||
UpdateNetworkMetrics(&states, rtc::Optional<int>(),
|
||||
rtc::Optional<float>(packet_loss));
|
||||
UpdateNetworkMetrics(&states, rtc::nullopt, packet_loss);
|
||||
CheckDecision(&states, initial_fec_enabled, packet_loss);
|
||||
}
|
||||
}
|
||||
@ -154,8 +146,7 @@ TEST(FecControllerPlrBasedTest,
|
||||
kDisablingBandwidthLow + 1, kEnablingBandwidthLow - 1,
|
||||
kEnablingBandwidthLow, kEnablingBandwidthLow + 1}) {
|
||||
auto states = CreateFecControllerPlrBased(initial_fec_enabled);
|
||||
UpdateNetworkMetrics(&states, rtc::Optional<int>(bandwidth),
|
||||
rtc::Optional<float>());
|
||||
UpdateNetworkMetrics(&states, bandwidth, rtc::nullopt);
|
||||
CheckDecision(&states, initial_fec_enabled, 0.0);
|
||||
}
|
||||
}
|
||||
@ -178,12 +169,10 @@ TEST(FecControllerPlrBasedTest, UpdateMultipleNetworkMetricsAtOnce) {
|
||||
// audio_network_adaptor_impl.cc.
|
||||
auto states = CreateFecControllerPlrBased(false);
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.uplink_bandwidth_bps =
|
||||
rtc::Optional<int>(kEnablingBandwidthHigh);
|
||||
network_metrics.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(kEnablingPacketLossAtHighBw);
|
||||
network_metrics.uplink_bandwidth_bps = kEnablingBandwidthHigh;
|
||||
network_metrics.uplink_packet_loss_fraction = kEnablingPacketLossAtHighBw;
|
||||
EXPECT_CALL(*states.packet_loss_smoother, GetAverage())
|
||||
.WillOnce(Return(rtc::Optional<float>(kEnablingPacketLossAtHighBw)));
|
||||
.WillOnce(Return(kEnablingPacketLossAtHighBw));
|
||||
states.controller->UpdateNetworkMetrics(network_metrics);
|
||||
CheckDecision(&states, true, kEnablingPacketLossAtHighBw);
|
||||
}
|
||||
|
||||
@ -48,9 +48,9 @@ void FecControllerRplrBased::MakeDecision(AudioEncoderRuntimeConfig* config) {
|
||||
|
||||
fec_enabled_ = fec_enabled_ ? !FecDisablingDecision() : FecEnablingDecision();
|
||||
|
||||
config->enable_fec = rtc::Optional<bool>(fec_enabled_);
|
||||
config->uplink_packet_loss_fraction = rtc::Optional<float>(
|
||||
uplink_recoverable_packet_loss_ ? *uplink_recoverable_packet_loss_ : 0.0);
|
||||
config->enable_fec = fec_enabled_;
|
||||
config->uplink_packet_loss_fraction =
|
||||
uplink_recoverable_packet_loss_ ? *uplink_recoverable_packet_loss_ : 0.0;
|
||||
}
|
||||
|
||||
bool FecControllerRplrBased::FecEnablingDecision() const {
|
||||
|
||||
@ -49,11 +49,9 @@ rtc::Optional<float> GetRandomProbabilityOrUnknown() {
|
||||
std::mt19937 generator(rd());
|
||||
std::uniform_real_distribution<> distribution(0, 1);
|
||||
|
||||
if (distribution(generator) < 0.2) {
|
||||
return rtc::Optional<float>();
|
||||
} else {
|
||||
return rtc::Optional<float>(distribution(generator));
|
||||
}
|
||||
return (distribution(generator) < 0.2)
|
||||
? rtc::nullopt
|
||||
: rtc::Optional<float>(distribution(generator));
|
||||
}
|
||||
|
||||
std::unique_ptr<FecControllerRplrBased> CreateFecControllerRplrBased(
|
||||
@ -108,13 +106,6 @@ void UpdateNetworkMetrics(
|
||||
uplink_recoveralbe_packet_loss);
|
||||
}
|
||||
|
||||
void UpdateNetworkMetrics(FecControllerRplrBased* controller,
|
||||
int uplink_bandwidth_bps,
|
||||
float uplink_recoveralbe_packet_loss) {
|
||||
UpdateNetworkMetrics(controller, rtc::Optional<int>(uplink_bandwidth_bps),
|
||||
rtc::Optional<float>(uplink_recoveralbe_packet_loss));
|
||||
}
|
||||
|
||||
// Checks that the FEC decision and |uplink_packet_loss_fraction| given by
|
||||
// |states->controller->MakeDecision| matches |expected_enable_fec| and
|
||||
// |expected_uplink_packet_loss_fraction|, respectively.
|
||||
@ -157,8 +148,8 @@ TEST(FecControllerRplrBasedTest, OutputInitValueWhenUplinkBandwidthUnknown) {
|
||||
kEnablingRecoverablePacketLossAtHighBw,
|
||||
kEnablingRecoverablePacketLossAtHighBw + kEpsilon}) {
|
||||
auto controller = CreateFecControllerRplrBased(initial_fec_enabled);
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(recoverable_packet_loss));
|
||||
UpdateNetworkMetrics(controller.get(), rtc::nullopt,
|
||||
recoverable_packet_loss);
|
||||
CheckDecision(controller.get(), initial_fec_enabled,
|
||||
recoverable_packet_loss);
|
||||
}
|
||||
@ -174,8 +165,7 @@ TEST(FecControllerRplrBasedTest,
|
||||
kDisablingBandwidthLow + 1, kEnablingBandwidthLow - 1,
|
||||
kEnablingBandwidthLow, kEnablingBandwidthLow + 1}) {
|
||||
auto controller = CreateFecControllerRplrBased(initial_fec_enabled);
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(bandwidth),
|
||||
rtc::Optional<float>());
|
||||
UpdateNetworkMetrics(controller.get(), bandwidth, rtc::nullopt);
|
||||
CheckDecision(controller.get(), initial_fec_enabled, 0.0);
|
||||
}
|
||||
}
|
||||
@ -198,12 +188,10 @@ TEST(FecControllerRplrBasedTest, UpdateMultipleNetworkMetricsAtOnce) {
|
||||
// audio_network_adaptor_impl.cc.
|
||||
auto controller = CreateFecControllerRplrBased(false);
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.uplink_bandwidth_bps =
|
||||
rtc::Optional<int>(kEnablingBandwidthHigh);
|
||||
network_metrics.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(GetRandomProbabilityOrUnknown());
|
||||
network_metrics.uplink_bandwidth_bps = kEnablingBandwidthHigh;
|
||||
network_metrics.uplink_packet_loss_fraction = GetRandomProbabilityOrUnknown();
|
||||
network_metrics.uplink_recoverable_packet_loss_fraction =
|
||||
rtc::Optional<float>(kEnablingRecoverablePacketLossAtHighBw);
|
||||
kEnablingRecoverablePacketLossAtHighBw;
|
||||
controller->UpdateNetworkMetrics(network_metrics);
|
||||
CheckDecision(controller.get(), true, kEnablingRecoverablePacketLossAtHighBw);
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ void FrameLengthController::MakeDecision(AudioEncoderRuntimeConfig* config) {
|
||||
prev_decision_increase_ = false;
|
||||
}
|
||||
config->last_fl_change_increase = prev_decision_increase_;
|
||||
config->frame_length_ms = rtc::Optional<int>(*frame_length_ms_);
|
||||
config->frame_length_ms = *frame_length_ms_;
|
||||
}
|
||||
|
||||
FrameLengthController::Config::FrameLengthChange::FrameLengthChange(
|
||||
|
||||
@ -105,8 +105,7 @@ void CheckDecision(FrameLengthController* controller,
|
||||
int expected_frame_length_ms) {
|
||||
AudioEncoderRuntimeConfig config;
|
||||
controller->MakeDecision(&config);
|
||||
EXPECT_EQ(rtc::Optional<int>(expected_frame_length_ms),
|
||||
config.frame_length_ms);
|
||||
EXPECT_EQ(expected_frame_length_ms, config.frame_length_ms);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -114,18 +113,17 @@ void CheckDecision(FrameLengthController* controller,
|
||||
TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkBandwidth) {
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
|
||||
UpdateNetworkMetrics(
|
||||
controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), kFl60msTo20msBandwidthBps,
|
||||
rtc::nullopt, kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkPacketLossFraction) {
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), rtc::nullopt,
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
@ -145,10 +143,8 @@ TEST(FrameLengthControllerTest, Maintain60MsOnMultipleConditions) {
|
||||
// 3. FEC is not decided ON.
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kMediumPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), kMediumBandwidthBps,
|
||||
kMediumPacketLossFraction, kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
|
||||
@ -160,10 +156,9 @@ TEST(FrameLengthControllerTest, IncreaseTo60MsOnMultipleConditions) {
|
||||
// 3. FEC is not decided or OFF.
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), kFl20msTo60msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
|
||||
@ -173,9 +168,9 @@ TEST(FrameLengthControllerTest, IncreaseTo60MsOnVeryLowUplinkBandwidth) {
|
||||
// We set packet loss fraction to kFlDecreasingPacketLossFraction, which
|
||||
// should have prevented frame length to increase, if the uplink bandwidth
|
||||
// was not this low.
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(20)),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), VeryLowBitrate(20),
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
|
||||
@ -185,9 +180,9 @@ TEST(FrameLengthControllerTest, Maintain60MsOnVeryLowUplinkBandwidth) {
|
||||
// We set packet loss fraction to FlDecreasingPacketLossFraction, which should
|
||||
// have caused the frame length to decrease, if the uplink bandwidth was not
|
||||
// this low.
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(20)),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), VeryLowBitrate(20),
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
|
||||
@ -202,10 +197,8 @@ TEST(FrameLengthControllerTest, UpdateMultipleNetworkMetricsAtOnce) {
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
|
||||
Controller::NetworkMetrics network_metrics;
|
||||
network_metrics.uplink_bandwidth_bps =
|
||||
rtc::Optional<int>(kFl20msTo60msBandwidthBps);
|
||||
network_metrics.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction);
|
||||
network_metrics.uplink_bandwidth_bps = kFl20msTo60msBandwidthBps;
|
||||
network_metrics.uplink_packet_loss_fraction = kFlIncreasingPacketLossFraction;
|
||||
controller->UpdateNetworkMetrics(network_metrics);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
@ -217,9 +210,9 @@ TEST(FrameLengthControllerTest,
|
||||
// Use a low uplink bandwidth and a low uplink packet loss fraction that would
|
||||
// cause frame length to increase if receiver frame length included 60ms.
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl20msTo60msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
@ -227,9 +220,9 @@ TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkBandwidth) {
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kMediumBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
@ -239,9 +232,9 @@ TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkPacketLossFraction) {
|
||||
// Use a low uplink bandwidth that would cause frame length to increase if
|
||||
// uplink packet loss fraction was low.
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kMediumPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl20msTo60msBandwidthBps,
|
||||
kMediumPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
@ -249,9 +242,9 @@ TEST(FrameLengthControllerTest, Maintain60MsWhenNo120msCriteriaIsSet) {
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60, 120}, 60);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
|
||||
@ -259,14 +252,16 @@ TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkBandwidth) {
|
||||
auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
|
||||
{20, 60, 120}, 120);
|
||||
// It takes two steps for frame length to go from 120ms to 20ms.
|
||||
UpdateNetworkMetrics(
|
||||
controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
kFl60msTo20msBandwidthBps,
|
||||
rtc::nullopt,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
|
||||
UpdateNetworkMetrics(
|
||||
controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
kFl60msTo20msBandwidthBps,
|
||||
rtc::nullopt,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
@ -274,14 +269,14 @@ TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkPacketLossFraction) {
|
||||
auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
|
||||
{20, 60, 120}, 120);
|
||||
// It takes two steps for frame length to go from 120ms to 20ms.
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), rtc::nullopt,
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), rtc::nullopt,
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
@ -291,9 +286,9 @@ TEST(FrameLengthControllerTest, Maintain120MsOnVeryLowUplinkBandwidth) {
|
||||
// We set packet loss fraction to FlDecreasingPacketLossFraction, which should
|
||||
// have caused the frame length to decrease, if the uplink bandwidth was not
|
||||
// this low.
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(60)),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), VeryLowBitrate(60),
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 120);
|
||||
}
|
||||
|
||||
@ -303,9 +298,9 @@ TEST(FrameLengthControllerTest, From60MsTo120MsOnVeryLowUplinkBandwidth) {
|
||||
// We set packet loss fraction to FlDecreasingPacketLossFraction, which should
|
||||
// have prevented frame length to increase, if the uplink bandwidth was not
|
||||
// this low.
|
||||
UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(60)),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
UpdateNetworkMetrics(controller.get(), VeryLowBitrate(60),
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 120);
|
||||
}
|
||||
|
||||
@ -317,14 +312,14 @@ TEST(FrameLengthControllerTest, From20MsTo120MsOnMultipleConditions) {
|
||||
{20, 60, 120}, 20);
|
||||
// It takes two steps for frame length to go from 20ms to 120ms.
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 120);
|
||||
}
|
||||
|
||||
@ -332,14 +327,14 @@ TEST(FrameLengthControllerTest, Stall60MsIf120MsNotInReceiverFrameLengthRange) {
|
||||
auto controller =
|
||||
CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), {20, 60}, 20);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
}
|
||||
|
||||
@ -347,39 +342,39 @@ TEST(FrameLengthControllerTest, CheckBehaviorOnChangingNetworkMetrics) {
|
||||
auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
|
||||
{20, 60, 120}, 20);
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kMediumBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl20msTo60msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kMediumPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kMediumPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl60msTo120msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 120);
|
||||
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kFl120msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kFl120msTo60msBandwidthBps,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 60);
|
||||
|
||||
UpdateNetworkMetrics(controller.get(),
|
||||
rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<size_t>(kOverheadBytesPerPacket));
|
||||
kMediumBandwidthBps,
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kOverheadBytesPerPacket);
|
||||
CheckDecision(controller.get(), 20);
|
||||
}
|
||||
|
||||
|
||||
@ -222,7 +222,7 @@ TEST_F(AudioEncoderCngTest, CheckTargetAudioBitratePropagation) {
|
||||
CreateCng(MakeCngConfig());
|
||||
EXPECT_CALL(*mock_encoder_,
|
||||
OnReceivedUplinkBandwidth(4711, rtc::Optional<int64_t>()));
|
||||
cng_->OnReceivedUplinkBandwidth(4711, rtc::Optional<int64_t>());
|
||||
cng_->OnReceivedUplinkBandwidth(4711, rtc::nullopt);
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCngTest, CheckPacketLossFractionPropagation) {
|
||||
|
||||
@ -35,9 +35,9 @@ LegacyEncodedAudioFrame::Decode(rtc::ArrayView<int16_t> decoded) const {
|
||||
decoded.size() * sizeof(int16_t), decoded.data(), &speech_type);
|
||||
|
||||
if (ret < 0)
|
||||
return rtc::Optional<DecodeResult>();
|
||||
return rtc::nullopt;
|
||||
|
||||
return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type});
|
||||
return DecodeResult{static_cast<size_t>(ret), speech_type};
|
||||
}
|
||||
|
||||
std::vector<AudioDecoder::ParseResult> LegacyEncodedAudioFrame::SplitBySamples(
|
||||
|
||||
@ -51,9 +51,9 @@ class OpusFrame : public AudioDecoder::EncodedAudioFrame {
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return rtc::Optional<DecodeResult>();
|
||||
return rtc::nullopt;
|
||||
|
||||
return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type});
|
||||
return DecodeResult{static_cast<size_t>(ret), speech_type};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -108,9 +108,10 @@ float OptimizePacketLossRate(float new_loss_rate, float old_loss_rate) {
|
||||
rtc::Optional<std::string> GetFormatParameter(const SdpAudioFormat& format,
|
||||
const std::string& param) {
|
||||
auto it = format.parameters.find(param);
|
||||
return (it == format.parameters.end())
|
||||
? rtc::Optional<std::string>()
|
||||
: rtc::Optional<std::string>(it->second);
|
||||
if (it == format.parameters.end())
|
||||
return rtc::nullopt;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -255,9 +256,9 @@ rtc::Optional<AudioCodecInfo> AudioEncoderOpusImpl::QueryAudioEncoder(
|
||||
info.allow_comfort_noise = false;
|
||||
info.supports_network_adaption = true;
|
||||
|
||||
return rtc::Optional<AudioCodecInfo>(info);
|
||||
return info;
|
||||
}
|
||||
return rtc::Optional<AudioCodecInfo>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
|
||||
AudioEncoderOpusConfig AudioEncoderOpusImpl::CreateConfig(
|
||||
@ -265,7 +266,7 @@ AudioEncoderOpusConfig AudioEncoderOpusImpl::CreateConfig(
|
||||
AudioEncoderOpusConfig config;
|
||||
config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48);
|
||||
config.num_channels = codec_inst.channels;
|
||||
config.bitrate_bps = rtc::Optional<int>(codec_inst.rate);
|
||||
config.bitrate_bps = codec_inst.rate;
|
||||
config.application = config.num_channels == 1
|
||||
? AudioEncoderOpusConfig::ApplicationMode::kVoip
|
||||
: AudioEncoderOpusConfig::ApplicationMode::kAudio;
|
||||
@ -277,7 +278,7 @@ rtc::Optional<AudioEncoderOpusConfig> AudioEncoderOpusImpl::SdpToConfig(
|
||||
const SdpAudioFormat& format) {
|
||||
if (STR_CASE_CMP(format.name.c_str(), "opus") != 0 ||
|
||||
format.clockrate_hz != 48000 || format.num_channels != 2) {
|
||||
return rtc::Optional<AudioEncoderOpusConfig>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
|
||||
AudioEncoderOpusConfig config;
|
||||
@ -287,9 +288,9 @@ rtc::Optional<AudioEncoderOpusConfig> AudioEncoderOpusImpl::SdpToConfig(
|
||||
config.fec_enabled = (GetFormatParameter(format, "useinbandfec") == "1");
|
||||
config.dtx_enabled = (GetFormatParameter(format, "usedtx") == "1");
|
||||
config.cbr_enabled = (GetFormatParameter(format, "cbr") == "1");
|
||||
config.bitrate_bps = rtc::Optional<int>(
|
||||
config.bitrate_bps =
|
||||
CalculateBitrate(config.max_playback_rate_hz, config.num_channels,
|
||||
GetFormatParameter(format, "maxaveragebitrate")));
|
||||
GetFormatParameter(format, "maxaveragebitrate"));
|
||||
config.application = config.num_channels == 1
|
||||
? AudioEncoderOpusConfig::ApplicationMode::kVoip
|
||||
: AudioEncoderOpusConfig::ApplicationMode::kAudio;
|
||||
@ -309,7 +310,7 @@ rtc::Optional<AudioEncoderOpusConfig> AudioEncoderOpusImpl::SdpToConfig(
|
||||
FindSupportedFrameLengths(min_frame_length_ms, max_frame_length_ms,
|
||||
&config.supported_frame_lengths_ms);
|
||||
RTC_DCHECK(config.IsOk());
|
||||
return rtc::Optional<AudioEncoderOpusConfig>(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
rtc::Optional<int> AudioEncoderOpusImpl::GetNewComplexity(
|
||||
@ -321,11 +322,11 @@ rtc::Optional<int> AudioEncoderOpusImpl::GetNewComplexity(
|
||||
bitrate_bps <= config.complexity_threshold_bps +
|
||||
config.complexity_threshold_window_bps) {
|
||||
// Within the hysteresis window; make no change.
|
||||
return rtc::Optional<int>();
|
||||
return rtc::nullopt;
|
||||
} else {
|
||||
return rtc::Optional<int>(bitrate_bps <= config.complexity_threshold_bps
|
||||
? config.low_rate_complexity
|
||||
: config.complexity);
|
||||
return bitrate_bps <= config.complexity_threshold_bps
|
||||
? config.low_rate_complexity
|
||||
: config.complexity;
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,8 +553,7 @@ void AudioEncoderOpusImpl::OnReceivedOverhead(
|
||||
audio_network_adaptor_->SetOverhead(overhead_bytes_per_packet);
|
||||
ApplyAudioNetworkAdaptor();
|
||||
} else {
|
||||
overhead_bytes_per_packet_ =
|
||||
rtc::Optional<size_t>(overhead_bytes_per_packet);
|
||||
overhead_bytes_per_packet_ = overhead_bytes_per_packet;
|
||||
}
|
||||
}
|
||||
|
||||
@ -707,9 +707,9 @@ void AudioEncoderOpusImpl::SetProjectedPacketLossRate(float fraction) {
|
||||
}
|
||||
|
||||
void AudioEncoderOpusImpl::SetTargetBitrate(int bits_per_second) {
|
||||
config_.bitrate_bps = rtc::Optional<int>(rtc::SafeClamp<int>(
|
||||
config_.bitrate_bps = rtc::SafeClamp<int>(
|
||||
bits_per_second, AudioEncoderOpusConfig::kMinBitrateBps,
|
||||
AudioEncoderOpusConfig::kMaxBitrateBps));
|
||||
AudioEncoderOpusConfig::kMaxBitrateBps);
|
||||
RTC_DCHECK(config_.IsOk());
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, GetBitrateBps(config_)));
|
||||
const auto new_complexity = GetNewComplexity(config_);
|
||||
@ -759,7 +759,7 @@ void AudioEncoderOpusImpl::MaybeUpdateUplinkBandwidth() {
|
||||
rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage();
|
||||
if (smoothed_bitrate)
|
||||
audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate);
|
||||
bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms);
|
||||
bitrate_smoother_last_update_time_ = now_ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ AudioEncoderOpusConfig CreateConfig(const CodecInst& codec_inst) {
|
||||
AudioEncoderOpusConfig config;
|
||||
config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48);
|
||||
config.num_channels = codec_inst.channels;
|
||||
config.bitrate_bps = rtc::Optional<int>(codec_inst.rate);
|
||||
config.bitrate_bps = codec_inst.rate;
|
||||
config.application = config.num_channels == 1
|
||||
? AudioEncoderOpusConfig::ApplicationMode::kVoip
|
||||
: AudioEncoderOpusConfig::ApplicationMode::kAudio;
|
||||
@ -102,13 +102,12 @@ AudioEncoderRuntimeConfig CreateEncoderRuntimeConfig() {
|
||||
constexpr size_t kNumChannels = 1;
|
||||
constexpr float kPacketLossFraction = 0.1f;
|
||||
AudioEncoderRuntimeConfig config;
|
||||
config.bitrate_bps = rtc::Optional<int>(kBitrate);
|
||||
config.frame_length_ms = rtc::Optional<int>(kFrameLength);
|
||||
config.enable_fec = rtc::Optional<bool>(kEnableFec);
|
||||
config.enable_dtx = rtc::Optional<bool>(kEnableDtx);
|
||||
config.num_channels = rtc::Optional<size_t>(kNumChannels);
|
||||
config.uplink_packet_loss_fraction =
|
||||
rtc::Optional<float>(kPacketLossFraction);
|
||||
config.bitrate_bps = kBitrate;
|
||||
config.frame_length_ms = kFrameLength;
|
||||
config.enable_fec = kEnableFec;
|
||||
config.enable_dtx = kEnableDtx;
|
||||
config.num_channels = kNumChannels;
|
||||
config.uplink_packet_loss_fraction = kPacketLossFraction;
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -201,24 +200,20 @@ TEST(AudioEncoderOpusTest,
|
||||
const int kMinBitrateBps = 6000;
|
||||
const int kMaxBitrateBps = 510000;
|
||||
// Set a too low bitrate.
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMinBitrateBps - 1,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMinBitrateBps - 1, rtc::nullopt);
|
||||
EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate());
|
||||
// Set a too high bitrate.
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMaxBitrateBps + 1,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMaxBitrateBps + 1, rtc::nullopt);
|
||||
EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate());
|
||||
// Set the minimum rate.
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMinBitrateBps,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMinBitrateBps, rtc::nullopt);
|
||||
EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate());
|
||||
// Set the maximum rate.
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMaxBitrateBps,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(kMaxBitrateBps, rtc::nullopt);
|
||||
EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate());
|
||||
// Set rates from kMaxBitrateBps up to 32000 bps.
|
||||
for (int rate = kMinBitrateBps; rate <= 32000; rate += 1000) {
|
||||
states.encoder->OnReceivedUplinkBandwidth(rate, rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(rate, rtc::nullopt);
|
||||
EXPECT_EQ(rate, states.encoder->GetTargetBitrate());
|
||||
}
|
||||
}
|
||||
@ -329,8 +324,8 @@ TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnReceivedUplinkBandwidth) {
|
||||
EXPECT_CALL(*states.mock_bitrate_smoother,
|
||||
SetTimeConstantMs(kProbingIntervalMs * 4));
|
||||
EXPECT_CALL(*states.mock_bitrate_smoother, AddSample(kTargetAudioBitrate));
|
||||
states.encoder->OnReceivedUplinkBandwidth(
|
||||
kTargetAudioBitrate, rtc::Optional<int64_t>(kProbingIntervalMs));
|
||||
states.encoder->OnReceivedUplinkBandwidth(kTargetAudioBitrate,
|
||||
kProbingIntervalMs);
|
||||
|
||||
CheckEncoderRuntimeConfig(states.encoder.get(), config);
|
||||
}
|
||||
@ -401,7 +396,7 @@ TEST(AudioEncoderOpusTest, DoNotInvokeSetTargetBitrateIfOverheadUnknown) {
|
||||
auto states = CreateCodec(2);
|
||||
|
||||
states.encoder->OnReceivedUplinkBandwidth(kDefaultOpusSettings.rate * 2,
|
||||
rtc::Optional<int64_t>());
|
||||
rtc::nullopt);
|
||||
|
||||
// Since |OnReceivedOverhead| has not been called, the codec bitrate should
|
||||
// not change.
|
||||
@ -418,8 +413,7 @@ TEST(AudioEncoderOpusTest, OverheadRemovedFromTargetAudioBitrate) {
|
||||
states.encoder->OnReceivedOverhead(kOverheadBytesPerPacket);
|
||||
|
||||
constexpr int kTargetBitrateBps = 40000;
|
||||
states.encoder->OnReceivedUplinkBandwidth(kTargetBitrateBps,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(kTargetBitrateBps, rtc::nullopt);
|
||||
|
||||
int packet_rate = rtc::CheckedDivExact(48000, kDefaultOpusSettings.pacsize);
|
||||
EXPECT_EQ(kTargetBitrateBps -
|
||||
@ -445,16 +439,14 @@ TEST(AudioEncoderOpusTest, BitrateBounded) {
|
||||
// subtracted. The eventual codec rate should be bounded by |kMinBitrateBps|.
|
||||
int target_bitrate =
|
||||
kOverheadBytesPerPacket * 8 * packet_rate + kMinBitrateBps - 1;
|
||||
states.encoder->OnReceivedUplinkBandwidth(target_bitrate,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(target_bitrate, rtc::nullopt);
|
||||
EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate());
|
||||
|
||||
// Set a target rate that is greater than |kMaxBitrateBps| when overhead is
|
||||
// subtracted. The eventual codec rate should be bounded by |kMaxBitrateBps|.
|
||||
target_bitrate =
|
||||
kOverheadBytesPerPacket * 8 * packet_rate + kMaxBitrateBps + 1;
|
||||
states.encoder->OnReceivedUplinkBandwidth(target_bitrate,
|
||||
rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(target_bitrate, rtc::nullopt);
|
||||
EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate());
|
||||
}
|
||||
|
||||
@ -465,24 +457,20 @@ TEST(AudioEncoderOpusTest, ConfigComplexityAdaptation) {
|
||||
config.complexity = 6;
|
||||
|
||||
// Bitrate within hysteresis window. Expect empty output.
|
||||
config.bitrate_bps = rtc::Optional<int>(12500);
|
||||
EXPECT_EQ(rtc::Optional<int>(),
|
||||
AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
config.bitrate_bps = 12500;
|
||||
EXPECT_EQ(rtc::nullopt, AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
|
||||
// Bitrate below hysteresis window. Expect higher complexity.
|
||||
config.bitrate_bps = rtc::Optional<int>(10999);
|
||||
EXPECT_EQ(rtc::Optional<int>(8),
|
||||
AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
config.bitrate_bps = 10999;
|
||||
EXPECT_EQ(8, AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
|
||||
// Bitrate within hysteresis window. Expect empty output.
|
||||
config.bitrate_bps = rtc::Optional<int>(12500);
|
||||
EXPECT_EQ(rtc::Optional<int>(),
|
||||
AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
config.bitrate_bps = 12500;
|
||||
EXPECT_EQ(rtc::nullopt, AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
|
||||
// Bitrate above hysteresis window. Expect lower complexity.
|
||||
config.bitrate_bps = rtc::Optional<int>(14001);
|
||||
EXPECT_EQ(rtc::Optional<int>(6),
|
||||
AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
config.bitrate_bps = 14001;
|
||||
EXPECT_EQ(6, AudioEncoderOpusImpl::GetNewComplexity(config));
|
||||
}
|
||||
|
||||
TEST(AudioEncoderOpusTest, EmptyConfigDoesNotAffectEncoderSettings) {
|
||||
@ -512,7 +500,7 @@ TEST(AudioEncoderOpusTest, UpdateUplinkBandwidthInAudioNetworkAdaptor) {
|
||||
audio.fill(0);
|
||||
rtc::Buffer encoded;
|
||||
EXPECT_CALL(*states.mock_bitrate_smoother, GetAverage())
|
||||
.WillOnce(Return(rtc::Optional<float>(50000)));
|
||||
.WillOnce(Return(50000));
|
||||
EXPECT_CALL(**states.mock_audio_network_adaptor, SetUplinkBandwidth(50000));
|
||||
states.encoder->Encode(
|
||||
0, rtc::ArrayView<const int16_t>(audio.data(), audio.size()), &encoded);
|
||||
@ -527,7 +515,7 @@ TEST(AudioEncoderOpusTest, UpdateUplinkBandwidthInAudioNetworkAdaptor) {
|
||||
|
||||
// Update when it is time to update.
|
||||
EXPECT_CALL(*states.mock_bitrate_smoother, GetAverage())
|
||||
.WillOnce(Return(rtc::Optional<float>(40000)));
|
||||
.WillOnce(Return(40000));
|
||||
EXPECT_CALL(**states.mock_audio_network_adaptor, SetUplinkBandwidth(40000));
|
||||
states.fake_clock->AdvanceTime(rtc::TimeDelta::FromMilliseconds(1));
|
||||
states.encoder->Encode(
|
||||
@ -544,7 +532,7 @@ TEST(AudioEncoderOpusTest, EncodeAtMinBitrate) {
|
||||
rtc::Buffer encoded;
|
||||
uint32_t rtp_timestamp = 12345; // Just a number not important to this test.
|
||||
|
||||
states.encoder->OnReceivedUplinkBandwidth(0, rtc::Optional<int64_t>());
|
||||
states.encoder->OnReceivedUplinkBandwidth(0, rtc::nullopt);
|
||||
for (int packet_index = 0; packet_index < kNumPacketsToEncode;
|
||||
packet_index++) {
|
||||
// Make sure we are not encoding before we have enough data for
|
||||
|
||||
@ -64,11 +64,11 @@ TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOn) {
|
||||
AudioEncoderOpusConfig config;
|
||||
// The limit -- including the hysteresis window -- at which the complexity
|
||||
// shuold be increased.
|
||||
config.bitrate_bps = rtc::Optional<int>(11000 - 1);
|
||||
config.bitrate_bps = 11000 - 1;
|
||||
config.low_rate_complexity = 9;
|
||||
int64_t runtime_10999bps = RunComplexityTest(config);
|
||||
|
||||
config.bitrate_bps = rtc::Optional<int>(15500);
|
||||
config.bitrate_bps = 15500;
|
||||
int64_t runtime_15500bps = RunComplexityTest(config);
|
||||
|
||||
test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_on",
|
||||
@ -85,10 +85,10 @@ TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOff) {
|
||||
// The limit -- including the hysteresis window -- at which the complexity
|
||||
// shuold be increased (but not in this test since complexity adaptation is
|
||||
// disabled).
|
||||
config.bitrate_bps = rtc::Optional<int>(11000 - 1);
|
||||
config.bitrate_bps = 11000 - 1;
|
||||
int64_t runtime_10999bps = RunComplexityTest(config);
|
||||
|
||||
config.bitrate_bps = rtc::Optional<int>(15500);
|
||||
config.bitrate_bps = 15500;
|
||||
int64_t runtime_15500bps = RunComplexityTest(config);
|
||||
|
||||
test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_off",
|
||||
|
||||
@ -101,7 +101,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckMaxFrameSizePropagation) {
|
||||
TEST_F(AudioEncoderCopyRedTest, CheckTargetAudioBitratePropagation) {
|
||||
EXPECT_CALL(*mock_encoder_,
|
||||
OnReceivedUplinkBandwidth(4711, rtc::Optional<int64_t>()));
|
||||
red_->OnReceivedUplinkBandwidth(4711, rtc::Optional<int64_t>());
|
||||
red_->OnReceivedUplinkBandwidth(4711, rtc::nullopt);
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCopyRedTest, CheckPacketLossFractionPropagation) {
|
||||
|
||||
@ -462,7 +462,7 @@ TEST_F(AudioDecoderPcmUTest, EncodeDecode) {
|
||||
|
||||
namespace {
|
||||
int SetAndGetTargetBitrate(AudioEncoder* audio_encoder, int rate) {
|
||||
audio_encoder->OnReceivedUplinkBandwidth(rate, rtc::Optional<int64_t>());
|
||||
audio_encoder->OnReceivedUplinkBandwidth(rate, rtc::nullopt);
|
||||
return audio_encoder->GetTargetBitrate();
|
||||
}
|
||||
void TestSetAndGetTargetBitratesWithFixedCodec(AudioEncoder* audio_encoder,
|
||||
|
||||
@ -104,10 +104,9 @@ DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) {
|
||||
const int sample_rate_hz = format.clockrate_hz;
|
||||
RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
|
||||
sample_rate_hz == 32000 || sample_rate_hz == 48000);
|
||||
return rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder>(
|
||||
{sample_rate_hz});
|
||||
return DecoderDatabase::DecoderInfo::CngDecoder{sample_rate_hz};
|
||||
} else {
|
||||
return rtc::Optional<CngDecoder>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,71 +18,67 @@ namespace webrtc {
|
||||
rtc::Optional<SdpAudioFormat> NetEqDecoderToSdpAudioFormat(NetEqDecoder nd) {
|
||||
switch (nd) {
|
||||
case NetEqDecoder::kDecoderPCMu:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("pcmu", 8000, 1));
|
||||
return SdpAudioFormat("pcmu", 8000, 1);
|
||||
case NetEqDecoder::kDecoderPCMa:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("pcma", 8000, 1));
|
||||
return SdpAudioFormat("pcma", 8000, 1);
|
||||
case NetEqDecoder::kDecoderPCMu_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("pcmu", 8000, 2));
|
||||
return SdpAudioFormat("pcmu", 8000, 2);
|
||||
case NetEqDecoder::kDecoderPCMa_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("pcma", 8000, 2));
|
||||
return SdpAudioFormat("pcma", 8000, 2);
|
||||
case NetEqDecoder::kDecoderILBC:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("ilbc", 8000, 1));
|
||||
return SdpAudioFormat("ilbc", 8000, 1);
|
||||
case NetEqDecoder::kDecoderISAC:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("isac", 16000, 1));
|
||||
return SdpAudioFormat("isac", 16000, 1);
|
||||
case NetEqDecoder::kDecoderISACswb:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("isac", 32000, 1));
|
||||
return SdpAudioFormat("isac", 32000, 1);
|
||||
case NetEqDecoder::kDecoderPCM16B:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 8000, 1));
|
||||
return SdpAudioFormat("l16", 8000, 1);
|
||||
case NetEqDecoder::kDecoderPCM16Bwb:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 16000, 1));
|
||||
return SdpAudioFormat("l16", 16000, 1);
|
||||
case NetEqDecoder::kDecoderPCM16Bswb32kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 32000, 1));
|
||||
return SdpAudioFormat("l16", 32000, 1);
|
||||
case NetEqDecoder::kDecoderPCM16Bswb48kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 48000, 1));
|
||||
return SdpAudioFormat("l16", 48000, 1);
|
||||
case NetEqDecoder::kDecoderPCM16B_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 8000, 2));
|
||||
return SdpAudioFormat("l16", 8000, 2);
|
||||
case NetEqDecoder::kDecoderPCM16Bwb_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 16000, 2));
|
||||
return SdpAudioFormat("l16", 16000, 2);
|
||||
case NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 32000, 2));
|
||||
return SdpAudioFormat("l16", 32000, 2);
|
||||
case NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 48000, 2));
|
||||
return SdpAudioFormat("l16", 48000, 2);
|
||||
case NetEqDecoder::kDecoderPCM16B_5ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("l16", 8000, 5));
|
||||
return SdpAudioFormat("l16", 8000, 5);
|
||||
case NetEqDecoder::kDecoderG722:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("g722", 8000, 1));
|
||||
return SdpAudioFormat("g722", 8000, 1);
|
||||
case NetEqDecoder::kDecoderG722_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("g722", 8000, 2));
|
||||
return SdpAudioFormat("g722", 8000, 2);
|
||||
case NetEqDecoder::kDecoderOpus:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("opus", 48000, 2));
|
||||
return SdpAudioFormat("opus", 48000, 2);
|
||||
case NetEqDecoder::kDecoderOpus_2ch:
|
||||
return rtc::Optional<SdpAudioFormat>(
|
||||
SdpAudioFormat("opus", 48000, 2,
|
||||
std::map<std::string, std::string>{{"stereo", "1"}}));
|
||||
return SdpAudioFormat(
|
||||
"opus", 48000, 2,
|
||||
std::map<std::string, std::string>{{"stereo", "1"}});
|
||||
case NetEqDecoder::kDecoderRED:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("red", 8000, 1));
|
||||
return SdpAudioFormat("red", 8000, 1);
|
||||
case NetEqDecoder::kDecoderAVT:
|
||||
return rtc::Optional<SdpAudioFormat>(
|
||||
SdpAudioFormat("telephone-event", 8000, 1));
|
||||
return SdpAudioFormat("telephone-event", 8000, 1);
|
||||
case NetEqDecoder::kDecoderAVT16kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(
|
||||
SdpAudioFormat("telephone-event", 16000, 1));
|
||||
return SdpAudioFormat("telephone-event", 16000, 1);
|
||||
case NetEqDecoder::kDecoderAVT32kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(
|
||||
SdpAudioFormat("telephone-event", 32000, 1));
|
||||
return SdpAudioFormat("telephone-event", 32000, 1);
|
||||
case NetEqDecoder::kDecoderAVT48kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(
|
||||
SdpAudioFormat("telephone-event", 48000, 1));
|
||||
return SdpAudioFormat("telephone-event", 48000, 1);
|
||||
case NetEqDecoder::kDecoderCNGnb:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("cn", 8000, 1));
|
||||
return SdpAudioFormat("cn", 8000, 1);
|
||||
case NetEqDecoder::kDecoderCNGwb:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("cn", 16000, 1));
|
||||
return SdpAudioFormat("cn", 16000, 1);
|
||||
case NetEqDecoder::kDecoderCNGswb32kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("cn", 32000, 1));
|
||||
return SdpAudioFormat("cn", 32000, 1);
|
||||
case NetEqDecoder::kDecoderCNGswb48kHz:
|
||||
return rtc::Optional<SdpAudioFormat>(SdpAudioFormat("cn", 48000, 1));
|
||||
return SdpAudioFormat("cn", 48000, 1);
|
||||
default:
|
||||
return rtc::Optional<SdpAudioFormat>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -423,10 +423,9 @@ rtc::Optional<uint32_t> NetEqImpl::GetPlayoutTimestamp() const {
|
||||
// We don't have a valid RTP timestamp until we have decoded our first
|
||||
// RTP packet. Also, the RTP timestamp is not accurate while playing CNG,
|
||||
// which is indicated by returning an empty value.
|
||||
return rtc::Optional<uint32_t>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
return rtc::Optional<uint32_t>(
|
||||
timestamp_scaler_->ToExternal(playout_timestamp_));
|
||||
return timestamp_scaler_->ToExternal(playout_timestamp_);
|
||||
}
|
||||
|
||||
int NetEqImpl::last_output_sample_rate_hz() const {
|
||||
@ -439,7 +438,7 @@ rtc::Optional<CodecInst> NetEqImpl::GetDecoder(int payload_type) const {
|
||||
const DecoderDatabase::DecoderInfo* di =
|
||||
decoder_database_->GetDecoderInfo(payload_type);
|
||||
if (!di) {
|
||||
return rtc::Optional<CodecInst>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
|
||||
// Create a CodecInst with some fields set. The remaining fields are zeroed,
|
||||
@ -452,7 +451,7 @@ rtc::Optional<CodecInst> NetEqImpl::GetDecoder(int payload_type) const {
|
||||
ci.plfreq = di->IsRed() ? 8000 : di->SampleRateHz();
|
||||
AudioDecoder* const decoder = di->GetDecoder();
|
||||
ci.channels = decoder ? decoder->Channels() : 1;
|
||||
return rtc::Optional<CodecInst>(ci);
|
||||
return ci;
|
||||
}
|
||||
|
||||
rtc::Optional<SdpAudioFormat> NetEqImpl::GetDecoderFormat(
|
||||
@ -461,9 +460,9 @@ rtc::Optional<SdpAudioFormat> NetEqImpl::GetDecoderFormat(
|
||||
const DecoderDatabase::DecoderInfo* const di =
|
||||
decoder_database_->GetDecoderInfo(payload_type);
|
||||
if (!di) {
|
||||
return rtc::Optional<SdpAudioFormat>(); // Payload type not registered.
|
||||
return rtc::nullopt; // Payload type not registered.
|
||||
}
|
||||
return rtc::Optional<SdpAudioFormat>(di->GetFormat());
|
||||
return di->GetFormat();
|
||||
}
|
||||
|
||||
int NetEqImpl::SetTargetNumberOfChannels() {
|
||||
@ -2004,7 +2003,7 @@ int NetEqImpl::ExtractPackets(size_t required_samples,
|
||||
stats_.JitterBufferDelay(extracted_samples, waiting_time_ms);
|
||||
|
||||
packet_list->push_back(std::move(*packet)); // Store packet in list.
|
||||
packet = rtc::Optional<Packet>(); // Ensure it's never used after the move.
|
||||
packet = rtc::nullopt; // Ensure it's never used after the move.
|
||||
|
||||
// Check what packet is available next.
|
||||
next_packet = packet_buffer_->PeekNextPacket();
|
||||
|
||||
@ -348,9 +348,8 @@ TEST_F(NetEqImplTest, InsertPacket) {
|
||||
.Times(1);
|
||||
EXPECT_CALL(*mock_packet_buffer_, InsertPacketList(_, _, _, _, _))
|
||||
.Times(2)
|
||||
.WillRepeatedly(
|
||||
DoAll(SetArgPointee<2>(rtc::Optional<uint8_t>(kPayloadType)),
|
||||
WithArg<0>(Invoke(DeletePacketsAndReturnOk))));
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(kPayloadType),
|
||||
WithArg<0>(Invoke(DeletePacketsAndReturnOk))));
|
||||
// SetArgPointee<2>(kPayloadType) means that the third argument (zero-based
|
||||
// index) is a pointer, and the variable pointed to is set to kPayloadType.
|
||||
// Also invoke the function DeletePacketsAndReturnOk to properly delete all
|
||||
|
||||
@ -53,12 +53,11 @@ class MockAudioDecoder final : public AudioDecoder {
|
||||
if (decoded.size() >= output_size) {
|
||||
memset(decoded.data(), 0,
|
||||
sizeof(int16_t) * kPacketDuration * num_channels_);
|
||||
return rtc::Optional<DecodeResult>(
|
||||
{kPacketDuration * num_channels_, kSpeech});
|
||||
return DecodeResult{kPacketDuration * num_channels_, kSpeech};
|
||||
} else {
|
||||
ADD_FAILURE() << "Expected decoded.size() to be >= output_size ("
|
||||
<< decoded.size() << " vs. " << output_size << ")";
|
||||
return rtc::Optional<DecodeResult>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -139,12 +139,11 @@ int PacketBuffer::InsertPacketList(
|
||||
if (*current_cng_rtp_payload_type &&
|
||||
**current_cng_rtp_payload_type != packet.payload_type) {
|
||||
// New CNG payload type implies new codec type.
|
||||
*current_rtp_payload_type = rtc::Optional<uint8_t>();
|
||||
*current_rtp_payload_type = rtc::nullopt;
|
||||
Flush();
|
||||
flushed = true;
|
||||
}
|
||||
*current_cng_rtp_payload_type =
|
||||
rtc::Optional<uint8_t>(packet.payload_type);
|
||||
*current_cng_rtp_payload_type = packet.payload_type;
|
||||
} else if (!decoder_database.IsDtmf(packet.payload_type)) {
|
||||
// This must be speech.
|
||||
if ((*current_rtp_payload_type &&
|
||||
@ -153,11 +152,11 @@ int PacketBuffer::InsertPacketList(
|
||||
!EqualSampleRates(packet.payload_type,
|
||||
**current_cng_rtp_payload_type,
|
||||
decoder_database))) {
|
||||
*current_cng_rtp_payload_type = rtc::Optional<uint8_t>();
|
||||
*current_cng_rtp_payload_type = rtc::nullopt;
|
||||
Flush();
|
||||
flushed = true;
|
||||
}
|
||||
*current_rtp_payload_type = rtc::Optional<uint8_t>(packet.payload_type);
|
||||
*current_rtp_payload_type = packet.payload_type;
|
||||
}
|
||||
int return_val = InsertPacket(std::move(packet), stats);
|
||||
if (return_val == kFlushed) {
|
||||
@ -210,7 +209,7 @@ const Packet* PacketBuffer::PeekNextPacket() const {
|
||||
rtc::Optional<Packet> PacketBuffer::GetNextPacket() {
|
||||
if (Empty()) {
|
||||
// Buffer is empty.
|
||||
return rtc::Optional<Packet>();
|
||||
return rtc::nullopt;
|
||||
}
|
||||
|
||||
rtc::Optional<Packet> packet(std::move(buffer_.front()));
|
||||
|
||||
@ -188,9 +188,8 @@ TEST(PacketBuffer, InsertPacketList) {
|
||||
¤t_cng_pt, &mock_stats));
|
||||
EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
|
||||
EXPECT_EQ(10u, buffer.NumPacketsInBuffer());
|
||||
EXPECT_EQ(rtc::Optional<uint8_t>(0),
|
||||
current_pt); // Current payload type changed to 0.
|
||||
EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
|
||||
EXPECT_EQ(0, current_pt); // Current payload type changed to 0.
|
||||
EXPECT_EQ(rtc::nullopt, current_cng_pt); // CNG payload type not changed.
|
||||
|
||||
buffer.Flush(); // Clean up.
|
||||
|
||||
@ -236,9 +235,8 @@ TEST(PacketBuffer, InsertPacketListChangePayloadType) {
|
||||
¤t_cng_pt, &mock_stats));
|
||||
EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
|
||||
EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet.
|
||||
EXPECT_EQ(rtc::Optional<uint8_t>(1),
|
||||
current_pt); // Current payload type changed to 1.
|
||||
EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
|
||||
EXPECT_EQ(1, current_pt); // Current payload type changed to 1.
|
||||
EXPECT_EQ(rtc::nullopt, current_cng_pt); // CNG payload type not changed.
|
||||
|
||||
buffer.Flush(); // Clean up.
|
||||
|
||||
@ -470,9 +468,8 @@ TEST(PacketBuffer, CngFirstThenSpeechWithNewSampleRate) {
|
||||
EXPECT_EQ(1u, buffer.NumPacketsInBuffer());
|
||||
ASSERT_TRUE(buffer.PeekNextPacket());
|
||||
EXPECT_EQ(kCngPt, buffer.PeekNextPacket()->payload_type);
|
||||
EXPECT_FALSE(current_pt); // Current payload type not set.
|
||||
EXPECT_EQ(rtc::Optional<uint8_t>(kCngPt),
|
||||
current_cng_pt); // CNG payload type set.
|
||||
EXPECT_EQ(current_pt, rtc::nullopt); // Current payload type not set.
|
||||
EXPECT_EQ(kCngPt, current_cng_pt); // CNG payload type set.
|
||||
|
||||
// Insert second packet, which is wide-band speech.
|
||||
{
|
||||
@ -490,9 +487,8 @@ TEST(PacketBuffer, CngFirstThenSpeechWithNewSampleRate) {
|
||||
ASSERT_TRUE(buffer.PeekNextPacket());
|
||||
EXPECT_EQ(kSpeechPt, buffer.PeekNextPacket()->payload_type);
|
||||
|
||||
EXPECT_EQ(rtc::Optional<uint8_t>(kSpeechPt),
|
||||
current_pt); // Current payload type set.
|
||||
EXPECT_FALSE(current_cng_pt); // CNG payload type reset.
|
||||
EXPECT_EQ(kSpeechPt, current_pt); // Current payload type set.
|
||||
EXPECT_EQ(rtc::nullopt, current_cng_pt); // CNG payload type reset.
|
||||
|
||||
buffer.Flush(); // Clean up.
|
||||
EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
|
||||
|
||||
@ -29,11 +29,11 @@ EncodeNetEqInput::EncodeNetEqInput(std::unique_ptr<Generator> generator,
|
||||
|
||||
rtc::Optional<int64_t> EncodeNetEqInput::NextPacketTime() const {
|
||||
RTC_DCHECK(packet_data_);
|
||||
return rtc::Optional<int64_t>(static_cast<int64_t>(packet_data_->time_ms));
|
||||
return static_cast<int64_t>(packet_data_->time_ms);
|
||||
}
|
||||
|
||||
rtc::Optional<int64_t> EncodeNetEqInput::NextOutputEventTime() const {
|
||||
return rtc::Optional<int64_t>(next_output_event_ms_);
|
||||
return next_output_event_ms_;
|
||||
}
|
||||
|
||||
std::unique_ptr<NetEqInput::PacketData> EncodeNetEqInput::PopPacket() {
|
||||
@ -52,7 +52,7 @@ void EncodeNetEqInput::AdvanceOutputEvent() {
|
||||
|
||||
rtc::Optional<RTPHeader> EncodeNetEqInput::NextHeader() const {
|
||||
RTC_DCHECK(packet_data_);
|
||||
return rtc::Optional<RTPHeader>(packet_data_->header);
|
||||
return packet_data_->header;
|
||||
}
|
||||
|
||||
void EncodeNetEqInput::CreatePacket() {
|
||||
|
||||
@ -59,8 +59,7 @@ int FakeDecodeFromFile::DecodeInternal(const uint8_t* encoded,
|
||||
RTC_CHECK(input_->Seek(jump));
|
||||
}
|
||||
|
||||
next_timestamp_from_input_ =
|
||||
rtc::Optional<uint32_t>(timestamp_to_decode + samples_to_decode);
|
||||
next_timestamp_from_input_ = timestamp_to_decode + samples_to_decode;
|
||||
|
||||
uint32_t original_payload_size_bytes =
|
||||
ByteReader<uint32_t>::ReadLittleEndian(&encoded[8]);
|
||||
|
||||
@ -86,12 +86,11 @@ void NetEqDelayAnalyzer::AfterGetAudio(int64_t time_now_ms,
|
||||
auto& it_timing = it->second;
|
||||
RTC_CHECK(!it_timing.decode_get_audio_count)
|
||||
<< "Decode time already written";
|
||||
it_timing.decode_get_audio_count = rtc::Optional<int64_t>(get_audio_count_);
|
||||
it_timing.decode_get_audio_count = get_audio_count_;
|
||||
RTC_CHECK(!it_timing.sync_delay_ms) << "Decode time already written";
|
||||
it_timing.sync_delay_ms = rtc::Optional<int64_t>(last_sync_buffer_ms_);
|
||||
it_timing.target_delay_ms = rtc::Optional<int>(neteq->TargetDelayMs());
|
||||
it_timing.current_delay_ms =
|
||||
rtc::Optional<int>(neteq->FilteredCurrentDelayMs());
|
||||
it_timing.sync_delay_ms = last_sync_buffer_ms_;
|
||||
it_timing.target_delay_ms = neteq->TargetDelayMs();
|
||||
it_timing.current_delay_ms = neteq->FilteredCurrentDelayMs();
|
||||
}
|
||||
last_sample_rate_hz_ = audio_frame.sample_rate_hz_;
|
||||
++get_audio_count_;
|
||||
@ -159,16 +158,16 @@ void NetEqDelayAnalyzer::CreateGraphs(
|
||||
const float playout_ms = *timing.decode_get_audio_count * 10 +
|
||||
get_audio_time_ms_[0] + *timing.sync_delay_ms -
|
||||
offset_send_time_ms;
|
||||
playout_delay_ms->push_back(rtc::Optional<float>(playout_ms));
|
||||
playout_delay_ms->push_back(playout_ms);
|
||||
RTC_DCHECK(timing.target_delay_ms);
|
||||
RTC_DCHECK(timing.current_delay_ms);
|
||||
const float target =
|
||||
playout_ms - *timing.current_delay_ms + *timing.target_delay_ms;
|
||||
target_delay_ms->push_back(rtc::Optional<float>(target));
|
||||
target_delay_ms->push_back(target);
|
||||
} else {
|
||||
// This packet was never decoded. Mark target and playout delays as empty.
|
||||
playout_delay_ms->push_back(rtc::Optional<float>());
|
||||
target_delay_ms->push_back(rtc::Optional<float>());
|
||||
playout_delay_ms->push_back(rtc::nullopt);
|
||||
target_delay_ms->push_back(rtc::nullopt);
|
||||
}
|
||||
}
|
||||
RTC_DCHECK(data_it == data_.end());
|
||||
|
||||
@ -52,9 +52,9 @@ class NetEqInput {
|
||||
const auto b = NextOutputEventTime();
|
||||
// Return the minimum of non-empty |a| and |b|, or empty if both are empty.
|
||||
if (a) {
|
||||
return b ? rtc::Optional<int64_t>(std::min(*a, *b)) : a;
|
||||
return b ? std::min(*a, *b) : a;
|
||||
}
|
||||
return b ? b : rtc::Optional<int64_t>();
|
||||
return b ? b : rtc::nullopt;
|
||||
}
|
||||
|
||||
// Returns the next packet to be inserted into NetEq. The packet following the
|
||||
|
||||
@ -25,12 +25,12 @@ NetEqPacketSourceInput::NetEqPacketSourceInput() : next_output_event_ms_(0) {}
|
||||
rtc::Optional<int64_t> NetEqPacketSourceInput::NextPacketTime() const {
|
||||
return packet_
|
||||
? rtc::Optional<int64_t>(static_cast<int64_t>(packet_->time_ms()))
|
||||
: rtc::Optional<int64_t>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
rtc::Optional<RTPHeader> NetEqPacketSourceInput::NextHeader() const {
|
||||
return packet_ ? rtc::Optional<RTPHeader>(packet_->header())
|
||||
: rtc::Optional<RTPHeader>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
void NetEqPacketSourceInput::LoadNextPacket() {
|
||||
@ -78,7 +78,7 @@ void NetEqRtpDumpInput::AdvanceOutputEvent() {
|
||||
*next_output_event_ms_ += kOutputPeriodMs;
|
||||
}
|
||||
if (!NextPacketTime()) {
|
||||
next_output_event_ms_ = rtc::Optional<int64_t>();
|
||||
next_output_event_ms_ = rtc::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,14 +97,13 @@ NetEqEventLogInput::NetEqEventLogInput(const std::string& file_name,
|
||||
}
|
||||
|
||||
rtc::Optional<int64_t> NetEqEventLogInput::NextOutputEventTime() const {
|
||||
return rtc::Optional<int64_t>(next_output_event_ms_);
|
||||
return next_output_event_ms_;
|
||||
}
|
||||
|
||||
void NetEqEventLogInput::AdvanceOutputEvent() {
|
||||
next_output_event_ms_ =
|
||||
rtc::Optional<int64_t>(source_->NextAudioOutputEventMs());
|
||||
next_output_event_ms_ = source_->NextAudioOutputEventMs();
|
||||
if (*next_output_event_ms_ == std::numeric_limits<int64_t>::max()) {
|
||||
next_output_event_ms_ = rtc::Optional<int64_t>();
|
||||
next_output_event_ms_ = rtc::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ NetEqReplacementInput::NetEqReplacementInput(
|
||||
rtc::Optional<int64_t> NetEqReplacementInput::NextPacketTime() const {
|
||||
return packet_
|
||||
? rtc::Optional<int64_t>(static_cast<int64_t>(packet_->time_ms))
|
||||
: rtc::Optional<int64_t>();
|
||||
: rtc::nullopt;
|
||||
}
|
||||
|
||||
rtc::Optional<int64_t> NetEqReplacementInput::NextOutputEventTime() const {
|
||||
|
||||
@ -209,20 +209,20 @@ rtc::Optional<int> CodecSampleRate(uint8_t payload_type) {
|
||||
if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma ||
|
||||
payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b ||
|
||||
payload_type == FLAG_cn_nb || payload_type == FLAG_avt)
|
||||
return rtc::Optional<int>(8000);
|
||||
return 8000;
|
||||
if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb ||
|
||||
payload_type == FLAG_g722 || payload_type == FLAG_cn_wb ||
|
||||
payload_type == FLAG_avt_16)
|
||||
return rtc::Optional<int>(16000);
|
||||
return 16000;
|
||||
if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 ||
|
||||
payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32)
|
||||
return rtc::Optional<int>(32000);
|
||||
return 32000;
|
||||
if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 ||
|
||||
payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48)
|
||||
return rtc::Optional<int>(48000);
|
||||
return 48000;
|
||||
if (payload_type == FLAG_red)
|
||||
return rtc::Optional<int>(0);
|
||||
return rtc::Optional<int>();
|
||||
return 0;
|
||||
return rtc::nullopt;
|
||||
}
|
||||
|
||||
// Class to let through only the packets with a given SSRC. Should be used as an
|
||||
@ -294,7 +294,7 @@ class SsrcSwitchDetector : public NetEqPostInsertPacket {
|
||||
<< static_cast<int>(packet.header.payloadType) << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
last_ssrc_ = rtc::Optional<uint32_t>(packet.header.ssrc);
|
||||
last_ssrc_ = packet.header.ssrc;
|
||||
if (other_callback_) {
|
||||
other_callback_->AfterInsertPacket(packet, neteq);
|
||||
}
|
||||
|
||||
@ -816,7 +816,7 @@ void APITest::TestRegisteration(char sendSide) {
|
||||
if (!myCodec) {
|
||||
CodecInst ci;
|
||||
AudioCodingModule::Codec(_codecCntrA, &ci);
|
||||
myCodec = rtc::Optional<CodecInst>(ci);
|
||||
myCodec = ci;
|
||||
}
|
||||
|
||||
if (!_randomTest) {
|
||||
|
||||
@ -225,7 +225,7 @@ void PCMFile::ReadStereo(bool is_stereo) {
|
||||
}
|
||||
|
||||
void PCMFile::SetNum10MsBlocksToRead(int value) {
|
||||
num_10ms_blocks_to_read_ = rtc::Optional<int>(value);
|
||||
num_10ms_blocks_to_read_ = value;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user