Optional: Use nullopt and implicit construction in /logging

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 <terelius@webrtc.org>
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20862}
This commit is contained in:
Oskar Sundbom
2017-11-16 10:56:47 +01:00
committed by Commit Bot
parent 6196feb2ed
commit f281853c11
3 changed files with 28 additions and 32 deletions

View File

@ -148,14 +148,14 @@ void RtcEventLogEncoderTest::TestRtcEventAudioNetworkAdaptation(
TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationBitrate) {
auto runtime_config = rtc::MakeUnique<AudioEncoderRuntimeConfig>();
const int bitrate_bps = RandomBitrate();
runtime_config->bitrate_bps = rtc::Optional<int>(bitrate_bps);
runtime_config->bitrate_bps = bitrate_bps;
TestRtcEventAudioNetworkAdaptation(std::move(runtime_config));
}
TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationFrameLength) {
auto runtime_config = rtc::MakeUnique<AudioEncoderRuntimeConfig>();
const int frame_length_ms = prng_.Rand(1, 1000);
runtime_config->frame_length_ms = rtc::Optional<int>(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<AudioEncoderRuntimeConfig>();
runtime_config->uplink_packet_loss_fraction = rtc::Optional<float>(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<AudioEncoderRuntimeConfig>();
runtime_config->enable_fec = rtc::Optional<bool>(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<AudioEncoderRuntimeConfig>();
runtime_config->enable_dtx = rtc::Optional<bool>(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<AudioEncoderRuntimeConfig>();
runtime_config->num_channels = rtc::Optional<size_t>(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<AudioEncoderRuntimeConfig>();
runtime_config->bitrate_bps = rtc::Optional<int>(bitrate_bps);
runtime_config->frame_length_ms = rtc::Optional<int>(frame_length_ms);
runtime_config->uplink_packet_loss_fraction = rtc::Optional<float>(plr);
runtime_config->enable_fec = rtc::Optional<bool>(fec_enabled);
runtime_config->enable_dtx = rtc::Optional<bool>(dtx_enabled);
runtime_config->num_channels = rtc::Optional<size_t>(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));
}

View File

@ -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<int>(ana_event.bitrate_bps());
config->bitrate_bps = ana_event.bitrate_bps();
if (ana_event.has_enable_fec())
config->enable_fec = rtc::Optional<bool>(ana_event.enable_fec());
config->enable_fec = ana_event.enable_fec();
if (ana_event.has_enable_dtx())
config->enable_dtx = rtc::Optional<bool>(ana_event.enable_dtx());
config->enable_dtx = ana_event.enable_dtx();
if (ana_event.has_frame_length_ms())
config->frame_length_ms = rtc::Optional<int>(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<size_t>(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<float>(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<uint64_t>(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>(
ProbeFailureReason::kInvalidSendReceiveInterval);
res.failure_reason = ProbeFailureReason::kInvalidSendReceiveInterval;
} else if (pr_event.result() ==
rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO) {
res.failure_reason = rtc::Optional<ProbeFailureReason>(
ProbeFailureReason::kInvalidSendReceiveRatio);
res.failure_reason = ProbeFailureReason::kInvalidSendReceiveRatio;
} else if (pr_event.result() == rtclog::BweProbeResult::TIMEOUT) {
res.failure_reason =
rtc::Optional<ProbeFailureReason>(ProbeFailureReason::kTimeout);
res.failure_reason = ProbeFailureReason::kTimeout;
} else {
RTC_NOTREACHED();
}

View File

@ -291,13 +291,12 @@ BweLossEvent GenerateBweLossEvent(Random* prng) {
void GenerateAudioNetworkAdaptation(const RtpHeaderExtensionMap& extensions,
AudioEncoderRuntimeConfig* config,
Random* prng) {
config->bitrate_bps = rtc::Optional<int>(prng->Rand(0, 3000000));
config->enable_fec = rtc::Optional<bool>(prng->Rand<bool>());
config->enable_dtx = rtc::Optional<bool>(prng->Rand<bool>());
config->frame_length_ms = rtc::Optional<int>(prng->Rand(10, 120));
config->num_channels = rtc::Optional<size_t>(prng->Rand(1, 2));
config->uplink_packet_loss_fraction =
rtc::Optional<float>(prng->Rand<float>());
config->bitrate_bps = prng->Rand(0, 3000000);
config->enable_fec = prng->Rand<bool>();
config->enable_dtx = prng->Rand<bool>();
config->frame_length_ms = prng->Rand(10, 120);
config->num_channels = prng->Rand(1, 2);
config->uplink_packet_loss_fraction = prng->Rand<float>();
}
class RtcEventLogSession