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

Unified Diff: webrtc/modules/audio_coding/neteq/delay_peak_detector.cc

Issue 1921163003: NetEq: Introduce TickTimer in DelayPeakDetector (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@packet-tick-timer
Patch Set: Correcting the function comments Created 4 years, 8 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/delay_peak_detector.cc
diff --git a/webrtc/modules/audio_coding/neteq/delay_peak_detector.cc b/webrtc/modules/audio_coding/neteq/delay_peak_detector.cc
index 712c7788aca50fe6862f503581279fc510bb9d95..ce9133bdaed3307805373b70262df9711083ae08 100644
--- a/webrtc/modules/audio_coding/neteq/delay_peak_detector.cc
+++ b/webrtc/modules/audio_coding/neteq/delay_peak_detector.cc
@@ -12,6 +12,9 @@
#include <algorithm> // max
+#include "webrtc/base/checks.h"
+#include "webrtc/base/safe_conversions.h"
+
namespace webrtc {
// The DelayPeakDetector keeps track of severe inter-arrival times, called
@@ -23,14 +26,15 @@ namespace webrtc {
DelayPeakDetector::~DelayPeakDetector() = default;
-DelayPeakDetector::DelayPeakDetector()
- : peak_found_(false),
- peak_detection_threshold_(0),
- peak_period_counter_ms_(-1) {
+DelayPeakDetector::DelayPeakDetector(const TickTimer* tick_timer)
+ : peak_found_(false),
+ peak_detection_threshold_(0),
+ tick_timer_(tick_timer) {
+ RTC_DCHECK(!peak_period_stopwatch_);
}
void DelayPeakDetector::Reset() {
- peak_period_counter_ms_ = -1; // Indicate that next peak is the first.
+ peak_period_stopwatch_.reset();
peak_found_ = false;
peak_history_.clear();
}
@@ -55,38 +59,40 @@ int DelayPeakDetector::MaxPeakHeight() const {
return max_height;
}
-int DelayPeakDetector::MaxPeakPeriod() const {
- int max_period = -1; // Returns -1 for an empty history.
- std::list<Peak>::const_iterator it;
- for (it = peak_history_.begin(); it != peak_history_.end(); ++it) {
- max_period = std::max(max_period, it->period_ms);
+uint64_t DelayPeakDetector::MaxPeakPeriod() const {
+ auto max_period_element = std::max_element(
+ peak_history_.begin(), peak_history_.end(),
+ [](Peak a, Peak b) { return a.period_ms < b.period_ms; });
+ if (max_period_element == peak_history_.end()) {
+ return 0; // |peak_history_| is empty.
}
- return max_period;
+ RTC_DCHECK_GT(max_period_element->period_ms, 0u);
+ return max_period_element->period_ms;
}
bool DelayPeakDetector::Update(int inter_arrival_time, int target_level) {
if (inter_arrival_time > target_level + peak_detection_threshold_ ||
inter_arrival_time > 2 * target_level) {
// A delay peak is observed.
- if (peak_period_counter_ms_ == -1) {
+ if (!peak_period_stopwatch_) {
// This is the first peak. Reset the period counter.
- peak_period_counter_ms_ = 0;
- } else if (peak_period_counter_ms_ <= kMaxPeakPeriodMs) {
+ peak_period_stopwatch_ = tick_timer_->GetNewStopwatch();
+ } else if (peak_period_stopwatch_->ElapsedMs() <= kMaxPeakPeriodMs) {
// This is not the first peak, and the period is valid.
// Store peak data in the vector.
Peak peak_data;
- peak_data.period_ms = peak_period_counter_ms_;
+ peak_data.period_ms = peak_period_stopwatch_->ElapsedMs();
peak_data.peak_height_packets = inter_arrival_time;
peak_history_.push_back(peak_data);
while (peak_history_.size() > kMaxNumPeaks) {
// Delete the oldest data point.
peak_history_.pop_front();
}
- peak_period_counter_ms_ = 0;
- } else if (peak_period_counter_ms_ <= 2 * kMaxPeakPeriodMs) {
+ peak_period_stopwatch_ = tick_timer_->GetNewStopwatch();
+ } else if (peak_period_stopwatch_->ElapsedMs() <= 2 * kMaxPeakPeriodMs) {
// Invalid peak due to too long period. Reset period counter and start
// looking for next peak.
- peak_period_counter_ms_ = 0;
+ peak_period_stopwatch_ = tick_timer_->GetNewStopwatch();
} else {
// More than 2 times the maximum period has elapsed since the last peak
// was registered. It seams that the network conditions have changed.
@@ -97,16 +103,10 @@ bool DelayPeakDetector::Update(int inter_arrival_time, int target_level) {
return CheckPeakConditions();
}
-void DelayPeakDetector::IncrementCounter(int inc_ms) {
- if (peak_period_counter_ms_ >= 0) {
- peak_period_counter_ms_ += inc_ms;
- }
-}
-
bool DelayPeakDetector::CheckPeakConditions() {
size_t s = peak_history_.size();
if (s >= kMinPeaksToTrigger &&
- peak_period_counter_ms_ <= 2 * MaxPeakPeriod()) {
+ peak_period_stopwatch_->ElapsedMs() <= 2 * MaxPeakPeriod()) {
peak_found_ = true;
} else {
peak_found_ = false;

Powered by Google App Engine
This is Rietveld 408576698