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