blob: 89b3a2a299fe6fe5cfc7f1367e04b29ce5e480d7 [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>
15#include <vector>
16
Gustaf Ullberg3646f972018-02-14 15:19:04 +010017#include "api/audio/echo_canceller3_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_processing/aec3/downsampled_render_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_processing/aec3/render_buffer.h"
peahcf02cf12017-04-05 14:18:07 -070020
peah69221db2017-01-27 03:28:19 -080021namespace webrtc {
22
23// Class for buffering the incoming render blocks such that these may be
24// extracted with a specified delay.
25class RenderDelayBuffer {
26 public:
Per Åhgren8ba58612017-12-01 23:01:44 +010027 enum class BufferingEvent {
28 kNone,
29 kRenderUnderrun,
30 kRenderOverrun,
Gustaf Ullberg11539f02018-10-15 13:40:29 +020031 kApiCallSkew
Per Åhgren8ba58612017-12-01 23:01:44 +010032 };
33
34 static RenderDelayBuffer* Create(const EchoCanceller3Config& config,
35 size_t num_bands);
peah69221db2017-01-27 03:28:19 -080036 virtual ~RenderDelayBuffer() = default;
37
Per Åhgren8ba58612017-12-01 23:01:44 +010038 // Resets the buffer alignment.
peahcf02cf12017-04-05 14:18:07 -070039 virtual void Reset() = 0;
peah69221db2017-01-27 03:28:19 -080040
Per Åhgren8ba58612017-12-01 23:01:44 +010041 // Inserts a block into the buffer.
42 virtual BufferingEvent Insert(
43 const std::vector<std::vector<float>>& block) = 0;
peah69221db2017-01-27 03:28:19 -080044
peahcf02cf12017-04-05 14:18:07 -070045 // Updates the buffers one step based on the specified buffer delay. Returns
Per Åhgren8ba58612017-12-01 23:01:44 +010046 // an enum indicating whether there was a special event that occurred.
Per Åhgrenc59a5762017-12-11 21:34:19 +010047 virtual BufferingEvent PrepareCaptureProcessing() = 0;
peahcf02cf12017-04-05 14:18:07 -070048
Per Åhgrenc59a5762017-12-11 21:34:19 +010049 // Sets the buffer delay and returns a bool indicating whether the delay
50 // changed.
Gustaf Ullberg8f32b6c2019-04-05 16:23:50 +020051 virtual bool AlignFromDelay(size_t delay) = 0;
52
53 // Sets the buffer delay from the most recently reported external delay.
54 virtual void AlignFromExternalDelay() = 0;
peah69221db2017-01-27 03:28:19 -080055
56 // Gets the buffer delay.
Per Åhgren5c532d32018-03-22 00:29:25 +010057 virtual size_t Delay() const = 0;
peah69221db2017-01-27 03:28:19 -080058
Per Åhgren8ba58612017-12-01 23:01:44 +010059 // Gets the buffer delay.
60 virtual size_t MaxDelay() const = 0;
61
peahcf02cf12017-04-05 14:18:07 -070062 // Returns the render buffer for the echo remover.
Per Åhgrenc59a5762017-12-11 21:34:19 +010063 virtual RenderBuffer* GetRenderBuffer() = 0;
peah69221db2017-01-27 03:28:19 -080064
peahcf02cf12017-04-05 14:18:07 -070065 // Returns the downsampled render buffer.
66 virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0;
Per Åhgrenc59a5762017-12-11 21:34:19 +010067
Per Åhgrenc59a5762017-12-11 21:34:19 +010068 // Returns the maximum non calusal offset that can occur in the delay buffer.
69 static int DelayEstimatorOffset(const EchoCanceller3Config& config);
Per Åhgrend0fa8202018-04-18 09:35:13 +020070
71 // Provides an optional external estimate of the audio buffer delay.
72 virtual void SetAudioBufferDelay(size_t delay_ms) = 0;
Gustaf Ullberg8f32b6c2019-04-05 16:23:50 +020073
74 // Returns whether an external delay estimate has been reported via
75 // SetAudioBufferDelay.
76 virtual bool HasReceivedBufferDelay() = 0;
peah69221db2017-01-27 03:28:19 -080077};
78
79} // namespace webrtc
80
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020081#endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_