Clear the FrameBuffer if it's full and a keyframe is being inserted.

Bug: webrtc:7705, webrtc:8593, chromium:706599, chromium:807624
Change-Id: Ie4e3e217bc2930fe511f8b6ad3a36afed484ab5f
Reviewed-on: https://webrtc-review.googlesource.com/59321
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22304}
This commit is contained in:
philipel
2018-03-02 11:06:27 +01:00
committed by Commit Bot
parent 8ddc2e6258
commit 9771c5050d
2 changed files with 30 additions and 6 deletions

View File

@ -319,12 +319,21 @@ int64_t FrameBuffer::InsertFrame(std::unique_ptr<EncodedFrame> frame) {
} }
if (num_frames_buffered_ >= kMaxFramesBuffered) { if (num_frames_buffered_ >= kMaxFramesBuffered) {
RTC_LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" if (frame->is_keyframe()) {
<< key.picture_id << ":" RTC_LOG(LS_WARNING) << "Inserting keyframe (picture_id:spatial_id) ("
<< static_cast<int>(key.spatial_layer) << key.picture_id << ":"
<< ") could not be inserted due to the frame " << static_cast<int>(key.spatial_layer)
<< "buffer being full, dropping frame."; << ") but buffer is full, clearing"
return last_continuous_picture_id; << " buffer and inserting the frame.";
ClearFramesAndHistory();
} else {
RTC_LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) ("
<< key.picture_id << ":"
<< static_cast<int>(key.spatial_layer)
<< ") could not be inserted due to the frame "
<< "buffer being full, dropping frame.";
return last_continuous_picture_id;
}
} }
if (last_decoded_frame_it_ != frames_.end() && if (last_decoded_frame_it_ != frames_.end() &&

View File

@ -559,5 +559,20 @@ TEST_F(TestFrameBuffer2, KeyframeRequired) {
CheckNoFrame(2); CheckNoFrame(2);
} }
TEST_F(TestFrameBuffer2, KeyframeClearsFullBuffer) {
const int kMaxBufferSize = 600;
for (int i = 1; i <= kMaxBufferSize; ++i)
EXPECT_EQ(-1, InsertFrame(i, 0, i * 1000, false, i - 1));
ExtractFrame();
CheckNoFrame(0);
EXPECT_EQ(
kMaxBufferSize + 1,
InsertFrame(kMaxBufferSize + 1, 0, (kMaxBufferSize + 1) * 1000, false));
ExtractFrame();
CheckFrame(1, kMaxBufferSize + 1, 0);
}
} // namespace video_coding } // namespace video_coding
} // namespace webrtc } // namespace webrtc