Chromium Code Reviews| Index: webrtc/modules/audio_coding/neteq/expand_unittest.cc |
| diff --git a/webrtc/modules/audio_coding/neteq/expand_unittest.cc b/webrtc/modules/audio_coding/neteq/expand_unittest.cc |
| index 68b4f60f15c4958d05719b9541773d323b1aa423..3050afc5bf241e71acd9595e76b07eba91c8b36e 100644 |
| --- a/webrtc/modules/audio_coding/neteq/expand_unittest.cc |
| +++ b/webrtc/modules/audio_coding/neteq/expand_unittest.cc |
| @@ -13,9 +13,15 @@ |
| #include "webrtc/modules/audio_coding/neteq/expand.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "webrtc/base/checks.h" |
| +#include "webrtc/base/safe_conversions.h" |
| +#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
| #include "webrtc/modules/audio_coding/neteq/background_noise.h" |
| #include "webrtc/modules/audio_coding/neteq/random_vector.h" |
| +#include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" |
| #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
| +#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
| +#include "webrtc/test/testsupport/fileutils.h" |
| namespace webrtc { |
| @@ -25,7 +31,8 @@ TEST(Expand, CreateAndDestroy) { |
| BackgroundNoise bgn(channels); |
| SyncBuffer sync_buffer(1, 1000); |
| RandomVector random_vector; |
| - Expand expand(&bgn, &sync_buffer, &random_vector, fs, channels); |
| + StatisticsCalculator statistics; |
| + Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels); |
| } |
| TEST(Expand, CreateUsingFactory) { |
| @@ -34,13 +41,109 @@ TEST(Expand, CreateUsingFactory) { |
| BackgroundNoise bgn(channels); |
| SyncBuffer sync_buffer(1, 1000); |
| RandomVector random_vector; |
| + StatisticsCalculator statistics; |
| ExpandFactory expand_factory; |
| - Expand* expand = |
| - expand_factory.Create(&bgn, &sync_buffer, &random_vector, fs, channels); |
| + Expand* expand = expand_factory.Create(&bgn, &sync_buffer, &random_vector, |
| + &statistics, fs, channels); |
| EXPECT_TRUE(expand != NULL); |
| delete expand; |
| } |
| +namespace { |
| +class FakeStatisticsCalculator : public StatisticsCalculator { |
| + public: |
| + void LogDelayedPacketOutageEvent(int outage_duration_ms) override { |
| + last_outage_duration_ms_ = outage_duration_ms; |
| + } |
| + |
| + int last_outage_duration_ms() const { return last_outage_duration_ms_; } |
| + |
| + private: |
| + int last_outage_duration_ms_ = 0; |
| +}; |
| +} // namespace |
| + |
| +class ExpandTest : public ::testing::Test { |
| + protected: |
| + ExpandTest() |
| + : input_file_(test::ResourcePath("audio_coding/testfile32kHz", "pcm"), |
| + 32000), |
| + test_sample_rate_hz_(32000), |
| + num_channels_(1), |
| + background_noise_(num_channels_), |
| + sync_buffer_( |
| + num_channels_, |
| + // Length of sync buffer is the same as in NetEq (120 ms). |
| + rtc::CheckedDivExact(2 * 2880 * test_sample_rate_hz_, 8000)), |
|
minyue-webrtc
2015/08/17 15:42:11
why 2880? make a meaning name maybe
hlundin-webrtc
2015/08/18 08:13:46
Done.
|
| + expand_(&background_noise_, |
| + &sync_buffer_, |
| + &random_vector_, |
| + &statistics_, |
| + test_sample_rate_hz_, |
| + num_channels_) { |
| + WebRtcSpl_Init(); |
| + input_file_.set_output_rate_hz(test_sample_rate_hz_); |
| + } |
| + |
| + virtual void SetUp() { |
|
minyue-webrtc
2015/08/17 15:42:11
probably
void SetUp() override
hlundin-webrtc
2015/08/18 08:13:46
Done.
|
| + // Fast-forward the input file until there is speech (about 1.1 second into |
| + // the file). |
| + const size_t speech_start_samples = test_sample_rate_hz_ * 1.1; |
|
minyue-webrtc
2015/08/17 15:42:11
probably write conversion explicitly. I prefer
(s
hlundin-webrtc
2015/08/18 08:13:46
Done.
|
| + ASSERT_TRUE(input_file_.Move(speech_start_samples)); |
| + |
| + // Pre-load the sync buffer with speech data. |
| + ASSERT_TRUE( |
| + input_file_.Read(sync_buffer_.Size(), &sync_buffer_.Channel(0)[0])); |
| + ASSERT_EQ(1u, num_channels_) << "Fix: Must populate all channels."; |
| + } |
| + |
| + test::ResampleInputAudioFile input_file_; |
| + int test_sample_rate_hz_; |
| + size_t num_channels_; |
| + BackgroundNoise background_noise_; |
| + SyncBuffer sync_buffer_; |
| + RandomVector random_vector_; |
| + FakeStatisticsCalculator statistics_; |
| + Expand expand_; |
| +}; |
| + |
| +// This test calls the expand object to produce concealment data a few times, |
| +// and then ends by calling SetParametersForNormalAfterExpand. This simulates |
| +// the situation where the packet next up for decoding was just delayed, not |
| +// lost. |
| +TEST_F(ExpandTest, DelayedPacketOutage) { |
| + AudioMultiVector output(num_channels_); |
| + size_t sum_output_len_samples = 0; |
| + for (int i = 0; i < 10; ++i) { |
| + EXPECT_EQ(0, expand_.Process(&output)); |
| + EXPECT_GT(output.Size(), 0u); |
| + sum_output_len_samples += output.Size(); |
| + EXPECT_EQ(0, statistics_.last_outage_duration_ms()); |
| + } |
| + expand_.SetParametersForNormalAfterExpand(); |
| + // Convert |sum_output_len_samples| to milliseconds. |
| + EXPECT_EQ(rtc::checked_cast<int>(sum_output_len_samples / |
| + (test_sample_rate_hz_ / 1000)), |
| + statistics_.last_outage_duration_ms()); |
| +} |
| + |
| +// This test is similar to DelayedPacketOutage, but ends by calling |
| +// SetParametersForMergeAfterExpand. This simulates the situation where the |
| +// packet next up for decoding was actually lost (or at least a later packet |
| +// arrived before it). |
| +TEST_F(ExpandTest, LostPacketOutage) { |
| + AudioMultiVector output(num_channels_); |
| + size_t sum_output_len_samples = 0; |
| + for (int i = 0; i < 10; ++i) { |
| + EXPECT_EQ(0, expand_.Process(&output)); |
| + EXPECT_GT(output.Size(), 0u); |
| + sum_output_len_samples += output.Size(); |
| + EXPECT_EQ(0, statistics_.last_outage_duration_ms()); |
| + } |
| + expand_.SetParametersForMergeAfterExpand(); |
| + EXPECT_EQ(0, statistics_.last_outage_duration_ms()); |
| +} |
| + |
| // TODO(hlundin): Write more tests. |
|
minyue-webrtc
2015/08/17 15:42:11
I'd like to see test on behavior after Reset().
hlundin-webrtc
2015/08/18 08:13:47
Done.
|
| } // namespace webrtc |