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..1e4b3baac638d05070b3d5b2046f32bfd075cbef 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,12 @@ 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()) { |
+ DCHECK(client_); |
+ DCHECK(cdm_plugin_); |
+ cdm_plugin_->set_decrypt_client(client); |
} |
PpapiDecryptor::~PpapiDecryptor() { |
@@ -25,12 +37,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), |
+ init_data_length))) { |
+ ReportError(key_system, ""); |
+ } |
} |
void PpapiDecryptor::AddKey(const std::string& key_system, |
@@ -39,43 +55,51 @@ 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))) { |
+ ReportError(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)) |
+ ReportError(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::ReportError(const std::string& key_system, |
+ const std::string& session_id) { |
+ client_->KeyError(key_system, session_id, kUnknownError, 0); |
ddorwin
2012/08/24 05:54:43
The intent was to DLOG "failed calling plugin". Th
xhwang
2012/08/24 16:57:46
Done.
|
} |
} // namespace webkit_media |