blob: b7718aa2c3f69791d9b332ab284b8f549da1185c [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/array_view.h"
19#include "modules/audio_processing/aec3/aec3_common.h"
20#include "modules/audio_processing/aec3/downsampled_render_buffer.h"
21#include "modules/audio_processing/aec3/fft_data.h"
22#include "modules/audio_processing/aec3/render_buffer.h"
Per Åhgren8ba58612017-12-01 23:01:44 +010023#include "modules/audio_processing/include/audio_processing.h"
peahcf02cf12017-04-05 14:18:07 -070024
peah69221db2017-01-27 03:28:19 -080025namespace webrtc {
26
27// Class for buffering the incoming render blocks such that these may be
28// extracted with a specified delay.
29class RenderDelayBuffer {
30 public:
Per Åhgren8ba58612017-12-01 23:01:44 +010031 enum class BufferingEvent {
32 kNone,
33 kRenderUnderrun,
34 kRenderOverrun,
35 kApiCallSkew,
36 kRenderDataLost
37 };
38
39 static RenderDelayBuffer* Create(const EchoCanceller3Config& config,
40 size_t num_bands);
peah69221db2017-01-27 03:28:19 -080041 virtual ~RenderDelayBuffer() = default;
42
Per Åhgren8ba58612017-12-01 23:01:44 +010043 // Resets the buffer alignment.
peahcf02cf12017-04-05 14:18:07 -070044 virtual void Reset() = 0;
peah69221db2017-01-27 03:28:19 -080045
Per Åhgren8ba58612017-12-01 23:01:44 +010046 // Inserts a block into the buffer.
47 virtual BufferingEvent Insert(
48 const std::vector<std::vector<float>>& block) = 0;
peah69221db2017-01-27 03:28:19 -080049
peahcf02cf12017-04-05 14:18:07 -070050 // Updates the buffers one step based on the specified buffer delay. Returns
Per Åhgren8ba58612017-12-01 23:01:44 +010051 // an enum indicating whether there was a special event that occurred.
Per Åhgrenc59a5762017-12-11 21:34:19 +010052 virtual BufferingEvent PrepareCaptureProcessing() = 0;
peahcf02cf12017-04-05 14:18:07 -070053
Per Åhgrenc59a5762017-12-11 21:34:19 +010054 // Sets the buffer delay and returns a bool indicating whether the delay
55 // changed.
56 virtual bool SetDelay(size_t delay) = 0;
peah69221db2017-01-27 03:28:19 -080057
58 // Gets the buffer delay.
Per Åhgrenc59a5762017-12-11 21:34:19 +010059 virtual rtc::Optional<size_t> Delay() const = 0;
peah69221db2017-01-27 03:28:19 -080060
Per Åhgren8ba58612017-12-01 23:01:44 +010061 // Gets the buffer delay.
62 virtual size_t MaxDelay() const = 0;
63
peahcf02cf12017-04-05 14:18:07 -070064 // Returns the render buffer for the echo remover.
Per Åhgrenc59a5762017-12-11 21:34:19 +010065 virtual RenderBuffer* GetRenderBuffer() = 0;
peah69221db2017-01-27 03:28:19 -080066
peahcf02cf12017-04-05 14:18:07 -070067 // Returns the downsampled render buffer.
68 virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0;
Per Åhgrenc59a5762017-12-11 21:34:19 +010069
70 // Returns whether the current delay is noncausal.
71 virtual bool CausalDelay() const = 0;
72
73 // Returns the maximum non calusal offset that can occur in the delay buffer.
74 static int DelayEstimatorOffset(const EchoCanceller3Config& config);
peah69221db2017-01-27 03:28:19 -080075};
76
77} // namespace webrtc
78
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_