blob: 08ac6233d5ff6ab48b5da4d6dc7bc4a34802f222 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/audio_processing_impl.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_processing/test/test_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "test/gmock.h"
15#include "test/gtest.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000016
17using ::testing::Invoke;
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000018
19namespace webrtc {
peaha9cc40b2017-06-29 08:32:09 -070020namespace {
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000021
22class MockInitialize : public AudioProcessingImpl {
23 public:
peah88ac8532016-09-12 16:47:25 -070024 explicit MockInitialize(const webrtc::Config& config)
25 : AudioProcessingImpl(config) {}
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000026
andrew@webrtc.orge84978f2014-01-25 02:09:06 +000027 MOCK_METHOD0(InitializeLocked, int());
danilchap56359be2017-09-07 07:53:45 -070028 int RealInitializeLocked() RTC_NO_THREAD_SAFETY_ANALYSIS {
pbos@webrtc.org788acd12014-12-15 09:41:24 +000029 return AudioProcessingImpl::InitializeLocked();
30 }
peaha9cc40b2017-06-29 08:32:09 -070031
Niels Möller6f72f562017-10-19 13:15:17 +020032 MOCK_CONST_METHOD0(AddRef, void());
33 MOCK_CONST_METHOD0(Release, rtc::RefCountReleaseStatus());
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000034};
35
peaha9cc40b2017-06-29 08:32:09 -070036} // namespace
37
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000038TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
peah88ac8532016-09-12 16:47:25 -070039 webrtc::Config config;
andrew@webrtc.orge84978f2014-01-25 02:09:06 +000040 MockInitialize mock(config);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000041 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;
peah2ace3f92016-09-10 04:42:27 -070048 // Call with the default parameters; there should be an init.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000049 frame.num_channels_ = 1;
50 SetFrameSampleRate(&frame, 16000);
Per Åhgren4bdced52017-06-27 16:00:38 +020051 EXPECT_CALL(mock, InitializeLocked()).Times(0);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000052 EXPECT_NOERR(mock.ProcessStream(&frame));
aluebsb0319552016-03-17 20:39:53 -070053 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000054
55 // New sample rate. (Only impacts ProcessStream).
56 SetFrameSampleRate(&frame, 32000);
57 EXPECT_CALL(mock, InitializeLocked())
58 .Times(1);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000059 EXPECT_NOERR(mock.ProcessStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000060
61 // New number of channels.
peah2ace3f92016-09-10 04:42:27 -070062 // TODO(peah): Investigate why this causes 2 inits.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000063 frame.num_channels_ = 2;
64 EXPECT_CALL(mock, InitializeLocked())
65 .Times(2);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000066 EXPECT_NOERR(mock.ProcessStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000067 // ProcessStream sets num_channels_ == num_output_channels.
68 frame.num_channels_ = 2;
aluebsb0319552016-03-17 20:39:53 -070069 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000070
aluebsb0319552016-03-17 20:39:53 -070071 // A new sample rate passed to ProcessReverseStream should cause an init.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000072 SetFrameSampleRate(&frame, 16000);
Alex Luebs5b830fe2016-03-08 17:52:52 +010073 EXPECT_CALL(mock, InitializeLocked()).Times(1);
aluebsb0319552016-03-17 20:39:53 -070074 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000075}
76
77} // namespace webrtc