2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-03-06 19:03:39 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#include <list>
|
2016-02-19 07:04:49 -08:00
|
|
|
#include <memory>
|
2015-07-23 11:41:39 -07:00
|
|
|
#include <vector>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-03-21 14:37:36 +01:00
|
|
|
#include "api/function_view.h"
|
2019-10-18 13:29:43 +02:00
|
|
|
#include "modules/audio_processing/aec3/echo_canceller3.h"
|
|
|
|
|
#include "modules/audio_processing/agc/agc_manager_direct.h"
|
2019-10-15 10:10:26 +02:00
|
|
|
#include "modules/audio_processing/agc/gain_control.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/audio_buffer.h"
|
2019-10-18 13:29:43 +02:00
|
|
|
#include "modules/audio_processing/echo_control_mobile_impl.h"
|
|
|
|
|
#include "modules/audio_processing/gain_control_impl.h"
|
|
|
|
|
#include "modules/audio_processing/gain_controller2.h"
|
|
|
|
|
#include "modules/audio_processing/high_pass_filter.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/include/aec_dump.h"
|
|
|
|
|
#include "modules/audio_processing/include/audio_processing.h"
|
2018-11-26 16:18:25 +01:00
|
|
|
#include "modules/audio_processing/include/audio_processing_statistics.h"
|
2019-12-13 15:05:48 +01:00
|
|
|
#include "modules/audio_processing/legacy_ns/legacy_noise_suppression.h"
|
2019-10-18 13:29:43 +02:00
|
|
|
#include "modules/audio_processing/level_estimator.h"
|
2019-10-29 22:59:44 +01:00
|
|
|
#include "modules/audio_processing/ns/noise_suppressor.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/render_queue_item_verifier.h"
|
2019-10-18 13:29:43 +02:00
|
|
|
#include "modules/audio_processing/residual_echo_detector.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/rms_level.h"
|
2019-10-18 13:29:43 +02:00
|
|
|
#include "modules/audio_processing/transient/transient_suppressor.h"
|
|
|
|
|
#include "modules/audio_processing/voice_detection.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/critical_section.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gtest_prod_util.h"
|
|
|
|
|
#include "rtc_base/ignore_wundef.h"
|
|
|
|
|
#include "rtc_base/swap_queue.h"
|
|
|
|
|
#include "rtc_base/thread_annotations.h"
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2018-02-12 21:42:56 +01:00
|
|
|
class ApmDataDumper;
|
2015-08-14 10:35:55 -07:00
|
|
|
class AudioConverter;
|
2015-03-25 16:37:27 -07:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
class AudioProcessingImpl : public AudioProcessing {
|
|
|
|
|
public:
|
2015-11-28 12:35:15 -08:00
|
|
|
// Methods forcing APM to run in a single-threaded manner.
|
|
|
|
|
// Acquires both the render and capture locks.
|
2016-09-12 16:47:25 -07:00
|
|
|
explicit AudioProcessingImpl(const webrtc::Config& config);
|
2018-06-21 10:12:24 +02:00
|
|
|
// AudioProcessingImpl takes ownership of capture post processor.
|
2016-09-12 16:47:25 -07:00
|
|
|
AudioProcessingImpl(const webrtc::Config& config,
|
2017-12-18 16:02:40 +01:00
|
|
|
std::unique_ptr<CustomProcessing> capture_post_processor,
|
|
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processor,
|
2017-10-12 15:13:17 +02:00
|
|
|
std::unique_ptr<EchoControlFactory> echo_control_factory,
|
2018-08-29 10:37:09 +02:00
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector,
|
|
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer);
|
2016-08-29 14:46:07 -07:00
|
|
|
~AudioProcessingImpl() override;
|
2015-03-04 12:58:35 +00:00
|
|
|
int Initialize() override;
|
2016-09-16 15:02:15 -07:00
|
|
|
int Initialize(int capture_input_sample_rate_hz,
|
|
|
|
|
int capture_output_sample_rate_hz,
|
|
|
|
|
int render_sample_rate_hz,
|
|
|
|
|
ChannelLayout capture_input_layout,
|
|
|
|
|
ChannelLayout capture_output_layout,
|
|
|
|
|
ChannelLayout render_input_layout) override;
|
2015-07-23 11:41:39 -07:00
|
|
|
int Initialize(const ProcessingConfig& processing_config) override;
|
2016-09-12 16:47:25 -07:00
|
|
|
void ApplyConfig(const AudioProcessing::Config& config) override;
|
|
|
|
|
void SetExtraOptions(const webrtc::Config& config) override;
|
2015-11-28 12:35:15 -08:00
|
|
|
void UpdateHistogramsOnCallEnd() override;
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
void AttachAecDump(std::unique_ptr<AecDump> aec_dump) override;
|
|
|
|
|
void DetachAecDump() override;
|
2018-03-02 16:03:21 +01:00
|
|
|
void AttachPlayoutAudioGenerator(
|
|
|
|
|
std::unique_ptr<AudioGenerator> audio_generator) override;
|
|
|
|
|
void DetachPlayoutAudioGenerator() override;
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2018-04-16 12:10:09 +02:00
|
|
|
void SetRuntimeSetting(RuntimeSetting setting) override;
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
// Capture-side exclusive methods possibly running APM in a
|
|
|
|
|
// multi-threaded manner. Acquire the capture lock.
|
2015-03-04 12:58:35 +00:00
|
|
|
int ProcessStream(AudioFrame* frame) override;
|
2015-07-23 11:41:39 -07:00
|
|
|
int ProcessStream(const float* const* src,
|
|
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config,
|
|
|
|
|
float* const* dest) override;
|
2019-11-13 11:12:29 +01:00
|
|
|
bool GetLinearAecOutput(
|
|
|
|
|
rtc::ArrayView<std::array<float, 160>> linear_output) const override;
|
2015-11-28 12:35:15 -08:00
|
|
|
void set_output_will_be_muted(bool muted) override;
|
|
|
|
|
int set_stream_delay_ms(int delay) override;
|
|
|
|
|
void set_delay_offset_ms(int offset) override;
|
|
|
|
|
int delay_offset_ms() const override;
|
|
|
|
|
void set_stream_key_pressed(bool key_pressed) override;
|
2019-03-27 13:28:08 +01:00
|
|
|
void set_stream_analog_level(int level) override;
|
|
|
|
|
int recommended_stream_analog_level() const override;
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
// Render-side exclusive methods possibly running APM in a
|
|
|
|
|
// multi-threaded manner. Acquire the render lock.
|
2015-08-14 10:35:55 -07:00
|
|
|
int ProcessReverseStream(AudioFrame* frame) override;
|
2019-10-22 15:21:31 +02:00
|
|
|
int AnalyzeReverseStream(const float* const* data,
|
|
|
|
|
const StreamConfig& reverse_config) override;
|
2015-08-14 10:35:55 -07:00
|
|
|
int ProcessReverseStream(const float* const* src,
|
2016-09-16 15:02:15 -07:00
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config,
|
2015-08-14 10:35:55 -07:00
|
|
|
float* const* dest) override;
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
// Methods only accessed from APM submodules or
|
|
|
|
|
// from AudioProcessing tests in a single-threaded manner.
|
|
|
|
|
// Hence there is no need for locks in these.
|
|
|
|
|
int proc_sample_rate_hz() const override;
|
|
|
|
|
int proc_split_sample_rate_hz() const override;
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t num_input_channels() const override;
|
|
|
|
|
size_t num_proc_channels() const override;
|
|
|
|
|
size_t num_output_channels() const override;
|
|
|
|
|
size_t num_reverse_channels() const override;
|
2015-03-04 12:58:35 +00:00
|
|
|
int stream_delay_ms() const override;
|
2015-11-28 12:35:15 -08:00
|
|
|
bool was_stream_delay_set() const override
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2019-12-30 14:32:14 +01:00
|
|
|
AudioProcessingStats GetStatistics(bool has_remote_tracks) override {
|
|
|
|
|
return GetStatistics();
|
|
|
|
|
}
|
|
|
|
|
AudioProcessingStats GetStatistics() override {
|
|
|
|
|
return stats_reporter_.GetStatistics();
|
|
|
|
|
}
|
2016-10-28 07:55:33 -07:00
|
|
|
|
2017-04-05 05:48:24 -07:00
|
|
|
// TODO(peah): Remove MutateConfig once the new API allows that.
|
2016-11-22 07:24:52 -08:00
|
|
|
void MutateConfig(rtc::FunctionView<void(AudioProcessing::Config*)> mutator);
|
2017-04-05 05:48:24 -07:00
|
|
|
AudioProcessing::Config GetConfig() const override;
|
2016-11-22 07:24:52 -08:00
|
|
|
|
2014-01-07 17:45:09 +00:00
|
|
|
protected:
|
2014-03-10 22:26:12 +00:00
|
|
|
// Overridden in a mock.
|
2015-11-28 12:35:15 -08:00
|
|
|
virtual int InitializeLocked()
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
private:
|
2016-10-07 14:54:10 -07:00
|
|
|
// TODO(peah): These friend classes should be removed as soon as the new
|
|
|
|
|
// parameter setting scheme allows.
|
|
|
|
|
FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, DefaultBehavior);
|
|
|
|
|
FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, ValidConfigBehavior);
|
|
|
|
|
FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, InValidConfigBehavior);
|
2018-04-16 12:10:09 +02:00
|
|
|
|
|
|
|
|
// Class providing thread-safe message pipe functionality for
|
|
|
|
|
// |runtime_settings_|.
|
|
|
|
|
class RuntimeSettingEnqueuer {
|
|
|
|
|
public:
|
|
|
|
|
explicit RuntimeSettingEnqueuer(
|
|
|
|
|
SwapQueue<RuntimeSetting>* runtime_settings);
|
|
|
|
|
~RuntimeSettingEnqueuer();
|
|
|
|
|
void Enqueue(RuntimeSetting setting);
|
|
|
|
|
|
|
|
|
|
private:
|
2018-04-20 13:16:55 +02:00
|
|
|
SwapQueue<RuntimeSetting>& runtime_settings_;
|
2018-05-15 10:52:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
|
|
|
|
static int instance_count_;
|
2019-10-29 22:59:44 +01:00
|
|
|
const bool enforced_usage_of_legacy_ns_;
|
2019-12-02 14:59:40 +01:00
|
|
|
const bool use_setup_specific_default_aec3_config_;
|
2018-05-15 10:52:28 +02:00
|
|
|
|
|
|
|
|
SwapQueue<RuntimeSetting> capture_runtime_settings_;
|
|
|
|
|
SwapQueue<RuntimeSetting> render_runtime_settings_;
|
|
|
|
|
|
|
|
|
|
RuntimeSettingEnqueuer capture_runtime_settings_enqueuer_;
|
|
|
|
|
RuntimeSettingEnqueuer render_runtime_settings_enqueuer_;
|
2018-04-16 12:10:09 +02:00
|
|
|
|
2017-10-12 15:13:17 +02:00
|
|
|
// EchoControl factory.
|
|
|
|
|
std::unique_ptr<EchoControlFactory> echo_control_factory_;
|
2017-10-11 16:29:02 +02:00
|
|
|
|
2019-10-18 13:29:43 +02:00
|
|
|
class SubmoduleStates {
|
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
|
|
|
public:
|
2019-10-18 13:29:43 +02:00
|
|
|
SubmoduleStates(bool capture_post_processor_enabled,
|
|
|
|
|
bool render_pre_processor_enabled,
|
|
|
|
|
bool capture_analyzer_enabled);
|
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
|
|
|
// Updates the submodule state and returns true if it has changed.
|
2018-09-28 14:15:09 +02:00
|
|
|
bool Update(bool high_pass_filter_enabled,
|
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
|
|
|
bool mobile_echo_controller_enabled,
|
2016-10-28 05:39:16 -07:00
|
|
|
bool residual_echo_detector_enabled,
|
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
|
|
|
bool noise_suppressor_enabled,
|
|
|
|
|
bool adaptive_gain_controller_enabled,
|
2017-05-22 06:57:06 -07:00
|
|
|
bool gain_controller2_enabled,
|
2018-04-16 16:31:22 +02:00
|
|
|
bool pre_amplifier_enabled,
|
2017-10-16 13:49:04 +02:00
|
|
|
bool echo_controller_enabled,
|
2019-10-07 14:03:56 +02:00
|
|
|
bool voice_detector_enabled,
|
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
|
|
|
bool transient_suppressor_enabled);
|
|
|
|
|
bool CaptureMultiBandSubModulesActive() const;
|
2019-10-09 13:34:36 +02:00
|
|
|
bool CaptureMultiBandProcessingPresent() const;
|
|
|
|
|
bool CaptureMultiBandProcessingActive(bool ec_processing_active) const;
|
2017-05-23 05:33:56 -07:00
|
|
|
bool CaptureFullBandProcessingActive() const;
|
2018-08-29 10:37:09 +02:00
|
|
|
bool CaptureAnalyzerActive() const;
|
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
|
|
|
bool RenderMultiBandSubModulesActive() const;
|
2017-12-18 16:02:40 +01:00
|
|
|
bool RenderFullBandProcessingActive() const;
|
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
|
|
|
bool RenderMultiBandProcessingActive() const;
|
2019-08-23 21:29:17 +02:00
|
|
|
bool HighPassFilteringRequired() const;
|
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
|
|
|
|
|
|
|
|
private:
|
2017-09-25 12:04:02 +02:00
|
|
|
const bool capture_post_processor_enabled_ = false;
|
2017-12-18 16:02:40 +01:00
|
|
|
const bool render_pre_processor_enabled_ = false;
|
2018-08-29 10:37:09 +02:00
|
|
|
const bool capture_analyzer_enabled_ = false;
|
2018-09-28 14:15:09 +02:00
|
|
|
bool high_pass_filter_enabled_ = false;
|
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
|
|
|
bool mobile_echo_controller_enabled_ = false;
|
2016-10-28 05:39:16 -07:00
|
|
|
bool residual_echo_detector_enabled_ = false;
|
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
|
|
|
bool noise_suppressor_enabled_ = false;
|
|
|
|
|
bool adaptive_gain_controller_enabled_ = false;
|
2017-05-22 06:57:06 -07:00
|
|
|
bool gain_controller2_enabled_ = false;
|
2018-04-16 16:31:22 +02:00
|
|
|
bool pre_amplifier_enabled_ = false;
|
2017-10-16 13:49:04 +02:00
|
|
|
bool echo_controller_enabled_ = false;
|
2019-10-07 14:03:56 +02:00
|
|
|
bool voice_detector_enabled_ = false;
|
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
|
|
|
bool transient_suppressor_enabled_ = false;
|
|
|
|
|
bool first_update_ = true;
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
// Method for modifying the formats struct that are called from both
|
|
|
|
|
// the render and capture threads. The check for whether modifications
|
|
|
|
|
// are needed is done while holding the render lock only, thereby avoiding
|
|
|
|
|
// that the capture thread blocks the render thread.
|
|
|
|
|
// The struct is modified in a single-threaded manner by holding both the
|
|
|
|
|
// render and capture locks.
|
|
|
|
|
int MaybeInitializeRender(const ProcessingConfig& processing_config)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
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
|
|
|
// Method for updating the state keeping track of the active submodules.
|
|
|
|
|
// Returns a bool indicating whether the state has changed.
|
2017-09-07 07:53:45 -07:00
|
|
|
bool UpdateActiveSubmoduleStates()
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2020-01-02 15:15:36 +01:00
|
|
|
// Methods requiring APM running in a single-threaded manner, requiring both
|
|
|
|
|
// the render and capture lock to be acquired.
|
2015-07-23 11:41:39 -07:00
|
|
|
int InitializeLocked(const ProcessingConfig& config)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
|
2016-10-28 05:39:16 -07:00
|
|
|
void InitializeResidualEchoDetector()
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
|
2019-04-25 15:18:06 +02:00
|
|
|
void InitializeEchoController()
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
|
2020-01-02 15:15:36 +01:00
|
|
|
|
|
|
|
|
// Initializations of capture-only submodules, requiring the capture lock
|
|
|
|
|
// already acquired.
|
|
|
|
|
void InitializeHighPassFilter() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
|
|
|
|
void InitializeVoiceDetector() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
|
|
|
|
void InitializeTransientSuppressor()
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2017-09-25 12:04:02 +02:00
|
|
|
void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2019-10-16 11:46:11 +02:00
|
|
|
void InitializeNoiseSuppressor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2018-04-16 16:31:22 +02:00
|
|
|
void InitializePreAmplifier() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2017-09-25 12:04:02 +02:00
|
|
|
void InitializePostProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2018-08-29 10:37:09 +02:00
|
|
|
void InitializeAnalyzer() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2020-01-02 15:15:36 +01:00
|
|
|
|
|
|
|
|
// Initializations of render-only submodules, requiring the render lock
|
|
|
|
|
// already acquired.
|
2017-12-18 16:02:40 +01:00
|
|
|
void InitializePreProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2019-10-09 13:02:14 +02:00
|
|
|
// Sample rate used for the fullband processing.
|
|
|
|
|
int proc_fullband_sample_rate_hz() const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
|
|
|
|
|
2018-05-15 10:52:28 +02:00
|
|
|
// Empties and handles the respective RuntimeSetting queues.
|
|
|
|
|
void HandleCaptureRuntimeSettings()
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
|
|
|
|
void HandleRenderRuntimeSettings() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
2019-03-27 13:28:08 +01:00
|
|
|
void ApplyAgc1Config(const Config::GainController1& agc_config)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
|
|
|
|
|
2016-10-22 05:04:30 -07:00
|
|
|
void EmptyQueuedRenderAudio();
|
|
|
|
|
void AllocateRenderQueue()
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
|
2017-05-15 07:19:21 -07:00
|
|
|
void QueueBandedRenderAudio(AudioBuffer* audio)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
2017-05-15 07:19:21 -07:00
|
|
|
void QueueNonbandedRenderAudio(AudioBuffer* audio)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
2016-10-22 05:04:30 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
// Capture-side exclusive methods possibly running APM in a multi-threaded
|
|
|
|
|
// manner that are called with the render lock already acquired.
|
2017-09-07 07:53:45 -07:00
|
|
|
int ProcessCaptureStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
// Render-side exclusive methods possibly running APM in a multi-threaded
|
|
|
|
|
// manner that are called with the render lock already acquired.
|
2015-08-14 10:35:55 -07:00
|
|
|
// TODO(ekm): Remove once all clients updated to new interface.
|
2015-11-28 12:35:15 -08:00
|
|
|
int AnalyzeReverseStreamLocked(const float* const* src,
|
|
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
|
|
|
|
int ProcessRenderStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
// Collects configuration settings from public and private
|
|
|
|
|
// submodules to be saved as an audioproc::Config message on the
|
|
|
|
|
// AecDump if it is attached. If not |forced|, only writes the current
|
|
|
|
|
// config if it is different from the last saved one; if |forced|,
|
|
|
|
|
// writes the config regardless of the last saved.
|
|
|
|
|
void WriteAecDumpConfigMessage(bool forced)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
// Notifies attached AecDump of current configuration and capture data.
|
|
|
|
|
void RecordUnprocessedCaptureStream(const float* const* capture_stream)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
void RecordUnprocessedCaptureStream(const AudioFrame& capture_frame)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
// Notifies attached AecDump of current configuration and
|
|
|
|
|
// processed capture data and issues a capture stream recording
|
|
|
|
|
// request.
|
|
|
|
|
void RecordProcessedCaptureStream(
|
|
|
|
|
const float* const* processed_capture_stream)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
void RecordProcessedCaptureStream(const AudioFrame& processed_capture_frame)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
// Notifies attached AecDump about current state (delay, drift, etc).
|
2017-09-07 07:53:45 -07:00
|
|
|
void RecordAudioProcessingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
// AecDump instance used for optionally logging APM config, input
|
|
|
|
|
// and output to file in the AEC-dump format defined in debug.proto.
|
|
|
|
|
std::unique_ptr<AecDump> aec_dump_;
|
|
|
|
|
|
|
|
|
|
// Hold the last config written with AecDump for avoiding writing
|
|
|
|
|
// the same config twice.
|
2017-09-07 07:53:45 -07:00
|
|
|
InternalAPMConfig apm_config_for_aec_dump_ RTC_GUARDED_BY(crit_capture_);
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
// Critical sections.
|
2017-09-07 07:53:45 -07:00
|
|
|
rtc::CriticalSection crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_);
|
2016-01-25 03:52:44 -08:00
|
|
|
rtc::CriticalSection crit_capture_;
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2016-10-07 14:54:10 -07:00
|
|
|
// Struct containing the Config specifying the behavior of APM.
|
|
|
|
|
AudioProcessing::Config config_;
|
|
|
|
|
|
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
|
|
|
// Class containing information about what submodules are active.
|
2019-10-18 13:29:43 +02:00
|
|
|
SubmoduleStates submodule_states_;
|
|
|
|
|
|
|
|
|
|
// Struct containing the pointers to the submodules.
|
|
|
|
|
struct Submodules {
|
|
|
|
|
Submodules(std::unique_ptr<CustomProcessing> capture_post_processor,
|
|
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processor,
|
|
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector,
|
2019-11-22 12:11:40 +01:00
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
|
2019-10-18 13:29:43 +02:00
|
|
|
: echo_detector(std::move(echo_detector)),
|
|
|
|
|
capture_post_processor(std::move(capture_post_processor)),
|
|
|
|
|
render_pre_processor(std::move(render_pre_processor)),
|
2019-11-22 12:11:40 +01:00
|
|
|
capture_analyzer(std::move(capture_analyzer)) {}
|
2019-10-18 13:29:43 +02:00
|
|
|
// Accessed internally from capture or during initialization.
|
|
|
|
|
std::unique_ptr<AgcManagerDirect> agc_manager;
|
|
|
|
|
std::unique_ptr<GainControlImpl> gain_control;
|
|
|
|
|
std::unique_ptr<GainController2> gain_controller2;
|
|
|
|
|
std::unique_ptr<HighPassFilter> high_pass_filter;
|
|
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector;
|
|
|
|
|
std::unique_ptr<EchoControl> echo_controller;
|
|
|
|
|
std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
|
2019-10-29 22:59:44 +01:00
|
|
|
std::unique_ptr<NoiseSuppression> legacy_noise_suppressor;
|
|
|
|
|
std::unique_ptr<NoiseSuppressor> noise_suppressor;
|
2019-10-18 13:29:43 +02:00
|
|
|
std::unique_ptr<TransientSuppressor> transient_suppressor;
|
|
|
|
|
std::unique_ptr<CustomProcessing> capture_post_processor;
|
|
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processor;
|
|
|
|
|
std::unique_ptr<GainApplier> pre_amplifier;
|
|
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer;
|
|
|
|
|
std::unique_ptr<LevelEstimator> output_level_estimator;
|
|
|
|
|
std::unique_ptr<VoiceDetection> voice_detector;
|
|
|
|
|
} submodules_;
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2015-11-17 02:16:45 -08:00
|
|
|
// State that is written to while holding both the render and capture locks
|
2015-11-28 12:35:15 -08:00
|
|
|
// but can be read without any lock being held.
|
|
|
|
|
// As this is only accessed internally of APM, and all internal methods in APM
|
|
|
|
|
// either are holding the render or capture locks, this construct is safe as
|
|
|
|
|
// it is not possible to read the variables while writing them.
|
|
|
|
|
struct ApmFormatState {
|
|
|
|
|
ApmFormatState()
|
|
|
|
|
: // Format of processing streams at input/output call sites.
|
|
|
|
|
api_format({{{kSampleRate16kHz, 1, false},
|
|
|
|
|
{kSampleRate16kHz, 1, false},
|
|
|
|
|
{kSampleRate16kHz, 1, false},
|
|
|
|
|
{kSampleRate16kHz, 1, false}}}),
|
2016-09-16 15:02:15 -07:00
|
|
|
render_processing_format(kSampleRate16kHz, 1) {}
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig api_format;
|
2016-09-16 15:02:15 -07:00
|
|
|
StreamConfig render_processing_format;
|
2015-11-28 12:35:15 -08:00
|
|
|
} formats_;
|
|
|
|
|
|
|
|
|
|
// APM constants.
|
|
|
|
|
const struct ApmConstants {
|
2019-11-22 12:11:40 +01:00
|
|
|
ApmConstants(int agc_startup_min_volume,
|
|
|
|
|
int agc_clipped_level_min,
|
|
|
|
|
bool use_experimental_agc,
|
|
|
|
|
bool use_experimental_agc_agc2_level_estimation,
|
|
|
|
|
bool use_experimental_agc_agc2_digital_adaptive,
|
2019-11-27 09:34:22 +01:00
|
|
|
bool multi_channel_render_support,
|
2019-12-10 13:04:15 +01:00
|
|
|
bool multi_channel_capture_support,
|
|
|
|
|
bool enforce_split_band_hpf)
|
2019-11-22 12:11:40 +01:00
|
|
|
: agc_startup_min_volume(agc_startup_min_volume),
|
|
|
|
|
agc_clipped_level_min(agc_clipped_level_min),
|
|
|
|
|
use_experimental_agc(use_experimental_agc),
|
|
|
|
|
use_experimental_agc_agc2_level_estimation(
|
|
|
|
|
use_experimental_agc_agc2_level_estimation),
|
|
|
|
|
use_experimental_agc_agc2_digital_adaptive(
|
|
|
|
|
use_experimental_agc_agc2_digital_adaptive),
|
2019-11-27 09:34:22 +01:00
|
|
|
multi_channel_render_support(multi_channel_render_support),
|
2019-12-10 13:04:15 +01:00
|
|
|
multi_channel_capture_support(multi_channel_capture_support),
|
|
|
|
|
enforce_split_band_hpf(enforce_split_band_hpf) {}
|
2019-11-22 12:11:40 +01:00
|
|
|
int agc_startup_min_volume;
|
2016-12-05 09:08:42 -08:00
|
|
|
int agc_clipped_level_min;
|
2019-11-22 12:11:40 +01:00
|
|
|
bool use_experimental_agc;
|
|
|
|
|
bool use_experimental_agc_agc2_level_estimation;
|
|
|
|
|
bool use_experimental_agc_agc2_digital_adaptive;
|
2019-11-27 09:34:22 +01:00
|
|
|
bool multi_channel_render_support;
|
|
|
|
|
bool multi_channel_capture_support;
|
2019-12-10 13:04:15 +01:00
|
|
|
bool enforce_split_band_hpf;
|
2015-11-28 12:35:15 -08:00
|
|
|
} constants_;
|
|
|
|
|
|
|
|
|
|
struct ApmCaptureState {
|
2020-01-02 15:15:36 +01:00
|
|
|
ApmCaptureState();
|
2016-08-29 14:46:07 -07:00
|
|
|
~ApmCaptureState();
|
2015-11-28 12:35:15 -08:00
|
|
|
int delay_offset_ms;
|
|
|
|
|
bool was_stream_delay_set;
|
|
|
|
|
bool output_will_be_muted;
|
|
|
|
|
bool key_pressed;
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<AudioBuffer> capture_audio;
|
2019-10-09 13:02:14 +02:00
|
|
|
std::unique_ptr<AudioBuffer> capture_fullband_audio;
|
2019-11-13 11:12:29 +01:00
|
|
|
std::unique_ptr<AudioBuffer> linear_aec_output;
|
2016-09-16 15:02:15 -07:00
|
|
|
// Only the rate and samples fields of capture_processing_format_ are used
|
|
|
|
|
// because the capture processing number of channels is mutable and is
|
|
|
|
|
// tracked by the capture_audio_.
|
|
|
|
|
StreamConfig capture_processing_format;
|
2015-11-28 12:35:15 -08:00
|
|
|
int split_rate;
|
2017-04-10 14:12:41 -07:00
|
|
|
bool echo_path_gain_change;
|
2018-07-16 17:08:41 +02:00
|
|
|
int prev_analog_mic_level;
|
2018-10-02 17:00:59 +02:00
|
|
|
float prev_pre_amp_gain;
|
2019-05-10 15:50:02 +02:00
|
|
|
int playout_volume;
|
|
|
|
|
int prev_playout_volume;
|
2018-11-26 16:18:25 +01:00
|
|
|
AudioProcessingStats stats;
|
2019-08-15 12:15:46 +02:00
|
|
|
struct KeyboardInfo {
|
|
|
|
|
void Extract(const float* const* data, const StreamConfig& stream_config);
|
|
|
|
|
size_t num_keyboard_frames = 0;
|
|
|
|
|
const float* keyboard_data = nullptr;
|
|
|
|
|
} keyboard_info;
|
2017-09-07 07:53:45 -07:00
|
|
|
} capture_ RTC_GUARDED_BY(crit_capture_);
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
struct ApmCaptureNonLockedState {
|
2018-08-30 13:01:34 +02:00
|
|
|
ApmCaptureNonLockedState()
|
2016-09-16 15:02:15 -07:00
|
|
|
: capture_processing_format(kSampleRate16kHz),
|
2015-11-28 12:35:15 -08:00
|
|
|
split_rate(kSampleRate16kHz),
|
2018-08-30 13:01:34 +02:00
|
|
|
stream_delay_ms(0) {}
|
2016-09-16 15:02:15 -07:00
|
|
|
// Only the rate and samples fields of capture_processing_format_ are used
|
|
|
|
|
// because the forward processing number of channels is mutable and is
|
|
|
|
|
// tracked by the capture_audio_.
|
|
|
|
|
StreamConfig capture_processing_format;
|
2015-11-28 12:35:15 -08:00
|
|
|
int split_rate;
|
|
|
|
|
int stream_delay_ms;
|
2017-10-16 13:49:04 +02:00
|
|
|
bool echo_controller_enabled = false;
|
2015-11-28 12:35:15 -08:00
|
|
|
} capture_nonlocked_;
|
|
|
|
|
|
|
|
|
|
struct ApmRenderState {
|
2016-08-29 14:46:07 -07:00
|
|
|
ApmRenderState();
|
|
|
|
|
~ApmRenderState();
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<AudioConverter> render_converter;
|
|
|
|
|
std::unique_ptr<AudioBuffer> render_audio;
|
2017-09-07 07:53:45 -07:00
|
|
|
} render_ RTC_GUARDED_BY(crit_render_);
|
|
|
|
|
|
2019-12-30 14:32:14 +01:00
|
|
|
// Class for statistics reporting. The class is thread-safe and no lock is
|
|
|
|
|
// needed when accessing it.
|
|
|
|
|
class ApmStatsReporter {
|
|
|
|
|
public:
|
|
|
|
|
ApmStatsReporter();
|
|
|
|
|
~ApmStatsReporter();
|
|
|
|
|
|
|
|
|
|
// Returns the most recently reported statistics.
|
|
|
|
|
AudioProcessingStats GetStatistics();
|
|
|
|
|
|
|
|
|
|
// Update the cached statistics.
|
|
|
|
|
void UpdateStatistics(const AudioProcessingStats& new_stats);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
rtc::CriticalSection crit_stats_;
|
|
|
|
|
AudioProcessingStats cached_stats_ RTC_GUARDED_BY(crit_stats_);
|
|
|
|
|
SwapQueue<AudioProcessingStats> stats_message_queue_;
|
|
|
|
|
} stats_reporter_;
|
|
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
std::vector<float> aec_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
|
|
|
|
|
std::vector<float> aec_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
|
|
|
|
|
|
|
|
|
|
std::vector<int16_t> aecm_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
|
|
|
|
|
std::vector<int16_t> aecm_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
|
|
|
|
|
|
|
|
|
|
size_t agc_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
|
|
|
|
|
RTC_GUARDED_BY(crit_capture_) = 0;
|
|
|
|
|
std::vector<int16_t> agc_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
|
|
|
|
|
std::vector<int16_t> agc_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
|
|
|
|
|
|
|
|
|
|
size_t red_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
|
|
|
|
|
RTC_GUARDED_BY(crit_capture_) = 0;
|
|
|
|
|
std::vector<float> red_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
|
|
|
|
|
std::vector<float> red_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
|
|
|
|
|
|
|
|
|
|
RmsLevel capture_input_rms_ RTC_GUARDED_BY(crit_capture_);
|
|
|
|
|
RmsLevel capture_output_rms_ RTC_GUARDED_BY(crit_capture_);
|
|
|
|
|
int capture_rms_interval_counter_ RTC_GUARDED_BY(crit_capture_) = 0;
|
2016-11-29 08:09:09 -08:00
|
|
|
|
2016-10-22 05:04:30 -07:00
|
|
|
// Lock protection not needed.
|
2016-10-25 05:42:20 -07:00
|
|
|
std::unique_ptr<
|
|
|
|
|
SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
|
|
|
|
|
aecm_render_signal_queue_;
|
2016-10-25 04:45:24 -07:00
|
|
|
std::unique_ptr<
|
|
|
|
|
SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
|
2016-10-25 05:42:20 -07:00
|
|
|
agc_render_signal_queue_;
|
2016-10-28 05:39:16 -07:00
|
|
|
std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
|
|
|
|
|
red_render_signal_queue_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
|