Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Unit tests for Expand class. | 11 // Unit tests for Expand class. |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_coding/neteq/expand.h" | 13 #include "webrtc/modules/audio_coding/neteq/expand.h" |
| 14 | 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/base/checks.h" | |
| 17 #include "webrtc/base/safe_conversions.h" | |
| 18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | |
| 16 #include "webrtc/modules/audio_coding/neteq/background_noise.h" | 19 #include "webrtc/modules/audio_coding/neteq/background_noise.h" |
| 17 #include "webrtc/modules/audio_coding/neteq/random_vector.h" | 20 #include "webrtc/modules/audio_coding/neteq/random_vector.h" |
| 21 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" | |
| 18 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 22 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
| 23 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h" | |
| 24 #include "webrtc/test/testsupport/fileutils.h" | |
| 19 | 25 |
| 20 namespace webrtc { | 26 namespace webrtc { |
| 21 | 27 |
| 22 TEST(Expand, CreateAndDestroy) { | 28 TEST(Expand, CreateAndDestroy) { |
| 23 int fs = 8000; | 29 int fs = 8000; |
| 24 size_t channels = 1; | 30 size_t channels = 1; |
| 25 BackgroundNoise bgn(channels); | 31 BackgroundNoise bgn(channels); |
| 26 SyncBuffer sync_buffer(1, 1000); | 32 SyncBuffer sync_buffer(1, 1000); |
| 27 RandomVector random_vector; | 33 RandomVector random_vector; |
| 28 Expand expand(&bgn, &sync_buffer, &random_vector, fs, channels); | 34 StatisticsCalculator statistics; |
| 35 Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels); | |
| 29 } | 36 } |
| 30 | 37 |
| 31 TEST(Expand, CreateUsingFactory) { | 38 TEST(Expand, CreateUsingFactory) { |
| 32 int fs = 8000; | 39 int fs = 8000; |
| 33 size_t channels = 1; | 40 size_t channels = 1; |
| 34 BackgroundNoise bgn(channels); | 41 BackgroundNoise bgn(channels); |
| 35 SyncBuffer sync_buffer(1, 1000); | 42 SyncBuffer sync_buffer(1, 1000); |
| 36 RandomVector random_vector; | 43 RandomVector random_vector; |
| 44 StatisticsCalculator statistics; | |
| 37 ExpandFactory expand_factory; | 45 ExpandFactory expand_factory; |
| 38 Expand* expand = | 46 Expand* expand = expand_factory.Create(&bgn, &sync_buffer, &random_vector, |
| 39 expand_factory.Create(&bgn, &sync_buffer, &random_vector, fs, channels); | 47 &statistics, fs, channels); |
| 40 EXPECT_TRUE(expand != NULL); | 48 EXPECT_TRUE(expand != NULL); |
| 41 delete expand; | 49 delete expand; |
| 42 } | 50 } |
| 43 | 51 |
| 52 namespace { | |
| 53 class FakeStatisticsCalculator : public StatisticsCalculator { | |
| 54 public: | |
| 55 void LogDelayedPacketOutageEvent(int outage_duration_ms) override { | |
| 56 last_outage_duration_ms_ = outage_duration_ms; | |
| 57 } | |
| 58 | |
| 59 int last_outage_duration_ms() const { return last_outage_duration_ms_; } | |
| 60 | |
| 61 private: | |
| 62 int last_outage_duration_ms_ = 0; | |
| 63 }; | |
| 64 } // namespace | |
| 65 | |
| 66 class ExpandTest : public ::testing::Test { | |
| 67 protected: | |
| 68 ExpandTest() | |
| 69 : input_file_(test::ResourcePath("audio_coding/testfile32kHz", "pcm"), | |
| 70 32000), | |
| 71 test_sample_rate_hz_(32000), | |
| 72 num_channels_(1), | |
| 73 background_noise_(num_channels_), | |
| 74 sync_buffer_( | |
| 75 num_channels_, | |
| 76 // Length of sync buffer is the same as in NetEq (120 ms). | |
| 77 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.
| |
| 78 expand_(&background_noise_, | |
| 79 &sync_buffer_, | |
| 80 &random_vector_, | |
| 81 &statistics_, | |
| 82 test_sample_rate_hz_, | |
| 83 num_channels_) { | |
| 84 WebRtcSpl_Init(); | |
| 85 input_file_.set_output_rate_hz(test_sample_rate_hz_); | |
| 86 } | |
| 87 | |
| 88 virtual void SetUp() { | |
|
minyue-webrtc
2015/08/17 15:42:11
probably
void SetUp() override
hlundin-webrtc
2015/08/18 08:13:46
Done.
| |
| 89 // Fast-forward the input file until there is speech (about 1.1 second into | |
| 90 // the file). | |
| 91 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.
| |
| 92 ASSERT_TRUE(input_file_.Move(speech_start_samples)); | |
| 93 | |
| 94 // Pre-load the sync buffer with speech data. | |
| 95 ASSERT_TRUE( | |
| 96 input_file_.Read(sync_buffer_.Size(), &sync_buffer_.Channel(0)[0])); | |
| 97 ASSERT_EQ(1u, num_channels_) << "Fix: Must populate all channels."; | |
| 98 } | |
| 99 | |
| 100 test::ResampleInputAudioFile input_file_; | |
| 101 int test_sample_rate_hz_; | |
| 102 size_t num_channels_; | |
| 103 BackgroundNoise background_noise_; | |
| 104 SyncBuffer sync_buffer_; | |
| 105 RandomVector random_vector_; | |
| 106 FakeStatisticsCalculator statistics_; | |
| 107 Expand expand_; | |
| 108 }; | |
| 109 | |
| 110 // This test calls the expand object to produce concealment data a few times, | |
| 111 // and then ends by calling SetParametersForNormalAfterExpand. This simulates | |
| 112 // the situation where the packet next up for decoding was just delayed, not | |
| 113 // lost. | |
| 114 TEST_F(ExpandTest, DelayedPacketOutage) { | |
| 115 AudioMultiVector output(num_channels_); | |
| 116 size_t sum_output_len_samples = 0; | |
| 117 for (int i = 0; i < 10; ++i) { | |
| 118 EXPECT_EQ(0, expand_.Process(&output)); | |
| 119 EXPECT_GT(output.Size(), 0u); | |
| 120 sum_output_len_samples += output.Size(); | |
| 121 EXPECT_EQ(0, statistics_.last_outage_duration_ms()); | |
| 122 } | |
| 123 expand_.SetParametersForNormalAfterExpand(); | |
| 124 // Convert |sum_output_len_samples| to milliseconds. | |
| 125 EXPECT_EQ(rtc::checked_cast<int>(sum_output_len_samples / | |
| 126 (test_sample_rate_hz_ / 1000)), | |
| 127 statistics_.last_outage_duration_ms()); | |
| 128 } | |
| 129 | |
| 130 // This test is similar to DelayedPacketOutage, but ends by calling | |
| 131 // SetParametersForMergeAfterExpand. This simulates the situation where the | |
| 132 // packet next up for decoding was actually lost (or at least a later packet | |
| 133 // arrived before it). | |
| 134 TEST_F(ExpandTest, LostPacketOutage) { | |
| 135 AudioMultiVector output(num_channels_); | |
| 136 size_t sum_output_len_samples = 0; | |
| 137 for (int i = 0; i < 10; ++i) { | |
| 138 EXPECT_EQ(0, expand_.Process(&output)); | |
| 139 EXPECT_GT(output.Size(), 0u); | |
| 140 sum_output_len_samples += output.Size(); | |
| 141 EXPECT_EQ(0, statistics_.last_outage_duration_ms()); | |
| 142 } | |
| 143 expand_.SetParametersForMergeAfterExpand(); | |
| 144 EXPECT_EQ(0, statistics_.last_outage_duration_ms()); | |
| 145 } | |
| 146 | |
| 44 // TODO(hlundin): Write more tests. | 147 // 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.
| |
| 45 | 148 |
| 46 } // namespace webrtc | 149 } // namespace webrtc |
| OLD | NEW |