From f281853c111a11e13ac7c6ad2db705ee526a39a8 Mon Sep 17 00:00:00 2001 From: Oskar Sundbom Date: Thu, 16 Nov 2017 10:56:47 +0100 Subject: [PATCH] Optional: Use nullopt and implicit construction in /logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Bug: None Change-Id: Ibe15d2814074a4cf67de18d6e04540076f1a9dc9 Reviewed-on: https://webrtc-review.googlesource.com/23611 Reviewed-by: Björn Terelius Commit-Queue: Oskar Sundbom Cr-Commit-Position: refs/heads/master@{#20862} --- .../encoder/rtc_event_log_encoder_unittest.cc | 24 +++++++++---------- logging/rtc_event_log/rtc_event_log_parser.cc | 23 ++++++++---------- .../rtc_event_log/rtc_event_log_unittest.cc | 13 +++++----- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc index 2221bf4b9a..ce4297cf3b 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc @@ -148,14 +148,14 @@ void RtcEventLogEncoderTest::TestRtcEventAudioNetworkAdaptation( TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationBitrate) { auto runtime_config = rtc::MakeUnique(); const int bitrate_bps = RandomBitrate(); - runtime_config->bitrate_bps = rtc::Optional(bitrate_bps); + runtime_config->bitrate_bps = bitrate_bps; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationFrameLength) { auto runtime_config = rtc::MakeUnique(); const int frame_length_ms = prng_.Rand(1, 1000); - runtime_config->frame_length_ms = rtc::Optional(frame_length_ms); + runtime_config->frame_length_ms = frame_length_ms; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } @@ -163,7 +163,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationPacketLoss) { // To simplify the test, we just check powers of two. const float plr = std::pow(0.5f, prng_.Rand(1, 8)); auto runtime_config = rtc::MakeUnique(); - runtime_config->uplink_packet_loss_fraction = rtc::Optional(plr); + runtime_config->uplink_packet_loss_fraction = plr; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } @@ -172,7 +172,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationFec) { // for safety's sake, we test both. for (bool fec_enabled : {false, true}) { auto runtime_config = rtc::MakeUnique(); - runtime_config->enable_fec = rtc::Optional(fec_enabled); + runtime_config->enable_fec = fec_enabled; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } } @@ -182,7 +182,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationDtx) { // for safety's sake, we test both. for (bool dtx_enabled : {false, true}) { auto runtime_config = rtc::MakeUnique(); - runtime_config->enable_dtx = rtc::Optional(dtx_enabled); + runtime_config->enable_dtx = dtx_enabled; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } } @@ -192,7 +192,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationChannels) { // for safety's sake, we test both. for (size_t channels : {1, 2}) { auto runtime_config = rtc::MakeUnique(); - runtime_config->num_channels = rtc::Optional(channels); + runtime_config->num_channels = channels; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } } @@ -205,12 +205,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationAll) { for (bool dtx_enabled : {false, true}) { for (size_t channels : {1, 2}) { auto runtime_config = rtc::MakeUnique(); - runtime_config->bitrate_bps = rtc::Optional(bitrate_bps); - runtime_config->frame_length_ms = rtc::Optional(frame_length_ms); - runtime_config->uplink_packet_loss_fraction = rtc::Optional(plr); - runtime_config->enable_fec = rtc::Optional(fec_enabled); - runtime_config->enable_dtx = rtc::Optional(dtx_enabled); - runtime_config->num_channels = rtc::Optional(channels); + runtime_config->bitrate_bps = bitrate_bps; + runtime_config->frame_length_ms = frame_length_ms; + runtime_config->uplink_packet_loss_fraction = plr; + runtime_config->enable_fec = fec_enabled; + runtime_config->enable_dtx = dtx_enabled; + runtime_config->num_channels = channels; TestRtcEventAudioNetworkAdaptation(std::move(runtime_config)); } diff --git a/logging/rtc_event_log/rtc_event_log_parser.cc b/logging/rtc_event_log/rtc_event_log_parser.cc index 060c553421..38697e9c92 100644 --- a/logging/rtc_event_log/rtc_event_log_parser.cc +++ b/logging/rtc_event_log/rtc_event_log_parser.cc @@ -585,18 +585,18 @@ void ParsedRtcEventLog::GetAudioNetworkAdaptation( const rtclog::AudioNetworkAdaptation& ana_event = event.audio_network_adaptation(); if (ana_event.has_bitrate_bps()) - config->bitrate_bps = rtc::Optional(ana_event.bitrate_bps()); + config->bitrate_bps = ana_event.bitrate_bps(); if (ana_event.has_enable_fec()) - config->enable_fec = rtc::Optional(ana_event.enable_fec()); + config->enable_fec = ana_event.enable_fec(); if (ana_event.has_enable_dtx()) - config->enable_dtx = rtc::Optional(ana_event.enable_dtx()); + config->enable_dtx = ana_event.enable_dtx(); if (ana_event.has_frame_length_ms()) - config->frame_length_ms = rtc::Optional(ana_event.frame_length_ms()); + config->frame_length_ms = ana_event.frame_length_ms(); if (ana_event.has_num_channels()) - config->num_channels = rtc::Optional(ana_event.num_channels()); + config->num_channels = ana_event.num_channels(); if (ana_event.has_uplink_packet_loss_fraction()) config->uplink_packet_loss_fraction = - rtc::Optional(ana_event.uplink_packet_loss_fraction()); + ana_event.uplink_packet_loss_fraction(); } ParsedRtcEventLog::BweProbeClusterCreatedEvent @@ -636,18 +636,15 @@ ParsedRtcEventLog::BweProbeResultEvent ParsedRtcEventLog::GetBweProbeResult( RTC_CHECK(pr_event.has_result()); if (pr_event.result() == rtclog::BweProbeResult::SUCCESS) { RTC_CHECK(pr_event.has_bitrate_bps()); - res.bitrate_bps = rtc::Optional(pr_event.bitrate_bps()); + res.bitrate_bps = pr_event.bitrate_bps(); } else if (pr_event.result() == rtclog::BweProbeResult::INVALID_SEND_RECEIVE_INTERVAL) { - res.failure_reason = rtc::Optional( - ProbeFailureReason::kInvalidSendReceiveInterval); + res.failure_reason = ProbeFailureReason::kInvalidSendReceiveInterval; } else if (pr_event.result() == rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO) { - res.failure_reason = rtc::Optional( - ProbeFailureReason::kInvalidSendReceiveRatio); + res.failure_reason = ProbeFailureReason::kInvalidSendReceiveRatio; } else if (pr_event.result() == rtclog::BweProbeResult::TIMEOUT) { - res.failure_reason = - rtc::Optional(ProbeFailureReason::kTimeout); + res.failure_reason = ProbeFailureReason::kTimeout; } else { RTC_NOTREACHED(); } diff --git a/logging/rtc_event_log/rtc_event_log_unittest.cc b/logging/rtc_event_log/rtc_event_log_unittest.cc index fbef901c00..156732317d 100644 --- a/logging/rtc_event_log/rtc_event_log_unittest.cc +++ b/logging/rtc_event_log/rtc_event_log_unittest.cc @@ -291,13 +291,12 @@ BweLossEvent GenerateBweLossEvent(Random* prng) { void GenerateAudioNetworkAdaptation(const RtpHeaderExtensionMap& extensions, AudioEncoderRuntimeConfig* config, Random* prng) { - config->bitrate_bps = rtc::Optional(prng->Rand(0, 3000000)); - config->enable_fec = rtc::Optional(prng->Rand()); - config->enable_dtx = rtc::Optional(prng->Rand()); - config->frame_length_ms = rtc::Optional(prng->Rand(10, 120)); - config->num_channels = rtc::Optional(prng->Rand(1, 2)); - config->uplink_packet_loss_fraction = - rtc::Optional(prng->Rand()); + config->bitrate_bps = prng->Rand(0, 3000000); + config->enable_fec = prng->Rand(); + config->enable_dtx = prng->Rand(); + config->frame_length_ms = prng->Rand(10, 120); + config->num_channels = prng->Rand(1, 2); + config->uplink_packet_loss_fraction = prng->Rand(); } class RtcEventLogSession