Optional: Use nullopt and implicit construction in /common_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=tina.legrand@webrtc.org

Bug: None
Change-Id: Iea6f04db7c1f92fe9da2c855bb60ad2f70c371d3
Reviewed-on: https://webrtc-review.googlesource.com/23615
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20915}
This commit is contained in:
Oskar Sundbom 2017-11-16 10:57:19 +01:00 committed by Commit Bot
parent aba85d1f53
commit 5e1a7496bb
2 changed files with 4 additions and 5 deletions

View File

@ -43,7 +43,7 @@ void SmoothingFilterImpl::AddSample(float sample) {
// This is equivalent to assuming the filter has been receiving the same
// value as the first sample since time -infinity.
state_ = last_sample_ = sample;
init_end_time_ms_ = rtc::Optional<int64_t>(now_ms + init_time_ms_);
init_end_time_ms_ = now_ms + init_time_ms_;
last_state_time_ms_ = now_ms;
return;
}
@ -55,10 +55,10 @@ void SmoothingFilterImpl::AddSample(float sample) {
rtc::Optional<float> SmoothingFilterImpl::GetAverage() {
if (!init_end_time_ms_) {
// |init_end_time_ms_| undefined since we have not received any sample.
return rtc::Optional<float>();
return rtc::nullopt;
}
ExtrapolateLastSample(rtc::TimeMillis());
return rtc::Optional<float>(state_);
return state_;
}
bool SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) {

View File

@ -132,8 +132,7 @@ TEST(SmoothingFilterTest, GetAverageOutputsEmptyBeforeFirstSample) {
EXPECT_FALSE(states.smoothing_filter.GetAverage());
constexpr float kFirstSample = 1.2345f;
states.smoothing_filter.AddSample(kFirstSample);
EXPECT_EQ(rtc::Optional<float>(kFirstSample),
states.smoothing_filter.GetAverage());
EXPECT_EQ(kFirstSample, states.smoothing_filter.GetAverage());
}
TEST(SmoothingFilterTest, CannotChangeTimeConstantDuringInitialization) {