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"
|
|
|
|
|
|
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"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gmock.h"
|
|
|
|
|
#include "webrtc/test/gtest.h"
|
2014-01-07 17:45:09 +00:00
|
|
|
|
|
|
|
|
using ::testing::Invoke;
|
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class MockInitialize : public AudioProcessingImpl {
|
|
|
|
|
public:
|
2016-09-12 16:47:25 -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-12 16:47:25 -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;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
// Call with the default parameters; there should be an init.
|
2014-01-07 17:45:09 +00:00
|
|
|
frame.num_channels_ = 1;
|
|
|
|
|
SetFrameSampleRate(&frame, 16000);
|
2017-06-27 16:00:38 +02:00
|
|
|
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.
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
// TODO(peah): Investigate why this causes 2 inits.
|
2014-01-07 17:45:09 +00:00
|
|
|
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
|