From 2412602b6801ae7495c7506fed47d573660c3545 Mon Sep 17 00:00:00 2001 From: Tim Na Date: Fri, 11 Dec 2020 13:31:55 -0800 Subject: [PATCH] Using absl::optional for round trip time return type handling. No-Try: True Bug: webrtc:11989 Change-Id: If2ed9b83468c03b82b372e64d8012e5786295476 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/197060 Commit-Queue: Mirko Bonadei Reviewed-by: Sam Zackrisson Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#32827} --- audio/voip/BUILD.gn | 1 + audio/voip/audio_ingress.cc | 16 ++++++++++------ audio/voip/audio_ingress.h | 9 +++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/audio/voip/BUILD.gn b/audio/voip/BUILD.gn index f4b6142a74..dd5267f55a 100644 --- a/audio/voip/BUILD.gn +++ b/audio/voip/BUILD.gn @@ -78,6 +78,7 @@ rtc_library("audio_ingress") { "../../rtc_base/synchronization:mutex", "../utility:audio_frame_operations", ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("audio_egress") { diff --git a/audio/voip/audio_ingress.cc b/audio/voip/audio_ingress.cc index 07def99559..3be471824d 100644 --- a/audio/voip/audio_ingress.cc +++ b/audio/voip/audio_ingress.cc @@ -184,8 +184,8 @@ void AudioIngress::ReceivedRTCPPacket( // Deliver RTCP packet to RTP/RTCP module for parsing. rtp_rtcp_->IncomingRtcpPacket(rtcp_packet.data(), rtcp_packet.size()); - int64_t rtt = GetRoundTripTime(); - if (rtt == -1) { + absl::optional rtt = GetRoundTripTime(); + if (!rtt.has_value()) { // Waiting for valid RTT. return; } @@ -199,18 +199,18 @@ void AudioIngress::ReceivedRTCPPacket( { MutexLock lock(&lock_); - ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); + ntp_estimator_.UpdateRtcpTimestamp(*rtt, ntp_secs, ntp_frac, rtp_timestamp); } } -int64_t AudioIngress::GetRoundTripTime() { +absl::optional AudioIngress::GetRoundTripTime() { const std::vector& report_data = rtp_rtcp_->GetLatestReportBlockData(); // If we do not have report block which means remote RTCP hasn't be received // yet, return -1 as to indicate uninitialized value. if (report_data.empty()) { - return -1; + return absl::nullopt; } // We don't know in advance the remote SSRC used by the other end's receiver @@ -226,7 +226,11 @@ int64_t AudioIngress::GetRoundTripTime() { rtp_rtcp_->SetRemoteSSRC(sender_ssrc); } - return (block_data.has_rtt() ? block_data.last_rtt_ms() : -1); + if (!block_data.has_rtt()) { + return absl::nullopt; + } + + return block_data.last_rtt_ms(); } } // namespace webrtc diff --git a/audio/voip/audio_ingress.h b/audio/voip/audio_ingress.h index d3680e0f00..663b59bc67 100644 --- a/audio/voip/audio_ingress.h +++ b/audio/voip/audio_ingress.h @@ -17,6 +17,7 @@ #include #include +#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/audio_mixer.h" #include "api/rtp_headers.h" @@ -78,10 +79,6 @@ class AudioIngress : public AudioMixer::Source { return output_audio_level_.TotalDuration(); } - // Returns network round trip time (RTT) measued by RTCP exchange with - // remote media endpoint. RTT value -1 indicates that it's not initialized. - int64_t GetRoundTripTime(); - NetworkStatistics GetNetworkStatistics() const { NetworkStatistics stats; acm_receiver_.GetNetworkStatistics(&stats, @@ -105,6 +102,10 @@ class AudioIngress : public AudioMixer::Source { } private: + // Returns network round trip time (RTT) measued by RTCP exchange with + // remote media endpoint. Returns absl::nullopt when it's not initialized. + absl::optional GetRoundTripTime(); + // Indicates AudioIngress status as caller invokes Start/StopPlaying. // If not playing, incoming RTP data processing is skipped, thus // producing no data to output device.