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..0a1c33486225c6e9dd67fa33a4e9de0002f7c27a |
| --- /dev/null |
| +++ b/webkit/media/crypto/proxy_decryptor.cc |
| @@ -0,0 +1,79 @@ |
| +// 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" |
| + |
| +namespace webkit_media { |
| + |
| +namespace { |
| + |
| +const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
|
scherkus (not reviewing)
2012/06/21 21:17:16
this is declared in webkit/media/key_systems.cc --
xhwang
2012/06/22 16:57:30
Will do.
xhwang
2012/06/26 23:45:50
Done.
|
| + |
| +} // namespace |
| + |
| +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()) { |
| + if (key_system == kClearKeyKeySystem) { |
| + base::AutoLock auto_lock(lock_); |
| + decryptor_.reset(new media::AesDecryptor(client_)); |
|
scherkus (not reviewing)
2012/06/21 21:17:16
is there a disadvantage to creating this in the ct
xhwang
2012/06/22 16:57:30
Currently we don't allow run-time switching betwee
|
| + current_key_system_ = key_system; |
| + } else { |
| + NOTREACHED(); |
|
scherkus (not reviewing)
2012/06/21 21:17:16
can these DCHECKs be triggered via JS? i.e., I cal
xhwang
2012/06/22 16:57:30
No. The WMPI will check IsSupportedKeySystem() and
|
| + } |
| + } |
| + |
| + 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() && key_system == current_key_system_); |
|
scherkus (not reviewing)
2012/06/21 21:17:16
instead of && split the DCHECKs
xhwang
2012/06/22 16:57:30
Will do.
xhwang
2012/06/26 23:45:50
Done.
|
| + 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() && key_system == current_key_system_); |
|
scherkus (not reviewing)
2012/06/21 21:17:16
instead of && split the DCHECKs
xhwang
2012/06/22 16:57:30
Will do.
xhwang
2012/06/26 23:45:50
Done.
|
| + 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 |