render_delay_buffer.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
  12. #include <stddef.h>
  13. #include <vector>
  14. #include "api/audio/echo_canceller3_config.h"
  15. #include "modules/audio_processing/aec3/downsampled_render_buffer.h"
  16. #include "modules/audio_processing/aec3/render_buffer.h"
  17. namespace webrtc {
  18. // Class for buffering the incoming render blocks such that these may be
  19. // extracted with a specified delay.
  20. class RenderDelayBuffer {
  21. public:
  22. enum class BufferingEvent {
  23. kNone,
  24. kRenderUnderrun,
  25. kRenderOverrun,
  26. kApiCallSkew
  27. };
  28. static RenderDelayBuffer* Create(const EchoCanceller3Config& config,
  29. int sample_rate_hz,
  30. size_t num_render_channels);
  31. virtual ~RenderDelayBuffer() = default;
  32. // Resets the buffer alignment.
  33. virtual void Reset() = 0;
  34. // Inserts a block into the buffer.
  35. virtual BufferingEvent Insert(
  36. const std::vector<std::vector<std::vector<float>>>& block) = 0;
  37. // Updates the buffers one step based on the specified buffer delay. Returns
  38. // an enum indicating whether there was a special event that occurred.
  39. virtual BufferingEvent PrepareCaptureProcessing() = 0;
  40. // Called on capture blocks where PrepareCaptureProcessing is not called.
  41. virtual void HandleSkippedCaptureProcessing() = 0;
  42. // Sets the buffer delay and returns a bool indicating whether the delay
  43. // changed.
  44. virtual bool AlignFromDelay(size_t delay) = 0;
  45. // Sets the buffer delay from the most recently reported external delay.
  46. virtual void AlignFromExternalDelay() = 0;
  47. // Gets the buffer delay.
  48. virtual size_t Delay() const = 0;
  49. // Gets the buffer delay.
  50. virtual size_t MaxDelay() const = 0;
  51. // Returns the render buffer for the echo remover.
  52. virtual RenderBuffer* GetRenderBuffer() = 0;
  53. // Returns the downsampled render buffer.
  54. virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0;
  55. // Returns the maximum non calusal offset that can occur in the delay buffer.
  56. static int DelayEstimatorOffset(const EchoCanceller3Config& config);
  57. // Provides an optional external estimate of the audio buffer delay.
  58. virtual void SetAudioBufferDelay(int delay_ms) = 0;
  59. // Returns whether an external delay estimate has been reported via
  60. // SetAudioBufferDelay.
  61. virtual bool HasReceivedBufferDelay() = 0;
  62. };
  63. } // namespace webrtc
  64. #endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_