blob: bb895b589b67a2c13a5a8c54f4b5c192798ba872 [file] [log] [blame]
andrew@webrtc.org60730cf2014-01-07 17:45:09 +00001/*
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
11#include "webrtc/modules/audio_processing/audio_processing_impl.h"
12
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000013#include "webrtc/modules/audio_processing/test/test_utils.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010014#include "webrtc/modules/include/module_common_types.h"
kwibergac9f8762016-09-30 22:29:43 -070015#include "webrtc/test/gmock.h"
16#include "webrtc/test/gtest.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000017
18using ::testing::Invoke;
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000019
20namespace webrtc {
peaha9cc40b2017-06-29 08:32:09 -070021namespace {
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000022
23class MockInitialize : public AudioProcessingImpl {
24 public:
peah88ac8532016-09-12 16:47:25 -070025 explicit MockInitialize(const webrtc::Config& config)
26 : AudioProcessingImpl(config) {}
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000027
andrew@webrtc.orge84978f2014-01-25 02:09:06 +000028 MOCK_METHOD0(InitializeLocked, int());
danilchap56359be2017-09-07 07:53:45 -070029 int RealInitializeLocked() RTC_NO_THREAD_SAFETY_ANALYSIS {
pbos@webrtc.org788acd12014-12-15 09:41:24 +000030 return AudioProcessingImpl::InitializeLocked();
31 }
peaha9cc40b2017-06-29 08:32:09 -070032
33 MOCK_CONST_METHOD0(AddRef, int());
34 MOCK_CONST_METHOD0(Release, int());
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000035};
36
peaha9cc40b2017-06-29 08:32:09 -070037} // namespace
38
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000039TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
peah88ac8532016-09-12 16:47:25 -070040 webrtc::Config config;
andrew@webrtc.orge84978f2014-01-25 02:09:06 +000041 MockInitialize mock(config);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000042 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;
peah2ace3f92016-09-10 04:42:27 -070049 // Call with the default parameters; there should be an init.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000050 frame.num_channels_ = 1;
51 SetFrameSampleRate(&frame, 16000);
Per Ã…hgren4bdced52017-06-27 16:00:38 +020052 EXPECT_CALL(mock, InitializeLocked()).Times(0);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000053 EXPECT_NOERR(mock.ProcessStream(&frame));
aluebsb0319552016-03-17 20:39:53 -070054 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000055
56 // New sample rate. (Only impacts ProcessStream).
57 SetFrameSampleRate(&frame, 32000);
58 EXPECT_CALL(mock, InitializeLocked())
59 .Times(1);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000060 EXPECT_NOERR(mock.ProcessStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000061
62 // New number of channels.
peah2ace3f92016-09-10 04:42:27 -070063 // TODO(peah): Investigate why this causes 2 inits.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000064 frame.num_channels_ = 2;
65 EXPECT_CALL(mock, InitializeLocked())
66 .Times(2);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000067 EXPECT_NOERR(mock.ProcessStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000068 // ProcessStream sets num_channels_ == num_output_channels.
69 frame.num_channels_ = 2;
aluebsb0319552016-03-17 20:39:53 -070070 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000071
aluebsb0319552016-03-17 20:39:53 -070072 // A new sample rate passed to ProcessReverseStream should cause an init.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000073 SetFrameSampleRate(&frame, 16000);
Alex Luebs5b830fe2016-03-08 17:52:52 +010074 EXPECT_CALL(mock, InitializeLocked()).Times(1);
aluebsb0319552016-03-17 20:39:53 -070075 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000076}
77
78} // namespace webrtc