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}
This commit is contained in:
philipel
2017-04-20 04:04:38 -07:00
committed by Commit bot
parent 7c8786ae8f
commit 146a48b0fa
2 changed files with 32 additions and 1 deletions

View File

@ -93,7 +93,8 @@ FrameBuffer::ReturnReason FrameBuffer::NextFrame(
if (continuous_end_it != frames_.end())
++continuous_end_it;
for (; frame_it != continuous_end_it; ++frame_it) {
for (; frame_it != continuous_end_it && frame_it != frames_.end();
++frame_it) {
if (!frame_it->second.continuous ||
frame_it->second.num_missing_decodable > 0) {
continue;
@ -233,6 +234,17 @@ int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) {
}
}
// Test if inserting this frame would cause the order of the frames to become
// ambiguous (covering more than half the interval of 2^16). This can happen
// when the picture id make large jumps mid stream.
if (!frames_.empty() &&
key < frames_.begin()->first &&
frames_.rbegin()->first < key) {
LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer.";
ClearFramesAndHistory();
last_continuous_picture_id = -1;
}
auto info = frames_.insert(std::make_pair(key, FrameInfo())).first;
if (info->second.frame) {