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 <mbonadei@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32827}
diff --git a/audio/voip/BUILD.gn b/audio/voip/BUILD.gn
index f4b6142..dd5267f 100644
--- a/audio/voip/BUILD.gn
+++ b/audio/voip/BUILD.gn
@@ -78,6 +78,7 @@
"../../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 07def99..3be4718 100644
--- a/audio/voip/audio_ingress.cc
+++ b/audio/voip/audio_ingress.cc
@@ -184,8 +184,8 @@
// 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<int64_t> rtt = GetRoundTripTime();
+ if (!rtt.has_value()) {
// Waiting for valid RTT.
return;
}
@@ -199,18 +199,18 @@
{
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<int64_t> AudioIngress::GetRoundTripTime() {
const std::vector<ReportBlockData>& 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 @@
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 d3680e0..663b59b 100644
--- a/audio/voip/audio_ingress.h
+++ b/audio/voip/audio_ingress.h
@@ -17,6 +17,7 @@
#include <memory>
#include <utility>
+#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 @@
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 @@
}
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<int64_t> 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.