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

Side by Side Diff: media/filters/decrypting_video_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: 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
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_video_decoder.h" 5 #include "media/filters/decrypting_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 120 }
121 121
122 DCHECK(decode_cb_.is_null()); 122 DCHECK(decode_cb_.is_null());
123 DoReset(); 123 DoReset();
124 } 124 }
125 125
126 void DecryptingVideoDecoder::Stop(const base::Closure& closure) { 126 void DecryptingVideoDecoder::Stop(const base::Closure& closure) {
127 DCHECK(task_runner_->BelongsToCurrentThread()); 127 DCHECK(task_runner_->BelongsToCurrentThread());
128 DVLOG(2) << "Stop() - state: " << state_; 128 DVLOG(2) << "Stop() - state: " << state_;
129 129
130 // Invalidate all weak pointers so that pending callbacks won't be fired into
131 // this object.
132 weak_factory_.InvalidateWeakPtrs();
133
130 // At this point the render thread is likely paused (in WebMediaPlayerImpl's 134 // At this point the render thread is likely paused (in WebMediaPlayerImpl's
131 // Destroy()), so running |closure| can't wait for anything that requires the 135 // Destroy()), so running |closure| can't wait for anything that requires the
132 // render thread to be processing messages to complete (such as PPAPI 136 // render thread to be processing messages to complete (such as PPAPI
133 // callbacks). 137 // callbacks).
134 if (decryptor_) { 138 if (decryptor_) {
135 decryptor_->RegisterNewKeyCB(Decryptor::kVideo, Decryptor::NewKeyCB()); 139 decryptor_->RegisterNewKeyCB(Decryptor::kVideo, Decryptor::NewKeyCB());
136 decryptor_->DeinitializeDecoder(Decryptor::kVideo); 140 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
137 decryptor_ = NULL; 141 decryptor_ = NULL;
138 } 142 }
139 if (!set_decryptor_ready_cb_.is_null()) 143 if (!set_decryptor_ready_cb_.is_null())
140 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 144 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
141 pending_buffer_to_decode_ = NULL; 145 pending_buffer_to_decode_ = NULL;
142 if (!init_cb_.is_null()) 146 if (!init_cb_.is_null())
143 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 147 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
144 if (!decode_cb_.is_null()) 148 if (!decode_cb_.is_null())
145 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL); 149 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL);
146 if (!reset_cb_.is_null()) 150 if (!reset_cb_.is_null())
147 base::ResetAndReturn(&reset_cb_).Run(); 151 base::ResetAndReturn(&reset_cb_).Run();
152
148 state_ = kStopped; 153 state_ = kStopped;
149 BindToCurrentLoop(closure).Run(); 154 BindToCurrentLoop(closure).Run();
150 } 155 }
151 156
152 DecryptingVideoDecoder::~DecryptingVideoDecoder() { 157 DecryptingVideoDecoder::~DecryptingVideoDecoder() {
153 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; 158 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
154 } 159 }
155 160
156 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) { 161 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) {
157 DVLOG(2) << "SetDecryptor()"; 162 DVLOG(2) << "SetDecryptor()";
158 DCHECK(task_runner_->BelongsToCurrentThread()); 163 DCHECK(task_runner_->BelongsToCurrentThread());
159
160 if (state_ == kStopped)
161 return;
162
163 DCHECK_EQ(state_, kDecryptorRequested) << state_; 164 DCHECK_EQ(state_, kDecryptorRequested) << state_;
164 DCHECK(!init_cb_.is_null()); 165 DCHECK(!init_cb_.is_null());
165 DCHECK(!set_decryptor_ready_cb_.is_null()); 166 DCHECK(!set_decryptor_ready_cb_.is_null());
166 set_decryptor_ready_cb_.Reset(); 167 set_decryptor_ready_cb_.Reset();
167 168
168 if (!decryptor) { 169 if (!decryptor) {
169 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 170 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
170 state_ = kStopped; 171 state_ = kStopped;
171 return; 172 return;
172 } 173 }
173 174
174 decryptor_ = decryptor; 175 decryptor_ = decryptor;
175 176
176 state_ = kPendingDecoderInit; 177 state_ = kPendingDecoderInit;
177 decryptor_->InitializeVideoDecoder( 178 decryptor_->InitializeVideoDecoder(
178 config_, 179 config_,
179 BindToCurrentLoop(base::Bind( 180 BindToCurrentLoop(base::Bind(
180 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); 181 &DecryptingVideoDecoder::FinishInitialization, weak_this_)));
181 } 182 }
182 183
183 void DecryptingVideoDecoder::FinishInitialization(bool success) { 184 void DecryptingVideoDecoder::FinishInitialization(bool success) {
184 DVLOG(2) << "FinishInitialization()"; 185 DVLOG(2) << "FinishInitialization()";
185 DCHECK(task_runner_->BelongsToCurrentThread()); 186 DCHECK(task_runner_->BelongsToCurrentThread());
186
187 if (state_ == kStopped)
acolwell GONE FROM CHROMIUM 2014/02/18 18:07:24 ditto
xhwang 2014/02/18 18:46:11 ditto
188 return;
189
190 DCHECK_EQ(state_, kPendingDecoderInit) << state_; 187 DCHECK_EQ(state_, kPendingDecoderInit) << state_;
191 DCHECK(!init_cb_.is_null()); 188 DCHECK(!init_cb_.is_null());
192 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 189 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
193 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. 190 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
194 191
195 if (!success) { 192 if (!success) {
196 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 193 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
197 state_ = kStopped; 194 state_ = kStopped;
198 return; 195 return;
199 } 196 }
(...skipping 22 matching lines...) Expand all
222 pending_buffer_to_decode_, BindToCurrentLoop(base::Bind( 219 pending_buffer_to_decode_, BindToCurrentLoop(base::Bind(
223 &DecryptingVideoDecoder::DeliverFrame, weak_this_, buffer_size))); 220 &DecryptingVideoDecoder::DeliverFrame, weak_this_, buffer_size)));
224 } 221 }
225 222
226 void DecryptingVideoDecoder::DeliverFrame( 223 void DecryptingVideoDecoder::DeliverFrame(
227 int buffer_size, 224 int buffer_size,
228 Decryptor::Status status, 225 Decryptor::Status status,
229 const scoped_refptr<VideoFrame>& frame) { 226 const scoped_refptr<VideoFrame>& frame) {
230 DVLOG(3) << "DeliverFrame() - status: " << status; 227 DVLOG(3) << "DeliverFrame() - status: " << status;
231 DCHECK(task_runner_->BelongsToCurrentThread()); 228 DCHECK(task_runner_->BelongsToCurrentThread());
232 TRACE_EVENT_ASYNC_END0(
233 "media", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_);
234
235 if (state_ == kStopped)
236 return;
237
238 DCHECK_EQ(state_, kPendingDecode) << state_; 229 DCHECK_EQ(state_, kPendingDecode) << state_;
239 DCHECK(!decode_cb_.is_null()); 230 DCHECK(!decode_cb_.is_null());
240 DCHECK(pending_buffer_to_decode_.get()); 231 DCHECK(pending_buffer_to_decode_.get());
241 232
233 TRACE_EVENT_ASYNC_END0(
234 "media", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_);
235
242 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_; 236 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_;
243 key_added_while_decode_pending_ = false; 237 key_added_while_decode_pending_ = false;
244 238
245 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = 239 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode =
246 pending_buffer_to_decode_; 240 pending_buffer_to_decode_;
247 pending_buffer_to_decode_ = NULL; 241 pending_buffer_to_decode_ = NULL;
248 242
249 if (!reset_cb_.is_null()) { 243 if (!reset_cb_.is_null()) {
250 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL); 244 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL);
251 DoReset(); 245 DoReset();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 308 }
315 309
316 void DecryptingVideoDecoder::DoReset() { 310 void DecryptingVideoDecoder::DoReset() {
317 DCHECK(init_cb_.is_null()); 311 DCHECK(init_cb_.is_null());
318 DCHECK(decode_cb_.is_null()); 312 DCHECK(decode_cb_.is_null());
319 state_ = kIdle; 313 state_ = kIdle;
320 base::ResetAndReturn(&reset_cb_).Run(); 314 base::ResetAndReturn(&reset_cb_).Run();
321 } 315 }
322 316
323 } // namespace media 317 } // namespace media
OLDNEW
« media/filters/decrypting_audio_decoder.cc ('K') | « media/filters/decrypting_audio_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698