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..099cd55c7982ca658b27ea0c1ee0d009bc03c039 |
--- /dev/null |
+++ b/webkit/media/crypto/content_decryption_module.h |
@@ -0,0 +1,123 @@ |
+// 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 __int64 int64_t; |
+#else |
+#include <stdint.h> |
+#endif |
+ |
+class ContentDecryptionModule; |
+ |
+extern ContentDecryptionModule* CdmCreateInstance(); |
+extern const char* CdmGetVersion(); |
+ |
+enum CdmStatus { |
+ kCdmStatusSuccess = 0, |
+ kCdmStatusErrorUnknown, |
+ kCdmStatusErrorNoKey |
+}; |
+ |
+// An input buffer can be split into several continuous subsamples. |
+// A SubsampleEntry specifies the number of clear and cypher bytes in each |
+// subsample. For example, the following buffer has three subsamples: |
+// |
+// |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
+// | clear1 | cypher1 | clear2 | cypher2 | clear3 | cypher3 | |
+// |
+// For decryption, all of the cypher 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: | cypher1 | cypher2 | cypher3 | |
+// Decrypted stream: |decryped1| decryped2 | decryped3 | |
+// |
+// After decryption, the decrypted bytes should be copied over the position |
+// of the corresponding cypher bytes in the original buffer to form the output |
+// buffer. Following the above example, the decrypted buffer should be: |
+// |
+// |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
+// | clear1 |decryped1| clear2 | decryped2 | clear3 | decryped3 | |
+// |
+struct SubsampleEntry { |
+ int clear_bytes; |
+ int cypher_bytes; |
+}; |
+ |
+struct InputBuffer { |
+ uint8_t* data; // Pointer to the beginning of the input data. |
+ int data_size; // Size (in bytes) of |data|. |
+ int data_offset; // Number of bytes to be discarded before decryption. |
+ uint8_t* key_id; // Key ID to identify the decryption key. |
+ int key_id_size; // Size (in bytes) of |key_id|. |
+ uint8_t* iv; // Initialization vector. |
+ int iv_size; // Size (in bytes) of |iv|. |
+ uint8_t* checksum; |
+ int checksum_size; // Size (in bytes) of the |checksum|. |
+ struct SubsampleEntry* subsamples; |
+ int 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. |
+ int data_size; // Size (in bytes) of |data|. |
+ int64_t timestamp; // Presentation timestamp in milliseconds. |
+ int64_t duration; // Duration in milliseconds. |
+}; |
+ |
+class ContentDecryptionModule { |
+ public: |
+ // Generates a |key_request| as well as a |session_id| given the |init_data|. |
+ // The CDM may also generate a |default_url|. |
ddorwin
2012/08/15 02:14:57
s/generate/extract/
xhwang
2012/08/15 04:27:46
Done.
|
+ // Returns kCdmStatusSuccess if the key request is successfully generated, |
+ // in which case the callee should allocates memory for the output parameters |
ddorwin
2012/08/15 02:14:57
s/should/should have/.
After the return, that happ
xhwang
2012/08/15 04:27:46
Done.
|
+ // (e.g session_id) and takes ownership of them. |
ddorwin
2012/08/15 02:14:57
But isn't ownership passed to the caller on return
xhwang
2012/08/15 04:27:46
Done.
|
+ // Returns kCdmStatusErrorUnknown otherwise, in which case the output |
+ // parameters should not be used by the caller. |
+ virtual CdmStatus 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. |
+ // Returns kCdmStatusSuccess if the key is successfully added. |
+ // Returns kCdmStatusErrorUnknown otherwise. |
+ virtual CdmStatus AddKey(const char* session_id, |
+ int session_id_size, |
+ const uint8_t* key, |
+ int key_size) = 0; |
+ |
+ // Cancels any pending key request made to the CDM for |session_id|. |
+ // Returns kCdmStatusSuccess if there is no key request to be canceled or |
ddorwin
2012/08/15 02:14:57
I would swap the phrases around "or" since the lat
xhwang
2012/08/15 04:27:46
Done.
|
+ // all pending key requests for |session_id| are successfully canceled. |
+ // Returns kCdmStatusErrorUnknown otherwise. |
+ virtual CdmStatus CancelKeyRequest(const char* session_id, |
+ int session_id_size) = 0; |
+ |
+ // Decrypts the |encrypted_buffer|. |
+ // Returns kCdmStatusSuccess if decryption succeeds, in which case the callee |
+ // should fill the |decrypted_buffer| and take ownership of |data| in |
ddorwin
2012/08/15 02:14:57
Similar to above.
xhwang
2012/08/15 04:27:46
Done.
|
+ // |decrypted_buffer|. |
+ // Returns kCdmStatusErrorNoKey if the CDM does not have a key to decrypt. |
ddorwin
2012/08/15 02:14:57
... have the necessary decryption key.
xhwang
2012/08/15 04:27:46
Done.
|
+ // Returns kCdmStatusErrorUnknown if any other error happens. |
+ // In these two cases, |decrypted_buffer| should not be used by the caller. |
+ virtual CdmStatus Decrypt(const char* session_id, |
+ int session_id_size, |
+ const InputBuffer& encrypted_buffer, |
+ OutputBuffer* decrypted_buffer) = 0; |
+ |
+ virtual ~ContentDecryptionModule() {}; |
+}; |
+ |
+#endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ |