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

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

Issue 11144036: Update Decryptor interface to support audio decoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove leftover unretained Created 8 years, 2 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
« no previous file with comments | « media/filters/ffmpeg_video_decoder.cc ('k') | webkit/media/crypto/ppapi/clear_key_cdm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 encrypted_frame_offset, 56 encrypted_frame_offset,
57 std::vector<SubsampleEntry>()))); 57 std::vector<SubsampleEntry>())));
58 return buffer; 58 return buffer;
59 } 59 }
60 60
61 ACTION_P(ReturnBuffer, buffer) { 61 ACTION_P(ReturnBuffer, buffer) {
62 arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); 62 arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
63 } 63 }
64 64
65 ACTION_P2(RunDecryptCB, status, buffer) { 65 ACTION_P2(RunDecryptCB, status, buffer) {
66 arg1.Run(status, buffer); 66 arg2.Run(status, buffer);
67 } 67 }
68 68
69 class FFmpegVideoDecoderTest : public testing::Test { 69 class FFmpegVideoDecoderTest : public testing::Test {
70 public: 70 public:
71 FFmpegVideoDecoderTest() 71 FFmpegVideoDecoderTest()
72 : decryptor_(new MockDecryptor()), 72 : decryptor_(new MockDecryptor()),
73 decoder_(NULL), 73 decoder_(NULL),
74 demuxer_(new StrictMock<MockDemuxerStream>()), 74 demuxer_(new StrictMock<MockDemuxerStream>()),
75 read_cb_(base::Bind(&FFmpegVideoDecoderTest::FrameReady, 75 read_cb_(base::Bind(&FFmpegVideoDecoderTest::FrameReady,
76 base::Unretained(this))) { 76 base::Unretained(this))) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 base::Bind(&MockStatisticsCB::OnStatistics, 116 base::Bind(&MockStatisticsCB::OnStatistics,
117 base::Unretained(&statistics_cb_))); 117 base::Unretained(&statistics_cb_)));
118 118
119 message_loop_.RunAllPending(); 119 message_loop_.RunAllPending();
120 } 120 }
121 121
122 void InitializeWithConfig(const VideoDecoderConfig& config) { 122 void InitializeWithConfig(const VideoDecoderConfig& config) {
123 InitializeWithConfigAndStatus(config, PIPELINE_OK); 123 InitializeWithConfigAndStatus(config, PIPELINE_OK);
124 } 124 }
125 125
126 void CancelDecrypt() { 126 void CancelDecrypt(Decryptor::StreamType stream_type) {
127 if (!decrypt_cb_.is_null()) { 127 if (!decrypt_cb_.is_null()) {
128 base::ResetAndReturn(&decrypt_cb_).Run( 128 base::ResetAndReturn(&decrypt_cb_).Run(
129 Decryptor::kError, scoped_refptr<DecoderBuffer>(NULL)); 129 Decryptor::kError, scoped_refptr<DecoderBuffer>(NULL));
130 } 130 }
131 } 131 }
132 132
133 void Reset() { 133 void Reset() {
134 EXPECT_CALL(*decryptor_, CancelDecrypt()) 134 EXPECT_CALL(*decryptor_, CancelDecrypt(Decryptor::kVideo))
135 .WillOnce(Invoke(this, &FFmpegVideoDecoderTest::CancelDecrypt)); 135 .WillOnce(Invoke(this, &FFmpegVideoDecoderTest::CancelDecrypt));
136 decoder_->Reset(NewExpectedClosure()); 136 decoder_->Reset(NewExpectedClosure());
137 message_loop_.RunAllPending(); 137 message_loop_.RunAllPending();
138 } 138 }
139 139
140 void Stop() { 140 void Stop() {
141 // Use AtMost(1) here because CancelDecrypt() will be called once if the 141 // Use AtMost(1) here because CancelDecrypt() will be called once if the
142 // decoder was initialized and has not been stopped, and will not be 142 // decoder was initialized and has not been stopped, and will not be
143 // called otherwise. 143 // called otherwise.
144 EXPECT_CALL(*decryptor_, CancelDecrypt()) 144 EXPECT_CALL(*decryptor_, CancelDecrypt(Decryptor::kVideo))
145 .Times(AtMost(1)) 145 .Times(AtMost(1))
146 .WillRepeatedly(Invoke(this, &FFmpegVideoDecoderTest::CancelDecrypt)); 146 .WillRepeatedly(Invoke(this, &FFmpegVideoDecoderTest::CancelDecrypt));
147 decoder_->Stop(NewExpectedClosure()); 147 decoder_->Stop(NewExpectedClosure());
148 message_loop_.RunAllPending(); 148 message_loop_.RunAllPending();
149 } 149 }
150 150
151 // Sets up expectations and actions to put FFmpegVideoDecoder in an active 151 // Sets up expectations and actions to put FFmpegVideoDecoder in an active
152 // decoding state. 152 // decoding state.
153 void EnterDecodingState() { 153 void EnterDecodingState() {
154 VideoDecoder::Status status; 154 VideoDecoder::Status status;
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify 460 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify
461 // the output size was adjusted. 461 // the output size was adjusted.
462 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) { 462 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) {
463 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120); 463 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120);
464 } 464 }
465 465
466 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) { 466 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) {
467 InitializeWithEncryptedConfig(); 467 InitializeWithEncryptedConfig();
468 468
469 // Simulate decoding a single encrypted frame. 469 // Simulate decoding a single encrypted frame.
470 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 470 EXPECT_CALL(*decryptor_,
471 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
471 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_)); 472 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_));
472 473
473 VideoDecoder::Status status; 474 VideoDecoder::Status status;
474 scoped_refptr<VideoFrame> video_frame; 475 scoped_refptr<VideoFrame> video_frame;
475 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame); 476 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame);
476 477
477 EXPECT_EQ(VideoDecoder::kOk, status); 478 EXPECT_EQ(VideoDecoder::kOk, status);
478 ASSERT_TRUE(video_frame); 479 ASSERT_TRUE(video_frame);
479 EXPECT_FALSE(video_frame->IsEndOfStream()); 480 EXPECT_FALSE(video_frame->IsEndOfStream());
480 } 481 }
481 482
482 // Test the case that the decryptor fails to decrypt the encrypted buffer. 483 // Test the case that the decryptor fails to decrypt the encrypted buffer.
483 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) { 484 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) {
484 InitializeWithEncryptedConfig(); 485 InitializeWithEncryptedConfig();
485 486
486 // Simulate decoding a single encrypted frame. 487 // Simulate decoding a single encrypted frame.
487 EXPECT_CALL(*demuxer_, Read(_)) 488 EXPECT_CALL(*demuxer_, Read(_))
488 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 489 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
489 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 490 EXPECT_CALL(*decryptor_,
491 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
490 .WillRepeatedly(RunDecryptCB(Decryptor::kError, 492 .WillRepeatedly(RunDecryptCB(Decryptor::kError,
491 scoped_refptr<media::DecoderBuffer>())); 493 scoped_refptr<media::DecoderBuffer>()));
492 494
493 // Our read should still get satisfied with end of stream frame during an 495 // Our read should still get satisfied with end of stream frame during an
494 // error. 496 // error.
495 VideoDecoder::Status status; 497 VideoDecoder::Status status;
496 scoped_refptr<VideoFrame> video_frame; 498 scoped_refptr<VideoFrame> video_frame;
497 Read(&status, &video_frame); 499 Read(&status, &video_frame);
498 EXPECT_EQ(VideoDecoder::kDecryptError, status); 500 EXPECT_EQ(VideoDecoder::kDecryptError, status);
499 EXPECT_FALSE(video_frame); 501 EXPECT_FALSE(video_frame);
500 502
501 message_loop_.RunAllPending(); 503 message_loop_.RunAllPending();
502 } 504 }
503 505
504 // Test the case that the decryptor has no key to decrypt the encrypted buffer. 506 // Test the case that the decryptor has no key to decrypt the encrypted buffer.
505 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) { 507 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) {
506 InitializeWithEncryptedConfig(); 508 InitializeWithEncryptedConfig();
507 509
508 // Simulate decoding a single encrypted frame. 510 // Simulate decoding a single encrypted frame.
509 EXPECT_CALL(*demuxer_, Read(_)) 511 EXPECT_CALL(*demuxer_, Read(_))
510 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 512 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
511 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 513 EXPECT_CALL(*decryptor_,
514 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
512 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, 515 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey,
513 scoped_refptr<media::DecoderBuffer>())); 516 scoped_refptr<media::DecoderBuffer>()));
514 517
515 // Our read should still get satisfied with end of stream frame during an 518 // Our read should still get satisfied with end of stream frame during an
516 // error. 519 // error.
517 VideoDecoder::Status status; 520 VideoDecoder::Status status;
518 scoped_refptr<VideoFrame> video_frame; 521 scoped_refptr<VideoFrame> video_frame;
519 Read(&status, &video_frame); 522 Read(&status, &video_frame);
520 EXPECT_EQ(VideoDecoder::kDecryptError, status); 523 EXPECT_EQ(VideoDecoder::kDecryptError, status);
521 EXPECT_FALSE(video_frame); 524 EXPECT_FALSE(video_frame);
522 525
523 message_loop_.RunAllPending(); 526 message_loop_.RunAllPending();
524 } 527 }
525 528
526 // Test the case that the decryptor fails to decrypt the encrypted buffer but 529 // Test the case that the decryptor fails to decrypt the encrypted buffer but
527 // cannot detect the decryption error and returns a corrupted buffer. 530 // cannot detect the decryption error and returns a corrupted buffer.
528 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) { 531 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) {
529 InitializeWithEncryptedConfig(); 532 InitializeWithEncryptedConfig();
530 533
531 // Simulate decoding a single encrypted frame. 534 // Simulate decoding a single encrypted frame.
532 EXPECT_CALL(*demuxer_, Read(_)) 535 EXPECT_CALL(*demuxer_, Read(_))
533 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 536 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
534 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 537 EXPECT_CALL(*decryptor_,
538 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
535 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, 539 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess,
536 corrupt_i_frame_buffer_)); 540 corrupt_i_frame_buffer_));
537 // The decoder only detects the error at the second decoding call. So 541 // The decoder only detects the error at the second decoding call. So
538 // |statistics_cb_| still gets called once. 542 // |statistics_cb_| still gets called once.
539 EXPECT_CALL(statistics_cb_, OnStatistics(_)); 543 EXPECT_CALL(statistics_cb_, OnStatistics(_));
540 544
541 // Our read should still get satisfied with end of stream frame during an 545 // Our read should still get satisfied with end of stream frame during an
542 // error. 546 // error.
543 VideoDecoder::Status status; 547 VideoDecoder::Status status;
544 scoped_refptr<VideoFrame> video_frame; 548 scoped_refptr<VideoFrame> video_frame;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 read_cb.Run(DemuxerStream::kOk, i_frame_buffer_); 597 read_cb.Run(DemuxerStream::kOk, i_frame_buffer_);
594 message_loop_.RunAllPending(); 598 message_loop_.RunAllPending();
595 } 599 }
596 600
597 // Test resetting when there is a pending decrypt on the decryptor. 601 // Test resetting when there is a pending decrypt on the decryptor.
598 TEST_F(FFmpegVideoDecoderTest, Reset_DuringPendingDecrypt) { 602 TEST_F(FFmpegVideoDecoderTest, Reset_DuringPendingDecrypt) {
599 InitializeWithEncryptedConfig(); 603 InitializeWithEncryptedConfig();
600 604
601 EXPECT_CALL(*demuxer_, Read(_)) 605 EXPECT_CALL(*demuxer_, Read(_))
602 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 606 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
603 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 607 EXPECT_CALL(*decryptor_,
604 .WillOnce(SaveArg<1>(&decrypt_cb_)); 608 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
609 .WillOnce(SaveArg<2>(&decrypt_cb_));
605 610
606 decoder_->Read(read_cb_); 611 decoder_->Read(read_cb_);
607 message_loop_.RunAllPending(); 612 message_loop_.RunAllPending();
608 // Make sure the Read() on the decoder triggers a Decrypt() on the decryptor. 613 // Make sure the Read() on the decoder triggers a Decrypt() on the decryptor.
609 EXPECT_FALSE(decrypt_cb_.is_null()); 614 EXPECT_FALSE(decrypt_cb_.is_null());
610 615
611 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); 616 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull()));
612 Reset(); 617 Reset();
613 message_loop_.RunAllPending(); 618 message_loop_.RunAllPending();
614 } 619 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 read_cb.Run(DemuxerStream::kOk, i_frame_buffer_); 660 read_cb.Run(DemuxerStream::kOk, i_frame_buffer_);
656 message_loop_.RunAllPending(); 661 message_loop_.RunAllPending();
657 } 662 }
658 663
659 // Test stopping when there is a pending decrypt on the decryptor. 664 // Test stopping when there is a pending decrypt on the decryptor.
660 TEST_F(FFmpegVideoDecoderTest, Stop_DuringPendingDecrypt) { 665 TEST_F(FFmpegVideoDecoderTest, Stop_DuringPendingDecrypt) {
661 InitializeWithEncryptedConfig(); 666 InitializeWithEncryptedConfig();
662 667
663 EXPECT_CALL(*demuxer_, Read(_)) 668 EXPECT_CALL(*demuxer_, Read(_))
664 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 669 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
665 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 670 EXPECT_CALL(*decryptor_,
666 .WillOnce(SaveArg<1>(&decrypt_cb_)); 671 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
672 .WillOnce(SaveArg<2>(&decrypt_cb_));
667 673
668 decoder_->Read(read_cb_); 674 decoder_->Read(read_cb_);
669 message_loop_.RunAllPending(); 675 message_loop_.RunAllPending();
670 // Make sure the Read() on the decoder triggers a Decrypt() on the decryptor. 676 // Make sure the Read() on the decoder triggers a Decrypt() on the decryptor.
671 EXPECT_FALSE(decrypt_cb_.is_null()); 677 EXPECT_FALSE(decrypt_cb_.is_null());
672 678
673 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); 679 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull()));
674 Stop(); 680 Stop();
675 message_loop_.RunAllPending(); 681 message_loop_.RunAllPending();
676 } 682 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 716
711 // Signal an aborted demuxer read. 717 // Signal an aborted demuxer read.
712 read_cb.Run(DemuxerStream::kAborted, NULL); 718 read_cb.Run(DemuxerStream::kAborted, NULL);
713 719
714 // Make sure we get a NULL video frame returned. 720 // Make sure we get a NULL video frame returned.
715 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); 721 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull()));
716 message_loop_.RunAllPending(); 722 message_loop_.RunAllPending();
717 } 723 }
718 724
719 } // namespace media 725 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_video_decoder.cc ('k') | webkit/media/crypto/ppapi/clear_key_cdm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698