| Index: webrtc/modules/rtp_rtcp/source/report_block_information.cc
|
| diff --git a/webrtc/modules/rtp_rtcp/source/report_block_information.cc b/webrtc/modules/rtp_rtcp/source/report_block_information.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5c9fc987618a326eaa1b1b5c2fd639a132175f74
|
| --- /dev/null
|
| +++ b/webrtc/modules/rtp_rtcp/source/report_block_information.cc
|
| @@ -0,0 +1,108 @@
|
| +/*
|
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| + */
|
| +
|
| +#include "webrtc/modules/rtp_rtcp/source/report_block_information.h"
|
| +
|
| +#include "webrtc/base/checks.h"
|
| +#include "webrtc/base/trace_event.h"
|
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h"
|
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
|
| +#include "webrtc/modules/rtp_rtcp/source/time_util.h"
|
| +
|
| +namespace webrtc {
|
| +namespace rtcp {
|
| +
|
| +ReportBlockInformation::ReportBlockInformation()
|
| + : number_rtt_(0), last_rtt_(0), min_rtt_(0), max_rtt_(0), sum_rtt_(0) {
|
| + memset(&last_received_block_, 0, sizeof(last_received_block_));
|
| +}
|
| +
|
| +void ReportBlockInformation::AddBlock(const rtcp::ReportBlock& block,
|
| + uint32_t remote_ssrc,
|
| + NtpTime now) {
|
| + last_received_block_.remoteSSRC = remote_ssrc;
|
| + last_received_block_.sourceSSRC = block.source_ssrc();
|
| + last_received_block_.fractionLost = block.fraction_lost();
|
| + last_received_block_.cumulativeLost = block.cumulative_lost();
|
| + last_received_block_.extendedHighSeqNum = block.extended_high_seq_num();
|
| + last_received_block_.jitter = block.jitter();
|
| + last_received_block_.lastSR = block.last_sr();
|
| + last_received_block_.delaySinceLastSR = block.delay_since_last_sr();
|
| +
|
| + AddRtt(now);
|
| +}
|
| +
|
| +void ReportBlockInformation::AddBlock(
|
| + const RTCPUtility::RTCPPacketReportBlockItem& block,
|
| + uint32_t remote_ssrc,
|
| + NtpTime now) {
|
| + last_received_block_.remoteSSRC = remote_ssrc;
|
| + last_received_block_.sourceSSRC = block.SSRC;
|
| + last_received_block_.fractionLost = block.FractionLost;
|
| + last_received_block_.cumulativeLost = block.CumulativeNumOfPacketsLost;
|
| + last_received_block_.extendedHighSeqNum = block.ExtendedHighestSequenceNumber;
|
| + last_received_block_.jitter = block.Jitter;
|
| + last_received_block_.lastSR = block.LastSR;
|
| + last_received_block_.delaySinceLastSR = block.DelayLastSR;
|
| +
|
| + AddRtt(now);
|
| +}
|
| +
|
| +const RTCPReportBlock& ReportBlockInformation::LastBlock() const {
|
| + return last_received_block_;
|
| +}
|
| +
|
| +bool ReportBlockInformation::HasRtt() const {
|
| + return number_rtt_ > 0;
|
| +}
|
| +
|
| +int64_t ReportBlockInformation::LastRttMs() const {
|
| + return CompactNtpIntervalToMs(last_rtt_);
|
| +}
|
| +int64_t ReportBlockInformation::MinRttMs() const {
|
| + return CompactNtpIntervalToMs(min_rtt_);
|
| +}
|
| +int64_t ReportBlockInformation::MaxRttMs() const {
|
| + return CompactNtpIntervalToMs(max_rtt_);
|
| +}
|
| +int64_t ReportBlockInformation::AvgRttMs() const {
|
| + RTC_DCHECK_NE(number_rtt_, 0u);
|
| + return CompactNtpIntervalToMs(sum_rtt_ / number_rtt_);
|
| +}
|
| +
|
| +void ReportBlockInformation::AddRtt(NtpTime now) {
|
| + uint32_t send_time = last_received_block_.lastSR;
|
| + int64_t rtt_ms = 0;
|
| + if (send_time > 0) {
|
| + uint32_t receive_time = CompactNtp(now);
|
| + uint32_t delay = last_received_block_.delaySinceLastSR;
|
| +
|
| + // RTT in 1/(2^16) seconds.
|
| + uint32_t rtt_ntp = receive_time - delay - send_time;
|
| +
|
| + last_rtt_ = rtt_ntp;
|
| + if (number_rtt_ == 0) {
|
| + min_rtt_ = rtt_ntp;
|
| + max_rtt_ = rtt_ntp;
|
| + } else {
|
| + if (min_rtt_ > rtt_ntp)
|
| + min_rtt_ = rtt_ntp;
|
| + if (max_rtt_ < rtt_ntp)
|
| + max_rtt_ = rtt_ntp;
|
| + }
|
| + sum_rtt_ += rtt_ntp;
|
| + ++number_rtt_;
|
| + rtt_ms = CompactNtpIntervalToMs(last_rtt_);
|
| + }
|
| + TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT",
|
| + last_received_block_.sourceSSRC, rtt_ms);
|
| +}
|
| +} // namespace rtcp
|
| +} // namespace webrtc
|
|
|