OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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/audio_coding/neteq/rtcp.h" | 11 #include "webrtc/modules/audio_coding/neteq/rtcp.h" |
12 | 12 |
13 #include <stdlib.h> | |
13 #include <string.h> | 14 #include <string.h> |
14 | 15 |
15 #include <algorithm> | 16 #include <algorithm> |
16 | 17 |
17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | |
18 #include "webrtc/modules/include/module_common_types.h" | 18 #include "webrtc/modules/include/module_common_types.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 void Rtcp::Init(uint16_t start_sequence_number) { | 22 void Rtcp::Init(uint16_t start_sequence_number) { |
23 cycles_ = 0; | 23 cycles_ = 0; |
24 max_seq_no_ = start_sequence_number; | 24 max_seq_no_ = start_sequence_number; |
25 base_seq_no_ = start_sequence_number; | 25 base_seq_no_ = start_sequence_number; |
26 received_packets_ = 0; | 26 received_packets_ = 0; |
27 received_packets_prior_ = 0; | 27 received_packets_prior_ = 0; |
(...skipping 11 matching lines...) Expand all Loading... | |
39 // Wrap-around detected. | 39 // Wrap-around detected. |
40 cycles_++; | 40 cycles_++; |
41 } | 41 } |
42 max_seq_no_ = rtp_header.sequenceNumber; | 42 max_seq_no_ = rtp_header.sequenceNumber; |
43 } | 43 } |
44 | 44 |
45 // Calculate jitter according to RFC 3550, and update previous timestamps. | 45 // Calculate jitter according to RFC 3550, and update previous timestamps. |
46 // Note that the value in |jitter_| is in Q4. | 46 // Note that the value in |jitter_| is in Q4. |
47 if (received_packets_ > 1) { | 47 if (received_packets_ > 1) { |
48 int32_t ts_diff = receive_timestamp - (rtp_header.timestamp - transit_); | 48 int32_t ts_diff = receive_timestamp - (rtp_header.timestamp - transit_); |
49 ts_diff = WEBRTC_SPL_ABS_W32(ts_diff); | 49 int64_t jitter_diff = (std::abs(int64_t{ts_diff}) << 4) - jitter_; |
50 int32_t jitter_diff = (ts_diff << 4) - jitter_; | |
51 // Calculate 15 * jitter_ / 16 + jitter_diff / 16 (with proper rounding). | 50 // Calculate 15 * jitter_ / 16 + jitter_diff / 16 (with proper rounding). |
52 jitter_ = jitter_ + ((jitter_diff + 8) >> 4); | 51 jitter_ = jitter_ + ((jitter_diff + 8) >> 4); |
52 RTC_DCHECK_GE(jitter_, 0); | |
ossu
2016/10/31 14:53:48
This, really, should be impossible: jitter_diff sh
| |
53 } | 53 } |
54 transit_ = rtp_header.timestamp - receive_timestamp; | 54 transit_ = rtp_header.timestamp - receive_timestamp; |
55 } | 55 } |
56 | 56 |
57 void Rtcp::GetStatistics(bool no_reset, RtcpStatistics* stats) { | 57 void Rtcp::GetStatistics(bool no_reset, RtcpStatistics* stats) { |
58 // Extended highest sequence number received. | 58 // Extended highest sequence number received. |
59 stats->extended_max_sequence_number = | 59 stats->extended_max_sequence_number = |
60 (static_cast<int>(cycles_) << 16) + max_seq_no_; | 60 (static_cast<int>(cycles_) << 16) + max_seq_no_; |
61 | 61 |
62 // Calculate expected number of packets and compare it with the number of | 62 // Calculate expected number of packets and compare it with the number of |
(...skipping 24 matching lines...) Expand all Loading... | |
87 if (expected_since_last == 0 || lost <= 0 || received_packets_ == 0) { | 87 if (expected_since_last == 0 || lost <= 0 || received_packets_ == 0) { |
88 stats->fraction_lost = 0; | 88 stats->fraction_lost = 0; |
89 } else { | 89 } else { |
90 stats->fraction_lost = std::min(0xFFU, (lost << 8) / expected_since_last); | 90 stats->fraction_lost = std::min(0xFFU, (lost << 8) / expected_since_last); |
91 } | 91 } |
92 | 92 |
93 stats->jitter = jitter_ >> 4; // Scaling from Q4. | 93 stats->jitter = jitter_ >> 4; // Scaling from Q4. |
94 } | 94 } |
95 | 95 |
96 } // namespace webrtc | 96 } // namespace webrtc |
OLD | NEW |