Optional: Use nullopt and implicit construction in /audio
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=solenberg@webrtc.org
Bug: None
Change-Id: I03562600978bdedb9dc93a34aeb0561c66f54aae
Reviewed-on: https://webrtc-review.googlesource.com/23617
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20731}
diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc
index b1e3f98..a1233f2 100644
--- a/audio/audio_receive_stream.cc
+++ b/audio/audio_receive_stream.cc
@@ -180,7 +180,7 @@
stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
if (codec_inst.pltype != -1) {
stats.codec_name = codec_inst.plname;
- stats.codec_payload_type = rtc::Optional<int>(codec_inst.pltype);
+ stats.codec_payload_type = codec_inst.pltype;
}
stats.ext_seqnum = call_stats.extendedMax;
if (codec_inst.plfreq / 1000 > 0) {
@@ -272,18 +272,18 @@
if (!rtp_receiver->GetLatestTimestamps(
&info.latest_received_capture_timestamp,
&info.latest_receive_time_ms)) {
- return rtc::Optional<Syncable::Info>();
+ return rtc::nullopt;
}
if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs,
&info.capture_time_ntp_frac,
nullptr,
nullptr,
&info.capture_time_source_clock) != 0) {
- return rtc::Optional<Syncable::Info>();
+ return rtc::nullopt;
}
info.current_delay_ms = channel_proxy_->GetDelayEstimate();
- return rtc::Optional<Syncable::Info>(info);
+ return info;
}
uint32_t AudioReceiveStream::GetPlayoutTimestamp() const {
diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc
index fc893e4..8583ed0 100644
--- a/audio/audio_send_stream.cc
+++ b/audio/audio_send_stream.cc
@@ -296,7 +296,7 @@
if (config_.send_codec_spec) {
const auto& spec = *config_.send_codec_spec;
stats.codec_name = spec.format.name;
- stats.codec_payload_type = rtc::Optional<int>(spec.payload_type);
+ stats.codec_payload_type = spec.payload_type;
// Get data from the last remote RTCP report.
for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) {
diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc
index d8d81a4..8e42029 100644
--- a/audio/audio_send_stream_unittest.cc
+++ b/audio/audio_send_stream_unittest.cc
@@ -115,14 +115,15 @@
.WillByDefault(Return(std::vector<AudioCodecSpec>(
std::begin(kCodecSpecs), std::end(kCodecSpecs))));
ON_CALL(*factory.get(), QueryAudioEncoder(_))
- .WillByDefault(Invoke([](const SdpAudioFormat& format) {
- for (const auto& spec : kCodecSpecs) {
- if (format == spec.format) {
- return rtc::Optional<AudioCodecInfo>(spec.info);
- }
- }
- return rtc::Optional<AudioCodecInfo>();
- }));
+ .WillByDefault(Invoke(
+ [](const SdpAudioFormat& format) -> rtc::Optional<AudioCodecInfo> {
+ for (const auto& spec : kCodecSpecs) {
+ if (format == spec.format) {
+ return spec.info;
+ }
+ }
+ return rtc::nullopt;
+ }));
ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _))
.WillByDefault(Invoke([](int payload_type, const SdpAudioFormat& format,
std::unique_ptr<AudioEncoder>* return_value) {
@@ -168,8 +169,7 @@
// Use ISAC as default codec so as to prevent unnecessary |voice_engine_|
// calls from the default ctor behavior.
stream_config_.send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
- {kIsacPayloadType, kIsacFormat});
+ AudioSendStream::Config::SendCodecSpec(kIsacPayloadType, kIsacFormat);
stream_config_.voe_channel_id = kChannelId;
stream_config_.rtp.ssrc = kSsrc;
stream_config_.rtp.nack.rtp_history_ms = 200;
@@ -358,11 +358,10 @@
config.min_bitrate_bps = 12000;
config.max_bitrate_bps = 34000;
config.send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
- {kIsacPayloadType, kIsacFormat});
+ AudioSendStream::Config::SendCodecSpec(kIsacPayloadType, kIsacFormat);
config.send_codec_spec->nack_enabled = true;
config.send_codec_spec->transport_cc_enabled = false;
- config.send_codec_spec->cng_payload_type = rtc::Optional<int>(42);
+ config.send_codec_spec->cng_payload_type = 42;
config.encoder_factory = MockAudioEncoderFactory::CreateUnusedFactory();
config.rtp.extensions.push_back(
RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
@@ -383,7 +382,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
}
TEST(AudioSendStreamTest, SendTelephoneEvent) {
@@ -391,7 +390,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
helper.SetupMockForSendTelephoneEvent();
EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType,
kTelephoneEventPayloadFrequency, kTelephoneEventCode,
@@ -403,7 +402,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true));
send_stream.SetMuted(true);
}
@@ -413,7 +412,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
}
TEST(AudioSendStreamTest, NoAudioBweCorrectObjectsOnChannelProxy) {
@@ -421,7 +420,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
}
TEST(AudioSendStreamTest, GetStats) {
@@ -429,7 +428,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
helper.SetupMockForGetStats();
AudioSendStream::Stats stats = send_stream.GetStats();
EXPECT_EQ(kSsrc, stats.local_ssrc);
@@ -461,12 +460,11 @@
ConfigHelper helper(false, true);
auto stream_config = helper.config();
stream_config.send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>({0, kOpusFormat});
+ AudioSendStream::Config::SendCodecSpec(0, kOpusFormat);
const std::string kAnaConfigString = "abcde";
const std::string kAnaReconfigString = "12345";
- stream_config.audio_network_adaptor_config =
- rtc::Optional<std::string>(kAnaConfigString);
+ stream_config.audio_network_adaptor_config = kAnaConfigString;
EXPECT_CALL(helper.mock_encoder_factory(), MakeAudioEncoderMock(_, _, _))
.WillOnce(Invoke([&kAnaConfigString, &kAnaReconfigString](
@@ -485,10 +483,9 @@
internal::AudioSendStream send_stream(
stream_config, helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
- stream_config.audio_network_adaptor_config =
- rtc::Optional<std::string>(kAnaReconfigString);
+ stream_config.audio_network_adaptor_config = kAnaReconfigString;
helper.SetupMockForModifyEncoder();
send_stream.Reconfigure(stream_config);
@@ -500,8 +497,8 @@
ConfigHelper helper(false, false);
auto stream_config = helper.config();
stream_config.send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>({9, kG722Format});
- stream_config.send_codec_spec->cng_payload_type = rtc::Optional<int>(105);
+ AudioSendStream::Config::SendCodecSpec(9, kG722Format);
+ stream_config.send_codec_spec->cng_payload_type = 105;
using ::testing::Invoke;
std::unique_ptr<AudioEncoder> stolen_encoder;
EXPECT_CALL(*helper.channel_proxy(), SetEncoderForMock(_, _))
@@ -515,7 +512,7 @@
internal::AudioSendStream send_stream(
stream_config, helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
// We cannot truly determine if the encoder created is an AudioEncoderCng. It
// is the only reasonable implementation that will return something from
@@ -529,7 +526,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
EXPECT_CALL(*helper.channel_proxy(),
SetBitrate(helper.config().max_bitrate_bps, _));
send_stream.OnBitrateUpdated(helper.config().max_bitrate_bps + 5000, 0.0, 50,
@@ -541,7 +538,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
EXPECT_CALL(*helper.channel_proxy(), SetBitrate(_, 5000));
send_stream.OnBitrateUpdated(50000, 0.0, 50, 5000);
}
@@ -559,12 +556,12 @@
auto stream_config = helper.config();
stream_config.send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>({9, kG722Format});
- stream_config.send_codec_spec->cng_payload_type = rtc::Optional<int>(105);
+ AudioSendStream::Config::SendCodecSpec(9, kG722Format);
+ stream_config.send_codec_spec->cng_payload_type = 105;
internal::AudioSendStream send_stream(
stream_config, helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
send_stream.Reconfigure(stream_config);
}
@@ -573,7 +570,7 @@
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
- helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
+ helper.rtcp_rtt_stats(), rtc::nullopt);
auto new_config = helper.config();
ConfigHelper::AddBweToConfig(&new_config);
EXPECT_CALL(*helper.channel_proxy(),
diff --git a/audio/test/audio_bwe_integration_test.cc b/audio/test/audio_bwe_integration_test.cc
index d57fef8..f89ced9 100644
--- a/audio/test/audio_bwe_integration_test.cc
+++ b/audio/test/audio_bwe_integration_test.cc
@@ -92,13 +92,12 @@
void ModifyAudioConfigs(
AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
- send_config->send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
- {test::CallTest::kAudioSendPayloadType,
- {"OPUS",
- 48000,
- 2,
- {{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}}});
+ send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
+ test::CallTest::kAudioSendPayloadType,
+ {"OPUS",
+ 48000,
+ 2,
+ {{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}});
send_config->min_bitrate_bps = 6000;
send_config->max_bitrate_bps = 100000;
diff --git a/audio/test/audio_end_to_end_test.cc b/audio/test/audio_end_to_end_test.cc
index 2ae9390..44bf3f7 100644
--- a/audio/test/audio_end_to_end_test.cc
+++ b/audio/test/audio_end_to_end_test.cc
@@ -80,9 +80,8 @@
// Large bitrate by default.
const webrtc::SdpAudioFormat kDefaultFormat("opus", 48000, 2,
{{"stereo", "1"}});
- send_config->send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
- {test::CallTest::kAudioSendPayloadType, kDefaultFormat});
+ send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
+ test::CallTest::kAudioSendPayloadType, kDefaultFormat);
}
void AudioEndToEndTest::OnAudioStreamsCreated(
diff --git a/audio/test/low_bandwidth_audio_test.cc b/audio/test/low_bandwidth_audio_test.cc
index b3c674d..cf84e19 100644
--- a/audio/test/low_bandwidth_audio_test.cc
+++ b/audio/test/low_bandwidth_audio_test.cc
@@ -77,15 +77,14 @@
class Mobile2GNetworkTest : public AudioQualityTest {
void ModifyAudioConfigs(AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
- send_config->send_codec_spec =
- rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
- {test::CallTest::kAudioSendPayloadType,
- {"OPUS",
- 48000,
- 2,
- {{"maxaveragebitrate", "6000"},
- {"ptime", "60"},
- {"stereo", "1"}}}});
+ send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
+ test::CallTest::kAudioSendPayloadType,
+ {"OPUS",
+ 48000,
+ 2,
+ {{"maxaveragebitrate", "6000"},
+ {"ptime", "60"},
+ {"stereo", "1"}}});
}
FakeNetworkPipe::Config GetNetworkPipeConfig() const override {