Chromium Code Reviews| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(BindToCurrentLoop( | 160 decoder_->Reset(BindToCurrentLoop( |
| 161 base::Bind(&AudioRendererImpl::ResetDecoderDone, weak_this_))); | 161 base::Bind(&AudioRendererImpl::ResetDecoderDone, weak_this_))); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void AudioRendererImpl::ResetDecoderDone() { | 164 void AudioRendererImpl::ResetDecoderDone() { |
| 165 base::AutoLock auto_lock(lock_); | 165 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 166 if (state_ == kStopped) | 166 { |
| 167 return; | 167 base::AutoLock auto_lock(lock_); |
| 168 if (state_ == kStopped) | |
| 169 return; | |
| 168 | 170 |
| 169 DCHECK_EQ(state_, kPaused); | 171 DCHECK_EQ(state_, kPaused); |
| 170 DCHECK(!flush_cb_.is_null()); | 172 DCHECK(!flush_cb_.is_null()); |
| 171 | 173 |
| 172 audio_time_buffered_ = kNoTimestamp(); | 174 audio_time_buffered_ = kNoTimestamp(); |
| 173 current_time_ = kNoTimestamp(); | 175 current_time_ = kNoTimestamp(); |
| 174 received_end_of_stream_ = false; | 176 received_end_of_stream_ = false; |
| 175 rendered_end_of_stream_ = false; | 177 rendered_end_of_stream_ = false; |
| 176 preroll_aborted_ = false; | 178 preroll_aborted_ = false; |
| 177 | 179 |
| 178 earliest_end_time_ = now_cb_.Run(); | 180 earliest_end_time_ = now_cb_.Run(); |
| 179 splicer_->Reset(); | 181 splicer_->Reset(); |
| 180 algorithm_->FlushBuffers(); | 182 algorithm_->FlushBuffers(); |
| 183 } | |
| 184 base::ResetAndReturn(&flush_cb_).Run(); | |
| 185 } | |
| 181 | 186 |
| 182 base::ResetAndReturn(&flush_cb_).Run(); | 187 void AudioRendererImpl::StopDecoderDone() { |
| 188 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 189 { | |
| 190 base::AutoLock auto_lock(lock_); | |
| 191 if (state_ == kStopped) | |
| 192 return; | |
| 193 | |
| 194 DCHECK(!stop_cb_.is_null()); | |
| 195 DCHECK(init_cb_.is_null()); | |
| 196 | |
| 197 ChangeState_Locked(kStopped); | |
| 198 algorithm_.reset(); | |
| 199 init_cb_.Reset(); | |
| 200 underflow_cb_.Reset(); | |
| 201 time_cb_.Reset(); | |
| 202 flush_cb_.Reset(); | |
| 203 } | |
| 204 base::ResetAndReturn(&stop_cb_).Run(); | |
| 183 } | 205 } |
| 184 | 206 |
| 185 void AudioRendererImpl::Stop(const base::Closure& callback) { | 207 void AudioRendererImpl::Stop(const base::Closure& callback) { |
| 186 DCHECK(task_runner_->BelongsToCurrentThread()); | 208 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 187 DCHECK(!callback.is_null()); | 209 DCHECK(!callback.is_null()); |
| 188 | 210 |
| 189 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing | 211 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing |
| 190 // task-running guards that check |state_| with DCHECK(). | 212 // task-running guards that check |state_| with DCHECK(). |
| 191 | 213 |
| 192 if (sink_) { | 214 if (sink_) { |
| 193 sink_->Stop(); | 215 sink_->Stop(); |
| 194 sink_ = NULL; | 216 sink_ = NULL; |
| 195 } | 217 } |
| 196 | 218 |
| 197 { | 219 stop_cb_ = callback; |
| 198 base::AutoLock auto_lock(lock_); | 220 |
| 199 ChangeState_Locked(kStopped); | 221 if (decoder_) { |
| 200 algorithm_.reset(NULL); | 222 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 201 init_cb_.Reset(); | 223 decoder_->Stop(BindToCurrentLoop( |
|
DaleCurtis
2014/01/10 01:36:42
This works, but scherkus@ pointed out that our pol
| |
| 202 underflow_cb_.Reset(); | 224 base::Bind(&AudioRendererImpl::StopDecoderDone, weak_this_))); |
| 203 time_cb_.Reset(); | 225 return; |
| 204 flush_cb_.Reset(); | |
| 205 } | 226 } |
| 206 | 227 |
| 207 callback.Run(); | 228 StopDecoderDone(); |
| 208 } | 229 } |
| 209 | 230 |
| 210 void AudioRendererImpl::Preroll(base::TimeDelta time, | 231 void AudioRendererImpl::Preroll(base::TimeDelta time, |
| 211 const PipelineStatusCB& cb) { | 232 const PipelineStatusCB& cb) { |
| 212 DCHECK(task_runner_->BelongsToCurrentThread()); | 233 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 213 | 234 |
| 214 base::AutoLock auto_lock(lock_); | 235 base::AutoLock auto_lock(lock_); |
| 215 DCHECK(!sink_playing_); | 236 DCHECK(!sink_playing_); |
| 216 DCHECK_EQ(state_, kPaused); | 237 DCHECK_EQ(state_, kPaused); |
| 217 DCHECK(!pending_read_) << "Pending read must complete before seeking"; | 238 DCHECK(!pending_read_) << "Pending read must complete before seeking"; |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 } | 721 } |
| 701 } | 722 } |
| 702 | 723 |
| 703 void AudioRendererImpl::ChangeState_Locked(State new_state) { | 724 void AudioRendererImpl::ChangeState_Locked(State new_state) { |
| 704 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state; | 725 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state; |
| 705 lock_.AssertAcquired(); | 726 lock_.AssertAcquired(); |
| 706 state_ = new_state; | 727 state_ = new_state; |
| 707 } | 728 } |
| 708 | 729 |
| 709 } // namespace media | 730 } // namespace media |
| OLD | NEW |