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

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

Issue 395703002: Fold {Audio|Video}Decoder::Stop() into the dtor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 6 years, 5 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (state_ == kWaitingForKey) { 118 if (state_ == kWaitingForKey) {
119 DCHECK(!decode_cb_.is_null()); 119 DCHECK(!decode_cb_.is_null());
120 pending_buffer_to_decode_ = NULL; 120 pending_buffer_to_decode_ = NULL;
121 base::ResetAndReturn(&decode_cb_).Run(kAborted); 121 base::ResetAndReturn(&decode_cb_).Run(kAborted);
122 } 122 }
123 123
124 DCHECK(decode_cb_.is_null()); 124 DCHECK(decode_cb_.is_null());
125 DoReset(); 125 DoReset();
126 } 126 }
127 127
128 void DecryptingVideoDecoder::Stop() { 128 DecryptingVideoDecoder::~DecryptingVideoDecoder() {
129 DCHECK(task_runner_->BelongsToCurrentThread()); 129 DCHECK(task_runner_->BelongsToCurrentThread());
130 DVLOG(2) << "Stop() - state: " << state_;
131 130
132 // Invalidate all weak pointers so that pending callbacks won't be fired into 131 if (state_ == kUninitialized)
133 // this object. 132 return;
134 weak_factory_.InvalidateWeakPtrs();
135 133
136 // At this point the render thread is likely paused (in WebMediaPlayerImpl's
137 // Destroy()), so running |closure| can't wait for anything that requires the
138 // render thread to be processing messages to complete (such as PPAPI
139 // callbacks).
140 if (decryptor_) { 134 if (decryptor_) {
141 decryptor_->DeinitializeDecoder(Decryptor::kVideo); 135 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
142 decryptor_ = NULL; 136 decryptor_ = NULL;
143 } 137 }
144 if (!set_decryptor_ready_cb_.is_null()) 138 if (!set_decryptor_ready_cb_.is_null())
145 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 139 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
146 pending_buffer_to_decode_ = NULL; 140 pending_buffer_to_decode_ = NULL;
147 if (!init_cb_.is_null()) 141 if (!init_cb_.is_null())
148 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 142 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
149 if (!decode_cb_.is_null()) 143 if (!decode_cb_.is_null())
150 base::ResetAndReturn(&decode_cb_).Run(kAborted); 144 base::ResetAndReturn(&decode_cb_).Run(kAborted);
151 if (!reset_cb_.is_null()) 145 if (!reset_cb_.is_null())
152 base::ResetAndReturn(&reset_cb_).Run(); 146 base::ResetAndReturn(&reset_cb_).Run();
153
154 state_ = kStopped;
155 }
156
157 DecryptingVideoDecoder::~DecryptingVideoDecoder() {
158 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
159 } 147 }
160 148
161 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) { 149 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) {
162 DVLOG(2) << "SetDecryptor()"; 150 DVLOG(2) << "SetDecryptor()";
163 DCHECK(task_runner_->BelongsToCurrentThread()); 151 DCHECK(task_runner_->BelongsToCurrentThread());
164 DCHECK_EQ(state_, kDecryptorRequested) << state_; 152 DCHECK_EQ(state_, kDecryptorRequested) << state_;
165 DCHECK(!init_cb_.is_null()); 153 DCHECK(!init_cb_.is_null());
166 DCHECK(!set_decryptor_ready_cb_.is_null()); 154 DCHECK(!set_decryptor_ready_cb_.is_null());
167 set_decryptor_ready_cb_.Reset(); 155 set_decryptor_ready_cb_.Reset();
168 156
169 if (!decryptor) { 157 if (!decryptor) {
170 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 158 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
171 state_ = kStopped; 159 state_ = kError;
172 return; 160 return;
173 } 161 }
174 162
175 decryptor_ = decryptor; 163 decryptor_ = decryptor;
176 164
177 state_ = kPendingDecoderInit; 165 state_ = kPendingDecoderInit;
178 decryptor_->InitializeVideoDecoder( 166 decryptor_->InitializeVideoDecoder(
179 config_, 167 config_,
180 BindToCurrentLoop(base::Bind( 168 BindToCurrentLoop(base::Bind(
181 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); 169 &DecryptingVideoDecoder::FinishInitialization, weak_this_)));
182 } 170 }
183 171
184 void DecryptingVideoDecoder::FinishInitialization(bool success) { 172 void DecryptingVideoDecoder::FinishInitialization(bool success) {
185 DVLOG(2) << "FinishInitialization()"; 173 DVLOG(2) << "FinishInitialization()";
186 DCHECK(task_runner_->BelongsToCurrentThread()); 174 DCHECK(task_runner_->BelongsToCurrentThread());
187 DCHECK_EQ(state_, kPendingDecoderInit) << state_; 175 DCHECK_EQ(state_, kPendingDecoderInit) << state_;
188 DCHECK(!init_cb_.is_null()); 176 DCHECK(!init_cb_.is_null());
189 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 177 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
190 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. 178 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
191 179
192 if (!success) { 180 if (!success) {
193 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 181 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
194 state_ = kStopped; 182 decryptor_ = NULL;
183 state_ = kError;
195 return; 184 return;
196 } 185 }
197 186
198 decryptor_->RegisterNewKeyCB( 187 decryptor_->RegisterNewKeyCB(
199 Decryptor::kVideo, 188 Decryptor::kVideo,
200 BindToCurrentLoop( 189 BindToCurrentLoop(
201 base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_))); 190 base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_)));
202 191
203 // Success! 192 // Success!
204 state_ = kIdle; 193 state_ = kIdle;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 304 }
316 305
317 void DecryptingVideoDecoder::DoReset() { 306 void DecryptingVideoDecoder::DoReset() {
318 DCHECK(init_cb_.is_null()); 307 DCHECK(init_cb_.is_null());
319 DCHECK(decode_cb_.is_null()); 308 DCHECK(decode_cb_.is_null());
320 state_ = kIdle; 309 state_ = kIdle;
321 base::ResetAndReturn(&reset_cb_).Run(); 310 base::ResetAndReturn(&reset_cb_).Run();
322 } 311 }
323 312
324 } // namespace media 313 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_video_decoder.h ('k') | media/filters/decrypting_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698