Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: webkit/media/crypto/ppapi_decryptor.cc

Issue 10871006: Connect PpapiDecryptor and PluginInstance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a minor bug happened during code copying. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/media/crypto/ppapi_decryptor.h ('k') | webkit/plugins/ppapi/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..70c4b1b3685c686fd648e641b6a87311350c8695 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,18 @@ 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);
- // }
+
+ // TODO(xhwang): Finalize the data type for |init_data| to avoid unnecessary
+ // data type conversions.
+ if (!cdm_plugin_->GenerateKeyRequest(
+ key_system,
+ std::string(reinterpret_cast<const char*>(init_data),
+ init_data_length))) {
+ ReportFailureToCallPlugin(key_system, "");
+ }
}
void PpapiDecryptor::AddKey(const std::string& key_system,
@@ -39,43 +55,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
« no previous file with comments | « webkit/media/crypto/ppapi_decryptor.h ('k') | webkit/plugins/ppapi/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698