peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_ |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 13 | |
| 14 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Gustaf Ullberg | 3646f97 | 2018-02-14 15:19:04 +0100 | [diff] [blame] | 18 | #include "api/audio/echo_canceller3_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/audio_processing/aec3/downsampled_render_buffer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_processing/aec3/render_buffer.h" |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 21 | |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
| 24 | // Class for buffering the incoming render blocks such that these may be |
| 25 | // extracted with a specified delay. |
| 26 | class RenderDelayBuffer { |
| 27 | public: |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 28 | enum class BufferingEvent { |
| 29 | kNone, |
| 30 | kRenderUnderrun, |
| 31 | kRenderOverrun, |
Gustaf Ullberg | 11539f0 | 2018-10-15 13:40:29 +0200 | [diff] [blame] | 32 | kApiCallSkew |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | static RenderDelayBuffer* Create(const EchoCanceller3Config& config, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame] | 36 | int sample_rate_hz, |
| 37 | size_t num_render_channels); |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 38 | virtual ~RenderDelayBuffer() = default; |
| 39 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 40 | // Resets the buffer alignment. |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 41 | virtual void Reset() = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 42 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 43 | // Inserts a block into the buffer. |
| 44 | virtual BufferingEvent Insert( |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame] | 45 | const std::vector<std::vector<std::vector<float>>>& block) = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 46 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 47 | // Updates the buffers one step based on the specified buffer delay. Returns |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 48 | // an enum indicating whether there was a special event that occurred. |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 49 | virtual BufferingEvent PrepareCaptureProcessing() = 0; |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 50 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 51 | // Sets the buffer delay and returns a bool indicating whether the delay |
| 52 | // changed. |
Gustaf Ullberg | 8f32b6c | 2019-04-05 16:23:50 +0200 | [diff] [blame] | 53 | virtual bool AlignFromDelay(size_t delay) = 0; |
| 54 | |
| 55 | // Sets the buffer delay from the most recently reported external delay. |
| 56 | virtual void AlignFromExternalDelay() = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 57 | |
| 58 | // Gets the buffer delay. |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 59 | virtual size_t Delay() const = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 60 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 61 | // Gets the buffer delay. |
| 62 | virtual size_t MaxDelay() const = 0; |
| 63 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 64 | // Returns the render buffer for the echo remover. |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 65 | virtual RenderBuffer* GetRenderBuffer() = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 66 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 67 | // Returns the downsampled render buffer. |
| 68 | virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0; |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 69 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 70 | // Returns the maximum non calusal offset that can occur in the delay buffer. |
| 71 | static int DelayEstimatorOffset(const EchoCanceller3Config& config); |
Per Åhgren | d0fa820 | 2018-04-18 09:35:13 +0200 | [diff] [blame] | 72 | |
| 73 | // Provides an optional external estimate of the audio buffer delay. |
Gustaf Ullberg | 3cb6104 | 2019-10-24 15:52:10 +0200 | [diff] [blame] | 74 | virtual void SetAudioBufferDelay(int delay_ms) = 0; |
Gustaf Ullberg | 8f32b6c | 2019-04-05 16:23:50 +0200 | [diff] [blame] | 75 | |
| 76 | // Returns whether an external delay estimate has been reported via |
| 77 | // SetAudioBufferDelay. |
| 78 | virtual bool HasReceivedBufferDelay() = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace webrtc |
| 82 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 83 | #endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_ |