Index: media/filters/audio_renderer_impl_unittest.cc |
diff --git a/media/filters/audio_renderer_impl_unittest.cc b/media/filters/audio_renderer_impl_unittest.cc |
index 89c870b2be144a022c9f0b626ba750ef536e1a91..b10a981ae9a47cb31662fb91af23138663fc83cf 100644 |
--- a/media/filters/audio_renderer_impl_unittest.cc |
+++ b/media/filters/audio_renderer_impl_unittest.cc |
@@ -27,46 +27,58 @@ namespace media { |
static uint8 kMutedAudio = 0x00; |
static uint8 kPlayingAudio = 0x99; |
+ACTION_P(RunPipelineStatusCB1, status) { |
+ arg1.Run(status); |
+} |
+ |
class AudioRendererImplTest : public ::testing::Test { |
public: |
- // Give the decoder some non-garbage media properties. |
AudioRendererImplTest() |
- : renderer_(new AudioRendererImpl(new NiceMock<MockAudioRendererSink>())), |
- decoder_(new MockAudioDecoder()) { |
+ : demuxer_stream_(new MockDemuxerStream()), |
+ decoder_(new MockAudioDecoder()), |
+ renderer_(new AudioRendererImpl( |
+ new NiceMock<MockAudioRendererSink>())) { |
+ |
+ EXPECT_CALL(*demuxer_stream_, type()) |
+ .WillRepeatedly(Return(DemuxerStream::AUDIO)); |
// Queue all reads from the decoder by default. |
ON_CALL(*decoder_, Read(_)) |
.WillByDefault(Invoke(this, &AudioRendererImplTest::SaveReadCallback)); |
// Set up audio properties. |
- SetSupportedAudioDecoderProperties(); |
+ SetSupportedAudioDecoderProperties(decoder_); |
EXPECT_CALL(*decoder_, bits_per_channel()) |
.Times(AnyNumber()); |
EXPECT_CALL(*decoder_, channel_layout()) |
.Times(AnyNumber()); |
EXPECT_CALL(*decoder_, samples_per_second()) |
.Times(AnyNumber()); |
+ |
+ decoders_.push_back(decoder_); |
} |
virtual ~AudioRendererImplTest() { |
renderer_->Stop(NewExpectedClosure()); |
} |
- void SetSupportedAudioDecoderProperties() { |
- ON_CALL(*decoder_, bits_per_channel()) |
+ void SetSupportedAudioDecoderProperties( |
+ const scoped_refptr<MockAudioDecoder>& decoder) { |
+ ON_CALL(*decoder, bits_per_channel()) |
.WillByDefault(Return(16)); |
- ON_CALL(*decoder_, channel_layout()) |
+ ON_CALL(*decoder, channel_layout()) |
.WillByDefault(Return(CHANNEL_LAYOUT_MONO)); |
- ON_CALL(*decoder_, samples_per_second()) |
+ ON_CALL(*decoder, samples_per_second()) |
.WillByDefault(Return(44100)); |
} |
- void SetUnsupportedAudioDecoderProperties() { |
- ON_CALL(*decoder_, bits_per_channel()) |
+ void SetUnsupportedAudioDecoderProperties( |
+ const scoped_refptr<MockAudioDecoder>& decoder) { |
+ ON_CALL(*decoder, bits_per_channel()) |
.WillByDefault(Return(3)); |
- ON_CALL(*decoder_, channel_layout()) |
+ ON_CALL(*decoder, channel_layout()) |
.WillByDefault(Return(CHANNEL_LAYOUT_UNSUPPORTED)); |
- ON_CALL(*decoder_, samples_per_second()) |
+ ON_CALL(*decoder, samples_per_second()) |
.WillByDefault(Return(0)); |
} |
@@ -76,6 +88,7 @@ class AudioRendererImplTest : public ::testing::Test { |
base::Unretained(this)); |
} |
+ MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics&)); |
MOCK_METHOD0(OnUnderflow, void()); |
MOCK_METHOD0(OnEnded, void()); |
MOCK_METHOD0(OnDisabled, void()); |
@@ -87,12 +100,16 @@ class AudioRendererImplTest : public ::testing::Test { |
} |
void Initialize() { |
+ EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
+ .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); |
InitializeWithStatus(PIPELINE_OK); |
} |
void InitializeWithStatus(PipelineStatus expected) { |
renderer_->Initialize( |
- decoder_, NewExpectedStatusCB(expected), |
+ demuxer_stream_, decoders_, NewExpectedStatusCB(expected), |
+ base::Bind(&AudioRendererImplTest::OnStatistics, |
+ base::Unretained(this)), |
base::Bind(&AudioRendererImplTest::OnUnderflow, |
base::Unretained(this)), |
base::Bind(&AudioRendererImplTest::OnAudioTimeCallback, |
@@ -206,11 +223,14 @@ class AudioRendererImplTest : public ::testing::Test { |
} |
// Fixture members. |
- scoped_refptr<AudioRendererImpl> renderer_; |
+ scoped_refptr<MockDemuxerStream> demuxer_stream_; |
scoped_refptr<MockAudioDecoder> decoder_; |
+ AudioRenderer::AudioDecoderList decoders_; |
+ scoped_refptr<AudioRendererImpl> renderer_; |
AudioDecoder::ReadCB read_cb_; |
base::TimeDelta next_timestamp_; |
+ |
private: |
void SaveReadCallback(const AudioDecoder::ReadCB& callback) { |
CHECK(read_cb_.is_null()) << "Overlapping reads are not permitted"; |
@@ -221,15 +241,54 @@ class AudioRendererImplTest : public ::testing::Test { |
}; |
TEST_F(AudioRendererImplTest, Initialize_Failed) { |
- SetUnsupportedAudioDecoderProperties(); |
+ scoped_refptr<StrictMock<MockAudioDecoder> > next_decoder = |
+ new StrictMock<MockAudioDecoder>(); |
+ decoders_.push_back(next_decoder); |
+ |
+ // First decoder reports catastrophic error: |next_decoder| shouldn't get |
+ // called. |
+ EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
+ .WillOnce(RunPipelineStatusCB1(PIPELINE_ERROR_DECODE)); |
+ InitializeWithStatus(PIPELINE_ERROR_DECODE); |
+ |
+ // We should have no reads. |
+ EXPECT_TRUE(read_cb_.is_null()); |
+} |
+ |
+TEST_F(AudioRendererImplTest, Initialize_UnsupportedProperties) { |
+ scoped_refptr<StrictMock<MockAudioDecoder> > next_decoder = |
+ new StrictMock<MockAudioDecoder>(); |
+ decoders_.push_back(next_decoder); |
+ |
+ // First decoder succeeds but with unsupported properties: |next_decoder| |
+ // shouldn't get called. |
+ EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
+ .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); |
+ SetUnsupportedAudioDecoderProperties(decoder_); |
+ |
InitializeWithStatus(PIPELINE_ERROR_INITIALIZATION_FAILED); |
// We should have no reads. |
EXPECT_TRUE(read_cb_.is_null()); |
} |
-TEST_F(AudioRendererImplTest, Initialize_Successful) { |
- Initialize(); |
+TEST_F(AudioRendererImplTest, Initialize_UseNextDecoder) { |
+ scoped_refptr<StrictMock<MockAudioDecoder> > next_decoder = |
+ new StrictMock<MockAudioDecoder>(); |
+ decoders_.push_back(next_decoder); |
+ |
+ // First decoder doesn't support the decoder config: |next_decoder| gets |
+ // initialized and queried for properties. |
+ EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
+ .WillOnce(RunPipelineStatusCB1(DECODER_ERROR_NOT_SUPPORTED)); |
+ EXPECT_CALL(*next_decoder, Initialize(_, _, _)) |
+ .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); |
+ EXPECT_CALL(*next_decoder, bits_per_channel()).Times(AnyNumber()); |
+ EXPECT_CALL(*next_decoder, channel_layout()).Times(AnyNumber()); |
+ EXPECT_CALL(*next_decoder, samples_per_second()).Times(AnyNumber()); |
+ SetSupportedAudioDecoderProperties(next_decoder); |
+ |
+ InitializeWithStatus(PIPELINE_OK); |
// We should have no reads. |
EXPECT_TRUE(read_cb_.is_null()); |