OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/debug/stack_trace.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
12 #include "base/timer.h" | 13 #include "base/timer.h" |
13 #include "media/base/data_buffer.h" | 14 #include "media/base/data_buffer.h" |
14 #include "media/base/gmock_callback_support.h" | 15 #include "media/base/gmock_callback_support.h" |
15 #include "media/base/limits.h" | 16 #include "media/base/limits.h" |
16 #include "media/base/mock_filters.h" | 17 #include "media/base/mock_filters.h" |
17 #include "media/base/test_helpers.h" | 18 #include "media/base/test_helpers.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // We expect the video size to be set. | 108 // We expect the video size to be set. |
108 EXPECT_CALL(*this, OnNaturalSizeChanged(kNaturalSize)); | 109 EXPECT_CALL(*this, OnNaturalSizeChanged(kNaturalSize)); |
109 | 110 |
110 // Start prerolling. | 111 // Start prerolling. |
111 QueuePrerollFrames(0); | 112 QueuePrerollFrames(0); |
112 Preroll(0, PIPELINE_OK); | 113 Preroll(0, PIPELINE_OK); |
113 } | 114 } |
114 | 115 |
115 void InitializeRenderer(PipelineStatus expected) { | 116 void InitializeRenderer(PipelineStatus expected) { |
116 SCOPED_TRACE(base::StringPrintf("InitializeRenderer(%d)", expected)); | 117 SCOPED_TRACE(base::StringPrintf("InitializeRenderer(%d)", expected)); |
| 118 WaitableMessageLoopEvent event; |
| 119 CallInitialize(event.GetPipelineStatusCB()); |
| 120 event.RunAndWaitForStatus(expected); |
| 121 } |
| 122 |
| 123 void CallInitialize(const PipelineStatusCB& status_cb) { |
117 VideoRendererBase::VideoDecoderList decoders; | 124 VideoRendererBase::VideoDecoderList decoders; |
118 decoders.push_back(decoder_); | 125 decoders.push_back(decoder_); |
119 | |
120 WaitableMessageLoopEvent event; | |
121 renderer_->Initialize( | 126 renderer_->Initialize( |
122 demuxer_stream_, | 127 demuxer_stream_, |
123 decoders, | 128 decoders, |
124 event.GetPipelineStatusCB(), | 129 status_cb, |
125 base::Bind(&MockStatisticsCB::OnStatistics, | 130 base::Bind(&MockStatisticsCB::OnStatistics, |
126 base::Unretained(&statistics_cb_object_)), | 131 base::Unretained(&statistics_cb_object_)), |
127 base::Bind(&VideoRendererBaseTest::OnTimeUpdate, | 132 base::Bind(&VideoRendererBaseTest::OnTimeUpdate, |
128 base::Unretained(this)), | 133 base::Unretained(this)), |
129 base::Bind(&VideoRendererBaseTest::OnNaturalSizeChanged, | 134 base::Bind(&VideoRendererBaseTest::OnNaturalSizeChanged, |
130 base::Unretained(this)), | 135 base::Unretained(this)), |
131 ended_event_.GetClosure(), | 136 ended_event_.GetClosure(), |
132 error_event_.GetPipelineStatusCB(), | 137 error_event_.GetPipelineStatusCB(), |
133 base::Bind(&VideoRendererBaseTest::GetTime, base::Unretained(this)), | 138 base::Bind(&VideoRendererBaseTest::GetTime, base::Unretained(this)), |
134 base::Bind(&VideoRendererBaseTest::GetDuration, | 139 base::Bind(&VideoRendererBaseTest::GetDuration, |
135 base::Unretained(this))); | 140 base::Unretained(this))); |
136 event.RunAndWaitForStatus(expected); | |
137 } | 141 } |
138 | 142 |
139 void Play() { | 143 void Play() { |
140 SCOPED_TRACE("Play()"); | 144 SCOPED_TRACE("Play()"); |
141 WaitableMessageLoopEvent event; | 145 WaitableMessageLoopEvent event; |
142 renderer_->Play(event.GetClosure()); | 146 renderer_->Play(event.GetClosure()); |
143 event.RunAndWait(); | 147 event.RunAndWait(); |
144 } | 148 } |
145 | 149 |
146 void Preroll(int timestamp_ms, PipelineStatus expected) { | 150 void Preroll(int timestamp_ms, PipelineStatus expected) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 WaitableMessageLoopEvent error_event_; | 351 WaitableMessageLoopEvent error_event_; |
348 WaitableMessageLoopEvent ended_event_; | 352 WaitableMessageLoopEvent ended_event_; |
349 base::Closure pending_read_cb_; | 353 base::Closure pending_read_cb_; |
350 | 354 |
351 std::deque<std::pair< | 355 std::deque<std::pair< |
352 VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_; | 356 VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_; |
353 | 357 |
354 DISALLOW_COPY_AND_ASSIGN(VideoRendererBaseTest); | 358 DISALLOW_COPY_AND_ASSIGN(VideoRendererBaseTest); |
355 }; | 359 }; |
356 | 360 |
| 361 TEST_F(VideoRendererBaseTest, DoNothing) { |
| 362 // Test that creation and deletion doesn't depend on calls to Initialize() |
| 363 // and/or Stop(). |
| 364 } |
| 365 |
| 366 TEST_F(VideoRendererBaseTest, StopWithoutInitialize) { |
| 367 Stop(); |
| 368 } |
| 369 |
357 TEST_F(VideoRendererBaseTest, Initialize) { | 370 TEST_F(VideoRendererBaseTest, Initialize) { |
358 Initialize(); | 371 Initialize(); |
359 EXPECT_EQ(0, GetCurrentTimestampInMs()); | 372 EXPECT_EQ(0, GetCurrentTimestampInMs()); |
360 Shutdown(); | 373 Shutdown(); |
361 } | 374 } |
362 | 375 |
| 376 static void ExpectNotCalled(PipelineStatus) { |
| 377 base::debug::StackTrace stack; |
| 378 ADD_FAILURE() << "Expected callback not to be called\n" << stack.ToString(); |
| 379 } |
| 380 |
| 381 TEST_F(VideoRendererBaseTest, StopWhileInitializing) { |
| 382 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
| 383 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
| 384 CallInitialize(base::Bind(&ExpectNotCalled)); |
| 385 Stop(); |
| 386 |
| 387 // ~VideoRendererBase() will CHECK() if we left anything initialized. |
| 388 } |
| 389 |
| 390 TEST_F(VideoRendererBaseTest, StopWhileFlushing) { |
| 391 Initialize(); |
| 392 Pause(); |
| 393 renderer_->Flush(base::Bind(&ExpectNotCalled, PIPELINE_OK)); |
| 394 Stop(); |
| 395 |
| 396 // ~VideoRendererBase() will CHECK() if we left anything initialized. |
| 397 } |
| 398 |
363 TEST_F(VideoRendererBaseTest, Play) { | 399 TEST_F(VideoRendererBaseTest, Play) { |
364 Initialize(); | 400 Initialize(); |
365 Play(); | 401 Play(); |
366 Shutdown(); | 402 Shutdown(); |
367 } | 403 } |
368 | 404 |
369 TEST_F(VideoRendererBaseTest, EndOfStream_DefaultFrameDuration) { | 405 TEST_F(VideoRendererBaseTest, EndOfStream_DefaultFrameDuration) { |
370 Initialize(); | 406 Initialize(); |
371 Play(); | 407 Play(); |
372 | 408 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 InSequence s; | 651 InSequence s; |
616 | 652 |
617 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 653 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
618 .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)); | 654 .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)); |
619 InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED); | 655 InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED); |
620 | 656 |
621 Stop(); | 657 Stop(); |
622 } | 658 } |
623 | 659 |
624 } // namespace media | 660 } // namespace media |
OLD | NEW |