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 "media/filters/audio_renderer_impl.h" | 5 #include "media/filters/audio_renderer_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 140 } |
141 | 141 |
142 void AudioRendererImpl::DoFlush_Locked() { | 142 void AudioRendererImpl::DoFlush_Locked() { |
143 DCHECK(task_runner_->BelongsToCurrentThread()); | 143 DCHECK(task_runner_->BelongsToCurrentThread()); |
144 lock_.AssertAcquired(); | 144 lock_.AssertAcquired(); |
145 | 145 |
146 DCHECK(!pending_read_); | 146 DCHECK(!pending_read_); |
147 DCHECK_EQ(state_, kPaused); | 147 DCHECK_EQ(state_, kPaused); |
148 | 148 |
149 if (decrypting_demuxer_stream_) { | 149 if (decrypting_demuxer_stream_) { |
150 decrypting_demuxer_stream_->Reset( | 150 decrypting_demuxer_stream_->Reset(BindToCurrentLoop( |
151 base::Bind(&AudioRendererImpl::ResetDecoder, weak_this_)); | 151 base::Bind(&AudioRendererImpl::ResetDecoder, weak_this_))); |
152 return; | 152 return; |
153 } | 153 } |
154 | 154 |
155 ResetDecoder(); | 155 ResetDecoder(); |
156 } | 156 } |
157 | 157 |
158 void AudioRendererImpl::ResetDecoder() { | 158 void AudioRendererImpl::ResetDecoder() { |
159 DCHECK(task_runner_->BelongsToCurrentThread()); | 159 DCHECK(task_runner_->BelongsToCurrentThread()); |
160 decoder_->Reset(base::Bind(&AudioRendererImpl::ResetDecoderDone, weak_this_)); | 160 decoder_->Reset(BindToCurrentLoop( |
| 161 base::Bind(&AudioRendererImpl::ResetDecoderDone, weak_this_))); |
161 } | 162 } |
162 | 163 |
163 void AudioRendererImpl::ResetDecoderDone() { | 164 void AudioRendererImpl::ResetDecoderDone() { |
164 DCHECK(task_runner_->BelongsToCurrentThread()); | 165 base::AutoLock auto_lock(lock_); |
165 { | 166 if (state_ == kStopped) |
166 base::AutoLock auto_lock(lock_); | 167 return; |
167 if (state_ == kStopped) | |
168 return; | |
169 | 168 |
170 DCHECK_EQ(state_, kPaused); | 169 DCHECK_EQ(state_, kPaused); |
171 DCHECK(!flush_cb_.is_null()); | 170 DCHECK(!flush_cb_.is_null()); |
172 | 171 |
173 audio_time_buffered_ = kNoTimestamp(); | 172 audio_time_buffered_ = kNoTimestamp(); |
174 current_time_ = kNoTimestamp(); | 173 current_time_ = kNoTimestamp(); |
175 received_end_of_stream_ = false; | 174 received_end_of_stream_ = false; |
176 rendered_end_of_stream_ = false; | 175 rendered_end_of_stream_ = false; |
177 preroll_aborted_ = false; | 176 preroll_aborted_ = false; |
178 | 177 |
179 earliest_end_time_ = now_cb_.Run(); | 178 earliest_end_time_ = now_cb_.Run(); |
180 splicer_->Reset(); | 179 splicer_->Reset(); |
181 algorithm_->FlushBuffers(); | 180 algorithm_->FlushBuffers(); |
182 } | 181 |
183 base::ResetAndReturn(&flush_cb_).Run(); | 182 base::ResetAndReturn(&flush_cb_).Run(); |
184 } | 183 } |
185 | 184 |
186 void AudioRendererImpl::StopDecoderDone() { | |
187 DCHECK(task_runner_->BelongsToCurrentThread()); | |
188 { | |
189 base::AutoLock auto_lock(lock_); | |
190 if (state_ == kStopped) | |
191 return; | |
192 | |
193 DCHECK(!stop_cb_.is_null()); | |
194 DCHECK(init_cb_.is_null()); | |
195 | |
196 ChangeState_Locked(kStopped); | |
197 algorithm_.reset(); | |
198 init_cb_.Reset(); | |
199 underflow_cb_.Reset(); | |
200 time_cb_.Reset(); | |
201 flush_cb_.Reset(); | |
202 } | |
203 base::ResetAndReturn(&stop_cb_).Run(); | |
204 } | |
205 | |
206 void AudioRendererImpl::Stop(const base::Closure& callback) { | 185 void AudioRendererImpl::Stop(const base::Closure& callback) { |
207 DCHECK(task_runner_->BelongsToCurrentThread()); | 186 DCHECK(task_runner_->BelongsToCurrentThread()); |
208 DCHECK(!callback.is_null()); | 187 DCHECK(!callback.is_null()); |
209 | 188 |
210 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing | 189 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing |
211 // task-running guards that check |state_| with DCHECK(). | 190 // task-running guards that check |state_| with DCHECK(). |
212 | 191 |
213 if (sink_) { | 192 if (sink_) { |
214 sink_->Stop(); | 193 sink_->Stop(); |
215 sink_ = NULL; | 194 sink_ = NULL; |
216 } | 195 } |
217 | 196 |
218 stop_cb_ = callback; | 197 { |
219 | 198 base::AutoLock auto_lock(lock_); |
220 if (decoder_) { | 199 ChangeState_Locked(kStopped); |
221 DCHECK(task_runner_->BelongsToCurrentThread()); | 200 algorithm_.reset(NULL); |
222 decoder_->Stop(base::Bind(&AudioRendererImpl::StopDecoderDone, weak_this_)); | 201 init_cb_.Reset(); |
223 return; | 202 underflow_cb_.Reset(); |
| 203 time_cb_.Reset(); |
| 204 flush_cb_.Reset(); |
224 } | 205 } |
225 | 206 |
226 StopDecoderDone(); | 207 callback.Run(); |
227 } | 208 } |
228 | 209 |
229 void AudioRendererImpl::Preroll(base::TimeDelta time, | 210 void AudioRendererImpl::Preroll(base::TimeDelta time, |
230 const PipelineStatusCB& cb) { | 211 const PipelineStatusCB& cb) { |
231 DCHECK(task_runner_->BelongsToCurrentThread()); | 212 DCHECK(task_runner_->BelongsToCurrentThread()); |
232 | 213 |
233 base::AutoLock auto_lock(lock_); | 214 base::AutoLock auto_lock(lock_); |
234 DCHECK(!sink_playing_); | 215 DCHECK(!sink_playing_); |
235 DCHECK_EQ(state_, kPaused); | 216 DCHECK_EQ(state_, kPaused); |
236 DCHECK(!pending_read_) << "Pending read must complete before seeking"; | 217 DCHECK(!pending_read_) << "Pending read must complete before seeking"; |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 } | 700 } |
720 } | 701 } |
721 | 702 |
722 void AudioRendererImpl::ChangeState_Locked(State new_state) { | 703 void AudioRendererImpl::ChangeState_Locked(State new_state) { |
723 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state; | 704 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state; |
724 lock_.AssertAcquired(); | 705 lock_.AssertAcquired(); |
725 state_ = new_state; | 706 state_ = new_state; |
726 } | 707 } |
727 | 708 |
728 } // namespace media | 709 } // namespace media |
OLD | NEW |