blob: 8c5667e081b8097c8022f197d431d3fb3b9aedc4 [file] [log] [blame]
peah69221db2017-01-27 03:28:19 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
peah69221db2017-01-27 03:28:19 -080013
14#include <stddef.h>
peahcf02cf12017-04-05 14:18:07 -070015#include <array>
peah69221db2017-01-27 03:28:19 -080016#include <vector>
17
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +020018#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/array_view.h"
Gustaf Ullberg3646f972018-02-14 15:19:04 +010020#include "api/audio/echo_canceller3_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/audio_processing/aec3/aec3_common.h"
22#include "modules/audio_processing/aec3/downsampled_render_buffer.h"
23#include "modules/audio_processing/aec3/fft_data.h"
24#include "modules/audio_processing/aec3/render_buffer.h"
peahcf02cf12017-04-05 14:18:07 -070025
peah69221db2017-01-27 03:28:19 -080026namespace webrtc {
27
28// Class for buffering the incoming render blocks such that these may be
29// extracted with a specified delay.
30class RenderDelayBuffer {
31 public:
Per Åhgren8ba58612017-12-01 23:01:44 +010032 enum class BufferingEvent {
33 kNone,
34 kRenderUnderrun,
35 kRenderOverrun,
Gustaf Ullberg11539f02018-10-15 13:40:29 +020036 kApiCallSkew
Per Åhgren8ba58612017-12-01 23:01:44 +010037 };
38
39 static RenderDelayBuffer* Create(const EchoCanceller3Config& config,
40 size_t num_bands);
Gustaf Ullberg11539f02018-10-15 13:40:29 +020041 static RenderDelayBuffer* Create2(const EchoCanceller3Config& config,
42 size_t num_bands);
peah69221db2017-01-27 03:28:19 -080043 virtual ~RenderDelayBuffer() = default;
44
Per Åhgren8ba58612017-12-01 23:01:44 +010045 // Resets the buffer alignment.
peahcf02cf12017-04-05 14:18:07 -070046 virtual void Reset() = 0;
peah69221db2017-01-27 03:28:19 -080047
Per Åhgren8ba58612017-12-01 23:01:44 +010048 // Inserts a block into the buffer.
49 virtual BufferingEvent Insert(
50 const std::vector<std::vector<float>>& block) = 0;
peah69221db2017-01-27 03:28:19 -080051
peahcf02cf12017-04-05 14:18:07 -070052 // Updates the buffers one step based on the specified buffer delay. Returns
Per Åhgren8ba58612017-12-01 23:01:44 +010053 // an enum indicating whether there was a special event that occurred.
Per Åhgrenc59a5762017-12-11 21:34:19 +010054 virtual BufferingEvent PrepareCaptureProcessing() = 0;
peahcf02cf12017-04-05 14:18:07 -070055
Per Åhgrenc59a5762017-12-11 21:34:19 +010056 // Sets the buffer delay and returns a bool indicating whether the delay
57 // changed.
58 virtual bool SetDelay(size_t delay) = 0;
peah69221db2017-01-27 03:28:19 -080059
60 // Gets the buffer delay.
Per Åhgren5c532d32018-03-22 00:29:25 +010061 virtual size_t Delay() const = 0;
peah69221db2017-01-27 03:28:19 -080062
Per Åhgren8ba58612017-12-01 23:01:44 +010063 // Gets the buffer delay.
64 virtual size_t MaxDelay() const = 0;
65
peahcf02cf12017-04-05 14:18:07 -070066 // Returns the render buffer for the echo remover.
Per Åhgrenc59a5762017-12-11 21:34:19 +010067 virtual RenderBuffer* GetRenderBuffer() = 0;
peah69221db2017-01-27 03:28:19 -080068
peahcf02cf12017-04-05 14:18:07 -070069 // Returns the downsampled render buffer.
70 virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0;
Per Åhgrenc59a5762017-12-11 21:34:19 +010071
72 // Returns whether the current delay is noncausal.
Per Åhgrena76ef9d2018-01-25 07:01:34 +010073 virtual bool CausalDelay(size_t delay) const = 0;
Per Åhgrenc59a5762017-12-11 21:34:19 +010074
75 // Returns the maximum non calusal offset that can occur in the delay buffer.
76 static int DelayEstimatorOffset(const EchoCanceller3Config& config);
Per Åhgrend0fa8202018-04-18 09:35:13 +020077
78 // Provides an optional external estimate of the audio buffer delay.
79 virtual void SetAudioBufferDelay(size_t delay_ms) = 0;
peah69221db2017-01-27 03:28:19 -080080};
81
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_