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.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-12-15 09:41:24 +00:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#include <list>
|
2011-08-03 21:08:51 +00:00
|
|
|
#include <string>
|
2015-07-23 11:41:39 -07:00
|
|
|
#include <vector>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-02-26 14:34:55 +00:00
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
2014-12-15 09:41:24 +00:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
2015-03-25 16:37:27 -07:00
|
|
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2014-12-15 09:41:24 +00:00
|
|
|
class AgcManagerDirect;
|
2011-07-07 08:21:25 +00:00
|
|
|
class AudioBuffer;
|
2015-03-25 16:37:27 -07:00
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
class Beamformer;
|
|
|
|
|
|
2011-08-03 21:08:51 +00:00
|
|
|
class CriticalSectionWrapper;
|
2014-02-27 22:23:17 +00:00
|
|
|
class EchoCancellationImpl;
|
2011-07-07 08:21:25 +00:00
|
|
|
class EchoControlMobileImpl;
|
2011-08-03 21:08:51 +00:00
|
|
|
class FileWrapper;
|
2011-07-07 08:21:25 +00:00
|
|
|
class GainControlImpl;
|
2014-12-15 09:41:24 +00:00
|
|
|
class GainControlForNewAgc;
|
2011-07-07 08:21:25 +00:00
|
|
|
class HighPassFilterImpl;
|
|
|
|
|
class LevelEstimatorImpl;
|
|
|
|
|
class NoiseSuppressionImpl;
|
|
|
|
|
class ProcessingComponent;
|
2014-12-15 09:41:24 +00:00
|
|
|
class TransientSuppressor;
|
2011-07-07 08:21:25 +00:00
|
|
|
class VoiceDetectionImpl;
|
|
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
|
|
|
|
namespace audioproc {
|
|
|
|
|
|
|
|
|
|
class Event;
|
|
|
|
|
|
|
|
|
|
} // namespace audioproc
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
class AudioProcessingImpl : public AudioProcessing {
|
|
|
|
|
public:
|
2014-01-25 02:09:06 +00:00
|
|
|
explicit AudioProcessingImpl(const Config& config);
|
2015-03-25 16:37:27 -07:00
|
|
|
|
|
|
|
|
// AudioProcessingImpl takes ownership of beamformer.
|
|
|
|
|
AudioProcessingImpl(const Config& config, Beamformer<float>* beamformer);
|
2011-07-07 08:21:25 +00:00
|
|
|
virtual ~AudioProcessingImpl();
|
|
|
|
|
|
|
|
|
|
// AudioProcessing methods.
|
2015-03-04 12:58:35 +00:00
|
|
|
int Initialize() override;
|
|
|
|
|
int Initialize(int input_sample_rate_hz,
|
|
|
|
|
int output_sample_rate_hz,
|
|
|
|
|
int reverse_sample_rate_hz,
|
|
|
|
|
ChannelLayout input_layout,
|
|
|
|
|
ChannelLayout output_layout,
|
|
|
|
|
ChannelLayout reverse_layout) override;
|
2015-07-23 11:41:39 -07:00
|
|
|
int Initialize(const ProcessingConfig& processing_config) override;
|
2015-03-04 12:58:35 +00:00
|
|
|
void SetExtraOptions(const Config& config) override;
|
|
|
|
|
int set_sample_rate_hz(int rate) override;
|
|
|
|
|
int input_sample_rate_hz() const override;
|
|
|
|
|
int sample_rate_hz() const override;
|
|
|
|
|
int proc_sample_rate_hz() const override;
|
|
|
|
|
int proc_split_sample_rate_hz() const override;
|
|
|
|
|
int num_input_channels() const override;
|
|
|
|
|
int num_output_channels() const override;
|
|
|
|
|
int num_reverse_channels() const override;
|
|
|
|
|
void set_output_will_be_muted(bool muted) override;
|
|
|
|
|
bool output_will_be_muted() const override;
|
|
|
|
|
int ProcessStream(AudioFrame* frame) override;
|
|
|
|
|
int ProcessStream(const float* const* src,
|
|
|
|
|
int samples_per_channel,
|
|
|
|
|
int input_sample_rate_hz,
|
|
|
|
|
ChannelLayout input_layout,
|
|
|
|
|
int output_sample_rate_hz,
|
|
|
|
|
ChannelLayout output_layout,
|
|
|
|
|
float* const* dest) 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;
|
2015-03-04 12:58:35 +00:00
|
|
|
int AnalyzeReverseStream(AudioFrame* frame) override;
|
|
|
|
|
int AnalyzeReverseStream(const float* const* data,
|
|
|
|
|
int samples_per_channel,
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
ChannelLayout layout) override;
|
2015-07-23 11:41:39 -07:00
|
|
|
int AnalyzeReverseStream(const float* const* data,
|
|
|
|
|
const StreamConfig& reverse_config) override;
|
2015-03-04 12:58:35 +00:00
|
|
|
int set_stream_delay_ms(int delay) override;
|
|
|
|
|
int stream_delay_ms() const override;
|
|
|
|
|
bool was_stream_delay_set() const override;
|
|
|
|
|
void set_delay_offset_ms(int offset) override;
|
|
|
|
|
int delay_offset_ms() const override;
|
|
|
|
|
void set_stream_key_pressed(bool key_pressed) override;
|
|
|
|
|
bool stream_key_pressed() const override;
|
|
|
|
|
int StartDebugRecording(const char filename[kMaxFilenameSize]) override;
|
|
|
|
|
int StartDebugRecording(FILE* handle) override;
|
|
|
|
|
int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override;
|
|
|
|
|
int StopDebugRecording() override;
|
2015-07-07 11:50:05 +02:00
|
|
|
void UpdateHistogramsOnCallEnd() override;
|
2015-03-04 12:58:35 +00:00
|
|
|
EchoCancellation* echo_cancellation() const override;
|
|
|
|
|
EchoControlMobile* echo_control_mobile() const override;
|
|
|
|
|
GainControl* gain_control() const override;
|
|
|
|
|
HighPassFilter* high_pass_filter() const override;
|
|
|
|
|
LevelEstimator* level_estimator() const override;
|
|
|
|
|
NoiseSuppression* noise_suppression() const override;
|
|
|
|
|
VoiceDetection* voice_detection() const override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-01-07 17:45:09 +00:00
|
|
|
protected:
|
2014-03-10 22:26:12 +00:00
|
|
|
// Overridden in a mock.
|
2014-12-15 09:41:24 +00:00
|
|
|
virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
private:
|
2015-07-23 11:41:39 -07:00
|
|
|
int InitializeLocked(const ProcessingConfig& config)
|
2014-12-15 09:41:24 +00:00
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2015-07-23 11:41:39 -07:00
|
|
|
int MaybeInitializeLocked(const ProcessingConfig& config)
|
2014-12-15 09:41:24 +00:00
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
|
|
|
|
int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
|
|
|
|
int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2012-04-24 18:38:03 +00:00
|
|
|
bool is_data_processed() const;
|
2014-03-04 20:58:13 +00:00
|
|
|
bool output_copy_needed(bool is_data_processed) const;
|
2012-04-24 18:38:03 +00:00
|
|
|
bool synthesis_needed(bool is_data_processed) const;
|
|
|
|
|
bool analysis_needed(bool is_data_processed) const;
|
2015-04-15 11:42:40 +02:00
|
|
|
void InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
|
|
|
|
void InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2014-12-19 19:57:34 +00:00
|
|
|
void InitializeBeamformer() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2015-06-29 14:57:29 +02:00
|
|
|
void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2011-08-03 21:08:51 +00:00
|
|
|
|
2014-02-27 22:23:17 +00:00
|
|
|
EchoCancellationImpl* echo_cancellation_;
|
2011-07-07 08:21:25 +00:00
|
|
|
EchoControlMobileImpl* echo_control_mobile_;
|
|
|
|
|
GainControlImpl* gain_control_;
|
|
|
|
|
HighPassFilterImpl* high_pass_filter_;
|
|
|
|
|
LevelEstimatorImpl* level_estimator_;
|
|
|
|
|
NoiseSuppressionImpl* noise_suppression_;
|
|
|
|
|
VoiceDetectionImpl* voice_detection_;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
std::list<ProcessingComponent*> component_list_;
|
|
|
|
|
CriticalSectionWrapper* crit_;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<AudioBuffer> render_audio_;
|
|
|
|
|
rtc::scoped_ptr<AudioBuffer> capture_audio_;
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
|
|
|
|
// TODO(andrew): make this more graceful. Ideally we would split this stuff
|
|
|
|
|
// out into a separate class with an "enabled" and "disabled" implementation.
|
|
|
|
|
int WriteMessageToDebugFile();
|
|
|
|
|
int WriteInitMessage();
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<FileWrapper> debug_file_;
|
|
|
|
|
rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
|
2014-01-07 17:45:09 +00:00
|
|
|
std::string event_str_; // Memory for protobuf serialization.
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
// Format of processing streams at input/output call sites.
|
|
|
|
|
ProcessingConfig api_format_;
|
|
|
|
|
|
|
|
|
|
// Only the rate and samples fields of fwd_proc_format_ are used because the
|
|
|
|
|
// forward processing number of channels is mutable and is tracked by the
|
|
|
|
|
// capture_audio_.
|
|
|
|
|
StreamConfig fwd_proc_format_;
|
|
|
|
|
StreamConfig rev_proc_format_;
|
2014-04-22 21:00:04 +00:00
|
|
|
int split_rate_;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int stream_delay_ms_;
|
2012-03-06 19:03:39 +00:00
|
|
|
int delay_offset_ms_;
|
2011-07-07 08:21:25 +00:00
|
|
|
bool was_stream_delay_set_;
|
2015-06-29 14:57:29 +02:00
|
|
|
int last_stream_delay_ms_;
|
|
|
|
|
int last_aec_system_delay_ms_;
|
2015-07-07 11:50:05 +02:00
|
|
|
int stream_delay_jumps_;
|
|
|
|
|
int aec_system_delay_jumps_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-27 11:30:43 +01:00
|
|
|
bool output_will_be_muted_ GUARDED_BY(crit_);
|
2014-02-11 20:52:30 +00:00
|
|
|
|
|
|
|
|
bool key_pressed_;
|
2014-12-15 09:41:24 +00:00
|
|
|
|
|
|
|
|
// Only set through the constructor's Config parameter.
|
|
|
|
|
const bool use_new_agc_;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<AgcManagerDirect> agc_manager_ GUARDED_BY(crit_);
|
2015-04-15 11:42:40 +02:00
|
|
|
int agc_startup_min_volume_;
|
2014-12-15 09:41:24 +00:00
|
|
|
|
|
|
|
|
bool transient_suppressor_enabled_;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<TransientSuppressor> transient_suppressor_;
|
2014-12-19 19:57:34 +00:00
|
|
|
const bool beamformer_enabled_;
|
2015-03-25 16:37:27 -07:00
|
|
|
rtc::scoped_ptr<Beamformer<float>> beamformer_;
|
2015-01-05 21:58:58 +00:00
|
|
|
const std::vector<Point> array_geometry_;
|
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
|
|
|
|
|
|
2014-12-15 09:41:24 +00:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
|