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..495436dfce5c1d8856d9670e0a6869d493fcbfc6 |
| --- /dev/null |
| +++ b/webrtc/modules/rtp_rtcp/source/report_block_information.cc |
| @@ -0,0 +1,107 @@ |
| +/* |
| + * 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(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)); |
| +} |
| + |
| +const RTCPReportBlock& ReportBlockInformation::LastBlock() const { |
| + return last_received_block_; |
| +} |
| + |
| +bool ReportBlockInformation::HasRtt() const { |
| + return number_rtt_ > 0; |
| +} |
| + |
| +uint32_t ReportBlockInformation::LastRttMs() const { |
|
philipel
2016/03/03 14:00:59
Change to int64_t for Last, Min, Max and AvgRttMs.
danilchap
2016/03/03 14:44:49
Done.
|
| + 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); |
| + return CompactNtpIntervalToMs(sum_rtt_ / number_rtt_); |
| +} |
| + |
| +void ReportBlockInformation::AddRtt(uint32_t receive_time) { |
| + uint32_t send_time = last_received_block_.lastSR; |
|
philipel
2016/03/03 14:00:59
int64_t
danilchap
2016/03/03 14:44:49
No, see comment below.
|
| + uint32_t rtt_ms = 0; |
|
philipel
2016/03/03 14:00:59
int64_t
danilchap
2016/03/03 14:44:49
Done.
|
| + if (send_time > 0) { |
| + uint32_t delay = last_received_block_.delaySinceLastSR; |
|
philipel
2016/03/03 14:00:59
int64_t
|
| + |
| + // RTT in 1/(2^16) seconds. |
| + uint32_t rtt_ntp = receive_time - delay - send_time; |
|
philipel
2016/03/03 14:00:59
int64_t
danilchap
2016/03/03 14:44:49
using int64_t in this function may produce incorre
|
| + |
| + 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 |