Don't clear newer packets from the video_coding::PacketBuffer when calling ClearTo.
BUG=webrtc:8060 Review-Url: https://codereview.webrtc.org/2987013002 Cr-Commit-Position: refs/heads/master@{#19212}
This commit is contained in:
parent
c18f1d7c94
commit
c5fb4683e5
@ -127,20 +127,37 @@ bool PacketBuffer::InsertPacket(VCMPacket* packet) {
|
||||
|
||||
void PacketBuffer::ClearTo(uint16_t seq_num) {
|
||||
rtc::CritScope lock(&crit_);
|
||||
// We have already cleared past this sequence number, no need to do anything.
|
||||
if (is_cleared_to_first_seq_num_ &&
|
||||
AheadOf<uint16_t>(first_seq_num_, seq_num)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the packet buffer was cleared between a frame was created and returned.
|
||||
if (!first_packet_received_)
|
||||
return;
|
||||
|
||||
is_cleared_to_first_seq_num_ = true;
|
||||
while (AheadOrAt<uint16_t>(seq_num, first_seq_num_)) {
|
||||
// Avoid iterating over the buffer more than once by capping the number of
|
||||
// iterations to the |size_| of the buffer.
|
||||
++seq_num;
|
||||
size_t diff = ForwardDiff<uint16_t>(first_seq_num_, seq_num);
|
||||
size_t iterations = std::min(diff, size_);
|
||||
for (size_t i = 0; i < iterations; ++i) {
|
||||
size_t index = first_seq_num_ % size_;
|
||||
delete[] data_buffer_[index].dataPtr;
|
||||
data_buffer_[index].dataPtr = nullptr;
|
||||
sequence_buffer_[index].used = false;
|
||||
RTC_DCHECK_EQ(data_buffer_[index].seqNum, sequence_buffer_[index].seq_num);
|
||||
if (AheadOf<uint16_t>(seq_num, sequence_buffer_[index].seq_num)) {
|
||||
delete[] data_buffer_[index].dataPtr;
|
||||
data_buffer_[index].dataPtr = nullptr;
|
||||
sequence_buffer_[index].used = false;
|
||||
}
|
||||
++first_seq_num_;
|
||||
}
|
||||
|
||||
// If |diff| is larger than |iterations| it means that we don't increment
|
||||
// |first_seq_num_| until we reach |seq_num|, so we set it here.
|
||||
first_seq_num_ = seq_num;
|
||||
|
||||
is_cleared_to_first_seq_num_ = true;
|
||||
missing_packets_.erase(missing_packets_.begin(),
|
||||
missing_packets_.upper_bound(seq_num));
|
||||
}
|
||||
|
||||
@ -303,6 +303,30 @@ TEST_F(TestPacketBuffer, ClearSinglePacket) {
|
||||
EXPECT_TRUE(Insert(seq_num + kMaxSize, kDeltaFrame, kFirst, kLast));
|
||||
}
|
||||
|
||||
TEST_F(TestPacketBuffer, ClearFullBuffer) {
|
||||
for (int i = 0; i < kMaxSize; ++i)
|
||||
EXPECT_TRUE(Insert(i, kDeltaFrame, kFirst, kLast));
|
||||
|
||||
packet_buffer_->ClearTo(kMaxSize - 1);
|
||||
|
||||
for (int i = kMaxSize; i < 2 * kMaxSize; ++i)
|
||||
EXPECT_TRUE(Insert(i, kDeltaFrame, kFirst, kLast));
|
||||
}
|
||||
|
||||
TEST_F(TestPacketBuffer, DontClearNewerPacket) {
|
||||
EXPECT_TRUE(Insert(0, kKeyFrame, kFirst, kLast));
|
||||
packet_buffer_->ClearTo(0);
|
||||
EXPECT_TRUE(Insert(2 * kStartSize, kKeyFrame, kFirst, kLast));
|
||||
EXPECT_TRUE(Insert(3 * kStartSize + 1, kKeyFrame, kFirst, kNotLast));
|
||||
packet_buffer_->ClearTo(2 * kStartSize);
|
||||
EXPECT_TRUE(Insert(3 * kStartSize + 2, kKeyFrame, kNotFirst, kLast));
|
||||
|
||||
ASSERT_EQ(3UL, frames_from_callback_.size());
|
||||
CheckFrame(0);
|
||||
CheckFrame(2 * kStartSize);
|
||||
CheckFrame(3 * kStartSize + 1);
|
||||
}
|
||||
|
||||
TEST_F(TestPacketBuffer, OneIncompleteFrame) {
|
||||
const uint16_t seq_num = Rand();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user