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

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

Issue 1928293002: NetEq: Use a BuiltinAudioDecoderFactory to create decoders (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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
11 // Unit tests for PayloadSplitter class. 11 // Unit tests for PayloadSplitter class.
12 12
13 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" 13 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h"
14 14
15 #include <assert.h> 15 #include <assert.h>
16 16
17 #include <memory> 17 #include <memory>
18 #include <utility> // pair 18 #include <utility> // pair
19 19
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
22 #include "webrtc/modules/audio_coding/codecs/mock_audio_decoder_factory.h"
21 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" 23 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h"
22 #include "webrtc/modules/audio_coding/neteq/packet.h" 24 #include "webrtc/modules/audio_coding/neteq/packet.h"
23 25
24 using ::testing::Return; 26 using ::testing::Return;
25 using ::testing::ReturnNull; 27 using ::testing::ReturnNull;
26 28
27 namespace webrtc { 29 namespace webrtc {
28 30
29 static const int kRedPayloadType = 100; 31 static const int kRedPayloadType = 100;
30 static const size_t kPayloadLength = 10; 32 static const size_t kPayloadLength = 10;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 PacketList packet_list; 304 PacketList packet_list;
303 for (uint8_t i = 0; i <= 3; ++i) { 305 for (uint8_t i = 0; i <= 3; ++i) {
304 // Create packet with payload type |i|, payload length 10 bytes, all 0. 306 // Create packet with payload type |i|, payload length 10 bytes, all 0.
305 Packet* packet = CreatePacket(i, 10, 0); 307 Packet* packet = CreatePacket(i, 10, 0);
306 packet_list.push_back(packet); 308 packet_list.push_back(packet);
307 } 309 }
308 310
309 // Use a real DecoderDatabase object here instead of a mock, since it is 311 // Use a real DecoderDatabase object here instead of a mock, since it is
310 // easier to just register the payload types and let the actual implementation 312 // easier to just register the payload types and let the actual implementation
311 // do its job. 313 // do its job.
312 DecoderDatabase decoder_database; 314 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
315 DecoderDatabase decoder_database(std::move(factory));
313 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderCNGnb, "cng-nb"); 316 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderCNGnb, "cng-nb");
314 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu"); 317 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu");
315 decoder_database.RegisterPayload(2, NetEqDecoder::kDecoderAVT, "avt"); 318 decoder_database.RegisterPayload(2, NetEqDecoder::kDecoderAVT, "avt");
316 decoder_database.RegisterPayload(3, NetEqDecoder::kDecoderILBC, "ilbc"); 319 decoder_database.RegisterPayload(3, NetEqDecoder::kDecoderILBC, "ilbc");
317 320
318 PayloadSplitter splitter; 321 PayloadSplitter splitter;
319 splitter.CheckRedPayloads(&packet_list, decoder_database); 322 splitter.CheckRedPayloads(&packet_list, decoder_database);
320 323
321 ASSERT_EQ(3u, packet_list.size()); // Should have dropped the last packet. 324 ASSERT_EQ(3u, packet_list.size()); // Should have dropped the last packet.
322 // Verify packets. The loop verifies that payload types 0, 1, and 2 are in the 325 // Verify packets. The loop verifies that payload types 0, 1, and 2 are in the
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 delete (*it); 739 delete (*it);
737 it = packet_list.erase(it); 740 it = packet_list.erase(it);
738 } 741 }
739 742
740 // The destructor is called when decoder_database goes out of scope. 743 // The destructor is called when decoder_database goes out of scope.
741 EXPECT_CALL(decoder_database, Die()); 744 EXPECT_CALL(decoder_database, Die());
742 } 745 }
743 746
744 TEST(FecPayloadSplitter, MixedPayload) { 747 TEST(FecPayloadSplitter, MixedPayload) {
745 PacketList packet_list; 748 PacketList packet_list;
746 DecoderDatabase decoder_database; 749 DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory());
747 750
748 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus"); 751 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus");
749 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu"); 752 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu");
750 753
751 Packet* packet = CreatePacket(0, 10, 0xFF, true); 754 Packet* packet = CreatePacket(0, 10, 0xFF, true);
752 packet_list.push_back(packet); 755 packet_list.push_back(packet);
753 756
754 packet = CreatePacket(0, 10, 0); // Non-FEC Opus payload. 757 packet = CreatePacket(0, 10, 0); // Non-FEC Opus payload.
755 packet_list.push_back(packet); 758 packet_list.push_back(packet);
756 759
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 794
792 // Check fourth packet. 795 // Check fourth packet.
793 packet = packet_list.front(); 796 packet = packet_list.front();
794 VerifyPacket(packet, 10, 1, kSequenceNumber, kBaseTimestamp, 0, true); 797 VerifyPacket(packet, 10, 1, kSequenceNumber, kBaseTimestamp, 0, true);
795 delete [] packet->payload; 798 delete [] packet->payload;
796 delete packet; 799 delete packet;
797 } 800 }
798 801
799 TEST(FecPayloadSplitter, EmbedFecInRed) { 802 TEST(FecPayloadSplitter, EmbedFecInRed) {
800 PacketList packet_list; 803 PacketList packet_list;
801 DecoderDatabase decoder_database; 804 DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory());
802 805
803 const int kTimestampOffset = 20 * 48; // 20 ms * 48 kHz. 806 const int kTimestampOffset = 20 * 48; // 20 ms * 48 kHz.
804 uint8_t payload_types[] = {0, 0}; 807 uint8_t payload_types[] = {0, 0};
805 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus"); 808 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus");
806 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset, true); 809 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset, true);
807 packet_list.push_back(packet); 810 packet_list.push_back(packet);
808 811
809 PayloadSplitter splitter; 812 PayloadSplitter splitter;
810 EXPECT_EQ(PayloadSplitter::kOK, 813 EXPECT_EQ(PayloadSplitter::kOK,
811 splitter.SplitRed(&packet_list)); 814 splitter.SplitRed(&packet_list));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp); 856 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp);
854 EXPECT_EQ(kPayloadLength, packet->payload_length); 857 EXPECT_EQ(kPayloadLength, packet->payload_length);
855 EXPECT_TRUE(packet->primary); 858 EXPECT_TRUE(packet->primary);
856 EXPECT_EQ(packet->payload[3], 0); 859 EXPECT_EQ(packet->payload[3], 0);
857 delete [] packet->payload; 860 delete [] packet->payload;
858 delete packet; 861 delete packet;
859 packet_list.pop_front(); 862 packet_list.pop_front();
860 } 863 }
861 864
862 } // namespace webrtc 865 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698