Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: media/filters/ffmpeg_video_decoder_unittest.cc

Issue 10910293: Add is_encrypted() in VideoDecoderConfig. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move is_encrypted into VideoDecoderConfig. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 // Initialize various test buffers. 85 // Initialize various test buffers.
86 frame_buffer_.reset(new uint8[kCodedSize.GetArea()]); 86 frame_buffer_.reset(new uint8[kCodedSize.GetArea()]);
87 end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer(); 87 end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer();
88 i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240"); 88 i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240");
89 corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame"); 89 corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame");
90 encrypted_i_frame_buffer_ = CreateFakeEncryptedBuffer(); 90 encrypted_i_frame_buffer_ = CreateFakeEncryptedBuffer();
91 91
92 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, 92 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
93 kVideoFormat, kCodedSize, kVisibleRect, kNaturalSize, 93 kVideoFormat, kCodedSize, kVisibleRect, kNaturalSize,
94 NULL, 0, true); 94 NULL, 0, false, true);
95 } 95 }
96 96
97 virtual ~FFmpegVideoDecoderTest() {} 97 virtual ~FFmpegVideoDecoderTest() {}
98 98
99 void Initialize() { 99 void Initialize() {
100 InitializeWithConfig(config_); 100 InitializeWithConfig(config_);
101 } 101 }
102 102
103 void InitializeWithEncryptedConfig() {
104 config_.set_is_encrypted(true);
acolwell GONE FROM CHROMIUM 2012/09/17 17:41:17 Just copy the config_.Initialize() call from above
xhwang 2012/09/17 19:42:25 Done.
105 InitializeWithConfig(config_);
106 }
107
103 void InitializeWithConfigAndStatus(const VideoDecoderConfig& config, 108 void InitializeWithConfigAndStatus(const VideoDecoderConfig& config,
104 PipelineStatus status) { 109 PipelineStatus status) {
105 EXPECT_CALL(*demuxer_, video_decoder_config()) 110 EXPECT_CALL(*demuxer_, video_decoder_config())
106 .WillRepeatedly(ReturnRef(config)); 111 .WillRepeatedly(ReturnRef(config));
107 112
108 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), 113 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status),
109 base::Bind(&MockStatisticsCB::OnStatistics, 114 base::Bind(&MockStatisticsCB::OnStatistics,
110 base::Unretained(&statistics_cb_))); 115 base::Unretained(&statistics_cb_)));
111 116
112 message_loop_.RunAllPending(); 117 message_loop_.RunAllPending();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 245
241 TEST_F(FFmpegVideoDecoderTest, Initialize_Normal) { 246 TEST_F(FFmpegVideoDecoderTest, Initialize_Normal) {
242 Initialize(); 247 Initialize();
243 } 248 }
244 249
245 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedDecoder) { 250 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedDecoder) {
246 // Test avcodec_find_decoder() returning NULL. 251 // Test avcodec_find_decoder() returning NULL.
247 VideoDecoderConfig config(kUnknownVideoCodec, VIDEO_CODEC_PROFILE_UNKNOWN, 252 VideoDecoderConfig config(kUnknownVideoCodec, VIDEO_CODEC_PROFILE_UNKNOWN,
248 kVideoFormat, 253 kVideoFormat,
249 kCodedSize, kVisibleRect, kNaturalSize, 254 kCodedSize, kVisibleRect, kNaturalSize,
250 NULL, 0); 255 NULL, false, false);
acolwell GONE FROM CHROMIUM 2012/09/17 17:41:17 nit: I'm pretty sure this should be 0, false here
xhwang 2012/09/17 19:42:25 Oops, thanks for the catch. Done here and blow.
251 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 256 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
252 } 257 }
253 258
254 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedPixelFormat) { 259 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedPixelFormat) {
255 // Ensure decoder handles unsupport pixel formats without crashing. 260 // Ensure decoder handles unsupport pixel formats without crashing.
256 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, 261 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
257 VideoFrame::INVALID, 262 VideoFrame::INVALID,
258 kCodedSize, kVisibleRect, kNaturalSize, 263 kCodedSize, kVisibleRect, kNaturalSize,
259 NULL, 0); 264 NULL, false, false);
260 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 265 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
261 } 266 }
262 267
263 TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) { 268 TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) {
264 // Specify Theora w/o extra data so that avcodec_open2() fails. 269 // Specify Theora w/o extra data so that avcodec_open2() fails.
265 VideoDecoderConfig config(kCodecTheora, VIDEO_CODEC_PROFILE_UNKNOWN, 270 VideoDecoderConfig config(kCodecTheora, VIDEO_CODEC_PROFILE_UNKNOWN,
266 kVideoFormat, 271 kVideoFormat,
267 kCodedSize, kVisibleRect, kNaturalSize, 272 kCodedSize, kVisibleRect, kNaturalSize,
268 NULL, 0); 273 NULL, false, false);
269 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 274 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
270 } 275 }
271 276
272 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorZero) { 277 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorZero) {
273 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 0, 1); 278 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 0, 1);
274 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 279 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
275 kVideoFormat, 280 kVideoFormat,
276 kCodedSize, kVisibleRect, natural_size, 281 kCodedSize, kVisibleRect, natural_size,
277 NULL, 0); 282 NULL, false, false);
278 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 283 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
279 } 284 }
280 285
281 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorZero) { 286 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorZero) {
282 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, 0); 287 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, 0);
283 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 288 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
284 kVideoFormat, 289 kVideoFormat,
285 kCodedSize, kVisibleRect, natural_size, 290 kCodedSize, kVisibleRect, natural_size,
286 NULL, 0); 291 NULL, false, false);
287 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 292 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
288 } 293 }
289 294
290 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorNegative) { 295 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorNegative) {
291 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), -1, 1); 296 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), -1, 1);
292 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 297 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
293 kVideoFormat, 298 kVideoFormat,
294 kCodedSize, kVisibleRect, natural_size, 299 kCodedSize, kVisibleRect, natural_size,
295 NULL, 0); 300 NULL, false, false);
296 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 301 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
297 } 302 }
298 303
299 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorNegative) { 304 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorNegative) {
300 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, -1); 305 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, -1);
301 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 306 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
302 kVideoFormat, 307 kVideoFormat,
303 kCodedSize, kVisibleRect, natural_size, 308 kCodedSize, kVisibleRect, natural_size,
304 NULL, 0); 309 NULL, false, false);
305 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 310 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
306 } 311 }
307 312
308 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorTooLarge) { 313 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorTooLarge) {
309 int width = kVisibleRect.size().width(); 314 int width = kVisibleRect.size().width();
310 int num = ceil(static_cast<double>(limits::kMaxDimension + 1) / width); 315 int num = ceil(static_cast<double>(limits::kMaxDimension + 1) / width);
311 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), num, 1); 316 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), num, 1);
312 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 317 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
313 kVideoFormat, 318 kVideoFormat,
314 kCodedSize, kVisibleRect, natural_size, 319 kCodedSize, kVisibleRect, natural_size,
315 NULL, 0); 320 NULL, false, false);
316 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 321 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
317 } 322 }
318 323
319 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorTooLarge) { 324 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorTooLarge) {
320 int den = kVisibleRect.size().width() + 1; 325 int den = kVisibleRect.size().width() + 1;
321 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, den); 326 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, den);
322 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 327 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
323 kVideoFormat, 328 kVideoFormat,
324 kCodedSize, kVisibleRect, natural_size, 329 kCodedSize, kVisibleRect, natural_size,
325 NULL, 0); 330 NULL, false, false);
326 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 331 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
327 } 332 }
328 333
329 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_Normal) { 334 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_Normal) {
330 Initialize(); 335 Initialize();
331 336
332 // Simulate decoding a single frame. 337 // Simulate decoding a single frame.
333 VideoDecoder::Status status; 338 VideoDecoder::Status status;
334 scoped_refptr<VideoFrame> video_frame; 339 scoped_refptr<VideoFrame> video_frame;
335 DecodeSingleFrame(i_frame_buffer_, &status, &video_frame); 340 DecodeSingleFrame(i_frame_buffer_, &status, &video_frame);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 DecodeIFrameThenTestFile("vp8-I-frame-320x480", 320, 480); 442 DecodeIFrameThenTestFile("vp8-I-frame-320x480", 320, 480);
438 } 443 }
439 444
440 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify 445 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify
441 // the output size was adjusted. 446 // the output size was adjusted.
442 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) { 447 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) {
443 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120); 448 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120);
444 } 449 }
445 450
446 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) { 451 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) {
447 Initialize(); 452 InitializeWithEncryptedConfig();
448 453
449 // Simulate decoding a single encrypted frame. 454 // Simulate decoding a single encrypted frame.
450 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 455 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
451 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_)); 456 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_));
452 457
453 VideoDecoder::Status status; 458 VideoDecoder::Status status;
454 scoped_refptr<VideoFrame> video_frame; 459 scoped_refptr<VideoFrame> video_frame;
455 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame); 460 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame);
456 461
457 EXPECT_EQ(status, VideoDecoder::kOk); 462 EXPECT_EQ(status, VideoDecoder::kOk);
458 ASSERT_TRUE(video_frame); 463 ASSERT_TRUE(video_frame);
459 EXPECT_FALSE(video_frame->IsEndOfStream()); 464 EXPECT_FALSE(video_frame->IsEndOfStream());
460 } 465 }
461 466
462 // Test the case that the decryptor fails to decrypt the encrypted buffer. 467 // Test the case that the decryptor fails to decrypt the encrypted buffer.
463 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) { 468 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) {
464 Initialize(); 469 InitializeWithEncryptedConfig();
465 470
466 // Simulate decoding a single encrypted frame. 471 // Simulate decoding a single encrypted frame.
467 EXPECT_CALL(*demuxer_, Read(_)) 472 EXPECT_CALL(*demuxer_, Read(_))
468 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 473 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
469 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 474 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
470 .WillRepeatedly(RunDecryptCB(Decryptor::kError, 475 .WillRepeatedly(RunDecryptCB(Decryptor::kError,
471 scoped_refptr<media::DecoderBuffer>())); 476 scoped_refptr<media::DecoderBuffer>()));
472 477
473 // Our read should still get satisfied with end of stream frame during an 478 // Our read should still get satisfied with end of stream frame during an
474 // error. 479 // error.
475 VideoDecoder::Status status; 480 VideoDecoder::Status status;
476 scoped_refptr<VideoFrame> video_frame; 481 scoped_refptr<VideoFrame> video_frame;
477 Read(&status, &video_frame); 482 Read(&status, &video_frame);
478 EXPECT_EQ(VideoDecoder::kDecryptError, status); 483 EXPECT_EQ(VideoDecoder::kDecryptError, status);
479 EXPECT_FALSE(video_frame); 484 EXPECT_FALSE(video_frame);
480 485
481 message_loop_.RunAllPending(); 486 message_loop_.RunAllPending();
482 } 487 }
483 488
484 // Test the case that the decryptor has no key to decrypt the encrypted buffer. 489 // Test the case that the decryptor has no key to decrypt the encrypted buffer.
485 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) { 490 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) {
486 Initialize(); 491 InitializeWithEncryptedConfig();
487 492
488 // Simulate decoding a single encrypted frame. 493 // Simulate decoding a single encrypted frame.
489 EXPECT_CALL(*demuxer_, Read(_)) 494 EXPECT_CALL(*demuxer_, Read(_))
490 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 495 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
491 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 496 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
492 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, 497 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey,
493 scoped_refptr<media::DecoderBuffer>())); 498 scoped_refptr<media::DecoderBuffer>()));
494 499
495 // Our read should still get satisfied with end of stream frame during an 500 // Our read should still get satisfied with end of stream frame during an
496 // error. 501 // error.
497 VideoDecoder::Status status; 502 VideoDecoder::Status status;
498 scoped_refptr<VideoFrame> video_frame; 503 scoped_refptr<VideoFrame> video_frame;
499 Read(&status, &video_frame); 504 Read(&status, &video_frame);
500 EXPECT_EQ(VideoDecoder::kDecryptError, status); 505 EXPECT_EQ(VideoDecoder::kDecryptError, status);
501 EXPECT_FALSE(video_frame); 506 EXPECT_FALSE(video_frame);
502 507
503 message_loop_.RunAllPending(); 508 message_loop_.RunAllPending();
504 } 509 }
505 510
506 // Test the case that the decryptor fails to decrypt the encrypted buffer but 511 // Test the case that the decryptor fails to decrypt the encrypted buffer but
507 // cannot detect the decryption error and returns a corrupted buffer. 512 // cannot detect the decryption error and returns a corrupted buffer.
508 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) { 513 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) {
509 Initialize(); 514 InitializeWithEncryptedConfig();
510 515
511 // Simulate decoding a single encrypted frame. 516 // Simulate decoding a single encrypted frame.
512 EXPECT_CALL(*demuxer_, Read(_)) 517 EXPECT_CALL(*demuxer_, Read(_))
513 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 518 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
514 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 519 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
515 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, 520 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess,
516 corrupt_i_frame_buffer_)); 521 corrupt_i_frame_buffer_));
517 522
518 // Our read should still get satisfied with end of stream frame during an 523 // Our read should still get satisfied with end of stream frame during an
519 // error. 524 // error.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 657
653 // Signal an aborted demuxer read. 658 // Signal an aborted demuxer read.
654 read_cb.Run(DemuxerStream::kAborted, NULL); 659 read_cb.Run(DemuxerStream::kAborted, NULL);
655 660
656 // Make sure we get a NULL video frame returned. 661 // Make sure we get a NULL video frame returned.
657 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); 662 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull()));
658 message_loop_.RunAllPending(); 663 message_loop_.RunAllPending();
659 } 664 }
660 665
661 } // namespace media 666 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698