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_helpers.h" | 6 #include "base/callback_helpers.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "media/base/gmock_callback_support.h" | 8 #include "media/base/gmock_callback_support.h" |
9 #include "media/base/mock_filters.h" | 9 #include "media/base/mock_filters.h" |
10 #include "media/base/test_helpers.h" | 10 #include "media/base/test_helpers.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace media { | 24 namespace media { |
25 | 25 |
26 static const VideoFrame::Format kVideoFormat = VideoFrame::YV12; | 26 static const VideoFrame::Format kVideoFormat = VideoFrame::YV12; |
27 static const gfx::Size kCodedSize(320, 240); | 27 static const gfx::Size kCodedSize(320, 240); |
28 static const gfx::Rect kVisibleRect(320, 240); | 28 static const gfx::Rect kVisibleRect(320, 240); |
29 static const gfx::Size kNaturalSize(320, 240); | 29 static const gfx::Size kNaturalSize(320, 240); |
30 | 30 |
31 class VideoFrameStreamTest : public testing::TestWithParam<bool> { | 31 class VideoFrameStreamTest : public testing::TestWithParam<bool> { |
32 public: | 32 public: |
33 VideoFrameStreamTest() | 33 VideoFrameStreamTest() |
34 : video_frame_stream_(new VideoFrameStream( | 34 : video_config_(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, |
35 message_loop_.message_loop_proxy(), | |
36 base::Bind(&VideoFrameStreamTest::SetDecryptorReadyCallback, | |
37 base::Unretained(this)))), | |
38 video_config_(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, | |
39 kCodedSize, kVisibleRect, kNaturalSize, NULL, 0, | 35 kCodedSize, kVisibleRect, kNaturalSize, NULL, 0, |
40 GetParam()), | 36 GetParam()), |
41 demuxer_stream_(new StrictMock<MockDemuxerStream>()), | 37 demuxer_stream_(new StrictMock<MockDemuxerStream>()), |
42 decryptor_(new NiceMock<MockDecryptor>()), | 38 decryptor_(new NiceMock<MockDecryptor>()), |
43 decoder_(new StrictMock<MockVideoDecoder>()), | 39 decoder_(new StrictMock<MockVideoDecoder>()), |
44 is_initialized_(false) { | 40 is_initialized_(false) { |
45 decoders_.push_back(decoder_); | 41 ScopedVector<VideoDecoder> decoders; |
| 42 decoders.push_back(decoder_); |
| 43 |
| 44 video_frame_stream_ = new VideoFrameStream( |
| 45 message_loop_.message_loop_proxy(), |
| 46 decoders.Pass(), |
| 47 base::Bind(&VideoFrameStreamTest::SetDecryptorReadyCallback, |
| 48 base::Unretained(this))); |
46 | 49 |
47 EXPECT_CALL(*demuxer_stream_, type()) | 50 EXPECT_CALL(*demuxer_stream_, type()) |
48 .WillRepeatedly(Return(DemuxerStream::VIDEO)); | 51 .WillRepeatedly(Return(DemuxerStream::VIDEO)); |
49 EXPECT_CALL(*demuxer_stream_, video_decoder_config()) | 52 EXPECT_CALL(*demuxer_stream_, video_decoder_config()) |
50 .WillRepeatedly(ReturnRef(video_config_)); | 53 .WillRepeatedly(ReturnRef(video_config_)); |
51 EXPECT_CALL(*demuxer_stream_, Read(_)) | 54 EXPECT_CALL(*demuxer_stream_, Read(_)) |
52 .WillRepeatedly(RunCallback<0>(DemuxerStream::kOk, | 55 .WillRepeatedly(RunCallback<0>(DemuxerStream::kOk, |
53 scoped_refptr<DecoderBuffer>())); | 56 scoped_refptr<DecoderBuffer>())); |
54 | 57 |
55 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 58 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) |
(...skipping 25 matching lines...) Expand all Loading... |
81 MOCK_METHOD2(OnFrameRead, void(VideoDecoder::Status, | 84 MOCK_METHOD2(OnFrameRead, void(VideoDecoder::Status, |
82 const scoped_refptr<VideoFrame>&)); | 85 const scoped_refptr<VideoFrame>&)); |
83 MOCK_METHOD0(OnReset, void()); | 86 MOCK_METHOD0(OnReset, void()); |
84 MOCK_METHOD0(OnStopped, void()); | 87 MOCK_METHOD0(OnStopped, void()); |
85 | 88 |
86 void EnterPendingInitializationState() { | 89 void EnterPendingInitializationState() { |
87 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 90 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
88 .WillOnce(SaveArg<1>(&decoder_init_cb_)); | 91 .WillOnce(SaveArg<1>(&decoder_init_cb_)); |
89 video_frame_stream_->Initialize( | 92 video_frame_stream_->Initialize( |
90 demuxer_stream_, | 93 demuxer_stream_, |
91 decoders_, | |
92 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), | 94 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), |
93 base::Bind(&VideoFrameStreamTest::OnInitialized, | 95 base::Bind(&VideoFrameStreamTest::OnInitialized, |
94 base::Unretained(this))); | 96 base::Unretained(this))); |
95 message_loop_.RunUntilIdle(); | 97 message_loop_.RunUntilIdle(); |
96 } | 98 } |
97 | 99 |
98 void SatisfyPendingInitialization(bool success) { | 100 void SatisfyPendingInitialization(bool success) { |
99 EXPECT_CALL(*this, OnInitialized(success, false)) | 101 EXPECT_CALL(*this, OnInitialized(success, false)) |
100 .WillOnce(SaveArg<0>(&is_initialized_)); | 102 .WillOnce(SaveArg<0>(&is_initialized_)); |
101 base::ResetAndReturn(&decoder_init_cb_).Run( | 103 base::ResetAndReturn(&decoder_init_cb_).Run( |
102 success ? PIPELINE_OK : DECODER_ERROR_NOT_SUPPORTED); | 104 success ? PIPELINE_OK : DECODER_ERROR_NOT_SUPPORTED); |
103 message_loop_.RunUntilIdle(); | 105 message_loop_.RunUntilIdle(); |
| 106 |
| 107 // Failed initialization will delete unused decoders. |
| 108 if (!success) |
| 109 decoder_ = NULL; |
104 } | 110 } |
105 | 111 |
106 void EnterPendingReadFrameState() { | 112 void EnterPendingReadFrameState() { |
107 EXPECT_CALL(*decoder_, Read(_)) | 113 EXPECT_CALL(*decoder_, Read(_)) |
108 .WillOnce(SaveArg<0>(&decoder_read_cb_)); | 114 .WillOnce(SaveArg<0>(&decoder_read_cb_)); |
109 EXPECT_CALL(*this, OnFrameRead(VideoDecoder::kOk, _)); | 115 EXPECT_CALL(*this, OnFrameRead(VideoDecoder::kOk, _)); |
110 video_frame_stream_->ReadFrame(base::Bind( | 116 video_frame_stream_->ReadFrame(base::Bind( |
111 &VideoFrameStreamTest::OnFrameRead, base::Unretained(this))); | 117 &VideoFrameStreamTest::OnFrameRead, base::Unretained(this))); |
112 message_loop_.RunUntilIdle(); | 118 message_loop_.RunUntilIdle(); |
113 } | 119 } |
(...skipping 14 matching lines...) Expand all Loading... |
128 } | 134 } |
129 | 135 |
130 void SatisfyPendingReset() { | 136 void SatisfyPendingReset() { |
131 base::ResetAndReturn(&decoder_reset_cb_).Run(); | 137 base::ResetAndReturn(&decoder_reset_cb_).Run(); |
132 message_loop_.RunUntilIdle(); | 138 message_loop_.RunUntilIdle(); |
133 } | 139 } |
134 | 140 |
135 void EnterPendingStopState() { | 141 void EnterPendingStopState() { |
136 // If initialization failed, we won't call VideoDecoder::Stop() during | 142 // If initialization failed, we won't call VideoDecoder::Stop() during |
137 // the stopping process. | 143 // the stopping process. |
138 EXPECT_CALL(*decoder_, Stop(_)) | 144 if (decoder_) { |
139 .Times(AtMost(1)) | 145 EXPECT_CALL(*decoder_, Stop(_)) |
140 .WillRepeatedly(SaveArg<0>(&decoder_stop_cb_)); | 146 .WillRepeatedly(SaveArg<0>(&decoder_stop_cb_)); |
| 147 } |
| 148 |
141 EXPECT_CALL(*this, OnStopped()) | 149 EXPECT_CALL(*this, OnStopped()) |
142 .WillOnce(Assign(&is_initialized_, false)); | 150 .WillOnce(Assign(&is_initialized_, false)); |
143 video_frame_stream_->Stop(base::Bind(&VideoFrameStreamTest::OnStopped, | 151 video_frame_stream_->Stop(base::Bind(&VideoFrameStreamTest::OnStopped, |
144 base::Unretained(this))); | 152 base::Unretained(this))); |
145 message_loop_.RunUntilIdle(); | 153 message_loop_.RunUntilIdle(); |
146 } | 154 } |
147 | 155 |
148 void SatisfyPendingStop() { | 156 void SatisfyPendingStop() { |
149 // If decoder is not initialized, |decoder_stop_cb_| can be null. In that | 157 // If decoder is not initialized, |decoder_stop_cb_| can be null. In that |
150 // case, we don't actually need to satisfy the stop callback. | 158 // case, we don't actually need to satisfy the stop callback. |
(...skipping 30 matching lines...) Expand all Loading... |
181 | 189 |
182 private: | 190 private: |
183 MessageLoop message_loop_; | 191 MessageLoop message_loop_; |
184 | 192 |
185 scoped_refptr<VideoFrameStream> video_frame_stream_; | 193 scoped_refptr<VideoFrameStream> video_frame_stream_; |
186 VideoDecoderConfig video_config_; | 194 VideoDecoderConfig video_config_; |
187 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_stream_; | 195 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_stream_; |
188 // Use NiceMock since we don't care about most of calls on the decryptor, e.g. | 196 // Use NiceMock since we don't care about most of calls on the decryptor, e.g. |
189 // RegisterNewKeyCB(). | 197 // RegisterNewKeyCB(). |
190 scoped_ptr<NiceMock<MockDecryptor> > decryptor_; | 198 scoped_ptr<NiceMock<MockDecryptor> > decryptor_; |
191 scoped_refptr<StrictMock<MockVideoDecoder> > decoder_; | 199 StrictMock<MockVideoDecoder>* decoder_; // Owned by |video_frame_stream_|. |
192 VideoFrameStream::VideoDecoderList decoders_; | |
193 | 200 |
194 // Callbacks to simulate pending decoder operations. | 201 // Callbacks to simulate pending decoder operations. |
195 PipelineStatusCB decoder_init_cb_; | 202 PipelineStatusCB decoder_init_cb_; |
196 VideoDecoder::ReadCB decoder_read_cb_; | 203 VideoDecoder::ReadCB decoder_read_cb_; |
197 base::Closure decoder_reset_cb_; | 204 base::Closure decoder_reset_cb_; |
198 base::Closure decoder_stop_cb_; | 205 base::Closure decoder_stop_cb_; |
199 | 206 |
200 bool is_initialized_; | 207 bool is_initialized_; |
201 | 208 |
202 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); | 209 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 333 } |
327 | 334 |
328 TEST_P(VideoFrameStreamTest, Stop_AfterReadFrame_AfterReset) { | 335 TEST_P(VideoFrameStreamTest, Stop_AfterReadFrame_AfterReset) { |
329 Initialize(); | 336 Initialize(); |
330 ReadFrame(); | 337 ReadFrame(); |
331 Reset(); | 338 Reset(); |
332 Stop(); | 339 Stop(); |
333 } | 340 } |
334 | 341 |
335 } // namespace media | 342 } // namespace media |
OLD | NEW |