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

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

Issue 167523004: Invalidate all weak pointers during Decrypting{Audio|Video}Decoder::Stop(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/filters/decrypting_video_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/decrypting_audio_decoder.h" 5 #include "media/filters/decrypting_audio_decoder.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 DCHECK(read_cb_.is_null()); 144 DCHECK(read_cb_.is_null());
145 DoReset(); 145 DoReset();
146 } 146 }
147 147
148 void DecryptingAudioDecoder::Stop(const base::Closure& closure) { 148 void DecryptingAudioDecoder::Stop(const base::Closure& closure) {
149 DVLOG(2) << "Stop() - state: " << state_; 149 DVLOG(2) << "Stop() - state: " << state_;
150 DCHECK(task_runner_->BelongsToCurrentThread()); 150 DCHECK(task_runner_->BelongsToCurrentThread());
151 151
152 // Invalidate all weak pointers so that pending callbacks won't be fired into
153 // this object.
154 weak_factory_.InvalidateWeakPtrs();
155
152 if (decryptor_) { 156 if (decryptor_) {
153 decryptor_->RegisterNewKeyCB(Decryptor::kAudio, Decryptor::NewKeyCB()); 157 decryptor_->RegisterNewKeyCB(Decryptor::kAudio, Decryptor::NewKeyCB());
154 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 158 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
155 decryptor_ = NULL; 159 decryptor_ = NULL;
156 } 160 }
157 if (!set_decryptor_ready_cb_.is_null()) 161 if (!set_decryptor_ready_cb_.is_null())
158 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 162 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
159 pending_buffer_to_decode_ = NULL; 163 pending_buffer_to_decode_ = NULL;
160 if (!init_cb_.is_null()) 164 if (!init_cb_.is_null())
161 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 165 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
162 if (!read_cb_.is_null()) 166 if (!read_cb_.is_null())
163 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); 167 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
164 if (!reset_cb_.is_null()) 168 if (!reset_cb_.is_null())
165 base::ResetAndReturn(&reset_cb_).Run(); 169 base::ResetAndReturn(&reset_cb_).Run();
170
166 state_ = kStopped; 171 state_ = kStopped;
167 task_runner_->PostTask(FROM_HERE, closure); 172 task_runner_->PostTask(FROM_HERE, closure);
168 } 173 }
169 174
170 int DecryptingAudioDecoder::bits_per_channel() { 175 int DecryptingAudioDecoder::bits_per_channel() {
171 DCHECK(task_runner_->BelongsToCurrentThread()); 176 DCHECK(task_runner_->BelongsToCurrentThread());
172 return bits_per_channel_; 177 return bits_per_channel_;
173 } 178 }
174 179
175 ChannelLayout DecryptingAudioDecoder::channel_layout() { 180 ChannelLayout DecryptingAudioDecoder::channel_layout() {
176 DCHECK(task_runner_->BelongsToCurrentThread()); 181 DCHECK(task_runner_->BelongsToCurrentThread());
177 return channel_layout_; 182 return channel_layout_;
178 } 183 }
179 184
180 int DecryptingAudioDecoder::samples_per_second() { 185 int DecryptingAudioDecoder::samples_per_second() {
181 DCHECK(task_runner_->BelongsToCurrentThread()); 186 DCHECK(task_runner_->BelongsToCurrentThread());
182 return samples_per_second_; 187 return samples_per_second_;
183 } 188 }
184 189
185 DecryptingAudioDecoder::~DecryptingAudioDecoder() { 190 DecryptingAudioDecoder::~DecryptingAudioDecoder() {
186 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; 191 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
187 } 192 }
188 193
189 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { 194 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
190 DVLOG(2) << "SetDecryptor()"; 195 DVLOG(2) << "SetDecryptor()";
191 DCHECK(task_runner_->BelongsToCurrentThread()); 196 DCHECK(task_runner_->BelongsToCurrentThread());
192
193 if (state_ == kStopped)
194 return;
195
196 DCHECK_EQ(state_, kDecryptorRequested) << state_; 197 DCHECK_EQ(state_, kDecryptorRequested) << state_;
197 DCHECK(!init_cb_.is_null()); 198 DCHECK(!init_cb_.is_null());
198 DCHECK(!set_decryptor_ready_cb_.is_null()); 199 DCHECK(!set_decryptor_ready_cb_.is_null());
199 200
200 set_decryptor_ready_cb_.Reset(); 201 set_decryptor_ready_cb_.Reset();
201 202
202 if (!decryptor) { 203 if (!decryptor) {
203 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 204 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
204 // TODO(xhwang): Add kError state. See http://crbug.com/251503 205 // TODO(xhwang): Add kError state. See http://crbug.com/251503
205 state_ = kStopped; 206 state_ = kStopped;
(...skipping 19 matching lines...) Expand all
225 state_ = kPendingDecoderInit; 226 state_ = kPendingDecoderInit;
226 decryptor_->InitializeAudioDecoder( 227 decryptor_->InitializeAudioDecoder(
227 config, 228 config,
228 BindToCurrentLoop(base::Bind( 229 BindToCurrentLoop(base::Bind(
229 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); 230 &DecryptingAudioDecoder::FinishInitialization, weak_this_)));
230 } 231 }
231 232
232 void DecryptingAudioDecoder::FinishInitialization(bool success) { 233 void DecryptingAudioDecoder::FinishInitialization(bool success) {
233 DVLOG(2) << "FinishInitialization()"; 234 DVLOG(2) << "FinishInitialization()";
234 DCHECK(task_runner_->BelongsToCurrentThread()); 235 DCHECK(task_runner_->BelongsToCurrentThread());
235
236 if (state_ == kStopped)
237 return;
238
239 DCHECK_EQ(state_, kPendingDecoderInit) << state_; 236 DCHECK_EQ(state_, kPendingDecoderInit) << state_;
240 DCHECK(!init_cb_.is_null()); 237 DCHECK(!init_cb_.is_null());
241 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 238 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
242 DCHECK(read_cb_.is_null()); // No Read() before initialization finished. 239 DCHECK(read_cb_.is_null()); // No Read() before initialization finished.
243 240
244 if (!success) { 241 if (!success) {
245 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 242 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
246 state_ = kStopped; 243 state_ = kStopped;
247 return; 244 return;
248 } 245 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 BindToCurrentLoop(base::Bind( 365 BindToCurrentLoop(base::Bind(
369 &DecryptingAudioDecoder::DeliverFrame, weak_this_, buffer_size))); 366 &DecryptingAudioDecoder::DeliverFrame, weak_this_, buffer_size)));
370 } 367 }
371 368
372 void DecryptingAudioDecoder::DeliverFrame( 369 void DecryptingAudioDecoder::DeliverFrame(
373 int buffer_size, 370 int buffer_size,
374 Decryptor::Status status, 371 Decryptor::Status status,
375 const Decryptor::AudioBuffers& frames) { 372 const Decryptor::AudioBuffers& frames) {
376 DVLOG(3) << "DeliverFrame() - status: " << status; 373 DVLOG(3) << "DeliverFrame() - status: " << status;
377 DCHECK(task_runner_->BelongsToCurrentThread()); 374 DCHECK(task_runner_->BelongsToCurrentThread());
378
379 if (state_ == kStopped)
380 return;
381
382 DCHECK_EQ(state_, kPendingDecode) << state_; 375 DCHECK_EQ(state_, kPendingDecode) << state_;
383 DCHECK(!read_cb_.is_null()); 376 DCHECK(!read_cb_.is_null());
384 DCHECK(pending_buffer_to_decode_.get()); 377 DCHECK(pending_buffer_to_decode_.get());
385 DCHECK(queued_audio_frames_.empty()); 378 DCHECK(queued_audio_frames_.empty());
386 379
387 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_; 380 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_;
388 key_added_while_decode_pending_ = false; 381 key_added_while_decode_pending_ = false;
389 382
390 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = 383 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode =
391 pending_buffer_to_decode_; 384 pending_buffer_to_decode_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 495 }
503 496
504 frame->set_timestamp(current_time); 497 frame->set_timestamp(current_time);
505 frame->set_duration( 498 frame->set_duration(
506 timestamp_helper_->GetFrameDuration(frame->frame_count())); 499 timestamp_helper_->GetFrameDuration(frame->frame_count()));
507 timestamp_helper_->AddFrames(frame->frame_count()); 500 timestamp_helper_->AddFrames(frame->frame_count());
508 } 501 }
509 } 502 }
510 503
511 } // namespace media 504 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/decrypting_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698