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(); | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
do these need to be extern C?
scherkus (not reviewing)
2012/08/15 23:26:29
what about deleting the instance?
we can't assume
xhwang
2012/08/16 02:37:43
Done.
xhwang
2012/08/16 02:37:43
Done.
| |
| 18 extern const char* CdmGetVersion(); | |
| 19 | |
| 20 enum CdmStatus { | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
move into CDM class and rename as Status?
xhwang
2012/08/16 02:37:43
Done.
| |
| 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 | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
s/cypher/cipher/g
(all src/crypto/ code uses ciph
xhwang
2012/08/16 02:37:43
Done. Will fix cypher in src/media later.
| |
| 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. | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
nit: add blank line between each data+size pair (i
xhwang
2012/08/16 02:37:43
Done.
| |
| 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. | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
AFAIK we no longer care about duration
xhwang
2012/08/16 02:37:43
Will media::Buffer drop the duration?
| |
| 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 extract a |default_url|. | |
| 79 // Returns kCdmStatusSuccess if the key request is successfully generated, | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
s/is/was
xhwang
2012/08/16 02:37:43
Done, here and below.
| |
| 80 // in which case the callee should have allocated memory for the output | |
|
scherkus (not reviewing)
2012/08/15 23:26:29
I'm suspicious of this memory allocating business
xhwang
2012/08/16 02:37:43
Thank you so much for the suggestions. We were awa
ddorwin
2012/08/16 04:15:48
More accurately, we'll need to do some experimenta
scherkus (not reviewing)
2012/08/16 21:18:57
For (3) I'm assuming we would build both halves of
| |
| 81 // parameters (e.g |session_id|) and passed the ownership to the caller. | |
| 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 all pending key requests for |session_id| are | |
| 103 // successfully canceled or there is no key request to be canceled. | |
|
ddorwin
2012/08/15 06:48:10
FYI, TBD what to do if no matching session. May be
| |
| 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 have filled the |decrypted_buffer| and passed the ownership of | |
| 111 // |data| in |decrypted_buffer| to the caller. | |
| 112 // Returns kCdmStatusErrorNoKey if the CDM does not have the necessary | |
| 113 // decryption key to decrypt. | |
| 114 // Returns kCdmStatusErrorUnknown if any other error happens. | |
| 115 // In these two cases, |decrypted_buffer| should not be used by the caller. | |
| 116 virtual CdmStatus Decrypt(const char* session_id, | |
| 117 int session_id_size, | |
| 118 const InputBuffer& encrypted_buffer, | |
| 119 OutputBuffer* decrypted_buffer) = 0; | |
| 120 | |
| 121 virtual ~ContentDecryptionModule() {}; | |
| 122 }; | |
| 123 | |
| 124 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | |
| OLD | NEW |