Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 2996dc5

Browse files
Break backwards traversal loop if we have looped around all packets in the PacketBuffer for H264 frames.
BUG=webrtc:7532, chromium:724031 [email protected] Review-Url: https://codereview.webrtc.org/2868723003 Cr-Original-Commit-Position: refs/heads/master@{#18191} Review-Url: https://codereview.webrtc.org/2899713002 . Cr-Commit-Position: refs/branch-heads/59@{#12} Cr-Branched-From: 10d095d-refs/heads/master@{#17657}
1 parent 7daab66 commit 2996dc5

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

webrtc/modules/video_coding/packet_buffer.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ bool PacketBuffer::PotentialNewFrame(uint16_t seq_num) const {
197197
std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
198198
uint16_t seq_num) {
199199
std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
200-
size_t packets_tested = 0;
201-
while (packets_tested < size_ && PotentialNewFrame(seq_num)) {
200+
for (size_t i = 0; i < size_ && PotentialNewFrame(seq_num); ++i) {
202201
size_t index = seq_num % size_;
203202
sequence_buffer_[index].continuous = true;
204203

@@ -215,7 +214,10 @@ std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
215214

216215
bool is_h264 = data_buffer_[start_index].codec == kVideoCodecH264;
217216
int64_t frame_timestamp = data_buffer_[start_index].timestamp;
218-
while (true) {
217+
218+
// Since packet at |data_buffer_[index]| is already part of the frame
219+
// we will have at most |size_ - 1| packets left to check.
220+
for (size_t j = 0; j < size_ - 1; ++j) {
219221
frame_size += data_buffer_[start_index].sizeBytes;
220222
max_nack_count =
221223
std::max(max_nack_count, data_buffer_[start_index].timesNacked);
@@ -232,12 +234,7 @@ std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
232234
// the timestamp of that packet is the same as this one. This may cause
233235
// the PacketBuffer to hand out incomplete frames.
234236
// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7106
235-
//
236-
// Since we ignore the |frame_begin| flag of the inserted packets
237-
// we check that |start_index != static_cast<int>(index)| to make sure
238-
// that we don't get stuck in a loop if the packet buffer is filled
239-
// with packets of the same timestamp.
240-
if (is_h264 && start_index != static_cast<int>(index) &&
237+
if (is_h264 &&
241238
(!sequence_buffer_[start_index].used ||
242239
data_buffer_[start_index].timestamp != frame_timestamp)) {
243240
break;
@@ -251,7 +248,6 @@ std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
251248
max_nack_count, clock_->TimeInMilliseconds()));
252249
}
253250
++seq_num;
254-
++packets_tested;
255251
}
256252
return found_frames;
257253
}

webrtc/modules/video_coding/video_packet_buffer_unittest.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,29 @@ TEST_F(TestPacketBuffer, ContinuousSeqNumDoubleMarkerBit) {
477477
EXPECT_EQ(0UL, frames_from_callback_.size());
478478
}
479479

480+
TEST_F(TestPacketBuffer, OneH264FrameFillBuffer) {
481+
VCMPacket packet;
482+
packet.seqNum = 0;
483+
packet.codec = kVideoCodecH264;
484+
packet.dataPtr = nullptr;
485+
packet.sizeBytes = 0;
486+
packet.is_first_packet_in_frame = true;
487+
packet.markerBit = false;
488+
packet_buffer_->InsertPacket(&packet);
489+
490+
packet.is_first_packet_in_frame = false;
491+
for (int i = 1; i < kStartSize - 1; ++i) {
492+
packet.seqNum = i;
493+
packet_buffer_->InsertPacket(&packet);
494+
}
495+
496+
packet.seqNum = kStartSize - 1;
497+
packet.markerBit = true;
498+
packet_buffer_->InsertPacket(&packet);
499+
500+
EXPECT_EQ(1UL, frames_from_callback_.size());
501+
CheckFrame(0);
502+
}
503+
480504
} // namespace video_coding
481505
} // namespace webrtc

0 commit comments

Comments
 (0)