| 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 <algorithm> |
| 6 |
| 5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 6 #include "base/callback.h" | 8 #include "base/callback.h" |
| 7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 8 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 9 #include "base/synchronization/condition_variable.h" | 11 #include "base/synchronization/condition_variable.h" |
| 10 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 11 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 13 #include "media/base/data_buffer.h" | 15 #include "media/base/data_buffer.h" |
| 16 #include "media/base/gmock_callback_support.h" |
| 14 #include "media/base/limits.h" | 17 #include "media/base/limits.h" |
| 15 #include "media/base/mock_callback.h" | 18 #include "media/base/mock_callback.h" |
| 16 #include "media/base/mock_filters.h" | 19 #include "media/base/mock_filters.h" |
| 17 #include "media/base/video_frame.h" | 20 #include "media/base/video_frame.h" |
| 18 #include "media/filters/video_renderer_base.h" | 21 #include "media/filters/video_renderer_base.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 23 |
| 21 using ::testing::_; | 24 using ::testing::_; |
| 22 using ::testing::AnyNumber; | 25 using ::testing::AnyNumber; |
| 23 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| 24 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 25 using ::testing::NotNull; | 28 using ::testing::NotNull; |
| 26 using ::testing::Return; | 29 using ::testing::Return; |
| 27 using ::testing::ReturnRef; | 30 using ::testing::ReturnRef; |
| 28 using ::testing::StrictMock; | 31 using ::testing::StrictMock; |
| 29 | 32 |
| 30 namespace media { | 33 namespace media { |
| 31 | 34 |
| 32 static const int kFrameDuration = 10; | 35 static const int kFrameDuration = 10; |
| 33 static const int kVideoDuration = kFrameDuration * 100; | 36 static const int kVideoDuration = kFrameDuration * 100; |
| 34 static const int kEndOfStream = -1; | 37 static const int kEndOfStream = -1; |
| 35 static const gfx::Size kNaturalSize(16u, 16u); | 38 static const gfx::Size kNaturalSize(16u, 16u); |
| 36 | 39 |
| 37 ACTION_P(RunPipelineStatusCB1, status) { | |
| 38 arg1.Run(status); | |
| 39 } | |
| 40 | |
| 41 class VideoRendererBaseTest : public ::testing::Test { | 40 class VideoRendererBaseTest : public ::testing::Test { |
| 42 public: | 41 public: |
| 43 VideoRendererBaseTest() | 42 VideoRendererBaseTest() |
| 44 : decoder_(new MockVideoDecoder()), | 43 : decoder_(new MockVideoDecoder()), |
| 45 demuxer_stream_(new MockDemuxerStream()), | 44 demuxer_stream_(new MockDemuxerStream()), |
| 46 cv_(&lock_), | 45 cv_(&lock_), |
| 47 event_(false, false), | 46 event_(false, false), |
| 48 timeout_(TestTimeouts::action_timeout()), | 47 timeout_(TestTimeouts::action_timeout()), |
| 49 prerolling_(false), | 48 prerolling_(false), |
| 50 next_frame_timestamp_(0), | 49 next_frame_timestamp_(0), |
| 51 paint_cv_(&lock_), | 50 paint_cv_(&lock_), |
| 52 paint_was_called_(false), | 51 paint_was_called_(false), |
| 53 should_queue_read_cb_(false) { | 52 should_queue_read_cb_(false) { |
| 54 renderer_ = new VideoRendererBase( | 53 renderer_ = new VideoRendererBase( |
| 55 base::Bind(&VideoRendererBaseTest::Paint, base::Unretained(this)), | 54 base::Bind(&VideoRendererBaseTest::Paint, base::Unretained(this)), |
| 56 base::Bind(&VideoRendererBaseTest::OnSetOpaque, base::Unretained(this)), | 55 base::Bind(&VideoRendererBaseTest::OnSetOpaque, base::Unretained(this)), |
| 57 true); | 56 true); |
| 58 | 57 |
| 59 EXPECT_CALL(*demuxer_stream_, type()) | 58 EXPECT_CALL(*demuxer_stream_, type()) |
| 60 .WillRepeatedly(Return(DemuxerStream::VIDEO)); | 59 .WillRepeatedly(Return(DemuxerStream::VIDEO)); |
| 61 | 60 |
| 62 // We expect these to be called but we don't care how/when. | 61 // We expect these to be called but we don't care how/when. |
| 63 EXPECT_CALL(*decoder_, Stop(_)) | 62 EXPECT_CALL(*decoder_, Stop(_)) |
| 64 .WillRepeatedly(RunClosure()); | 63 .WillRepeatedly(RunClosure<0>()); |
| 65 EXPECT_CALL(statistics_cb_object_, OnStatistics(_)) | 64 EXPECT_CALL(statistics_cb_object_, OnStatistics(_)) |
| 66 .Times(AnyNumber()); | 65 .Times(AnyNumber()); |
| 67 EXPECT_CALL(*this, OnTimeUpdate(_)) | 66 EXPECT_CALL(*this, OnTimeUpdate(_)) |
| 68 .Times(AnyNumber()); | 67 .Times(AnyNumber()); |
| 69 EXPECT_CALL(*this, OnSetOpaque(_)) | 68 EXPECT_CALL(*this, OnSetOpaque(_)) |
| 70 .Times(AnyNumber()); | 69 .Times(AnyNumber()); |
| 71 } | 70 } |
| 72 | 71 |
| 73 virtual ~VideoRendererBaseTest() { | 72 virtual ~VideoRendererBaseTest() { |
| 74 read_queue_.clear(); | 73 read_queue_.clear(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 100 // Monitor reads from the decoder. | 99 // Monitor reads from the decoder. |
| 101 EXPECT_CALL(*decoder_, Read(_)) | 100 EXPECT_CALL(*decoder_, Read(_)) |
| 102 .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::FrameRequested)); | 101 .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::FrameRequested)); |
| 103 | 102 |
| 104 EXPECT_CALL(*decoder_, Reset(_)) | 103 EXPECT_CALL(*decoder_, Reset(_)) |
| 105 .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::FlushRequested)); | 104 .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::FlushRequested)); |
| 106 | 105 |
| 107 InSequence s; | 106 InSequence s; |
| 108 | 107 |
| 109 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 108 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
| 110 .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); | 109 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
| 111 | 110 |
| 112 // Set playback rate before anything else happens. | 111 // Set playback rate before anything else happens. |
| 113 renderer_->SetPlaybackRate(1.0f); | 112 renderer_->SetPlaybackRate(1.0f); |
| 114 | 113 |
| 115 // Initialize, we shouldn't have any reads. | 114 // Initialize, we shouldn't have any reads. |
| 116 InitializeRenderer(PIPELINE_OK); | 115 InitializeRenderer(PIPELINE_OK); |
| 117 | 116 |
| 118 // We expect the video size to be set. | 117 // We expect the video size to be set. |
| 119 EXPECT_CALL(*this, OnNaturalSizeChanged(kNaturalSize)); | 118 EXPECT_CALL(*this, OnNaturalSizeChanged(kNaturalSize)); |
| 120 | 119 |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 StartPrerolling(kFrameDuration * 6, PIPELINE_OK); | 686 StartPrerolling(kFrameDuration * 6, PIPELINE_OK); |
| 688 AbortRead(); | 687 AbortRead(); |
| 689 VerifyNotPrerolling(); | 688 VerifyNotPrerolling(); |
| 690 Shutdown(); | 689 Shutdown(); |
| 691 } | 690 } |
| 692 | 691 |
| 693 TEST_F(VideoRendererBaseTest, VideoDecoder_InitFailure) { | 692 TEST_F(VideoRendererBaseTest, VideoDecoder_InitFailure) { |
| 694 InSequence s; | 693 InSequence s; |
| 695 | 694 |
| 696 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 695 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
| 697 .WillOnce(RunPipelineStatusCB1(PIPELINE_ERROR_DECODE)); | 696 .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE)); |
| 698 InitializeRenderer(PIPELINE_ERROR_DECODE); | 697 InitializeRenderer(PIPELINE_ERROR_DECODE); |
| 699 } | 698 } |
| 700 | 699 |
| 701 } // namespace media | 700 } // namespace media |
| OLD | NEW |