Chromium Code Reviews| Index: webkit/media/crypto/proxy_decryptor.cc |
| diff --git a/webkit/media/crypto/proxy_decryptor.cc b/webkit/media/crypto/proxy_decryptor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..36db7d02cb81e416905eba466400051c32299037 |
| --- /dev/null |
| +++ b/webkit/media/crypto/proxy_decryptor.cc |
| @@ -0,0 +1,76 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "webkit/media/crypto/proxy_decryptor.h" |
| + |
| +#include "base/logging.h" |
| +#include "media/base/decoder_buffer.h" |
| +#include "media/base/decryptor_client.h" |
| +#include "media/crypto/aes_decryptor.h" |
| +#include "webkit/media/crypto/key_systems.h" |
| + |
| +namespace webkit_media { |
| + |
| +ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client) |
| + : client_(client) { |
| +} |
| + |
| +ProxyDecryptor::~ProxyDecryptor() { |
| +} |
| + |
| +void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, |
| + const uint8* init_data, |
| + int init_data_length) { |
| + // We do not support run-time switching of decryptors. GenerateKeyRequest() |
| + // should only be called when the decryptor is not initialized, or on the |
| + // existing decryptor associated with the |current_key_system_|. |
| + DCHECK(!decryptor_.get() || key_system == current_key_system_); |
| + |
| + 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.
|
| + if (key_system == kClearKeyKeySystem) { |
| + 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.
|
| + decryptor_.reset(new media::AesDecryptor(client_)); |
| + current_key_system_ = key_system; |
| + } else { |
| + NOTREACHED(); |
| + } |
| + } |
| + |
| + decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); |
| +} |
| + |
| +void ProxyDecryptor::AddKey(const std::string& key_system, |
| + const uint8* key, |
| + int key_length, |
| + const uint8* init_data, |
| + int init_data_length, |
| + const std::string& session_id) { |
| + DCHECK(decryptor_.get()); |
|
ddorwin
2012/06/27 04:00:08
// WMPI ensures GenerateKeyRequest() has been call
xhwang
2012/06/27 21:41:26
Done.
|
| + DCHECK_EQ(current_key_system_, key_system); |
| + decryptor_->AddKey(key_system, key, key_length, init_data, init_data_length, |
| + session_id); |
| +} |
| + |
| +void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, |
| + const std::string& session_id) { |
| + DCHECK(decryptor_.get()); |
| + DCHECK_EQ(current_key_system_, key_system); |
| + decryptor_->CancelKeyRequest(key_system, session_id); |
| +} |
| + |
| +scoped_refptr<media::DecoderBuffer> ProxyDecryptor::Decrypt( |
| + const scoped_refptr<media::DecoderBuffer>& input) { |
| + // This is safe as we do not replace/delete an existing decryptor at run-time. |
| + Decryptor* decryptor = NULL; |
| + { |
| + base::AutoLock auto_lock(lock_); |
| + decryptor = decryptor_.get(); |
| + } |
| + if (!decryptor) |
| + return NULL; |
| + |
| + return decryptor->Decrypt(input); |
| +} |
| + |
| +} // namespace webkit_media |