2014-01-07 17:45:09 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/audio_processing/audio_processing_impl.h"
|
|
|
|
|
|
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
2014-03-11 16:55:14 +00:00
|
|
|
#include "webrtc/config.h"
|
2014-01-07 17:45:09 +00:00
|
|
|
#include "webrtc/modules/audio_processing/test/test_utils.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2014-01-07 17:45:09 +00:00
|
|
|
|
|
|
|
|
using ::testing::Invoke;
|
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class MockInitialize : public AudioProcessingImpl {
|
|
|
|
|
public:
|
2016-09-09 14:15:57 -07:00
|
|
|
explicit MockInitialize(const webrtc::Config& config)
|
|
|
|
|
: AudioProcessingImpl(config) {}
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2014-01-25 02:09:06 +00:00
|
|
|
MOCK_METHOD0(InitializeLocked, int());
|
2014-12-15 09:41:24 +00:00
|
|
|
int RealInitializeLocked() NO_THREAD_SAFETY_ANALYSIS {
|
|
|
|
|
return AudioProcessingImpl::InitializeLocked();
|
|
|
|
|
}
|
2014-01-07 17:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
|
2016-09-09 14:15:57 -07:00
|
|
|
webrtc::Config config;
|
2014-01-25 02:09:06 +00:00
|
|
|
MockInitialize mock(config);
|
2014-01-07 17:45:09 +00:00
|
|
|
ON_CALL(mock, InitializeLocked())
|
|
|
|
|
.WillByDefault(Invoke(&mock, &MockInitialize::RealInitializeLocked));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock, InitializeLocked()).Times(1);
|
|
|
|
|
mock.Initialize();
|
|
|
|
|
|
|
|
|
|
AudioFrame frame;
|
|
|
|
|
// Call with the default parameters; there should be no init.
|
|
|
|
|
frame.num_channels_ = 1;
|
|
|
|
|
SetFrameSampleRate(&frame, 16000);
|
|
|
|
|
EXPECT_CALL(mock, InitializeLocked())
|
|
|
|
|
.Times(0);
|
2014-03-10 22:26:12 +00:00
|
|
|
EXPECT_NOERR(mock.ProcessStream(&frame));
|
2016-03-17 20:39:53 -07:00
|
|
|
EXPECT_NOERR(mock.ProcessReverseStream(&frame));
|
2014-01-07 17:45:09 +00:00
|
|
|
|
|
|
|
|
// New sample rate. (Only impacts ProcessStream).
|
|
|
|
|
SetFrameSampleRate(&frame, 32000);
|
|
|
|
|
EXPECT_CALL(mock, InitializeLocked())
|
|
|
|
|
.Times(1);
|
2014-03-10 22:26:12 +00:00
|
|
|
EXPECT_NOERR(mock.ProcessStream(&frame));
|
2014-01-07 17:45:09 +00:00
|
|
|
|
|
|
|
|
// New number of channels.
|
|
|
|
|
frame.num_channels_ = 2;
|
|
|
|
|
EXPECT_CALL(mock, InitializeLocked())
|
|
|
|
|
.Times(2);
|
2014-03-10 22:26:12 +00:00
|
|
|
EXPECT_NOERR(mock.ProcessStream(&frame));
|
2014-01-07 17:45:09 +00:00
|
|
|
// ProcessStream sets num_channels_ == num_output_channels.
|
|
|
|
|
frame.num_channels_ = 2;
|
2016-03-17 20:39:53 -07:00
|
|
|
EXPECT_NOERR(mock.ProcessReverseStream(&frame));
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2016-03-17 20:39:53 -07:00
|
|
|
// A new sample rate passed to ProcessReverseStream should cause an init.
|
2014-01-07 17:45:09 +00:00
|
|
|
SetFrameSampleRate(&frame, 16000);
|
2016-03-08 17:52:52 +01:00
|
|
|
EXPECT_CALL(mock, InitializeLocked()).Times(1);
|
2016-03-17 20:39:53 -07:00
|
|
|
EXPECT_NOERR(mock.ProcessReverseStream(&frame));
|
2014-01-07 17:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|