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 <cstdlib> | |
16 | |
17 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" | 15 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" |
18 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 16 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
19 | 17 |
20 namespace webrtc { | 18 namespace webrtc { |
21 | 19 |
22 const int64_t kStatisticsTimeoutMs = 8000; | 20 const int64_t kStatisticsTimeoutMs = 8000; |
23 const int64_t kStatisticsProcessIntervalMs = 1000; | 21 const int64_t kStatisticsProcessIntervalMs = 1000; |
24 | 22 |
25 StreamStatistician::~StreamStatistician() {} | 23 StreamStatistician::~StreamStatistician() {} |
26 | 24 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 106 |
109 void StreamStatisticianImpl::UpdateJitter(const RTPHeader& header, | 107 void StreamStatisticianImpl::UpdateJitter(const RTPHeader& header, |
110 NtpTime receive_time) { | 108 NtpTime receive_time) { |
111 uint32_t receive_time_rtp = | 109 uint32_t receive_time_rtp = |
112 NtpToRtp(receive_time, header.payload_type_frequency); | 110 NtpToRtp(receive_time, header.payload_type_frequency); |
113 uint32_t last_receive_time_rtp = | 111 uint32_t last_receive_time_rtp = |
114 NtpToRtp(last_receive_time_ntp_, header.payload_type_frequency); | 112 NtpToRtp(last_receive_time_ntp_, header.payload_type_frequency); |
115 int32_t time_diff_samples = (receive_time_rtp - last_receive_time_rtp) - | 113 int32_t time_diff_samples = (receive_time_rtp - last_receive_time_rtp) - |
116 (header.timestamp - last_received_timestamp_); | 114 (header.timestamp - last_received_timestamp_); |
117 | 115 |
118 time_diff_samples = std::abs(time_diff_samples); | 116 time_diff_samples = abs(time_diff_samples); |
119 | 117 |
120 // lib_jingle sometimes deliver crazy jumps in TS for the same stream. | 118 // lib_jingle sometimes deliver crazy jumps in TS for the same stream. |
121 // If this happens, don't update jitter value. Use 5 secs video frequency | 119 // If this happens, don't update jitter value. Use 5 secs video frequency |
122 // as the threshold. | 120 // as the threshold. |
123 if (time_diff_samples < 450000) { | 121 if (time_diff_samples < 450000) { |
124 // Note we calculate in Q4 to avoid using float. | 122 // Note we calculate in Q4 to avoid using float. |
125 int32_t jitter_diff_q4 = (time_diff_samples << 4) - jitter_q4_; | 123 int32_t jitter_diff_q4 = (time_diff_samples << 4) - jitter_q4_; |
126 jitter_q4_ += ((jitter_diff_q4 + 8) >> 4); | 124 jitter_q4_ += ((jitter_diff_q4 + 8) >> 4); |
127 } | 125 } |
128 | 126 |
129 // Extended jitter report, RFC 5450. | 127 // Extended jitter report, RFC 5450. |
130 // Actual network jitter, excluding the source-introduced jitter. | 128 // Actual network jitter, excluding the source-introduced jitter. |
131 int32_t time_diff_samples_ext = | 129 int32_t time_diff_samples_ext = |
132 (receive_time_rtp - last_receive_time_rtp) - | 130 (receive_time_rtp - last_receive_time_rtp) - |
133 ((header.timestamp + | 131 ((header.timestamp + |
134 header.extension.transmissionTimeOffset) - | 132 header.extension.transmissionTimeOffset) - |
135 (last_received_timestamp_ + | 133 (last_received_timestamp_ + |
136 last_received_transmission_time_offset_)); | 134 last_received_transmission_time_offset_)); |
137 | 135 |
138 time_diff_samples_ext = std::abs(time_diff_samples_ext); | 136 time_diff_samples_ext = abs(time_diff_samples_ext); |
139 | 137 |
140 if (time_diff_samples_ext < 450000) { | 138 if (time_diff_samples_ext < 450000) { |
141 int32_t jitter_diffQ4TransmissionTimeOffset = | 139 int32_t jitter_diffQ4TransmissionTimeOffset = |
142 (time_diff_samples_ext << 4) - jitter_q4_transmission_time_offset_; | 140 (time_diff_samples_ext << 4) - jitter_q4_transmission_time_offset_; |
143 jitter_q4_transmission_time_offset_ += | 141 jitter_q4_transmission_time_offset_ += |
144 ((jitter_diffQ4TransmissionTimeOffset + 8) >> 4); | 142 ((jitter_diffQ4TransmissionTimeOffset + 8) >> 4); |
145 } | 143 } |
146 } | 144 } |
147 | 145 |
148 void StreamStatisticianImpl::NotifyRtpCallback() { | 146 void StreamStatisticianImpl::NotifyRtpCallback() { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 527 |
530 void NullReceiveStatistics::Process() {} | 528 void NullReceiveStatistics::Process() {} |
531 | 529 |
532 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( | 530 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( |
533 RtcpStatisticsCallback* callback) {} | 531 RtcpStatisticsCallback* callback) {} |
534 | 532 |
535 void NullReceiveStatistics::RegisterRtpStatisticsCallback( | 533 void NullReceiveStatistics::RegisterRtpStatisticsCallback( |
536 StreamDataCountersCallback* callback) {} | 534 StreamDataCountersCallback* callback) {} |
537 | 535 |
538 } // namespace webrtc | 536 } // namespace webrtc |
OLD | NEW |