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/audio_coding/neteq/statistics_calculator.h" | 11 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <string.h> // memset | 14 #include <string.h> // memset |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/safe_conversions.h" | 18 #include "webrtc/base/safe_conversions.h" |
19 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" | 19 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" |
20 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" | 20 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" |
21 #include "webrtc/system_wrappers/include/metrics.h" | 21 #include "webrtc/system_wrappers/include/metrics.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 namespace { | |
26 size_t AddIntToSizeTWithLowerCap(int a, size_t b) { | |
27 if (a < 0 && static_cast<size_t>(-a) > b) { | |
kwiberg-webrtc
2017/05/04 19:55:04
if (safe_cmp::Gt(-a, b)) {
Both your and my versi
minyue-webrtc
2017/05/05 07:14:00
how about
size_t ret = b + a; // you may cast a i
hlundin-webrtc
2017/05/05 07:42:14
Is it conceivable that abs(int_min) is larger than
kwiberg-webrtc
2017/05/05 08:34:29
AFAICT, the standard just says that "The type size
hlundin-webrtc
2017/05/05 11:40:09
Changed to Minyue's version.
| |
28 // Simply doing a + b would give a negative result, with a negative wrap. | |
29 // Cap it to zero instead. | |
30 return 0; | |
31 } | |
32 return a + b; | |
kwiberg-webrtc
2017/05/04 19:55:04
I'm pretty sure a will be promoted to size_t befor
hlundin-webrtc
2017/05/05 07:42:15
Done.
| |
33 } | |
34 } | |
35 | |
25 // Allocating the static const so that it can be passed by reference to | 36 // Allocating the static const so that it can be passed by reference to |
26 // RTC_DCHECK. | 37 // RTC_DCHECK. |
27 const size_t StatisticsCalculator::kLenWaitingTimes; | 38 const size_t StatisticsCalculator::kLenWaitingTimes; |
28 | 39 |
29 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger( | 40 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger( |
30 const std::string& uma_name, | 41 const std::string& uma_name, |
31 int report_interval_ms, | 42 int report_interval_ms, |
32 int max_value) | 43 int max_value) |
33 : uma_name_(uma_name), | 44 : uma_name_(uma_name), |
34 report_interval_ms_(report_interval_ms), | 45 report_interval_ms_(report_interval_ms), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 } | 152 } |
142 | 153 |
143 void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples) { | 154 void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples) { |
144 expanded_speech_samples_ += num_samples; | 155 expanded_speech_samples_ += num_samples; |
145 } | 156 } |
146 | 157 |
147 void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) { | 158 void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) { |
148 expanded_noise_samples_ += num_samples; | 159 expanded_noise_samples_ += num_samples; |
149 } | 160 } |
150 | 161 |
162 void StatisticsCalculator::ExpandedVoiceSamplesCorrection(int num_samples) { | |
163 expanded_speech_samples_ = | |
164 AddIntToSizeTWithLowerCap(num_samples, expanded_speech_samples_); | |
165 } | |
166 | |
167 void StatisticsCalculator::ExpandedNoiseSamplesCorrection(int num_samples) { | |
168 expanded_noise_samples_ = | |
169 AddIntToSizeTWithLowerCap(num_samples, expanded_noise_samples_); | |
170 } | |
171 | |
151 void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) { | 172 void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) { |
152 preemptive_samples_ += num_samples; | 173 preemptive_samples_ += num_samples; |
153 } | 174 } |
154 | 175 |
155 void StatisticsCalculator::AcceleratedSamples(size_t num_samples) { | 176 void StatisticsCalculator::AcceleratedSamples(size_t num_samples) { |
156 accelerate_samples_ += num_samples; | 177 accelerate_samples_ += num_samples; |
157 } | 178 } |
158 | 179 |
159 void StatisticsCalculator::AddZeros(size_t num_samples) { | 180 void StatisticsCalculator::AddZeros(size_t num_samples) { |
160 added_zero_samples_ += num_samples; | 181 added_zero_samples_ += num_samples; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Ratio must be smaller than 1 in Q14. | 309 // Ratio must be smaller than 1 in Q14. |
289 assert((numerator << 14) / denominator < (1 << 14)); | 310 assert((numerator << 14) / denominator < (1 << 14)); |
290 return static_cast<uint16_t>((numerator << 14) / denominator); | 311 return static_cast<uint16_t>((numerator << 14) / denominator); |
291 } else { | 312 } else { |
292 // Will not produce a ratio larger than 1, since this is probably an error. | 313 // Will not produce a ratio larger than 1, since this is probably an error. |
293 return 1 << 14; | 314 return 1 << 14; |
294 } | 315 } |
295 } | 316 } |
296 | 317 |
297 } // namespace webrtc | 318 } // namespace webrtc |
OLD | NEW |