echo_emulation.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2019 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 TEST_PC_E2E_ECHO_ECHO_EMULATION_H_
  11. #define TEST_PC_E2E_ECHO_ECHO_EMULATION_H_
  12. #include <atomic>
  13. #include <deque>
  14. #include <memory>
  15. #include <vector>
  16. #include "api/test/peerconnection_quality_test_fixture.h"
  17. #include "modules/audio_device/include/test_audio_device.h"
  18. #include "rtc_base/swap_queue.h"
  19. namespace webrtc {
  20. namespace webrtc_pc_e2e {
  21. // Reduces audio input strength from provided capturer twice and adds input
  22. // provided into EchoEmulatingCapturer::OnAudioRendered(...).
  23. class EchoEmulatingCapturer : public TestAudioDeviceModule::Capturer {
  24. public:
  25. EchoEmulatingCapturer(
  26. std::unique_ptr<TestAudioDeviceModule::Capturer> capturer,
  27. PeerConnectionE2EQualityTestFixture::EchoEmulationConfig config);
  28. void OnAudioRendered(rtc::ArrayView<const int16_t> data);
  29. int SamplingFrequency() const override {
  30. return delegate_->SamplingFrequency();
  31. }
  32. int NumChannels() const override { return delegate_->NumChannels(); }
  33. bool Capture(rtc::BufferT<int16_t>* buffer) override;
  34. private:
  35. std::unique_ptr<TestAudioDeviceModule::Capturer> delegate_;
  36. const PeerConnectionE2EQualityTestFixture::EchoEmulationConfig config_;
  37. SwapQueue<std::vector<int16_t>> renderer_queue_;
  38. SequenceChecker renderer_thread_;
  39. std::vector<int16_t> queue_input_ RTC_GUARDED_BY(renderer_thread_);
  40. bool recording_started_ RTC_GUARDED_BY(renderer_thread_) = false;
  41. SequenceChecker capturer_thread_;
  42. std::vector<int16_t> queue_output_ RTC_GUARDED_BY(capturer_thread_);
  43. bool delay_accumulated_ RTC_GUARDED_BY(capturer_thread_) = false;
  44. };
  45. // Renders output into provided renderer and also copy output into provided
  46. // EchoEmulationCapturer.
  47. class EchoEmulatingRenderer : public TestAudioDeviceModule::Renderer {
  48. public:
  49. EchoEmulatingRenderer(
  50. std::unique_ptr<TestAudioDeviceModule::Renderer> renderer,
  51. EchoEmulatingCapturer* echo_emulating_capturer);
  52. int SamplingFrequency() const override {
  53. return delegate_->SamplingFrequency();
  54. }
  55. int NumChannels() const override { return delegate_->NumChannels(); }
  56. bool Render(rtc::ArrayView<const int16_t> data) override;
  57. private:
  58. std::unique_ptr<TestAudioDeviceModule::Renderer> delegate_;
  59. EchoEmulatingCapturer* echo_emulating_capturer_;
  60. };
  61. } // namespace webrtc_pc_e2e
  62. } // namespace webrtc
  63. #endif // TEST_PC_E2E_ECHO_ECHO_EMULATION_H_