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

Commit 6d56d2e

Browse files
Check if the order of frames becomes ambiguous if we were to insert the incoming frame, and if so, clear the FrameBuffer.
BUG=chromium:679306 Review-Url: https://codereview.webrtc.org/2830723002 Cr-Commit-Position: refs/heads/master@{#17785} (cherry picked from commit 146a48b) [email protected] Review-Url: https://codereview.webrtc.org/2835963002 . Cr-Commit-Position: refs/branch-heads/59@{#4} Cr-Branched-From: 10d095d-refs/heads/master@{#17657}
1 parent 262cbaa commit 6d56d2e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

webrtc/modules/video_coding/frame_buffer2.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ FrameBuffer::ReturnReason FrameBuffer::NextFrame(
9393
if (continuous_end_it != frames_.end())
9494
++continuous_end_it;
9595

96-
for (; frame_it != continuous_end_it; ++frame_it) {
96+
for (; frame_it != continuous_end_it && frame_it != frames_.end();
97+
++frame_it) {
9798
if (!frame_it->second.continuous ||
9899
frame_it->second.num_missing_decodable > 0) {
99100
continue;
@@ -233,6 +234,17 @@ int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) {
233234
}
234235
}
235236

237+
// Test if inserting this frame would cause the order of the frames to become
238+
// ambiguous (covering more than half the interval of 2^16). This can happen
239+
// when the picture id make large jumps mid stream.
240+
if (!frames_.empty() &&
241+
key < frames_.begin()->first &&
242+
frames_.rbegin()->first < key) {
243+
LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer.";
244+
ClearFramesAndHistory();
245+
last_continuous_picture_id = -1;
246+
}
247+
236248
auto info = frames_.insert(std::make_pair(key, FrameInfo())).first;
237249

238250
if (info->second.frame) {

webrtc/modules/video_coding/frame_buffer2_unittest.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,24 @@ TEST_F(TestFrameBuffer2, StatsCallback) {
497497
CheckFrame(0, pid, 0);
498498
}
499499

500+
TEST_F(TestFrameBuffer2, ForwardJumps) {
501+
EXPECT_EQ(5453, InsertFrame(5453, 0, 1, false));
502+
ExtractFrame();
503+
EXPECT_EQ(5454, InsertFrame(5454, 0, 1, false, 5453));
504+
ExtractFrame();
505+
EXPECT_EQ(15670, InsertFrame(15670, 0, 1, false));
506+
ExtractFrame();
507+
EXPECT_EQ(29804, InsertFrame(29804, 0, 1, false));
508+
ExtractFrame();
509+
EXPECT_EQ(29805, InsertFrame(29805, 0, 1, false, 29804));
510+
ExtractFrame();
511+
EXPECT_EQ(29806, InsertFrame(29806, 0, 1, false, 29805));
512+
ExtractFrame();
513+
EXPECT_EQ(33819, InsertFrame(33819, 0, 1, false));
514+
ExtractFrame();
515+
EXPECT_EQ(41248, InsertFrame(41248, 0, 1, false));
516+
ExtractFrame();
517+
}
518+
500519
} // namespace video_coding
501520
} // namespace webrtc

0 commit comments

Comments
 (0)