From 7556282a6ce98f243b52d4db436f162e93e69abb Mon Sep 17 00:00:00 2001 From: philipel Date: Mon, 5 Sep 2016 10:57:41 +0200 Subject: [PATCH] FrameBuffer::NextFrame now return a ReturnReason and take an additional std::unique_ptr* as output parameter. In order to distinguish between a return caused by the FrameBuffer being stopped and a return caused by a timeout we now return a ReturnReason. BUG=webrtc:5514 R=danilchap@webrtc.org, mflodman@webrtc.org Review URL: https://codereview.webrtc.org/2302473002 . Cr-Commit-Position: refs/heads/master@{#14065} --- webrtc/modules/video_coding/frame_buffer2.cc | 11 +++++++---- webrtc/modules/video_coding/frame_buffer2.h | 13 ++++++++++--- .../modules/video_coding/frame_buffer2_unittest.cc | 11 +++++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/webrtc/modules/video_coding/frame_buffer2.cc b/webrtc/modules/video_coding/frame_buffer2.cc index dab7832546..766e6a05d7 100644 --- a/webrtc/modules/video_coding/frame_buffer2.cc +++ b/webrtc/modules/video_coding/frame_buffer2.cc @@ -52,7 +52,9 @@ FrameBuffer::FrameBuffer(Clock* clock, stopped_(false), protection_mode_(kProtectionNack) {} -std::unique_ptr FrameBuffer::NextFrame(int64_t max_wait_time_ms) { +FrameBuffer::ReturnReason FrameBuffer::NextFrame( + int64_t max_wait_time_ms, + std::unique_ptr* frame_out) { int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; int64_t now = clock_->TimeInMilliseconds(); int64_t wait_ms = max_wait_time_ms; @@ -63,7 +65,7 @@ std::unique_ptr FrameBuffer::NextFrame(int64_t max_wait_time_ms) { rtc::CritScope lock(&crit_); frame_inserted_event_.Reset(); if (stopped_) - return std::unique_ptr(); + return kStopped; now = clock_->TimeInMilliseconds(); wait_ms = max_wait_time_ms; @@ -115,9 +117,10 @@ std::unique_ptr FrameBuffer::NextFrame(int64_t max_wait_time_ms) { decoded_frames_.insert(next_frame_it->first); std::unique_ptr frame = std::move(next_frame_it->second); frames_.erase(frames_.begin(), ++next_frame_it); - return frame; + *frame_out = std::move(frame); + return kFrameFound; } else { - return std::unique_ptr(); + return kTimeout; } } } diff --git a/webrtc/modules/video_coding/frame_buffer2.h b/webrtc/modules/video_coding/frame_buffer2.h index 0af2bf9523..d0f896133f 100644 --- a/webrtc/modules/video_coding/frame_buffer2.h +++ b/webrtc/modules/video_coding/frame_buffer2.h @@ -36,6 +36,8 @@ class FrameObject; class FrameBuffer { public: + enum ReturnReason { kFrameFound, kTimeout, kStopped }; + FrameBuffer(Clock* clock, VCMJitterEstimator* jitter_estimator, VCMTiming* timing); @@ -44,9 +46,14 @@ class FrameBuffer { void InsertFrame(std::unique_ptr frame); // Get the next frame for decoding. Will return at latest after - // |max_wait_time_ms|, with either a managed FrameObject or an empty - // unique ptr if there is no available frame for decoding. - std::unique_ptr NextFrame(int64_t max_wait_time_ms); + // |max_wait_time_ms|. + // - If a frame is availiable within |max_wait_time_ms| it will return + // kFrameFound and set |frame_out| to the resulting frame. + // - If no frame is available after |max_wait_time_ms| it will return + // kTimeout. + // - If the FrameBuffer is stopped then it will return kStopped. + ReturnReason NextFrame(int64_t max_wait_time_ms, + std::unique_ptr* frame_out); // Tells the FrameBuffer which protection mode that is in use. Affects // the frame timing. diff --git a/webrtc/modules/video_coding/frame_buffer2_unittest.cc b/webrtc/modules/video_coding/frame_buffer2_unittest.cc index 674ae29bfc..ad776df310 100644 --- a/webrtc/modules/video_coding/frame_buffer2_unittest.cc +++ b/webrtc/modules/video_coding/frame_buffer2_unittest.cc @@ -135,7 +135,10 @@ class TestFrameBuffer2 : public ::testing::Test { void ExtractFrame(int64_t max_wait_time = 0) { crit_.Enter(); if (max_wait_time == 0) { - frames_.emplace_back(buffer_.NextFrame(0)); + std::unique_ptr frame; + FrameBuffer::ReturnReason res = buffer_.NextFrame(0, &frame); + if (res != FrameBuffer::ReturnReason::kStopped) + frames_.emplace_back(std::move(frame)); crit_.Leave(); } else { max_wait_time_ = max_wait_time; @@ -170,7 +173,11 @@ class TestFrameBuffer2 : public ::testing::Test { if (tfb->tear_down_) return false; - tfb->frames_.emplace_back(tfb->buffer_.NextFrame(tfb->max_wait_time_)); + std::unique_ptr frame; + FrameBuffer::ReturnReason res = + tfb->buffer_.NextFrame(tfb->max_wait_time_, &frame); + if (res != FrameBuffer::ReturnReason::kStopped) + tfb->frames_.emplace_back(std::move(frame)); } } }