Index: webkit/media/crypto/ppapi_decryptor.cc |
diff --git a/webkit/media/crypto/ppapi_decryptor.cc b/webkit/media/crypto/ppapi_decryptor.cc |
index f547f687dcb2212769571d599141f6e9da991522..894a223696e32e8053cfc4f6805cc407ac2a9d78 100644 |
--- a/webkit/media/crypto/ppapi_decryptor.cc |
+++ b/webkit/media/crypto/ppapi_decryptor.cc |
@@ -4,7 +4,14 @@ |
#include "webkit/media/crypto/ppapi_decryptor.h" |
+#include <string> |
+ |
+#include "base/bind.h" |
+#include "base/location.h" |
#include "base/logging.h" |
+#include "base/message_loop.h" |
+#include "base/message_loop_proxy.h" |
+#include "content/public/renderer/render_thread.h" |
#include "media/base/decoder_buffer.h" |
#include "media/base/decryptor_client.h" |
#include "webkit/media/crypto/key_systems.h" |
@@ -16,7 +23,11 @@ PpapiDecryptor::PpapiDecryptor( |
media::DecryptorClient* client, |
const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance) |
: client_(client), |
- cdm_plugin_(plugin_instance) { |
+ cdm_plugin_(plugin_instance), |
+ render_loop_proxy_(content::RenderThread::Get()->GetMessageLoop() |
+ ->message_loop_proxy()) { |
dmichael (off chromium)
2012/08/09 16:24:52
nit: indentation is off.
Would it fit if you brea
|
+ DCHECK(cdm_plugin_); |
+ cdm_plugin_->SetDecryptClient(client); |
} |
PpapiDecryptor::~PpapiDecryptor() { |
@@ -25,12 +36,16 @@ PpapiDecryptor::~PpapiDecryptor() { |
void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
const uint8* init_data, |
int init_data_length) { |
+ DVLOG(1) << "GenerateKeyRequest()"; |
+ DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
DCHECK(cdm_plugin_); |
+ |
// TODO(xhwang): Enable the following once we have updated PluginInstance. |
- // if (!cdm_plugin_->GenerateKeyRequest(key_system, |
- // init_data, init_data_length)) { |
- // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
- // } |
+ std::string init_data_string(reinterpret_cast<const char*>(init_data), |
+ init_data_length); |
+ if (!cdm_plugin_->GenerateKeyRequest(key_system, init_data_string)) { |
+ client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
+ } |
} |
void PpapiDecryptor::AddKey(const std::string& key_system, |
@@ -39,6 +54,8 @@ void PpapiDecryptor::AddKey(const std::string& key_system, |
const uint8* init_data, |
int init_data_length, |
const std::string& session_id) { |
+ DVLOG(1) << "AddKey()"; |
+ DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
DCHECK(cdm_plugin_); |
// TODO(xhwang): Enable the following once we have updated PluginInstance. |
// if (!cdm_plugin_->AddKey(key_system, key, key_length, |
@@ -49,6 +66,8 @@ void PpapiDecryptor::AddKey(const std::string& key_system, |
void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
const std::string& session_id) { |
+ DVLOG(1) << "CancelKeyRequest()"; |
+ DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
DCHECK(cdm_plugin_); |
// TODO(xhwang): Enable the following once we have updated PluginInstance. |
// if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) |
@@ -58,23 +77,49 @@ void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
void PpapiDecryptor::Decrypt( |
const scoped_refptr<media::DecoderBuffer>& encrypted, |
const DecryptCB& decrypt_cb) { |
+ DVLOG(1) << "Decrypt()"; |
DCHECK(cdm_plugin_); |
- // TODO(xhwang): Enable the following once we have updated PluginInstance. |
- // TODO(xhwang): Need to figure out thread safety about PPP calls. |
- // if (!cdm_plugin_->Decrypt( |
- // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { |
- // decrypt_cb.Run(kError, NULL); |
- // } |
+ |
+ if (!render_loop_proxy_->BelongsToCurrentThread()) { |
+ render_loop_proxy_->PostTask(FROM_HERE, base::Bind(&PpapiDecryptor::Decrypt, |
+ base::Unretained(this), |
+ encrypted, decrypt_cb)); |
+ return; |
+ } |
+ |
+ cdm_plugin_->Decrypt(encrypted, base::Bind(&PpapiDecryptor::DataReady, |
+ base::Unretained(this), |
+ decrypt_cb)); |
+ |
+ // TODO(xhwang): This is a hack only for testing purpose. |
+ for (int i = 0; i < 4; ++i ) { |
+ cdm_plugin_->Decrypt(encrypted, base::Bind(&PpapiDecryptor::DataReady, |
+ base::Unretained(this), |
+ DecryptCB())); |
+ } |
} |
void PpapiDecryptor::Stop() { |
} |
void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, |
- const uint8* data, int data_size ) { |
- DCHECK(!decrypt_cb.is_null()); |
+ void* data, int data_size ) { |
+ DVLOG(1) << "DataReady()"; |
+ DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
+ |
+ // TODO(xhwang): This is a hack only for testing purpose. |
+ if (decrypt_cb.is_null()) |
+ return; |
+ |
+ if (!data || !data_size) { |
+ decrypt_cb.Run(kError, NULL); |
+ return; |
+ } |
+ |
scoped_refptr<media::DecoderBuffer> decrypted_data = |
- media::DecoderBuffer::CopyFrom(data, data_size); |
+ media::DecoderBuffer::CopyFrom(reinterpret_cast<const uint8*>(data), |
+ data_size); |
+ DCHECK(!decrypt_cb.is_null()); |
decrypt_cb.Run(kSuccess, decrypted_data); |
} |