Changing to using factory methods for some classes in NetEq

In this CL, the Expand, Accelerate and PreemptiveExpand objects are
created using factory methods. The factory methods are injected into
NetEqImpl on creation. This is a step towards implementing a no-decode
operation.

BUG=2776
R=turaj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/6999005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5382 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2014-01-14 10:18:45 +00:00
parent aebb1ade9d
commit d9faa46d57
12 changed files with 137 additions and 14 deletions

View File

@ -78,4 +78,11 @@ Accelerate::ReturnCodes Accelerate::CheckCriteriaAndStretch(
}
}
Accelerate* AccelerateFactory::Create(
int sample_rate_hz,
size_t num_channels,
const BackgroundNoise& background_noise) const {
return new Accelerate(sample_rate_hz, num_channels, background_noise);
}
} // namespace webrtc

View File

@ -64,5 +64,14 @@ class Accelerate : public TimeStretch {
DISALLOW_COPY_AND_ASSIGN(Accelerate);
};
struct AccelerateFactory {
AccelerateFactory() {}
virtual ~AccelerateFactory() {}
virtual Accelerate* Create(int sample_rate_hz,
size_t num_channels,
const BackgroundNoise& background_noise) const;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_ACCELERATE_H_

View File

@ -864,4 +864,14 @@ void Expand::UpdateLagIndex() {
}
}
Expand* ExpandFactory::Create(BackgroundNoise* background_noise,
SyncBuffer* sync_buffer,
RandomVector* random_vector,
int fs,
size_t num_channels) const {
return new Expand(background_noise, sync_buffer, random_vector, fs,
num_channels);
}
} // namespace webrtc

View File

@ -153,5 +153,16 @@ class Expand {
DISALLOW_COPY_AND_ASSIGN(Expand);
};
struct ExpandFactory {
ExpandFactory() {}
virtual ~ExpandFactory() {}
virtual Expand* Create(BackgroundNoise* background_noise,
SyncBuffer* sync_buffer,
RandomVector* random_vector,
int fs,
size_t num_channels) const;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_EXPAND_H_

View File

@ -28,6 +28,19 @@ TEST(Expand, CreateAndDestroy) {
Expand expand(&bgn, &sync_buffer, &random_vector, fs, channels);
}
TEST(Expand, CreateUsingFactory) {
int fs = 8000;
size_t channels = 1;
BackgroundNoise bgn(channels);
SyncBuffer sync_buffer(1, 1000);
RandomVector random_vector;
ExpandFactory expand_factory;
Expand* expand =
expand_factory.Create(&bgn, &sync_buffer, &random_vector, fs, channels);
EXPECT_TRUE(expand != NULL);
delete expand;
}
// TODO(hlundin): Write more tests.
} // namespace webrtc

View File

@ -10,15 +10,18 @@
#include "webrtc/modules/audio_coding/neteq4/interface/neteq.h"
#include "webrtc/modules/audio_coding/neteq4/accelerate.h"
#include "webrtc/modules/audio_coding/neteq4/buffer_level_filter.h"
#include "webrtc/modules/audio_coding/neteq4/decoder_database.h"
#include "webrtc/modules/audio_coding/neteq4/delay_manager.h"
#include "webrtc/modules/audio_coding/neteq4/delay_peak_detector.h"
#include "webrtc/modules/audio_coding/neteq4/dtmf_buffer.h"
#include "webrtc/modules/audio_coding/neteq4/dtmf_tone_generator.h"
#include "webrtc/modules/audio_coding/neteq4/expand.h"
#include "webrtc/modules/audio_coding/neteq4/neteq_impl.h"
#include "webrtc/modules/audio_coding/neteq4/packet_buffer.h"
#include "webrtc/modules/audio_coding/neteq4/payload_splitter.h"
#include "webrtc/modules/audio_coding/neteq4/preemptive_expand.h"
#include "webrtc/modules/audio_coding/neteq4/timestamp_scaler.h"
namespace webrtc {
@ -37,6 +40,10 @@ NetEq* NetEq::Create(int sample_rate_hz) {
kMaxBytesInBuffer);
PayloadSplitter* payload_splitter = new PayloadSplitter;
TimestampScaler* timestamp_scaler = new TimestampScaler(*decoder_database);
AccelerateFactory* accelerate_factory = new AccelerateFactory;
ExpandFactory* expand_factory = new ExpandFactory;
PreemptiveExpandFactory* preemptive_expand_factory =
new PreemptiveExpandFactory;
return new NetEqImpl(sample_rate_hz,
buffer_level_filter,
decoder_database,
@ -46,7 +53,10 @@ NetEq* NetEq::Create(int sample_rate_hz) {
dtmf_tone_generator,
packet_buffer,
payload_splitter,
timestamp_scaler);
timestamp_scaler,
accelerate_factory,
expand_factory,
preemptive_expand_factory);
}
} // namespace webrtc

