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(CompactNtp(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(CompactNtp(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 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.
| |
67 return CompactNtpIntervalToMs(last_rtt_); | |
68 } | |
69 uint32_t ReportBlockInformation::MinRttMs() const { | |
70 return CompactNtpIntervalToMs(min_rtt_); | |
71 } | |
72 uint32_t ReportBlockInformation::MaxRttMs() const { | |
73 return CompactNtpIntervalToMs(max_rtt_); | |
74 } | |
75 uint32_t ReportBlockInformation::AvgRttMs() const { | |
76 RTC_CHECK_GT(number_rtt_, 0u); | |
77 return CompactNtpIntervalToMs(sum_rtt_ / number_rtt_); | |
78 } | |
79 | |
80 void ReportBlockInformation::AddRtt(uint32_t receive_time) { | |
81 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.
| |
82 uint32_t rtt_ms = 0; | |
philipel
2016/03/03 14:00:59
int64_t
danilchap
2016/03/03 14:44:49
Done.
| |
83 if (send_time > 0) { | |
84 uint32_t delay = last_received_block_.delaySinceLastSR; | |
philipel
2016/03/03 14:00:59
int64_t
| |
85 | |
86 // RTT in 1/(2^16) seconds. | |
87 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
| |
88 | |
89 last_rtt_ = rtt_ntp; | |
90 if (number_rtt_ == 0) { | |
91 min_rtt_ = rtt_ntp; | |
92 max_rtt_ = rtt_ntp; | |
93 } else { | |
94 if (min_rtt_ > rtt_ntp) | |
95 min_rtt_ = rtt_ntp; | |
96 if (max_rtt_ < rtt_ntp) | |
97 max_rtt_ = rtt_ntp; | |
98 } | |
99 sum_rtt_ += rtt_ntp; | |
100 ++number_rtt_; | |
101 rtt_ms = CompactNtpIntervalToMs(last_rtt_); | |
102 } | |
103 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", | |
104 last_received_block_.sourceSSRC, rtt_ms); | |
105 } | |
106 } // namespace rtcp | |
107 } // namespace webrtc | |
OLD | NEW |