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 <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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 void Initialize() { | 102 void Initialize() { |
103 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) | 103 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) |
104 .Times(AtMost(1)) | 104 .Times(AtMost(1)) |
105 .WillOnce(RunCallback<1>(true)); | 105 .WillOnce(RunCallback<1>(true)); |
106 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 106 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
107 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | 107 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); |
108 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 108 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
109 .WillOnce(SaveArg<1>(&key_added_cb_)); | 109 .WillOnce(SaveArg<1>(&key_added_cb_)); |
110 | 110 |
111 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, | 111 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
112 NULL, 0, true); | 112 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); |
113 InitializeAndExpectStatus(config, PIPELINE_OK); | 113 InitializeAndExpectStatus(config, PIPELINE_OK); |
114 | 114 |
115 EXPECT_EQ(16, decoder_->bits_per_channel()); | 115 EXPECT_EQ(config.bits_per_channel(), decoder_->bits_per_channel()); |
116 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, decoder_->channel_layout()); | 116 EXPECT_EQ(config.channel_layout(), decoder_->channel_layout()); |
117 EXPECT_EQ(44100, decoder_->samples_per_second()); | 117 EXPECT_EQ(config.samples_per_second(), decoder_->samples_per_second()); |
118 } | 118 } |
119 | 119 |
120 void ReadAndExpectFrameReadyWith( | 120 void ReadAndExpectFrameReadyWith( |
121 AudioDecoder::Status status, | 121 AudioDecoder::Status status, |
122 const scoped_refptr<Buffer>& audio_frame) { | 122 const scoped_refptr<Buffer>& audio_frame) { |
123 if (status != AudioDecoder::kOk) | 123 if (status != AudioDecoder::kOk) |
124 EXPECT_CALL(*this, FrameReady(status, IsNull())); | 124 EXPECT_CALL(*this, FrameReady(status, IsNull())); |
125 else if (audio_frame->IsEndOfStream()) | 125 else if (audio_frame->IsEndOfStream()) |
126 EXPECT_CALL(*this, FrameReady(status, IsEndOfStream())); | 126 EXPECT_CALL(*this, FrameReady(status, IsEndOfStream())); |
127 else | 127 else |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 private: | 236 private: |
237 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest); | 237 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest); |
238 }; | 238 }; |
239 | 239 |
240 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { | 240 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { |
241 Initialize(); | 241 Initialize(); |
242 } | 242 } |
243 | 243 |
244 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. | 244 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. |
245 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { | 245 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { |
246 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, | 246 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
247 NULL, 0, false); | 247 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, false); |
248 | 248 |
249 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 249 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
250 } | 250 } |
251 | 251 |
252 // Ensure decoder handles invalid audio configs without crashing. | 252 // Ensure decoder handles invalid audio configs without crashing. |
253 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { | 253 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { |
254 AudioDecoderConfig config(kUnknownAudioCodec, 0, CHANNEL_LAYOUT_STEREO, 0, | 254 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, |
255 NULL, 0, true); | 255 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true); |
256 | 256 |
257 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); | 257 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); |
258 } | 258 } |
259 | 259 |
260 // Ensure decoder handles unsupported audio configs without crashing. | 260 // Ensure decoder handles unsupported audio configs without crashing. |
261 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { | 261 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
262 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) | 262 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) |
263 .WillOnce(RunCallback<1>(false)); | 263 .WillOnce(RunCallback<1>(false)); |
264 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 264 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
265 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | 265 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); |
266 | 266 |
267 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, | 267 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
268 NULL, 0, true); | 268 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); |
269 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 269 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
270 } | 270 } |
271 | 271 |
272 // Test normal decrypt and decode case. | 272 // Test normal decrypt and decode case. |
273 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { | 273 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
274 Initialize(); | 274 Initialize(); |
275 EnterNormalDecodingState(); | 275 EnterNormalDecodingState(); |
276 } | 276 } |
277 | 277 |
278 // Test the case where the decryptor returns error when doing decrypt and | 278 // Test the case where the decryptor returns error when doing decrypt and |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 EXPECT_CALL(*demuxer_, Read(_)) | 465 EXPECT_CALL(*demuxer_, Read(_)) |
466 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, | 466 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, |
467 scoped_refptr<DecoderBuffer>())); | 467 scoped_refptr<DecoderBuffer>())); |
468 | 468 |
469 // TODO(xhwang): Update this test when kConfigChanged is supported in | 469 // TODO(xhwang): Update this test when kConfigChanged is supported in |
470 // DecryptingAudioDecoder. | 470 // DecryptingAudioDecoder. |
471 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); | 471 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); |
472 } | 472 } |
473 | 473 |
474 } // namespace media | 474 } // namespace media |
OLD | NEW |