Moved codec-specific audio packet splitting into decoders.
There's still some code run specifically for Opus w/ FEC. It will be addressed in a separate CL. BUG=webrtc:5805 Review-Url: https://codereview.webrtc.org/2326003002 Cr-Commit-Position: refs/heads/master@{#14319}
This commit is contained in:
@ -25,14 +25,6 @@ class MockPayloadSplitter : public PayloadSplitter {
|
||||
int(PacketList* packet_list, DecoderDatabase* decoder_database));
|
||||
MOCK_METHOD2(CheckRedPayloads,
|
||||
int(PacketList* packet_list, const DecoderDatabase& decoder_database));
|
||||
MOCK_METHOD2(SplitAudio,
|
||||
int(PacketList* packet_list, const DecoderDatabase& decoder_database));
|
||||
MOCK_METHOD4(SplitBySamples,
|
||||
void(const Packet* packet, size_t bytes_per_ms,
|
||||
uint32_t timestamps_per_ms, PacketList* new_packets));
|
||||
MOCK_METHOD4(SplitByFrames,
|
||||
int(const Packet* packet, size_t bytes_per_frame,
|
||||
uint32_t timestamps_per_frame, PacketList* new_packets));
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -658,21 +658,6 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
|
||||
}
|
||||
}
|
||||
|
||||
// Split payloads into smaller chunks. This also verifies that all payloads
|
||||
// are of a known payload type.
|
||||
ret = payload_splitter_->SplitAudio(&packet_list, *decoder_database_);
|
||||
if (ret != PayloadSplitter::kOK) {
|
||||
PacketBuffer::DeleteAllPackets(&packet_list);
|
||||
switch (ret) {
|
||||
case PayloadSplitter::kUnknownPayloadType:
|
||||
return kUnknownRtpPayloadType;
|
||||
case PayloadSplitter::kFrameSplitError:
|
||||
return kFrameSplitError;
|
||||
default:
|
||||
return kOtherError;
|
||||
}
|
||||
}
|
||||
|
||||
// Update bandwidth estimate, if the packet is not comfort noise.
|
||||
if (!packet_list.empty() &&
|
||||
!decoder_database_->IsComfortNoise(main_header.payloadType)) {
|
||||
@ -710,7 +695,7 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
|
||||
const RTPHeader& original_header = packet->header;
|
||||
for (auto& result : results) {
|
||||
RTC_DCHECK(result.frame);
|
||||
// Reuse the packet if possible
|
||||
// Reuse the packet if possible.
|
||||
if (!packet) {
|
||||
packet.reset(new Packet);
|
||||
packet->header = original_header;
|
||||
|
||||
@ -336,9 +336,6 @@ TEST_F(NetEqImplTest, InsertPacket) {
|
||||
EXPECT_CALL(*mock_payload_splitter_, SplitFec(_, _))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(PayloadSplitter::kOK));
|
||||
EXPECT_CALL(*mock_payload_splitter_, SplitAudio(_, _))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(PayloadSplitter::kOK));
|
||||
|
||||
// Insert first packet.
|
||||
neteq_->InsertPacket(rtp_header, payload, kFirstReceiveTime);
|
||||
|
||||
@ -212,214 +212,4 @@ int PayloadSplitter::CheckRedPayloads(PacketList* packet_list,
|
||||
return num_deleted_packets;
|
||||
}
|
||||
|
||||
int PayloadSplitter::SplitAudio(PacketList* packet_list,
|
||||
const DecoderDatabase& decoder_database) {
|
||||
PacketList::iterator it = packet_list->begin();
|
||||
// Iterate through all packets in |packet_list|.
|
||||
while (it != packet_list->end()) {
|
||||
Packet* packet = (*it); // Just to make the notation more intuitive.
|
||||
// Get codec type for this payload.
|
||||
const DecoderDatabase::DecoderInfo* info =
|
||||
decoder_database.GetDecoderInfo(packet->header.payloadType);
|
||||
if (!info) {
|
||||
LOG(LS_WARNING) << "SplitAudio unknown payload type";
|
||||
return kUnknownPayloadType;
|
||||
}
|
||||
PacketList new_packets;
|
||||
switch (info->codec_type) {
|
||||
case NetEqDecoder::kDecoderPCMu:
|
||||
case NetEqDecoder::kDecoderPCMa: {
|
||||
// 8 bytes per ms; 8 timestamps per ms.
|
||||
SplitBySamples(packet, 8, 8, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCMu_2ch:
|
||||
case NetEqDecoder::kDecoderPCMa_2ch: {
|
||||
// 2 * 8 bytes per ms; 8 timestamps per ms.
|
||||
SplitBySamples(packet, 2 * 8, 8, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderG722: {
|
||||
// 8 bytes per ms; 16 timestamps per ms.
|
||||
SplitBySamples(packet, 8, 16, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16B: {
|
||||
// 16 bytes per ms; 8 timestamps per ms.
|
||||
SplitBySamples(packet, 16, 8, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16Bwb: {
|
||||
// 32 bytes per ms; 16 timestamps per ms.
|
||||
SplitBySamples(packet, 32, 16, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16Bswb32kHz: {
|
||||
// 64 bytes per ms; 32 timestamps per ms.
|
||||
SplitBySamples(packet, 64, 32, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16Bswb48kHz: {
|
||||
// 96 bytes per ms; 48 timestamps per ms.
|
||||
SplitBySamples(packet, 96, 48, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16B_2ch: {
|
||||
// 2 * 16 bytes per ms; 8 timestamps per ms.
|
||||
SplitBySamples(packet, 2 * 16, 8, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16Bwb_2ch: {
|
||||
// 2 * 32 bytes per ms; 16 timestamps per ms.
|
||||
SplitBySamples(packet, 2 * 32, 16, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch: {
|
||||
// 2 * 64 bytes per ms; 32 timestamps per ms.
|
||||
SplitBySamples(packet, 2 * 64, 32, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch: {
|
||||
// 2 * 96 bytes per ms; 48 timestamps per ms.
|
||||
SplitBySamples(packet, 2 * 96, 48, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderPCM16B_5ch: {
|
||||
// 5 * 16 bytes per ms; 8 timestamps per ms.
|
||||
SplitBySamples(packet, 5 * 16, 8, &new_packets);
|
||||
break;
|
||||
}
|
||||
case NetEqDecoder::kDecoderILBC: {
|
||||
size_t bytes_per_frame;
|
||||
int timestamps_per_frame;
|
||||
if (packet->payload.size() >= 950) {
|
||||
LOG(LS_WARNING) << "SplitAudio too large iLBC payload";
|
||||
return kTooLargePayload;
|
||||
}
|
||||
if (packet->payload.size() % 38 == 0) {
|
||||
// 20 ms frames.
|
||||
bytes_per_frame = 38;
|
||||
timestamps_per_frame = 160;
|
||||
} else if (packet->payload.size() % 50 == 0) {
|
||||
// 30 ms frames.
|
||||
bytes_per_frame = 50;
|
||||
timestamps_per_frame = 240;
|
||||
} else {
|
||||
LOG(LS_WARNING) << "SplitAudio invalid iLBC payload";
|
||||
return kFrameSplitError;
|
||||
}
|
||||
int ret = SplitByFrames(packet, bytes_per_frame, timestamps_per_frame,
|
||||
&new_packets);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
} else if (ret == kNoSplit) {
|
||||
// Do not split at all. Simply advance to the next packet in the list.
|
||||
++it;
|
||||
// We do not have any new packets to insert, and should not delete the
|
||||
// old one. Skip the code after the switch case, and jump straight to
|
||||
// the next packet in the while loop.
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// Do not split at all. Simply advance to the next packet in the list.
|
||||
++it;
|
||||
// We do not have any new packets to insert, and should not delete the
|
||||
// old one. Skip the code after the switch case, and jump straight to
|
||||
// the next packet in the while loop.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Insert new packets into original list, before the element pointed to by
|
||||
// iterator |it|.
|
||||
packet_list->splice(it, new_packets, new_packets.begin(),
|
||||
new_packets.end());
|
||||
// Delete old packet payload.
|
||||
delete (*it);
|
||||
// Remove |it| from the packet list. This operation effectively moves the
|
||||
// iterator |it| to the next packet in the list. Thus, we do not have to
|
||||
// increment it manually.
|
||||
it = packet_list->erase(it);
|
||||
}
|
||||
return kOK;
|
||||
}
|
||||
|
||||
void PayloadSplitter::SplitBySamples(const Packet* packet,
|
||||
size_t bytes_per_ms,
|
||||
uint32_t timestamps_per_ms,
|
||||
PacketList* new_packets) {
|
||||
assert(packet);
|
||||
assert(new_packets);
|
||||
|
||||
size_t split_size_bytes = packet->payload.size();
|
||||
|
||||
// Find a "chunk size" >= 20 ms and < 40 ms.
|
||||
size_t min_chunk_size = bytes_per_ms * 20;
|
||||
// Reduce the split size by half as long as |split_size_bytes| is at least
|
||||
// twice the minimum chunk size (so that the resulting size is at least as
|
||||
// large as the minimum chunk size).
|
||||
while (split_size_bytes >= 2 * min_chunk_size) {
|
||||
split_size_bytes >>= 1;
|
||||
}
|
||||
uint32_t timestamps_per_chunk = static_cast<uint32_t>(
|
||||
split_size_bytes * timestamps_per_ms / bytes_per_ms);
|
||||
uint32_t timestamp = packet->header.timestamp;
|
||||
|
||||
const uint8_t* payload_ptr = packet->payload.data();
|
||||
size_t len = packet->payload.size();
|
||||
while (len >= (2 * split_size_bytes)) {
|
||||
Packet* new_packet = new Packet;
|
||||
new_packet->header = packet->header;
|
||||
new_packet->header.timestamp = timestamp;
|
||||
timestamp += timestamps_per_chunk;
|
||||
new_packet->primary = packet->primary;
|
||||
new_packet->payload.SetData(payload_ptr, split_size_bytes);
|
||||
payload_ptr += split_size_bytes;
|
||||
new_packets->push_back(new_packet);
|
||||
len -= split_size_bytes;
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
Packet* new_packet = new Packet;
|
||||
new_packet->header = packet->header;
|
||||
new_packet->header.timestamp = timestamp;
|
||||
new_packet->primary = packet->primary;
|
||||
new_packet->payload.SetData(payload_ptr, len);
|
||||
new_packets->push_back(new_packet);
|
||||
}
|
||||
}
|
||||
|
||||
int PayloadSplitter::SplitByFrames(const Packet* packet,
|
||||
size_t bytes_per_frame,
|
||||
uint32_t timestamps_per_frame,
|
||||
PacketList* new_packets) {
|
||||
if (packet->payload.size() % bytes_per_frame != 0) {
|
||||
LOG(LS_WARNING) << "SplitByFrames length mismatch";
|
||||
return kFrameSplitError;
|
||||
}
|
||||
|
||||
if (packet->payload.size() == bytes_per_frame) {
|
||||
// Special case. Do not split the payload.
|
||||
return kNoSplit;
|
||||
}
|
||||
|
||||
uint32_t timestamp = packet->header.timestamp;
|
||||
const uint8_t* payload_ptr = packet->payload.data();
|
||||
size_t len = packet->payload.size();
|
||||
while (len > 0) {
|
||||
assert(len >= bytes_per_frame);
|
||||
Packet* new_packet = new Packet;
|
||||
new_packet->header = packet->header;
|
||||
new_packet->header.timestamp = timestamp;
|
||||
timestamp += timestamps_per_frame;
|
||||
new_packet->primary = packet->primary;
|
||||
new_packet->payload.SetData(payload_ptr, bytes_per_frame);
|
||||
payload_ptr += bytes_per_frame;
|
||||
new_packets->push_back(new_packet);
|
||||
len -= bytes_per_frame;
|
||||
}
|
||||
return kOK;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -20,16 +20,14 @@ namespace webrtc {
|
||||
class DecoderDatabase;
|
||||
|
||||
// This class handles splitting of payloads into smaller parts.
|
||||
// The class does not have any member variables, and the methods could have
|
||||
// been made static. The reason for not making them static is testability.
|
||||
// With this design, the splitting functionality can be mocked during testing
|
||||
// of the NetEqImpl class.
|
||||
|
||||
// For RED and FEC the splitting is done internally. Other codecs' packets are
|
||||
// split by calling AudioDecoder::SplitPacket.
|
||||
class PayloadSplitter {
|
||||
public:
|
||||
enum SplitterReturnCodes {
|
||||
kOK = 0,
|
||||
kNoSplit = 1,
|
||||
kTooLargePayload = -1,
|
||||
kFrameSplitError = -2,
|
||||
kUnknownPayloadType = -3,
|
||||
kRedLengthMismatch = -4,
|
||||
@ -60,29 +58,7 @@ class PayloadSplitter {
|
||||
virtual int CheckRedPayloads(PacketList* packet_list,
|
||||
const DecoderDatabase& decoder_database);
|
||||
|
||||
// Iterates through |packet_list| and, if possible, splits each audio payload
|
||||
// into suitable size chunks. The result is written back to |packet_list| as
|
||||
// new packets. The decoder database is needed to get information about which
|
||||
// payload type each packet contains.
|
||||
virtual int SplitAudio(PacketList* packet_list,
|
||||
const DecoderDatabase& decoder_database);
|
||||
|
||||
private:
|
||||
// Splits the payload in |packet|. The payload is assumed to be from a
|
||||
// sample-based codec.
|
||||
virtual void SplitBySamples(const Packet* packet,
|
||||
size_t bytes_per_ms,
|
||||
uint32_t timestamps_per_ms,
|
||||
PacketList* new_packets);
|
||||
|
||||
// Splits the payload in |packet|. The payload will be split into chunks of
|
||||
// size |bytes_per_frame|, corresponding to a |timestamps_per_frame|
|
||||
// RTP timestamps.
|
||||
virtual int SplitByFrames(const Packet* packet,
|
||||
size_t bytes_per_frame,
|
||||
uint32_t timestamps_per_frame,
|
||||
PacketList* new_packets);
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(PayloadSplitter);
|
||||
};
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
Reference in New Issue
Block a user