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 "content/renderer/media/rtc_video_decoder.h" | 5 #include "content/renderer/media/rtc_video_decoder.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 decoder_->Initialize( | 215 decoder_->Initialize( |
216 NULL, NewExpectedStatusCB(PIPELINE_OK), NewStatisticsCB()); | 216 NULL, NewExpectedStatusCB(PIPELINE_OK), NewStatisticsCB()); |
217 message_loop_.RunAllPending(); | 217 message_loop_.RunAllPending(); |
218 } | 218 } |
219 | 219 |
220 StatisticsCB NewStatisticsCB() { | 220 StatisticsCB NewStatisticsCB() { |
221 return base::Bind(&MockStatisticsCB::OnStatistics, | 221 return base::Bind(&MockStatisticsCB::OnStatistics, |
222 base::Unretained(&statistics_cb_)); | 222 base::Unretained(&statistics_cb_)); |
223 } | 223 } |
224 | 224 |
| 225 void RenderFrame() { |
| 226 NullVideoFrame video_frame; |
| 227 decoder_->RenderFrame(&video_frame); |
| 228 } |
| 229 |
225 MOCK_METHOD2(FrameReady, void(media::VideoDecoder::DecoderStatus status, | 230 MOCK_METHOD2(FrameReady, void(media::VideoDecoder::DecoderStatus status, |
226 const scoped_refptr<media::VideoFrame>&)); | 231 const scoped_refptr<media::VideoFrame>&)); |
227 | 232 |
228 // Fixture members. | 233 // Fixture members. |
229 scoped_refptr<MockVideoTrack> video_track_; | 234 scoped_refptr<MockVideoTrack> video_track_; |
230 scoped_refptr<RTCVideoDecoder> decoder_; | 235 scoped_refptr<RTCVideoDecoder> decoder_; |
231 scoped_refptr<MockVideoRenderer> renderer_; | 236 scoped_refptr<MockVideoRenderer> renderer_; |
232 MockStatisticsCB statistics_cb_; | 237 MockStatisticsCB statistics_cb_; |
233 MessageLoop message_loop_; | 238 MessageLoop message_loop_; |
234 media::VideoDecoder::ReadCB read_cb_; | 239 media::VideoDecoder::ReadCB read_cb_; |
235 | 240 |
236 private: | 241 private: |
237 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest); | 242 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoderTest); |
238 }; | 243 }; |
239 | 244 |
240 const int RTCVideoDecoderTest::kWidth = 640; | 245 const int RTCVideoDecoderTest::kWidth = 640; |
241 const int RTCVideoDecoderTest::kHeight = 480; | 246 const int RTCVideoDecoderTest::kHeight = 480; |
242 const PipelineStatistics RTCVideoDecoderTest::kStatistics; | 247 const PipelineStatistics RTCVideoDecoderTest::kStatistics; |
243 | 248 |
| 249 MATCHER_P2(HasSize, width, height, "") { |
| 250 EXPECT_EQ(arg->data_size().width(), width); |
| 251 EXPECT_EQ(arg->data_size().height(), height); |
| 252 EXPECT_EQ(arg->natural_size().width(), width); |
| 253 EXPECT_EQ(arg->natural_size().height(), height); |
| 254 return (arg->data_size().width() == width) && |
| 255 (arg->data_size().height() == height) && |
| 256 (arg->natural_size().width() == width) && |
| 257 (arg->natural_size().height() == height); |
| 258 } |
| 259 |
244 TEST_F(RTCVideoDecoderTest, Initialize_Successful) { | 260 TEST_F(RTCVideoDecoderTest, Initialize_Successful) { |
245 InitializeDecoderSuccessfully(); | 261 InitializeDecoderSuccessfully(); |
246 | 262 |
247 // Test that the output media format is an uncompressed video surface that | 263 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
248 // matches the dimensions specified by RTC. | 264 HasSize(kWidth, kHeight))); |
249 EXPECT_EQ(kWidth, decoder_->natural_size().width()); | 265 decoder_->Read(read_cb_); |
250 EXPECT_EQ(kHeight, decoder_->natural_size().height()); | 266 RenderFrame(); |
251 } | 267 } |
252 | 268 |
253 TEST_F(RTCVideoDecoderTest, DoReset) { | 269 TEST_F(RTCVideoDecoderTest, DoReset) { |
254 InitializeDecoderSuccessfully(); | 270 InitializeDecoderSuccessfully(); |
255 | 271 |
256 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, _)); | 272 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
| 273 scoped_refptr<media::VideoFrame>())); |
257 decoder_->Read(read_cb_); | 274 decoder_->Read(read_cb_); |
258 decoder_->Reset(media::NewExpectedClosure()); | 275 decoder_->Reset(media::NewExpectedClosure()); |
259 | 276 |
260 message_loop_.RunAllPending(); | 277 message_loop_.RunAllPending(); |
261 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); | 278 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); |
262 } | 279 } |
263 | 280 |
264 TEST_F(RTCVideoDecoderTest, DoRenderFrame) { | 281 TEST_F(RTCVideoDecoderTest, DoRenderFrame) { |
265 InitializeDecoderSuccessfully(); | 282 InitializeDecoderSuccessfully(); |
266 | 283 |
267 NullVideoFrame video_frame; | 284 for (size_t i = 0; i < media::limits::kMaxVideoFrames; ++i) |
268 | 285 RenderFrame(); |
269 for (size_t i = 0; i < media::limits::kMaxVideoFrames; ++i) { | |
270 decoder_->RenderFrame(&video_frame); | |
271 } | |
272 | 286 |
273 message_loop_.RunAllPending(); | 287 message_loop_.RunAllPending(); |
274 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); | 288 EXPECT_EQ(RTCVideoDecoder::kNormal, decoder_->state_); |
275 } | 289 } |
276 | 290 |
277 TEST_F(RTCVideoDecoderTest, DoSetSize) { | 291 TEST_F(RTCVideoDecoderTest, DoSetSize) { |
278 InitializeDecoderSuccessfully(); | 292 InitializeDecoderSuccessfully(); |
279 | 293 |
| 294 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
| 295 HasSize(kWidth, kHeight))); |
| 296 decoder_->Read(read_cb_); |
| 297 RenderFrame(); |
| 298 message_loop_.RunAllPending(); |
| 299 |
280 int new_width = kWidth * 2; | 300 int new_width = kWidth * 2; |
281 int new_height = kHeight * 2; | 301 int new_height = kHeight * 2; |
282 gfx::Size new_natural_size(new_width, new_height); | |
283 | |
284 decoder_->SetSize(new_width, new_height); | 302 decoder_->SetSize(new_width, new_height); |
285 | 303 |
286 EXPECT_EQ(new_width, decoder_->natural_size().width()); | 304 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
287 EXPECT_EQ(new_height, decoder_->natural_size().height()); | 305 HasSize(new_width, new_height))); |
288 | 306 decoder_->Read(read_cb_); |
| 307 RenderFrame(); |
289 message_loop_.RunAllPending(); | 308 message_loop_.RunAllPending(); |
290 } | 309 } |
291 | 310 |
292 TEST_F(RTCVideoDecoderTest, ReadAndShutdown) { | 311 TEST_F(RTCVideoDecoderTest, ReadAndShutdown) { |
293 // Test all the Read requests can be fullfilled (which is needed in order to | 312 // Test all the Read requests can be fullfilled (which is needed in order to |
294 // teardown the pipeline) even when there's no input frame. | 313 // teardown the pipeline) even when there's no input frame. |
295 InitializeDecoderSuccessfully(); | 314 InitializeDecoderSuccessfully(); |
296 | 315 |
297 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, _)).Times(2); | 316 EXPECT_CALL(*this, FrameReady(media::VideoDecoder::kOk, |
| 317 scoped_refptr<media::VideoFrame>())).Times(2); |
298 decoder_->Read(read_cb_); | 318 decoder_->Read(read_cb_); |
299 EXPECT_FALSE(decoder_->shutting_down_); | 319 EXPECT_FALSE(decoder_->shutting_down_); |
300 decoder_->PrepareForShutdownHack(); | 320 decoder_->PrepareForShutdownHack(); |
301 EXPECT_TRUE(decoder_->shutting_down_); | 321 EXPECT_TRUE(decoder_->shutting_down_); |
302 decoder_->Read(read_cb_); | 322 decoder_->Read(read_cb_); |
303 | 323 |
304 message_loop_.RunAllPending(); | 324 message_loop_.RunAllPending(); |
305 } | 325 } |
OLD | NEW |