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/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "media/base/audio_buffer_converter.h" | 10 #include "media/base/audio_buffer_converter.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 hardware_config_, | 99 hardware_config_, |
100 new MediaLog())); | 100 new MediaLog())); |
101 } | 101 } |
102 | 102 |
103 virtual ~AudioRendererImplTest() { | 103 virtual ~AudioRendererImplTest() { |
104 SCOPED_TRACE("~AudioRendererImplTest()"); | 104 SCOPED_TRACE("~AudioRendererImplTest()"); |
105 } | 105 } |
106 | 106 |
107 void ExpectUnsupportedAudioDecoder() { | 107 void ExpectUnsupportedAudioDecoder() { |
108 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 108 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
109 .WillOnce(DoAll(SaveArg<2>(&output_cb_), | 109 .WillOnce(DoAll(SaveArg<2>(&output_cb_), RunCallback<1>(false))); |
110 RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED))); | |
111 } | 110 } |
112 | 111 |
113 MOCK_METHOD1(OnStatistics, void(const PipelineStatistics&)); | 112 MOCK_METHOD1(OnStatistics, void(const PipelineStatistics&)); |
114 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); | 113 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); |
115 MOCK_METHOD1(OnError, void(PipelineStatus)); | 114 MOCK_METHOD1(OnError, void(PipelineStatus)); |
116 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 115 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
117 | 116 |
118 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { | 117 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { |
119 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 118 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
120 renderer_->Initialize( | 119 renderer_->Initialize( |
121 &demuxer_stream_, pipeline_status_cb, SetDecryptorReadyCB(), | 120 &demuxer_stream_, pipeline_status_cb, SetDecryptorReadyCB(), |
122 base::Bind(&AudioRendererImplTest::OnStatistics, | 121 base::Bind(&AudioRendererImplTest::OnStatistics, |
123 base::Unretained(this)), | 122 base::Unretained(this)), |
124 base::Bind(&AudioRendererImplTest::OnBufferingStateChange, | 123 base::Bind(&AudioRendererImplTest::OnBufferingStateChange, |
125 base::Unretained(this)), | 124 base::Unretained(this)), |
126 base::Bind(&AudioRendererImplTest::OnEnded, base::Unretained(this)), | 125 base::Bind(&AudioRendererImplTest::OnEnded, base::Unretained(this)), |
127 base::Bind(&AudioRendererImplTest::OnError, base::Unretained(this)), | 126 base::Bind(&AudioRendererImplTest::OnError, base::Unretained(this)), |
128 base::Bind(&AudioRendererImplTest::OnWaitingForDecryptionKey, | 127 base::Bind(&AudioRendererImplTest::OnWaitingForDecryptionKey, |
129 base::Unretained(this))); | 128 base::Unretained(this))); |
130 } | 129 } |
131 | 130 |
132 void Initialize() { | 131 void Initialize() { |
133 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 132 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
134 .WillOnce(DoAll(SaveArg<2>(&output_cb_), | 133 .WillOnce(DoAll(SaveArg<2>(&output_cb_), RunCallback<1>(true))); |
135 RunCallback<1>(PIPELINE_OK))); | |
136 InitializeWithStatus(PIPELINE_OK); | 134 InitializeWithStatus(PIPELINE_OK); |
137 | 135 |
138 next_timestamp_.reset(new AudioTimestampHelper(kInputSamplesPerSecond)); | 136 next_timestamp_.reset(new AudioTimestampHelper(kInputSamplesPerSecond)); |
139 } | 137 } |
140 | 138 |
141 void InitializeWithStatus(PipelineStatus expected) { | 139 void InitializeWithStatus(PipelineStatus expected) { |
142 SCOPED_TRACE(base::StringPrintf("InitializeWithStatus(%d)", expected)); | 140 SCOPED_TRACE(base::StringPrintf("InitializeWithStatus(%d)", expected)); |
143 | 141 |
144 WaitableMessageLoopEvent event; | 142 WaitableMessageLoopEvent event; |
145 InitializeRenderer(event.GetPipelineStatusCB()); | 143 InitializeRenderer(event.GetPipelineStatusCB()); |
146 event.RunAndWaitForStatus(expected); | 144 event.RunAndWaitForStatus(expected); |
147 | 145 |
148 // We should have no reads. | 146 // We should have no reads. |
149 EXPECT_TRUE(decode_cb_.is_null()); | 147 EXPECT_TRUE(decode_cb_.is_null()); |
150 } | 148 } |
151 | 149 |
152 void InitializeAndDestroy() { | 150 void InitializeAndDestroy() { |
153 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 151 EXPECT_CALL(*decoder_, Initialize(_, _, _)).WillOnce(RunCallback<1>(true)); |
154 .WillOnce(RunCallback<1>(PIPELINE_OK)); | |
155 | 152 |
156 WaitableMessageLoopEvent event; | 153 WaitableMessageLoopEvent event; |
157 InitializeRenderer(event.GetPipelineStatusCB()); | 154 InitializeRenderer(event.GetPipelineStatusCB()); |
158 | 155 |
159 // Destroy the |renderer_| before we let the MessageLoop run, this simulates | 156 // Destroy the |renderer_| before we let the MessageLoop run, this simulates |
160 // an interleaving in which we end up destroying the |renderer_| while the | 157 // an interleaving in which we end up destroying the |renderer_| while the |
161 // OnDecoderSelected callback is in flight. | 158 // OnDecoderSelected callback is in flight. |
162 renderer_.reset(); | 159 renderer_.reset(); |
163 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT); | 160 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT); |
164 } | 161 } |
165 | 162 |
166 void InitializeAndDestroyDuringDecoderInit() { | 163 void InitializeAndDestroyDuringDecoderInit() { |
167 EXPECT_CALL(*decoder_, Initialize(_, _, _)) | 164 EXPECT_CALL(*decoder_, Initialize(_, _, _)) |
168 .WillOnce(EnterPendingDecoderInitStateAction(this)); | 165 .WillOnce(EnterPendingDecoderInitStateAction(this)); |
169 | 166 |
170 WaitableMessageLoopEvent event; | 167 WaitableMessageLoopEvent event; |
171 InitializeRenderer(event.GetPipelineStatusCB()); | 168 InitializeRenderer(event.GetPipelineStatusCB()); |
172 base::RunLoop().RunUntilIdle(); | 169 base::RunLoop().RunUntilIdle(); |
173 DCHECK(!init_decoder_cb_.is_null()); | 170 DCHECK(!init_decoder_cb_.is_null()); |
174 | 171 |
175 renderer_.reset(); | 172 renderer_.reset(); |
176 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT); | 173 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT); |
177 } | 174 } |
178 | 175 |
179 void EnterPendingDecoderInitState(PipelineStatusCB cb) { | 176 void EnterPendingDecoderInitState(const AudioDecoder::InitCB& cb) { |
180 init_decoder_cb_ = cb; | 177 init_decoder_cb_ = cb; |
181 } | 178 } |
182 | 179 |
183 void FlushDuringPendingRead() { | 180 void FlushDuringPendingRead() { |
184 SCOPED_TRACE("FlushDuringPendingRead()"); | 181 SCOPED_TRACE("FlushDuringPendingRead()"); |
185 WaitableMessageLoopEvent flush_event; | 182 WaitableMessageLoopEvent flush_event; |
186 renderer_->Flush(flush_event.GetClosure()); | 183 renderer_->Flush(flush_event.GetClosure()); |
187 SatisfyPendingRead(InputFrames(256)); | 184 SatisfyPendingRead(InputFrames(256)); |
188 flush_event.RunAndWait(); | 185 flush_event.RunAndWait(); |
189 | 186 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 388 |
392 // Used for satisfying reads. | 389 // Used for satisfying reads. |
393 AudioDecoder::OutputCB output_cb_; | 390 AudioDecoder::OutputCB output_cb_; |
394 AudioDecoder::DecodeCB decode_cb_; | 391 AudioDecoder::DecodeCB decode_cb_; |
395 base::Closure reset_cb_; | 392 base::Closure reset_cb_; |
396 scoped_ptr<AudioTimestampHelper> next_timestamp_; | 393 scoped_ptr<AudioTimestampHelper> next_timestamp_; |
397 | 394 |
398 // Run during DecodeDecoder() to unblock WaitForPendingRead(). | 395 // Run during DecodeDecoder() to unblock WaitForPendingRead(). |
399 base::Closure wait_for_pending_decode_cb_; | 396 base::Closure wait_for_pending_decode_cb_; |
400 | 397 |
401 PipelineStatusCB init_decoder_cb_; | 398 AudioDecoder::InitCB init_decoder_cb_; |
402 bool ended_; | 399 bool ended_; |
403 | 400 |
404 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); | 401 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); |
405 }; | 402 }; |
406 | 403 |
407 TEST_F(AudioRendererImplTest, Initialize_Successful) { | 404 TEST_F(AudioRendererImplTest, Initialize_Successful) { |
408 Initialize(); | 405 Initialize(); |
409 } | 406 } |
410 | 407 |
411 TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) { | 408 TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 // Start rendering with zero playback rate. Sink should be paused until | 743 // Start rendering with zero playback rate. Sink should be paused until |
747 // non-zero rate is set. | 744 // non-zero rate is set. |
748 renderer_->SetPlaybackRate(0.0); | 745 renderer_->SetPlaybackRate(0.0); |
749 renderer_->StartTicking(); | 746 renderer_->StartTicking(); |
750 EXPECT_EQ(FakeAudioRendererSink::kPaused, sink_->state()); | 747 EXPECT_EQ(FakeAudioRendererSink::kPaused, sink_->state()); |
751 renderer_->SetPlaybackRate(1.0); | 748 renderer_->SetPlaybackRate(1.0); |
752 EXPECT_EQ(FakeAudioRendererSink::kPlaying, sink_->state()); | 749 EXPECT_EQ(FakeAudioRendererSink::kPlaying, sink_->state()); |
753 } | 750 } |
754 | 751 |
755 } // namespace media | 752 } // namespace media |
OLD | NEW |