Index: webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc |
diff --git a/webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc b/webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc |
index bd9d4d46595c849a244c3020817ccb62b8a66b4c..0a4b2157b5acc4b7e8c0500481d8dfd585487091 100644 |
--- a/webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc |
+++ b/webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc |
@@ -152,7 +152,7 @@ void VerifyPacket(const Packet* packet, |
EXPECT_EQ(primary, packet->primary); |
ASSERT_FALSE(packet->payload.empty()); |
for (size_t i = 0; i < packet->payload.size(); ++i) { |
- EXPECT_EQ(payload_value, packet->payload[i]); |
+ ASSERT_EQ(payload_value, packet->payload.data()[i]); |
} |
} |
@@ -344,376 +344,6 @@ TEST(RedPayloadSplitter, WrongPayloadLength) { |
packet_list.pop_front(); |
} |
-// Test that iSAC, iSAC-swb, RED, DTMF, CNG, and "Arbitrary" payloads do not |
-// get split. |
-TEST(AudioPayloadSplitter, NonSplittable) { |
- // Set up packets with different RTP payload types. The actual values do not |
- // matter, since we are mocking the decoder database anyway. |
- PacketList packet_list; |
- for (uint8_t i = 0; i < 6; ++i) { |
- // Let the payload type be |i|, and the payload value 10 * |i|. |
- packet_list.push_back(CreatePacket(i, kPayloadLength, 10 * i)); |
- } |
- |
- MockDecoderDatabase decoder_database; |
- // Tell the mock decoder database to return DecoderInfo structs with different |
- // codec types. |
- // Use scoped pointers to avoid having to delete them later. |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info0( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderISAC, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
- .WillRepeatedly(Return(info0.get())); |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info1( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderISACswb, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(1)) |
- .WillRepeatedly(Return(info1.get())); |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info2( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderRED, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(2)) |
- .WillRepeatedly(Return(info2.get())); |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info3( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderAVT, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(3)) |
- .WillRepeatedly(Return(info3.get())); |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info4( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderCNGnb, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(4)) |
- .WillRepeatedly(Return(info4.get())); |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info5( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderArbitrary, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(5)) |
- .WillRepeatedly(Return(info5.get())); |
- |
- PayloadSplitter splitter; |
- EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); |
- EXPECT_EQ(6u, packet_list.size()); |
- |
- // Check that all payloads are intact. |
- uint8_t payload_type = 0; |
- PacketList::iterator it = packet_list.begin(); |
- while (it != packet_list.end()) { |
- VerifyPacket((*it), kPayloadLength, payload_type, kSequenceNumber, |
- kBaseTimestamp, 10 * payload_type); |
- ++payload_type; |
- delete (*it); |
- it = packet_list.erase(it); |
- } |
- |
- // The destructor is called when decoder_database goes out of scope. |
- EXPECT_CALL(decoder_database, Die()); |
-} |
- |
-// Test unknown payload type. |
-TEST(AudioPayloadSplitter, UnknownPayloadType) { |
- PacketList packet_list; |
- static const uint8_t kPayloadType = 17; // Just a random number. |
- size_t kPayloadLengthBytes = 4711; // Random number. |
- packet_list.push_back(CreatePacket(kPayloadType, kPayloadLengthBytes, 0)); |
- |
- MockDecoderDatabase decoder_database; |
- // Tell the mock decoder database to return NULL when asked for decoder info. |
- // This signals that the decoder database does not recognize the payload type. |
- EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) |
- .WillRepeatedly(ReturnNull()); |
- |
- PayloadSplitter splitter; |
- EXPECT_EQ(PayloadSplitter::kUnknownPayloadType, |
- splitter.SplitAudio(&packet_list, decoder_database)); |
- EXPECT_EQ(1u, packet_list.size()); |
- |
- |
- // Delete the packets and payloads to avoid having the test leak memory. |
- PacketList::iterator it = packet_list.begin(); |
- while (it != packet_list.end()) { |
- delete (*it); |
- it = packet_list.erase(it); |
- } |
- |
- // The destructor is called when decoder_database goes out of scope. |
- EXPECT_CALL(decoder_database, Die()); |
-} |
- |
-class SplitBySamplesTest : public ::testing::TestWithParam<NetEqDecoder> { |
- protected: |
- virtual void SetUp() { |
- decoder_type_ = GetParam(); |
- switch (decoder_type_) { |
- case NetEqDecoder::kDecoderPCMu: |
- case NetEqDecoder::kDecoderPCMa: |
- bytes_per_ms_ = 8; |
- samples_per_ms_ = 8; |
- break; |
- case NetEqDecoder::kDecoderPCMu_2ch: |
- case NetEqDecoder::kDecoderPCMa_2ch: |
- bytes_per_ms_ = 2 * 8; |
- samples_per_ms_ = 8; |
- break; |
- case NetEqDecoder::kDecoderG722: |
- bytes_per_ms_ = 8; |
- samples_per_ms_ = 16; |
- break; |
- case NetEqDecoder::kDecoderPCM16B: |
- bytes_per_ms_ = 16; |
- samples_per_ms_ = 8; |
- break; |
- case NetEqDecoder::kDecoderPCM16Bwb: |
- bytes_per_ms_ = 32; |
- samples_per_ms_ = 16; |
- break; |
- case NetEqDecoder::kDecoderPCM16Bswb32kHz: |
- bytes_per_ms_ = 64; |
- samples_per_ms_ = 32; |
- break; |
- case NetEqDecoder::kDecoderPCM16Bswb48kHz: |
- bytes_per_ms_ = 96; |
- samples_per_ms_ = 48; |
- break; |
- case NetEqDecoder::kDecoderPCM16B_2ch: |
- bytes_per_ms_ = 2 * 16; |
- samples_per_ms_ = 8; |
- break; |
- case NetEqDecoder::kDecoderPCM16Bwb_2ch: |
- bytes_per_ms_ = 2 * 32; |
- samples_per_ms_ = 16; |
- break; |
- case NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch: |
- bytes_per_ms_ = 2 * 64; |
- samples_per_ms_ = 32; |
- break; |
- case NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch: |
- bytes_per_ms_ = 2 * 96; |
- samples_per_ms_ = 48; |
- break; |
- case NetEqDecoder::kDecoderPCM16B_5ch: |
- bytes_per_ms_ = 5 * 16; |
- samples_per_ms_ = 8; |
- break; |
- default: |
- assert(false); |
- break; |
- } |
- } |
- size_t bytes_per_ms_; |
- int samples_per_ms_; |
- NetEqDecoder decoder_type_; |
-}; |
- |
-// Test splitting sample-based payloads. |
-TEST_P(SplitBySamplesTest, PayloadSizes) { |
- PacketList packet_list; |
- static const uint8_t kPayloadType = 17; // Just a random number. |
- for (int payload_size_ms = 10; payload_size_ms <= 60; payload_size_ms += 10) { |
- // The payload values are set to be the same as the payload_size, so that |
- // one can distinguish from which packet the split payloads come from. |
- size_t payload_size_bytes = payload_size_ms * bytes_per_ms_; |
- packet_list.push_back(CreatePacket(kPayloadType, payload_size_bytes, |
- payload_size_ms)); |
- } |
- |
- MockDecoderDatabase decoder_database; |
- // Tell the mock decoder database to return DecoderInfo structs with different |
- // codec types. |
- // Use scoped pointers to avoid having to delete them later. |
- // (Sample rate is set to 8000 Hz, but does not matter.) |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info( |
- new DecoderDatabase::DecoderInfo(decoder_type_, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) |
- .WillRepeatedly(Return(info.get())); |
- |
- PayloadSplitter splitter; |
- EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); |
- // The payloads are expected to be split as follows: |
- // 10 ms -> 10 ms |
- // 20 ms -> 20 ms |
- // 30 ms -> 30 ms |
- // 40 ms -> 20 + 20 ms |
- // 50 ms -> 25 + 25 ms |
- // 60 ms -> 30 + 30 ms |
- int expected_size_ms[] = {10, 20, 30, 20, 20, 25, 25, 30, 30}; |
- int expected_payload_value[] = {10, 20, 30, 40, 40, 50, 50, 60, 60}; |
- int expected_timestamp_offset_ms[] = {0, 0, 0, 0, 20, 0, 25, 0, 30}; |
- size_t expected_num_packets = |
- sizeof(expected_size_ms) / sizeof(expected_size_ms[0]); |
- EXPECT_EQ(expected_num_packets, packet_list.size()); |
- |
- PacketList::iterator it = packet_list.begin(); |
- int i = 0; |
- while (it != packet_list.end()) { |
- size_t length_bytes = expected_size_ms[i] * bytes_per_ms_; |
- uint32_t expected_timestamp = kBaseTimestamp + |
- expected_timestamp_offset_ms[i] * samples_per_ms_; |
- VerifyPacket((*it), length_bytes, kPayloadType, kSequenceNumber, |
- expected_timestamp, expected_payload_value[i]); |
- delete (*it); |
- it = packet_list.erase(it); |
- ++i; |
- } |
- |
- // The destructor is called when decoder_database goes out of scope. |
- EXPECT_CALL(decoder_database, Die()); |
-} |
- |
-INSTANTIATE_TEST_CASE_P( |
- PayloadSplitter, |
- SplitBySamplesTest, |
- ::testing::Values(NetEqDecoder::kDecoderPCMu, |
- NetEqDecoder::kDecoderPCMa, |
- NetEqDecoder::kDecoderPCMu_2ch, |
- NetEqDecoder::kDecoderPCMa_2ch, |
- NetEqDecoder::kDecoderG722, |
- NetEqDecoder::kDecoderPCM16B, |
- NetEqDecoder::kDecoderPCM16Bwb, |
- NetEqDecoder::kDecoderPCM16Bswb32kHz, |
- NetEqDecoder::kDecoderPCM16Bswb48kHz, |
- NetEqDecoder::kDecoderPCM16B_2ch, |
- NetEqDecoder::kDecoderPCM16Bwb_2ch, |
- NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch, |
- NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch, |
- NetEqDecoder::kDecoderPCM16B_5ch)); |
- |
-class SplitIlbcTest : public ::testing::TestWithParam<std::pair<int, int> > { |
- protected: |
- virtual void SetUp() { |
- const std::pair<int, int> parameters = GetParam(); |
- num_frames_ = parameters.first; |
- frame_length_ms_ = parameters.second; |
- frame_length_bytes_ = (frame_length_ms_ == 20) ? 38 : 50; |
- } |
- size_t num_frames_; |
- int frame_length_ms_; |
- size_t frame_length_bytes_; |
-}; |
- |
-// Test splitting sample-based payloads. |
-TEST_P(SplitIlbcTest, NumFrames) { |
- PacketList packet_list; |
- static const uint8_t kPayloadType = 17; // Just a random number. |
- const int frame_length_samples = frame_length_ms_ * 8; |
- size_t payload_length_bytes = frame_length_bytes_ * num_frames_; |
- Packet* packet = CreatePacket(kPayloadType, payload_length_bytes, 0); |
- // Fill payload with increasing integers {0, 1, 2, ...}. |
- for (size_t i = 0; i < packet->payload.size(); ++i) { |
- packet->payload[i] = static_cast<uint8_t>(i); |
- } |
- packet_list.push_back(packet); |
- |
- MockDecoderDatabase decoder_database; |
- // Tell the mock decoder database to return DecoderInfo structs with different |
- // codec types. |
- // Use scoped pointers to avoid having to delete them later. |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) |
- .WillRepeatedly(Return(info.get())); |
- |
- PayloadSplitter splitter; |
- EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); |
- EXPECT_EQ(num_frames_, packet_list.size()); |
- |
- PacketList::iterator it = packet_list.begin(); |
- int frame_num = 0; |
- uint8_t payload_value = 0; |
- while (it != packet_list.end()) { |
- Packet* packet = (*it); |
- EXPECT_EQ(kBaseTimestamp + frame_length_samples * frame_num, |
- packet->header.timestamp); |
- EXPECT_EQ(frame_length_bytes_, packet->payload.size()); |
- EXPECT_EQ(kPayloadType, packet->header.payloadType); |
- EXPECT_EQ(kSequenceNumber, packet->header.sequenceNumber); |
- EXPECT_EQ(true, packet->primary); |
- ASSERT_FALSE(packet->payload.empty()); |
- for (size_t i = 0; i < packet->payload.size(); ++i) { |
- EXPECT_EQ(payload_value, packet->payload[i]); |
- ++payload_value; |
- } |
- delete (*it); |
- it = packet_list.erase(it); |
- ++frame_num; |
- } |
- |
- // The destructor is called when decoder_database goes out of scope. |
- EXPECT_CALL(decoder_database, Die()); |
-} |
- |
-// Test 1 through 5 frames of 20 and 30 ms size. |
-// Also test the maximum number of frames in one packet for 20 and 30 ms. |
-// The maximum is defined by the largest payload length that can be uniquely |
-// resolved to a frame size of either 38 bytes (20 ms) or 50 bytes (30 ms). |
-INSTANTIATE_TEST_CASE_P( |
- PayloadSplitter, SplitIlbcTest, |
- ::testing::Values(std::pair<int, int>(1, 20), // 1 frame, 20 ms. |
- std::pair<int, int>(2, 20), // 2 frames, 20 ms. |
- std::pair<int, int>(3, 20), // And so on. |
- std::pair<int, int>(4, 20), |
- std::pair<int, int>(5, 20), |
- std::pair<int, int>(24, 20), |
- std::pair<int, int>(1, 30), |
- std::pair<int, int>(2, 30), |
- std::pair<int, int>(3, 30), |
- std::pair<int, int>(4, 30), |
- std::pair<int, int>(5, 30), |
- std::pair<int, int>(18, 30))); |
- |
-// Test too large payload size. |
-TEST(IlbcPayloadSplitter, TooLargePayload) { |
- PacketList packet_list; |
- static const uint8_t kPayloadType = 17; // Just a random number. |
- size_t kPayloadLengthBytes = 950; |
- Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0); |
- packet_list.push_back(packet); |
- |
- MockDecoderDatabase decoder_database; |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) |
- .WillRepeatedly(Return(info.get())); |
- |
- PayloadSplitter splitter; |
- EXPECT_EQ(PayloadSplitter::kTooLargePayload, |
- splitter.SplitAudio(&packet_list, decoder_database)); |
- EXPECT_EQ(1u, packet_list.size()); |
- |
- // Delete the packets and payloads to avoid having the test leak memory. |
- PacketList::iterator it = packet_list.begin(); |
- while (it != packet_list.end()) { |
- delete (*it); |
- it = packet_list.erase(it); |
- } |
- |
- // The destructor is called when decoder_database goes out of scope. |
- EXPECT_CALL(decoder_database, Die()); |
-} |
- |
-// Payload not an integer number of frames. |
-TEST(IlbcPayloadSplitter, UnevenPayload) { |
- PacketList packet_list; |
- static const uint8_t kPayloadType = 17; // Just a random number. |
- size_t kPayloadLengthBytes = 39; // Not an even number of frames. |
- Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0); |
- packet_list.push_back(packet); |
- |
- MockDecoderDatabase decoder_database; |
- std::unique_ptr<DecoderDatabase::DecoderInfo> info( |
- new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); |
- EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) |
- .WillRepeatedly(Return(info.get())); |
- |
- PayloadSplitter splitter; |
- EXPECT_EQ(PayloadSplitter::kFrameSplitError, |
- splitter.SplitAudio(&packet_list, decoder_database)); |
- EXPECT_EQ(1u, packet_list.size()); |
- |
- // Delete the packets and payloads to avoid having the test leak memory. |
- PacketList::iterator it = packet_list.begin(); |
- while (it != packet_list.end()) { |
- delete (*it); |
- it = packet_list.erase(it); |
- } |
- |
- // The destructor is called when decoder_database goes out of scope. |
- EXPECT_CALL(decoder_database, Die()); |
-} |
- |
TEST(FecPayloadSplitter, MixedPayload) { |
PacketList packet_list; |
DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory()); |