diff --git a/webrtc/modules/audio_coding/neteq4/accelerate.cc b/webrtc/modules/audio_coding/neteq4/accelerate.cc index 88cfa4dad9..eb546e9764 100644 --- a/webrtc/modules/audio_coding/neteq4/accelerate.cc +++ b/webrtc/modules/audio_coding/neteq4/accelerate.cc @@ -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 diff --git a/webrtc/modules/audio_coding/neteq4/accelerate.h b/webrtc/modules/audio_coding/neteq4/accelerate.h index 83e3e38454..81f1abb53c 100644 --- a/webrtc/modules/audio_coding/neteq4/accelerate.h +++ b/webrtc/modules/audio_coding/neteq4/accelerate.h @@ -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_ diff --git a/webrtc/modules/audio_coding/neteq4/expand.cc b/webrtc/modules/audio_coding/neteq4/expand.cc index 73f2ef85a5..cba99243da 100644 --- a/webrtc/modules/audio_coding/neteq4/expand.cc +++ b/webrtc/modules/audio_coding/neteq4/expand.cc @@ -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 diff --git a/webrtc/modules/audio_coding/neteq4/expand.h b/webrtc/modules/audio_coding/neteq4/expand.h index 25ae61903a..d5bff9d494 100644 --- a/webrtc/modules/audio_coding/neteq4/expand.h +++ b/webrtc/modules/audio_coding/neteq4/expand.h @@ -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_ diff --git a/webrtc/modules/audio_coding/neteq4/expand_unittest.cc b/webrtc/modules/audio_coding/neteq4/expand_unittest.cc index a63ed142f0..353af2cf4e 100644 --- a/webrtc/modules/audio_coding/neteq4/expand_unittest.cc +++ b/webrtc/modules/audio_coding/neteq4/expand_unittest.cc @@ -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 diff --git a/webrtc/modules/audio_coding/neteq4/neteq.cc b/webrtc/modules/audio_coding/neteq4/neteq.cc index 1ec71a2a6f..a64f01b256 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 @@ 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 diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc index cd69fc9e3b..d6fce18cc0 100644 --- a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc @@ -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(), diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.h b/webrtc/modules/audio_coding/neteq4/neteq_impl.h index 83dd58b5ac..c17ff1e29c 100644 --- a/webrtc/modules/audio_coding/neteq4/neteq_impl.h +++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.h @@ -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 algorithm_buffer_; scoped_ptr sync_buffer_; scoped_ptr expand_; + scoped_ptr expand_factory_; scoped_ptr normal_; scoped_ptr merge_; scoped_ptr accelerate_; + scoped_ptr accelerate_factory_; scoped_ptr preemptive_expand_; + scoped_ptr preemptive_expand_factory_; RandomVector random_vector_; scoped_ptr 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 7a82053918..0fbcedbedb 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 @@ 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() { diff --git a/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc b/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc index ac787eb1d6..c7ce31040a 100644 --- a/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc +++ b/webrtc/modules/audio_coding/neteq4/preemptive_expand.cc @@ -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 diff --git a/webrtc/modules/audio_coding/neteq4/preemptive_expand.h b/webrtc/modules/audio_coding/neteq4/preemptive_expand.h index 4cd92cc0bb..241425e818 100644 --- a/webrtc/modules/audio_coding/neteq4/preemptive_expand.h +++ b/webrtc/modules/audio_coding/neteq4/preemptive_expand.h @@ -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_ diff --git a/webrtc/modules/audio_coding/neteq4/time_stretch_unittest.cc b/webrtc/modules/audio_coding/neteq4/time_stretch_unittest.cc index cf8131f3a0..188c18b71c 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.