Chromium Code Reviews| 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..15bd3b3ad9c5ed2c3ea13231392fabe4ef134e9a |
| --- /dev/null |
| +++ b/webrtc/modules/rtp_rtcp/source/report_block_information.cc |
| @@ -0,0 +1,99 @@ |
| +/* |
| + * 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_)); |
| +} |
| + |
| +uint32_t ReportBlockInformation::LastRttMs() const { |
| + return CompactNtpIntervalToMs(last_rtt_); |
| +} |
| +uint32_t ReportBlockInformation::MinRttMs() const { |
| + return CompactNtpIntervalToMs(min_rtt_); |
| +} |
| +uint32_t ReportBlockInformation::MaxRttMs() const { |
| + return CompactNtpIntervalToMs(max_rtt_); |
| +} |
| +uint32_t ReportBlockInformation::AvgRttMs() const { |
| + RTC_CHECK_GT(number_rtt_, 0u); |
|
philipel
2016/02/29 13:21:47
Expected value first:
RTC_CHECK_GT(0u, number_rtt_
danilchap
2016/02/29 14:41:27
Disagree,
Code search shows that expected value la
philipel
2016/03/03 14:00:58
I think you are right. Shouldn't it be DCHECK inst
danilchap
2016/03/03 14:44:48
Done.
|
| + return CompactNtpIntervalToMs(sum_rtt_ / number_rtt_); |
| +} |
| + |
| +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(CompactNtp(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(CompactNtp(now)); |
| +} |
| + |
| +void ReportBlockInformation::AddRtt(uint32_t receive_time) { |
| + uint32_t send_time = last_received_block_.lastSR; |
| + uint32_t rtt_ms = 0; |
| + if (send_time > 0) { |
| + 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 |