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

Unified 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 side-by-side diff with in-line comments
Download patch
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..51807069e7a67ea79fe65b8b97e4e440c9b23fd9 100644
--- a/webrtc/modules/audio_coding/neteq/statistics_calculator.cc
+++ b/webrtc/modules/audio_coding/neteq/statistics_calculator.cc
@@ -15,6 +15,7 @@
#include <algorithm>
#include "webrtc/base/checks.h"
+#include "webrtc/base/safe_compare.h"
#include "webrtc/base/safe_conversions.h"
#include "webrtc/modules/audio_coding/neteq/decision_logic.h"
#include "webrtc/modules/audio_coding/neteq/delay_manager.h"
@@ -22,6 +23,17 @@
namespace webrtc {
+namespace {
+size_t AddIntToSizeTWithLowerCap(int a, size_t b) {
+ if (rtc::safe_cmp::Gt(-int64_t{a}, b)) {
+ // Simply doing a + b would give a negative result, with a negative wrap.
+ // Cap it to zero instead.
+ return 0;
+ }
+ return rtc::dchecked_cast<size_t>(a) + b;
+}
+}
+
// Allocating the static const so that it can be passed by reference to
// RTC_DCHECK.
const size_t StatisticsCalculator::kLenWaitingTimes;
@@ -148,6 +160,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;
}

Powered by Google App Engine
This is Rietveld 408576698