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
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer.h b/webrtc/modules/audio_coding/neteq/packet_buffer.h
index 76c4ddd..b9a1618 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer.h
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer.h
@@ -95,9 +95,19 @@
// PacketBuffer::kOK otherwise.
virtual int DiscardNextPacket();
- // Discards all packets that are (strictly) older than |timestamp_limit|.
+ // Discards all packets that are (strictly) older than timestamp_limit,
+ // but newer than timestamp_limit - horizon_samples. Setting horizon_samples
+ // to zero implies that the horizon is set to half the timestamp range. That
+ // is, if a packet is more than 2^31 timestamps into the future compared with
+ // timestamp_limit (including wrap-around), it is considered old.
// Returns number of packets discarded.
- virtual int DiscardOldPackets(uint32_t timestamp_limit);
+ virtual int DiscardOldPackets(uint32_t timestamp_limit,
+ uint32_t horizon_samples);
+
+ // Discards all packets that are (strictly) older than timestamp_limit.
+ virtual int DiscardAllOldPackets(uint32_t timestamp_limit) {
+ return DiscardOldPackets(timestamp_limit, 0);
+ }
// Returns the number of packets in the buffer, including duplicates and
// redundant packets.
@@ -125,6 +135,20 @@
// in |packet_list|.
static void DeleteAllPackets(PacketList* packet_list);
+ // Static method returning true if |timestamp| is older than |timestamp_limit|
+ // but less than |horizon_samples| behind |timestamp_limit|. For instance,
+ // with timestamp_limit = 100 and horizon_samples = 10, a timestamp in the
+ // range (90, 100) is considered obsolete, and will yield true.
+ // Setting |horizon_samples| to 0 is the same as setting it to 2^31, i.e.,
+ // half the 32-bit timestamp range.
+ static bool IsObsoleteTimestamp(uint32_t timestamp,
+ uint32_t timestamp_limit,
+ uint32_t horizon_samples) {
+ return IsNewerTimestamp(timestamp_limit, timestamp) &&
+ (horizon_samples == 0 ||
+ IsNewerTimestamp(timestamp, timestamp_limit - horizon_samples));
+ }
+
private:
size_t max_number_of_packets_;
PacketList buffer_;