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.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_COMMON_H
|
||||
#define WEBRTC_COMMON_H
|
||||
#ifndef WEBRTC_COMMON_H_
|
||||
#define WEBRTC_COMMON_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
@ -38,14 +38,14 @@ namespace webrtc {
|
||||
class Config {
|
||||
public:
|
||||
// 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.
|
||||
//
|
||||
// Requires std::is_default_constructible<T>
|
||||
template<typename T> const T& Get() const;
|
||||
|
||||
// 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);
|
||||
|
||||
Config() {}
|
||||
@ -116,5 +116,7 @@ void Config::Set(T* value) {
|
||||
delete it;
|
||||
it = new Option<T>(value);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_COMMON_H
|
||||
|
||||
#endif // WEBRTC_COMMON_H_
|
||||
|
@ -60,6 +60,7 @@
|
||||
'audio_processing_impl.h',
|
||||
'echo_cancellation_impl.cc',
|
||||
'echo_cancellation_impl.h',
|
||||
'echo_cancellation_impl_wrapper.h',
|
||||
'echo_control_mobile_impl.cc',
|
||||
'echo_control_mobile_impl.h',
|
||||
'gain_control_impl.cc',
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <assert.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/gain_control_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_input_channels_(1),
|
||||
num_output_channels_(1) {
|
||||
echo_cancellation_ = new EchoCancellationImpl(this);
|
||||
echo_cancellation_ = EchoCancellationImplWrapper::Create(this);
|
||||
component_list_.push_back(echo_cancellation_);
|
||||
|
||||
echo_control_mobile_ = new EchoControlMobileImpl(this);
|
||||
@ -181,6 +181,12 @@ int AudioProcessingImpl::InitializeLocked() {
|
||||
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) {
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
if (rate == sample_rate_hz_) {
|
||||
|
@ -21,7 +21,7 @@
|
||||
namespace webrtc {
|
||||
class AudioBuffer;
|
||||
class CriticalSectionWrapper;
|
||||
class EchoCancellationImpl;
|
||||
class EchoCancellationImplWrapper;
|
||||
class EchoControlMobileImpl;
|
||||
class FileWrapper;
|
||||
class GainControlImpl;
|
||||
@ -58,6 +58,7 @@ class AudioProcessingImpl : public AudioProcessing {
|
||||
// AudioProcessing methods.
|
||||
virtual int Initialize();
|
||||
virtual int InitializeLocked();
|
||||
virtual void SetExtraOptions(const Config& config);
|
||||
virtual int set_sample_rate_hz(int rate);
|
||||
virtual int sample_rate_hz() const;
|
||||
virtual int set_num_channels(int input_channels, int output_channels);
|
||||
@ -92,7 +93,7 @@ class AudioProcessingImpl : public AudioProcessing {
|
||||
|
||||
int id_;
|
||||
|
||||
EchoCancellationImpl* echo_cancellation_;
|
||||
EchoCancellationImplWrapper* echo_cancellation_;
|
||||
EchoControlMobileImpl* echo_control_mobile_;
|
||||
GainControlImpl* gain_control_;
|
||||
HighPassFilterImpl* high_pass_filter_;
|
||||
|
@ -54,6 +54,11 @@ AudioProcessing::Error MapError(int err) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
EchoCancellationImplWrapper* EchoCancellationImplWrapper::Create(
|
||||
const AudioProcessingImpl* audioproc) {
|
||||
return new EchoCancellationImpl(audioproc);
|
||||
}
|
||||
|
||||
EchoCancellationImpl::EchoCancellationImpl(const AudioProcessingImpl* apm)
|
||||
: ProcessingComponent(apm),
|
||||
apm_(apm),
|
||||
|
@ -11,21 +11,21 @@
|
||||
#ifndef 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/processing_component.h"
|
||||
#include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioProcessingImpl;
|
||||
class AudioBuffer;
|
||||
|
||||
class EchoCancellationImpl : public EchoCancellation,
|
||||
public ProcessingComponent {
|
||||
class EchoCancellationImpl : public EchoCancellationImplWrapper {
|
||||
public:
|
||||
explicit EchoCancellationImpl(const AudioProcessingImpl* apm);
|
||||
virtual ~EchoCancellationImpl();
|
||||
|
||||
int ProcessRenderAudio(const AudioBuffer* audio);
|
||||
int ProcessCaptureAudio(AudioBuffer* audio);
|
||||
// EchoCancellationImplWrapper implementation.
|
||||
virtual int ProcessRenderAudio(const AudioBuffer* audio);
|
||||
virtual int ProcessCaptureAudio(AudioBuffer* audio);
|
||||
|
||||
// EchoCancellation implementation.
|
||||
virtual bool is_enabled() const;
|
||||
@ -71,6 +71,7 @@ class EchoCancellationImpl : public EchoCancellation,
|
||||
bool stream_has_echo_;
|
||||
bool delay_logging_enabled_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#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 "webrtc/common.h"
|
||||
#include "webrtc/modules/interface/module.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
@ -132,6 +133,10 @@ class AudioProcessing : public Module {
|
||||
// existing values. Otherwise they are no-ops.
|
||||
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
|
||||
// streams. 8000, 16000 or 32000 Hz are permitted.
|
||||
virtual int set_sample_rate_hz(int rate) = 0;
|
||||
|
@ -181,6 +181,8 @@ class MockAudioProcessing : public AudioProcessing {
|
||||
|
||||
MOCK_METHOD0(Initialize,
|
||||
int());
|
||||
MOCK_METHOD1(SetExtraOptions,
|
||||
void(const Config& config));
|
||||
MOCK_METHOD1(set_sample_rate_hz,
|
||||
int(int rate));
|
||||
MOCK_CONST_METHOD0(sample_rate_hz,
|
||||
|
@ -16,14 +16,17 @@
|
||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioProcessingImpl;
|
||||
|
||||
class ProcessingComponent {
|
||||
public:
|
||||
ProcessingComponent() {}
|
||||
explicit ProcessingComponent(const AudioProcessingImpl* apm);
|
||||
virtual ~ProcessingComponent();
|
||||
|
||||
virtual int Initialize();
|
||||
virtual void SetExtraOptions(const Config& config) {}
|
||||
virtual int Destroy();
|
||||
|
||||
bool is_component_enabled() const;
|
||||
@ -48,6 +51,7 @@ class ProcessingComponent {
|
||||
bool enabled_;
|
||||
int num_handles_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_PROCESSING_COMPONENT_H__
|
||||
|
Reference in New Issue
Block a user