Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: media/renderers/video_renderer_impl_unittest.cc

Issue 1136513004: Switch GetWallClockTime to using vectors for input and output. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/renderers/video_renderer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/debug/stack_trace.h" 10 #include "base/debug/stack_trace.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "base/test/simple_test_tick_clock.h" 17 #include "base/test/simple_test_tick_clock.h"
18 #include "media/base/data_buffer.h" 18 #include "media/base/data_buffer.h"
19 #include "media/base/gmock_callback_support.h" 19 #include "media/base/gmock_callback_support.h"
20 #include "media/base/limits.h" 20 #include "media/base/limits.h"
21 #include "media/base/mock_filters.h" 21 #include "media/base/mock_filters.h"
22 #include "media/base/null_video_sink.h" 22 #include "media/base/null_video_sink.h"
23 #include "media/base/test_helpers.h" 23 #include "media/base/test_helpers.h"
24 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
25 #include "media/base/wall_clock_time_source.h"
25 #include "media/renderers/video_renderer_impl.h" 26 #include "media/renderers/video_renderer_impl.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 using ::testing::_; 29 using ::testing::_;
29 using ::testing::AnyNumber; 30 using ::testing::AnyNumber;
30 using ::testing::Invoke; 31 using ::testing::Invoke;
31 using ::testing::Mock; 32 using ::testing::Mock;
32 using ::testing::NiceMock; 33 using ::testing::NiceMock;
33 using ::testing::Return; 34 using ::testing::Return;
34 using ::testing::SaveArg; 35 using ::testing::SaveArg;
(...skipping 24 matching lines...) Expand all
59 base::Bind(&MockCB::FrameReceived, base::Unretained(&mock_cb_)), 60 base::Bind(&MockCB::FrameReceived, base::Unretained(&mock_cb_)),
60 message_loop_.task_runner())); 61 message_loop_.task_runner()));
61 62
62 renderer_.reset(new VideoRendererImpl( 63 renderer_.reset(new VideoRendererImpl(
63 message_loop_.message_loop_proxy(), null_video_sink_.get(), 64 message_loop_.message_loop_proxy(), null_video_sink_.get(),
64 decoders.Pass(), true, new MediaLog())); 65 decoders.Pass(), true, new MediaLog()));
65 if (!GetParam()) 66 if (!GetParam())
66 renderer_->disable_new_video_renderer_for_testing(); 67 renderer_->disable_new_video_renderer_for_testing();
67 renderer_->SetTickClockForTesting(scoped_ptr<base::TickClock>(tick_clock_)); 68 renderer_->SetTickClockForTesting(scoped_ptr<base::TickClock>(tick_clock_));
68 null_video_sink_->set_tick_clock_for_testing(tick_clock_); 69 null_video_sink_->set_tick_clock_for_testing(tick_clock_);
70 time_source_.set_tick_clock_for_testing(tick_clock_);
69 71
70 // Start wallclock time at a non-zero value. 72 // Start wallclock time at a non-zero value.
71 AdvanceWallclockTimeInMs(12345); 73 AdvanceWallclockTimeInMs(12345);
72 74
73 demuxer_stream_.set_video_decoder_config(TestVideoConfig::Normal()); 75 demuxer_stream_.set_video_decoder_config(TestVideoConfig::Normal());
74 76
75 // We expect these to be called but we don't care how/when. 77 // We expect these to be called but we don't care how/when.
76 EXPECT_CALL(demuxer_stream_, Read(_)).WillRepeatedly( 78 EXPECT_CALL(demuxer_stream_, Read(_)).WillRepeatedly(
77 RunCallback<0>(DemuxerStream::kOk, 79 RunCallback<0>(DemuxerStream::kOk,
78 scoped_refptr<DecoderBuffer>(new DecoderBuffer(0)))); 80 scoped_refptr<DecoderBuffer>(new DecoderBuffer(0))));
(...skipping 22 matching lines...) Expand all
101 WaitableMessageLoopEvent event; 103 WaitableMessageLoopEvent event;
102 CallInitialize(event.GetPipelineStatusCB(), low_delay, expected); 104 CallInitialize(event.GetPipelineStatusCB(), low_delay, expected);
103 event.RunAndWaitForStatus(expected); 105 event.RunAndWaitForStatus(expected);
104 } 106 }
105 107
106 void CallInitialize(const PipelineStatusCB& status_cb, 108 void CallInitialize(const PipelineStatusCB& status_cb,
107 bool low_delay, 109 bool low_delay,
108 PipelineStatus decoder_status) { 110 PipelineStatus decoder_status) {
109 if (low_delay) 111 if (low_delay)
110 demuxer_stream_.set_liveness(DemuxerStream::LIVENESS_LIVE); 112 demuxer_stream_.set_liveness(DemuxerStream::LIVENESS_LIVE);
111 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)).WillOnce( 113 EXPECT_CALL(*decoder_, Initialize(_, _, _, _))
112 DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(decoder_status))); 114 .WillOnce(
115 DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(decoder_status)));
113 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); 116 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
114 renderer_->Initialize( 117 renderer_->Initialize(
115 &demuxer_stream_, status_cb, media::SetDecryptorReadyCB(), 118 &demuxer_stream_, status_cb, media::SetDecryptorReadyCB(),
116 base::Bind(&VideoRendererImplTest::OnStatisticsUpdate, 119 base::Bind(&VideoRendererImplTest::OnStatisticsUpdate,
117 base::Unretained(this)), 120 base::Unretained(this)),
118 base::Bind(&StrictMock<MockCB>::BufferingStateChange, 121 base::Bind(&StrictMock<MockCB>::BufferingStateChange,
119 base::Unretained(&mock_cb_)), 122 base::Unretained(&mock_cb_)),
120 ended_event_.GetClosure(), error_event_.GetPipelineStatusCB(), 123 ended_event_.GetClosure(), error_event_.GetPipelineStatusCB(),
121 base::Bind(&VideoRendererImplTest::GetWallClockTime, 124 base::Bind(&WallClockTimeSource::GetWallClockTimes,
122 base::Unretained(this)), 125 base::Unretained(&time_source_)),
123 base::Bind(&VideoRendererImplTest::OnWaitingForDecryptionKey, 126 base::Bind(&VideoRendererImplTest::OnWaitingForDecryptionKey,
124 base::Unretained(this))); 127 base::Unretained(this)));
125 } 128 }
126 129
127 void StartPlayingFrom(int milliseconds) { 130 void StartPlayingFrom(int milliseconds) {
128 SCOPED_TRACE(base::StringPrintf("StartPlayingFrom(%d)", milliseconds)); 131 SCOPED_TRACE(base::StringPrintf("StartPlayingFrom(%d)", milliseconds));
129 renderer_->StartPlayingFrom( 132 const base::TimeDelta media_time =
130 base::TimeDelta::FromMilliseconds(milliseconds)); 133 base::TimeDelta::FromMilliseconds(milliseconds);
134 time_source_.SetMediaTime(media_time);
135 renderer_->StartPlayingFrom(media_time);
131 message_loop_.RunUntilIdle(); 136 message_loop_.RunUntilIdle();
132 } 137 }
133 138
134 void Flush() { 139 void Flush() {
135 SCOPED_TRACE("Flush()"); 140 SCOPED_TRACE("Flush()");
136 WaitableMessageLoopEvent event; 141 WaitableMessageLoopEvent event;
137 renderer_->Flush(event.GetClosure()); 142 renderer_->Flush(event.GetClosure());
138 event.RunAndWait(); 143 event.RunAndWait();
139 } 144 }
140 145
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void AdvanceWallclockTimeInMs(int time_ms) { 261 void AdvanceWallclockTimeInMs(int time_ms) {
257 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 262 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
258 base::AutoLock l(lock_); 263 base::AutoLock l(lock_);
259 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms)); 264 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms));
260 } 265 }
261 266
262 void AdvanceTimeInMs(int time_ms) { 267 void AdvanceTimeInMs(int time_ms) {
263 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 268 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
264 base::AutoLock l(lock_); 269 base::AutoLock l(lock_);
265 time_ += base::TimeDelta::FromMilliseconds(time_ms); 270 time_ += base::TimeDelta::FromMilliseconds(time_ms);
271 time_source_.StopTicking();
272 time_source_.SetMediaTime(time_);
273 time_source_.StartTicking();
266 } 274 }
267 275
268 bool has_ended() const { 276 bool has_ended() const {
269 return ended_event_.is_signaled(); 277 return ended_event_.is_signaled();
270 } 278 }
271 279
272 protected: 280 protected:
273 // Fixture members. 281 // Fixture members.
274 scoped_ptr<VideoRendererImpl> renderer_; 282 scoped_ptr<VideoRendererImpl> renderer_;
275 base::SimpleTestTickClock* tick_clock_; // Owned by |renderer_|. 283 base::SimpleTestTickClock* tick_clock_; // Owned by |renderer_|.
276 MockVideoDecoder* decoder_; // Owned by |renderer_|. 284 MockVideoDecoder* decoder_; // Owned by |renderer_|.
277 NiceMock<MockDemuxerStream> demuxer_stream_; 285 NiceMock<MockDemuxerStream> demuxer_stream_;
278 286
279 // Use StrictMock<T> to catch missing/extra callbacks. 287 // Use StrictMock<T> to catch missing/extra callbacks.
280 class MockCB { 288 class MockCB {
281 public: 289 public:
282 MOCK_METHOD1(FrameReceived, void(const scoped_refptr<VideoFrame>&)); 290 MOCK_METHOD1(FrameReceived, void(const scoped_refptr<VideoFrame>&));
283 MOCK_METHOD1(BufferingStateChange, void(BufferingState)); 291 MOCK_METHOD1(BufferingStateChange, void(BufferingState));
284 }; 292 };
285 StrictMock<MockCB> mock_cb_; 293 StrictMock<MockCB> mock_cb_;
286 294
287 // Must be destroyed before |renderer_| since they share |tick_clock_|. 295 // Must be destroyed before |renderer_| since they share |tick_clock_|.
288 scoped_ptr<NullVideoSink> null_video_sink_; 296 scoped_ptr<NullVideoSink> null_video_sink_;
289 297
290 PipelineStatistics last_pipeline_statistics_; 298 PipelineStatistics last_pipeline_statistics_;
291 299
300 WallClockTimeSource time_source_;
301
292 private: 302 private:
293 base::TimeTicks GetWallClockTime(base::TimeDelta time) {
294 base::AutoLock l(lock_);
295 return tick_clock_->NowTicks() + (time - time_);
296 }
297
298 void DecodeRequested(const scoped_refptr<DecoderBuffer>& buffer, 303 void DecodeRequested(const scoped_refptr<DecoderBuffer>& buffer,
299 const VideoDecoder::DecodeCB& decode_cb) { 304 const VideoDecoder::DecodeCB& decode_cb) {
300 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 305 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
301 CHECK(decode_cb_.is_null()); 306 CHECK(decode_cb_.is_null());
302 decode_cb_ = decode_cb; 307 decode_cb_ = decode_cb;
303 308
304 // Wake up WaitForPendingRead() if needed. 309 // Wake up WaitForPendingRead() if needed.
305 if (!wait_for_pending_decode_cb_.is_null()) 310 if (!wait_for_pending_decode_cb_.is_null())
306 base::ResetAndReturn(&wait_for_pending_decode_cb_).Run(); 311 base::ResetAndReturn(&wait_for_pending_decode_cb_).Run();
307 312
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 Destroy(); 432 Destroy();
428 } 433 }
429 434
430 TEST_P(VideoRendererImplTest, DecodeError_Playing) { 435 TEST_P(VideoRendererImplTest, DecodeError_Playing) {
431 Initialize(); 436 Initialize();
432 QueueFrames("0 10 20 30"); 437 QueueFrames("0 10 20 30");
433 EXPECT_CALL(mock_cb_, FrameReceived(_)).Times(testing::AtLeast(1)); 438 EXPECT_CALL(mock_cb_, FrameReceived(_)).Times(testing::AtLeast(1));
434 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); 439 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH));
435 StartPlayingFrom(0); 440 StartPlayingFrom(0);
436 renderer_->OnTimeStateChanged(true); 441 renderer_->OnTimeStateChanged(true);
442 time_source_.StartTicking();
437 AdvanceTimeInMs(10); 443 AdvanceTimeInMs(10);
438 444
439 QueueFrames("error"); 445 QueueFrames("error");
440 SatisfyPendingRead(); 446 SatisfyPendingRead();
441 WaitForError(PIPELINE_ERROR_DECODE); 447 WaitForError(PIPELINE_ERROR_DECODE);
442 Destroy(); 448 Destroy();
443 } 449 }
444 450
445 TEST_P(VideoRendererImplTest, DecodeError_DuringStartPlayingFrom) { 451 TEST_P(VideoRendererImplTest, DecodeError_DuringStartPlayingFrom) {
446 Initialize(); 452 Initialize();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) 495 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH))
490 .Times(AnyNumber()); 496 .Times(AnyNumber());
491 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_NOTHING)) 497 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_NOTHING))
492 .Times(AnyNumber()); 498 .Times(AnyNumber());
493 StartPlayingFrom(0); 499 StartPlayingFrom(0);
494 500
495 QueueFrames("10"); 501 QueueFrames("10");
496 SatisfyPendingRead(); 502 SatisfyPendingRead();
497 503
498 renderer_->OnTimeStateChanged(true); 504 renderer_->OnTimeStateChanged(true);
505 time_source_.StartTicking();
506
499 WaitableMessageLoopEvent event; 507 WaitableMessageLoopEvent event;
500 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) 508 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10)))
501 .WillOnce(RunClosure(event.GetClosure())); 509 .WillOnce(RunClosure(event.GetClosure()));
502 AdvanceTimeInMs(10); 510 AdvanceTimeInMs(10);
503 event.RunAndWait(); 511 event.RunAndWait();
504 512
505 Destroy(); 513 Destroy();
506 } 514 }
507 515
508 // Verify that a late decoder response doesn't break invariants in the renderer. 516 // Verify that a late decoder response doesn't break invariants in the renderer.
(...skipping 29 matching lines...) Expand all
538 Mock::VerifyAndClearExpectations(&mock_cb_); 546 Mock::VerifyAndClearExpectations(&mock_cb_);
539 } 547 }
540 548
541 renderer_->OnTimeStateChanged(true); 549 renderer_->OnTimeStateChanged(true);
542 550
543 // Advance time slightly, but enough to exceed the duration of the last frame. 551 // Advance time slightly, but enough to exceed the duration of the last frame.
544 // Frames should be dropped and we should NOT signal having nothing. 552 // Frames should be dropped and we should NOT signal having nothing.
545 { 553 {
546 SCOPED_TRACE("Waiting for frame drops"); 554 SCOPED_TRACE("Waiting for frame drops");
547 WaitableMessageLoopEvent event; 555 WaitableMessageLoopEvent event;
548 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))) 556
549 .Times(0); 557 // Note: Starting the TimeSource will cause the old VideoRendererImpl to
550 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))) 558 // start rendering frames on its own thread, so the first frame may be
551 .Times(0); 559 // received.
560 time_source_.StartTicking();
561 if (GetParam())
562 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))).Times(0);
563 else
564 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))).Times(AnyNumber());
565
566 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))).Times(0);
552 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))) 567 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90)))
553 .WillOnce(RunClosure(event.GetClosure())); 568 .WillOnce(RunClosure(event.GetClosure()));
554 AdvanceTimeInMs(91); 569 AdvanceTimeInMs(91);
555 570
556 event.RunAndWait(); 571 event.RunAndWait();
557 Mock::VerifyAndClearExpectations(&mock_cb_); 572 Mock::VerifyAndClearExpectations(&mock_cb_);
558 } 573 }
559 574
560 // Advance time more. Now we should signal having nothing. And put 575 // Advance time more. Now we should signal having nothing. And put
561 // the last frame up for display. 576 // the last frame up for display.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); 683 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH));
669 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))) 684 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0)))
670 .WillOnce(RunClosure(event.GetClosure())); 685 .WillOnce(RunClosure(event.GetClosure()));
671 StartPlayingFrom(0); 686 StartPlayingFrom(0);
672 event.RunAndWait(); 687 event.RunAndWait();
673 Mock::VerifyAndClearExpectations(&mock_cb_); 688 Mock::VerifyAndClearExpectations(&mock_cb_);
674 EXPECT_EQ(0u, last_pipeline_statistics_.video_frames_dropped); 689 EXPECT_EQ(0u, last_pipeline_statistics_.video_frames_dropped);
675 } 690 }
676 691
677 renderer_->OnTimeStateChanged(true); 692 renderer_->OnTimeStateChanged(true);
693 time_source_.StartTicking();
678 694
679 // Suspend all future callbacks and synthetically advance the media time, 695 // Suspend all future callbacks and synthetically advance the media time,
680 // because this is a background render, we won't underflow by waiting until 696 // because this is a background render, we won't underflow by waiting until
681 // a pending read is ready. 697 // a pending read is ready.
682 null_video_sink_->set_background_render(true); 698 null_video_sink_->set_background_render(true);
683 AdvanceTimeInMs(91); 699 AdvanceTimeInMs(91);
684 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))); 700 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90)));
685 WaitForPendingRead(); 701 WaitForPendingRead();
686 SatisfyPendingReadWithEndOfStream(); 702 SatisfyPendingReadWithEndOfStream();
687 703
688 // If this wasn't background rendering mode, this would result in two frames 704 // If this wasn't background rendering mode, this would result in two frames
689 // being dropped, but since we set background render to true, none should be 705 // being dropped, but since we set background render to true, none should be
690 // reported 706 // reported
691 EXPECT_EQ(0u, last_pipeline_statistics_.video_frames_dropped); 707 EXPECT_EQ(0u, last_pipeline_statistics_.video_frames_dropped);
692 EXPECT_EQ(4u, last_pipeline_statistics_.video_frames_decoded); 708 EXPECT_EQ(4u, last_pipeline_statistics_.video_frames_decoded);
693 709
694 AdvanceTimeInMs(30); 710 AdvanceTimeInMs(30);
695 WaitForEnded(); 711 WaitForEnded();
696 Destroy(); 712 Destroy();
697 } 713 }
698 714
699 INSTANTIATE_TEST_CASE_P(OldVideoRenderer, 715 INSTANTIATE_TEST_CASE_P(OldVideoRenderer,
700 VideoRendererImplTest, 716 VideoRendererImplTest,
701 testing::Values(false)); 717 testing::Values(false));
702 INSTANTIATE_TEST_CASE_P(NewVideoRenderer, 718 INSTANTIATE_TEST_CASE_P(NewVideoRenderer,
703 VideoRendererImplTest, 719 VideoRendererImplTest,
704 testing::Values(true)); 720 testing::Values(true));
705 721
706 } // namespace media 722 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/video_renderer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698