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

Unified Diff: webkit/media/crypto/content_decryption_module.h

Issue 10823299: Add ContentDecryptionModule interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve ddorwin's comments. 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/media/crypto/content_decryption_module.h
diff --git a/webkit/media/crypto/content_decryption_module.h b/webkit/media/crypto/content_decryption_module.h
new file mode 100644
index 0000000000000000000000000000000000000000..48f950f56f5fb234c6762e15334c26b0e82a8970
--- /dev/null
+++ b/webkit/media/crypto/content_decryption_module.h
@@ -0,0 +1,150 @@
+// 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.
+
+#ifndef WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_
+#define WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_
+
+#if defined(_MSC_VER)
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+typedef __int64 int64_t;
+#else
+#include <stdint.h>
+#endif
+
+namespace cdm {
+class ContentDecryptionModule;
+}
+
+extern "C" cdm::ContentDecryptionModule* CreateCdmInstance();
+extern "C" void DestroyCdmInstance(cdm::ContentDecryptionModule* instance);
+extern "C" const char* GetCdmVersion();
+
+namespace cdm {
+
+// An input buffer can be split into several continuous subsamples.
+// A SubsampleEntry specifies the number of clear and cipher bytes in each
+// subsample. For example, the following buffer has three subsamples:
+//
+// |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
+// | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 |
+//
+// For decryption, all of the cipher bytes in a buffer should be concatenated
+// (in the subsample order) into a single logical stream. The clear bytes should
+// not be considered as part of decryption.
+//
+// Stream to decrypt: | cipher1 | cipher2 | cipher3 |
+// Decrypted stream: | decrypted1| decrypted2 | decrypted3 |
+//
+// After decryption, the decrypted bytes should be copied over the position
+// of the corresponding cipher bytes in the original buffer to form the output
+// buffer. Following the above example, the decrypted buffer should be:
+//
+// |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
+// | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 |
+//
+// TODO(xhwang): Add checks to make sure these structs have fixed layout.
+struct SubsampleEntry {
+ uint32_t clear_bytes;
+ uint32_t cipher_bytes;
+};
+
+struct InputBuffer {
+ uint8_t* data; // Pointer to the beginning of the input data.
+ uint32_t data_size; // Size (in bytes) of |data|.
+
+ uint32_t data_offset; // Number of bytes to be discarded before decryption.
+
+ uint8_t* key_id; // Key ID to identify the decryption key.
+ uint32_t key_id_size; // Size (in bytes) of |key_id|.
+
+ uint8_t* iv; // Initialization vector.
+ uint32_t iv_size; // Size (in bytes) of |iv|.
+
+ uint8_t* checksum;
+ uint32_t checksum_size; // Size (in bytes) of the |checksum|.
+
+ struct SubsampleEntry* subsamples;
+ uint32_t num_subsamples; // Number of subsamples in |subsamples|.
+
+ int64_t timestamp; // Presentation timestamp in milliseconds.
+ int64_t duration; // Duration in milliseconds.
+};
+
+struct OutputBuffer {
+ uint8_t* data; // Pointer to the beginning of the output data.
+ uint32_t data_size; // Size (in bytes) of |data|.
+
+ int64_t timestamp; // Presentation timestamp in milliseconds.
+ int64_t duration; // Duration in milliseconds.
+};
+
+class ContentDecryptionModule {
+ public:
+ enum Status {
+ kSuccess = 0,
+ kErrorUnknown,
+ kErrorNoKey
+ };
+
+ // Generates a |key_request| as well as a |session_id| given the |init_data|.
+ // The CDM may also extract a |default_url|.
+ // Returns kSuccess if the key request was successfully generated,
+ // in which case the callee should have allocated memory for the output
+ // parameters (e.g |session_id|) and passed the ownership to the caller.
+ // Returns kErrorUnknown otherwise, in which case the output
+ // parameters should not be used by the caller.
+ //
+ // TODO(xhwang): It's not safe to pass the ownership of the dynamically
+ // allocated memory over library boundaries. Fix it after related PPAPI change
+ // are sample CDM are landed.
ddorwin 2012/08/16 17:16:39 s/are/and/
xhwang 2012/08/16 20:27:22 Done.
+ virtual Status GenerateKeyRequest(const uint8_t* init_data,
+ int init_data_size,
+ char** session_id,
+ int* session_id_size,
+ uint8_t** key_request,
+ int* key_request_size,
+ char** default_url,
+ int* default_url_size) = 0;
+
+ // Adds the |key| to the CDM to be associated with |key_id|.
+ // Returns kSuccess if the key was successfully added.
+ // Returns kErrorUnknown otherwise.
+ virtual Status AddKey(const char* session_id,
+ int session_id_size,
+ const uint8_t* key,
+ int key_size,
+ const uint8_t* key_id,
+ int key_id_size) = 0;
+
+ // Cancels any pending key request made to the CDM for |session_id|.
+ // Returns kSuccess if all pending key requests for |session_id| were
+ // successfully canceled or there was no key request to be canceled.
+ // Returns kErrorUnknown otherwise.
+ virtual Status CancelKeyRequest(const char* session_id,
+ int session_id_size) = 0;
+
+ // Decrypts the |encrypted_buffer|.
+ // Returns kSuccess if decryption succeeded, in which case the callee
+ // should have filled the |decrypted_buffer| and passed the ownership of
+ // |data| in |decrypted_buffer| to the caller.
+ // Returns kErrorNoKey if the CDM did not have the necessary decryption key
+ // to decrypt.
+ // Returns kErrorUnknown if any other error happened.
+ // In these two cases, |decrypted_buffer| should not be used by the caller.
+ //
+ // TODO(xhwang): It's not safe to pass the ownership of the dynamically
+ // allocated memory over library boundaries. Fix it after related PPAPI change
+ // are sample CDM are landed.
ddorwin 2012/08/16 17:16:39 same
xhwang 2012/08/16 20:27:22 Done.
+ virtual Status Decrypt(const char* session_id,
+ int session_id_size,
+ const InputBuffer& encrypted_buffer,
+ OutputBuffer* decrypted_buffer) = 0;
+
+ virtual ~ContentDecryptionModule() {};
+};
+
+} // namespace cdm
+
+#endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698