Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: media/filters/audio_renderer_impl.cc

Issue 140823012: Reland: Add Stop() to AudioDecoder. (https://codereview.chromium.org/126793002/) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crash. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(BindToCurrentLoop( 150 decrypting_demuxer_stream_->Reset(
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(BindToCurrentLoop( 160 decoder_->Reset(base::Bind(&AudioRendererImpl::ResetDecoderDone, weak_this_));
161 base::Bind(&AudioRendererImpl::ResetDecoderDone, weak_this_)));
162 } 161 }
163 162
164 void AudioRendererImpl::ResetDecoderDone() { 163 void AudioRendererImpl::ResetDecoderDone() {
165 base::AutoLock auto_lock(lock_); 164 DCHECK(task_runner_->BelongsToCurrentThread());
166 if (state_ == kStopped) 165 {
167 return; 166 base::AutoLock auto_lock(lock_);
167 if (state_ == kStopped)
168 return;
168 169
169 DCHECK_EQ(state_, kPaused); 170 DCHECK_EQ(state_, kPaused);
170 DCHECK(!flush_cb_.is_null()); 171 DCHECK(!flush_cb_.is_null());
171 172
172 audio_time_buffered_ = kNoTimestamp(); 173 audio_time_buffered_ = kNoTimestamp();
173 current_time_ = kNoTimestamp(); 174 current_time_ = kNoTimestamp();
174 received_end_of_stream_ = false; 175 received_end_of_stream_ = false;
175 rendered_end_of_stream_ = false; 176 rendered_end_of_stream_ = false;
176 preroll_aborted_ = false; 177 preroll_aborted_ = false;
177 178
178 earliest_end_time_ = now_cb_.Run(); 179 earliest_end_time_ = now_cb_.Run();
179 splicer_->Reset(); 180 splicer_->Reset();
180 algorithm_->FlushBuffers(); 181 algorithm_->FlushBuffers();
181 182 }
182 base::ResetAndReturn(&flush_cb_).Run(); 183 base::ResetAndReturn(&flush_cb_).Run();
183 } 184 }
184 185
185 void AudioRendererImpl::Stop(const base::Closure& callback) { 186 void AudioRendererImpl::Stop(const base::Closure& callback) {
186 DCHECK(task_runner_->BelongsToCurrentThread()); 187 DCHECK(task_runner_->BelongsToCurrentThread());
187 DCHECK(!callback.is_null()); 188 DCHECK(!callback.is_null());
188 189
189 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing 190 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing
190 // task-running guards that check |state_| with DCHECK(). 191 // task-running guards that check |state_| with DCHECK().
191 192
192 if (sink_) { 193 if (sink_) {
193 sink_->Stop(); 194 sink_->Stop();
194 sink_ = NULL; 195 sink_ = NULL;
195 } 196 }
196 197
197 { 198 {
198 base::AutoLock auto_lock(lock_); 199 base::AutoLock auto_lock(lock_);
200 if (state_ == kStopped)
201 return;
202
203 DCHECK(init_cb_.is_null());
204
199 ChangeState_Locked(kStopped); 205 ChangeState_Locked(kStopped);
200 algorithm_.reset(NULL); 206 algorithm_.reset();
201 init_cb_.Reset(); 207 init_cb_.Reset();
202 underflow_cb_.Reset(); 208 underflow_cb_.Reset();
203 time_cb_.Reset(); 209 time_cb_.Reset();
204 flush_cb_.Reset(); 210 flush_cb_.Reset();
205 } 211 }
206 212
213 if (!init_cb_.is_null()) {
rileya (GONE FROM CHROMIUM) 2014/01/21 19:08:50 This resolves the layout test failure (if we have
214 decoder_selector_->Abort();
215 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT);
rileya (GONE FROM CHROMIUM) 2014/01/21 19:08:50 Is there a better error for this?
DaleCurtis 2014/01/21 21:14:39 Hmm, I don't see VideoFrameStream / VideoRendererI
216 callback.Run();
217 return;
218 }
219
220 if (decoder_) {
221 DCHECK(task_runner_->BelongsToCurrentThread());
222 decoder_->Stop(callback);
rileya (GONE FROM CHROMIUM) 2014/01/21 19:08:50 The canary crash was caused (so far as I can tell)
223 return;
224 }
225
207 callback.Run(); 226 callback.Run();
208 } 227 }
209 228
210 void AudioRendererImpl::Preroll(base::TimeDelta time, 229 void AudioRendererImpl::Preroll(base::TimeDelta time,
211 const PipelineStatusCB& cb) { 230 const PipelineStatusCB& cb) {
212 DCHECK(task_runner_->BelongsToCurrentThread()); 231 DCHECK(task_runner_->BelongsToCurrentThread());
213 232
214 base::AutoLock auto_lock(lock_); 233 base::AutoLock auto_lock(lock_);
215 DCHECK(!sink_playing_); 234 DCHECK(!sink_playing_);
216 DCHECK_EQ(state_, kPaused); 235 DCHECK_EQ(state_, kPaused);
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 } 719 }
701 } 720 }
702 721
703 void AudioRendererImpl::ChangeState_Locked(State new_state) { 722 void AudioRendererImpl::ChangeState_Locked(State new_state) {
704 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state; 723 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state;
705 lock_.AssertAcquired(); 724 lock_.AssertAcquired();
706 state_ = new_state; 725 state_ = new_state;
707 } 726 }
708 727
709 } // namespace media 728 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/audio_decoder_selector_unittest.cc ('k') | media/filters/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698