| 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/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 |
| 12 namespace webkit_media { |
| 13 |
| 14 namespace { |
| 15 |
| 16 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client) |
| 21 : client_(client) { |
| 22 } |
| 23 |
| 24 ProxyDecryptor::~ProxyDecryptor() { |
| 25 } |
| 26 |
| 27 void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, |
| 28 const uint8* init_data, |
| 29 int init_data_length) { |
| 30 // We do not support run-time switching of decryptors. GenerateKeyRequest() |
| 31 // should only be called when the decryptor is not initialized, or on the |
| 32 // existing decryptor associated with the |current_key_system_|. |
| 33 DCHECK(!decryptor_.get() || key_system == current_key_system_); |
| 34 |
| 35 if (!decryptor_.get()) { |
| 36 if (key_system == kClearKeyKeySystem) { |
| 37 base::AutoLock auto_lock(lock_); |
| 38 decryptor_.reset(new media::AesDecryptor(client_)); |
| 39 current_key_system_ = key_system; |
| 40 } else { |
| 41 NOTREACHED(); |
| 42 } |
| 43 } |
| 44 |
| 45 decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); |
| 46 } |
| 47 |
| 48 void ProxyDecryptor::AddKey(const std::string& key_system, |
| 49 const uint8* key, |
| 50 int key_length, |
| 51 const uint8* init_data, |
| 52 int init_data_length, |
| 53 const std::string& session_id) { |
| 54 DCHECK(decryptor_.get() && key_system == current_key_system_); |
| 55 decryptor_->AddKey(key_system, key, key_length, init_data, init_data_length, |
| 56 session_id); |
| 57 } |
| 58 |
| 59 void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, |
| 60 const std::string& session_id) { |
| 61 DCHECK(decryptor_.get() && key_system == current_key_system_); |
| 62 decryptor_->CancelKeyRequest(key_system, session_id); |
| 63 } |
| 64 |
| 65 scoped_refptr<media::DecoderBuffer> ProxyDecryptor::Decrypt( |
| 66 const scoped_refptr<media::DecoderBuffer>& input) { |
| 67 // This is safe as we do not replace/delete an existing decryptor at run-time. |
| 68 Decryptor* decryptor = NULL; |
| 69 { |
| 70 base::AutoLock auto_lock(lock_); |
| 71 decryptor = decryptor_.get(); |
| 72 } |
| 73 if (!decryptor) |
| 74 return NULL; |
| 75 |
| 76 return decryptor->Decrypt(input); |
| 77 } |
| 78 |
| 79 } // namespace webkit_media |
| OLD | NEW |