View File

@ -58,7 +58,10 @@ NetEqImpl::NetEqImpl(int fs,
DtmfToneGenerator* dtmf_tone_generator,
PacketBuffer* packet_buffer,
PayloadSplitter* payload_splitter,
TimestampScaler* timestamp_scaler)
TimestampScaler* timestamp_scaler,
AccelerateFactory* accelerate_factory,
ExpandFactory* expand_factory,
PreemptiveExpandFactory* preemptive_expand_factory)
: buffer_level_filter_(buffer_level_filter),
decoder_database_(decoder_database),
delay_manager_(delay_manager),
@ -69,6 +72,9 @@ NetEqImpl::NetEqImpl(int fs,
payload_splitter_(payload_splitter),
timestamp_scaler_(timestamp_scaler),
vad_(new PostDecodeVad()),
expand_factory_(expand_factory),
accelerate_factory_(accelerate_factory),
preemptive_expand_factory_(preemptive_expand_factory),
last_mode_(kModeNormal),
mute_factor_array_(NULL),
decoded_buffer_length_(kMaxFrameSize),
@ -1853,8 +1859,9 @@ void NetEqImpl::SetSampleRateAndChannels(int fs_hz, size_t channels) {
random_vector_.Reset();
// Delete Expand object and create a new one.
expand_.reset(new Expand(background_noise_.get(), sync_buffer_.get(),
&random_vector_, fs_hz, channels));
expand_.reset(expand_factory_->Create(background_noise_.get(),
sync_buffer_.get(), &random_vector_,
fs_hz, channels));
// Move index so that we create a small set of future samples (all 0).
sync_buffer_->set_next_index(sync_buffer_->next_index() -
expand_->overlap_length());
@ -1862,9 +1869,10 @@ void NetEqImpl::SetSampleRateAndChannels(int fs_hz, size_t channels) {
normal_.reset(new Normal(fs_hz, decoder_database_.get(), *background_noise_,
expand_.get()));
merge_.reset(new Merge(fs_hz, channels, expand_.get(), sync_buffer_.get()));
accelerate_.reset(new Accelerate(fs_hz, channels, *background_noise_));
preemptive_expand_.reset(new PreemptiveExpand(fs_hz, channels,
*background_noise_));
accelerate_.reset(
accelerate_factory_->Create(fs_hz, channels, *background_noise_));
preemptive_expand_.reset(
preemptive_expand_factory_->Create(fs_hz, channels, *background_noise_));
// Delete ComfortNoise object and create a new one.
comfort_noise_.reset(new ComfortNoise(fs_hz, decoder_database_.get(),

View File

@ -48,7 +48,10 @@ class PreemptiveExpand;
class RandomVector;
class SyncBuffer;
class TimestampScaler;
struct AccelerateFactory;
struct DtmfEvent;
struct ExpandFactory;
struct PreemptiveExpandFactory;
class NetEqImpl : public webrtc::NetEq {
public:
@ -63,7 +66,10 @@ class NetEqImpl : public webrtc::NetEq {
DtmfToneGenerator* dtmf_tone_generator,
PacketBuffer* packet_buffer,
PayloadSplitter* payload_splitter,
TimestampScaler* timestamp_scaler);
TimestampScaler* timestamp_scaler,
AccelerateFactory* accelerate_factory,
ExpandFactory* expand_factory,
PreemptiveExpandFactory* preemptive_expand_factory);
virtual ~NetEqImpl();
@ -315,10 +321,13 @@ class NetEqImpl : public webrtc::NetEq {
scoped_ptr<AudioMultiVector> algorithm_buffer_;
scoped_ptr<SyncBuffer> sync_buffer_;
scoped_ptr<Expand> expand_;
scoped_ptr<ExpandFactory> expand_factory_;
scoped_ptr<Normal> normal_;
scoped_ptr<Merge> merge_;
scoped_ptr<Accelerate> accelerate_;
scoped_ptr<AccelerateFactory> accelerate_factory_;
scoped_ptr<PreemptiveExpand> preemptive_expand_;
scoped_ptr<PreemptiveExpandFactory> preemptive_expand_factory_;
RandomVector random_vector_;
scoped_ptr<ComfortNoise> comfort_noise_;
Rtcp rtcp_;

View File

@ -13,6 +13,8 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "webrtc/modules/audio_coding/neteq4/accelerate.h"
#include "webrtc/modules/audio_coding/neteq4/expand.h"
#include "webrtc/modules/audio_coding/neteq4/mock/mock_audio_decoder.h"
#include "webrtc/modules/audio_coding/neteq4/mock/mock_buffer_level_filter.h"
#include "webrtc/modules/audio_coding/neteq4/mock/mock_decoder_database.h"
@ -22,6 +24,7 @@
#include "webrtc/modules/audio_coding/neteq4/mock/mock_dtmf_tone_generator.h"
#include "webrtc/modules/audio_coding/neteq4/mock/mock_packet_buffer.h"
#include "webrtc/modules/audio_coding/neteq4/mock/mock_payload_splitter.h"
#include "webrtc/modules/audio_coding/neteq4/preemptive_expand.h"
#include "webrtc/modules/audio_coding/neteq4/timestamp_scaler.h"
using ::testing::Return;
@ -60,6 +63,11 @@ class NetEqImplTest : public ::testing::Test {
timestamp_scaler_ = new TimestampScaler(*decoder_database_);
EXPECT_CALL(*decoder_database_, GetActiveCngDecoder())
.WillOnce(ReturnNull());
AccelerateFactory* accelerate_factory = new AccelerateFactory;
ExpandFactory* expand_factory = new ExpandFactory;
PreemptiveExpandFactory* preemptive_expand_factory =
new PreemptiveExpandFactory;
neteq_ = new NetEqImpl(kInitSampleRateHz,
buffer_level_filter_,
decoder_database_,
@ -69,7 +77,10 @@ class NetEqImplTest : public ::testing::Test {
dtmf_tone_generator_,
packet_buffer_,
payload_splitter_,
timestamp_scaler_);
timestamp_scaler_,
accelerate_factory,
expand_factory,
preemptive_expand_factory);
}
virtual ~NetEqImplTest() {

View File

@ -98,4 +98,11 @@ PreemptiveExpand::ReturnCodes PreemptiveExpand::CheckCriteriaAndStretch(
}
}
PreemptiveExpand* PreemptiveExpandFactory::Create(
int sample_rate_hz,
size_t num_channels,
const BackgroundNoise& background_noise) const {
return new PreemptiveExpand(sample_rate_hz, num_channels, background_noise);
}
} // namespace webrtc

View File

@ -70,5 +70,15 @@ class PreemptiveExpand : public TimeStretch {
DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand);
};
struct PreemptiveExpandFactory {
PreemptiveExpandFactory() {}
virtual ~PreemptiveExpandFactory() {}
virtual PreemptiveExpand* Create(
int sample_rate_hz,
size_t num_channels,
const BackgroundNoise& background_noise) const;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PREEMPTIVE_EXPAND_H_

View File

@ -19,11 +19,29 @@
namespace webrtc {
TEST(TimeStretch, CreateAndDestroy) {
int sample_rate = 8000;
size_t num_channels = 1;
BackgroundNoise bgn(num_channels);
Accelerate accelerate(sample_rate, num_channels, bgn);
PreemptiveExpand preemptive_expand(sample_rate, num_channels, bgn);
const int kSampleRate = 8000;
const size_t kNumChannels = 1;
BackgroundNoise bgn(kNumChannels);
Accelerate accelerate(kSampleRate, kNumChannels, bgn);
PreemptiveExpand preemptive_expand(kSampleRate, kNumChannels, bgn);
}
TEST(TimeStretch, CreateUsingFactory) {
const int kSampleRate = 8000;
const size_t kNumChannels = 1;
BackgroundNoise bgn(kNumChannels);
AccelerateFactory accelerate_factory;
Accelerate* accelerate =
accelerate_factory.Create(kSampleRate, kNumChannels, bgn);
EXPECT_TRUE(accelerate != NULL);
delete accelerate;
PreemptiveExpandFactory preemptive_expand_factory;
PreemptiveExpand* preemptive_expand =
preemptive_expand_factory.Create(kSampleRate, kNumChannels, bgn);
EXPECT_TRUE(preemptive_expand != NULL);
delete preemptive_expand;
}
// TODO(hlundin): Write more tests.