Replace rtc::Optional with absl::optional in modules/audio_coding
This is a no-op change because rtc::Optional is an alias to absl::optional
This CL generated by running script with parameter 'modules/audio_coding'
find $@ -type f \( -name \*.h -o -name \*.cc \) \
-exec sed -i 's|rtc::Optional|absl::optional|g' {} \+ \
-exec sed -i 's|rtc::nullopt|absl::nullopt|g' {} \+ \
-exec sed -i 's|#include "api/optional.h"|#include "absl/types/optional.h"|' {} \+
find $@ -type f -name BUILD.gn \
-exec sed -r -i 's|"[\./api]*:optional"|"//third_party/abseil-cpp/absl/types:optional"|' {} \+;
git cl format
Bug: webrtc:9078
Change-Id: Ic980ee605148fdb160666d4aa03cc87175e48fe8
Reviewed-on: https://webrtc-review.googlesource.com/84130
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23659}
diff --git a/modules/audio_coding/acm2/acm_receiver.cc b/modules/audio_coding/acm2/acm_receiver.cc
index 84efc5c..b61099c 100644
--- a/modules/audio_coding/acm2/acm_receiver.cc
+++ b/modules/audio_coding/acm2/acm_receiver.cc
@@ -64,7 +64,7 @@
return neteq_->LeastRequiredDelayMs();
}
-rtc::Optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
+absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
rtc::CritScope lock(&crit_sect_);
return last_packet_sample_rate_hz_;
}
@@ -86,7 +86,7 @@
{
rtc::CritScope lock(&crit_sect_);
- const rtc::Optional<CodecInst> ci =
+ const absl::optional<CodecInst> ci =
RtpHeaderToDecoder(*header, incoming_payload[0]);
if (!ci) {
RTC_LOG_F(LS_ERROR) << "Payload-type "
@@ -202,15 +202,15 @@
const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder {
if (acm_codec_id == -1)
return NetEqDecoder::kDecoderArbitrary; // External decoder.
- const rtc::Optional<RentACodec::CodecId> cid =
+ const absl::optional<RentACodec::CodecId> cid =
RentACodec::CodecIdFromIndex(acm_codec_id);
RTC_DCHECK(cid) << "Invalid codec index: " << acm_codec_id;
- const rtc::Optional<NetEqDecoder> ned =
+ const absl::optional<NetEqDecoder> ned =
RentACodec::NetEqDecoderFromCodecId(*cid, channels);
RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast<int>(*cid);
return *ned;
}();
- const rtc::Optional<SdpAudioFormat> new_format =
+ const absl::optional<SdpAudioFormat> new_format =
NetEqDecoderToSdpAudioFormat(neteq_decoder);
rtc::CritScope lock(&crit_sect_);
@@ -276,9 +276,9 @@
void AcmReceiver::RemoveAllCodecs() {
rtc::CritScope lock(&crit_sect_);
neteq_->RemoveAllPayloadTypes();
- last_audio_decoder_ = rtc::nullopt;
- last_audio_format_ = rtc::nullopt;
- last_packet_sample_rate_hz_ = rtc::nullopt;
+ last_audio_decoder_ = absl::nullopt;
+ last_audio_format_ = absl::nullopt;
+ last_packet_sample_rate_hz_ = absl::nullopt;
}
int AcmReceiver::RemoveCodec(uint8_t payload_type) {
@@ -289,14 +289,14 @@
return -1;
}
if (last_audio_decoder_ && payload_type == last_audio_decoder_->pltype) {
- last_audio_decoder_ = rtc::nullopt;
- last_audio_format_ = rtc::nullopt;
- last_packet_sample_rate_hz_ = rtc::nullopt;
+ last_audio_decoder_ = absl::nullopt;
+ last_audio_format_ = absl::nullopt;
+ last_packet_sample_rate_hz_ = absl::nullopt;
}
return 0;
}
-rtc::Optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
+absl::optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
return neteq_->GetPlayoutTimestamp();
}
@@ -317,7 +317,7 @@
return 0;
}
-rtc::Optional<SdpAudioFormat> AcmReceiver::LastAudioFormat() const {
+absl::optional<SdpAudioFormat> AcmReceiver::LastAudioFormat() const {
rtc::CritScope lock(&crit_sect_);
return last_audio_format_;
}
@@ -354,7 +354,7 @@
int AcmReceiver::DecoderByPayloadType(uint8_t payload_type,
CodecInst* codec) const {
rtc::CritScope lock(&crit_sect_);
- const rtc::Optional<CodecInst> ci = neteq_->GetDecoder(payload_type);
+ const absl::optional<CodecInst> ci = neteq_->GetDecoder(payload_type);
if (ci) {
*codec = *ci;
return 0;
@@ -384,10 +384,10 @@
// TODO(turajs): Should NetEq Buffer be flushed?
}
-const rtc::Optional<CodecInst> AcmReceiver::RtpHeaderToDecoder(
+const absl::optional<CodecInst> AcmReceiver::RtpHeaderToDecoder(
const RTPHeader& rtp_header,
uint8_t first_payload_byte) const {
- const rtc::Optional<CodecInst> ci =
+ const absl::optional<CodecInst> ci =
neteq_->GetDecoder(rtp_header.payloadType);
if (ci && STR_CASE_CMP(ci->plname, "red") == 0) {
// This is a RED packet. Get the payload of the audio codec.
diff --git a/modules/audio_coding/acm2/acm_receiver.h b/modules/audio_coding/acm2/acm_receiver.h
index ce1e1f2..c0afbb1 100644
--- a/modules/audio_coding/acm2/acm_receiver.h
+++ b/modules/audio_coding/acm2/acm_receiver.h
@@ -16,9 +16,9 @@
#include <string>
#include <vector>
-#include "api/audio/audio_frame.h"
+#include "absl/types/optional.h"
#include "api/array_view.h"
-#include "api/optional.h"
+#include "api/audio/audio_frame.h"
#include "common_audio/vad/include/webrtc_vad.h"
#include "modules/audio_coding/acm2/acm_resampler.h"
#include "modules/audio_coding/acm2/call_statistics.h"
@@ -159,7 +159,7 @@
// packet. If no packet of a registered non-CNG codec has been received, the
// return value is empty. Also, if the decoder was unregistered since the last
// packet was inserted, the return value is empty.
- rtc::Optional<int> last_packet_sample_rate_hz() const;
+ absl::optional<int> last_packet_sample_rate_hz() const;
// Returns last_output_sample_rate_hz from the NetEq instance.
int last_output_sample_rate_hz() const;
@@ -195,7 +195,7 @@
// Returns the RTP timestamp for the last sample delivered by GetAudio().
// The return value will be empty if no valid timestamp is available.
- rtc::Optional<uint32_t> GetPlayoutTimestamp();
+ absl::optional<uint32_t> GetPlayoutTimestamp();
// Returns the current total delay from NetEq (packet buffer and sync buffer)
// in ms, with smoothing applied to even out short-time fluctuations due to
@@ -215,7 +215,7 @@
//
int LastAudioCodec(CodecInst* codec) const;
- rtc::Optional<SdpAudioFormat> LastAudioFormat() const;
+ absl::optional<SdpAudioFormat> LastAudioFormat() const;
//
// Get a decoder given its registered payload-type.
@@ -273,22 +273,23 @@
int sample_rate_hz;
};
- const rtc::Optional<CodecInst> RtpHeaderToDecoder(const RTPHeader& rtp_header,
- uint8_t first_payload_byte)
- const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ const absl::optional<CodecInst> RtpHeaderToDecoder(
+ const RTPHeader& rtp_header,
+ uint8_t first_payload_byte) const
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
uint32_t NowInTimestamp(int decoder_sampling_rate) const;
rtc::CriticalSection crit_sect_;
- rtc::Optional<CodecInst> last_audio_decoder_ RTC_GUARDED_BY(crit_sect_);
- rtc::Optional<SdpAudioFormat> last_audio_format_ RTC_GUARDED_BY(crit_sect_);
+ absl::optional<CodecInst> last_audio_decoder_ RTC_GUARDED_BY(crit_sect_);
+ absl::optional<SdpAudioFormat> last_audio_format_ RTC_GUARDED_BY(crit_sect_);
ACMResampler resampler_ RTC_GUARDED_BY(crit_sect_);
std::unique_ptr<int16_t[]> last_audio_buffer_ RTC_GUARDED_BY(crit_sect_);
CallStatistics call_stats_ RTC_GUARDED_BY(crit_sect_);
const std::unique_ptr<NetEq> neteq_; // NetEq is thread-safe; no lock needed.
const Clock* const clock_;
bool resampled_last_output_frame_ RTC_GUARDED_BY(crit_sect_);
- rtc::Optional<int> last_packet_sample_rate_hz_ RTC_GUARDED_BY(crit_sect_);
+ absl::optional<int> last_packet_sample_rate_hz_ RTC_GUARDED_BY(crit_sect_);
};
} // namespace acm2
diff --git a/modules/audio_coding/acm2/audio_coding_module.cc b/modules/audio_coding/acm2/audio_coding_module.cc
index 4545810..2d8827c 100644
--- a/modules/audio_coding/acm2/audio_coding_module.cc
+++ b/modules/audio_coding/acm2/audio_coding_module.cc
@@ -54,7 +54,7 @@
rtc::FunctionView<void(const AudioEncoder*)> query) override;
// Get current send codec.
- rtc::Optional<CodecInst> SendCodec() const override;
+ absl::optional<CodecInst> SendCodec() const override;
// Get current send frequency.
int SendFrequency() const override;
@@ -142,7 +142,7 @@
// Get current received codec.
int ReceiveCodec(CodecInst* current_codec) const override;
- rtc::Optional<SdpAudioFormat> ReceiveFormat() const override;
+ absl::optional<SdpAudioFormat> ReceiveFormat() const override;
// Incoming packet from network parsed and ready for decode.
int IncomingPacket(const uint8_t* incoming_payload,
@@ -160,7 +160,7 @@
RTC_DEPRECATED int32_t PlayoutTimestamp(uint32_t* timestamp) override;
- rtc::Optional<uint32_t> PlayoutTimestamp() override;
+ absl::optional<uint32_t> PlayoutTimestamp() override;
int FilteredCurrentDelayMs() const override;
@@ -603,7 +603,7 @@
}
// Get current send codec.
-rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const {
+absl::optional<CodecInst> AudioCodingModuleImpl::SendCodec() const {
rtc::CritScope lock(&acm_crit_sect_);
if (encoder_factory_) {
auto* ci = encoder_factory_->codec_manager.GetCodecInst();
@@ -616,12 +616,12 @@
if (enc) {
return acm2::CodecManager::ForgeCodecInst(enc.get());
}
- return rtc::nullopt;
+ return absl::nullopt;
} else {
return encoder_stack_
- ? rtc::Optional<CodecInst>(
+ ? absl::optional<CodecInst>(
acm2::CodecManager::ForgeCodecInst(encoder_stack_.get()))
- : rtc::nullopt;
+ : absl::nullopt;
}
}
@@ -640,7 +640,7 @@
void AudioCodingModuleImpl::SetBitRate(int bitrate_bps) {
rtc::CritScope lock(&acm_crit_sect_);
if (encoder_stack_) {
- encoder_stack_->OnReceivedUplinkBandwidth(bitrate_bps, rtc::nullopt);
+ encoder_stack_->OnReceivedUplinkBandwidth(bitrate_bps, absl::nullopt);
}
}
@@ -1062,7 +1062,7 @@
return receiver_.LastAudioCodec(current_codec);
}
-rtc::Optional<SdpAudioFormat> AudioCodingModuleImpl::ReceiveFormat() const {
+absl::optional<SdpAudioFormat> AudioCodingModuleImpl::ReceiveFormat() const {
rtc::CritScope lock(&acm_crit_sect_);
return receiver_.LastAudioFormat();
}
@@ -1180,14 +1180,14 @@
}
int32_t AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) {
- rtc::Optional<uint32_t> ts = PlayoutTimestamp();
+ absl::optional<uint32_t> ts = PlayoutTimestamp();
if (!ts)
return -1;
*timestamp = *ts;
return 0;
}
-rtc::Optional<uint32_t> AudioCodingModuleImpl::PlayoutTimestamp() {
+absl::optional<uint32_t> AudioCodingModuleImpl::PlayoutTimestamp() {
return receiver_.GetPlayoutTimestamp();
}
@@ -1279,7 +1279,7 @@
CodecInst* codec,
int sampling_freq_hz,
size_t channels) {
- rtc::Optional<CodecInst> ci = acm2::RentACodec::CodecInstByParams(
+ absl::optional<CodecInst> ci = acm2::RentACodec::CodecInstByParams(
payload_name, sampling_freq_hz, channels);
if (ci) {
*codec = *ci;
@@ -1299,12 +1299,12 @@
int AudioCodingModule::Codec(const char* payload_name,
int sampling_freq_hz,
size_t channels) {
- rtc::Optional<acm2::RentACodec::CodecId> ci =
+ absl::optional<acm2::RentACodec::CodecId> ci =
acm2::RentACodec::CodecIdByParams(payload_name, sampling_freq_hz,
channels);
if (!ci)
return -1;
- rtc::Optional<int> i = acm2::RentACodec::CodecIndexFromId(*ci);
+ absl::optional<int> i = acm2::RentACodec::CodecIndexFromId(*ci);
return i ? *i : -1;
}
diff --git a/modules/audio_coding/acm2/audio_coding_module_unittest.cc b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
index e4926b6..e16d54a 100644
--- a/modules/audio_coding/acm2/audio_coding_module_unittest.cc
+++ b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
@@ -241,7 +241,7 @@
// These two have to be kept in sync for now. In the future, we'll be able to
// eliminate the CodecInst and keep only the SdpAudioFormat.
- rtc::Optional<SdpAudioFormat> audio_format_;
+ absl::optional<SdpAudioFormat> audio_format_;
CodecInst codec_;
Clock* clock_;
@@ -1058,7 +1058,7 @@
}
std::unique_ptr<AudioDecoder> MakeAudioDecoder(
const SdpAudioFormat& format,
- rtc::Optional<AudioCodecPairId> codec_pair_id) override {
+ absl::optional<AudioCodecPairId> codec_pair_id) override {
return format.name == "MockPCMu"
? std::move(mock_decoder_)
: fact_->MakeAudioDecoder(format, codec_pair_id);
diff --git a/modules/audio_coding/acm2/codec_manager.h b/modules/audio_coding/acm2/codec_manager.h
index 7485426..ffbad96 100644
--- a/modules/audio_coding/acm2/codec_manager.h
+++ b/modules/audio_coding/acm2/codec_manager.h
@@ -13,7 +13,7 @@
#include <map>
-#include "api/optional.h"
+#include "absl/types/optional.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/acm2/rent_a_codec.h"
#include "modules/audio_coding/include/audio_coding_module.h"
@@ -43,7 +43,7 @@
return send_codec_inst_ ? &*send_codec_inst_ : nullptr;
}
- void UnsetCodecInst() { send_codec_inst_ = rtc::nullopt; }
+ void UnsetCodecInst() { send_codec_inst_ = absl::nullopt; }
const RentACodec::StackParameters* GetStackParams() const {
return &codec_stack_params_;
@@ -63,7 +63,7 @@
private:
rtc::ThreadChecker thread_checker_;
- rtc::Optional<CodecInst> send_codec_inst_;
+ absl::optional<CodecInst> send_codec_inst_;
RentACodec::StackParameters codec_stack_params_;
bool recreate_encoder_ = true; // Need to recreate encoder?
diff --git a/modules/audio_coding/acm2/rent_a_codec.cc b/modules/audio_coding/acm2/rent_a_codec.cc
index 78db38d..818e17f 100644
--- a/modules/audio_coding/acm2/rent_a_codec.cc
+++ b/modules/audio_coding/acm2/rent_a_codec.cc
@@ -44,7 +44,7 @@
namespace webrtc {
namespace acm2 {
-rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
+absl::optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
const char* payload_name,
int sampling_freq_hz,
size_t channels) {
@@ -52,25 +52,25 @@
ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels));
}
-rtc::Optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) {
- rtc::Optional<int> mi = CodecIndexFromId(codec_id);
- return mi ? rtc::Optional<CodecInst>(Database()[*mi])
- : rtc::nullopt;
+absl::optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) {
+ absl::optional<int> mi = CodecIndexFromId(codec_id);
+ return mi ? absl::optional<CodecInst>(Database()[*mi]) : absl::nullopt;
}
-rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByInst(
+absl::optional<RentACodec::CodecId> RentACodec::CodecIdByInst(
const CodecInst& codec_inst) {
return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst));
}
-rtc::Optional<CodecInst> RentACodec::CodecInstByParams(const char* payload_name,
- int sampling_freq_hz,
- size_t channels) {
- rtc::Optional<CodecId> codec_id =
+absl::optional<CodecInst> RentACodec::CodecInstByParams(
+ const char* payload_name,
+ int sampling_freq_hz,
+ size_t channels) {
+ absl::optional<CodecId> codec_id =
CodecIdByParams(payload_name, sampling_freq_hz, channels);
if (!codec_id)
- return rtc::nullopt;
- rtc::Optional<CodecInst> ci = CodecInstById(*codec_id);
+ return absl::nullopt;
+ absl::optional<CodecInst> ci = CodecInstById(*codec_id);
RTC_DCHECK(ci);
// Keep the number of channels from the function call. For most codecs it
@@ -84,13 +84,13 @@
return ACMCodecDB::CodecNumber(codec_inst) >= 0;
}
-rtc::Optional<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id,
- size_t num_channels) {
+absl::optional<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id,
+ size_t num_channels) {
auto i = CodecIndexFromId(codec_id);
- return i ? rtc::Optional<bool>(
+ return i ? absl::optional<bool>(
ACMCodecDB::codec_settings_[*i].channel_support >=
num_channels)
- : rtc::nullopt;
+ : absl::nullopt;
}
rtc::ArrayView<const CodecInst> RentACodec::Database() {
@@ -98,12 +98,12 @@
NumberOfCodecs());
}
-rtc::Optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
+absl::optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
CodecId codec_id,
size_t num_channels) {
- rtc::Optional<int> i = CodecIndexFromId(codec_id);
+ absl::optional<int> i = CodecIndexFromId(codec_id);
if (!i)
- return rtc::nullopt;
+ return absl::nullopt;
const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i];
return (ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
? NetEqDecoder::kDecoderOpus_2ch
@@ -276,8 +276,7 @@
auto pt = [¶m](const std::map<int, int>& m) {
auto it = m.find(param->speech_encoder->SampleRateHz());
- return it == m.end() ? rtc::nullopt
- : rtc::Optional<int>(it->second);
+ return it == m.end() ? absl::nullopt : absl::optional<int>(it->second);
};
auto cng_pt = pt(param->cng_payload_types);
param->use_cng =
diff --git a/modules/audio_coding/acm2/rent_a_codec.h b/modules/audio_coding/acm2/rent_a_codec.h
index f8fac4c..02f9d03 100644
--- a/modules/audio_coding/acm2/rent_a_codec.h
+++ b/modules/audio_coding/acm2/rent_a_codec.h
@@ -15,10 +15,10 @@
#include <map>
#include <memory>
+#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/audio_codecs/audio_decoder.h"
#include "api/audio_codecs/audio_encoder.h"
-#include "api/optional.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/neteq/neteq_decoder_enum.h"
#include "rtc_base/constructormagic.h"
@@ -107,28 +107,28 @@
return static_cast<size_t>(CodecId::kNumCodecs);
}
- static inline rtc::Optional<int> CodecIndexFromId(CodecId codec_id) {
+ static inline absl::optional<int> CodecIndexFromId(CodecId codec_id) {
const int i = static_cast<int>(codec_id);
return i >= 0 && i < static_cast<int>(NumberOfCodecs())
- ? rtc::Optional<int>(i)
- : rtc::nullopt;
+ ? absl::optional<int>(i)
+ : absl::nullopt;
}
- static inline rtc::Optional<CodecId> CodecIdFromIndex(int codec_index) {
+ static inline absl::optional<CodecId> CodecIdFromIndex(int codec_index) {
return static_cast<size_t>(codec_index) < NumberOfCodecs()
- ? rtc::Optional<RentACodec::CodecId>(
+ ? absl::optional<RentACodec::CodecId>(
static_cast<RentACodec::CodecId>(codec_index))
- : rtc::nullopt;
+ : absl::nullopt;
}
- static rtc::Optional<CodecId> CodecIdByParams(const char* payload_name,
- int sampling_freq_hz,
- size_t channels);
- static rtc::Optional<CodecInst> CodecInstById(CodecId codec_id);
- static rtc::Optional<CodecId> CodecIdByInst(const CodecInst& codec_inst);
- static rtc::Optional<CodecInst> CodecInstByParams(const char* payload_name,
- int sampling_freq_hz,
- size_t channels);
+ static absl::optional<CodecId> CodecIdByParams(const char* payload_name,
+ int sampling_freq_hz,
+ size_t channels);
+ static absl::optional<CodecInst> CodecInstById(CodecId codec_id);
+ static absl::optional<CodecId> CodecIdByInst(const CodecInst& codec_inst);
+ static absl::optional<CodecInst> CodecInstByParams(const char* payload_name,
+ int sampling_freq_hz,
+ size_t channels);
static bool IsCodecValid(const CodecInst& codec_inst);
static inline bool IsPayloadTypeValid(int payload_type) {
@@ -137,10 +137,10 @@
static rtc::ArrayView<const CodecInst> Database();
- static rtc::Optional<bool> IsSupportedNumChannels(CodecId codec_id,
- size_t num_channels);
+ static absl::optional<bool> IsSupportedNumChannels(CodecId codec_id,
+ size_t num_channels);
- static rtc::Optional<NetEqDecoder> NetEqDecoderFromCodecId(
+ static absl::optional<NetEqDecoder> NetEqDecoderFromCodecId(
CodecId codec_id,
size_t num_channels);