 Chromium Code Reviews
 Chromium Code Reviews Issue 2859483005:
  NetEq: Fix a bug in expand_rate and speech_expand_rate calculation  (Closed)
    
  
    Issue 2859483005:
  NetEq: Fix a bug in expand_rate and speech_expand_rate calculation  (Closed) 
  | 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..c6d274f43247d027312ddfebd158fbe2ac4e3997 100644 | 
| --- a/webrtc/modules/audio_coding/neteq/statistics_calculator.cc | 
| +++ b/webrtc/modules/audio_coding/neteq/statistics_calculator.cc | 
| @@ -22,6 +22,16 @@ | 
| namespace webrtc { | 
| +namespace { | 
| +size_t AddIntToSizeTWithLowerCap(int a, size_t b) { | 
| + const size_t ret = b + a; | 
| + // If a + b is negative, resulting in a negative wrap, cap it to zero instead. | 
| + static_assert(sizeof(size_t) >= sizeof(int), | 
| + "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
 | 
| + return (a < 0 && ret > b) ? 0 : ret; | 
| +} | 
| +} // namespace | 
| + | 
| // Allocating the static const so that it can be passed by reference to | 
| // RTC_DCHECK. | 
| const size_t StatisticsCalculator::kLenWaitingTimes; | 
| @@ -148,6 +158,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; | 
| } |