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 unsigned int uint32_t; | |
11 typedef __int64 int64_t; | |
12 #else | |
13 #include <stdint.h> | |
14 #endif | |
15 | |
16 namespace cdm { | |
17 class ContentDecryptionModule; | |
18 } | |
19 | |
20 extern "C" cdm::ContentDecryptionModule* CreateCdmInstance(); | |
21 extern "C" void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); | |
22 extern "C" const char* GetCdmVersion(); | |
23 | |
24 namespace cdm { | |
25 | |
26 // An input buffer can be split into several continuous subsamples. | |
27 // A SubsampleEntry specifies the number of clear and cipher bytes in each | |
28 // subsample. For example, the following buffer has three subsamples: | |
29 // | |
30 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | |
31 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | | |
32 // | |
33 // For decryption, all of the cipher 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: | cipher1 | cipher2 | cipher3 | | |
38 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 | | |
39 // | |
40 // After decryption, the decrypted bytes should be copied over the position | |
41 // of the corresponding cipher 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 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 | | |
46 // | |
47 // TODO(xhwang): Add checks to make sure these structs have fixed layout. | |
48 struct SubsampleEntry { | |
49 uint32_t clear_bytes; | |
50 uint32_t cipher_bytes; | |
51 }; | |
52 | |
53 struct InputBuffer { | |
54 uint8_t* data; // Pointer to the beginning of the input data. | |
55 uint32_t data_size; // Size (in bytes) of |data|. | |
56 | |
57 uint32_t data_offset; // Number of bytes to be discarded before decryption. | |
58 | |
59 uint8_t* key_id; // Key ID to identify the decryption key. | |
60 uint32_t key_id_size; // Size (in bytes) of |key_id|. | |
61 | |
62 uint8_t* iv; // Initialization vector. | |
63 uint32_t iv_size; // Size (in bytes) of |iv|. | |
64 | |
65 uint8_t* checksum; | |
66 uint32_t checksum_size; // Size (in bytes) of the |checksum|. | |
67 | |
68 struct SubsampleEntry* subsamples; | |
69 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | |
70 | |
71 int64_t timestamp; // Presentation timestamp in milliseconds. | |
72 int64_t duration; // Duration in milliseconds. | |
73 }; | |
74 | |
75 struct OutputBuffer { | |
76 uint8_t* data; // Pointer to the beginning of the output data. | |
77 uint32_t data_size; // Size (in bytes) of |data|. | |
78 | |
79 int64_t timestamp; // Presentation timestamp in milliseconds. | |
80 int64_t duration; // Duration in milliseconds. | |
81 }; | |
82 | |
83 class ContentDecryptionModule { | |
84 public: | |
85 enum Status { | |
86 kSuccess = 0, | |
87 kErrorUnknown, | |
88 kErrorNoKey | |
89 }; | |
90 | |
91 // Generates a |key_request| as well as a |session_id| given the |init_data|. | |
92 // The CDM may also extract a |default_url|. | |
93 // Returns kSuccess if the key request was successfully generated, | |
94 // in which case the callee should have allocated memory for the output | |
95 // parameters (e.g |session_id|) and passed the ownership to the caller. | |
96 // Returns kErrorUnknown otherwise, in which case the output | |
97 // parameters should not be used by the caller. | |
98 // | |
99 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | |
100 // allocated memory over library boundaries. Fix it after related PPAPI change | |
101 // are sample CDM are landed. | |
ddorwin
2012/08/16 17:16:39
s/are/and/
xhwang
2012/08/16 20:27:22
Done.
| |
102 virtual Status GenerateKeyRequest(const uint8_t* init_data, | |
103 int init_data_size, | |
104 char** session_id, | |
105 int* session_id_size, | |
106 uint8_t** key_request, | |
107 int* key_request_size, | |
108 char** default_url, | |
109 int* default_url_size) = 0; | |
110 | |
111 // Adds the |key| to the CDM to be associated with |key_id|. | |
112 // Returns kSuccess if the key was successfully added. | |
113 // Returns kErrorUnknown otherwise. | |
114 virtual Status AddKey(const char* session_id, | |
115 int session_id_size, | |
116 const uint8_t* key, | |
117 int key_size, | |
118 const uint8_t* key_id, | |
119 int key_id_size) = 0; | |
120 | |
121 // Cancels any pending key request made to the CDM for |session_id|. | |
122 // Returns kSuccess if all pending key requests for |session_id| were | |
123 // successfully canceled or there was no key request to be canceled. | |
124 // Returns kErrorUnknown otherwise. | |
125 virtual Status CancelKeyRequest(const char* session_id, | |
126 int session_id_size) = 0; | |
127 | |
128 // Decrypts the |encrypted_buffer|. | |
129 // Returns kSuccess if decryption succeeded, in which case the callee | |
130 // should have filled the |decrypted_buffer| and passed the ownership of | |
131 // |data| in |decrypted_buffer| to the caller. | |
132 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | |
133 // to decrypt. | |
134 // Returns kErrorUnknown if any other error happened. | |
135 // In these two cases, |decrypted_buffer| should not be used by the caller. | |
136 // | |
137 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | |
138 // allocated memory over library boundaries. Fix it after related PPAPI change | |
139 // are sample CDM are landed. | |
ddorwin
2012/08/16 17:16:39
same
xhwang
2012/08/16 20:27:22
Done.
| |
140 virtual Status Decrypt(const char* session_id, | |
141 int session_id_size, | |
142 const InputBuffer& encrypted_buffer, | |
143 OutputBuffer* decrypted_buffer) = 0; | |
144 | |
145 virtual ~ContentDecryptionModule() {}; | |
146 }; | |
147 | |
148 } // namespace cdm | |
149 | |
150 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | |
OLD | NEW |