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

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

Issue 11342031: Add DecryptingDemuxerStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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/decrypting_audio_decoder.cc ('k') | media/filters/decrypting_demuxer_stream.h » ('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"
11 #include "media/base/buffers.h" 11 #include "media/base/buffers.h"
12 #include "media/base/data_buffer.h" 12 #include "media/base/data_buffer.h"
13 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
14 #include "media/base/decrypt_config.h" 14 #include "media/base/decrypt_config.h"
15 #include "media/base/gmock_callback_support.h" 15 #include "media/base/gmock_callback_support.h"
16 #include "media/base/mock_callback.h" 16 #include "media/base/mock_callback.h"
17 #include "media/base/mock_filters.h" 17 #include "media/base/mock_filters.h"
18 #include "media/filters/decrypting_audio_decoder.h" 18 #include "media/filters/decrypting_audio_decoder.h"
19 #include "media/filters/ffmpeg_decoder_unittest.h" 19 #include "media/filters/ffmpeg_decoder_unittest.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 21
22 using ::testing::_; 22 using ::testing::_;
23 using ::testing::AtMost; 23 using ::testing::AtMost;
24 using ::testing::Invoke;
25 using ::testing::IsNull; 24 using ::testing::IsNull;
26 using ::testing::ReturnRef; 25 using ::testing::ReturnRef;
27 using ::testing::SaveArg; 26 using ::testing::SaveArg;
28 using ::testing::StrictMock; 27 using ::testing::StrictMock;
29 28
30 namespace media { 29 namespace media {
31 30
32 static const int kFakeAudioFrameSize = 16; 31 static const int kFakeAudioFrameSize = 16;
33 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; 32 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 };
34 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; 33 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 };
(...skipping 30 matching lines...) Expand all
65 64
66 MATCHER(IsEndOfStream, "end of stream") { 65 MATCHER(IsEndOfStream, "end of stream") {
67 return (arg->IsEndOfStream()); 66 return (arg->IsEndOfStream());
68 } 67 }
69 68
70 } // namespace 69 } // namespace
71 70
72 class DecryptingAudioDecoderTest : public testing::Test { 71 class DecryptingAudioDecoderTest : public testing::Test {
73 public: 72 public:
74 DecryptingAudioDecoderTest() 73 DecryptingAudioDecoderTest()
75 : decoder_(new StrictMock<DecryptingAudioDecoder>( 74 : decoder_(new DecryptingAudioDecoder(
76 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, 75 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >,
77 message_loop_.message_loop_proxy()), 76 message_loop_.message_loop_proxy()),
78 base::Bind( 77 base::Bind(
79 &DecryptingAudioDecoderTest::RequestDecryptorNotification, 78 &DecryptingAudioDecoderTest::RequestDecryptorNotification,
80 base::Unretained(this)))), 79 base::Unretained(this)))),
81 decryptor_(new StrictMock<MockDecryptor>()), 80 decryptor_(new StrictMock<MockDecryptor>()),
82 demuxer_(new StrictMock<MockDemuxerStream>()), 81 demuxer_(new StrictMock<MockDemuxerStream>()),
83 encrypted_buffer_(CreateFakeEncryptedBuffer()), 82 encrypted_buffer_(CreateFakeEncryptedBuffer()),
84 decoded_frame_(NULL), 83 decoded_frame_(NULL),
85 end_of_stream_frame_(new DataBuffer(0)), 84 end_of_stream_frame_(new DataBuffer(0)),
86 decoded_frame_list_() { 85 decoded_frame_list_() {
87 // TODO(xhwang): Fix this after DataBuffer(data, size) is public. 86 scoped_refptr<DataBuffer> data_buffer = new DataBuffer(kFakeAudioFrameSize);
88 scoped_refptr<DataBuffer> buffer = new DataBuffer(kFakeAudioFrameSize); 87 data_buffer->SetDataSize(kFakeAudioFrameSize);
89 buffer->SetDataSize(kFakeAudioFrameSize); 88 // |decoded_frame_| contains random data.
90 decoded_frame_ = buffer; 89 decoded_frame_ = data_buffer;
91 decoded_frame_list_.push_back(decoded_frame_); 90 decoded_frame_list_.push_back(decoded_frame_);
92 } 91 }
93 92
94 void InitializeAndExpectStatus(const AudioDecoderConfig& config, 93 void InitializeAndExpectStatus(const AudioDecoderConfig& config,
95 PipelineStatus status) { 94 PipelineStatus status) {
96 EXPECT_CALL(*demuxer_, audio_decoder_config()) 95 EXPECT_CALL(*demuxer_, audio_decoder_config())
97 .WillRepeatedly(ReturnRef(config)); 96 .WillRepeatedly(ReturnRef(config));
98 97
99 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), 98 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status),
100 base::Bind(&MockStatisticsCB::OnStatistics, 99 base::Bind(&MockStatisticsCB::OnStatistics,
101 base::Unretained(&statistics_cb_))); 100 base::Unretained(&statistics_cb_)));
102 message_loop_.RunUntilIdle(); 101 message_loop_.RunUntilIdle();
103 } 102 }
104 103
105 void Initialize() { 104 void Initialize() {
106 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) 105 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _))
107 .Times(AtMost(1)) 106 .Times(AtMost(1))
108 .WillOnce(RunCallback<1>(true)); 107 .WillOnce(RunCallback<1>(true));
109 EXPECT_CALL(*this, RequestDecryptorNotification(_)) 108 EXPECT_CALL(*this, RequestDecryptorNotification(_))
110 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); 109 .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
111 EXPECT_CALL(*decryptor_, RegisterKeyAddedCB(Decryptor::kAudio, _)) 110 EXPECT_CALL(*decryptor_, RegisterKeyAddedCB(Decryptor::kAudio, _))
112 .WillOnce(SaveArg<1>(&key_added_cb_)); 111 .WillOnce(SaveArg<1>(&key_added_cb_));
113 112
114 config_.Initialize(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, 113 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100,
115 NULL, 0, true, true); 114 NULL, 0, true);
115 InitializeAndExpectStatus(config, PIPELINE_OK);
116 116
117 InitializeAndExpectStatus(config_, PIPELINE_OK);
118 EXPECT_EQ(16, decoder_->bits_per_channel()); 117 EXPECT_EQ(16, decoder_->bits_per_channel());
119 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, decoder_->channel_layout()); 118 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, decoder_->channel_layout());
120 EXPECT_EQ(44100, decoder_->samples_per_second()); 119 EXPECT_EQ(44100, decoder_->samples_per_second());
121 } 120 }
122 121
123 void ReadAndExpectFrameReadyWith( 122 void ReadAndExpectFrameReadyWith(
124 AudioDecoder::Status status, 123 AudioDecoder::Status status,
125 const scoped_refptr<Buffer>& audio_frame) { 124 const scoped_refptr<Buffer>& audio_frame) {
126 if (status != AudioDecoder::kOk) 125 if (status != AudioDecoder::kOk)
127 EXPECT_CALL(*this, FrameReady(status, IsNull())); 126 EXPECT_CALL(*this, FrameReady(status, IsNull()));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 base::Unretained(this))); 182 base::Unretained(this)));
184 message_loop_.RunUntilIdle(); 183 message_loop_.RunUntilIdle();
185 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the 184 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the
186 // decryptor. 185 // decryptor.
187 EXPECT_FALSE(pending_audio_decode_cb_.is_null()); 186 EXPECT_FALSE(pending_audio_decode_cb_.is_null());
188 } 187 }
189 188
190 void EnterWaitingForKeyState() { 189 void EnterWaitingForKeyState() {
191 EXPECT_CALL(*demuxer_, Read(_)) 190 EXPECT_CALL(*demuxer_, Read(_))
192 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); 191 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
193 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) 192 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _))
194 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, 193 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey,
195 Decryptor::AudioBuffers())); 194 Decryptor::AudioBuffers()));
196 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, 195 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
197 base::Unretained(this))); 196 base::Unretained(this)));
198 message_loop_.RunUntilIdle(); 197 message_loop_.RunUntilIdle();
199 } 198 }
200 199
201 void AbortPendingAudioDecodeCB() { 200 void AbortPendingAudioDecodeCB() {
202 if (!pending_audio_decode_cb_.is_null()) { 201 if (!pending_audio_decode_cb_.is_null()) {
203 base::ResetAndReturn(&pending_audio_decode_cb_).Run( 202 base::ResetAndReturn(&pending_audio_decode_cb_).Run(
(...skipping 10 matching lines...) Expand all
214 message_loop_.RunUntilIdle(); 213 message_loop_.RunUntilIdle();
215 } 214 }
216 215
217 MOCK_METHOD1(RequestDecryptorNotification, 216 MOCK_METHOD1(RequestDecryptorNotification,
218 void(const DecryptingAudioDecoder::DecryptorNotificationCB&)); 217 void(const DecryptingAudioDecoder::DecryptorNotificationCB&));
219 218
220 MOCK_METHOD2(FrameReady, void(AudioDecoder::Status, 219 MOCK_METHOD2(FrameReady, void(AudioDecoder::Status,
221 const scoped_refptr<Buffer>&)); 220 const scoped_refptr<Buffer>&));
222 221
223 MessageLoop message_loop_; 222 MessageLoop message_loop_;
224 scoped_refptr<StrictMock<DecryptingAudioDecoder> > decoder_; 223 scoped_refptr<DecryptingAudioDecoder> decoder_;
225 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; 224 scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
226 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; 225 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_;
227 MockStatisticsCB statistics_cb_; 226 MockStatisticsCB statistics_cb_;
228 AudioDecoderConfig config_;
229 227
230 DemuxerStream::ReadCB pending_demuxer_read_cb_; 228 DemuxerStream::ReadCB pending_demuxer_read_cb_;
231 Decryptor::DecoderInitCB pending_init_cb_; 229 Decryptor::DecoderInitCB pending_init_cb_;
232 Decryptor::KeyAddedCB key_added_cb_; 230 Decryptor::KeyAddedCB key_added_cb_;
233 Decryptor::AudioDecodeCB pending_audio_decode_cb_; 231 Decryptor::AudioDecodeCB pending_audio_decode_cb_;
234 232
235 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. 233 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|.
236 scoped_refptr<DecoderBuffer> encrypted_buffer_; 234 scoped_refptr<DecoderBuffer> encrypted_buffer_;
237 scoped_refptr<Buffer> decoded_frame_; 235 scoped_refptr<Buffer> decoded_frame_;
238 scoped_refptr<Buffer> end_of_stream_frame_; 236 scoped_refptr<Buffer> end_of_stream_frame_;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 EXPECT_CALL(*demuxer_, Read(_)) 468 EXPECT_CALL(*demuxer_, Read(_))
471 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, 469 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
472 scoped_refptr<DecoderBuffer>())); 470 scoped_refptr<DecoderBuffer>()));
473 471
474 // TODO(xhwang): Update this test when kConfigChanged is supported in 472 // TODO(xhwang): Update this test when kConfigChanged is supported in
475 // DecryptingAudioDecoder. 473 // DecryptingAudioDecoder.
476 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); 474 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL);
477 } 475 }
478 476
479 } // namespace media 477 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_audio_decoder.cc ('k') | media/filters/decrypting_demuxer_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698