Optional: Use nullopt and implicit construction in /api/audio_codecs
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: I30f47ec9b6dbef216ee061a96fad8ca14c041bb5
Reviewed-on: https://webrtc-review.googlesource.com/23566
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20711}
diff --git a/api/audio_codecs/opus/audio_decoder_opus.cc b/api/audio_codecs/opus/audio_decoder_opus.cc
index 5575833..472a079 100644
--- a/api/audio_codecs/opus/audio_decoder_opus.cc
+++ b/api/audio_codecs/opus/audio_decoder_opus.cc
@@ -22,25 +22,25 @@
rtc::Optional<AudioDecoderOpus::Config> AudioDecoderOpus::SdpToConfig(
const SdpAudioFormat& format) {
- const rtc::Optional<int> num_channels = [&] {
+ const auto num_channels = [&]() -> rtc::Optional<int> {
auto stereo = format.parameters.find("stereo");
if (stereo != format.parameters.end()) {
if (stereo->second == "0") {
- return rtc::Optional<int>(1);
+ return 1;
} else if (stereo->second == "1") {
- return rtc::Optional<int>(2);
+ return 2;
} else {
- return rtc::Optional<int>(); // Bad stereo parameter.
+ return rtc::nullopt; // Bad stereo parameter.
}
}
- return rtc::Optional<int>(1); // Default to mono.
+ return 1; // Default to mono.
}();
if (STR_CASE_CMP(format.name.c_str(), "opus") == 0 &&
format.clockrate_hz == 48000 && format.num_channels == 2 &&
num_channels) {
- return rtc::Optional<Config>(Config{*num_channels});
+ return Config{*num_channels};
} else {
- return rtc::Optional<Config>();
+ return rtc::nullopt;
}
}