Chromium Code Reviews| 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 const size_t ret = b + a; | |
| 28 // If a + b is negative, resulting in a negative wrap, cap it to zero instead. | |
| 29 static_assert(sizeof(size_t) >= sizeof(int), | |
| 30 "int must not be wider than size_t for this to work"); | |
|
kwiberg-webrtc
2017/05/05 11:43:52
It's up to you, but I'd skip the description. It's
| |
| 31 return (a < 0 && ret > b) ? 0 : ret; | |
| 32 } | |
| 33 } // namespace | |
| 34 | |
| 25 // Allocating the static const so that it can be passed by reference to | 35 // Allocating the static const so that it can be passed by reference to |
| 26 // RTC_DCHECK. | 36 // RTC_DCHECK. |
| 27 const size_t StatisticsCalculator::kLenWaitingTimes; | 37 const size_t StatisticsCalculator::kLenWaitingTimes; |
| 28 | 38 |
| 29 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger( | 39 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger( |
| 30 const std::string& uma_name, | 40 const std::string& uma_name, |
| 31 int report_interval_ms, | 41 int report_interval_ms, |
| 32 int max_value) | 42 int max_value) |
| 33 : uma_name_(uma_name), | 43 : uma_name_(uma_name), |
| 34 report_interval_ms_(report_interval_ms), | 44 report_interval_ms_(report_interval_ms), |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 } | 151 } |
| 142 | 152 |
| 143 void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples) { | 153 void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples) { |
| 144 expanded_speech_samples_ += num_samples; | 154 expanded_speech_samples_ += num_samples; |
| 145 } | 155 } |
| 146 | 156 |
| 147 void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) { | 157 void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) { |
| 148 expanded_noise_samples_ += num_samples; | 158 expanded_noise_samples_ += num_samples; |
| 149 } | 159 } |
| 150 | 160 |
| 161 void StatisticsCalculator::ExpandedVoiceSamplesCorrection(int num_samples) { | |
| 162 expanded_speech_samples_ = | |
| 163 AddIntToSizeTWithLowerCap(num_samples, expanded_speech_samples_); | |
| 164 } | |
| 165 | |
| 166 void StatisticsCalculator::ExpandedNoiseSamplesCorrection(int num_samples) { | |
| 167 expanded_noise_samples_ = | |
| 168 AddIntToSizeTWithLowerCap(num_samples, expanded_noise_samples_); | |
| 169 } | |
| 170 | |
| 151 void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) { | 171 void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) { |
| 152 preemptive_samples_ += num_samples; | 172 preemptive_samples_ += num_samples; |
| 153 } | 173 } |
| 154 | 174 |
| 155 void StatisticsCalculator::AcceleratedSamples(size_t num_samples) { | 175 void StatisticsCalculator::AcceleratedSamples(size_t num_samples) { |
| 156 accelerate_samples_ += num_samples; | 176 accelerate_samples_ += num_samples; |
| 157 } | 177 } |
| 158 | 178 |
| 159 void StatisticsCalculator::AddZeros(size_t num_samples) { | 179 void StatisticsCalculator::AddZeros(size_t num_samples) { |
| 160 added_zero_samples_ += num_samples; | 180 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. | 308 // Ratio must be smaller than 1 in Q14. |
| 289 assert((numerator << 14) / denominator < (1 << 14)); | 309 assert((numerator << 14) / denominator < (1 << 14)); |
| 290 return static_cast<uint16_t>((numerator << 14) / denominator); | 310 return static_cast<uint16_t>((numerator << 14) / denominator); |
| 291 } else { | 311 } else { |
| 292 // Will not produce a ratio larger than 1, since this is probably an error. | 312 // Will not produce a ratio larger than 1, since this is probably an error. |
| 293 return 1 << 14; | 313 return 1 << 14; |
| 294 } | 314 } |
| 295 } | 315 } |
| 296 | 316 |
| 297 } // namespace webrtc | 317 } // namespace webrtc |
| OLD | NEW |