APM: add AudioProcessingBuilder::SetConfig()

Bug: webrtc:5298
Change-Id: If3468ebb841c49dcd410a8bea2f9f8111ee8bc06
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/234842
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35199}
This commit is contained in:
Alessio Bazzica 2021-10-14 10:55:08 +02:00 committed by WebRTC LUCI CQ
parent 56fb4b4e31
commit 20a9ac655c
4 changed files with 33 additions and 14 deletions

View file

@ -26,9 +26,9 @@ rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilder::Create() {
return nullptr; return nullptr;
#else // WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE #else // WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE
return rtc::make_ref_counted<AudioProcessingImpl>( return rtc::make_ref_counted<AudioProcessingImpl>(
std::move(capture_post_processing_), std::move(render_pre_processing_), config_, std::move(capture_post_processing_),
std::move(echo_control_factory_), std::move(echo_detector_), std::move(render_pre_processing_), std::move(echo_control_factory_),
std::move(capture_analyzer_)); std::move(echo_detector_), std::move(capture_analyzer_));
#endif #endif
} }

View file

@ -235,7 +235,8 @@ bool AudioProcessingImpl::SubmoduleStates::HighPassFilteringRequired() const {
} }
AudioProcessingImpl::AudioProcessingImpl() AudioProcessingImpl::AudioProcessingImpl()
: AudioProcessingImpl(/*capture_post_processor=*/nullptr, : AudioProcessingImpl(/*config=*/{},
/*capture_post_processor=*/nullptr,
/*render_pre_processor=*/nullptr, /*render_pre_processor=*/nullptr,
/*echo_control_factory=*/nullptr, /*echo_control_factory=*/nullptr,
/*echo_detector=*/nullptr, /*echo_detector=*/nullptr,
@ -244,6 +245,7 @@ AudioProcessingImpl::AudioProcessingImpl()
int AudioProcessingImpl::instance_count_ = 0; int AudioProcessingImpl::instance_count_ = 0;
AudioProcessingImpl::AudioProcessingImpl( AudioProcessingImpl::AudioProcessingImpl(
const AudioProcessing::Config& config,
std::unique_ptr<CustomProcessing> capture_post_processor, std::unique_ptr<CustomProcessing> capture_post_processor,
std::unique_ptr<CustomProcessing> render_pre_processor, std::unique_ptr<CustomProcessing> render_pre_processor,
std::unique_ptr<EchoControlFactory> echo_control_factory, std::unique_ptr<EchoControlFactory> echo_control_factory,
@ -260,6 +262,7 @@ AudioProcessingImpl::AudioProcessingImpl(
capture_runtime_settings_enqueuer_(&capture_runtime_settings_), capture_runtime_settings_enqueuer_(&capture_runtime_settings_),
render_runtime_settings_enqueuer_(&render_runtime_settings_), render_runtime_settings_enqueuer_(&render_runtime_settings_),
echo_control_factory_(std::move(echo_control_factory)), echo_control_factory_(std::move(echo_control_factory)),
config_(config),
submodule_states_(!!capture_post_processor, submodule_states_(!!capture_post_processor,
!!render_pre_processor, !!render_pre_processor,
!!capture_analyzer), !!capture_analyzer),

View file

@ -56,8 +56,8 @@ class AudioProcessingImpl : public AudioProcessing {
// Methods forcing APM to run in a single-threaded manner. // Methods forcing APM to run in a single-threaded manner.
// Acquires both the render and capture locks. // Acquires both the render and capture locks.
AudioProcessingImpl(); AudioProcessingImpl();
// AudioProcessingImpl takes ownership of capture post processor. AudioProcessingImpl(const AudioProcessing::Config& config,
AudioProcessingImpl(std::unique_ptr<CustomProcessing> capture_post_processor, std::unique_ptr<CustomProcessing> capture_post_processor,
std::unique_ptr<CustomProcessing> render_pre_processor, std::unique_ptr<CustomProcessing> render_pre_processor,
std::unique_ptr<EchoControlFactory> echo_control_factory, std::unique_ptr<EchoControlFactory> echo_control_factory,
rtc::scoped_refptr<EchoDetector> echo_detector, rtc::scoped_refptr<EchoDetector> echo_detector,

View file

@ -743,48 +743,64 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface {
class RTC_EXPORT AudioProcessingBuilder { class RTC_EXPORT AudioProcessingBuilder {
public: public:
AudioProcessingBuilder(); AudioProcessingBuilder();
AudioProcessingBuilder(const AudioProcessingBuilder&) = delete;
AudioProcessingBuilder& operator=(const AudioProcessingBuilder&) = delete;
~AudioProcessingBuilder(); ~AudioProcessingBuilder();
// The AudioProcessingBuilder takes ownership of the echo_control_factory.
// Sets the APM configuration.
AudioProcessingBuilder& SetConfig(const AudioProcessing::Config& config) {
config_ = config;
return *this;
}
// Sets the echo controller factory to inject when APM is created.
AudioProcessingBuilder& SetEchoControlFactory( AudioProcessingBuilder& SetEchoControlFactory(
std::unique_ptr<EchoControlFactory> echo_control_factory) { std::unique_ptr<EchoControlFactory> echo_control_factory) {
echo_control_factory_ = std::move(echo_control_factory); echo_control_factory_ = std::move(echo_control_factory);
return *this; return *this;
} }
// The AudioProcessingBuilder takes ownership of the capture_post_processing.
// Sets the capture post-processing sub-module to inject when APM is created.
AudioProcessingBuilder& SetCapturePostProcessing( AudioProcessingBuilder& SetCapturePostProcessing(
std::unique_ptr<CustomProcessing> capture_post_processing) { std::unique_ptr<CustomProcessing> capture_post_processing) {
capture_post_processing_ = std::move(capture_post_processing); capture_post_processing_ = std::move(capture_post_processing);
return *this; return *this;
} }
// The AudioProcessingBuilder takes ownership of the render_pre_processing.
// Sets the render pre-processing sub-module to inject when APM is created.
AudioProcessingBuilder& SetRenderPreProcessing( AudioProcessingBuilder& SetRenderPreProcessing(
std::unique_ptr<CustomProcessing> render_pre_processing) { std::unique_ptr<CustomProcessing> render_pre_processing) {
render_pre_processing_ = std::move(render_pre_processing); render_pre_processing_ = std::move(render_pre_processing);
return *this; return *this;
} }
// The AudioProcessingBuilder takes ownership of the echo_detector.
// Sets the echo detector to inject when APM is created.
AudioProcessingBuilder& SetEchoDetector( AudioProcessingBuilder& SetEchoDetector(
rtc::scoped_refptr<EchoDetector> echo_detector) { rtc::scoped_refptr<EchoDetector> echo_detector) {
echo_detector_ = std::move(echo_detector); echo_detector_ = std::move(echo_detector);
return *this; return *this;
} }
// The AudioProcessingBuilder takes ownership of the capture_analyzer.
// Sets the capture analyzer sub-module to inject when APM is created.
AudioProcessingBuilder& SetCaptureAnalyzer( AudioProcessingBuilder& SetCaptureAnalyzer(
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer) { std::unique_ptr<CustomAudioAnalyzer> capture_analyzer) {
capture_analyzer_ = std::move(capture_analyzer); capture_analyzer_ = std::move(capture_analyzer);
return *this; return *this;
} }
// This creates an APM instance using the previously set components. Calling
// the Create function resets the AudioProcessingBuilder to its initial state. // Creates an APM instance with the specified config or the default one if
// unspecified. Injects the specified components transferring the ownership
// to the newly created APM instance - i.e., except for the config, the
// builder is reset to its initial state.
rtc::scoped_refptr<AudioProcessing> Create(); rtc::scoped_refptr<AudioProcessing> Create();
private: private:
AudioProcessing::Config config_;
std::unique_ptr<EchoControlFactory> echo_control_factory_; std::unique_ptr<EchoControlFactory> echo_control_factory_;
std::unique_ptr<CustomProcessing> capture_post_processing_; std::unique_ptr<CustomProcessing> capture_post_processing_;
std::unique_ptr<CustomProcessing> render_pre_processing_; std::unique_ptr<CustomProcessing> render_pre_processing_;
rtc::scoped_refptr<EchoDetector> echo_detector_; rtc::scoped_refptr<EchoDetector> echo_detector_;
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer_; std::unique_ptr<CustomAudioAnalyzer> capture_analyzer_;
RTC_DISALLOW_COPY_AND_ASSIGN(AudioProcessingBuilder);
}; };
class StreamConfig { class StreamConfig {