Restructure the audioproc_f tool into a library with a thin executable wrapper.

This refactoring makes it easier to experiment with injectable components.

Bug: webrtc:8732
Change-Id: I2cd2a8ff80516a76aec814af02b61778915f2217
Reviewed-on: https://webrtc-review.googlesource.com/60863
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22372}
This commit is contained in:
Ivo Creusen 2018-03-09 17:33:04 +01:00 committed by Commit Bot
parent 45d9c1de9c
commit 8c812f3fc3
10 changed files with 88 additions and 17 deletions

View File

@ -669,7 +669,7 @@ if (rtc_include_tests) {
}
if (rtc_enable_protobuf) {
rtc_executable("audioproc_f") {
rtc_source_set("audioproc_f_impl") {
testonly = true
sources = [
"test/aec_dump_based_simulator.cc",
@ -677,6 +677,7 @@ if (rtc_include_tests) {
"test/audio_processing_simulator.cc",
"test/audio_processing_simulator.h",
"test/audioproc_float.cc",
"test/audioproc_float.h",
"test/wav_based_simulator.cc",
"test/wav_based_simulator.h",
]
@ -703,6 +704,17 @@ if (rtc_include_tests) {
"aec_dump:aec_dump_impl",
"//testing/gtest",
]
} # audioproc_f_impl
rtc_executable("audioproc_f") {
testonly = true
sources = [
"test/audioproc_float_main.cc",
]
deps = [
":audio_processing",
":audioproc_f_impl",
"../../rtc_base:rtc_base_approved",
]
} # audioproc_f
}

View File

@ -62,8 +62,10 @@ bool VerifyFloatBitExactness(const webrtc::audioproc::Stream& msg,
} // namespace
AecDumpBasedSimulator::AecDumpBasedSimulator(const SimulationSettings& settings)
: AudioProcessingSimulator(settings) {}
AecDumpBasedSimulator::AecDumpBasedSimulator(
const SimulationSettings& settings,
std::unique_ptr<AudioProcessingBuilder> ap_builder)
: AudioProcessingSimulator(settings, std::move(ap_builder)) {}
AecDumpBasedSimulator::~AecDumpBasedSimulator() = default;

View File

@ -30,7 +30,8 @@ namespace test {
// Used to perform an audio processing simulation from an aec dump.
class AecDumpBasedSimulator final : public AudioProcessingSimulator {
public:
explicit AecDumpBasedSimulator(const SimulationSettings& settings);
AecDumpBasedSimulator(const SimulationSettings& settings,
std::unique_ptr<AudioProcessingBuilder> ap_builder);
~AecDumpBasedSimulator() override;
// Processes the messages in the aecdump file.

View File

@ -26,6 +26,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/json.h"
#include "rtc_base/logging.h"
#include "rtc_base/ptr_util.h"
#include "rtc_base/stringutils.h"
namespace webrtc {
@ -303,8 +304,11 @@ void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) {
}
AudioProcessingSimulator::AudioProcessingSimulator(
const SimulationSettings& settings)
const SimulationSettings& settings,
std::unique_ptr<AudioProcessingBuilder> ap_builder)
: settings_(settings),
ap_builder_(ap_builder ? std::move(ap_builder)
: rtc::MakeUnique<AudioProcessingBuilder>()),
analog_mic_level_(settings.initial_mic_level),
fake_recording_device_(
settings.initial_mic_level,
@ -569,7 +573,8 @@ void AudioProcessingSimulator::CreateAudioProcessor() {
apm_config.residual_echo_detector.enabled = *settings_.use_ed;
}
ap_.reset(AudioProcessingBuilder()
RTC_CHECK(ap_builder_);
ap_.reset((*ap_builder_)
.SetEchoControlFactory(std::move(echo_control_factory))
.Create(config));
RTC_CHECK(ap_);

View File

@ -108,7 +108,8 @@ class AudioProcessingSimulator {
public:
static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs;
explicit AudioProcessingSimulator(const SimulationSettings& settings);
AudioProcessingSimulator(const SimulationSettings& settings,
std::unique_ptr<AudioProcessingBuilder> ap_builder);
virtual ~AudioProcessingSimulator();
// Processes the data in the input.
@ -157,6 +158,7 @@ class AudioProcessingSimulator {
const SimulationSettings settings_;
std::unique_ptr<AudioProcessing> ap_;
std::unique_ptr<AudioProcessingBuilder> ap_builder_;
std::unique_ptr<ChannelBuffer<float>> in_buf_;
std::unique_ptr<ChannelBuffer<float>> out_buf_;

View File

@ -16,6 +16,7 @@
#include "modules/audio_processing/include/audio_processing.h"
#include "modules/audio_processing/test/aec_dump_based_simulator.h"
#include "modules/audio_processing/test/audio_processing_simulator.h"
#include "modules/audio_processing/test/audioproc_float.h"
#include "modules/audio_processing/test/wav_based_simulator.h"
#include "rtc_base/flags.h"
@ -460,7 +461,9 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
} // namespace
int main(int argc, char* argv[]) {
int audioproc_f(std::unique_ptr<AudioProcessingBuilder> ap_builder,
int argc,
char* argv[]) {
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
FLAG_help || argc != 1) {
printf("%s", kUsageDescription);
@ -476,9 +479,9 @@ int main(int argc, char* argv[]) {
std::unique_ptr<AudioProcessingSimulator> processor;
if (settings.aec_dump_input_filename) {
processor.reset(new AecDumpBasedSimulator(settings));
processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder)));
} else {
processor.reset(new WavBasedSimulator(settings));
processor.reset(new WavBasedSimulator(settings, std::move(ap_builder)));
}
processor->Process();
@ -511,7 +514,3 @@ int main(int argc, char* argv[]) {
} // namespace test
} // namespace webrtc
int main(int argc, char* argv[]) {
return webrtc::test::main(argc, argv);
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2018 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.
*/
#ifndef MODULES_AUDIO_PROCESSING_TEST_AUDIOPROC_FLOAT_H_
#define MODULES_AUDIO_PROCESSING_TEST_AUDIOPROC_FLOAT_H_
#include <memory>
#include "modules/audio_processing/include/audio_processing.h"
namespace webrtc {
namespace test {
// This function implements the audio processing simulation utility.
int audioproc_f(std::unique_ptr<AudioProcessingBuilder> ap_builder,
int argc,
char* argv[]);
} // namespace test
} // namespace webrtc
#endif // MODULES_AUDIO_PROCESSING_TEST_AUDIOPROC_FLOAT_H_

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2018 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 "modules/audio_processing/include/audio_processing.h"
#include "modules/audio_processing/test/audioproc_float.h"
#include "rtc_base/ptr_util.h"
int main(int argc, char* argv[]) {
return webrtc::test::audioproc_f(
rtc::MakeUnique<webrtc::AudioProcessingBuilder>(), argc, argv);
}

View File

@ -53,8 +53,10 @@ WavBasedSimulator::GetCustomEventChain(const std::string& filename) {
return call_chain;
}
WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings)
: AudioProcessingSimulator(settings) {}
WavBasedSimulator::WavBasedSimulator(
const SimulationSettings& settings,
std::unique_ptr<AudioProcessingBuilder> ap_builder)
: AudioProcessingSimulator(settings, std::move(ap_builder)) {}
WavBasedSimulator::~WavBasedSimulator() = default;

View File

@ -23,7 +23,8 @@ namespace test {
// Used to perform an audio processing simulation from wav files.
class WavBasedSimulator final : public AudioProcessingSimulator {
public:
explicit WavBasedSimulator(const SimulationSettings& settings);
WavBasedSimulator(const SimulationSettings& settings,
std::unique_ptr<AudioProcessingBuilder> ap_builder);
~WavBasedSimulator() override;
// Processes the WAV input.