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

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

Issue 10575026: Add ProxyDecryptor which wraps concrete Decryptor implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits and rebased. 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
« no previous file with comments | « webkit/media/crypto/proxy_decryptor.h ('k') | webkit/media/key_systems.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/media/crypto/proxy_decryptor.cc
diff --git a/webkit/media/crypto/proxy_decryptor.cc b/webkit/media/crypto/proxy_decryptor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e44e6f49a21d0a896b81b2d2ff6fc855006df979
--- /dev/null
+++ b/webkit/media/crypto/proxy_decryptor.cc
@@ -0,0 +1,69 @@
+// 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/crypto/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"
+#include "webkit/media/crypto/key_systems.h"
+
+namespace webkit_media {
+
+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()
+ // only creates a new decryptor when |decryptor_| is not initialized.
+ if (!decryptor_.get()) {
+ base::AutoLock auto_lock(lock_);
+ decryptor_ = CreateDecryptor(key_system, client_);
+ }
+
+ DCHECK(decryptor_.get());
+ 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) {
+ // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
+ DCHECK(decryptor_.get());
+ 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) {
+ // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
+ DCHECK(decryptor_.get());
+ 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
« no previous file with comments | « webkit/media/crypto/proxy_decryptor.h ('k') | webkit/media/key_systems.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698