andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/audio_processing_impl.h" |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "modules/audio_processing/test/test_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "test/gmock.h" |
| 15 | #include "test/gtest.h" |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 16 | |
| 17 | using ::testing::Invoke; |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 20 | namespace { |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 21 | |
| 22 | class MockInitialize : public AudioProcessingImpl { |
| 23 | public: |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 24 | explicit MockInitialize(const webrtc::Config& config) |
| 25 | : AudioProcessingImpl(config) {} |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 26 | |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 27 | MOCK_METHOD0(InitializeLocked, int()); |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 28 | int RealInitializeLocked() RTC_NO_THREAD_SAFETY_ANALYSIS { |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 29 | return AudioProcessingImpl::InitializeLocked(); |
| 30 | } |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 31 | |
Niels Möller | 6f72f56 | 2017-10-19 13:15:17 +0200 | [diff] [blame] | 32 | MOCK_CONST_METHOD0(AddRef, void()); |
| 33 | MOCK_CONST_METHOD0(Release, rtc::RefCountReleaseStatus()); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 36 | } // namespace |
| 37 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 38 | TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) { |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 39 | webrtc::Config config; |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 40 | MockInitialize mock(config); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 41 | ON_CALL(mock, InitializeLocked()) |
| 42 | .WillByDefault(Invoke(&mock, &MockInitialize::RealInitializeLocked)); |
| 43 | |
| 44 | EXPECT_CALL(mock, InitializeLocked()).Times(1); |
| 45 | mock.Initialize(); |
| 46 | |
| 47 | AudioFrame frame; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 48 | // Call with the default parameters; there should be an init. |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 49 | frame.num_channels_ = 1; |
| 50 | SetFrameSampleRate(&frame, 16000); |
Per Åhgren | 4bdced5 | 2017-06-27 16:00:38 +0200 | [diff] [blame] | 51 | EXPECT_CALL(mock, InitializeLocked()).Times(0); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 52 | EXPECT_NOERR(mock.ProcessStream(&frame)); |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 53 | EXPECT_NOERR(mock.ProcessReverseStream(&frame)); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 54 | |
| 55 | // New sample rate. (Only impacts ProcessStream). |
| 56 | SetFrameSampleRate(&frame, 32000); |
| 57 | EXPECT_CALL(mock, InitializeLocked()) |
| 58 | .Times(1); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 59 | EXPECT_NOERR(mock.ProcessStream(&frame)); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 60 | |
| 61 | // New number of channels. |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 62 | // TODO(peah): Investigate why this causes 2 inits. |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 63 | frame.num_channels_ = 2; |
| 64 | EXPECT_CALL(mock, InitializeLocked()) |
| 65 | .Times(2); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 66 | EXPECT_NOERR(mock.ProcessStream(&frame)); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 67 | // ProcessStream sets num_channels_ == num_output_channels. |
| 68 | frame.num_channels_ = 2; |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 69 | EXPECT_NOERR(mock.ProcessReverseStream(&frame)); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 70 | |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 71 | // A new sample rate passed to ProcessReverseStream should cause an init. |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 72 | SetFrameSampleRate(&frame, 16000); |
Alex Luebs | 5b830fe | 2016-03-08 17:52:52 +0100 | [diff] [blame] | 73 | EXPECT_CALL(mock, InitializeLocked()).Times(1); |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 74 | EXPECT_NOERR(mock.ProcessReverseStream(&frame)); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 77 | TEST(AudioProcessingImplTest, UpdateCapturePreGainRuntimeSetting) { |
| 78 | // TODO(bugs.chromium.org/9138): Implement this test as soon as the pre-gain |
| 79 | // sub-module is implemented and it is notified by HandleRuntimeSettings() |
| 80 | // when the gain changes. |
| 81 | } |
| 82 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 83 | } // namespace webrtc |