Add a Config class interface to AudioProcessing for passing options.
Pass the Config down to all AudioProcessing components. Also add an EchoCancellationImplWrapper to optionally create different EchoCancellationImpls. BUG=2117 TBR=turaj@webrtc.org TESTED=git try Review URL: https://webrtc-codereview.appspot.com/1843004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4400 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -8,8 +8,8 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WEBRTC_COMMON_H
|
#ifndef WEBRTC_COMMON_H_
|
||||||
#define WEBRTC_COMMON_H
|
#define WEBRTC_COMMON_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -38,14 +38,14 @@ namespace webrtc {
|
|||||||
class Config {
|
class Config {
|
||||||
public:
|
public:
|
||||||
// Returns the option if set or a default constructed one.
|
// Returns the option if set or a default constructed one.
|
||||||
// Callers that access options to often are encouraged to cache the result.
|
// Callers that access options too often are encouraged to cache the result.
|
||||||
// Returned references are owned by this.
|
// Returned references are owned by this.
|
||||||
//
|
//
|
||||||
// Requires std::is_default_constructible<T>
|
// Requires std::is_default_constructible<T>
|
||||||
template<typename T> const T& Get() const;
|
template<typename T> const T& Get() const;
|
||||||
|
|
||||||
// Set the option, deleting any previous instance of the same.
|
// Set the option, deleting any previous instance of the same.
|
||||||
// This instance gets ownership of the newly setted value.
|
// This instance gets ownership of the newly set value.
|
||||||
template<typename T> void Set(T* value);
|
template<typename T> void Set(T* value);
|
||||||
|
|
||||||
Config() {}
|
Config() {}
|
||||||
@ -116,5 +116,7 @@ void Config::Set(T* value) {
|
|||||||
delete it;
|
delete it;
|
||||||
it = new Option<T>(value);
|
it = new Option<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
#endif // WEBRTC_COMMON_H
|
|
||||||
|
#endif // WEBRTC_COMMON_H_
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
'audio_processing_impl.h',
|
'audio_processing_impl.h',
|
||||||
'echo_cancellation_impl.cc',
|
'echo_cancellation_impl.cc',
|
||||||
'echo_cancellation_impl.h',
|
'echo_cancellation_impl.h',
|
||||||
|
'echo_cancellation_impl_wrapper.h',
|
||||||
'echo_control_mobile_impl.cc',
|
'echo_control_mobile_impl.cc',
|
||||||
'echo_control_mobile_impl.h',
|
'echo_control_mobile_impl.h',
|
||||||
'gain_control_impl.cc',
|
'gain_control_impl.cc',
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
||||||
#include "webrtc/modules/audio_processing/echo_cancellation_impl.h"
|
#include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h"
|
||||||
#include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
|
#include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
|
||||||
#include "webrtc/modules/audio_processing/gain_control_impl.h"
|
#include "webrtc/modules/audio_processing/gain_control_impl.h"
|
||||||
#include "webrtc/modules/audio_processing/high_pass_filter_impl.h"
|
#include "webrtc/modules/audio_processing/high_pass_filter_impl.h"
|
||||||
@ -76,7 +76,7 @@ AudioProcessingImpl::AudioProcessingImpl(int id)
|
|||||||
num_reverse_channels_(1),
|
num_reverse_channels_(1),
|
||||||
num_input_channels_(1),
|
num_input_channels_(1),
|
||||||
num_output_channels_(1) {
|
num_output_channels_(1) {
|
||||||
echo_cancellation_ = new EchoCancellationImpl(this);
|
echo_cancellation_ = EchoCancellationImplWrapper::Create(this);
|
||||||
component_list_.push_back(echo_cancellation_);
|
component_list_.push_back(echo_cancellation_);
|
||||||
|
|
||||||
echo_control_mobile_ = new EchoControlMobileImpl(this);
|
echo_control_mobile_ = new EchoControlMobileImpl(this);
|
||||||
@ -181,6 +181,12 @@ int AudioProcessingImpl::InitializeLocked() {
|
|||||||
return kNoError;
|
return kNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioProcessingImpl::SetExtraOptions(const Config& config) {
|
||||||
|
std::list<ProcessingComponent*>::iterator it;
|
||||||
|
for (it = component_list_.begin(); it != component_list_.end(); ++it)
|
||||||
|
(*it)->SetExtraOptions(config);
|
||||||
|
}
|
||||||
|
|
||||||
int AudioProcessingImpl::set_sample_rate_hz(int rate) {
|
int AudioProcessingImpl::set_sample_rate_hz(int rate) {
|
||||||
CriticalSectionScoped crit_scoped(crit_);
|
CriticalSectionScoped crit_scoped(crit_);
|
||||||
if (rate == sample_rate_hz_) {
|
if (rate == sample_rate_hz_) {
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
class AudioBuffer;
|
class AudioBuffer;
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EchoCancellationImpl;
|
class EchoCancellationImplWrapper;
|
||||||
class EchoControlMobileImpl;
|
class EchoControlMobileImpl;
|
||||||
class FileWrapper;
|
class FileWrapper;
|
||||||
class GainControlImpl;
|
class GainControlImpl;
|
||||||
@ -58,6 +58,7 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
// AudioProcessing methods.
|
// AudioProcessing methods.
|
||||||
virtual int Initialize();
|
virtual int Initialize();
|
||||||
virtual int InitializeLocked();
|
virtual int InitializeLocked();
|
||||||
|
virtual void SetExtraOptions(const Config& config);
|
||||||
virtual int set_sample_rate_hz(int rate);
|
virtual int set_sample_rate_hz(int rate);
|
||||||
virtual int sample_rate_hz() const;
|
virtual int sample_rate_hz() const;
|
||||||
virtual int set_num_channels(int input_channels, int output_channels);
|
virtual int set_num_channels(int input_channels, int output_channels);
|
||||||
@ -92,7 +93,7 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
|
|
||||||
int id_;
|
int id_;
|
||||||
|
|
||||||
EchoCancellationImpl* echo_cancellation_;
|
EchoCancellationImplWrapper* echo_cancellation_;
|
||||||
EchoControlMobileImpl* echo_control_mobile_;
|
EchoControlMobileImpl* echo_control_mobile_;
|
||||||
GainControlImpl* gain_control_;
|
GainControlImpl* gain_control_;
|
||||||
HighPassFilterImpl* high_pass_filter_;
|
HighPassFilterImpl* high_pass_filter_;
|
||||||
|
@ -54,6 +54,11 @@ AudioProcessing::Error MapError(int err) {
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
EchoCancellationImplWrapper* EchoCancellationImplWrapper::Create(
|
||||||
|
const AudioProcessingImpl* audioproc) {
|
||||||
|
return new EchoCancellationImpl(audioproc);
|
||||||
|
}
|
||||||
|
|
||||||
EchoCancellationImpl::EchoCancellationImpl(const AudioProcessingImpl* apm)
|
EchoCancellationImpl::EchoCancellationImpl(const AudioProcessingImpl* apm)
|
||||||
: ProcessingComponent(apm),
|
: ProcessingComponent(apm),
|
||||||
apm_(apm),
|
apm_(apm),
|
||||||
|
@ -11,21 +11,21 @@
|
|||||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|
||||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|
#define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|
||||||
|
|
||||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
#include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h"
|
||||||
#include "webrtc/modules/audio_processing/processing_component.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class AudioProcessingImpl;
|
class AudioProcessingImpl;
|
||||||
class AudioBuffer;
|
class AudioBuffer;
|
||||||
|
|
||||||
class EchoCancellationImpl : public EchoCancellation,
|
class EchoCancellationImpl : public EchoCancellationImplWrapper {
|
||||||
public ProcessingComponent {
|
|
||||||
public:
|
public:
|
||||||
explicit EchoCancellationImpl(const AudioProcessingImpl* apm);
|
explicit EchoCancellationImpl(const AudioProcessingImpl* apm);
|
||||||
virtual ~EchoCancellationImpl();
|
virtual ~EchoCancellationImpl();
|
||||||
|
|
||||||
int ProcessRenderAudio(const AudioBuffer* audio);
|
// EchoCancellationImplWrapper implementation.
|
||||||
int ProcessCaptureAudio(AudioBuffer* audio);
|
virtual int ProcessRenderAudio(const AudioBuffer* audio);
|
||||||
|
virtual int ProcessCaptureAudio(AudioBuffer* audio);
|
||||||
|
|
||||||
// EchoCancellation implementation.
|
// EchoCancellation implementation.
|
||||||
virtual bool is_enabled() const;
|
virtual bool is_enabled() const;
|
||||||
@ -71,6 +71,7 @@ class EchoCancellationImpl : public EchoCancellation,
|
|||||||
bool stream_has_echo_;
|
bool stream_has_echo_;
|
||||||
bool delay_logging_enabled_;
|
bool delay_logging_enabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_WRAPPER_H_
|
||||||
|
#define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_WRAPPER_H_
|
||||||
|
|
||||||
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||||
|
#include "webrtc/modules/audio_processing/processing_component.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
class AudioProcessingImpl;
|
||||||
|
class AudioBuffer;
|
||||||
|
|
||||||
|
class EchoCancellationImplWrapper : public virtual EchoCancellation,
|
||||||
|
public virtual ProcessingComponent {
|
||||||
|
public:
|
||||||
|
static EchoCancellationImplWrapper* Create(
|
||||||
|
const AudioProcessingImpl* audioproc);
|
||||||
|
virtual ~EchoCancellationImplWrapper() {}
|
||||||
|
|
||||||
|
virtual int ProcessRenderAudio(const AudioBuffer* audio) = 0;
|
||||||
|
virtual int ProcessCaptureAudio(AudioBuffer* audio) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_WRAPPER_H_
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <stddef.h> // size_t
|
#include <stddef.h> // size_t
|
||||||
|
|
||||||
|
#include "webrtc/common.h"
|
||||||
#include "webrtc/modules/interface/module.h"
|
#include "webrtc/modules/interface/module.h"
|
||||||
#include "webrtc/typedefs.h"
|
#include "webrtc/typedefs.h"
|
||||||
|
|
||||||
@ -132,6 +133,10 @@ class AudioProcessing : public Module {
|
|||||||
// existing values. Otherwise they are no-ops.
|
// existing values. Otherwise they are no-ops.
|
||||||
virtual int Initialize() = 0;
|
virtual int Initialize() = 0;
|
||||||
|
|
||||||
|
// Pass down additional options which don't have explicit setters. This
|
||||||
|
// ensures the options are applied immediately.
|
||||||
|
virtual void SetExtraOptions(const Config& config) = 0;
|
||||||
|
|
||||||
// Sets the sample |rate| in Hz for both the primary and reverse audio
|
// Sets the sample |rate| in Hz for both the primary and reverse audio
|
||||||
// streams. 8000, 16000 or 32000 Hz are permitted.
|
// streams. 8000, 16000 or 32000 Hz are permitted.
|
||||||
virtual int set_sample_rate_hz(int rate) = 0;
|
virtual int set_sample_rate_hz(int rate) = 0;
|
||||||
|
@ -181,6 +181,8 @@ class MockAudioProcessing : public AudioProcessing {
|
|||||||
|
|
||||||
MOCK_METHOD0(Initialize,
|
MOCK_METHOD0(Initialize,
|
||||||
int());
|
int());
|
||||||
|
MOCK_METHOD1(SetExtraOptions,
|
||||||
|
void(const Config& config));
|
||||||
MOCK_METHOD1(set_sample_rate_hz,
|
MOCK_METHOD1(set_sample_rate_hz,
|
||||||
int(int rate));
|
int(int rate));
|
||||||
MOCK_CONST_METHOD0(sample_rate_hz,
|
MOCK_CONST_METHOD0(sample_rate_hz,
|
||||||
|
@ -16,14 +16,17 @@
|
|||||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class AudioProcessingImpl;
|
class AudioProcessingImpl;
|
||||||
|
|
||||||
class ProcessingComponent {
|
class ProcessingComponent {
|
||||||
public:
|
public:
|
||||||
|
ProcessingComponent() {}
|
||||||
explicit ProcessingComponent(const AudioProcessingImpl* apm);
|
explicit ProcessingComponent(const AudioProcessingImpl* apm);
|
||||||
virtual ~ProcessingComponent();
|
virtual ~ProcessingComponent();
|
||||||
|
|
||||||
virtual int Initialize();
|
virtual int Initialize();
|
||||||
|
virtual void SetExtraOptions(const Config& config) {}
|
||||||
virtual int Destroy();
|
virtual int Destroy();
|
||||||
|
|
||||||
bool is_component_enabled() const;
|
bool is_component_enabled() const;
|
||||||
@ -48,6 +51,7 @@ class ProcessingComponent {
|
|||||||
bool enabled_;
|
bool enabled_;
|
||||||
int num_handles_;
|
int num_handles_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_PROCESSING_COMPONENT_H__
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_PROCESSING_COMPONENT_H__
|
||||||
|
Reference in New Issue
Block a user