| 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 static const int kFrameDurationInMs = 10; | 33 static const int kFrameDurationInMs = 10; |
| 34 static const int kVideoDurationInMs = kFrameDurationInMs * 100; | 34 static const int kVideoDurationInMs = kFrameDurationInMs * 100; |
| 35 static const gfx::Size kNaturalSize(16u, 16u); | 35 static const gfx::Size kNaturalSize(16u, 16u); |
| 36 | 36 |
| 37 class VideoRendererBaseTest : public ::testing::Test { | 37 class VideoRendererBaseTest : public ::testing::Test { |
| 38 public: | 38 public: |
| 39 VideoRendererBaseTest() | 39 VideoRendererBaseTest() |
| 40 : decoder_(new MockVideoDecoder()), | 40 : decoder_(new MockVideoDecoder()), |
| 41 demuxer_stream_(new MockDemuxerStream()) { | 41 demuxer_stream_(new MockDemuxerStream()) { |
| 42 renderer_ = new VideoRendererBase( | 42 renderer_ = new VideoRendererBase( |
| 43 message_loop_.message_loop_proxy(), |
| 43 base::Bind(&VideoRendererBaseTest::OnPaint, base::Unretained(this)), | 44 base::Bind(&VideoRendererBaseTest::OnPaint, base::Unretained(this)), |
| 44 base::Bind(&VideoRendererBaseTest::OnSetOpaque, base::Unretained(this)), | 45 base::Bind(&VideoRendererBaseTest::OnSetOpaque, base::Unretained(this)), |
| 45 true); | 46 true); |
| 46 | 47 |
| 47 EXPECT_CALL(*demuxer_stream_, type()) | 48 EXPECT_CALL(*demuxer_stream_, type()) |
| 48 .WillRepeatedly(Return(DemuxerStream::VIDEO)); | 49 .WillRepeatedly(Return(DemuxerStream::VIDEO)); |
| 49 | 50 |
| 50 // We expect these to be called but we don't care how/when. | 51 // We expect these to be called but we don't care how/when. |
| 51 EXPECT_CALL(*decoder_, Stop(_)) | 52 EXPECT_CALL(*decoder_, Stop(_)) |
| 52 .WillRepeatedly(RunClosure<0>()); | 53 .WillRepeatedly(RunClosure<0>()); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 base::TimeDelta GetTime() { | 291 base::TimeDelta GetTime() { |
| 291 base::AutoLock l(lock_); | 292 base::AutoLock l(lock_); |
| 292 return time_; | 293 return time_; |
| 293 } | 294 } |
| 294 | 295 |
| 295 base::TimeDelta GetDuration() { | 296 base::TimeDelta GetDuration() { |
| 296 return duration_; | 297 return duration_; |
| 297 } | 298 } |
| 298 | 299 |
| 299 void FrameRequested(const VideoDecoder::ReadCB& read_cb) { | 300 void FrameRequested(const VideoDecoder::ReadCB& read_cb) { |
| 300 // TODO(scherkus): Make VideoRendererBase call on right thread. | 301 DCHECK_EQ(&message_loop_, MessageLoop::current()); |
| 301 if (&message_loop_ != MessageLoop::current()) { | |
| 302 message_loop_.PostTask(FROM_HERE, base::Bind( | |
| 303 &VideoRendererBaseTest::FrameRequested, base::Unretained(this), | |
| 304 read_cb)); | |
| 305 return; | |
| 306 } | |
| 307 | |
| 308 CHECK(read_cb_.is_null()); | 302 CHECK(read_cb_.is_null()); |
| 309 read_cb_ = read_cb; | 303 read_cb_ = read_cb; |
| 310 | 304 |
| 311 // Wake up WaitForPendingRead() if needed. | 305 // Wake up WaitForPendingRead() if needed. |
| 312 if (!pending_read_cb_.is_null()) | 306 if (!pending_read_cb_.is_null()) |
| 313 base::ResetAndReturn(&pending_read_cb_).Run(); | 307 base::ResetAndReturn(&pending_read_cb_).Run(); |
| 314 | 308 |
| 315 if (decode_results_.empty()) | 309 if (decode_results_.empty()) |
| 316 return; | 310 return; |
| 317 | 311 |
| 318 SatisfyPendingRead(); | 312 SatisfyPendingRead(); |
| 319 } | 313 } |
| 320 | 314 |
| 321 void FlushRequested(const base::Closure& callback) { | 315 void FlushRequested(const base::Closure& callback) { |
| 322 // TODO(scherkus): Make VideoRendererBase call on right thread. | 316 DCHECK_EQ(&message_loop_, MessageLoop::current()); |
| 323 if (&message_loop_ != MessageLoop::current()) { | |
| 324 message_loop_.PostTask(FROM_HERE, base::Bind( | |
| 325 &VideoRendererBaseTest::FlushRequested, base::Unretained(this), | |
| 326 callback)); | |
| 327 return; | |
| 328 } | |
| 329 | |
| 330 decode_results_.clear(); | 317 decode_results_.clear(); |
| 331 if (!read_cb_.is_null()) { | 318 if (!read_cb_.is_null()) { |
| 332 QueueAbortedRead(); | 319 QueueAbortedRead(); |
| 333 SatisfyPendingRead(); | 320 SatisfyPendingRead(); |
| 334 } | 321 } |
| 335 | 322 |
| 336 message_loop_.PostTask(FROM_HERE, callback); | 323 message_loop_.PostTask(FROM_HERE, callback); |
| 337 } | 324 } |
| 338 | 325 |
| 339 MessageLoop message_loop_; | 326 MessageLoop message_loop_; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 InSequence s; | 605 InSequence s; |
| 619 | 606 |
| 620 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 607 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
| 621 .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE)); | 608 .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE)); |
| 622 InitializeRenderer(PIPELINE_ERROR_DECODE); | 609 InitializeRenderer(PIPELINE_ERROR_DECODE); |
| 623 | 610 |
| 624 Stop(); | 611 Stop(); |
| 625 } | 612 } |
| 626 | 613 |
| 627 } // namespace media | 614 } // namespace media |
| OLD | NEW |