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