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

Unified Diff: webkit/media/proxy_decryptor.cc

Issue 10575026: Add ProxyDecryptor which wraps concrete Decryptor implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
Index: webkit/media/proxy_decryptor.cc
diff --git a/webkit/media/proxy_decryptor.cc b/webkit/media/proxy_decryptor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9282561f856c910c27676804f6ecb763106d03ef
--- /dev/null
+++ b/webkit/media/proxy_decryptor.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/media/proxy_decryptor.h"
+
+#include "base/logging.h"
+#include "media/base/decoder_buffer.h"
+#include "media/base/decryptor_client.h"
+#include "media/crypto/aes_decryptor.h"
+
+namespace webkit_media {
+
+namespace {
+
+const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
+
+} // namespace
+
+ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client)
+ : client_(client) {
+}
+
+ProxyDecryptor::~ProxyDecryptor() {
+}
+
+void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system,
+ const uint8* init_data,
+ int init_data_length) {
+ // We do not support run-time switching of decryptors. GenerateKeyRequest()
+ // should only be called when the decryptor is not initialized, or on the
+ // existing decryptor associated with the |current_key_system_|.
+ DCHECK(!decryptor_.get() || key_system == current_key_system_);
+
+ if (!decryptor_.get()) {
+ if (key_system == kClearKeyKeySystem) {
+ base::AutoLock auto_lock(lock_);
+ decryptor_.reset(new media::AesDecryptor(client_));
+ current_key_system_ = key_system;
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length);
+}
+
+void ProxyDecryptor::AddKey(const std::string& key_system,
+ const uint8* key,
+ int key_length,
+ const uint8* init_data,
+ int init_data_length,
+ const std::string& session_id) {
+ DCHECK(decryptor_.get() && key_system == current_key_system_);
+ decryptor_->AddKey(key_system, key, key_length, init_data, init_data_length,
+ session_id);
+}
+
+void ProxyDecryptor::CancelKeyRequest(const std::string& key_system,
+ const std::string& session_id) {
+ DCHECK(decryptor_.get() && key_system == current_key_system_);
+ decryptor_->CancelKeyRequest(key_system, session_id);
+}
+
+scoped_refptr<media::DecoderBuffer> ProxyDecryptor::Decrypt(
+ const scoped_refptr<media::DecoderBuffer>& input) {
+ // This is safe as we do not replace/delete an existing decryptor at run-time.
+ Decryptor* decryptor = NULL;
+ {
+ base::AutoLock auto_lock(lock_);
+ decryptor = decryptor_.get();
+ }
+ if (!decryptor)
+ return NULL;
+
+ return decryptor->Decrypt(input);
+}
+
+} // namespace webkit_media

Powered by Google App Engine
This is Rietveld 408576698