Skip to content

Commit

Permalink
Consider start time for frame painting and fix naming in test.
Browse files Browse the repository at this point in the history
These changes were accidentally dropped from the final commit after
approval in previous review: https://codereview.chromium.org/2007463005

BUG=614099
TBR=xhwang

Review-Url: https://codereview.chromium.org/2034903002
Cr-Commit-Position: refs/heads/master@{#397614}
(cherry picked from commit 094201d)

Review URL: https://codereview.chromium.org/2038053003 .

Cr-Commit-Position: refs/branch-heads/2743@{crosswalk-project#217}
Cr-Branched-From: 2b3ae3b-refs/heads/master@{#394939}
  • Loading branch information
dalecurtis committed Jun 3, 2016
1 parent c3567d7 commit 53a26bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
5 changes: 5 additions & 0 deletions media/renderers/video_renderer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ void VideoRendererImpl::FrameReady(uint32_t sequence_token,
// We want to paint the first frame under two conditions: Either (1) we have
// enough frames to know it's definitely the first frame or (2) there may be
// no more frames coming (sometimes unless we paint one of them).
//
// For the first condition, we need at least two frames or the first frame
// must have a timestamp >= |start_timestamp_|, since otherwise we may be
// prerolling frames before the actual start time that will be dropped.
if (algorithm_->frames_queued() > 1 || received_end_of_stream_ ||
algorithm_->first_frame()->timestamp() >= start_timestamp_ ||
low_delay_ || !video_frame_stream_->CanReadWithoutStalling()) {
scoped_refptr<VideoFrame> frame = algorithm_->first_frame();
CheckForMetadataChanges(frame->format(), frame->natural_size());
Expand Down
48 changes: 24 additions & 24 deletions media/renderers/video_renderer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ class VideoRendererImplTest : public testing::Test {
event.RunAndWait();
}

void WaitForPendingRead() {
SCOPED_TRACE("WaitForPendingRead()");
void WaitForPendingDecode() {
SCOPED_TRACE("WaitForPendingDecode()");
if (!decode_cb_.is_null())
return;

Expand All @@ -231,7 +231,7 @@ class VideoRendererImplTest : public testing::Test {
DCHECK(wait_for_pending_decode_cb_.is_null());
}

void SatisfyPendingRead() {
void SatisfyPendingDecode() {
CHECK(!decode_cb_.is_null());
CHECK(!decode_results_.empty());

Expand All @@ -245,7 +245,7 @@ class VideoRendererImplTest : public testing::Test {
decode_results_.pop_front();
}

void SatisfyPendingReadWithEndOfStream() {
void SatisfyPendingDecodeWithEndOfStream() {
DCHECK(!decode_cb_.is_null());

// Return EOS buffer to trigger EOS frame.
Expand All @@ -258,7 +258,7 @@ class VideoRendererImplTest : public testing::Test {
FROM_HERE,
base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK));

WaitForPendingRead();
WaitForPendingDecode();

message_loop_.PostTask(
FROM_HERE,
Expand Down Expand Up @@ -353,7 +353,7 @@ class VideoRendererImplTest : public testing::Test {
EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
.WillOnce(RunClosure(event.GetClosure()));
EXPECT_CALL(mock_cb_, OnEnded());
SatisfyPendingReadWithEndOfStream();
SatisfyPendingDecodeWithEndOfStream();
event.RunAndWait();
}

Expand Down Expand Up @@ -414,7 +414,7 @@ class VideoRendererImplTest : public testing::Test {
QueueFrames("80 100 120 140 160");
else
QueueFrames("40 60 80 90");
SatisfyPendingRead();
SatisfyPendingDecode();
event.RunAndWait();
}

Expand Down Expand Up @@ -449,22 +449,22 @@ class VideoRendererImplTest : public testing::Test {
CHECK(decode_cb_.is_null());
decode_cb_ = decode_cb;

// Wake up WaitForPendingRead() if needed.
// Wake up WaitForPendingDecode() if needed.
if (!wait_for_pending_decode_cb_.is_null())
base::ResetAndReturn(&wait_for_pending_decode_cb_).Run();

if (decode_results_.empty())
return;

SatisfyPendingRead();
SatisfyPendingDecode();
}

void FlushRequested(const base::Closure& callback) {
DCHECK_EQ(&message_loop_, base::MessageLoop::current());
decode_results_.clear();
if (!decode_cb_.is_null()) {
QueueFrames("abort");
SatisfyPendingRead();
SatisfyPendingDecode();
}

message_loop_.PostTask(FROM_HERE, callback);
Expand All @@ -479,7 +479,7 @@ class VideoRendererImplTest : public testing::Test {
VideoDecoder::DecodeCB decode_cb_;
base::TimeDelta next_frame_timestamp_;

// Run during DecodeRequested() to unblock WaitForPendingRead().
// Run during DecodeRequested() to unblock WaitForPendingDecode().
base::Closure wait_for_pending_decode_cb_;

std::deque<std::pair<DecodeStatus, scoped_refptr<VideoFrame>>>
Expand Down Expand Up @@ -517,14 +517,14 @@ TEST_F(VideoRendererImplTest, InitializeAndStartPlayingFrom) {
TEST_F(VideoRendererImplTest, InitializeAndEndOfStream) {
Initialize();
StartPlayingFrom(0);
WaitForPendingRead();
WaitForPendingDecode();
{
SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH");
WaitableMessageLoopEvent event;
EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
.WillOnce(RunClosure(event.GetClosure()));
EXPECT_CALL(mock_cb_, OnEnded());
SatisfyPendingReadWithEndOfStream();
SatisfyPendingDecodeWithEndOfStream();
event.RunAndWait();
}
// Firing a time state changed to true should be ignored...
Expand Down Expand Up @@ -594,7 +594,7 @@ TEST_F(VideoRendererImplTest, DecodeError_Playing) {
AdvanceTimeInMs(10);

QueueFrames("error");
SatisfyPendingRead();
SatisfyPendingDecode();
WaitForError(PIPELINE_ERROR_DECODE);
Destroy();
}
Expand Down Expand Up @@ -664,7 +664,7 @@ TEST_F(VideoRendererImplTest, StartPlayingFrom_LowDelay) {
StartPlayingFrom(10);

QueueFrames("20");
SatisfyPendingRead();
SatisfyPendingDecode();

renderer_->OnTimeStateChanged(true);
time_source_.StartTicking();
Expand Down Expand Up @@ -744,7 +744,7 @@ TEST_F(VideoRendererImplTest, RenderingStopsAfterFirstFrame) {
StartPlayingFrom(0);

EXPECT_TRUE(IsReadPending());
SatisfyPendingReadWithEndOfStream();
SatisfyPendingDecodeWithEndOfStream();

event.RunAndWait();
}
Expand Down Expand Up @@ -773,7 +773,7 @@ TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) {
renderer_->OnTimeStateChanged(true);

EXPECT_TRUE(IsReadPending());
SatisfyPendingReadWithEndOfStream();
SatisfyPendingDecodeWithEndOfStream();
WaitForEnded();

renderer_->OnTimeStateChanged(false);
Expand Down Expand Up @@ -807,7 +807,7 @@ TEST_F(VideoRendererImplTest, RenderingStartedThenStopped) {

// Consider the case that rendering is faster than we setup the test event.
// In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will
// be called. And then during SatisfyPendingReadWithEndOfStream,
// be called. And then during SatisfyPendingDecodeWithEndOfStream,
// BUFFER_HAVE_ENOUGH will be called again.
EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
.Times(testing::AtMost(1));
Expand All @@ -824,8 +824,8 @@ TEST_F(VideoRendererImplTest, RenderingStartedThenStopped) {
null_video_sink_->set_background_render(true);
AdvanceTimeInMs(91);
EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90)));
WaitForPendingRead();
SatisfyPendingReadWithEndOfStream();
WaitForPendingDecode();
SatisfyPendingDecodeWithEndOfStream();

// If this wasn't background rendering mode, this would result in two frames
// being dropped, but since we set background render to true, none should be
Expand Down Expand Up @@ -867,15 +867,15 @@ TEST_F(VideoRendererImplTest, UnderflowEvictionBeforeEOS) {
event.RunAndWait();
}

WaitForPendingRead();
WaitForPendingDecode();

// Jump time far enough forward that no frames are valid.
renderer_->OnTimeStateChanged(false);
AdvanceTimeInMs(1000);
time_source_.StopTicking();

// Providing the end of stream packet should remove all frames and exit.
SatisfyPendingReadWithEndOfStream();
SatisfyPendingDecodeWithEndOfStream();
EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
WaitForEnded();
Destroy();
Expand Down Expand Up @@ -905,8 +905,8 @@ TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) {
Flush();

StartPlayingFrom(200);
WaitForPendingRead();
SatisfyPendingReadWithEndOfStream();
WaitForPendingDecode();
SatisfyPendingDecodeWithEndOfStream();
EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
WaitForEnded();
Destroy();
Expand Down

0 comments on commit 53a26bb

Please sign in to comment.