Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc

Issue 2281453002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 uint32_t timestamp, 148 uint32_t timestamp,
149 uint8_t payload_value, 149 uint8_t payload_value,
150 bool primary = true) { 150 bool primary = true) {
151 EXPECT_EQ(payload_length, packet->payload_length); 151 EXPECT_EQ(payload_length, packet->payload_length);
152 EXPECT_EQ(payload_type, packet->header.payloadType); 152 EXPECT_EQ(payload_type, packet->header.payloadType);
153 EXPECT_EQ(sequence_number, packet->header.sequenceNumber); 153 EXPECT_EQ(sequence_number, packet->header.sequenceNumber);
154 EXPECT_EQ(timestamp, packet->header.timestamp); 154 EXPECT_EQ(timestamp, packet->header.timestamp);
155 EXPECT_EQ(primary, packet->primary); 155 EXPECT_EQ(primary, packet->primary);
156 ASSERT_FALSE(packet->payload == NULL); 156 ASSERT_FALSE(packet->payload == NULL);
157 for (size_t i = 0; i < packet->payload_length; ++i) { 157 for (size_t i = 0; i < packet->payload_length; ++i) {
158 EXPECT_EQ(payload_value, packet->payload[i]); 158 ASSERT_EQ(payload_value, packet->payload[i]);
kwiberg-webrtc 2016/08/26 12:39:25 The caller of VerifyPacket doesn't call ASSERT/EXP
ossu 2016/08/26 13:05:30 Well you'll get one roughly one trillion errors du
kwiberg-webrtc 2016/08/26 22:05:13 OK. But then the callers ought to use ASSERT_NO_FA
159 } 159 }
160 } 160 }
161 161
162 // Start of test definitions. 162 // Start of test definitions.
163 163
164 TEST(PayloadSplitter, CreateAndDestroy) { 164 TEST(PayloadSplitter, CreateAndDestroy) {
165 PayloadSplitter* splitter = new PayloadSplitter; 165 PayloadSplitter* splitter = new PayloadSplitter;
166 delete splitter; 166 delete splitter;
167 } 167 }
168 168
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // get split. 363 // get split.
364 TEST(AudioPayloadSplitter, NonSplittable) { 364 TEST(AudioPayloadSplitter, NonSplittable) {
365 // Set up packets with different RTP payload types. The actual values do not 365 // Set up packets with different RTP payload types. The actual values do not
366 // matter, since we are mocking the decoder database anyway. 366 // matter, since we are mocking the decoder database anyway.
367 PacketList packet_list; 367 PacketList packet_list;
368 for (uint8_t i = 0; i < 6; ++i) { 368 for (uint8_t i = 0; i < 6; ++i) {
369 // Let the payload type be |i|, and the payload value 10 * |i|. 369 // Let the payload type be |i|, and the payload value 10 * |i|.
370 packet_list.push_back(CreatePacket(i, kPayloadLength, 10 * i)); 370 packet_list.push_back(CreatePacket(i, kPayloadLength, 10 * i));
371 } 371 }
372 372
373 class NoOpAudioDecoder : public AudioDecoder {
374 public:
375 void Reset() override { }
376 int SampleRateHz() const override { return 8000; }
377 size_t Channels() const override { return 1; }
378
379 private:
380 int DecodeInternal(const uint8_t* encoded,
381 size_t encoded_len,
382 int sample_rate_hz,
383 int16_t* decoded,
384 SpeechType* speech_type) override
385 { return 0; }
386 };
387
388 rtc::scoped_refptr<AudioDecoderFactory> factory =
389 CreateBuiltinAudioDecoderFactory();
390 std::unique_ptr<AudioDecoder> external_decoder(new NoOpAudioDecoder);
373 MockDecoderDatabase decoder_database; 391 MockDecoderDatabase decoder_database;
374 // Tell the mock decoder database to return DecoderInfo structs with different 392 // Tell the mock decoder database to return DecoderInfo structs with different
375 // codec types. 393 // codec types.
376 // Use scoped pointers to avoid having to delete them later. 394 // Use scoped pointers to avoid having to delete them later.
377 std::unique_ptr<DecoderDatabase::DecoderInfo> info0( 395 std::unique_ptr<DecoderDatabase::DecoderInfo> info0(
378 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderISAC, "")); 396 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderISAC, "",
397 factory));
379 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) 398 EXPECT_CALL(decoder_database, GetDecoderInfo(0))
380 .WillRepeatedly(Return(info0.get())); 399 .WillRepeatedly(Return(info0.get()));
381 std::unique_ptr<DecoderDatabase::DecoderInfo> info1( 400 std::unique_ptr<DecoderDatabase::DecoderInfo> info1(
382 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderISACswb, "")); 401 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderISACswb, "",
402 factory));
383 EXPECT_CALL(decoder_database, GetDecoderInfo(1)) 403 EXPECT_CALL(decoder_database, GetDecoderInfo(1))
384 .WillRepeatedly(Return(info1.get())); 404 .WillRepeatedly(Return(info1.get()));
385 std::unique_ptr<DecoderDatabase::DecoderInfo> info2( 405 std::unique_ptr<DecoderDatabase::DecoderInfo> info2(
386 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderRED, "")); 406 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderRED, "", factory));
387 EXPECT_CALL(decoder_database, GetDecoderInfo(2)) 407 EXPECT_CALL(decoder_database, GetDecoderInfo(2))
388 .WillRepeatedly(Return(info2.get())); 408 .WillRepeatedly(Return(info2.get()));
389 std::unique_ptr<DecoderDatabase::DecoderInfo> info3( 409 std::unique_ptr<DecoderDatabase::DecoderInfo> info3(
390 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderAVT, "")); 410 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderAVT, "", factory));
391 EXPECT_CALL(decoder_database, GetDecoderInfo(3)) 411 EXPECT_CALL(decoder_database, GetDecoderInfo(3))
392 .WillRepeatedly(Return(info3.get())); 412 .WillRepeatedly(Return(info3.get()));
393 std::unique_ptr<DecoderDatabase::DecoderInfo> info4( 413 std::unique_ptr<DecoderDatabase::DecoderInfo> info4(
394 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderCNGnb, "")); 414 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderCNGnb, "",
415 factory));
395 EXPECT_CALL(decoder_database, GetDecoderInfo(4)) 416 EXPECT_CALL(decoder_database, GetDecoderInfo(4))
396 .WillRepeatedly(Return(info4.get())); 417 .WillRepeatedly(Return(info4.get()));
397 std::unique_ptr<DecoderDatabase::DecoderInfo> info5( 418 std::unique_ptr<DecoderDatabase::DecoderInfo> info5(
398 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderArbitrary, "")); 419 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderArbitrary, "",
420 external_decoder.get()));
399 EXPECT_CALL(decoder_database, GetDecoderInfo(5)) 421 EXPECT_CALL(decoder_database, GetDecoderInfo(5))
400 .WillRepeatedly(Return(info5.get())); 422 .WillRepeatedly(Return(info5.get()));
401 423
402 PayloadSplitter splitter; 424 PayloadSplitter splitter;
403 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); 425 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database));
404 EXPECT_EQ(6u, packet_list.size()); 426 EXPECT_EQ(6u, packet_list.size());
405 427
406 // Check that all payloads are intact. 428 // Check that all payloads are intact.
407 uint8_t payload_type = 0; 429 uint8_t payload_type = 0;
408 PacketList::iterator it = packet_list.begin(); 430 PacketList::iterator it = packet_list.begin();
409 while (it != packet_list.end()) { 431 while (it != packet_list.end()) {
410 VerifyPacket((*it), kPayloadLength, payload_type, kSequenceNumber, 432 VerifyPacket((*it), kPayloadLength, payload_type, kSequenceNumber,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 PacketList packet_list; 542 PacketList packet_list;
521 static const uint8_t kPayloadType = 17; // Just a random number. 543 static const uint8_t kPayloadType = 17; // Just a random number.
522 for (int payload_size_ms = 10; payload_size_ms <= 60; payload_size_ms += 10) { 544 for (int payload_size_ms = 10; payload_size_ms <= 60; payload_size_ms += 10) {
523 // The payload values are set to be the same as the payload_size, so that 545 // The payload values are set to be the same as the payload_size, so that
524 // one can distinguish from which packet the split payloads come from. 546 // one can distinguish from which packet the split payloads come from.
525 size_t payload_size_bytes = payload_size_ms * bytes_per_ms_; 547 size_t payload_size_bytes = payload_size_ms * bytes_per_ms_;
526 packet_list.push_back(CreatePacket(kPayloadType, payload_size_bytes, 548 packet_list.push_back(CreatePacket(kPayloadType, payload_size_bytes,
527 payload_size_ms)); 549 payload_size_ms));
528 } 550 }
529 551
552 rtc::scoped_refptr<AudioDecoderFactory> factory =
553 CreateBuiltinAudioDecoderFactory();
530 MockDecoderDatabase decoder_database; 554 MockDecoderDatabase decoder_database;
531 // Tell the mock decoder database to return DecoderInfo structs with different 555 // Tell the mock decoder database to return DecoderInfo structs with different
532 // codec types. 556 // codec types.
533 // Use scoped pointers to avoid having to delete them later. 557 // Use scoped pointers to avoid having to delete them later.
534 // (Sample rate is set to 8000 Hz, but does not matter.) 558 // (Sample rate is set to 8000 Hz, but does not matter.)
535 std::unique_ptr<DecoderDatabase::DecoderInfo> info( 559 std::unique_ptr<DecoderDatabase::DecoderInfo> info(
536 new DecoderDatabase::DecoderInfo(decoder_type_, "")); 560 new DecoderDatabase::DecoderInfo(decoder_type_, "", factory));
537 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) 561 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType))
538 .WillRepeatedly(Return(info.get())); 562 .WillRepeatedly(Return(info.get()));
539 563
540 PayloadSplitter splitter; 564 PayloadSplitter splitter;
541 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); 565 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database));
542 // The payloads are expected to be split as follows: 566 // The payloads are expected to be split as follows:
543 // 10 ms -> 10 ms 567 // 10 ms -> 10 ms
544 // 20 ms -> 20 ms 568 // 20 ms -> 20 ms
545 // 30 ms -> 30 ms 569 // 30 ms -> 30 ms
546 // 40 ms -> 20 + 20 ms 570 // 40 ms -> 20 + 20 ms
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 static const uint8_t kPayloadType = 17; // Just a random number. 632 static const uint8_t kPayloadType = 17; // Just a random number.
609 const int frame_length_samples = frame_length_ms_ * 8; 633 const int frame_length_samples = frame_length_ms_ * 8;
610 size_t payload_length_bytes = frame_length_bytes_ * num_frames_; 634 size_t payload_length_bytes = frame_length_bytes_ * num_frames_;
611 Packet* packet = CreatePacket(kPayloadType, payload_length_bytes, 0); 635 Packet* packet = CreatePacket(kPayloadType, payload_length_bytes, 0);
612 // Fill payload with increasing integers {0, 1, 2, ...}. 636 // Fill payload with increasing integers {0, 1, 2, ...}.
613 for (size_t i = 0; i < packet->payload_length; ++i) { 637 for (size_t i = 0; i < packet->payload_length; ++i) {
614 packet->payload[i] = static_cast<uint8_t>(i); 638 packet->payload[i] = static_cast<uint8_t>(i);
615 } 639 }
616 packet_list.push_back(packet); 640 packet_list.push_back(packet);
617 641
642 rtc::scoped_refptr<AudioDecoderFactory> factory =
643 CreateBuiltinAudioDecoderFactory();
618 MockDecoderDatabase decoder_database; 644 MockDecoderDatabase decoder_database;
619 // Tell the mock decoder database to return DecoderInfo structs with different 645 // Tell the mock decoder database to return DecoderInfo structs with different
620 // codec types. 646 // codec types.
621 // Use scoped pointers to avoid having to delete them later. 647 // Use scoped pointers to avoid having to delete them later.
622 std::unique_ptr<DecoderDatabase::DecoderInfo> info( 648 std::unique_ptr<DecoderDatabase::DecoderInfo> info(
623 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); 649 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "",
650 factory));
624 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) 651 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType))
625 .WillRepeatedly(Return(info.get())); 652 .WillRepeatedly(Return(info.get()));
626 653
627 PayloadSplitter splitter; 654 PayloadSplitter splitter;
628 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); 655 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database));
629 EXPECT_EQ(num_frames_, packet_list.size()); 656 EXPECT_EQ(num_frames_, packet_list.size());
630 657
631 PacketList::iterator it = packet_list.begin(); 658 PacketList::iterator it = packet_list.begin();
632 int frame_num = 0; 659 int frame_num = 0;
633 uint8_t payload_value = 0; 660 uint8_t payload_value = 0;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 std::pair<int, int>(18, 30))); 701 std::pair<int, int>(18, 30)));
675 702
676 // Test too large payload size. 703 // Test too large payload size.
677 TEST(IlbcPayloadSplitter, TooLargePayload) { 704 TEST(IlbcPayloadSplitter, TooLargePayload) {
678 PacketList packet_list; 705 PacketList packet_list;
679 static const uint8_t kPayloadType = 17; // Just a random number. 706 static const uint8_t kPayloadType = 17; // Just a random number.
680 size_t kPayloadLengthBytes = 950; 707 size_t kPayloadLengthBytes = 950;
681 Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0); 708 Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0);
682 packet_list.push_back(packet); 709 packet_list.push_back(packet);
683 710
711 rtc::scoped_refptr<AudioDecoderFactory> factory =
712 CreateBuiltinAudioDecoderFactory();
684 MockDecoderDatabase decoder_database; 713 MockDecoderDatabase decoder_database;
685 std::unique_ptr<DecoderDatabase::DecoderInfo> info( 714 std::unique_ptr<DecoderDatabase::DecoderInfo> info(
686 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); 715 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "",
716 factory));
687 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) 717 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType))
688 .WillRepeatedly(Return(info.get())); 718 .WillRepeatedly(Return(info.get()));
689 719
690 PayloadSplitter splitter; 720 PayloadSplitter splitter;
691 EXPECT_EQ(PayloadSplitter::kTooLargePayload, 721 EXPECT_EQ(PayloadSplitter::kFrameSplitError,
692 splitter.SplitAudio(&packet_list, decoder_database)); 722 splitter.SplitAudio(&packet_list, decoder_database));
693 EXPECT_EQ(1u, packet_list.size()); 723 EXPECT_EQ(1u, packet_list.size());
694 724
695 // Delete the packets and payloads to avoid having the test leak memory. 725 // Delete the packets and payloads to avoid having the test leak memory.
696 PacketList::iterator it = packet_list.begin(); 726 PacketList::iterator it = packet_list.begin();
697 while (it != packet_list.end()) { 727 while (it != packet_list.end()) {
698 delete [] (*it)->payload; 728 delete [] (*it)->payload;
699 delete (*it); 729 delete (*it);
700 it = packet_list.erase(it); 730 it = packet_list.erase(it);
701 } 731 }
702 732
703 // The destructor is called when decoder_database goes out of scope. 733 // The destructor is called when decoder_database goes out of scope.
704 EXPECT_CALL(decoder_database, Die()); 734 EXPECT_CALL(decoder_database, Die());
705 } 735 }
706 736
707 // Payload not an integer number of frames. 737 // Payload not an integer number of frames.
708 TEST(IlbcPayloadSplitter, UnevenPayload) { 738 TEST(IlbcPayloadSplitter, UnevenPayload) {
709 PacketList packet_list; 739 PacketList packet_list;
710 static const uint8_t kPayloadType = 17; // Just a random number. 740 static const uint8_t kPayloadType = 17; // Just a random number.
711 size_t kPayloadLengthBytes = 39; // Not an even number of frames. 741 size_t kPayloadLengthBytes = 39; // Not an even number of frames.
712 Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0); 742 Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0);
713 packet_list.push_back(packet); 743 packet_list.push_back(packet);
714 744
745 rtc::scoped_refptr<AudioDecoderFactory> factory =
746 CreateBuiltinAudioDecoderFactory();
715 MockDecoderDatabase decoder_database; 747 MockDecoderDatabase decoder_database;
716 std::unique_ptr<DecoderDatabase::DecoderInfo> info( 748 std::unique_ptr<DecoderDatabase::DecoderInfo> info(
717 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); 749 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "",
750 factory));
718 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) 751 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType))
719 .WillRepeatedly(Return(info.get())); 752 .WillRepeatedly(Return(info.get()));
720 753
721 PayloadSplitter splitter; 754 PayloadSplitter splitter;
722 EXPECT_EQ(PayloadSplitter::kFrameSplitError, 755 EXPECT_EQ(PayloadSplitter::kFrameSplitError,
723 splitter.SplitAudio(&packet_list, decoder_database)); 756 splitter.SplitAudio(&packet_list, decoder_database));
724 EXPECT_EQ(1u, packet_list.size()); 757 EXPECT_EQ(1u, packet_list.size());
725 758
726 // Delete the packets and payloads to avoid having the test leak memory. 759 // Delete the packets and payloads to avoid having the test leak memory.
727 PacketList::iterator it = packet_list.begin(); 760 PacketList::iterator it = packet_list.begin();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp); 880 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp);
848 EXPECT_EQ(kPayloadLength, packet->payload_length); 881 EXPECT_EQ(kPayloadLength, packet->payload_length);
849 EXPECT_TRUE(packet->primary); 882 EXPECT_TRUE(packet->primary);
850 EXPECT_EQ(packet->payload[3], 0); 883 EXPECT_EQ(packet->payload[3], 0);
851 delete [] packet->payload; 884 delete [] packet->payload;
852 delete packet; 885 delete packet;
853 packet_list.pop_front(); 886 packet_list.pop_front();
854 } 887 }
855 888
856 } // namespace webrtc 889 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698