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}
diff --git a/modules/audio_coding/acm2/acm_receiver.cc b/modules/audio_coding/acm2/acm_receiver.cc
index 360a583..8f8b273 100644
--- a/modules/audio_coding/acm2/acm_receiver.cc
+++ b/modules/audio_coding/acm2/acm_receiver.cc
@@ -103,7 +103,7 @@
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::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 @@
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;
}
diff --git a/modules/audio_coding/acm2/acm_receiver_unittest.cc b/modules/audio_coding/acm2/acm_receiver_unittest.cc
index c420c7e..e8f8b4a 100644
--- a/modules/audio_coding/acm2/acm_receiver_unittest.cc
+++ b/modules/audio_coding/acm2/acm_receiver_unittest.cc
@@ -483,8 +483,7 @@
// 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 @@
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));
}
diff --git a/modules/audio_coding/acm2/audio_coding_module.cc b/modules/audio_coding/acm2/audio_coding_module.cc
index 361278f..340cc92 100644
--- a/modules/audio_coding/acm2/audio_coding_module.cc
+++ b/modules/audio_coding/acm2/audio_coding_module.cc
@@ -606,21 +606,20 @@
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 @@
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);
}
}
diff --git a/modules/audio_coding/acm2/audio_coding_module_unittest.cc b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
index ca59b31..68dd671 100644
--- a/modules/audio_coding/acm2/audio_coding_module_unittest.cc
+++ b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
@@ -184,8 +184,7 @@
// 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 @@
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;
diff --git a/modules/audio_coding/acm2/codec_manager.cc b/modules/audio_coding/acm2/codec_manager.cc
index 50ef9ef..a101d3d 100644
--- a/modules/audio_coding/acm2/codec_manager.cc
+++ b/modules/audio_coding/acm2/codec_manager.cc
@@ -106,7 +106,7 @@
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;
}
diff --git a/modules/audio_coding/acm2/codec_manager.h b/modules/audio_coding/acm2/codec_manager.h
index a2a6810..7485426 100644
--- a/modules/audio_coding/acm2/codec_manager.h
+++ b/modules/audio_coding/acm2/codec_manager.h
@@ -43,7 +43,7 @@
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_;
diff --git a/modules/audio_coding/acm2/rent_a_codec.cc b/modules/audio_coding/acm2/rent_a_codec.cc
index 39efd96..78db38d 100644
--- a/modules/audio_coding/acm2/rent_a_codec.cc
+++ b/modules/audio_coding/acm2/rent_a_codec.cc
@@ -55,7 +55,7 @@
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<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 @@
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 @@
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 @@
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);
diff --git a/modules/audio_coding/acm2/rent_a_codec.h b/modules/audio_coding/acm2/rent_a_codec.h
index cecb914..f8fac4c 100644
--- a/modules/audio_coding/acm2/rent_a_codec.h
+++ b/modules/audio_coding/acm2/rent_a_codec.h
@@ -111,14 +111,14 @@
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,