| 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 int int32_t; |
| 12 typedef __int64 int64_t; | 12 typedef __int64 int64_t; |
| 13 #else | 13 #else |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include "webkit/media/crypto/ppapi/cdm_export.h" | 17 #include "webkit/media/crypto/ppapi/cdm_export.h" |
| 18 | 18 |
| 19 namespace cdm { | 19 namespace cdm { |
| 20 class Allocator; |
| 21 class Buffer; |
| 20 class ContentDecryptionModule; | 22 class ContentDecryptionModule; |
| 23 class KeyMessage; |
| 24 class OutputBuffer; |
| 21 } | 25 } |
| 22 | 26 |
| 23 extern "C" { | 27 extern "C" { |
| 24 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); | 28 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance( |
| 29 cdm::Allocator* allocator); |
| 25 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); | 30 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); |
| 26 CDM_EXPORT const char* GetCdmVersion(); | 31 CDM_EXPORT const char* GetCdmVersion(); |
| 27 } | 32 } |
| 28 | 33 |
| 29 namespace cdm { | 34 namespace cdm { |
| 30 | 35 |
| 31 enum Status { | 36 enum Status { |
| 32 kSuccess = 0, | 37 kSuccess = 0, |
| 33 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. | 38 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. |
| 34 kNoKey, // The required decryption key is not available. | 39 kNoKey, // The required decryption key is not available. |
| 35 kError | 40 kError |
| 36 }; | 41 }; |
| 37 | 42 |
| 38 // Represents a key message sent by the CDM. It does not own any pointers in | |
| 39 // this struct. | |
| 40 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and | |
| 41 // update checks to include <0. | |
| 42 struct KeyMessage { | |
| 43 KeyMessage() | |
| 44 : session_id(NULL), | |
| 45 session_id_size(0), | |
| 46 message(NULL), | |
| 47 message_size(0), | |
| 48 default_url(NULL), | |
| 49 default_url_size(0) {} | |
| 50 | |
| 51 char* session_id; | |
| 52 uint32_t session_id_size; | |
| 53 uint8_t* message; | |
| 54 uint32_t message_size; | |
| 55 char* default_url; | |
| 56 uint32_t default_url_size; | |
| 57 }; | |
| 58 | |
| 59 // An input buffer can be split into several continuous subsamples. | 43 // An input buffer can be split into several continuous subsamples. |
| 60 // A SubsampleEntry specifies the number of clear and cipher bytes in each | 44 // A SubsampleEntry specifies the number of clear and cipher bytes in each |
| 61 // subsample. For example, the following buffer has three subsamples: | 45 // subsample. For example, the following buffer has three subsamples: |
| 62 // | 46 // |
| 63 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | 47 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
| 64 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | | 48 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | |
| 65 // | 49 // |
| 66 // For decryption, all of the cipher bytes in a buffer should be concatenated | 50 // For decryption, all of the cipher bytes in a buffer should be concatenated |
| 67 // (in the subsample order) into a single logical stream. The clear bytes should | 51 // (in the subsample order) into a single logical stream. The clear bytes should |
| 68 // not be considered as part of decryption. | 52 // not be considered as part of decryption. |
| 69 // | 53 // |
| 70 // Stream to decrypt: | cipher1 | cipher2 | cipher3 | | 54 // Stream to decrypt: | cipher1 | cipher2 | cipher3 | |
| 71 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 | | 55 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 | |
| 72 // | 56 // |
| 73 // After decryption, the decrypted bytes should be copied over the position | 57 // After decryption, the decrypted bytes should be copied over the position |
| 74 // of the corresponding cipher bytes in the original buffer to form the output | 58 // of the corresponding cipher bytes in the original buffer to form the output |
| 75 // buffer. Following the above example, the decrypted buffer should be: | 59 // buffer. Following the above example, the decrypted buffer should be: |
| 76 // | 60 // |
| 77 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | 61 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
| 78 // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 | | 62 // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 | |
| 79 // | 63 // |
| 80 // TODO(xhwang): Add checks to make sure these structs have fixed layout. | 64 // TODO(xhwang): Add checks to make sure these structs have fixed layout. |
| 81 struct SubsampleEntry { | 65 struct SubsampleEntry { |
| 82 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) | 66 SubsampleEntry(int32_t clear_bytes, int32_t cipher_bytes) |
| 83 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} | 67 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} |
| 84 | 68 |
| 85 uint32_t clear_bytes; | 69 int32_t clear_bytes; |
| 86 uint32_t cipher_bytes; | 70 int32_t cipher_bytes; |
| 87 }; | 71 }; |
| 88 | 72 |
| 89 // Represents an input buffer to be decrypted (and possibly decoded). It does | 73 // Represents an input buffer to be decrypted (and possibly decoded). It does |
| 90 // own any pointers in this struct. | 74 // own any pointers in this struct. |
| 91 struct InputBuffer { | 75 struct InputBuffer { |
| 92 InputBuffer() | 76 InputBuffer() |
| 93 : data(NULL), | 77 : data(NULL), |
| 94 data_size(0), | 78 data_size(0), |
| 95 data_offset(0), | 79 data_offset(0), |
| 96 key_id(NULL), | 80 key_id(NULL), |
| 97 key_id_size(0), | 81 key_id_size(0), |
| 98 iv(NULL), | 82 iv(NULL), |
| 99 iv_size(0), | 83 iv_size(0), |
| 100 subsamples(NULL), | 84 subsamples(NULL), |
| 101 num_subsamples(0), | 85 num_subsamples(0), |
| 102 timestamp(0) {} | 86 timestamp(0) {} |
| 103 | 87 |
| 104 const uint8_t* data; // Pointer to the beginning of the input data. | 88 const uint8_t* data; // Pointer to the beginning of the input data. |
| 105 uint32_t data_size; // Size (in bytes) of |data|. | 89 int32_t data_size; // Size (in bytes) of |data|. |
| 106 | 90 |
| 107 uint32_t data_offset; // Number of bytes to be discarded before decryption. | 91 int32_t data_offset; // Number of bytes to be discarded before decryption. |
| 108 | 92 |
| 109 const uint8_t* key_id; // Key ID to identify the decryption key. | 93 const uint8_t* key_id; // Key ID to identify the decryption key. |
| 110 uint32_t key_id_size; // Size (in bytes) of |key_id|. | 94 int32_t key_id_size; // Size (in bytes) of |key_id|. |
| 111 | 95 |
| 112 const uint8_t* iv; // Initialization vector. | 96 const uint8_t* iv; // Initialization vector. |
| 113 uint32_t iv_size; // Size (in bytes) of |iv|. | 97 int32_t iv_size; // Size (in bytes) of |iv|. |
| 114 | 98 |
| 115 const struct SubsampleEntry* subsamples; | 99 const struct SubsampleEntry* subsamples; |
| 116 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | 100 int32_t num_subsamples; // Number of subsamples in |subsamples|. |
| 117 | 101 |
| 118 int64_t timestamp; // Presentation timestamp in microseconds. | 102 int64_t timestamp; // Presentation timestamp in microseconds. |
| 119 }; | 103 }; |
| 120 | |
| 121 // Represents an output decrypted buffer. It does not own |data|. | |
| 122 struct OutputBuffer { | |
| 123 OutputBuffer() | |
| 124 : data(NULL), | |
| 125 data_size(0), | |
| 126 timestamp(0) {} | |
| 127 | |
| 128 const uint8_t* data; // Pointer to the beginning of the output data. | |
| 129 uint32_t data_size; // Size (in bytes) of |data|. | |
| 130 | |
| 131 int64_t timestamp; // Presentation timestamp in microseconds. | |
| 132 }; | |
| 133 | 104 |
| 134 // Surface formats based on FOURCC labels, see: | 105 // Surface formats based on FOURCC labels, see: |
| 135 // http://www.fourcc.org/yuv.php | 106 // http://www.fourcc.org/yuv.php |
| 136 enum VideoFormat { | 107 enum VideoFormat { |
| 137 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. | 108 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. |
| 138 kEmptyVideoFrame, // An empty frame. | 109 kEmptyVideoFrame, // An empty frame. |
| 139 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. | 110 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. |
| 140 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 111 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
| 141 }; | 112 }; |
| 142 | 113 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 267 |
| 297 // Stops the CDM video decoder and sets it to an uninitialized state. The | 268 // Stops the CDM video decoder and sets it to an uninitialized state. The |
| 298 // caller can call InitializeVideoDecoder() again after this call to | 269 // caller can call InitializeVideoDecoder() again after this call to |
| 299 // re-initialize the video decoder. This can be used to reconfigure the | 270 // re-initialize the video decoder. This can be used to reconfigure the |
| 300 // video decoder if the config changes. | 271 // video decoder if the config changes. |
| 301 virtual void StopVideoDecoder() = 0; | 272 virtual void StopVideoDecoder() = 0; |
| 302 | 273 |
| 303 virtual ~ContentDecryptionModule() {} | 274 virtual ~ContentDecryptionModule() {} |
| 304 }; | 275 }; |
| 305 | 276 |
| 277 // Represents a buffer created by Allocator implementations. |
| 278 class Buffer { |
| 279 public: |
| 280 // Destroys the buffer in the same context as it was created. |
| 281 virtual void Destroy() = 0; |
| 282 |
| 283 virtual uint8_t* buffer() = 0; |
| 284 virtual int32_t size() const = 0; |
| 285 |
| 286 protected: |
| 287 Buffer() {} |
| 288 virtual ~Buffer() {} |
| 289 |
| 290 private: |
| 291 Buffer(const Buffer&); |
| 292 void operator=(const Buffer&); |
| 293 }; |
| 294 |
| 295 // Interface class that hides cross object memory allocation details from CDMs. |
| 296 class Allocator { |
| 297 public: |
| 298 // Returns a Buffer* containing non-zero members upon success, or NULL on |
| 299 // failure. The caller owns the Buffer* until it is passed back to the CDM |
| 300 // wrapper. |
| 301 virtual Buffer* Allocate(int32_t size) = 0; |
| 302 |
| 303 protected: |
| 304 Allocator() {} |
| 305 virtual ~Allocator() {} |
| 306 }; |
| 307 |
| 308 // Represents a key message sent by the CDM. |
| 309 class KeyMessage { |
| 310 public: |
| 311 virtual void set_session_id(const char* session_id, int32_t length) = 0; |
| 312 virtual const char* session_id() const = 0; |
| 313 virtual int32_t session_id_length() const = 0; |
| 314 |
| 315 virtual void set_message(Buffer* message) = 0; |
| 316 virtual Buffer* message() const = 0; |
| 317 |
| 318 virtual void set_default_url(const char* default_url, int32_t length) = 0; |
| 319 virtual const char* default_url() const = 0; |
| 320 virtual int32_t default_url_length() const = 0; |
| 321 |
| 322 protected: |
| 323 KeyMessage() {} |
| 324 virtual ~KeyMessage() {} |
| 325 }; |
| 326 |
| 327 // Represents an output decrypted buffer. |
| 328 class OutputBuffer { |
| 329 public: |
| 330 virtual void set_buffer(Buffer* buffer) = 0; |
| 331 virtual Buffer* buffer() const = 0; |
| 332 |
| 333 // TODO(tomfinegan): Figure out if timestamp is really needed. If it is not, |
| 334 // we can just pass Buffer*s around. |
| 335 virtual void set_timestamp(int64_t timestamp) = 0; |
| 336 virtual int64_t timestamp() const = 0; |
| 337 |
| 338 protected: |
| 339 OutputBuffer() {} |
| 340 virtual ~OutputBuffer() {} |
| 341 }; |
| 342 |
| 306 } // namespace cdm | 343 } // namespace cdm |
| 307 | 344 |
| 308 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 345 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |