Add NetEq::FilteredCurrentDelayMs() and use it in VoiceEngine

The new method returns the current total delay (packet buffer and sync
buffer) in ms, with smoothing applied to even out short-time
fluctuations due to jitter. The packet buffer part of the delay is not
updated during DTX/CNG periods.

This CL also pipes the new metric through ACM and uses it in
VoiceEngine. It replaces the previous method of estimating the buffer
delay (where an inserted packet's RTP timestamp was compared with the
last played timestamp from NetEq). The new method works better under
periods of DTX/CNG.

Review-Url: https://codereview.webrtc.org/2262203002
Cr-Commit-Position: refs/heads/master@{#13855}
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
index 024c73d..9cd73b6 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
@@ -353,6 +353,22 @@
   return delay_ms;
 }
 
+int NetEqImpl::FilteredCurrentDelayMs() const {
+  rtc::CritScope lock(&crit_sect_);
+  // Calculate the filtered packet buffer level in samples. The value from
+  // |buffer_level_filter_| is in number of packets, represented in Q8.
+  const size_t packet_buffer_samples =
+      (buffer_level_filter_->filtered_current_level() *
+       decoder_frame_length_) >>
+      8;
+  // Sum up the filtered packet buffer level with the future length of the sync
+  // buffer, and divide the sum by the sample rate.
+  const size_t delay_samples =
+      packet_buffer_samples + sync_buffer_->FutureLength();
+  // The division below will truncate. The return value is in ms.
+  return static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000);
+}
+
 // Deprecated.
 // TODO(henrik.lundin) Delete.
 void NetEqImpl::SetPlayoutMode(NetEqPlayoutMode mode) {