OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h" | 11 #include "webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 | 14 |
15 #include "webrtc/base/scoped_ptr.h" | 15 #include "webrtc/base/scoped_ptr.h" |
16 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" | 16 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" |
17 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 17 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 const int64_t kStatisticsTimeoutMs = 8000; | 22 const int64_t kStatisticsTimeoutMs = 8000; |
23 const int64_t kStatisticsProcessIntervalMs = 1000; | 23 const int64_t kStatisticsProcessIntervalMs = 1000; |
24 | 24 |
25 StreamStatistician::~StreamStatistician() {} | 25 StreamStatistician::~StreamStatistician() {} |
26 | 26 |
27 StreamStatisticianImpl::StreamStatisticianImpl( | 27 StreamStatisticianImpl::StreamStatisticianImpl( |
28 Clock* clock, | 28 Clock* clock, |
29 RtcpStatisticsCallback* rtcp_callback, | 29 RtcpStatisticsCallback* rtcp_callback, |
30 StreamDataCountersCallback* rtp_callback) | 30 StreamDataCountersCallback* rtp_callback) |
31 : clock_(clock), | 31 : clock_(clock), |
32 stream_lock_(CriticalSectionWrapper::CreateCriticalSection()), | 32 stream_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
33 incoming_bitrate_(clock, NULL), | 33 incoming_bitrate_(clock, NULL), |
34 ssrc_(0), | 34 ssrc_(0), |
35 max_reordering_threshold_(kDefaultMaxReorderingThreshold), | 35 max_reordering_threshold_(kDefaultMaxReorderingThreshold), |
36 jitter_q4_(0), | 36 jitter_q4_(0), |
37 cumulative_loss_(0), | 37 cumulative_loss_(0), |
38 jitter_q4_transmission_time_offset_(0), | 38 jitter_q4_transmission_time_offset_(0), |
39 last_receive_time_ms_(0), | 39 last_receive_time_ms_(0), |
40 last_receive_time_secs_(0), | |
41 last_receive_time_frac_(0), | |
42 last_received_timestamp_(0), | 40 last_received_timestamp_(0), |
43 last_received_transmission_time_offset_(0), | 41 last_received_transmission_time_offset_(0), |
44 received_seq_first_(0), | 42 received_seq_first_(0), |
45 received_seq_max_(0), | 43 received_seq_max_(0), |
46 received_seq_wraps_(0), | 44 received_seq_wraps_(0), |
47 received_packet_overhead_(12), | 45 received_packet_overhead_(12), |
48 last_report_inorder_packets_(0), | 46 last_report_inorder_packets_(0), |
49 last_report_old_packets_(0), | 47 last_report_old_packets_(0), |
50 last_report_seq_max_(0), | 48 last_report_seq_max_(0), |
51 rtcp_callback_(rtcp_callback), | 49 rtcp_callback_(rtcp_callback), |
(...skipping 20 matching lines...) Expand all Loading... | |
72 | 70 |
73 if (receive_counters_.transmitted.packets == 1) { | 71 if (receive_counters_.transmitted.packets == 1) { |
74 received_seq_first_ = header.sequenceNumber; | 72 received_seq_first_ = header.sequenceNumber; |
75 receive_counters_.first_packet_time_ms = clock_->TimeInMilliseconds(); | 73 receive_counters_.first_packet_time_ms = clock_->TimeInMilliseconds(); |
76 } | 74 } |
77 | 75 |
78 // Count only the new packets received. That is, if packets 1, 2, 3, 5, 4, 6 | 76 // Count only the new packets received. That is, if packets 1, 2, 3, 5, 4, 6 |
79 // are received, 4 will be ignored. | 77 // are received, 4 will be ignored. |
80 if (in_order) { | 78 if (in_order) { |
81 // Current time in samples. | 79 // Current time in samples. |
82 uint32_t receive_time_secs; | 80 NtpTime receive_time(*clock_); |
83 uint32_t receive_time_frac; | |
84 clock_->CurrentNtp(receive_time_secs, receive_time_frac); | |
85 | 81 |
86 // Wrong if we use RetransmitOfOldPacket. | 82 // Wrong if we use RetransmitOfOldPacket. |
87 if (receive_counters_.transmitted.packets > 1 && | 83 if (receive_counters_.transmitted.packets > 1 && |
88 received_seq_max_ > header.sequenceNumber) { | 84 received_seq_max_ > header.sequenceNumber) { |
89 // Wrap around detected. | 85 // Wrap around detected. |
90 received_seq_wraps_++; | 86 received_seq_wraps_++; |
91 } | 87 } |
92 // New max. | 88 // New max. |
93 received_seq_max_ = header.sequenceNumber; | 89 received_seq_max_ = header.sequenceNumber; |
94 | 90 |
95 // If new time stamp and more than one in-order packet received, calculate | 91 // If new time stamp and more than one in-order packet received, calculate |
96 // new jitter statistics. | 92 // new jitter statistics. |
97 if (header.timestamp != last_received_timestamp_ && | 93 if (header.timestamp != last_received_timestamp_ && |
98 (receive_counters_.transmitted.packets - | 94 (receive_counters_.transmitted.packets - |
99 receive_counters_.retransmitted.packets) > 1) { | 95 receive_counters_.retransmitted.packets) > 1) { |
100 UpdateJitter(header, receive_time_secs, receive_time_frac); | 96 UpdateJitter(header, receive_time); |
101 } | 97 } |
102 last_received_timestamp_ = header.timestamp; | 98 last_received_timestamp_ = header.timestamp; |
103 last_receive_time_secs_ = receive_time_secs; | 99 last_receive_time_ntp_ = receive_time; |
104 last_receive_time_frac_ = receive_time_frac; | |
105 last_receive_time_ms_ = clock_->TimeInMilliseconds(); | 100 last_receive_time_ms_ = clock_->TimeInMilliseconds(); |
106 } | 101 } |
107 | 102 |
108 size_t packet_oh = header.headerLength + header.paddingLength; | 103 size_t packet_oh = header.headerLength + header.paddingLength; |
109 | 104 |
110 // Our measured overhead. Filter from RFC 5104 4.2.1.2: | 105 // Our measured overhead. Filter from RFC 5104 4.2.1.2: |
111 // avg_OH (new) = 15/16*avg_OH (old) + 1/16*pckt_OH, | 106 // avg_OH (new) = 15/16*avg_OH (old) + 1/16*pckt_OH, |
112 received_packet_overhead_ = (15 * received_packet_overhead_ + packet_oh) >> 4; | 107 received_packet_overhead_ = (15 * received_packet_overhead_ + packet_oh) >> 4; |
113 } | 108 } |
114 | 109 |
115 void StreamStatisticianImpl::UpdateJitter(const RTPHeader& header, | 110 void StreamStatisticianImpl::UpdateJitter(const RTPHeader& header, |
116 uint32_t receive_time_secs, | 111 NtpTime receive_time) { |
åsapersson
2015/12/21 11:19:17
use const ref for receive_time?
danilchap
2015/12/21 12:49:50
NtpTime is a trivial type (basically it is an int6
| |
117 uint32_t receive_time_frac) { | 112 uint32_t receive_time_rtp = |
118 uint32_t receive_time_rtp = RtpUtility::ConvertNTPTimeToRTP( | 113 NtpToRtp(receive_time, header.payload_type_frequency); |
119 receive_time_secs, receive_time_frac, header.payload_type_frequency); | |
120 uint32_t last_receive_time_rtp = | 114 uint32_t last_receive_time_rtp = |
121 RtpUtility::ConvertNTPTimeToRTP(last_receive_time_secs_, | 115 NtpToRtp(last_receive_time_ntp_, header.payload_type_frequency); |
122 last_receive_time_frac_, | |
123 header.payload_type_frequency); | |
124 int32_t time_diff_samples = (receive_time_rtp - last_receive_time_rtp) - | 116 int32_t time_diff_samples = (receive_time_rtp - last_receive_time_rtp) - |
125 (header.timestamp - last_received_timestamp_); | 117 (header.timestamp - last_received_timestamp_); |
126 | 118 |
127 time_diff_samples = abs(time_diff_samples); | 119 time_diff_samples = abs(time_diff_samples); |
128 | 120 |
129 // lib_jingle sometimes deliver crazy jumps in TS for the same stream. | 121 // lib_jingle sometimes deliver crazy jumps in TS for the same stream. |
130 // If this happens, don't update jitter value. Use 5 secs video frequency | 122 // If this happens, don't update jitter value. Use 5 secs video frequency |
131 // as the threshold. | 123 // as the threshold. |
132 if (time_diff_samples < 450000) { | 124 if (time_diff_samples < 450000) { |
133 // Note we calculate in Q4 to avoid using float. | 125 // Note we calculate in Q4 to avoid using float. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 } | 304 } |
313 | 305 |
314 void StreamStatisticianImpl::ProcessBitrate() { | 306 void StreamStatisticianImpl::ProcessBitrate() { |
315 CriticalSectionScoped cs(stream_lock_.get()); | 307 CriticalSectionScoped cs(stream_lock_.get()); |
316 incoming_bitrate_.Process(); | 308 incoming_bitrate_.Process(); |
317 } | 309 } |
318 | 310 |
319 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs, | 311 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs, |
320 uint32_t* frac) const { | 312 uint32_t* frac) const { |
321 CriticalSectionScoped cs(stream_lock_.get()); | 313 CriticalSectionScoped cs(stream_lock_.get()); |
322 *secs = last_receive_time_secs_; | 314 *secs = last_receive_time_ntp_.seconds(); |
323 *frac = last_receive_time_frac_; | 315 *frac = last_receive_time_ntp_.fractions(); |
324 } | 316 } |
325 | 317 |
326 bool StreamStatisticianImpl::IsRetransmitOfOldPacket( | 318 bool StreamStatisticianImpl::IsRetransmitOfOldPacket( |
327 const RTPHeader& header, int64_t min_rtt) const { | 319 const RTPHeader& header, int64_t min_rtt) const { |
328 CriticalSectionScoped cs(stream_lock_.get()); | 320 CriticalSectionScoped cs(stream_lock_.get()); |
329 if (InOrderPacketInternal(header.sequenceNumber)) { | 321 if (InOrderPacketInternal(header.sequenceNumber)) { |
330 return false; | 322 return false; |
331 } | 323 } |
332 uint32_t frequency_khz = header.payload_type_frequency / 1000; | 324 uint32_t frequency_khz = header.payload_type_frequency / 1000; |
333 assert(frequency_khz > 0); | 325 assert(frequency_khz > 0); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 | 531 |
540 int32_t NullReceiveStatistics::Process() { return 0; } | 532 int32_t NullReceiveStatistics::Process() { return 0; } |
541 | 533 |
542 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( | 534 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( |
543 RtcpStatisticsCallback* callback) {} | 535 RtcpStatisticsCallback* callback) {} |
544 | 536 |
545 void NullReceiveStatistics::RegisterRtpStatisticsCallback( | 537 void NullReceiveStatistics::RegisterRtpStatisticsCallback( |
546 StreamDataCountersCallback* callback) {} | 538 StreamDataCountersCallback* callback) {} |
547 | 539 |
548 } // namespace webrtc | 540 } // namespace webrtc |
OLD | NEW |