AEC3: Support negative delay with external delay estimator

Bug: b/130016532
Change-Id: If41121e9ad95f235200c4b6b146ba8a8749daac4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158220
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29602}
This commit is contained in:
Gustaf Ullberg 2019-10-24 15:52:10 +02:00 committed by Commit Bot
parent a9229043e3
commit 3cb6104864
12 changed files with 22 additions and 18 deletions

View File

@ -39,7 +39,11 @@ class EchoControl {
virtual Metrics GetMetrics() const = 0;
// Provides an optional external estimate of the audio buffer delay.
virtual void SetAudioBufferDelay(size_t delay_ms) = 0;
virtual void SetAudioBufferDelay(size_t delay_ms) {}
virtual void SetAudioBufferDelay(int delay_ms) {
// Default to old implementation.
SetAudioBufferDelay(static_cast<size_t>(delay_ms));
}
// Returns wheter the signal is altered.
virtual bool ActiveProcessing() const = 0;

View File

@ -61,7 +61,7 @@ class BlockProcessorImpl final : public BlockProcessor {
void GetMetrics(EchoControl::Metrics* metrics) const override;
void SetAudioBufferDelay(size_t delay_ms) override;
void SetAudioBufferDelay(int delay_ms) override;
private:
static int instance_count_;
@ -230,7 +230,7 @@ void BlockProcessorImpl::GetMetrics(EchoControl::Metrics* metrics) const {
metrics->delay_ms = delay ? static_cast<int>(*delay) * block_size_ms : 0;
}
void BlockProcessorImpl::SetAudioBufferDelay(size_t delay_ms) {
void BlockProcessorImpl::SetAudioBufferDelay(int delay_ms) {
render_buffer_->SetAudioBufferDelay(delay_ms);
}

View File

@ -53,7 +53,7 @@ class BlockProcessor {
virtual void GetMetrics(EchoControl::Metrics* metrics) const = 0;
// Provides an optional external estimate of the audio buffer delay.
virtual void SetAudioBufferDelay(size_t delay_ms) = 0;
virtual void SetAudioBufferDelay(int delay_ms) = 0;
// Processes a block of capture data.
virtual void ProcessCapture(

View File

@ -374,7 +374,7 @@ EchoControl::Metrics EchoCanceller3::GetMetrics() const {
return metrics;
}
void EchoCanceller3::SetAudioBufferDelay(size_t delay_ms) {
void EchoCanceller3::SetAudioBufferDelay(int delay_ms) {
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_);
block_processor_->SetAudioBufferDelay(delay_ms);
}

View File

@ -109,7 +109,7 @@ class EchoCanceller3 : public EchoControl {
// Collect current metrics from the echo canceller.
Metrics GetMetrics() const override;
// Provides an optional external estimate of the audio buffer delay.
void SetAudioBufferDelay(size_t delay_ms) override;
void SetAudioBufferDelay(int delay_ms) override;
bool ActiveProcessing() const override;

View File

@ -121,7 +121,7 @@ class CaptureTransportVerificationProcessor : public BlockProcessor {
void GetMetrics(EchoControl::Metrics* metrics) const override {}
void SetAudioBufferDelay(size_t delay_ms) override {}
void SetAudioBufferDelay(int delay_ms) override {}
private:
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTransportVerificationProcessor);
@ -153,7 +153,7 @@ class RenderTransportVerificationProcessor : public BlockProcessor {
void GetMetrics(EchoControl::Metrics* metrics) const override {}
void SetAudioBufferDelay(size_t delay_ms) override {}
void SetAudioBufferDelay(int delay_ms) override {}
private:
std::deque<std::vector<std::vector<std::vector<float>>>>

View File

@ -33,7 +33,7 @@ class MockBlockProcessor : public BlockProcessor {
void(const std::vector<std::vector<std::vector<float>>>& block));
MOCK_METHOD1(UpdateEchoLeakageStatus, void(bool leakage_detected));
MOCK_CONST_METHOD1(GetMetrics, void(EchoControl::Metrics* metrics));
MOCK_METHOD1(SetAudioBufferDelay, void(size_t delay_ms));
MOCK_METHOD1(SetAudioBufferDelay, void(int delay_ms));
};
} // namespace test

View File

@ -40,7 +40,7 @@ class MockRenderDelayBuffer : public RenderDelayBuffer {
MOCK_CONST_METHOD0(GetDownsampledRenderBuffer,
const DownsampledRenderBuffer&());
MOCK_CONST_METHOD1(CausalDelay, bool(size_t delay));
MOCK_METHOD1(SetAudioBufferDelay, void(size_t delay_ms));
MOCK_METHOD1(SetAudioBufferDelay, void(int delay_ms));
MOCK_METHOD0(HasReceivedBufferDelay, bool());
private:

View File

@ -62,7 +62,7 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer {
}
int BufferLatency() const;
void SetAudioBufferDelay(size_t delay_ms) override;
void SetAudioBufferDelay(int delay_ms) override;
bool HasReceivedBufferDelay() override;
private:
@ -90,7 +90,7 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer {
int64_t render_call_counter_ = 0;
bool render_activity_ = false;
size_t render_activity_counter_ = 0;
absl::optional<size_t> external_audio_buffer_delay_;
absl::optional<int> external_audio_buffer_delay_;
bool external_audio_buffer_delay_verified_after_reset_ = false;
size_t min_latency_blocks_ = 0;
size_t excess_render_detection_counter_ = 0;
@ -165,7 +165,7 @@ void RenderDelayBufferImpl::Reset() {
// Check for any external audio buffer delay and whether it is feasible.
if (external_audio_buffer_delay_) {
const size_t headroom = 2;
const int headroom = 2;
size_t audio_buffer_delay_to_set;
// Minimum delay is 1 (like the low-rate render buffer).
if (*external_audio_buffer_delay_ <= headroom) {
@ -318,7 +318,7 @@ bool RenderDelayBufferImpl::AlignFromDelay(size_t delay) {
return true;
}
void RenderDelayBufferImpl::SetAudioBufferDelay(size_t delay_ms) {
void RenderDelayBufferImpl::SetAudioBufferDelay(int delay_ms) {
if (!external_audio_buffer_delay_) {
RTC_LOG_V(delay_log_level_)
<< "Receiving a first externally reported audio buffer delay of "
@ -326,7 +326,7 @@ void RenderDelayBufferImpl::SetAudioBufferDelay(size_t delay_ms) {
}
// Convert delay from milliseconds to blocks (rounded down).
external_audio_buffer_delay_ = delay_ms >> 2;
external_audio_buffer_delay_ = delay_ms / 4;
}
bool RenderDelayBufferImpl::HasReceivedBufferDelay() {

View File

@ -71,7 +71,7 @@ class RenderDelayBuffer {
static int DelayEstimatorOffset(const EchoCanceller3Config& config);
// Provides an optional external estimate of the audio buffer delay.
virtual void SetAudioBufferDelay(size_t delay_ms) = 0;
virtual void SetAudioBufferDelay(int delay_ms) = 0;
// Returns whether an external delay estimate has been reported via
// SetAudioBufferDelay.

View File

@ -48,7 +48,7 @@ class MockEchoControl : public EchoControl {
MOCK_METHOD2(ProcessCapture,
void(AudioBuffer* capture, bool echo_path_change));
MOCK_CONST_METHOD0(GetMetrics, Metrics());
MOCK_METHOD1(SetAudioBufferDelay, void(size_t delay_ms));
MOCK_METHOD1(SetAudioBufferDelay, void(int delay_ms));
MOCK_CONST_METHOD0(ActiveProcessing, bool());
};

View File

@ -25,7 +25,7 @@ class MockEchoControl : public EchoControl {
MOCK_METHOD2(ProcessCapture,
void(AudioBuffer* capture, bool echo_path_change));
MOCK_CONST_METHOD0(GetMetrics, EchoControl::Metrics());
MOCK_METHOD1(SetAudioBufferDelay, void(size_t delay_ms));
MOCK_METHOD1(SetAudioBufferDelay, void(int delay_ms));
MOCK_CONST_METHOD0(ActiveProcessing, bool());
};