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
diff --git a/webrtc/modules/audio_coding/neteq4/accelerate.cc b/webrtc/modules/audio_coding/neteq4/accelerate.cc
index 88cfa4d..eb546e9 100644
--- a/webrtc/modules/audio_coding/neteq4/accelerate.cc
+++ b/webrtc/modules/audio_coding/neteq4/accelerate.cc
@@ -78,4 +78,11 @@
}
}
+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
diff --git a/webrtc/modules/audio_coding/neteq4/accelerate.h b/webrtc/modules/audio_coding/neteq4/accelerate.h
index 83e3e38..81f1abb 100644
--- a/webrtc/modules/audio_coding/neteq4/accelerate.h
+++ b/webrtc/modules/audio_coding/neteq4/accelerate.h
@@ -64,5 +64,14 @@
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_
diff --git a/webrtc/modules/audio_coding/neteq4/expand.cc b/webrtc/modules/audio_coding/neteq4/expand.cc
index 73f2ef8..cba9924 100644
--- a/webrtc/modules/audio_coding/neteq4/expand.cc
+++ b/webrtc/modules/audio_coding/neteq4/expand.cc
@@ -864,4 +864,14 @@
}
}
+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
diff --git a/webrtc/modules/audio_coding/neteq4/expand.h b/webrtc/modules/audio_coding/neteq4/expand.h
index 25ae619..d5bff9d 100644
--- a/webrtc/modules/audio_coding/neteq4/expand.h
+++ b/webrtc/modules/audio_coding/neteq4/expand.h
@@ -153,5 +153,16 @@
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_
diff --git a/webrtc/modules/audio_coding/neteq4/expand_unittest.cc b/webrtc/modules/audio_coding/neteq4/expand_unittest.cc
index a63ed14..353af2c 100644
--- a/webrtc/modules/audio_coding/neteq4/expand_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq4/expand_unittest.cc
@@ -28,6 +28,19 @@
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
diff --git a/webrtc/modules/audio_coding/neteq4/neteq.cc b/webrtc/modules/audio_coding/neteq4/neteq.cc
index 1ec71a2..a64f01b 100644
--- a/webrtc/modules/audio_coding/neteq4/neteq.cc
+++ b/webrtc/modules/audio_coding/neteq4/neteq.cc
@@ -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 @@
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 @@
dtmf_tone_generator,
packet_buffer,
payload_splitter,
- timestamp_scaler);
+ timestamp_scaler,
+ accelerate_factory,
+ expand_factory,
+ preemptive_expand_factory);
}
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc
index cd69fc9..d6fce18 100644
--- a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc
@@ -58,7 +58,10 @@
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 @@
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 @@
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 @@
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(),
diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.h b/webrtc/modules/audio_coding/neteq4/neteq_impl.h
index 83dd58b..c17ff1e 100644
--- a/webrtc/modules/audio_coding/neteq4/neteq_impl.h
+++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.h
@@ -48,7 +48,10 @@
class RandomVector;
class SyncBuffer;
class TimestampScaler;
+struct AccelerateFactory;
struct DtmfEvent;
+struct ExpandFactory;
+struct PreemptiveExpandFactory;
class NetEqImpl : public webrtc::NetEq {
public:
@@ -63,7 +66,10 @@
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 @@
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_;
diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl_unittest.cc b/webrtc/modules/audio_coding/neteq4/neteq_impl_unittest.cc
index 7a82053..0fbcedb 100644
--- a/webrtc/modules/audio_coding/neteq4/neteq_impl_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq4/neteq_impl_unittest.cc
@@ -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 @@
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 @@
dtmf_tone_generator_,
packet_buffer_,
payload_splitter_,
- timestamp_scaler_);
+ timestamp_scaler_,
+ accelerate_factory,
+ expand_factory,
+ preemptive_expand_factory);
}
virtual ~NetEqImplTest() {
diff --git a/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc b/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc
index ac787eb..c7ce310 100644
--- a/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc
+++ b/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc
@@ -98,4 +98,11 @@
}
}
+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
diff --git a/webrtc/modules/audio_coding/neteq4/preemptive_expand.h b/webrtc/modules/audio_coding/neteq4/preemptive_expand.h
index 4cd92cc..241425e 100644
--- a/webrtc/modules/audio_coding/neteq4/preemptive_expand.h
+++ b/webrtc/modules/audio_coding/neteq4/preemptive_expand.h
@@ -70,5 +70,15 @@
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_
diff --git a/webrtc/modules/audio_coding/neteq4/time_stretch_unittest.cc b/webrtc/modules/audio_coding/neteq4/time_stretch_unittest.cc
index cf8131f..188c18b 100644
--- a/webrtc/modules/audio_coding/neteq4/time_stretch_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq4/time_stretch_unittest.cc
@@ -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.