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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback_helpers.h" | 6 #include "base/callback_helpers.h" |
7 #include "base/gtest_prod_util.h" | 7 #include "base/gtest_prod_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "media/base/audio_timestamp_helper.h" | 10 #include "media/base/audio_timestamp_helper.h" |
11 #include "media/base/data_buffer.h" | 11 #include "media/base/data_buffer.h" |
12 #include "media/base/gmock_callback_support.h" | 12 #include "media/base/gmock_callback_support.h" |
13 #include "media/base/mock_audio_renderer_sink.h" | 13 #include "media/base/mock_audio_renderer_sink.h" |
14 #include "media/base/mock_filters.h" | 14 #include "media/base/mock_filters.h" |
15 #include "media/base/test_helpers.h" | 15 #include "media/base/test_helpers.h" |
16 #include "media/filters/audio_renderer_impl.h" | 16 #include "media/filters/audio_renderer_impl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 using ::testing::_; | 19 using ::testing::_; |
20 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
21 using ::testing::Invoke; | 21 using ::testing::Invoke; |
22 using ::testing::Return; | 22 using ::testing::Return; |
| 23 using ::testing::ReturnRef; |
23 using ::testing::NiceMock; | 24 using ::testing::NiceMock; |
24 using ::testing::StrictMock; | 25 using ::testing::StrictMock; |
25 | 26 |
26 namespace media { | 27 namespace media { |
27 | 28 |
28 // Constants for distinguishing between muted audio and playing audio when using | 29 // Constants for distinguishing between muted audio and playing audio when using |
29 // ConsumeBufferedData(). | 30 // ConsumeBufferedData(). |
30 static uint8 kMutedAudio = 0x00; | 31 static uint8 kMutedAudio = 0x00; |
31 static uint8 kPlayingAudio = 0x99; | 32 static uint8 kPlayingAudio = 0x99; |
32 | 33 |
33 class AudioRendererImplTest : public ::testing::Test { | 34 class AudioRendererImplTest : public ::testing::Test { |
34 public: | 35 public: |
35 // Give the decoder some non-garbage media properties. | 36 // Give the decoder some non-garbage media properties. |
36 AudioRendererImplTest() | 37 AudioRendererImplTest() |
37 : renderer_(new AudioRendererImpl(new NiceMock<MockAudioRendererSink>())), | 38 : renderer_(new AudioRendererImpl(new NiceMock<MockAudioRendererSink>(), |
| 39 SetDecryptorReadyCB())), |
38 demuxer_stream_(new MockDemuxerStream()), | 40 demuxer_stream_(new MockDemuxerStream()), |
39 decoder_(new MockAudioDecoder()) { | 41 decoder_(new MockAudioDecoder()), |
| 42 audio_config_(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, |
| 43 44100, NULL, 0, false) { |
40 EXPECT_CALL(*demuxer_stream_, type()) | 44 EXPECT_CALL(*demuxer_stream_, type()) |
41 .WillRepeatedly(Return(DemuxerStream::AUDIO)); | 45 .WillRepeatedly(Return(DemuxerStream::AUDIO)); |
| 46 EXPECT_CALL(*demuxer_stream_, audio_decoder_config()) |
| 47 .WillRepeatedly(ReturnRef(audio_config_)); |
42 | 48 |
43 // Queue all reads from the decoder by default. | 49 // Queue all reads from the decoder by default. |
44 ON_CALL(*decoder_, Read(_)) | 50 ON_CALL(*decoder_, Read(_)) |
45 .WillByDefault(Invoke(this, &AudioRendererImplTest::SaveReadCallback)); | 51 .WillByDefault(Invoke(this, &AudioRendererImplTest::SaveReadCallback)); |
46 | 52 |
47 // Set up audio properties. | 53 // Set up audio properties. |
48 SetSupportedAudioDecoderProperties(); | 54 SetSupportedAudioDecoderProperties(); |
49 EXPECT_CALL(*decoder_, bits_per_channel()) | 55 EXPECT_CALL(*decoder_, bits_per_channel()) |
50 .Times(AnyNumber()); | 56 .Times(AnyNumber()); |
51 EXPECT_CALL(*decoder_, channel_layout()) | 57 EXPECT_CALL(*decoder_, channel_layout()) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 renderer_->ResumeAfterUnderflow(false); | 235 renderer_->ResumeAfterUnderflow(false); |
230 } | 236 } |
231 | 237 |
232 // Fixture members. | 238 // Fixture members. |
233 scoped_refptr<AudioRendererImpl> renderer_; | 239 scoped_refptr<AudioRendererImpl> renderer_; |
234 scoped_refptr<MockDemuxerStream> demuxer_stream_; | 240 scoped_refptr<MockDemuxerStream> demuxer_stream_; |
235 scoped_refptr<MockAudioDecoder> decoder_; | 241 scoped_refptr<MockAudioDecoder> decoder_; |
236 AudioRendererImpl::AudioDecoderList decoders_; | 242 AudioRendererImpl::AudioDecoderList decoders_; |
237 AudioDecoder::ReadCB read_cb_; | 243 AudioDecoder::ReadCB read_cb_; |
238 scoped_ptr<AudioTimestampHelper> next_timestamp_; | 244 scoped_ptr<AudioTimestampHelper> next_timestamp_; |
| 245 AudioDecoderConfig audio_config_; |
239 MessageLoop message_loop_; | 246 MessageLoop message_loop_; |
240 | 247 |
241 private: | 248 private: |
242 void SaveReadCallback(const AudioDecoder::ReadCB& callback) { | 249 void SaveReadCallback(const AudioDecoder::ReadCB& callback) { |
243 CHECK(read_cb_.is_null()) << "Overlapping reads are not permitted"; | 250 CHECK(read_cb_.is_null()) << "Overlapping reads are not permitted"; |
244 read_cb_ = callback; | 251 read_cb_ = callback; |
245 } | 252 } |
246 | 253 |
247 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); | 254 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); |
248 }; | 255 }; |
(...skipping 11 matching lines...) Expand all Loading... |
260 | 267 |
261 TEST_F(AudioRendererImplTest, Initialize_Successful) { | 268 TEST_F(AudioRendererImplTest, Initialize_Successful) { |
262 Initialize(); | 269 Initialize(); |
263 | 270 |
264 // We should have no reads. | 271 // We should have no reads. |
265 EXPECT_TRUE(read_cb_.is_null()); | 272 EXPECT_TRUE(read_cb_.is_null()); |
266 } | 273 } |
267 | 274 |
268 TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) { | 275 TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) { |
269 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 276 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
270 .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE)); | 277 .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)); |
271 InitializeWithStatus(PIPELINE_ERROR_DECODE); | 278 InitializeWithStatus(DECODER_ERROR_NOT_SUPPORTED); |
272 | 279 |
273 // We should have no reads. | 280 // We should have no reads. |
274 EXPECT_TRUE(read_cb_.is_null()); | 281 EXPECT_TRUE(read_cb_.is_null()); |
275 } | 282 } |
276 | 283 |
277 TEST_F(AudioRendererImplTest, Initialize_MultipleDecoders) { | 284 TEST_F(AudioRendererImplTest, Initialize_MultipleDecoders) { |
278 scoped_refptr<MockAudioDecoder> decoder1 = new MockAudioDecoder(); | 285 scoped_refptr<MockAudioDecoder> decoder1 = new MockAudioDecoder(); |
279 // Insert |decoder1| as the first decoder in the list. | 286 // Insert |decoder1| as the first decoder in the list. |
280 decoders_.push_front(decoder1); | 287 decoders_.push_front(decoder1); |
281 EXPECT_CALL(*decoder1, Initialize(_, _, _)) | 288 EXPECT_CALL(*decoder1, Initialize(_, _, _)) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 EXPECT_TRUE(ConsumeBufferedData(bytes_buffered() / 2, NULL)); | 482 EXPECT_TRUE(ConsumeBufferedData(bytes_buffered() / 2, NULL)); |
476 | 483 |
477 renderer_->Pause(NewExpectedClosure()); | 484 renderer_->Pause(NewExpectedClosure()); |
478 | 485 |
479 AbortPendingRead(); | 486 AbortPendingRead(); |
480 | 487 |
481 Preroll(base::TimeDelta::FromSeconds(1)); | 488 Preroll(base::TimeDelta::FromSeconds(1)); |
482 } | 489 } |
483 | 490 |
484 } // namespace media | 491 } // namespace media |
OLD | NEW |