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 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 ASSERT_FALSE(packet == NULL); | 377 ASSERT_FALSE(packet == NULL); |
378 EXPECT_EQ(current_ts, packet->header.timestamp); | 378 EXPECT_EQ(current_ts, packet->header.timestamp); |
379 current_ts += ts_increment; | 379 current_ts += ts_increment; |
380 delete packet; | 380 delete packet; |
381 } | 381 } |
382 EXPECT_TRUE(buffer.Empty()); | 382 EXPECT_TRUE(buffer.Empty()); |
383 | 383 |
384 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 384 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
385 } | 385 } |
386 | 386 |
387 // The test first inserts a packet with narrow-band CNG, then a packet with | |
388 // wide-band speech. The expected behavior of the packet buffer is to detect a | |
389 // change in sample rate, even though no speech packet has been inserted before, | |
390 // and flush out the CNG packet. | |
391 TEST(PacketBuffer, CngFirstThenSpeechWithNewSampleRate) { | |
392 TickTimer tick_timer; | |
393 PacketBuffer buffer(10, &tick_timer); // 10 packets. | |
394 const uint8_t kCngPt = 13; | |
395 const int kPayloadLen = 10; | |
396 const uint8_t kSpeechPt = 100; | |
397 | |
398 MockDecoderDatabase decoder_database; | |
399 auto factory = CreateBuiltinAudioDecoderFactory(); | |
400 const DecoderDatabase::DecoderInfo infoCng(NetEqDecoder::kDecoderCNGnb, "", | |
minyue-webrtc
2016/09/01 15:59:45
info_cng
hlundin-webrtc
2016/09/01 16:11:15
kInfoCng, because it is a compile-time constant.
hlundin-webrtc
2016/09/01 16:15:27
No, you are right. Because of "factory", this is n
| |
401 factory); | |
402 EXPECT_CALL(decoder_database, GetDecoderInfo(kCngPt)) | |
403 .WillRepeatedly(Return(&infoCng)); | |
404 const DecoderDatabase::DecoderInfo infoSpeech(NetEqDecoder::kDecoderPCM16Bwb, | |
405 "", factory); | |
406 EXPECT_CALL(decoder_database, GetDecoderInfo(kSpeechPt)) | |
407 .WillRepeatedly(Return(&infoSpeech)); | |
minyue-webrtc
2016/09/01 15:59:45
info_speech
hlundin-webrtc
2016/09/01 16:11:15
kInfoSpeech, because it is a compile-time constant
hlundin-webrtc
2016/09/01 16:15:26
No, you are right. Because of "factory", this is n
| |
408 | |
409 // Insert first packet, which is narrow-band CNG. | |
410 PacketGenerator gen(0, 0, kCngPt, 10); | |
411 PacketList list; | |
412 list.push_back(gen.NextPacket(kPayloadLen)); | |
413 rtc::Optional<uint8_t> current_pt; | |
414 rtc::Optional<uint8_t> current_cng_pt; | |
415 EXPECT_EQ(PacketBuffer::kOK, | |
416 buffer.InsertPacketList(&list, decoder_database, ¤t_pt, | |
417 ¤t_cng_pt)); | |
418 EXPECT_TRUE(list.empty()); | |
419 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); | |
420 ASSERT_TRUE(buffer.NextRtpHeader()); | |
421 EXPECT_EQ(kCngPt, buffer.NextRtpHeader()->payloadType); | |
422 EXPECT_FALSE(current_pt); // Current payload type not set. | |
423 EXPECT_EQ(rtc::Optional<uint8_t>(kCngPt), | |
424 current_cng_pt); // CNG payload type set. | |
425 | |
426 // Insert second packet, which is wide-band speech. | |
427 Packet* packet = gen.NextPacket(kPayloadLen); | |
428 packet->header.payloadType = kSpeechPt; | |
429 list.push_back(packet); | |
430 // Expect the buffer to flush out the CNG packet, since it does not match the | |
431 // new speech sample rate. | |
432 EXPECT_EQ(PacketBuffer::kFlushed, | |
433 buffer.InsertPacketList(&list, decoder_database, ¤t_pt, | |
434 ¤t_cng_pt)); | |
435 EXPECT_TRUE(list.empty()); | |
436 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); | |
437 ASSERT_TRUE(buffer.NextRtpHeader()); | |
438 EXPECT_EQ(kSpeechPt, buffer.NextRtpHeader()->payloadType); | |
439 | |
440 EXPECT_EQ(rtc::Optional<uint8_t>(kSpeechPt), | |
441 current_pt); // Current payload type set. | |
442 EXPECT_FALSE(current_cng_pt); // CNG payload type reset. | |
443 | |
444 buffer.Flush(); // Clean up. | |
445 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | |
446 } | |
447 | |
387 TEST(PacketBuffer, Failures) { | 448 TEST(PacketBuffer, Failures) { |
388 const uint16_t start_seq_no = 17; | 449 const uint16_t start_seq_no = 17; |
389 const uint32_t start_ts = 4711; | 450 const uint32_t start_ts = 4711; |
390 const uint32_t ts_increment = 10; | 451 const uint32_t ts_increment = 10; |
391 int payload_len = 100; | 452 int payload_len = 100; |
392 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 453 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); |
393 TickTimer tick_timer; | 454 TickTimer tick_timer; |
394 | 455 |
395 PacketBuffer* buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 456 PacketBuffer* buffer = new PacketBuffer(100, &tick_timer); // 100 packets. |
396 Packet* packet = NULL; | 457 Packet* packet = NULL; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 // Test the IsObsoleteTimestamp method with different limit timestamps. | 645 // Test the IsObsoleteTimestamp method with different limit timestamps. |
585 TEST(PacketBuffer, IsObsoleteTimestamp) { | 646 TEST(PacketBuffer, IsObsoleteTimestamp) { |
586 TestIsObsoleteTimestamp(0); | 647 TestIsObsoleteTimestamp(0); |
587 TestIsObsoleteTimestamp(1); | 648 TestIsObsoleteTimestamp(1); |
588 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. | 649 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. |
589 TestIsObsoleteTimestamp(0x80000000); // 2^31. | 650 TestIsObsoleteTimestamp(0x80000000); // 2^31. |
590 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. | 651 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. |
591 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. | 652 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. |
592 } | 653 } |
593 } // namespace webrtc | 654 } // namespace webrtc |
OLD | NEW |