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; |
| 11 typedef int int32_t; |
11 typedef __int64 int64_t; | 12 typedef __int64 int64_t; |
12 #else | 13 #else |
13 #include <stdint.h> | 14 #include <stdint.h> |
14 #endif | 15 #endif |
15 | 16 |
16 #include "webkit/media/crypto/ppapi/cdm_export.h" | 17 #include "webkit/media/crypto/ppapi/cdm_export.h" |
17 | 18 |
18 namespace cdm { | 19 namespace cdm { |
19 class ContentDecryptionModule; | 20 class ContentDecryptionModule; |
20 } | 21 } |
21 | 22 |
22 extern "C" { | 23 extern "C" { |
23 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); | 24 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); |
24 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); | 25 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); |
25 CDM_EXPORT const char* GetCdmVersion(); | 26 CDM_EXPORT const char* GetCdmVersion(); |
26 } | 27 } |
27 | 28 |
28 namespace cdm { | 29 namespace cdm { |
29 | 30 |
30 enum Status { | 31 enum Status { |
31 kSuccess = 0, | 32 kSuccess = 0, |
32 kErrorUnknown, | 33 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. |
33 kErrorNoKey | 34 kNoKey, // The required decryption key is not available. |
| 35 kError |
34 }; | 36 }; |
35 | 37 |
| 38 // Represents a key message sent by the CDM. It does not own any pointers in |
| 39 // this struct. |
36 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and | 40 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and |
37 // update checks to include <0. | 41 // update checks to include <0. |
38 struct KeyMessage { | 42 struct KeyMessage { |
39 KeyMessage() | 43 KeyMessage() |
40 : session_id(NULL), | 44 : session_id(NULL), |
41 session_id_size(0), | 45 session_id_size(0), |
42 message(NULL), | 46 message(NULL), |
43 message_size(0), | 47 message_size(0), |
44 default_url(NULL), | 48 default_url(NULL), |
45 default_url_size(0) {} | 49 default_url_size(0) {} |
(...skipping 29 matching lines...) Expand all Loading... |
75 // | 79 // |
76 // TODO(xhwang): Add checks to make sure these structs have fixed layout. | 80 // TODO(xhwang): Add checks to make sure these structs have fixed layout. |
77 struct SubsampleEntry { | 81 struct SubsampleEntry { |
78 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) | 82 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) |
79 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} | 83 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} |
80 | 84 |
81 uint32_t clear_bytes; | 85 uint32_t clear_bytes; |
82 uint32_t cipher_bytes; | 86 uint32_t cipher_bytes; |
83 }; | 87 }; |
84 | 88 |
| 89 // Represents an input buffer to be decrypted (and possibly decoded). It does |
| 90 // own any pointers in this struct. |
85 struct InputBuffer { | 91 struct InputBuffer { |
86 InputBuffer() | 92 InputBuffer() |
87 : data(NULL), | 93 : data(NULL), |
88 data_size(0), | 94 data_size(0), |
89 data_offset(0), | 95 data_offset(0), |
90 key_id(NULL), | 96 key_id(NULL), |
91 key_id_size(0), | 97 key_id_size(0), |
92 iv(NULL), | 98 iv(NULL), |
93 iv_size(0), | 99 iv_size(0), |
94 checksum(NULL), | 100 checksum(NULL), |
(...skipping 15 matching lines...) Expand all Loading... |
110 | 116 |
111 const uint8_t* checksum; | 117 const uint8_t* checksum; |
112 uint32_t checksum_size; // Size (in bytes) of the |checksum|. | 118 uint32_t checksum_size; // Size (in bytes) of the |checksum|. |
113 | 119 |
114 const struct SubsampleEntry* subsamples; | 120 const struct SubsampleEntry* subsamples; |
115 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | 121 uint32_t num_subsamples; // Number of subsamples in |subsamples|. |
116 | 122 |
117 int64_t timestamp; // Presentation timestamp in microseconds. | 123 int64_t timestamp; // Presentation timestamp in microseconds. |
118 }; | 124 }; |
119 | 125 |
| 126 // Represents an output decrypted buffer. It does not own |data|. |
120 struct OutputBuffer { | 127 struct OutputBuffer { |
121 OutputBuffer() | 128 OutputBuffer() |
122 : data(NULL), | 129 : data(NULL), |
123 data_size(0), | 130 data_size(0), |
124 timestamp(0) {} | 131 timestamp(0) {} |
125 | 132 |
126 const uint8_t* data; // Pointer to the beginning of the output data. | 133 const uint8_t* data; // Pointer to the beginning of the output data. |
127 uint32_t data_size; // Size (in bytes) of |data|. | 134 uint32_t data_size; // Size (in bytes) of |data|. |
128 | 135 |
129 int64_t timestamp; // Presentation timestamp in microseconds. | 136 int64_t timestamp; // Presentation timestamp in microseconds. |
130 }; | 137 }; |
131 | 138 |
| 139 // Surface formats based on FOURCC labels, see: |
| 140 // http://www.fourcc.org/yuv.php |
| 141 enum VideoFormat { |
| 142 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. |
| 143 kEmptyVideoFrame, // An empty frame. |
| 144 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. |
| 145 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
| 146 }; |
| 147 |
| 148 struct Size { |
| 149 Size() : width(0), height(0) {} |
| 150 Size(int32_t width, int32_t height) : width(width), height(height) {} |
| 151 |
| 152 int32_t width; |
| 153 int32_t height; |
| 154 }; |
| 155 |
| 156 struct VideoFrame { |
| 157 static const int32_t kMaxPlanes = 3; |
| 158 |
| 159 VideoFrame() |
| 160 : timestamp(0) { |
| 161 for (int i = 0; i < kMaxPlanes; ++i) { |
| 162 strides[i] = 0; |
| 163 data[i] = NULL; |
| 164 } |
| 165 } |
| 166 |
| 167 // Array of strides for each plane, typically greater or equal to the width |
| 168 // of the surface divided by the horizontal sampling period. Note that |
| 169 // strides can be negative. |
| 170 int32_t strides[kMaxPlanes]; |
| 171 |
| 172 // Array of data pointers to each plane. |
| 173 uint8_t* data[kMaxPlanes]; |
| 174 |
| 175 int64_t timestamp; // Presentation timestamp in microseconds. |
| 176 }; |
| 177 |
| 178 struct VideoDecoderConfig { |
| 179 enum VideoCodec { |
| 180 kUnknownVideoCodec = 0, |
| 181 kCodecVP8 |
| 182 }; |
| 183 |
| 184 enum VideoCodecProfile { |
| 185 kUnknownVideoCodecProfile = 0, |
| 186 kVp8ProfileMain |
| 187 }; |
| 188 |
| 189 VideoDecoderConfig() |
| 190 : codec(kUnknownVideoCodec), |
| 191 profile(kUnknownVideoCodecProfile), |
| 192 format(kUnknownVideoFormat), |
| 193 extra_data(NULL), |
| 194 extra_data_size() {} |
| 195 |
| 196 VideoCodec codec; |
| 197 VideoCodecProfile profile; |
| 198 VideoFormat format; |
| 199 |
| 200 // Width and height of video frame immediately post-decode. Not all pixels |
| 201 // in this region are valid. |
| 202 Size coded_size; |
| 203 |
| 204 // Optional byte data required to initialize video decoders, such as H.264 |
| 205 // AAVC data. |
| 206 uint8_t* extra_data; |
| 207 int32_t extra_data_size; |
| 208 }; |
| 209 |
132 class ContentDecryptionModule { | 210 class ContentDecryptionModule { |
133 public: | 211 public: |
134 // Generates a |key_request| given the |init_data|. | 212 // Generates a |key_request| given the |init_data|. |
| 213 // |
135 // Returns kSuccess if the key request was successfully generated, | 214 // Returns kSuccess if the key request was successfully generated, |
136 // in which case the callee should have allocated memory for the output | 215 // in which case the callee should have allocated memory for the output |
137 // parameters (e.g |session_id| in |key_request|) and passed the ownership | 216 // parameters (e.g |session_id| in |key_request|) and passed the ownership |
138 // to the caller. | 217 // to the caller. |
139 // Returns kErrorUnknown otherwise, in which case the output parameters should | 218 // Returns kError if any error happened, in which case the |key_request| |
140 // not be used by the caller. | 219 // should not be used by the caller. |
141 // | 220 // |
142 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 221 // TODO(xhwang): It's not safe to pass the ownership of the dynamically |
143 // allocated memory over library boundaries. Fix it after related PPAPI change | 222 // allocated memory over library boundaries. Fix it after related PPAPI change |
144 // and sample CDM are landed. | 223 // and sample CDM are landed. |
145 virtual Status GenerateKeyRequest(const uint8_t* init_data, | 224 virtual Status GenerateKeyRequest(const uint8_t* init_data, |
146 int init_data_size, | 225 int init_data_size, |
147 KeyMessage* key_request) = 0; | 226 KeyMessage* key_request) = 0; |
148 | 227 |
149 // Adds the |key| to the CDM to be associated with |key_id|. | 228 // Adds the |key| to the CDM to be associated with |key_id|. |
150 // Returns kSuccess if the key was successfully added. | 229 // |
151 // Returns kErrorUnknown otherwise. | 230 // Returns kSuccess if the key was successfully added, kError otherwise. |
152 virtual Status AddKey(const char* session_id, | 231 virtual Status AddKey(const char* session_id, |
153 int session_id_size, | 232 int session_id_size, |
154 const uint8_t* key, | 233 const uint8_t* key, |
155 int key_size, | 234 int key_size, |
156 const uint8_t* key_id, | 235 const uint8_t* key_id, |
157 int key_id_size) = 0; | 236 int key_id_size) = 0; |
158 | 237 |
159 // Cancels any pending key request made to the CDM for |session_id|. | 238 // Cancels any pending key request made to the CDM for |session_id|. |
| 239 // |
160 // Returns kSuccess if all pending key requests for |session_id| were | 240 // Returns kSuccess if all pending key requests for |session_id| were |
161 // successfully canceled or there was no key request to be canceled. | 241 // successfully canceled or there was no key request to be canceled, kError |
162 // Returns kErrorUnknown otherwise. | 242 // otherwise. |
163 virtual Status CancelKeyRequest(const char* session_id, | 243 virtual Status CancelKeyRequest(const char* session_id, |
164 int session_id_size) = 0; | 244 int session_id_size) = 0; |
165 | 245 |
166 // Decrypts the |encrypted_buffer|. | 246 // Decrypts the |encrypted_buffer|. |
| 247 // |
167 // Returns kSuccess if decryption succeeded, in which case the callee | 248 // Returns kSuccess if decryption succeeded, in which case the callee |
168 // should have filled the |decrypted_buffer| and passed the ownership of | 249 // should have filled the |decrypted_buffer| and passed the ownership of |
169 // |data| in |decrypted_buffer| to the caller. | 250 // |data| in |decrypted_buffer| to the caller. |
170 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | 251 // Returns kNoKey if the CDM did not have the necessary decryption key |
171 // to decrypt. | 252 // to decrypt. |
172 // Returns kErrorUnknown if any other error happened. | 253 // Returns kError if any other error happened. |
173 // In these two cases, |decrypted_buffer| should not be used by the caller. | 254 // If the return value is not kSuccess, |decrypted_buffer| should be ignored |
| 255 // by the caller. |
174 // | 256 // |
175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 257 // TODO(xhwang): It's not safe to pass the ownership of the dynamically |
176 // allocated memory over library boundaries. Fix it after related PPAPI change | 258 // allocated memory over library boundaries. Fix it after related PPAPI change |
177 // and sample CDM are landed. | 259 // and sample CDM are landed. |
178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 260 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
179 OutputBuffer* decrypted_buffer) = 0; | 261 OutputBuffer* decrypted_buffer) = 0; |
180 | 262 |
| 263 // Initializes the CDM video decoder with |video_decoder_config|. This |
| 264 // function must be called before DecryptAndDecodeVideo() is called. |
| 265 // |
| 266 // Returns kSuccess if the |video_decoder_config| is supported and the CDM |
| 267 // video decoder is successfully initialized. |
| 268 // Returns kError if |video_decoder_config| is not supported. The CDM may |
| 269 // still be able to do Decrypt(). |
| 270 // |
| 271 // TODO(xhwang): Add stream ID here and in the following video decoder |
| 272 // functions when we need to support multiple video streams in one CDM. |
| 273 virtual Status InitializeVideoDecoder( |
| 274 const VideoDecoderConfig& video_decoder_config) = 0; |
| 275 |
| 276 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a |
| 277 // |video_frame|. Upon end-of-stream, the caller should call this function |
| 278 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty |
| 279 // |video_frame| (|format| == kEmptyVideoFrame) is produced. |
| 280 // |
| 281 // Returns kSuccess if decryption and decoding both succeeded, in which case |
| 282 // the callee should have filled the |video_frame| and passed the ownership of |
| 283 // |data| in |video_frame| to the caller. |
| 284 // Returns kNoKey if the CDM did not have the necessary decryption key |
| 285 // to decrypt. |
| 286 // Returns kNeedMoreData if more data was needed by the decoder to generate |
| 287 // a decoded frame (e.g. during initialization). |
| 288 // Returns kError if any other (decryption or decoding) error happened. |
| 289 // If the return value is not kSuccess, |video_frame| should be ignored by |
| 290 // the caller. |
| 291 // |
| 292 // TODO(xhwang): It's not safe to pass the ownership of the dynamically |
| 293 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 294 // and sample CDM are landed. |
| 295 virtual Status DecryptAndDecodeVideo(const InputBuffer& encrypted_buffer, |
| 296 VideoFrame* video_frame) = 0; |
| 297 |
| 298 // Resets the CDM video decoder to an initialized clean state. All internal |
| 299 // buffers will be flushed. |
| 300 virtual void ResetVideoDecoder() = 0; |
| 301 |
| 302 // Stops the CDM video decoder and sets it to an uninitialized state. The |
| 303 // caller can call InitializeVideoDecoder() again after this call to |
| 304 // re-initialize the video decoder. This can be used to reconfigure the |
| 305 // video decoder if the config changes. |
| 306 virtual void StopVideoDecoder() = 0; |
| 307 |
181 virtual ~ContentDecryptionModule() {} | 308 virtual ~ContentDecryptionModule() {} |
182 }; | 309 }; |
183 | 310 |
184 } // namespace cdm | 311 } // namespace cdm |
185 | 312 |
186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 313 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
OLD | NEW |