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..20743c7184b983cb6da2791ac1a0aac959598a8c 100644 |
--- a/webkit/media/crypto/ppapi_decryptor.cc |
+++ b/webkit/media/crypto/ppapi_decryptor.cc |
@@ -4,7 +4,13 @@ |
#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 "media/base/decoder_buffer.h" |
#include "media/base/decryptor_client.h" |
#include "webkit/media/crypto/key_systems.h" |
@@ -16,7 +22,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_(base::MessageLoopProxy::current()) { |
+ DCHECK(client_); |
+ DCHECK(cdm_plugin_); |
+ cdm_plugin_->set_decrypt_client(client); |
} |
PpapiDecryptor::~PpapiDecryptor() { |
@@ -25,12 +35,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); |
- // } |
+ |
+ if (!cdm_plugin_->GenerateKeyRequest( |
+ key_system, |
+ std::string(reinterpret_cast<const char*>(init_data), |
dmichael (off chromium)
2012/08/27 20:14:48
Could you add a TODO here about figuring out what
xhwang
2012/08/27 22:58:14
Done.
|
+ init_data_length))) { |
+ ReportFailureToCallPlugin(key_system, ""); |
+ } |
} |
void PpapiDecryptor::AddKey(const std::string& key_system, |
@@ -39,43 +53,52 @@ 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, |
- // init_data, init_data_length, session_id)) { |
- // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
- // } |
+ |
+ if (!cdm_plugin_->AddKey(session_id, |
+ std::string(reinterpret_cast<const char*>(key), |
+ key_length), |
+ std::string(reinterpret_cast<const char*>(init_data), |
+ init_data_length))) { |
+ ReportFailureToCallPlugin(key_system, session_id); |
+ } |
} |
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)) |
- // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
+ |
+ if (!cdm_plugin_->CancelKeyRequest(session_id)) |
+ ReportFailureToCallPlugin(key_system, session_id); |
} |
void PpapiDecryptor::Decrypt( |
const scoped_refptr<media::DecoderBuffer>& encrypted, |
const DecryptCB& decrypt_cb) { |
- 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); |
- // } |
+ DVLOG(1) << "Decrypt()"; |
+ if (!render_loop_proxy_->BelongsToCurrentThread()) { |
+ render_loop_proxy_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this), |
+ encrypted, decrypt_cb)); |
+ return; |
+ } |
+ |
+ if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb)) |
+ decrypt_cb.Run(kError, NULL); |
} |
void PpapiDecryptor::Stop() { |
} |
-void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, |
- const uint8* data, int data_size ) { |
- DCHECK(!decrypt_cb.is_null()); |
- scoped_refptr<media::DecoderBuffer> decrypted_data = |
- media::DecoderBuffer::CopyFrom(data, data_size); |
- decrypt_cb.Run(kSuccess, decrypted_data); |
+void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, |
+ const std::string& session_id) { |
+ DVLOG(1) << "Failed to call plugin."; |
+ client_->KeyError(key_system, session_id, kUnknownError, 0); |
} |
} // namespace webkit_media |