Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | |
| 6 #define WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | |
| 7 | |
| 8 #if defined(_MSC_VER) | |
| 9 typedef unsigned char uint8_t; | |
| 10 typedef __int64 int64_t; | |
| 11 #else | |
| 12 #include <stdint.h> | |
| 13 #endif | |
| 14 | |
| 15 class ContentDecryptionModule; | |
| 16 | |
| 17 extern ContentDecryptionModule* CdmCreateInstance(); | |
| 18 extern const char* CdmGetVersion(); | |
| 19 | |
| 20 enum CdmStatus { | |
| 21 kCdmStatusSuccess = 0, | |
| 22 kCdmStatusErrorUnknown, | |
| 23 kCdmStatusErrorNoKey | |
| 24 }; | |
| 25 | |
| 26 // An input buffer can be split into several continuous subsamples. | |
| 27 // A SubsampleEntry specifies the number of clear and cypher bytes in each | |
| 28 // subsample. For example, the following buffer has three subsamples: | |
| 29 // | |
| 30 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | |
| 31 // | clear1 | cypher1 | clear2 | cypher2 | clear3 | cypher3 | | |
| 32 // | |
| 33 // For decryption, all of the cypher bytes in a buffer should be concatenated | |
| 34 // (in the subsample order) into a single logical stream. The clear bytes should | |
| 35 // not be considered as part of decryption. | |
| 36 // | |
| 37 // Stream to decrypt: | cypher1 | cypher2 | cypher3 | | |
| 38 // Decrypted stream: |decryped1| decryped2 | decryped3 | | |
| 39 // | |
| 40 // After decryption, the decrypted bytes should be copied over the position | |
| 41 // of the corresponding cypher bytes in the original buffer to form the output | |
| 42 // buffer. Following the above example, the decrypted buffer should be: | |
| 43 // | |
| 44 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | |
| 45 // | clear1 |decryped1| clear2 | decryped2 | clear3 | decryped3 | | |
| 46 // | |
| 47 struct SubsampleEntry { | |
| 48 int clear_bytes; | |
| 49 int cypher_bytes; | |
| 50 }; | |
| 51 | |
| 52 struct InputBuffer { | |
| 53 uint8_t* data; // Pointer to the beginning of the input data. | |
| 54 int data_size; // Size (in bytes) of |data|. | |
| 55 int data_offset; // Number of bytes to be discarded before decryption. | |
| 56 uint8_t* key_id; // Key ID to identify the decryption key. | |
| 57 int key_id_size; // Size (in bytes) of |key_id|. | |
| 58 uint8_t* iv; // Initialization vector. | |
| 59 int iv_size; // Size (in bytes) of |iv|. | |
| 60 uint8_t* checksum; | |
| 61 int checksum_size; // Size (in bytes) of the |checksum|. | |
| 62 struct SubsampleEntry* subsamples; | |
| 63 int num_subsamples; // Number of subsamples in |subsamples|. | |
| 64 int64_t timestamp; // Presentation timestamp in milliseconds. | |
| 65 int64_t duration; // Duration in milliseconds. | |
| 66 }; | |
| 67 | |
| 68 struct OutputBuffer { | |
| 69 uint8_t* data; // Pointer to the beginning of the output data. | |
| 70 int data_size; // Size (in bytes) of |data|. | |
| 71 int64_t timestamp; // Presentation timestamp in milliseconds. | |
| 72 int64_t duration; // Duration in milliseconds. | |
| 73 }; | |
| 74 | |
| 75 class ContentDecryptionModule { | |
| 76 public: | |
| 77 // Generates a |key_request| as well as a |session_id| given the |init_data|. | |
| 78 // 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.
| |
| 79 // Returns kCdmStatusSuccess if the key request is successfully generated, | |
| 80 // 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.
| |
| 81 // (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.
| |
| 82 // Returns kCdmStatusErrorUnknown otherwise, in which case the output | |
| 83 // parameters should not be used by the caller. | |
| 84 virtual CdmStatus GenerateKeyRequest(const uint8_t* init_data, | |
| 85 int init_data_size, | |
| 86 char** session_id, | |
| 87 int* session_id_size, | |
| 88 uint8_t** key_request, | |
| 89 int* key_request_size, | |
| 90 char** default_url, | |
| 91 int* default_url_size) = 0; | |
| 92 | |
| 93 // Adds the |key| to the CDM. | |
| 94 // Returns kCdmStatusSuccess if the key is successfully added. | |
| 95 // Returns kCdmStatusErrorUnknown otherwise. | |
| 96 virtual CdmStatus AddKey(const char* session_id, | |
| 97 int session_id_size, | |
| 98 const uint8_t* key, | |
| 99 int key_size) = 0; | |
| 100 | |
| 101 // Cancels any pending key request made to the CDM for |session_id|. | |
| 102 // 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.
| |
| 103 // all pending key requests for |session_id| are successfully canceled. | |
| 104 // Returns kCdmStatusErrorUnknown otherwise. | |
| 105 virtual CdmStatus CancelKeyRequest(const char* session_id, | |
| 106 int session_id_size) = 0; | |
| 107 | |
| 108 // Decrypts the |encrypted_buffer|. | |
| 109 // Returns kCdmStatusSuccess if decryption succeeds, in which case the callee | |
| 110 // 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.
| |
| 111 // |decrypted_buffer|. | |
| 112 // 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.
| |
| 113 // Returns kCdmStatusErrorUnknown if any other error happens. | |
| 114 // In these two cases, |decrypted_buffer| should not be used by the caller. | |
| 115 virtual CdmStatus Decrypt(const char* session_id, | |
| 116 int session_id_size, | |
| 117 const InputBuffer& encrypted_buffer, | |
| 118 OutputBuffer* decrypted_buffer) = 0; | |
| 119 | |
| 120 virtual ~ContentDecryptionModule() {}; | |
| 121 }; | |
| 122 | |
| 123 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | |
| OLD | NEW |