#include "modules/audio_processing/audio_processing_impl.h"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include "absl/base/nullability.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/audio/audio_frame.h"
#include "api/task_queue/task_queue_base.h"
#include "common_audio/audio_converter.h"
#include "common_audio/include/audio_util.h"
#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
#include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_processing/include/audio_frame_view.h"
#include "modules/audio_processing/logging/apm_data_dumper.h"
#include "rtc_base/checks.h"
#include "rtc_base/experiments/field_trial_parser.h"
#include "rtc_base/logging.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
#include "system_wrappers/include/denormal_disabler.h"
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/metrics.h"
#define RETURN_ON_ERR(expr) …
namespace webrtc {
namespace {
bool SampleRateSupportsMultiBand(int sample_rate_hz) { … }
bool EnforceSplitBandHpf() { … }
bool UseSetupSpecificDefaultAec3Congfig() { … }
int SuitableProcessRate(int minimum_rate,
int max_splitting_rate,
bool band_splitting_required) { … }
GainControl::Mode Agc1ConfigModeToInterfaceMode(
AudioProcessing::Config::GainController1::Mode mode) { … }
bool MinimizeProcessingForUnusedOutput() { … }
static const size_t kMaxAllowedValuesOfSamplesPerBand = …;
static const size_t kMaxAllowedValuesOfSamplesPerFrame = …;
static const size_t kMaxNumFramesToBuffer = …;
void PackRenderAudioBufferForEchoDetector(const AudioBuffer& audio,
std::vector<float>& packed_buffer) { … }
enum class FormatErrorOutputOption { … };
enum class AudioFormatValidity { … };
AudioFormatValidity ValidateAudioFormat(const StreamConfig& config) { … }
int AudioFormatValidityToErrorCode(AudioFormatValidity validity) { … }
std::pair<int, FormatErrorOutputOption> ChooseErrorOutputOption(
const StreamConfig& input_config,
const StreamConfig& output_config) { … }
int HandleUnsupportedAudioFormats(const int16_t* const src,
const StreamConfig& input_config,
const StreamConfig& output_config,
int16_t* const dest) { … }
int HandleUnsupportedAudioFormats(const float* const* src,
const StreamConfig& input_config,
const StreamConfig& output_config,
float* const* dest) { … }
DownmixMethod;
void SetDownmixMethod(AudioBuffer& buffer, DownmixMethod method) { … }
constexpr int kUnspecifiedDataDumpInputVolume = …;
}
static_assert …;
AudioProcessingImpl::SubmoduleStates::SubmoduleStates(
bool capture_post_processor_enabled,
bool render_pre_processor_enabled,
bool capture_analyzer_enabled)
: … { … }
bool AudioProcessingImpl::SubmoduleStates::Update(
bool high_pass_filter_enabled,
bool mobile_echo_controller_enabled,
bool noise_suppressor_enabled,
bool adaptive_gain_controller_enabled,
bool gain_controller2_enabled,
bool gain_adjustment_enabled,
bool echo_controller_enabled) { … }
bool AudioProcessingImpl::SubmoduleStates::CaptureMultiBandSubModulesActive()
const { … }
bool AudioProcessingImpl::SubmoduleStates::CaptureMultiBandProcessingPresent()
const { … }
bool AudioProcessingImpl::SubmoduleStates::CaptureMultiBandProcessingActive(
bool ec_processing_active) const { … }
bool AudioProcessingImpl::SubmoduleStates::CaptureFullBandProcessingActive()
const { … }
bool AudioProcessingImpl::SubmoduleStates::CaptureAnalyzerActive() const { … }
bool AudioProcessingImpl::SubmoduleStates::RenderMultiBandSubModulesActive()
const { … }
bool AudioProcessingImpl::SubmoduleStates::RenderFullBandProcessingActive()
const { … }
bool AudioProcessingImpl::SubmoduleStates::RenderMultiBandProcessingActive()
const { … }
bool AudioProcessingImpl::SubmoduleStates::HighPassFilteringRequired() const { … }
AudioProcessingImpl::AudioProcessingImpl()
: … { … }
std::atomic<int> AudioProcessingImpl::instance_count_(0);
AudioProcessingImpl::AudioProcessingImpl(
const AudioProcessing::Config& config,
std::unique_ptr<CustomProcessing> capture_post_processor,
std::unique_ptr<CustomProcessing> render_pre_processor,
std::unique_ptr<EchoControlFactory> echo_control_factory,
rtc::scoped_refptr<EchoDetector> echo_detector,
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
: … { … }
AudioProcessingImpl::~AudioProcessingImpl() = default;
int AudioProcessingImpl::Initialize() { … }
int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { … }
void AudioProcessingImpl::MaybeInitializeRender(
const StreamConfig& input_config,
const StreamConfig& output_config) { … }
void AudioProcessingImpl::InitializeLocked() { … }
void AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { … }
void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { … }
int AudioProcessingImpl::proc_sample_rate_hz() const { … }
int AudioProcessingImpl::proc_fullband_sample_rate_hz() const { … }
int AudioProcessingImpl::proc_split_sample_rate_hz() const { … }
size_t AudioProcessingImpl::num_reverse_channels() const { … }
size_t AudioProcessingImpl::num_input_channels() const { … }
size_t AudioProcessingImpl::num_proc_channels() const { … }
size_t AudioProcessingImpl::num_output_channels() const { … }
void AudioProcessingImpl::set_output_will_be_muted(bool muted) { … }
void AudioProcessingImpl::HandleCaptureOutputUsedSetting(
bool capture_output_used) { … }
void AudioProcessingImpl::SetRuntimeSetting(RuntimeSetting setting) { … }
bool AudioProcessingImpl::PostRuntimeSetting(RuntimeSetting setting) { … }
AudioProcessingImpl::RuntimeSettingEnqueuer::RuntimeSettingEnqueuer(
SwapQueue<RuntimeSetting>* runtime_settings)
: … { … }
AudioProcessingImpl::RuntimeSettingEnqueuer::~RuntimeSettingEnqueuer() =
default;
bool AudioProcessingImpl::RuntimeSettingEnqueuer::Enqueue(
RuntimeSetting setting) { … }
void AudioProcessingImpl::MaybeInitializeCapture(
const StreamConfig& input_config,
const StreamConfig& output_config) { … }
int AudioProcessingImpl::ProcessStream(const float* const* src,
const StreamConfig& input_config,
const StreamConfig& output_config,
float* const* dest) { … }
void AudioProcessingImpl::HandleCaptureRuntimeSettings() { … }
void AudioProcessingImpl::HandleOverrunInCaptureRuntimeSettingsQueue() { … }
void AudioProcessingImpl::HandleRenderRuntimeSettings() { … }
void AudioProcessingImpl::QueueBandedRenderAudio(AudioBuffer* audio) { … }
void AudioProcessingImpl::QueueNonbandedRenderAudio(AudioBuffer* audio) { … }
void AudioProcessingImpl::AllocateRenderQueue() { … }
void AudioProcessingImpl::EmptyQueuedRenderAudio() { … }
void AudioProcessingImpl::EmptyQueuedRenderAudioLocked() { … }
int AudioProcessingImpl::ProcessStream(const int16_t* const src,
const StreamConfig& input_config,
const StreamConfig& output_config,
int16_t* const dest) { … }
int AudioProcessingImpl::ProcessCaptureStreamLocked() { … }
int AudioProcessingImpl::AnalyzeReverseStream(
const float* const* data,
const StreamConfig& reverse_config) { … }
int AudioProcessingImpl::ProcessReverseStream(const float* const* src,
const StreamConfig& input_config,
const StreamConfig& output_config,
float* const* dest) { … }
int AudioProcessingImpl::AnalyzeReverseStreamLocked(
const float* const* src,
const StreamConfig& input_config,
const StreamConfig& output_config) { … }
int AudioProcessingImpl::ProcessReverseStream(const int16_t* const src,
const StreamConfig& input_config,
const StreamConfig& output_config,
int16_t* const dest) { … }
int AudioProcessingImpl::ProcessRenderStreamLocked() { … }
int AudioProcessingImpl::set_stream_delay_ms(int delay) { … }
bool AudioProcessingImpl::GetLinearAecOutput(
rtc::ArrayView<std::array<float, 160>> linear_output) const { … }
int AudioProcessingImpl::stream_delay_ms() const { … }
void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { … }
void AudioProcessingImpl::set_stream_analog_level(int level) { … }
void AudioProcessingImpl::set_stream_analog_level_locked(int level) { … }
int AudioProcessingImpl::recommended_stream_analog_level() const { … }
void AudioProcessingImpl::UpdateRecommendedInputVolumeLocked() { … }
bool AudioProcessingImpl::CreateAndAttachAecDump(
absl::string_view file_name,
int64_t max_log_size_bytes,
absl::Nonnull<TaskQueueBase*> worker_queue) { … }
bool AudioProcessingImpl::CreateAndAttachAecDump(
FILE* handle,
int64_t max_log_size_bytes,
absl::Nonnull<TaskQueueBase*> worker_queue) { … }
void AudioProcessingImpl::AttachAecDump(std::unique_ptr<AecDump> aec_dump) { … }
void AudioProcessingImpl::DetachAecDump() { … }
AudioProcessing::Config AudioProcessingImpl::GetConfig() const { … }
bool AudioProcessingImpl::UpdateActiveSubmoduleStates() { … }
void AudioProcessingImpl::InitializeHighPassFilter(bool forced_reset) { … }
void AudioProcessingImpl::InitializeEchoController() { … }
void AudioProcessingImpl::InitializeGainController1() { … }
void AudioProcessingImpl::InitializeGainController2() { … }
void AudioProcessingImpl::InitializeNoiseSuppressor() { … }
void AudioProcessingImpl::InitializeCaptureLevelsAdjuster() { … }
void AudioProcessingImpl::InitializeResidualEchoDetector() { … }
void AudioProcessingImpl::InitializeAnalyzer() { … }
void AudioProcessingImpl::InitializePostProcessor() { … }
void AudioProcessingImpl::InitializePreProcessor() { … }
void AudioProcessingImpl::WriteAecDumpConfigMessage(bool forced) { … }
void AudioProcessingImpl::RecordUnprocessedCaptureStream(
const float* const* src) { … }
void AudioProcessingImpl::RecordUnprocessedCaptureStream(
const int16_t* const data,
const StreamConfig& config) { … }
void AudioProcessingImpl::RecordProcessedCaptureStream(
const float* const* processed_capture_stream) { … }
void AudioProcessingImpl::RecordProcessedCaptureStream(
const int16_t* const data,
const StreamConfig& config) { … }
void AudioProcessingImpl::RecordAudioProcessingState() { … }
AudioProcessingImpl::ApmCaptureState::ApmCaptureState()
: … { … }
AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
AudioProcessingImpl::ApmStatsReporter::ApmStatsReporter()
: … { … }
AudioProcessingImpl::ApmStatsReporter::~ApmStatsReporter() = default;
AudioProcessingStats AudioProcessingImpl::ApmStatsReporter::GetStatistics() { … }
void AudioProcessingImpl::ApmStatsReporter::UpdateStatistics(
const AudioProcessingStats& new_stats) { … }
}