From 9771c5050d4997b4474ba6e2aca9958d9b5c875c Mon Sep 17 00:00:00 2001 From: philipel Date: Fri, 2 Mar 2018 11:06:27 +0100 Subject: [PATCH] Clear the FrameBuffer if it's full and a keyframe is being inserted. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Erik Språng Commit-Queue: Philip Eliasson Cr-Commit-Position: refs/heads/master@{#22304} --- modules/video_coding/frame_buffer2.cc | 21 +++++++++++++------ .../video_coding/frame_buffer2_unittest.cc | 15 +++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/modules/video_coding/frame_buffer2.cc b/modules/video_coding/frame_buffer2.cc index 8a5d56f72a..b041018bfd 100644 --- a/modules/video_coding/frame_buffer2.cc +++ b/modules/video_coding/frame_buffer2.cc @@ -319,12 +319,21 @@ int64_t FrameBuffer::InsertFrame(std::unique_ptr frame) { } if (num_frames_buffered_ >= kMaxFramesBuffered) { - RTC_LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" - << key.picture_id << ":" - << static_cast(key.spatial_layer) - << ") could not be inserted due to the frame " - << "buffer being full, dropping frame."; - return last_continuous_picture_id; + if (frame->is_keyframe()) { + RTC_LOG(LS_WARNING) << "Inserting keyframe (picture_id:spatial_id) (" + << key.picture_id << ":" + << static_cast(key.spatial_layer) + << ") but buffer is full, clearing" + << " buffer and inserting the frame."; + ClearFramesAndHistory(); + } else { + RTC_LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" + << key.picture_id << ":" + << static_cast(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() && diff --git a/modules/video_coding/frame_buffer2_unittest.cc b/modules/video_coding/frame_buffer2_unittest.cc index 807520c4ed..ffc02e845b 100644 --- a/modules/video_coding/frame_buffer2_unittest.cc +++ b/modules/video_coding/frame_buffer2_unittest.cc @@ -559,5 +559,20 @@ TEST_F(TestFrameBuffer2, KeyframeRequired) { 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 webrtc