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* CdmCreateInstance(); | |
ddorwin
2012/08/16 04:15:48
CreateCdmInstnace? Same below
xhwang
2012/08/16 16:44:28
Done.
| |
21 extern "C" void CdmDestroyInstance(cdm::ContentDecryptionModule* instance); | |
22 extern "C" const char* CdmGetVersion(); | |
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 buffer over .so | |
100 // boundaries. Fix this later. | |
ddorwin
2012/08/16 04:15:48
Later is too vague.
xhwang
2012/08/16 16:44:28
Done.
| |
101 virtual Status GenerateKeyRequest(const uint8_t* init_data, | |
102 int init_data_size, | |
103 char** session_id, | |
104 int* session_id_size, | |
105 uint8_t** key_request, | |
106 int* key_request_size, | |
107 char** default_url, | |
108 int* default_url_size) = 0; | |
109 | |
110 // Adds the |key| to the CDM. | |
111 // Returns kSuccess if the key was successfully added. | |
112 // Returns kErrorUnknown otherwise. | |
113 virtual Status AddKey(const char* session_id, | |
114 int session_id_size, | |
115 const uint8_t* key, | |
116 int key_size) = 0; | |
117 | |
118 // Cancels any pending key request made to the CDM for |session_id|. | |
119 // Returns kSuccess if all pending key requests for |session_id| were | |
120 // successfully canceled or there was no key request to be canceled. | |
121 // Returns kErrorUnknown otherwise. | |
122 virtual Status CancelKeyRequest(const char* session_id, | |
123 int session_id_size) = 0; | |
124 | |
125 // Decrypts the |encrypted_buffer|. | |
126 // Returns kSuccess if decryption succeeded, in which case the callee | |
127 // should have filled the |decrypted_buffer| and passed the ownership of | |
128 // |data| in |decrypted_buffer| to the caller. | |
129 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | |
130 // to decrypt. | |
131 // Returns kErrorUnknown if any other error happened. | |
132 // In these two cases, |decrypted_buffer| should not be used by the caller. | |
133 // | |
134 // TODO(xhwang): It's not safe to pass the ownership of the buffer over .so | |
135 // boundaries. Fix this later. | |
136 virtual Status Decrypt(const char* session_id, | |
137 int session_id_size, | |
138 const InputBuffer& encrypted_buffer, | |
139 OutputBuffer* decrypted_buffer) = 0; | |
140 | |
141 virtual ~ContentDecryptionModule() {}; | |
142 }; | |
143 | |
144 } // namespace cdm | |
145 | |
146 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | |
OLD | NEW |