Reland: Implement NetEq's CurrentDelay function
This was not implemented before. It returns the current total delay
(packet buffer and sync buffer) of NetEq. This is the same information
that was already available in
NetEqNetworkStatistics::current_buffer_size_ms, that can be obtained
through NetEq::NetworkStatistics(). But, since the current delay is a
key metric of NetEq, it is convenient to have it available in a
simpler way.
This is a re-landing of r9359,
https://webrtc-codereview.appspot.com/51149004, which was reverted in
r9360. The refactoring made in r9669 facilitated the relanding.
TBR=minyue@webrtc.org
Review URL: https://codereview.webrtc.org/1313873003
Cr-Commit-Position: refs/heads/master@{#9801}
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
index cf7afbc..c9c1f86 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
@@ -15,6 +15,7 @@
#include <algorithm>
+#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/safe_conversions.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
@@ -282,8 +283,20 @@
return kNotImplemented;
}
-int NetEqImpl::CurrentDelay() {
- return kNotImplemented;
+int NetEqImpl::CurrentDelayMs() const {
+ CriticalSectionScoped lock(crit_sect_.get());
+ if (fs_hz_ == 0)
+ return 0;
+ // Sum up the samples in the packet buffer with the future length of the sync
+ // buffer, and divide the sum by the sample rate.
+ const size_t delay_samples =
+ packet_buffer_->NumSamplesInBuffer(decoder_database_.get(),
+ decoder_frame_length_) +
+ sync_buffer_->FutureLength();
+ // The division below will truncate.
+ const int delay_ms =
+ static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000);
+ return delay_ms;
}
// Deprecated.