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

Side by Side Diff: media/filters/decrypting_audio_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_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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (state_ == kWaitingForKey) { 137 if (state_ == kWaitingForKey) {
138 DCHECK(!decode_cb_.is_null()); 138 DCHECK(!decode_cb_.is_null());
139 pending_buffer_to_decode_ = NULL; 139 pending_buffer_to_decode_ = NULL;
140 base::ResetAndReturn(&decode_cb_).Run(kAborted); 140 base::ResetAndReturn(&decode_cb_).Run(kAborted);
141 } 141 }
142 142
143 DCHECK(decode_cb_.is_null()); 143 DCHECK(decode_cb_.is_null());
144 DoReset(); 144 DoReset();
145 } 145 }
146 146
147 void DecryptingAudioDecoder::Stop() { 147 DecryptingAudioDecoder::~DecryptingAudioDecoder() {
148 DVLOG(2) << "Stop() - state: " << state_; 148 DVLOG(2) << __FUNCTION__;
149 DCHECK(task_runner_->BelongsToCurrentThread()); 149 DCHECK(task_runner_->BelongsToCurrentThread());
150 150
151 // Invalidate all weak pointers so that pending callbacks won't be fired into 151 if (state_ == kUninitialized)
152 // this object. 152 return;
153 weak_factory_.InvalidateWeakPtrs();
154 153
155 if (decryptor_) { 154 if (decryptor_) {
156 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 155 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
157 decryptor_ = NULL; 156 decryptor_ = NULL;
158 } 157 }
159 if (!set_decryptor_ready_cb_.is_null()) 158 if (!set_decryptor_ready_cb_.is_null())
160 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 159 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
161 pending_buffer_to_decode_ = NULL; 160 pending_buffer_to_decode_ = NULL;
162 if (!init_cb_.is_null()) 161 if (!init_cb_.is_null())
163 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 162 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
164 if (!decode_cb_.is_null()) 163 if (!decode_cb_.is_null())
165 base::ResetAndReturn(&decode_cb_).Run(kAborted); 164 base::ResetAndReturn(&decode_cb_).Run(kAborted);
166 if (!reset_cb_.is_null()) 165 if (!reset_cb_.is_null())
167 base::ResetAndReturn(&reset_cb_).Run(); 166 base::ResetAndReturn(&reset_cb_).Run();
168
169 state_ = kStopped;
170 }
171
172 DecryptingAudioDecoder::~DecryptingAudioDecoder() {
173 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
174 } 167 }
175 168
176 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { 169 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
177 DVLOG(2) << "SetDecryptor()"; 170 DVLOG(2) << "SetDecryptor()";
178 DCHECK(task_runner_->BelongsToCurrentThread()); 171 DCHECK(task_runner_->BelongsToCurrentThread());
179 DCHECK_EQ(state_, kDecryptorRequested) << state_; 172 DCHECK_EQ(state_, kDecryptorRequested) << state_;
180 DCHECK(!init_cb_.is_null()); 173 DCHECK(!init_cb_.is_null());
181 DCHECK(!set_decryptor_ready_cb_.is_null()); 174 DCHECK(!set_decryptor_ready_cb_.is_null());
182 175
183 set_decryptor_ready_cb_.Reset(); 176 set_decryptor_ready_cb_.Reset();
184 177
185 if (!decryptor) { 178 if (!decryptor) {
186 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 179 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
187 // TODO(xhwang): Add kError state. See http://crbug.com/251503 180 state_ = kError;
188 state_ = kStopped;
189 return; 181 return;
190 } 182 }
191 183
192 decryptor_ = decryptor; 184 decryptor_ = decryptor;
193 185
194 InitializeDecoder(); 186 InitializeDecoder();
195 } 187 }
196 188
197 void DecryptingAudioDecoder::InitializeDecoder() { 189 void DecryptingAudioDecoder::InitializeDecoder() {
198 state_ = kPendingDecoderInit; 190 state_ = kPendingDecoderInit;
199 decryptor_->InitializeAudioDecoder( 191 decryptor_->InitializeAudioDecoder(
200 config_, 192 config_,
201 BindToCurrentLoop(base::Bind( 193 BindToCurrentLoop(base::Bind(
202 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); 194 &DecryptingAudioDecoder::FinishInitialization, weak_this_)));
203 } 195 }
204 196
205 void DecryptingAudioDecoder::FinishInitialization(bool success) { 197 void DecryptingAudioDecoder::FinishInitialization(bool success) {
206 DVLOG(2) << "FinishInitialization()"; 198 DVLOG(2) << "FinishInitialization()";
207 DCHECK(task_runner_->BelongsToCurrentThread()); 199 DCHECK(task_runner_->BelongsToCurrentThread());
208 DCHECK(state_ == kPendingDecoderInit) << state_; 200 DCHECK(state_ == kPendingDecoderInit) << state_;
209 DCHECK(!init_cb_.is_null()); 201 DCHECK(!init_cb_.is_null());
210 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 202 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
211 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. 203 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
212 204
213 if (!success) { 205 if (!success) {
214 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 206 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
215 state_ = kStopped; 207 decryptor_ = NULL;
208 state_ = kError;
216 return; 209 return;
217 } 210 }
218 211
219 // Success! 212 // Success!
220 timestamp_helper_.reset( 213 timestamp_helper_.reset(
221 new AudioTimestampHelper(config_.samples_per_second())); 214 new AudioTimestampHelper(config_.samples_per_second()));
222 215
223 decryptor_->RegisterNewKeyCB( 216 decryptor_->RegisterNewKeyCB(
224 Decryptor::kAudio, 217 Decryptor::kAudio,
225 BindToCurrentLoop( 218 BindToCurrentLoop(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 350 }
358 351
359 frame->set_timestamp(current_time); 352 frame->set_timestamp(current_time);
360 timestamp_helper_->AddFrames(frame->frame_count()); 353 timestamp_helper_->AddFrames(frame->frame_count());
361 354
362 output_cb_.Run(frame); 355 output_cb_.Run(frame);
363 } 356 }
364 } 357 }
365 358
366 } // namespace media 359 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_audio_decoder.h ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698