Index: webrtc/modules/audio_coding/neteq/statistics_calculator.cc |
diff --git a/webrtc/modules/audio_coding/neteq/statistics_calculator.cc b/webrtc/modules/audio_coding/neteq/statistics_calculator.cc |
index b47ca127dbe7a2107b4315a7bd4eece1ef0d19fa..5214dde97758c33d08c4d9bada6e229b4022c988 100644 |
--- a/webrtc/modules/audio_coding/neteq/statistics_calculator.cc |
+++ b/webrtc/modules/audio_coding/neteq/statistics_calculator.cc |
@@ -22,6 +22,17 @@ |
namespace webrtc { |
+namespace { |
+size_t AddIntToSizeTWithLowerCap(int a, size_t b) { |
+ 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.
|
+ // Simply doing a + b would give a negative result, with a negative wrap. |
+ // Cap it to zero instead. |
+ return 0; |
+ } |
+ 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.
|
+} |
+} |
+ |
// Allocating the static const so that it can be passed by reference to |
// RTC_DCHECK. |
const size_t StatisticsCalculator::kLenWaitingTimes; |
@@ -148,6 +159,16 @@ void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples) { |
expanded_noise_samples_ += num_samples; |
} |
+void StatisticsCalculator::ExpandedVoiceSamplesCorrection(int num_samples) { |
+ expanded_speech_samples_ = |
+ AddIntToSizeTWithLowerCap(num_samples, expanded_speech_samples_); |
+} |
+ |
+void StatisticsCalculator::ExpandedNoiseSamplesCorrection(int num_samples) { |
+ expanded_noise_samples_ = |
+ AddIntToSizeTWithLowerCap(num_samples, expanded_noise_samples_); |
+} |
+ |
void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) { |
preemptive_samples_ += num_samples; |
} |