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 Normal class. | 11 // Unit tests for Normal class. |
12 | 12 |
13 #include "webrtc/modules/audio_coding/neteq/normal.h" | 13 #include "webrtc/modules/audio_coding/neteq/normal.h" |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" |
20 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" | 20 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" |
21 #include "webrtc/modules/audio_coding/neteq/background_noise.h" | 21 #include "webrtc/modules/audio_coding/neteq/background_noise.h" |
22 #include "webrtc/modules/audio_coding/neteq/expand.h" | 22 #include "webrtc/modules/audio_coding/neteq/expand.h" |
23 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" | 23 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" |
24 #include "webrtc/modules/audio_coding/neteq/mock/mock_expand.h" | 24 #include "webrtc/modules/audio_coding/neteq/mock/mock_expand.h" |
25 #include "webrtc/modules/audio_coding/neteq/random_vector.h" | 25 #include "webrtc/modules/audio_coding/neteq/random_vector.h" |
26 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" | 26 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" |
27 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 27 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
28 | 28 |
29 using ::testing::_; | 29 using ::testing::_; |
30 using ::testing::Invoke; | |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 | 33 |
34 namespace { | |
35 | |
36 int ExpandProcess120ms(AudioMultiVector* output) { | |
37 AudioMultiVector dummy_audio(1, 11520u); | |
38 dummy_audio.CopyTo(output); | |
39 return 0; | |
40 } | |
41 | |
42 } // namespace | |
43 | |
33 TEST(Normal, CreateAndDestroy) { | 44 TEST(Normal, CreateAndDestroy) { |
34 MockDecoderDatabase db; | 45 MockDecoderDatabase db; |
35 int fs = 8000; | 46 int fs = 8000; |
36 size_t channels = 1; | 47 size_t channels = 1; |
37 BackgroundNoise bgn(channels); | 48 BackgroundNoise bgn(channels); |
38 SyncBuffer sync_buffer(1, 1000); | 49 SyncBuffer sync_buffer(1, 1000); |
39 RandomVector random_vector; | 50 RandomVector random_vector; |
40 StatisticsCalculator statistics; | 51 StatisticsCalculator statistics; |
41 Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels); | 52 Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels); |
42 Normal normal(fs, &db, bgn, &expand); | 53 Normal normal(fs, &db, bgn, &expand); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 EXPECT_EQ( | 125 EXPECT_EQ( |
115 0, | 126 0, |
116 normal.Process( | 127 normal.Process( |
117 input, input_len, kModeExpand, mute_factor_array.get(), &output)); | 128 input, input_len, kModeExpand, mute_factor_array.get(), &output)); |
118 EXPECT_EQ(0u, output.Size()); | 129 EXPECT_EQ(0u, output.Size()); |
119 | 130 |
120 EXPECT_CALL(db, Die()); // Called when |db| goes out of scope. | 131 EXPECT_CALL(db, Die()); // Called when |db| goes out of scope. |
121 EXPECT_CALL(expand, Die()); // Called when |expand| goes out of scope. | 132 EXPECT_CALL(expand, Die()); // Called when |expand| goes out of scope. |
122 } | 133 } |
123 | 134 |
135 TEST(Normal, LastModeExpand120msPacket) { | |
136 WebRtcSpl_Init(); | |
137 MockDecoderDatabase db; | |
138 const int kFs = 48000; | |
139 const size_t kPacketsizeBytes = 11520u; | |
140 const size_t kChannels = 1; | |
141 BackgroundNoise bgn(kChannels); | |
142 SyncBuffer sync_buffer(kChannels, 1000); | |
143 RandomVector random_vector; | |
144 StatisticsCalculator statistics; | |
145 MockExpand expand(&bgn, &sync_buffer, &random_vector, &statistics, kFs, | |
146 kChannels); | |
147 Normal normal(kFs, &db, bgn, &expand); | |
148 | |
149 int16_t input[kPacketsizeBytes] = {0}; | |
150 | |
151 std::unique_ptr<int16_t[]> mute_factor_array(new int16_t[kChannels]); | |
152 for (size_t i = 0; i < kChannels; ++i) { | |
minyue-webrtc
2016/05/02 10:44:53
this is the second fix
| |
153 mute_factor_array[i] = 16384; | |
154 } | |
155 | |
156 AudioMultiVector output(kChannels); | |
157 | |
158 EXPECT_CALL(expand, SetParametersForNormalAfterExpand()); | |
159 EXPECT_CALL(expand, Process(_)).WillOnce(Invoke(ExpandProcess120ms)); | |
160 EXPECT_CALL(expand, Reset()); | |
161 EXPECT_EQ(static_cast<int>(kPacketsizeBytes), | |
162 normal.Process(input, | |
163 kPacketsizeBytes, | |
164 kModeExpand, | |
165 mute_factor_array.get(), | |
166 &output)); | |
167 | |
168 EXPECT_EQ(kPacketsizeBytes, output.Size()); | |
169 | |
170 EXPECT_CALL(db, Die()); // Called when |db| goes out of scope. | |
171 EXPECT_CALL(expand, Die()); // Called when |expand| goes out of scope. | |
172 } | |
173 | |
124 // TODO(hlundin): Write more tests. | 174 // TODO(hlundin): Write more tests. |
125 | 175 |
126 } // namespace webrtc | 176 } // namespace webrtc |
OLD | NEW |