Fix problem with late packets in NetEq

Since r7255, it could happen that an old packet would block the decoding
process until enough packet was received for the buffer to flush. This
CL fixes that by:
- Partially reverting r7255;
- Remove recent old packets before taking a decision for GetAudio;
- Remove all old packets after a packet has been extracted for decoding;
- Adding tests for reordered packets.

BUG=chrome:423985
R=tina.legrand@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/25079004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7612 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org
2014-11-04 14:03:58 +00:00
parent 09cc686c8b
commit 52b42cb069
8 changed files with 207 additions and 20 deletions

View File

@ -391,7 +391,7 @@ TEST(PacketBuffer, Failures) {
EXPECT_EQ(NULL, buffer->NextRtpHeader());
EXPECT_EQ(NULL, buffer->GetNextPacket(NULL));
EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->DiscardNextPacket());
EXPECT_EQ(0, buffer->DiscardOldPackets(0)); // 0 packets discarded.
EXPECT_EQ(0, buffer->DiscardAllOldPackets(0)); // 0 packets discarded.
// Insert one packet to make the buffer non-empty.
packet = gen.NextPacket(payload_len);
@ -513,4 +513,61 @@ TEST(PacketBuffer, DeleteAllPackets) {
EXPECT_FALSE(PacketBuffer::DeleteFirstPacket(&list));
}
namespace {
void TestIsObsoleteTimestamp(uint32_t limit_timestamp) {
// Check with zero horizon, which implies that the horizon is at 2^31, i.e.,
// half the timestamp range.
static const uint32_t kZeroHorizon = 0;
static const uint32_t k2Pow31Minus1 = 0x7FFFFFFF;
// Timestamp on the limit is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp, limit_timestamp, kZeroHorizon));
// 1 sample behind is old.
EXPECT_TRUE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp - 1, limit_timestamp, kZeroHorizon));
// 2^31 - 1 samples behind is old.
EXPECT_TRUE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp - k2Pow31Minus1, limit_timestamp, kZeroHorizon));
// 1 sample ahead is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp + 1, limit_timestamp, kZeroHorizon));
// 2^31 samples ahead is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp + (1 << 31), limit_timestamp, kZeroHorizon));
// Fixed horizon at 10 samples.
static const uint32_t kHorizon = 10;
// Timestamp on the limit is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp, limit_timestamp, kHorizon));
// 1 sample behind is old.
EXPECT_TRUE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp - 1, limit_timestamp, kHorizon));
// 9 samples behind is old.
EXPECT_TRUE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp - 9, limit_timestamp, kHorizon));
// 10 samples behind is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp - 10, limit_timestamp, kHorizon));
// 2^31 - 1 samples behind is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp - k2Pow31Minus1, limit_timestamp, kHorizon));
// 1 sample ahead is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp + 1, limit_timestamp, kHorizon));
// 2^31 samples ahead is not old.
EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp(
limit_timestamp + (1 << 31), limit_timestamp, kHorizon));
}
} // namespace
// Test the IsObsoleteTimestamp method with different limit timestamps.
TEST(PacketBuffer, IsObsoleteTimestamp) {
TestIsObsoleteTimestamp(0);
TestIsObsoleteTimestamp(1);
TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t.
TestIsObsoleteTimestamp(0x80000000); // 2^31.
TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1.
TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1.
}
} // namespace webrtc