| OLD | NEW |
| 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 Loading... |
| 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 | |
| 152 // this object. | |
| 153 weak_factory_.InvalidateWeakPtrs(); | |
| 154 | |
| 155 if (decryptor_) { | 151 if (decryptor_) { |
| 156 decryptor_->DeinitializeDecoder(Decryptor::kAudio); | 152 decryptor_->DeinitializeDecoder(Decryptor::kAudio); |
| 157 decryptor_ = NULL; | 153 decryptor_ = NULL; |
| 158 } | 154 } |
| 159 if (!set_decryptor_ready_cb_.is_null()) | 155 if (!set_decryptor_ready_cb_.is_null()) |
| 160 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); | 156 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); |
| 161 pending_buffer_to_decode_ = NULL; | 157 pending_buffer_to_decode_ = NULL; |
| 162 if (!init_cb_.is_null()) | 158 if (!init_cb_.is_null()) |
| 163 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 159 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
| 164 if (!decode_cb_.is_null()) | 160 if (!decode_cb_.is_null()) |
| 165 base::ResetAndReturn(&decode_cb_).Run(kAborted); | 161 base::ResetAndReturn(&decode_cb_).Run(kAborted); |
| 166 if (!reset_cb_.is_null()) | 162 if (!reset_cb_.is_null()) |
| 167 base::ResetAndReturn(&reset_cb_).Run(); | 163 base::ResetAndReturn(&reset_cb_).Run(); |
| 168 | |
| 169 state_ = kStopped; | |
| 170 } | |
| 171 | |
| 172 DecryptingAudioDecoder::~DecryptingAudioDecoder() { | |
| 173 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; | |
| 174 } | 164 } |
| 175 | 165 |
| 176 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { | 166 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { |
| 177 DVLOG(2) << "SetDecryptor()"; | 167 DVLOG(2) << "SetDecryptor()"; |
| 178 DCHECK(task_runner_->BelongsToCurrentThread()); | 168 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 179 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 169 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
| 180 DCHECK(!init_cb_.is_null()); | 170 DCHECK(!init_cb_.is_null()); |
| 181 DCHECK(!set_decryptor_ready_cb_.is_null()); | 171 DCHECK(!set_decryptor_ready_cb_.is_null()); |
| 182 | 172 |
| 183 set_decryptor_ready_cb_.Reset(); | 173 set_decryptor_ready_cb_.Reset(); |
| 184 | 174 |
| 185 if (!decryptor) { | 175 if (!decryptor) { |
| 186 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 176 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
| 187 // TODO(xhwang): Add kError state. See http://crbug.com/251503 | 177 state_ = kError; |
| 188 state_ = kStopped; | |
| 189 return; | 178 return; |
| 190 } | 179 } |
| 191 | 180 |
| 192 decryptor_ = decryptor; | 181 decryptor_ = decryptor; |
| 193 | 182 |
| 194 InitializeDecoder(); | 183 InitializeDecoder(); |
| 195 } | 184 } |
| 196 | 185 |
| 197 void DecryptingAudioDecoder::InitializeDecoder() { | 186 void DecryptingAudioDecoder::InitializeDecoder() { |
| 198 state_ = kPendingDecoderInit; | 187 state_ = kPendingDecoderInit; |
| 199 decryptor_->InitializeAudioDecoder( | 188 decryptor_->InitializeAudioDecoder( |
| 200 config_, | 189 config_, |
| 201 BindToCurrentLoop(base::Bind( | 190 BindToCurrentLoop(base::Bind( |
| 202 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); | 191 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); |
| 203 } | 192 } |
| 204 | 193 |
| 205 void DecryptingAudioDecoder::FinishInitialization(bool success) { | 194 void DecryptingAudioDecoder::FinishInitialization(bool success) { |
| 206 DVLOG(2) << "FinishInitialization()"; | 195 DVLOG(2) << "FinishInitialization()"; |
| 207 DCHECK(task_runner_->BelongsToCurrentThread()); | 196 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 208 DCHECK(state_ == kPendingDecoderInit) << state_; | 197 DCHECK(state_ == kPendingDecoderInit) << state_; |
| 209 DCHECK(!init_cb_.is_null()); | 198 DCHECK(!init_cb_.is_null()); |
| 210 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. | 199 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. |
| 211 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. | 200 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. |
| 212 | 201 |
| 213 if (!success) { | 202 if (!success) { |
| 214 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 203 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
| 215 state_ = kStopped; | 204 decryptor_ = NULL; |
| 205 state_ = kError; |
| 216 return; | 206 return; |
| 217 } | 207 } |
| 218 | 208 |
| 219 // Success! | 209 // Success! |
| 220 timestamp_helper_.reset( | 210 timestamp_helper_.reset( |
| 221 new AudioTimestampHelper(config_.samples_per_second())); | 211 new AudioTimestampHelper(config_.samples_per_second())); |
| 222 | 212 |
| 223 decryptor_->RegisterNewKeyCB( | 213 decryptor_->RegisterNewKeyCB( |
| 224 Decryptor::kAudio, | 214 Decryptor::kAudio, |
| 225 BindToCurrentLoop( | 215 BindToCurrentLoop( |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 347 } |
| 358 | 348 |
| 359 frame->set_timestamp(current_time); | 349 frame->set_timestamp(current_time); |
| 360 timestamp_helper_->AddFrames(frame->frame_count()); | 350 timestamp_helper_->AddFrames(frame->frame_count()); |
| 361 | 351 |
| 362 output_cb_.Run(frame); | 352 output_cb_.Run(frame); |
| 363 } | 353 } |
| 364 } | 354 } |
| 365 | 355 |
| 366 } // namespace media | 356 } // namespace media |
| OLD | NEW |