Chromium Code Reviews| Index: webkit/media/crypto/ppapi_decryptor.cc |
| diff --git a/webkit/media/crypto/ppapi_decryptor.cc b/webkit/media/crypto/ppapi_decryptor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..34afab48bc747f88fd30787879e2ab4ab5696287 |
| --- /dev/null |
| +++ b/webkit/media/crypto/ppapi_decryptor.cc |
| @@ -0,0 +1,81 @@ |
| +// 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/ppapi_decryptor.h" |
| + |
| +#include "base/logging.h" |
| +#include "media/base/decoder_buffer.h" |
| +#include "media/base/decryptor_client.h" |
| +#include "webkit/media/crypto/key_systems.h" |
| +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| + |
| +namespace webkit_media { |
| + |
| +PpapiDecryptor::PpapiDecryptor(media::DecryptorClient* client, |
| + const CreatePluginCB& create_plugin_cb) |
| + : client_(client), |
| + create_plugin_cb_(create_plugin_cb) { |
| +} |
| + |
| +PpapiDecryptor::~PpapiDecryptor() { |
| +} |
| + |
| +void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
| + const uint8* init_data, |
| + int init_data_length) { |
| + const char* plugin_name = GetPluginName(key_system); |
| + DCHECK(plugin_name); |
| + |
| + cdm_plugin_ = create_plugin_cb_.Run(plugin_name); |
|
ddorwin
2012/07/17 21:31:28
I think we should try to do this at creation time
xhwang
2012/07/18 19:43:17
Moved plugin creation into PpapiDecryptor::Init().
|
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + //if (!cdm_plugin_ || |
| + // !cdm_plugin_->GenerateKeyRequest(key_system, |
|
xhwang
2012/07/17 00:57:23
This call (and call to AddKey, CancelKeyRequest) a
|
| + // init_data, init_data_length)) { |
| + // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
| + //} |
| +} |
| + |
| +void PpapiDecryptor::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(cdm_plugin_); |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + //if (!cdm_plugin_->AddKey(key_system, key, key_length, |
| + // init_data, init_data_length, session_id)) { |
| + // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
| + //} |
| +} |
| + |
| +void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
| + const std::string& session_id) { |
| + DCHECK(cdm_plugin_); |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + //if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) |
| + // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
| +} |
| + |
| +void PpapiDecryptor::Decrypt( |
| + const scoped_refptr<media::DecoderBuffer>& encrypted, |
| + const DecryptCB& decrypt_cb) { |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + // TODO(xhwang): Need to figure out thread safety about PPP calls. |
|
xhwang
2012/07/17 00:57:23
I'll need to find a way to post this function to t
|
| + //if (!cdm_plugin_->Decrypt( |
| + // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { |
|
ddorwin
2012/07/17 21:31:28
indentation?
xhwang
2012/07/18 19:43:17
Done.
|
| + // decrypt_cb.Run(kError, NULL); |
| + //} |
| +} |
| + |
| +void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, |
| + const uint8* data, int data_size ) { |
| + // convert to DecoderBuffer or VideoFrame. then fire the callback! |
| + DCHECK(!decrypt_cb.is_null()); |
| + scoped_refptr<media::DecoderBuffer> decrypted = |
| + media::DecoderBuffer::CopyFrom(data, data_size); |
| + decrypt_cb.Run(kSuccess, decrypted); |
| +} |
| + |
| +} // namespace webkit_media |