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