Chromium Code Reviews| 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 checksum(NULL), | 84 checksum(NULL), |
| 101 checksum_size(0), | 85 checksum_size(0), |
| 102 subsamples(NULL), | 86 subsamples(NULL), |
| 103 num_subsamples(0), | 87 num_subsamples(0), |
| 104 timestamp(0) {} | 88 timestamp(0) {} |
| 105 | 89 |
| 106 const uint8_t* data; // Pointer to the beginning of the input data. | 90 const uint8_t* data; // Pointer to the beginning of the input data. |
| 107 uint32_t data_size; // Size (in bytes) of |data|. | 91 int32_t data_size; // Size (in bytes) of |data|. |
| 108 | 92 |
| 109 uint32_t data_offset; // Number of bytes to be discarded before decryption. | 93 int32_t data_offset; // Number of bytes to be discarded before decryption. |
| 110 | 94 |
| 111 const uint8_t* key_id; // Key ID to identify the decryption key. | 95 const uint8_t* key_id; // Key ID to identify the decryption key. |
| 112 uint32_t key_id_size; // Size (in bytes) of |key_id|. | 96 int32_t key_id_size; // Size (in bytes) of |key_id|. |
| 113 | 97 |
| 114 const uint8_t* iv; // Initialization vector. | 98 const uint8_t* iv; // Initialization vector. |
| 115 uint32_t iv_size; // Size (in bytes) of |iv|. | 99 int32_t iv_size; // Size (in bytes) of |iv|. |
| 116 | 100 |
| 117 const uint8_t* checksum; | 101 const uint8_t* checksum; |
| 118 uint32_t checksum_size; // Size (in bytes) of the |checksum|. | 102 int32_t checksum_size; // Size (in bytes) of the |checksum|. |
| 119 | 103 |
| 120 const struct SubsampleEntry* subsamples; | 104 const struct SubsampleEntry* subsamples; |
| 121 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | 105 int32_t num_subsamples; // Number of subsamples in |subsamples|. |
| 122 | 106 |
| 123 int64_t timestamp; // Presentation timestamp in microseconds. | 107 int64_t timestamp; // Presentation timestamp in microseconds. |
| 124 }; | 108 }; |
| 125 | |
| 126 // Represents an output decrypted buffer. It does not own |data|. | |
| 127 struct OutputBuffer { | |
| 128 OutputBuffer() | |
| 129 : data(NULL), | |
| 130 data_size(0), | |
| 131 timestamp(0) {} | |
| 132 | |
| 133 const uint8_t* data; // Pointer to the beginning of the output data. | |
| 134 uint32_t data_size; // Size (in bytes) of |data|. | |
| 135 | |
| 136 int64_t timestamp; // Presentation timestamp in microseconds. | |
| 137 }; | |
| 138 | 109 |
| 139 // Surface formats based on FOURCC labels, see: | 110 // Surface formats based on FOURCC labels, see: |
| 140 // http://www.fourcc.org/yuv.php | 111 // http://www.fourcc.org/yuv.php |
| 141 enum VideoFormat { | 112 enum VideoFormat { |
| 142 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. | 113 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. |
| 143 kEmptyVideoFrame, // An empty frame. | 114 kEmptyVideoFrame, // An empty frame. |
| 144 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. | 115 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. |
| 145 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 116 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
| 146 }; | 117 }; |
| 147 | 118 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 | 272 |
| 302 // Stops the CDM video decoder and sets it to an uninitialized state. The | 273 // Stops the CDM video decoder and sets it to an uninitialized state. The |
| 303 // caller can call InitializeVideoDecoder() again after this call to | 274 // caller can call InitializeVideoDecoder() again after this call to |
| 304 // re-initialize the video decoder. This can be used to reconfigure the | 275 // re-initialize the video decoder. This can be used to reconfigure the |
| 305 // video decoder if the config changes. | 276 // video decoder if the config changes. |
| 306 virtual void StopVideoDecoder() = 0; | 277 virtual void StopVideoDecoder() = 0; |
| 307 | 278 |
| 308 virtual ~ContentDecryptionModule() {} | 279 virtual ~ContentDecryptionModule() {} |
| 309 }; | 280 }; |
| 310 | 281 |
| 282 // Represents a buffer created by Allocator implementations. | |
| 283 class Buffer { | |
| 284 public: | |
| 285 virtual ~Buffer() {} | |
|
ddorwin
2012/09/17 21:19:23
protected.
Don't let the CDM delete Buffers.
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 286 virtual uint8_t* buffer() = 0; | |
| 287 virtual int32_t size() const = 0; | |
| 288 | |
| 289 protected: | |
| 290 Buffer() {} | |
| 291 | |
| 292 private: | |
| 293 Buffer(const Buffer&); | |
| 294 void operator=(const Buffer&); | |
| 295 }; | |
| 296 | |
| 297 // Interface class that hides cross object memory allocation details from CDMs. | |
| 298 // Allocated buffers should only be freed by the CDM wrapper with the single | |
| 299 // exception noted by the |ReleaseBuffer()| comment. | |
| 300 class Allocator { | |
| 301 public: | |
| 302 Allocator() {} | |
|
ddorwin
2012/09/17 21:19:23
protected for these two.
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 303 virtual ~Allocator() {} | |
| 304 | |
| 305 // Returns a Buffer* containing non-zero members upon success, or NULL on | |
| 306 // failure. The caller owns the Buffer* until it is passed back to the CDM | |
| 307 // wrapper. | |
| 308 virtual Buffer* Allocate(int32_t size) = 0; | |
| 309 | |
| 310 // Release a Buffer returned by Allocate(). The |buffer| pointer is no longer | |
|
ddorwin
2012/09/17 21:19:23
Correcting myself: I think we should just say "|bu
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 311 // valid after calling this method. | |
| 312 virtual void Release(const Buffer* buffer) = 0; | |
| 313 }; | |
| 314 | |
| 315 // Represents a key message sent by the CDM. | |
| 316 class KeyMessage { | |
| 317 public: | |
| 318 virtual bool set_session_id(const char* session_id, int32_t length) = 0; | |
| 319 virtual const char* session_id() const = 0; | |
| 320 virtual int32_t session_id_length() const = 0; | |
| 321 | |
| 322 virtual bool set_message(Buffer* message) = 0; | |
| 323 virtual Buffer* message() const = 0; | |
| 324 | |
| 325 virtual bool set_default_url(const char* default_url, int32_t length) = 0; | |
| 326 virtual const char* default_url() const = 0; | |
| 327 virtual int32_t default_url_length() const = 0; | |
| 328 | |
| 329 protected: | |
| 330 KeyMessage() {} | |
| 331 virtual ~KeyMessage() {} | |
| 332 }; | |
| 333 | |
| 334 // Represents an output decrypted buffer. | |
| 335 class OutputBuffer { | |
| 336 public: | |
| 337 virtual bool set_buffer(Buffer* buffer) = 0; | |
| 338 virtual Buffer* buffer() const = 0; | |
| 339 | |
| 340 virtual void set_timestamp(int64_t timestamp) = 0; | |
| 341 virtual int64_t timestamp() const = 0; | |
|
ddorwin
2012/09/17 21:19:23
TODO: Figure out if we need timestamp() here. If n
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 342 | |
| 343 protected: | |
| 344 OutputBuffer() {} | |
| 345 virtual ~OutputBuffer() {} | |
| 346 }; | |
| 347 | |
| 311 } // namespace cdm | 348 } // namespace cdm |
| 312 | 349 |
| 313 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 350 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |