OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/modules/rtp_rtcp/source/report_block_information.h" |
| 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/trace_event.h" |
| 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| 18 |
| 19 namespace webrtc { |
| 20 namespace rtcp { |
| 21 |
| 22 ReportBlockInformation::ReportBlockInformation() |
| 23 : number_rtt_(0), last_rtt_(0), min_rtt_(0), max_rtt_(0), sum_rtt_(0) { |
| 24 memset(&last_received_block_, 0, sizeof(last_received_block_)); |
| 25 } |
| 26 |
| 27 void ReportBlockInformation::AddBlock(const rtcp::ReportBlock& block, |
| 28 uint32_t remote_ssrc, |
| 29 NtpTime now) { |
| 30 last_received_block_.remoteSSRC = remote_ssrc; |
| 31 last_received_block_.sourceSSRC = block.source_ssrc(); |
| 32 last_received_block_.fractionLost = block.fraction_lost(); |
| 33 last_received_block_.cumulativeLost = block.cumulative_lost(); |
| 34 last_received_block_.extendedHighSeqNum = block.extended_high_seq_num(); |
| 35 last_received_block_.jitter = block.jitter(); |
| 36 last_received_block_.lastSR = block.last_sr(); |
| 37 last_received_block_.delaySinceLastSR = block.delay_since_last_sr(); |
| 38 |
| 39 AddRtt(now); |
| 40 } |
| 41 |
| 42 void ReportBlockInformation::AddBlock( |
| 43 const RTCPUtility::RTCPPacketReportBlockItem& block, |
| 44 uint32_t remote_ssrc, |
| 45 NtpTime now) { |
| 46 last_received_block_.remoteSSRC = remote_ssrc; |
| 47 last_received_block_.sourceSSRC = block.SSRC; |
| 48 last_received_block_.fractionLost = block.FractionLost; |
| 49 last_received_block_.cumulativeLost = block.CumulativeNumOfPacketsLost; |
| 50 last_received_block_.extendedHighSeqNum = block.ExtendedHighestSequenceNumber; |
| 51 last_received_block_.jitter = block.Jitter; |
| 52 last_received_block_.lastSR = block.LastSR; |
| 53 last_received_block_.delaySinceLastSR = block.DelayLastSR; |
| 54 |
| 55 AddRtt(now); |
| 56 } |
| 57 |
| 58 const RTCPReportBlock& ReportBlockInformation::LastBlock() const { |
| 59 return last_received_block_; |
| 60 } |
| 61 |
| 62 bool ReportBlockInformation::HasRtt() const { |
| 63 return number_rtt_ > 0; |
| 64 } |
| 65 |
| 66 int64_t ReportBlockInformation::LastRttMs() const { |
| 67 return CompactNtpIntervalToMs(last_rtt_); |
| 68 } |
| 69 int64_t ReportBlockInformation::MinRttMs() const { |
| 70 return CompactNtpIntervalToMs(min_rtt_); |
| 71 } |
| 72 int64_t ReportBlockInformation::MaxRttMs() const { |
| 73 return CompactNtpIntervalToMs(max_rtt_); |
| 74 } |
| 75 int64_t ReportBlockInformation::AvgRttMs() const { |
| 76 RTC_DCHECK_NE(number_rtt_, 0u); |
| 77 return CompactNtpIntervalToMs(sum_rtt_ / number_rtt_); |
| 78 } |
| 79 |
| 80 void ReportBlockInformation::AddRtt(NtpTime now) { |
| 81 uint32_t send_time = last_received_block_.lastSR; |
| 82 int64_t rtt_ms = 0; |
| 83 if (send_time > 0) { |
| 84 uint32_t receive_time = CompactNtp(now); |
| 85 uint32_t delay = last_received_block_.delaySinceLastSR; |
| 86 |
| 87 // RTT in 1/(2^16) seconds. |
| 88 uint32_t rtt_ntp = receive_time - delay - send_time; |
| 89 |
| 90 last_rtt_ = rtt_ntp; |
| 91 if (number_rtt_ == 0) { |
| 92 min_rtt_ = rtt_ntp; |
| 93 max_rtt_ = rtt_ntp; |
| 94 } else { |
| 95 if (min_rtt_ > rtt_ntp) |
| 96 min_rtt_ = rtt_ntp; |
| 97 if (max_rtt_ < rtt_ntp) |
| 98 max_rtt_ = rtt_ntp; |
| 99 } |
| 100 sum_rtt_ += rtt_ntp; |
| 101 ++number_rtt_; |
| 102 rtt_ms = CompactNtpIntervalToMs(last_rtt_); |
| 103 } |
| 104 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", |
| 105 last_received_block_.sourceSSRC, rtt_ms); |
| 106 } |
| 107 } // namespace rtcp |
| 108 } // namespace webrtc |
OLD | NEW |