Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| 7 | 7 |
| 8 #if defined(_MSC_VER) | 8 #if defined(_MSC_VER) |
| 9 typedef unsigned char uint8_t; | 9 typedef unsigned char uint8_t; |
| 10 typedef unsigned int uint32_t; | 10 typedef unsigned int uint32_t; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 namespace cdm { | 28 namespace cdm { |
| 29 | 29 |
| 30 enum Status { | 30 enum Status { |
| 31 kSuccess = 0, | 31 kSuccess = 0, |
| 32 kErrorUnknown, | 32 kErrorUnknown, |
| 33 kErrorNoKey | 33 kErrorNoKey |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 struct KeyMessage { | 36 struct KeyMessage { |
| 37 KeyMessage() | |
| 38 : session_id(NULL), | |
| 39 session_id_size(0), | |
| 40 message(NULL), | |
| 41 message_size(0), | |
| 42 default_url(NULL), | |
| 43 default_url_size(0) {} | |
| 44 | |
| 37 char* session_id; | 45 char* session_id; |
| 38 uint32_t session_id_size; | 46 uint32_t session_id_size; |
|
ddorwin
2012/08/22 18:25:54
should this really be unsigned?
If you change this
xhwang
2012/08/24 22:01:59
Good catch, chromium/google uses signed int (int32
| |
| 39 uint8_t* message; | 47 uint8_t* message; |
| 40 uint32_t message_size; | 48 uint32_t message_size; |
| 41 char* default_url; | 49 char* default_url; |
| 42 uint32_t default_url_size; | 50 uint32_t default_url_size; |
| 43 }; | 51 }; |
| 44 | 52 |
| 45 // An input buffer can be split into several continuous subsamples. | 53 // An input buffer can be split into several continuous subsamples. |
| 46 // A SubsampleEntry specifies the number of clear and cipher bytes in each | 54 // A SubsampleEntry specifies the number of clear and cipher bytes in each |
| 47 // subsample. For example, the following buffer has three subsamples: | 55 // subsample. For example, the following buffer has three subsamples: |
| 48 // | 56 // |
| 49 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | 57 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
| 50 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | | 58 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | |
| 51 // | 59 // |
| 52 // For decryption, all of the cipher bytes in a buffer should be concatenated | 60 // For decryption, all of the cipher bytes in a buffer should be concatenated |
| 53 // (in the subsample order) into a single logical stream. The clear bytes should | 61 // (in the subsample order) into a single logical stream. The clear bytes should |
| 54 // not be considered as part of decryption. | 62 // not be considered as part of decryption. |
| 55 // | 63 // |
| 56 // Stream to decrypt: | cipher1 | cipher2 | cipher3 | | 64 // Stream to decrypt: | cipher1 | cipher2 | cipher3 | |
| 57 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 | | 65 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 | |
| 58 // | 66 // |
| 59 // After decryption, the decrypted bytes should be copied over the position | 67 // After decryption, the decrypted bytes should be copied over the position |
| 60 // of the corresponding cipher bytes in the original buffer to form the output | 68 // of the corresponding cipher bytes in the original buffer to form the output |
| 61 // buffer. Following the above example, the decrypted buffer should be: | 69 // buffer. Following the above example, the decrypted buffer should be: |
| 62 // | 70 // |
| 63 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | 71 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
| 64 // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 | | 72 // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 | |
| 65 // | 73 // |
| 66 // TODO(xhwang): Add checks to make sure these structs have fixed layout. | 74 // TODO(xhwang): Add checks to make sure these structs have fixed layout. |
| 67 struct SubsampleEntry { | 75 struct SubsampleEntry { |
| 76 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) | |
| 77 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} | |
| 78 | |
| 68 uint32_t clear_bytes; | 79 uint32_t clear_bytes; |
| 69 uint32_t cipher_bytes; | 80 uint32_t cipher_bytes; |
| 70 }; | 81 }; |
| 71 | 82 |
| 72 struct InputBuffer { | 83 struct InputBuffer { |
| 73 uint8_t* data; // Pointer to the beginning of the input data. | 84 InputBuffer() |
| 85 : data(NULL), | |
| 86 data_size(0), | |
| 87 data_offset(0), | |
| 88 key_id(NULL), | |
| 89 key_id_size(0), | |
| 90 iv(NULL), | |
| 91 iv_size(0), | |
| 92 checksum(NULL), | |
| 93 checksum_size(0), | |
| 94 subsamples(NULL), | |
| 95 num_subsamples(0), | |
| 96 timestamp(0) {} | |
| 97 | |
| 98 const uint8_t* data; // Pointer to the beginning of the input data. | |
| 74 uint32_t data_size; // Size (in bytes) of |data|. | 99 uint32_t data_size; // Size (in bytes) of |data|. |
| 75 | 100 |
| 76 uint32_t data_offset; // Number of bytes to be discarded before decryption. | 101 uint32_t data_offset; // Number of bytes to be discarded before decryption. |
| 77 | 102 |
| 78 uint8_t* key_id; // Key ID to identify the decryption key. | 103 const uint8_t* key_id; // Key ID to identify the decryption key. |
| 79 uint32_t key_id_size; // Size (in bytes) of |key_id|. | 104 uint32_t key_id_size; // Size (in bytes) of |key_id|. |
| 80 | 105 |
| 81 uint8_t* iv; // Initialization vector. | 106 const uint8_t* iv; // Initialization vector. |
| 82 uint32_t iv_size; // Size (in bytes) of |iv|. | 107 uint32_t iv_size; // Size (in bytes) of |iv|. |
| 83 | 108 |
| 84 uint8_t* checksum; | 109 const uint8_t* checksum; |
| 85 uint32_t checksum_size; // Size (in bytes) of the |checksum|. | 110 uint32_t checksum_size; // Size (in bytes) of the |checksum|. |
| 86 | 111 |
| 87 struct SubsampleEntry* subsamples; | 112 const struct SubsampleEntry* subsamples; |
| 88 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | 113 uint32_t num_subsamples; // Number of subsamples in |subsamples|. |
| 89 | 114 |
| 90 int64_t timestamp; // Presentation timestamp in microseconds. | 115 int64_t timestamp; // Presentation timestamp in microseconds. |
| 91 }; | 116 }; |
| 92 | 117 |
| 93 struct OutputBuffer { | 118 struct OutputBuffer { |
| 94 uint8_t* data; // Pointer to the beginning of the output data. | 119 const uint8_t* data; // Pointer to the beginning of the output data. |
| 95 uint32_t data_size; // Size (in bytes) of |data|. | 120 uint32_t data_size; // Size (in bytes) of |data|. |
| 96 | 121 |
| 97 int64_t timestamp; // Presentation timestamp in microseconds. | 122 int64_t timestamp; // Presentation timestamp in microseconds. |
| 98 }; | 123 }; |
| 99 | 124 |
| 100 class ContentDecryptionModule { | 125 class ContentDecryptionModule { |
| 101 public: | 126 public: |
| 102 // Generates a |key_request| given the |init_data|. | 127 // Generates a |key_request| given the |init_data|. |
| 103 // Returns kSuccess if the key request was successfully generated, | 128 // Returns kSuccess if the key request was successfully generated, |
| 104 // in which case the callee should have allocated memory for the output | 129 // in which case the callee should have allocated memory for the output |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 // and sample CDM are landed. | 170 // and sample CDM are landed. |
| 146 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 171 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
| 147 OutputBuffer* decrypted_buffer) = 0; | 172 OutputBuffer* decrypted_buffer) = 0; |
| 148 | 173 |
| 149 virtual ~ContentDecryptionModule() {} | 174 virtual ~ContentDecryptionModule() {} |
| 150 }; | 175 }; |
| 151 | 176 |
| 152 } // namespace cdm | 177 } // namespace cdm |
| 153 | 178 |
| 154 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 179 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |