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}
This commit is contained in:
Tim Na
2020-12-11 13:31:55 -08:00
committed by Commit Bot
parent c70bd1837d
commit 2412602b68
3 changed files with 16 additions and 10 deletions

View File

@ -78,6 +78,7 @@ rtc_library("audio_ingress") {
"../../rtc_base/synchronization:mutex", "../../rtc_base/synchronization:mutex",
"../utility:audio_frame_operations", "../utility:audio_frame_operations",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
} }
rtc_library("audio_egress") { rtc_library("audio_egress") {

View File

@ -184,8 +184,8 @@ void AudioIngress::ReceivedRTCPPacket(
// Deliver RTCP packet to RTP/RTCP module for parsing. // Deliver RTCP packet to RTP/RTCP module for parsing.
rtp_rtcp_->IncomingRtcpPacket(rtcp_packet.data(), rtcp_packet.size()); rtp_rtcp_->IncomingRtcpPacket(rtcp_packet.data(), rtcp_packet.size());
int64_t rtt = GetRoundTripTime(); absl::optional<int64_t> rtt = GetRoundTripTime();
if (rtt == -1) { if (!rtt.has_value()) {
// Waiting for valid RTT. // Waiting for valid RTT.
return; return;
} }
@ -199,18 +199,18 @@ void AudioIngress::ReceivedRTCPPacket(
{ {
MutexLock lock(&lock_); 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 = const std::vector<ReportBlockData>& report_data =
rtp_rtcp_->GetLatestReportBlockData(); rtp_rtcp_->GetLatestReportBlockData();
// If we do not have report block which means remote RTCP hasn't be received // If we do not have report block which means remote RTCP hasn't be received
// yet, return -1 as to indicate uninitialized value. // yet, return -1 as to indicate uninitialized value.
if (report_data.empty()) { 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 // 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); 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 } // namespace webrtc

View File

@ -17,6 +17,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "absl/types/optional.h"
#include "api/array_view.h" #include "api/array_view.h"
#include "api/audio/audio_mixer.h" #include "api/audio/audio_mixer.h"
#include "api/rtp_headers.h" #include "api/rtp_headers.h"
@ -78,10 +79,6 @@ class AudioIngress : public AudioMixer::Source {
return output_audio_level_.TotalDuration(); 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 GetNetworkStatistics() const {
NetworkStatistics stats; NetworkStatistics stats;
acm_receiver_.GetNetworkStatistics(&stats, acm_receiver_.GetNetworkStatistics(&stats,
@ -105,6 +102,10 @@ class AudioIngress : public AudioMixer::Source {
} }
private: 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. // Indicates AudioIngress status as caller invokes Start/StopPlaying.
// If not playing, incoming RTP data processing is skipped, thus // If not playing, incoming RTP data processing is skipped, thus
// producing no data to output device. // producing no data to output device.