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
11 #include <array>
12 #include <memory>
13 #include <utility>
14
15 #include "modules/audio_processing/aec_dump/mock_aec_dump.h"
16 #include "modules/audio_processing/audio_processing_impl.h"
17 #include "modules/audio_processing/include/audio_processing.h"
18 #include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
19
20 using ::testing::_;
21 using ::testing::AtLeast;
22 using ::testing::Exactly;
23 using ::testing::StrictMock;
24
25 namespace {
CreateAudioProcessing()26 rtc::scoped_refptr<webrtc::AudioProcessing> CreateAudioProcessing() {
27 rtc::scoped_refptr<webrtc::AudioProcessing> apm(
28 webrtc::AudioProcessingBuilderForTesting().Create());
29 RTC_DCHECK(apm);
30 return apm;
31 }
32
CreateMockAecDump()33 std::unique_ptr<webrtc::test::MockAecDump> CreateMockAecDump() {
34 auto mock_aec_dump =
35 std::make_unique<testing::StrictMock<webrtc::test::MockAecDump>>();
36 EXPECT_CALL(*mock_aec_dump.get(), WriteConfig(_)).Times(AtLeast(1));
37 EXPECT_CALL(*mock_aec_dump.get(), WriteInitMessage(_, _)).Times(AtLeast(1));
38 return std::unique_ptr<webrtc::test::MockAecDump>(std::move(mock_aec_dump));
39 }
40
41 } // namespace
42
TEST(AecDumpIntegration,ConfigurationAndInitShouldBeLogged)43 TEST(AecDumpIntegration, ConfigurationAndInitShouldBeLogged) {
44 auto apm = CreateAudioProcessing();
45
46 apm->AttachAecDump(CreateMockAecDump());
47 }
48
TEST(AecDumpIntegration,RenderStreamShouldBeLoggedOnceEveryProcessReverseStream)49 TEST(AecDumpIntegration,
50 RenderStreamShouldBeLoggedOnceEveryProcessReverseStream) {
51 auto apm = CreateAudioProcessing();
52 auto mock_aec_dump = CreateMockAecDump();
53 constexpr int kNumChannels = 1;
54 constexpr int kNumSampleRateHz = 16000;
55 constexpr int kNumSamplesPerChannel = kNumSampleRateHz / 100;
56 std::array<int16_t, kNumSamplesPerChannel * kNumChannels> frame;
57 frame.fill(0.f);
58 webrtc::StreamConfig stream_config(kNumSampleRateHz, kNumChannels);
59
60 EXPECT_CALL(*mock_aec_dump.get(), WriteRenderStreamMessage(_, _, _))
61 .Times(Exactly(1));
62
63 apm->AttachAecDump(std::move(mock_aec_dump));
64 apm->ProcessReverseStream(frame.data(), stream_config, stream_config,
65 frame.data());
66 }
67
TEST(AecDumpIntegration,CaptureStreamShouldBeLoggedOnceEveryProcessStream)68 TEST(AecDumpIntegration, CaptureStreamShouldBeLoggedOnceEveryProcessStream) {
69 auto apm = CreateAudioProcessing();
70 auto mock_aec_dump = CreateMockAecDump();
71 constexpr int kNumChannels = 1;
72 constexpr int kNumSampleRateHz = 16000;
73 constexpr int kNumSamplesPerChannel = kNumSampleRateHz / 100;
74 std::array<int16_t, kNumSamplesPerChannel * kNumChannels> frame;
75 frame.fill(0.f);
76
77 webrtc::StreamConfig stream_config(kNumSampleRateHz, kNumChannels);
78
79 EXPECT_CALL(*mock_aec_dump.get(), AddCaptureStreamInput(_, _, _))
80 .Times(AtLeast(1));
81
82 EXPECT_CALL(*mock_aec_dump.get(), AddCaptureStreamOutput(_, _, _))
83 .Times(Exactly(1));
84
85 EXPECT_CALL(*mock_aec_dump.get(), AddAudioProcessingState(_))
86 .Times(Exactly(1));
87
88 EXPECT_CALL(*mock_aec_dump.get(), WriteCaptureStreamMessage())
89 .Times(Exactly(1));
90
91 apm->AttachAecDump(std::move(mock_aec_dump));
92 apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data());
93 }
94