NetEq: Rectify the implementation of PacketBuffer::DiscardOldPackets

The implementation of this method did not follow the description in
the method comment. It was supposed to delete all packets in a range
[A, B], but if at least one packet in the buffer had a timestamp lower
than A, then no packets at all were discarded. This is now fixed.

BUG=webrtc:7937

Review-Url: https://codereview.webrtc.org/2969123003
Cr-Commit-Position: refs/heads/master@{#18903}
This commit is contained in:
henrik.lundin
2017-07-05 07:03:34 -07:00
committed by Commit Bot
parent 440ea8cdff
commit 63d146b743
2 changed files with 27 additions and 13 deletions

View File

@ -221,15 +221,13 @@ int PacketBuffer::DiscardNextPacket(StatisticsCalculator* stats) {
void PacketBuffer::DiscardOldPackets(uint32_t timestamp_limit,
uint32_t horizon_samples,
StatisticsCalculator* stats) {
// TODO(minyue): the following implementation is wrong. It won't discard
// old packets if the buffer_.front() is newer than timestamp_limit -
// horizon_samples. https://bugs.chromium.org/p/webrtc/issues/detail?id=7937
while (!Empty() && timestamp_limit != buffer_.front().timestamp &&
IsObsoleteTimestamp(buffer_.front().timestamp, timestamp_limit,
horizon_samples)) {
if (DiscardNextPacket(stats) != kOK) {
assert(false); // Must be ok by design.
}
const size_t old_size = buffer_.size();
buffer_.remove_if([timestamp_limit, horizon_samples](const Packet& p) {
return timestamp_limit != p.timestamp &&
IsObsoleteTimestamp(p.timestamp, timestamp_limit, horizon_samples);
});
if (old_size > buffer_.size()) {
stats->PacketsDiscarded(old_size - buffer_.size());
}
}