Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Unified Diff: webrtc/modules/audio_processing/echo_control_mobile_impl.cc

Issue 1803433003: Removed the dependency on AudioProcessingImpl in EchoControlMobileImpl (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected the error code returned when the stream delay had not been set Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/echo_control_mobile_impl.cc
diff --git a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc
index ad25fa2ca69c0ab676945a623d48150c870ec4c7..cadbd042eac9077674d806381db9ba98b324585b 100644
--- a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc
+++ b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc
@@ -64,6 +64,20 @@ size_t EchoControlMobile::echo_path_size_bytes() {
return WebRtcAecm_echo_path_size_bytes();
}
+struct EchoControlMobileImpl::StreamProperties {
+ StreamProperties() = delete;
+ StreamProperties(int sample_rate_hz,
+ size_t num_reverse_channels,
+ size_t num_output_channels)
+ : sample_rate_hz(sample_rate_hz),
+ num_reverse_channels(num_reverse_channels),
+ num_output_channels(num_output_channels) {}
+
+ int sample_rate_hz;
+ size_t num_reverse_channels;
+ size_t num_output_channels;
+};
+
class EchoControlMobileImpl::Canceller {
public:
Canceller() {
@@ -99,17 +113,14 @@ class EchoControlMobileImpl::Canceller {
RTC_DISALLOW_COPY_AND_ASSIGN(Canceller);
};
-EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm,
- rtc::CriticalSection* crit_render,
+EchoControlMobileImpl::EchoControlMobileImpl(rtc::CriticalSection* crit_render,
rtc::CriticalSection* crit_capture)
- : apm_(apm),
- crit_render_(crit_render),
+ : crit_render_(crit_render),
crit_capture_(crit_capture),
routing_mode_(kSpeakerphone),
comfort_noise_enabled_(true),
external_echo_path_(NULL),
render_queue_element_max_size_(0) {
- RTC_DCHECK(apm);
RTC_DCHECK(crit_render);
RTC_DCHECK(crit_capture);
}
@@ -128,9 +139,10 @@ int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) {
}
RTC_DCHECK_GE(160u, audio->num_frames_per_band());
- RTC_DCHECK_EQ(audio->num_channels(), apm_->num_reverse_channels());
- RTC_DCHECK_GE(cancellers_.size(),
- apm_->num_output_channels() * audio->num_channels());
+ RTC_DCHECK_EQ(audio->num_channels(),
+ stream_properties_->num_reverse_channels);
+ RTC_DCHECK_GE(cancellers_.size(), stream_properties_->num_output_channels *
+ audio->num_channels());
int err = AudioProcessing::kNoError;
// The ordering convention must be followed to pass to the correct AECM.
@@ -177,9 +189,9 @@ void EchoControlMobileImpl::ReadQueuedRenderData() {
while (render_signal_queue_->Remove(&capture_queue_buffer_)) {
size_t buffer_index = 0;
- size_t num_frames_per_band =
- capture_queue_buffer_.size() /
- (apm_->num_output_channels() * apm_->num_reverse_channels());
+ size_t num_frames_per_band = capture_queue_buffer_.size() /
+ (stream_properties_->num_output_channels *
+ stream_properties_->num_reverse_channels);
for (auto& canceller : cancellers_) {
WebRtcAecm_BufferFarend(canceller->state(),
@@ -191,20 +203,17 @@ void EchoControlMobileImpl::ReadQueuedRenderData() {
}
}
-int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
+int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio,
+ int stream_delay_ms) {
rtc::CritScope cs_capture(crit_capture_);
if (!enabled_) {
return AudioProcessing::kNoError;
}
- if (!apm_->was_stream_delay_set()) {
- return AudioProcessing::kStreamParameterNotSetError;
- }
-
RTC_DCHECK_GE(160u, audio->num_frames_per_band());
- RTC_DCHECK_EQ(audio->num_channels(), apm_->num_output_channels());
- RTC_DCHECK_GE(cancellers_.size(),
- apm_->num_reverse_channels() * audio->num_channels());
+ RTC_DCHECK_EQ(audio->num_channels(), stream_properties_->num_output_channels);
+ RTC_DCHECK_GE(cancellers_.size(), stream_properties_->num_reverse_channels *
+ audio->num_channels());
int err = AudioProcessing::kNoError;
@@ -219,11 +228,11 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
noisy = clean;
clean = NULL;
}
- for (size_t render = 0; render < apm_->num_reverse_channels(); ++render) {
+ for (size_t render = 0; render < stream_properties_->num_reverse_channels;
+ ++render) {
err = WebRtcAecm_Process(cancellers_[handle_index]->state(), noisy, clean,
audio->split_bands(capture)[kBand0To8kHz],
- audio->num_frames_per_band(),
- apm_->stream_delay_ms());
+ audio->num_frames_per_band(), stream_delay_ms);
if (err != AudioProcessing::kNoError) {
return MapError(err);
@@ -239,20 +248,21 @@ int EchoControlMobileImpl::Enable(bool enable) {
// Ensure AEC and AECM are not both enabled.
rtc::CritScope cs_render(crit_render_);
rtc::CritScope cs_capture(crit_capture_);
- // The is_enabled call is safe from a deadlock perspective
- // as both locks are allready held in the correct order.
- if (enable && apm_->echo_cancellation()->is_enabled()) {
- return AudioProcessing::kBadParameterError;
- }
if (enable &&
- apm_->proc_sample_rate_hz() > AudioProcessing::kSampleRate16kHz) {
+ stream_properties_->sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
return AudioProcessing::kBadSampleRateError;
}
if (enable && !enabled_) {
enabled_ = enable; // Must be set before Initialize() is called.
- Initialize();
+
+ // TODO(peah): Simplify once the Enable function has been removed from
+ // the public APM API.
+ RTC_DCHECK(stream_properties_);
+ Initialize(stream_properties_->sample_rate_hz,
+ stream_properties_->num_reverse_channels,
+ stream_properties_->num_output_channels);
} else {
enabled_ = enable;
}
@@ -314,7 +324,12 @@ int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
memcpy(external_echo_path_, echo_path, size_bytes);
}
- Initialize();
+ // TODO(peah): Simplify once the Enable function has been removed from
+ // the public APM API.
+ RTC_DCHECK(stream_properties_);
+ Initialize(stream_properties_->sample_rate_hz,
+ stream_properties_->num_reverse_channels,
+ stream_properties_->num_output_channels);
return AudioProcessing::kNoError;
}
@@ -342,18 +357,23 @@ int EchoControlMobileImpl::GetEchoPath(void* echo_path,
return AudioProcessing::kNoError;
}
-void EchoControlMobileImpl::Initialize() {
+void EchoControlMobileImpl::Initialize(int sample_rate_hz,
+ size_t num_reverse_channels,
+ size_t num_output_channels) {
rtc::CritScope cs_render(crit_render_);
rtc::CritScope cs_capture(crit_capture_);
+
+ stream_properties_.reset(new StreamProperties(
+ sample_rate_hz, num_reverse_channels, num_output_channels));
+
if (!enabled_) {
return;
}
- if (apm_->proc_sample_rate_hz() > AudioProcessing::kSampleRate16kHz) {
+ if (stream_properties_->sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
LOG(LS_ERROR) << "AECM only supports 16 kHz or lower sample rates";
}
- int sample_rate_hz = apm_->proc_sample_rate_hz();
cancellers_.resize(num_handles_required());
for (auto& canceller : cancellers_) {
if (!canceller) {
@@ -413,6 +433,7 @@ int EchoControlMobileImpl::Configure() {
size_t EchoControlMobileImpl::num_handles_required() const {
// Not locked as it only relies on APM public API which is threadsafe.
- return apm_->num_output_channels() * apm_->num_reverse_channels();
+ return stream_properties_->num_output_channels *
+ stream_properties_->num_reverse_channels;
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698