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 PacketBuffer class. | 11 // Unit tests for PacketBuffer class. |
12 | 12 |
13 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" | 13 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" |
14 | 14 |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |
17 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" | 18 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" |
18 #include "webrtc/modules/audio_coding/neteq/packet.h" | 19 #include "webrtc/modules/audio_coding/neteq/packet.h" |
19 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" | 20 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
20 | 21 |
21 using ::testing::Return; | 22 using ::testing::Return; |
22 using ::testing::_; | 23 using ::testing::_; |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
25 | 26 |
26 // Helper class to generate packets. Packets must be deleted by the user. | 27 // Helper class to generate packets. Packets must be deleted by the user. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 PacketList list; | 168 PacketList list; |
168 const int payload_len = 10; | 169 const int payload_len = 10; |
169 | 170 |
170 // Insert 10 small packets. | 171 // Insert 10 small packets. |
171 for (int i = 0; i < 10; ++i) { | 172 for (int i = 0; i < 10; ++i) { |
172 Packet* packet = gen.NextPacket(payload_len); | 173 Packet* packet = gen.NextPacket(payload_len); |
173 list.push_back(packet); | 174 list.push_back(packet); |
174 } | 175 } |
175 | 176 |
176 MockDecoderDatabase decoder_database; | 177 MockDecoderDatabase decoder_database; |
| 178 auto factory = CreateBuiltinAudioDecoderFactory(); |
| 179 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, "", |
| 180 factory); |
| 181 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
| 182 .WillRepeatedly(Return(&info)); |
177 rtc::Optional<uint8_t> current_pt; | 183 rtc::Optional<uint8_t> current_pt; |
178 rtc::Optional<uint8_t> current_cng_pt; | 184 rtc::Optional<uint8_t> current_cng_pt; |
179 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, | 185 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, |
180 decoder_database, | 186 decoder_database, |
181 ¤t_pt, | 187 ¤t_pt, |
182 ¤t_cng_pt)); | 188 ¤t_cng_pt)); |
183 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 189 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
184 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 190 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
185 EXPECT_EQ(0, current_pt.value_or(-1)); // Current payload type changed to 0. | 191 EXPECT_EQ(0, current_pt.value_or(-1)); // Current payload type changed to 0. |
186 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed. | 192 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed. |
(...skipping 18 matching lines...) Expand all Loading... |
205 Packet* packet = gen.NextPacket(payload_len); | 211 Packet* packet = gen.NextPacket(payload_len); |
206 list.push_back(packet); | 212 list.push_back(packet); |
207 } | 213 } |
208 // Insert 11th packet of another payload type (not CNG). | 214 // Insert 11th packet of another payload type (not CNG). |
209 Packet* packet = gen.NextPacket(payload_len); | 215 Packet* packet = gen.NextPacket(payload_len); |
210 packet->header.payloadType = 1; | 216 packet->header.payloadType = 1; |
211 list.push_back(packet); | 217 list.push_back(packet); |
212 | 218 |
213 | 219 |
214 MockDecoderDatabase decoder_database; | 220 MockDecoderDatabase decoder_database; |
| 221 auto factory = CreateBuiltinAudioDecoderFactory(); |
| 222 const DecoderDatabase::DecoderInfo info0(NetEqDecoder::kDecoderPCMu, "", |
| 223 factory); |
| 224 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
| 225 .WillRepeatedly(Return(&info0)); |
| 226 const DecoderDatabase::DecoderInfo info1(NetEqDecoder::kDecoderPCMa, "", |
| 227 factory); |
| 228 EXPECT_CALL(decoder_database, GetDecoderInfo(1)) |
| 229 .WillRepeatedly(Return(&info1)); |
215 rtc::Optional<uint8_t> current_pt; | 230 rtc::Optional<uint8_t> current_pt; |
216 rtc::Optional<uint8_t> current_cng_pt; | 231 rtc::Optional<uint8_t> current_cng_pt; |
217 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list, | 232 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list, |
218 decoder_database, | 233 decoder_database, |
219 ¤t_pt, | 234 ¤t_pt, |
220 ¤t_cng_pt)); | 235 ¤t_cng_pt)); |
221 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 236 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
222 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet. | 237 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet. |
223 EXPECT_EQ(1, current_pt.value_or(-1)); // Current payload type changed to 0. | 238 EXPECT_EQ(1, current_pt.value_or(-1)); // Current payload type changed to 0. |
224 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed. | 239 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 for (int i = 0; i < 10; ++i) { | 349 for (int i = 0; i < 10; ++i) { |
335 Packet* packet = gen.NextPacket(payload_len); | 350 Packet* packet = gen.NextPacket(payload_len); |
336 if (i % 2) { | 351 if (i % 2) { |
337 list.push_front(packet); | 352 list.push_front(packet); |
338 } else { | 353 } else { |
339 list.push_back(packet); | 354 list.push_back(packet); |
340 } | 355 } |
341 } | 356 } |
342 | 357 |
343 MockDecoderDatabase decoder_database; | 358 MockDecoderDatabase decoder_database; |
| 359 auto factory = CreateBuiltinAudioDecoderFactory(); |
| 360 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, "", |
| 361 factory); |
| 362 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
| 363 .WillRepeatedly(Return(&info)); |
344 rtc::Optional<uint8_t> current_pt; | 364 rtc::Optional<uint8_t> current_pt; |
345 rtc::Optional<uint8_t> current_cng_pt; | 365 rtc::Optional<uint8_t> current_cng_pt; |
346 | 366 |
347 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, | 367 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, |
348 decoder_database, | 368 decoder_database, |
349 ¤t_pt, | 369 ¤t_pt, |
350 ¤t_cng_pt)); | 370 ¤t_cng_pt)); |
351 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 371 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
352 | 372 |
353 // Extract them and make sure that come out in the right order. | 373 // Extract them and make sure that come out in the right order. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // discarded. | 425 // discarded. |
406 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 426 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. |
407 PacketList list; | 427 PacketList list; |
408 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 428 list.push_back(gen.NextPacket(payload_len)); // Valid packet. |
409 packet = gen.NextPacket(payload_len); | 429 packet = gen.NextPacket(payload_len); |
410 delete [] packet->payload; | 430 delete [] packet->payload; |
411 packet->payload = NULL; // Invalid. | 431 packet->payload = NULL; // Invalid. |
412 list.push_back(packet); | 432 list.push_back(packet); |
413 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 433 list.push_back(gen.NextPacket(payload_len)); // Valid packet. |
414 MockDecoderDatabase decoder_database; | 434 MockDecoderDatabase decoder_database; |
| 435 auto factory = CreateBuiltinAudioDecoderFactory(); |
| 436 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, "", |
| 437 factory); |
| 438 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
| 439 .WillRepeatedly(Return(&info)); |
415 rtc::Optional<uint8_t> current_pt; | 440 rtc::Optional<uint8_t> current_pt; |
416 rtc::Optional<uint8_t> current_cng_pt; | 441 rtc::Optional<uint8_t> current_cng_pt; |
417 EXPECT_EQ(PacketBuffer::kInvalidPacket, | 442 EXPECT_EQ(PacketBuffer::kInvalidPacket, |
418 buffer->InsertPacketList(&list, | 443 buffer->InsertPacketList(&list, |
419 decoder_database, | 444 decoder_database, |
420 ¤t_pt, | 445 ¤t_pt, |
421 ¤t_cng_pt)); | 446 ¤t_cng_pt)); |
422 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 447 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
423 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); | 448 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); |
424 delete buffer; | 449 delete buffer; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // Test the IsObsoleteTimestamp method with different limit timestamps. | 589 // Test the IsObsoleteTimestamp method with different limit timestamps. |
565 TEST(PacketBuffer, IsObsoleteTimestamp) { | 590 TEST(PacketBuffer, IsObsoleteTimestamp) { |
566 TestIsObsoleteTimestamp(0); | 591 TestIsObsoleteTimestamp(0); |
567 TestIsObsoleteTimestamp(1); | 592 TestIsObsoleteTimestamp(1); |
568 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. | 593 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. |
569 TestIsObsoleteTimestamp(0x80000000); // 2^31. | 594 TestIsObsoleteTimestamp(0x80000000); // 2^31. |
570 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. | 595 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. |
571 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. | 596 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. |
572 } | 597 } |
573 } // namespace webrtc | 598 } // namespace webrtc |
OLD | NEW |