Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: webrtc/modules/audio_coding/neteq/statistics_calculator.cc

Issue 2859483005: NetEq: Fix a bug in expand_rate and speech_expand_rate calculation (Closed)
Patch Set: After first round of reviews Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_compare.h"
18 #include "webrtc/base/safe_conversions.h" 19 #include "webrtc/base/safe_conversions.h"
19 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" 20 #include "webrtc/modules/audio_coding/neteq/decision_logic.h"
20 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" 21 #include "webrtc/modules/audio_coding/neteq/delay_manager.h"
21 #include "webrtc/system_wrappers/include/metrics.h" 22 #include "webrtc/system_wrappers/include/metrics.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 25
26 namespace {
27 size_t AddIntToSizeTWithLowerCap(int a, size_t b) {
28 if (rtc::safe_cmp::Gt(-int64_t{a}, b)) {
29 // Simply doing a + b would give a negative result, with a negative wrap.
30 // Cap it to zero instead.
31 return 0;
32 }
33 return rtc::dchecked_cast<size_t>(a) + b;
34 }
35 }
36
25 // Allocating the static const so that it can be passed by reference to 37 // Allocating the static const so that it can be passed by reference to
26 // RTC_DCHECK. 38 // RTC_DCHECK.
27 const size_t StatisticsCalculator::kLenWaitingTimes; 39 const size_t StatisticsCalculator::kLenWaitingTimes;
28 40
29 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger( 41 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger(
30 const std::string& uma_name, 42 const std::string& uma_name,
31 int report_interval_ms, 43 int report_interval_ms,
32 int max_value) 44 int max_value)
33 : uma_name_(uma_name), 45 : uma_name_(uma_name),
34 report_interval_ms_(report_interval_ms), 46 report_interval_ms_(report_interval_ms),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 153 }
142 154
143 void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples) { 155 void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples) {
144 expanded_speech_samples_ += num_samples; 156 expanded_speech_samples_ += num_samples;
145 } 157 }
146 158
147 void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) { 159 void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) {
148 expanded_noise_samples_ += num_samples; 160 expanded_noise_samples_ += num_samples;
149 } 161 }
150 162
163 void StatisticsCalculator::ExpandedVoiceSamplesCorrection(int num_samples) {
164 expanded_speech_samples_ =
165 AddIntToSizeTWithLowerCap(num_samples, expanded_speech_samples_);
166 }
167
168 void StatisticsCalculator::ExpandedNoiseSamplesCorrection(int num_samples) {
169 expanded_noise_samples_ =
170 AddIntToSizeTWithLowerCap(num_samples, expanded_noise_samples_);
171 }
172
151 void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) { 173 void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) {
152 preemptive_samples_ += num_samples; 174 preemptive_samples_ += num_samples;
153 } 175 }
154 176
155 void StatisticsCalculator::AcceleratedSamples(size_t num_samples) { 177 void StatisticsCalculator::AcceleratedSamples(size_t num_samples) {
156 accelerate_samples_ += num_samples; 178 accelerate_samples_ += num_samples;
157 } 179 }
158 180
159 void StatisticsCalculator::AddZeros(size_t num_samples) { 181 void StatisticsCalculator::AddZeros(size_t num_samples) {
160 added_zero_samples_ += num_samples; 182 added_zero_samples_ += num_samples;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Ratio must be smaller than 1 in Q14. 310 // Ratio must be smaller than 1 in Q14.
289 assert((numerator << 14) / denominator < (1 << 14)); 311 assert((numerator << 14) / denominator < (1 << 14));
290 return static_cast<uint16_t>((numerator << 14) / denominator); 312 return static_cast<uint16_t>((numerator << 14) / denominator);
291 } else { 313 } else {
292 // Will not produce a ratio larger than 1, since this is probably an error. 314 // Will not produce a ratio larger than 1, since this is probably an error.
293 return 1 << 14; 315 return 1 << 14;
294 } 316 }
295 } 317 }
296 318
297 } // namespace webrtc 319 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698