NetEq: Use TickTimer in DelayManager
This change replaces packet_iat_count_ms_ and max_timer_ms_, two
time-counting member variables in DelayManager, with Stopwatch objects
obtained from a TickTimer.
BUG=webrtc:5608
Review-Url: https://codereview.webrtc.org/1929863002
Cr-Commit-Position: refs/heads/master@{#12554}
diff --git a/webrtc/modules/audio_coding/neteq/delay_manager.cc b/webrtc/modules/audio_coding/neteq/delay_manager.cc
index e955f17..84bda7c 100644
--- a/webrtc/modules/audio_coding/neteq/delay_manager.cc
+++ b/webrtc/modules/audio_coding/neteq/delay_manager.cc
@@ -24,12 +24,13 @@
namespace webrtc {
DelayManager::DelayManager(size_t max_packets_in_buffer,
- DelayPeakDetector* peak_detector)
+ DelayPeakDetector* peak_detector,
+ const TickTimer* tick_timer)
: first_packet_received_(false),
max_packets_in_buffer_(max_packets_in_buffer),
iat_vector_(kMaxIat + 1, 0),
iat_factor_(0),
- packet_iat_count_ms_(0),
+ tick_timer_(tick_timer),
base_target_level_(4), // In Q0 domain.
target_level_(base_target_level_ << 8), // In Q8 domain.
packet_len_ms_(0),
@@ -41,7 +42,6 @@
maximum_delay_ms_(target_level_),
iat_cumulative_sum_(0),
max_iat_cumulative_sum_(0),
- max_timer_ms_(0),
peak_detector_(*peak_detector),
last_pack_cng_or_dtmf_(1) {
assert(peak_detector); // Should never be NULL.
@@ -79,7 +79,7 @@
if (!first_packet_received_) {
// Prepare for next packet arrival.
- packet_iat_count_ms_ = 0;
+ packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
last_seq_no_ = sequence_number;
last_timestamp_ = timestamp;
first_packet_received_ = true;
@@ -106,7 +106,7 @@
// Calculate inter-arrival time (IAT) in integer "packet times"
// (rounding down). This is the value used as index to the histogram
// vector |iat_vector_|.
- int iat_packets = packet_iat_count_ms_ / packet_len_ms;
+ int iat_packets = packet_iat_stopwatch_->ElapsedMs() / packet_len_ms;
if (streaming_mode_) {
UpdateCumulativeSums(packet_len_ms, sequence_number);
@@ -137,7 +137,7 @@
} // End if (packet_len_ms > 0).
// Prepare for next packet arrival.
- packet_iat_count_ms_ = 0;
+ packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
last_seq_no_ = sequence_number;
last_timestamp_ = timestamp;
return 0;
@@ -147,7 +147,8 @@
uint16_t sequence_number) {
// Calculate IAT in Q8, including fractions of a packet (i.e., more
// accurate than |iat_packets|.
- int iat_packets_q8 = (packet_iat_count_ms_ << 8) / packet_len_ms;
+ int iat_packets_q8 =
+ (packet_iat_stopwatch_->ElapsedMs() << 8) / packet_len_ms;
// Calculate cumulative sum IAT with sequence number compensation. The sum
// is zero if there is no clock-drift.
iat_cumulative_sum_ += (iat_packets_q8 -
@@ -159,9 +160,9 @@
if (iat_cumulative_sum_ > max_iat_cumulative_sum_) {
// Found a new maximum.
max_iat_cumulative_sum_ = iat_cumulative_sum_;
- max_timer_ms_ = 0;
+ max_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
}
- if (max_timer_ms_ > kMaxStreamingPeakPeriodMs) {
+ if (max_iat_stopwatch_->ElapsedMs() > kMaxStreamingPeakPeriodMs) {
// Too long since the last maximum was observed; decrease max value.
max_iat_cumulative_sum_ -= kCumulativeSumDrift;
}
@@ -299,7 +300,7 @@
}
packet_len_ms_ = length_ms;
peak_detector_.SetPacketAudioLength(packet_len_ms_);
- packet_iat_count_ms_ = 0;
+ packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
last_pack_cng_or_dtmf_ = 1; // TODO(hlundin): Legacy. Remove?
return 0;
}
@@ -311,8 +312,8 @@
peak_detector_.Reset();
ResetHistogram(); // Resets target levels too.
iat_factor_ = 0; // Adapt the histogram faster for the first few packets.
- packet_iat_count_ms_ = 0;
- max_timer_ms_ = 0;
+ packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
+ max_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
iat_cumulative_sum_ = 0;
max_iat_cumulative_sum_ = 0;
last_pack_cng_or_dtmf_ = 1;
@@ -340,13 +341,10 @@
return peak_detector_.peak_found();
}
-void DelayManager::UpdateCounters(int elapsed_time_ms) {
- packet_iat_count_ms_ += elapsed_time_ms;
- max_timer_ms_ += elapsed_time_ms;
+void DelayManager::ResetPacketIatCount() {
+ packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch();
}
-void DelayManager::ResetPacketIatCount() { packet_iat_count_ms_ = 0; }
-
// Note that |low_limit| and |higher_limit| are not assigned to
// |minimum_delay_ms_| and |maximum_delay_ms_| defined by the client of this
// class. They are computed from |target_level_| and used for decision making.