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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // We expect the video size to be set. | 105 // We expect the video size to be set. |
105 EXPECT_CALL(*this, OnNaturalSizeChanged(kNaturalSize)); | 106 EXPECT_CALL(*this, OnNaturalSizeChanged(kNaturalSize)); |
106 | 107 |
107 // Start prerolling. | 108 // Start prerolling. |
108 QueuePrerollFrames(0); | 109 QueuePrerollFrames(0); |
109 Preroll(0, PIPELINE_OK); | 110 Preroll(0, PIPELINE_OK); |
110 } | 111 } |
111 | 112 |
112 void InitializeRenderer(PipelineStatus expected) { | 113 void InitializeRenderer(PipelineStatus expected) { |
113 SCOPED_TRACE(base::StringPrintf("InitializeRenderer(%d)", expected)); | 114 SCOPED_TRACE(base::StringPrintf("InitializeRenderer(%d)", expected)); |
| 115 WaitableMessageLoopEvent event; |
| 116 CallInitialize(event.GetPipelineStatusCB()); |
| 117 event.RunAndWaitForStatus(expected); |
| 118 } |
| 119 |
| 120 void CallInitialize(const PipelineStatusCB& status_cb) { |
114 VideoRendererBase::VideoDecoderList decoders; | 121 VideoRendererBase::VideoDecoderList decoders; |
115 decoders.push_back(decoder_); | 122 decoders.push_back(decoder_); |
116 | |
117 WaitableMessageLoopEvent event; | |
118 renderer_->Initialize( | 123 renderer_->Initialize( |
119 demuxer_stream_, | 124 demuxer_stream_, |
120 decoders, | 125 decoders, |
121 event.GetPipelineStatusCB(), | 126 status_cb, |
122 base::Bind(&MockStatisticsCB::OnStatistics, | 127 base::Bind(&MockStatisticsCB::OnStatistics, |
123 base::Unretained(&statistics_cb_object_)), | 128 base::Unretained(&statistics_cb_object_)), |
124 base::Bind(&VideoRendererBaseTest::OnTimeUpdate, | 129 base::Bind(&VideoRendererBaseTest::OnTimeUpdate, |
125 base::Unretained(this)), | 130 base::Unretained(this)), |
126 base::Bind(&VideoRendererBaseTest::OnNaturalSizeChanged, | 131 base::Bind(&VideoRendererBaseTest::OnNaturalSizeChanged, |
127 base::Unretained(this)), | 132 base::Unretained(this)), |
128 ended_event_.GetClosure(), | 133 ended_event_.GetClosure(), |
129 error_event_.GetPipelineStatusCB(), | 134 error_event_.GetPipelineStatusCB(), |
130 base::Bind(&VideoRendererBaseTest::GetTime, base::Unretained(this)), | 135 base::Bind(&VideoRendererBaseTest::GetTime, base::Unretained(this)), |
131 base::Bind(&VideoRendererBaseTest::GetDuration, | 136 base::Bind(&VideoRendererBaseTest::GetDuration, |
132 base::Unretained(this))); | 137 base::Unretained(this))); |
133 event.RunAndWaitForStatus(expected); | |
134 } | 138 } |
135 | 139 |
136 void Play() { | 140 void Play() { |
137 SCOPED_TRACE("Play()"); | 141 SCOPED_TRACE("Play()"); |
138 WaitableMessageLoopEvent event; | 142 WaitableMessageLoopEvent event; |
139 renderer_->Play(event.GetClosure()); | 143 renderer_->Play(event.GetClosure()); |
140 event.RunAndWait(); | 144 event.RunAndWait(); |
141 } | 145 } |
142 | 146 |
143 void Preroll(int timestamp_ms, PipelineStatus expected) { | 147 void Preroll(int timestamp_ms, PipelineStatus expected) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 359 |
356 // Run during FrameRequested() to unblock WaitForPendingRead(). | 360 // Run during FrameRequested() to unblock WaitForPendingRead(). |
357 base::Closure wait_for_pending_read_cb_; | 361 base::Closure wait_for_pending_read_cb_; |
358 | 362 |
359 std::deque<std::pair< | 363 std::deque<std::pair< |
360 VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_; | 364 VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_; |
361 | 365 |
362 DISALLOW_COPY_AND_ASSIGN(VideoRendererBaseTest); | 366 DISALLOW_COPY_AND_ASSIGN(VideoRendererBaseTest); |
363 }; | 367 }; |
364 | 368 |
| 369 TEST_F(VideoRendererBaseTest, DoNothing) { |
| 370 // Test that creation and deletion doesn't depend on calls to Initialize() |
| 371 // and/or Stop(). |
| 372 } |
| 373 |
| 374 TEST_F(VideoRendererBaseTest, StopWithoutInitialize) { |
| 375 Stop(); |
| 376 } |
| 377 |
365 TEST_F(VideoRendererBaseTest, Initialize) { | 378 TEST_F(VideoRendererBaseTest, Initialize) { |
366 Initialize(); | 379 Initialize(); |
367 EXPECT_EQ(0, GetCurrentTimestampInMs()); | 380 EXPECT_EQ(0, GetCurrentTimestampInMs()); |
368 Shutdown(); | 381 Shutdown(); |
369 } | 382 } |
370 | 383 |
| 384 static void ExpectNotCalled(PipelineStatus) { |
| 385 base::debug::StackTrace stack; |
| 386 ADD_FAILURE() << "Expected callback not to be called\n" << stack.ToString(); |
| 387 } |
| 388 |
| 389 TEST_F(VideoRendererBaseTest, StopWhileInitializing) { |
| 390 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
| 391 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
| 392 CallInitialize(base::Bind(&ExpectNotCalled)); |
| 393 Stop(); |
| 394 |
| 395 // ~VideoRendererBase() will CHECK() if we left anything initialized. |
| 396 } |
| 397 |
| 398 TEST_F(VideoRendererBaseTest, StopWhileFlushing) { |
| 399 Initialize(); |
| 400 Pause(); |
| 401 renderer_->Flush(base::Bind(&ExpectNotCalled, PIPELINE_OK)); |
| 402 Stop(); |
| 403 |
| 404 // ~VideoRendererBase() will CHECK() if we left anything initialized. |
| 405 } |
| 406 |
371 TEST_F(VideoRendererBaseTest, Play) { | 407 TEST_F(VideoRendererBaseTest, Play) { |
372 Initialize(); | 408 Initialize(); |
373 Play(); | 409 Play(); |
374 Shutdown(); | 410 Shutdown(); |
375 } | 411 } |
376 | 412 |
377 TEST_F(VideoRendererBaseTest, EndOfStream_DefaultFrameDuration) { | 413 TEST_F(VideoRendererBaseTest, EndOfStream_DefaultFrameDuration) { |
378 Initialize(); | 414 Initialize(); |
379 Play(); | 415 Play(); |
380 | 416 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 InSequence s; | 643 InSequence s; |
608 | 644 |
609 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 645 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
610 .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)); | 646 .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)); |
611 InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED); | 647 InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED); |
612 | 648 |
613 Stop(); | 649 Stop(); |
614 } | 650 } |
615 | 651 |
616 } // namespace media | 652 } // namespace media |
OLD | NEW |