Chromium Code Reviews| 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 "webkit/media/crypto/proxy_decryptor.h" | 5 #include "webkit/media/crypto/proxy_decryptor.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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 const std::string& session_id) { | 147 const std::string& session_id) { |
| 148 DVLOG(1) << "CancelKeyRequest()"; | 148 DVLOG(1) << "CancelKeyRequest()"; |
| 149 | 149 |
| 150 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. | 150 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. |
| 151 decryptor_->CancelKeyRequest(key_system, session_id); | 151 decryptor_->CancelKeyRequest(key_system, session_id); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void ProxyDecryptor::Decrypt( | 154 void ProxyDecryptor::Decrypt( |
| 155 const scoped_refptr<media::DecoderBuffer>& encrypted, | 155 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 156 const DecryptCB& decrypt_cb) { | 156 const DecryptCB& decrypt_cb) { |
| 157 DVLOG(2) << "Decrypt()"; | |
| 157 DCHECK(decryption_message_loop_->BelongsToCurrentThread()); | 158 DCHECK(decryption_message_loop_->BelongsToCurrentThread()); |
| 158 | 159 |
| 159 DCHECK(!is_canceling_decrypt_); | 160 DCHECK(!is_canceling_decrypt_); |
| 160 DCHECK(!pending_buffer_to_decrypt_); | 161 DCHECK(!pending_buffer_to_decrypt_); |
| 161 DCHECK(pending_decrypt_cb_.is_null()); | 162 DCHECK(pending_decrypt_cb_.is_null()); |
| 162 | 163 |
| 163 pending_buffer_to_decrypt_ = encrypted; | 164 pending_buffer_to_decrypt_ = encrypted; |
| 164 pending_decrypt_cb_ = decrypt_cb; | 165 pending_decrypt_cb_ = decrypt_cb; |
| 165 | 166 |
| 166 // This is safe as we do not replace/delete an existing decryptor at run-time. | 167 // This is safe as we do not replace/delete an existing decryptor at run-time. |
| 167 media::Decryptor* decryptor = NULL; | 168 media::Decryptor* decryptor = NULL; |
| 168 { | 169 { |
| 169 base::AutoLock auto_lock(lock_); | 170 base::AutoLock auto_lock(lock_); |
| 170 decryptor = decryptor_.get(); | 171 decryptor = decryptor_.get(); |
| 171 } | 172 } |
| 172 if (!decryptor) { | 173 if (!decryptor) { |
| 173 DVLOG(1) << "ProxyDecryptor::Decrypt(): decryptor not initialized."; | 174 DVLOG(1) << "Decrypt(): decryptor not initialized."; |
| 174 | 175 |
| 175 // TODO(xhwang): The same NeedKey may be fired here and multiple times in | 176 // TODO(xhwang): The same NeedKey may be fired here and multiple times in |
| 176 // OnBufferDecrypted(). While the spec says only one NeedKey should be | 177 // OnBufferDecrypted(). While the spec says only one NeedKey should be |
| 177 // fired. Leave them as is since the spec about this may change. | 178 // fired. Leave them as is since the spec about this may change. |
| 178 FireNeedKey(client_, encrypted); | 179 FireNeedKey(client_, encrypted); |
| 179 return; | 180 return; |
| 180 } | 181 } |
| 181 | 182 |
| 182 DecryptPendingBuffer(); | 183 DecryptPendingBuffer(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void ProxyDecryptor::CancelDecrypt() { | 186 void ProxyDecryptor::CancelDecrypt() { |
| 187 DVLOG(1) << "CancelDecrypt()"; | |
| 186 DCHECK(decryption_message_loop_->BelongsToCurrentThread()); | 188 DCHECK(decryption_message_loop_->BelongsToCurrentThread()); |
| 187 | 189 |
| 188 if (!pending_buffer_to_decrypt_) { | 190 if (!pending_buffer_to_decrypt_) { |
| 189 DCHECK(pending_decrypt_cb_.is_null()); | 191 DCHECK(pending_decrypt_cb_.is_null()); |
| 190 DCHECK(!is_waiting_for_decryptor_); | 192 DCHECK(!is_waiting_for_decryptor_); |
| 191 return; | 193 return; |
| 192 } | 194 } |
| 193 | 195 |
| 194 DecryptCB decrypt_cb; | 196 DecryptCB decrypt_cb; |
| 195 if (!is_waiting_for_decryptor_) { | 197 if (!is_waiting_for_decryptor_) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 | 276 |
| 275 if (is_waiting_for_decryptor_) { | 277 if (is_waiting_for_decryptor_) { |
| 276 has_new_key_added_ = true; | 278 has_new_key_added_ = true; |
| 277 return; | 279 return; |
| 278 } | 280 } |
| 279 | 281 |
| 280 DecryptPendingBuffer(); | 282 DecryptPendingBuffer(); |
| 281 } | 283 } |
| 282 | 284 |
| 283 void ProxyDecryptor::DecryptPendingBuffer() { | 285 void ProxyDecryptor::DecryptPendingBuffer() { |
| 286 DVLOG(3) << "DecryptPendingBuffer()"; | |
| 284 DCHECK(decryption_message_loop_->BelongsToCurrentThread()); | 287 DCHECK(decryption_message_loop_->BelongsToCurrentThread()); |
| 285 DCHECK(pending_buffer_to_decrypt_); | 288 DCHECK(pending_buffer_to_decrypt_); |
| 286 DCHECK(!is_waiting_for_decryptor_); | 289 DCHECK(!is_waiting_for_decryptor_); |
| 287 | 290 |
| 288 is_waiting_for_decryptor_ = true; | 291 is_waiting_for_decryptor_ = true; |
| 289 decryptor_->Decrypt( | 292 decryptor_->Decrypt( |
| 290 pending_buffer_to_decrypt_, | 293 pending_buffer_to_decrypt_, |
| 291 base::Bind(&ProxyDecryptor::OnBufferDecrypted, base::Unretained(this))); | 294 base::Bind(&ProxyDecryptor::OnBufferDecrypted, base::Unretained(this))); |
| 292 } | 295 } |
| 293 | 296 |
| 294 void ProxyDecryptor::OnBufferDecrypted( | 297 void ProxyDecryptor::OnBufferDecrypted( |
| 295 media::Decryptor::Status status, | 298 media::Decryptor::Status status, |
| 296 const scoped_refptr<media::DecoderBuffer>& decrypted) { | 299 const scoped_refptr<media::DecoderBuffer>& decrypted) { |
| 297 if (!decryption_message_loop_->BelongsToCurrentThread()) { | 300 if (!decryption_message_loop_->BelongsToCurrentThread()) { |
| 298 decryption_message_loop_->PostTask(FROM_HERE, base::Bind( | 301 decryption_message_loop_->PostTask(FROM_HERE, base::Bind( |
| 299 &ProxyDecryptor::OnBufferDecrypted, base::Unretained(this), | 302 &ProxyDecryptor::OnBufferDecrypted, base::Unretained(this), |
| 300 status, decrypted)); | 303 status, decrypted)); |
| 301 return; | 304 return; |
| 302 } | 305 } |
| 303 | 306 |
| 307 DVLOG(2) << "OnBufferDecrypted() - status: " << status; | |
|
brettw
2012/10/12 19:44:06
I don't undrestand these DVLOG priorities. They se
| |
| 304 DCHECK(pending_buffer_to_decrypt_); | 308 DCHECK(pending_buffer_to_decrypt_); |
| 305 DCHECK(!pending_decrypt_cb_.is_null()); | 309 DCHECK(!pending_decrypt_cb_.is_null()); |
| 306 DCHECK(is_waiting_for_decryptor_); | 310 DCHECK(is_waiting_for_decryptor_); |
| 307 | 311 |
| 308 is_waiting_for_decryptor_ = false; | 312 is_waiting_for_decryptor_ = false; |
| 309 bool need_to_try_again_if_nokey_is_returned = has_new_key_added_; | 313 bool need_to_try_again_if_nokey_is_returned = has_new_key_added_; |
| 310 has_new_key_added_ = false; | 314 has_new_key_added_ = false; |
| 311 | 315 |
| 312 if (is_canceling_decrypt_) { | 316 if (is_canceling_decrypt_) { |
| 313 pending_buffer_to_decrypt_ = NULL; | 317 pending_buffer_to_decrypt_ = NULL; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 330 return; | 334 return; |
| 331 } | 335 } |
| 332 | 336 |
| 333 // TODO(xhwang): The same NeedKey may be fired multiple times here and also | 337 // TODO(xhwang): The same NeedKey may be fired multiple times here and also |
| 334 // in Decrypt(). While the spec says only one NeedKey should be fired. Leave | 338 // in Decrypt(). While the spec says only one NeedKey should be fired. Leave |
| 335 // them as is since the spec about this may change. | 339 // them as is since the spec about this may change. |
| 336 FireNeedKey(client_, pending_buffer_to_decrypt_); | 340 FireNeedKey(client_, pending_buffer_to_decrypt_); |
| 337 } | 341 } |
| 338 | 342 |
| 339 } // namespace webkit_media | 343 } // namespace webkit_media |
| OLD | NEW |