Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/media/crypto/proxy_decryptor.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "media/base/decoder_buffer.h" | |
| 9 #include "media/base/decryptor_client.h" | |
| 10 #include "media/crypto/aes_decryptor.h" | |
| 11 #include "webkit/media/crypto/key_systems.h" | |
| 12 | |
| 13 namespace webkit_media { | |
| 14 | |
| 15 ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client) | |
| 16 : client_(client) { | |
| 17 } | |
| 18 | |
| 19 ProxyDecryptor::~ProxyDecryptor() { | |
| 20 } | |
| 21 | |
| 22 void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, | |
| 23 const uint8* init_data, | |
| 24 int init_data_length) { | |
| 25 // We do not support run-time switching of decryptors. GenerateKeyRequest() | |
| 26 // should only be called when the decryptor is not initialized, or on the | |
| 27 // existing decryptor associated with the |current_key_system_|. | |
| 28 DCHECK(!decryptor_.get() || key_system == current_key_system_); | |
| 29 | |
| 30 if (!decryptor_.get()) { | |
|
ddorwin
2012/06/27 04:00:08
Do we assume that decryptor_ is set always on the
xhwang
2012/06/27 21:41:26
Added comment about |lock_| in .h file.
| |
| 31 if (key_system == kClearKeyKeySystem) { | |
| 32 base::AutoLock auto_lock(lock_); | |
|
ddorwin
2012/06/27 04:00:08
If we don't need to lock above, why are we locking
xhwang
2012/06/27 21:41:26
Added comment about |lock_| in .h file.
| |
| 33 decryptor_.reset(new media::AesDecryptor(client_)); | |
| 34 current_key_system_ = key_system; | |
| 35 } else { | |
| 36 NOTREACHED(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); | |
| 41 } | |
| 42 | |
| 43 void ProxyDecryptor::AddKey(const std::string& key_system, | |
| 44 const uint8* key, | |
| 45 int key_length, | |
| 46 const uint8* init_data, | |
| 47 int init_data_length, | |
| 48 const std::string& session_id) { | |
| 49 DCHECK(decryptor_.get()); | |
|
ddorwin
2012/06/27 04:00:08
// WMPI ensures GenerateKeyRequest() has been call
xhwang
2012/06/27 21:41:26
Done.
| |
| 50 DCHECK_EQ(current_key_system_, key_system); | |
| 51 decryptor_->AddKey(key_system, key, key_length, init_data, init_data_length, | |
| 52 session_id); | |
| 53 } | |
| 54 | |
| 55 void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, | |
| 56 const std::string& session_id) { | |
| 57 DCHECK(decryptor_.get()); | |
| 58 DCHECK_EQ(current_key_system_, key_system); | |
| 59 decryptor_->CancelKeyRequest(key_system, session_id); | |
| 60 } | |
| 61 | |
| 62 scoped_refptr<media::DecoderBuffer> ProxyDecryptor::Decrypt( | |
| 63 const scoped_refptr<media::DecoderBuffer>& input) { | |
| 64 // This is safe as we do not replace/delete an existing decryptor at run-time. | |
| 65 Decryptor* decryptor = NULL; | |
| 66 { | |
| 67 base::AutoLock auto_lock(lock_); | |
| 68 decryptor = decryptor_.get(); | |
| 69 } | |
| 70 if (!decryptor) | |
| 71 return NULL; | |
| 72 | |
| 73 return decryptor->Decrypt(input); | |
| 74 } | |
| 75 | |
| 76 } // namespace webkit_media | |
| OLD | NEW |