Optional: Use nullopt and implicit construction in /modules/video_coding
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: Iedebf4dc56a973306e7d7e7649525879808dc72b
Reviewed-on: https://webrtc-review.googlesource.com/23578
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20878}
diff --git a/modules/video_coding/codecs/test/videoprocessor.cc b/modules/video_coding/codecs/test/videoprocessor.cc
index 5e20615..20cb0cf 100644
--- a/modules/video_coding/codecs/test/videoprocessor.cc
+++ b/modules/video_coding/codecs/test/videoprocessor.cc
@@ -47,7 +47,7 @@
rtc::Optional<size_t> GetMaxNaluLength(const EncodedImage& encoded_frame,
const TestConfig& config) {
if (config.codec_settings.codecType != kVideoCodecH264)
- return rtc::Optional<size_t>();
+ return rtc::nullopt;
std::vector<webrtc::H264::NaluIndex> nalu_indices =
webrtc::H264::FindNaluIndices(encoded_frame._buffer,
@@ -59,7 +59,7 @@
for (const webrtc::H264::NaluIndex& index : nalu_indices)
max_length = std::max(max_length, index.payload_size);
- return rtc::Optional<size_t>(max_length);
+ return max_length;
}
int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) {
diff --git a/modules/video_coding/codecs/vp8/screenshare_layers_unittest.cc b/modules/video_coding/codecs/vp8/screenshare_layers_unittest.cc
index 988c1b3..754235a 100644
--- a/modules/video_coding/codecs/vp8/screenshare_layers_unittest.cc
+++ b/modules/video_coding/codecs/vp8/screenshare_layers_unittest.cc
@@ -132,7 +132,7 @@
// FrameEncoded() call will be omitted and needs to be done by the caller.
// Returns the flags for the last frame.
int SkipUntilTl(int layer) {
- return SkipUntilTlAndSync(layer, rtc::Optional<bool>());
+ return SkipUntilTlAndSync(layer, rtc::nullopt);
}
// Same as SkipUntilTl, but also waits until the sync bit condition is met.
@@ -583,7 +583,7 @@
EXPECT_TRUE(RunGracePeriod());
// Move ahead until we have a sync frame in TL1.
- EXPECT_EQ(kTl1SyncFlags, SkipUntilTlAndSync(1, rtc::Optional<bool>(true)));
+ EXPECT_EQ(kTl1SyncFlags, SkipUntilTlAndSync(1, true));
ASSERT_TRUE(vp8_info_.layerSync);
// Simulate overshoot of this frame.
diff --git a/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
index 015485f..5d6abec 100644
--- a/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
+++ b/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
@@ -108,7 +108,7 @@
EXPECT_GT(frame.width(), 0);
EXPECT_GT(frame.height(), 0);
EXPECT_TRUE(qp);
- frame_ = rtc::Optional<VideoFrame>(frame);
+ frame_ = frame;
qp_ = qp;
complete_ = true;
}
diff --git a/modules/video_coding/codecs/vp8/vp8_impl.cc b/modules/video_coding/codecs/vp8/vp8_impl.cc
index 107618f..9e89696 100644
--- a/modules/video_coding/codecs/vp8/vp8_impl.cc
+++ b/modules/video_coding/codecs/vp8/vp8_impl.cc
@@ -1234,8 +1234,7 @@
VideoFrame decoded_image(buffer, timestamp, 0, kVideoRotation_0);
decoded_image.set_ntp_time_ms(ntp_time_ms);
- decode_complete_callback_->Decoded(decoded_image, rtc::Optional<int32_t>(),
- rtc::Optional<uint8_t>(qp));
+ decode_complete_callback_->Decoded(decoded_image, rtc::nullopt, qp);
return WEBRTC_VIDEO_CODEC_OK;
}
diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc
index 7c69dfd..5fa4537 100644
--- a/modules/video_coding/codecs/vp9/vp9_impl.cc
+++ b/modules/video_coding/codecs/vp9/vp9_impl.cc
@@ -983,8 +983,7 @@
0 /* render_time_ms */, webrtc::kVideoRotation_0);
decoded_image.set_ntp_time_ms(ntp_time_ms);
- decode_complete_callback_->Decoded(decoded_image, rtc::Optional<int32_t>(),
- rtc::Optional<uint8_t>(qp));
+ decode_complete_callback_->Decoded(decoded_image, rtc::nullopt, qp);
return WEBRTC_VIDEO_CODEC_OK;
}
diff --git a/modules/video_coding/frame_object.cc b/modules/video_coding/frame_object.cc
index 72dd70e..6a31cfd 100644
--- a/modules/video_coding/frame_object.cc
+++ b/modules/video_coding/frame_object.cc
@@ -167,8 +167,8 @@
rtc::CritScope lock(&packet_buffer_->crit_);
VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_);
if (!packet)
- return rtc::Optional<RTPVideoTypeHeader>();
- return rtc::Optional<RTPVideoTypeHeader>(packet->video_header.codecHeader);
+ return rtc::nullopt;
+ return packet->video_header.codecHeader;
}
} // namespace video_coding
diff --git a/modules/video_coding/generic_decoder.cc b/modules/video_coding/generic_decoder.cc
index f3af20c..a7d6a85 100644
--- a/modules/video_coding/generic_decoder.cc
+++ b/modules/video_coding/generic_decoder.cc
@@ -58,8 +58,8 @@
int64_t decode_time_ms) {
Decoded(decodedImage,
decode_time_ms >= 0 ? rtc::Optional<int32_t>(decode_time_ms)
- : rtc::Optional<int32_t>(),
- rtc::Optional<uint8_t>());
+ : rtc::nullopt,
+ rtc::nullopt);
return WEBRTC_VIDEO_CODEC_OK;
}
@@ -85,8 +85,7 @@
const int64_t now_ms = _clock->TimeInMilliseconds();
if (!decode_time_ms) {
- decode_time_ms =
- rtc::Optional<int32_t>(now_ms - frameInfo->decodeStartTimeMs);
+ decode_time_ms = now_ms - frameInfo->decodeStartTimeMs;
}
_timing->StopDecodeTimer(decodedImage.timestamp(), *decode_time_ms, now_ms,
frameInfo->renderTimeMs);
diff --git a/modules/video_coding/packet_buffer.cc b/modules/video_coding/packet_buffer.cc
index bf83083..9b3d93e 100644
--- a/modules/video_coding/packet_buffer.cc
+++ b/modules/video_coding/packet_buffer.cc
@@ -116,9 +116,9 @@
UpdateMissingPackets(packet->seqNum);
int64_t now_ms = clock_->TimeInMilliseconds();
- last_received_packet_ms_ = rtc::Optional<int64_t>(now_ms);
+ last_received_packet_ms_ = now_ms;
if (packet->frameType == kVideoFrameKey)
- last_received_keyframe_packet_ms_ = rtc::Optional<int64_t>(now_ms);
+ last_received_keyframe_packet_ms_ = now_ms;
found_frames = FindFrames(seq_num);
}
@@ -458,7 +458,7 @@
void PacketBuffer::UpdateMissingPackets(uint16_t seq_num) {
if (!newest_inserted_seq_num_)
- newest_inserted_seq_num_ = rtc::Optional<uint16_t>(seq_num);
+ newest_inserted_seq_num_ = seq_num;
const int kMaxPaddingAge = 1000;
if (AheadOf(seq_num, *newest_inserted_seq_num_)) {
diff --git a/modules/video_coding/utility/moving_average.cc b/modules/video_coding/utility/moving_average.cc
index d72c465..8076f93 100644
--- a/modules/video_coding/utility/moving_average.cc
+++ b/modules/video_coding/utility/moving_average.cc
@@ -28,9 +28,9 @@
rtc::Optional<int> MovingAverage::GetAverage(size_t num_samples) const {
if (num_samples > size() || num_samples == 0)
- return rtc::Optional<int>();
+ return rtc::nullopt;
int sum = sum_ - sum_history_[(count_ - num_samples) % sum_history_.size()];
- return rtc::Optional<int>(sum / static_cast<int>(num_samples));
+ return sum / static_cast<int>(num_samples);
}
void MovingAverage::Reset() {