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..0d3449d3a240fe22380a879cefa49e694c662d95 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" |
ddorwin
2012/08/22 01:26:26
What is this used for?
xhwang
2012/08/24 00:51:51
For FROM_HERE in PostTask.
|
#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_->SetDecryptClient(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()"; |
ddorwin
2012/08/22 01:26:26
Probably worth providing context (PPAPI) since Aes
xhwang
2012/08/24 00:51:51
In the logging, it will always show the file name
|
+ DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
ddorwin
2012/08/22 01:26:26
It's not obvious why this needs to be the case in
xhwang
2012/08/24 00:51:51
I guess this is just another (better) way to comme
|
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), |
ddorwin
2012/08/22 01:26:26
It's unfortunate we have to do this cast in multip
dmichael (off chromium)
2012/08/22 20:30:15
It's not really clear to me why we pass a string i
xhwang
2012/08/24 00:51:51
We discussed this before, and decided to use:
- st
xhwang
2012/08/24 00:51:51
Yes, if we decided to use pointer/size for init_da
dmichael (off chromium)
2012/08/24 17:18:34
The performance wouldn't bother me if the code was
|
+ init_data_length))) { |
+ client_->KeyError(key_system, "", kUnknownError, 0); |
Tom Finegan
2012/08/22 01:05:47
nit: one line statement in the if, not sure about
ddorwin
2012/08/22 01:26:26
You might move this to a helper function and log "
xhwang
2012/08/24 00:51:51
Done.
xhwang
2012/08/24 00:51:51
I remember we should use curly braces when the if(
|
+ } |
} |
void PpapiDecryptor::AddKey(const std::string& key_system, |
@@ -39,43 +55,47 @@ 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, |
ddorwin
2012/08/22 01:26:26
nit: It seems this would look better if indented f
dmichael (off chromium)
2012/08/22 20:30:15
Agreed... I think it should be 4 from the open pa
xhwang
2012/08/24 00:51:51
Done. But not sure if this is what you meant.
|
+ std::string(reinterpret_cast<const char*>(key), key_length), |
+ std::string(reinterpret_cast<const char*>(init_data), |
+ init_data_length))) { |
+ client_->KeyError(key_system, session_id, kUnknownError, 0); |
ddorwin
2012/08/22 01:26:26
Does client always post to ensure we never report
xhwang
2012/08/24 00:51:51
Yes, the client is the webmediaplayer_proxy, which
|
+ } |
} |
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)) |
+ client_->KeyError(key_system, session_id, kUnknownError, 0); |
} |
void PpapiDecryptor::Decrypt( |
const scoped_refptr<media::DecoderBuffer>& encrypted, |
ddorwin
2012/08/22 01:26:26
Is it possible to avoid refptr for this?
xhwang
2012/08/24 00:51:51
I think the rule is if |encrypted| is a scoped_ref
|
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; |
+ } |
-void PpapiDecryptor::Stop() { |
+ if (cdm_plugin_->Decrypt(encrypted, decrypt_cb)) { |
ddorwin
2012/08/22 01:26:26
Missing a '!' ?
xhwang
2012/08/24 00:51:51
Oops, thanks for catching this. Done.
|
+ decrypt_cb.Run(kError, NULL); |
+ } |
} |
-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::Stop() { |
} |
} // namespace webkit_media |