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; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 extern "C" { | 22 extern "C" { |
| 23 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); | 23 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); |
| 24 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); | 24 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); |
| 25 CDM_EXPORT const char* GetCdmVersion(); | 25 CDM_EXPORT const char* GetCdmVersion(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace cdm { | 28 namespace cdm { |
| 29 | 29 |
| 30 enum Status { | 30 enum Status { |
| 31 kSuccess = 0, | 31 kSuccess = 0, |
| 32 kErrorUnknown, | 32 kDecryptOnly, // The CDM does not support to DecryptAndDecode() requested |
|
ddorwin
2012/09/03 12:35:30
"to" does not seem like the correct grammar.
| |
| 33 kErrorNoKey | 33 // decoder config but can still be used to do Decrypt() only. |
| 34 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. | |
| 35 kNoKey, // The decryption key is not available for decryption. | |
| 36 kError | |
| 34 }; | 37 }; |
| 35 | 38 |
| 36 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and | 39 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and |
| 37 // update checks to include <0. | 40 // update checks to include <0. |
| 38 struct KeyMessage { | 41 struct KeyMessage { |
| 39 KeyMessage() | 42 KeyMessage() |
| 40 : session_id(NULL), | 43 : session_id(NULL), |
| 41 session_id_size(0), | 44 session_id_size(0), |
| 42 message(NULL), | 45 message(NULL), |
| 43 message_size(0), | 46 message_size(0), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 : data(NULL), | 125 : data(NULL), |
| 123 data_size(0), | 126 data_size(0), |
| 124 timestamp(0) {} | 127 timestamp(0) {} |
| 125 | 128 |
| 126 const uint8_t* data; // Pointer to the beginning of the output data. | 129 const uint8_t* data; // Pointer to the beginning of the output data. |
| 127 uint32_t data_size; // Size (in bytes) of |data|. | 130 uint32_t data_size; // Size (in bytes) of |data|. |
| 128 | 131 |
| 129 int64_t timestamp; // Presentation timestamp in microseconds. | 132 int64_t timestamp; // Presentation timestamp in microseconds. |
| 130 }; | 133 }; |
| 131 | 134 |
| 135 struct VideoFrame { | |
| 136 // Surface formats based on FOURCC labels, see: | |
| 137 // http://www.fourcc.org/yuv.php | |
| 138 enum Format { | |
| 139 kInvalidFormat = 0, // Invalid format value. Used for error reporting. | |
| 140 kEmpty, // An empty frame. | |
| 141 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | |
| 142 }; | |
| 143 | |
| 144 struct Size { | |
| 145 Size() : width(0), height(0) {} | |
| 146 Size(int32_t width, int32_t height) : width(width), height(height) {} | |
| 147 | |
| 148 int32_t width; | |
| 149 int32_t height; | |
| 150 }; | |
| 151 | |
| 152 static const int32_t kMaxPlanes = 3; | |
| 153 | |
| 154 VideoFrame() | |
| 155 : format(kInvalidFormat), | |
| 156 timestamp(0) { | |
| 157 for (int i = 0; i < kMaxPlanes; ++i) { | |
| 158 strides[i] = 0; | |
| 159 data[i] = NULL; | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 Format format; | |
| 164 | |
| 165 // Width and height of the video frame. | |
| 166 Size data_size; | |
| 167 | |
| 168 // Array of strides for each plane, typically greater or equal to the width | |
| 169 // of the surface divided by the horizontal sampling period. Note that | |
| 170 // strides can be negative. | |
| 171 int32_t strides[kMaxPlanes]; | |
| 172 | |
| 173 // Array of data pointers to each plane. | |
| 174 uint8_t* data[kMaxPlanes]; | |
| 175 | |
| 176 int64_t timestamp; // Presentation timestamp in microseconds. | |
| 177 }; | |
| 178 | |
| 179 struct VideoDecoderConfig { | |
| 180 enum VideoCodec { | |
| 181 kUnknownVideoCodec = 0, | |
| 182 kCodecVP8 | |
| 183 }; | |
| 184 | |
| 185 enum VideoCodecProfile { | |
| 186 kUnknownVideoCodecProfile = 0, | |
| 187 kVp8ProfileMain | |
| 188 }; | |
| 189 | |
| 190 VideoDecoderConfig() | |
| 191 : codec(kUnknownVideoCodec), | |
| 192 profile(kUnknownVideoCodecProfile), | |
| 193 format(VideoFrame::kInvalidFormat), | |
| 194 extra_data(NULL), | |
| 195 extra_data_size() {} | |
| 196 | |
| 197 VideoCodec codec; | |
| 198 VideoCodecProfile profile; | |
| 199 VideoFrame::Format format; | |
| 200 VideoFrame::Size coded_size; | |
| 201 uint8_t* extra_data; | |
| 202 int32_t extra_data_size; | |
| 203 }; | |
| 204 | |
| 132 class ContentDecryptionModule { | 205 class ContentDecryptionModule { |
| 133 public: | 206 public: |
| 134 // Generates a |key_request| given the |init_data|. | 207 // Generates a |key_request| given the |init_data|. |
| 135 // Returns kSuccess if the key request was successfully generated, | 208 // Returns kSuccess if the key request was successfully generated, |
| 136 // in which case the callee should have allocated memory for the output | 209 // 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 | 210 // parameters (e.g |session_id| in |key_request|) and passed the ownership |
| 138 // to the caller. | 211 // to the caller. |
| 139 // Returns kErrorUnknown otherwise, in which case the output parameters should | 212 // Returns kError otherwise, in which case the output parameters should |
| 140 // not be used by the caller. | 213 // not be used by the caller. |
| 141 // | 214 // |
| 142 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 215 // 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 | 216 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 144 // and sample CDM are landed. | 217 // and sample CDM are landed. |
| 145 virtual Status GenerateKeyRequest(const uint8_t* init_data, | 218 virtual Status GenerateKeyRequest(const uint8_t* init_data, |
| 146 int init_data_size, | 219 int init_data_size, |
| 147 KeyMessage* key_request) = 0; | 220 KeyMessage* key_request) = 0; |
| 148 | 221 |
| 149 // Adds the |key| to the CDM to be associated with |key_id|. | 222 // Adds the |key| to the CDM to be associated with |key_id|. |
| 150 // Returns kSuccess if the key was successfully added. | 223 // Returns kSuccess if the key was successfully added. |
| 151 // Returns kErrorUnknown otherwise. | 224 // Returns kError otherwise. |
| 152 virtual Status AddKey(const char* session_id, | 225 virtual Status AddKey(const char* session_id, |
| 153 int session_id_size, | 226 int session_id_size, |
| 154 const uint8_t* key, | 227 const uint8_t* key, |
| 155 int key_size, | 228 int key_size, |
| 156 const uint8_t* key_id, | 229 const uint8_t* key_id, |
| 157 int key_id_size) = 0; | 230 int key_id_size) = 0; |
| 158 | 231 |
| 159 // Cancels any pending key request made to the CDM for |session_id|. | 232 // Cancels any pending key request made to the CDM for |session_id|. |
| 160 // Returns kSuccess if all pending key requests for |session_id| were | 233 // Returns kSuccess if all pending key requests for |session_id| were |
| 161 // successfully canceled or there was no key request to be canceled. | 234 // successfully canceled or there was no key request to be canceled. |
| 162 // Returns kErrorUnknown otherwise. | 235 // Returns kError otherwise. |
| 163 virtual Status CancelKeyRequest(const char* session_id, | 236 virtual Status CancelKeyRequest(const char* session_id, |
| 164 int session_id_size) = 0; | 237 int session_id_size) = 0; |
| 165 | 238 |
| 166 // Decrypts the |encrypted_buffer|. | 239 // Decrypts the |encrypted_buffer|. |
| 167 // Returns kSuccess if decryption succeeded, in which case the callee | 240 // Returns kSuccess if decryption succeeded, in which case the callee |
| 168 // should have filled the |decrypted_buffer| and passed the ownership of | 241 // should have filled the |decrypted_buffer| and passed the ownership of |
| 169 // |data| in |decrypted_buffer| to the caller. | 242 // |data| in |decrypted_buffer| to the caller. |
| 170 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | 243 // Returns kNoKey if the CDM did not have the necessary decryption key |
| 171 // to decrypt. | 244 // to decrypt. |
| 172 // Returns kErrorUnknown if any other error happened. | 245 // Returns kError if any other error happened. |
| 173 // In these two cases, |decrypted_buffer| should not be used by the caller. | 246 // If the return value is not kSuccess, |decrypted_buffer| should be discarded |
| 247 // and not be used by the caller. | |
| 174 // | 248 // |
| 175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 249 // 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 | 250 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 177 // and sample CDM are landed. | 251 // and sample CDM are landed. |
| 178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 252 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
| 179 OutputBuffer* decrypted_buffer) = 0; | 253 OutputBuffer* decrypted_buffer) = 0; |
| 180 | 254 |
| 255 // Initializes the CDM video decoder with |video_decoder_config|. This | |
| 256 // function must be called before DecryptAndDecode() is called. | |
| 257 // Returns kSuccess if the |video_decoder_config| is supported and the CDM | |
| 258 // video decoder is successfully initialized. | |
| 259 // Returns kDecryptOnly if the |video_decoder_config| is not supported | |
| 260 // but the CDM can still be used to Decrypt() the video stream. | |
| 261 // Returns kError if |video_decoder_config| is not supported and the | |
| 262 // CDM can not be used (or is not allowed) to Decrypt() the video stream. | |
| 263 virtual Status InitializeVideoDecoder( | |
| 264 const VideoDecoderConfig& video_decoder_config) = 0; | |
| 265 | |
| 266 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a | |
| 267 // |video_frame|. Upon end-of-stream, the caller should call this function | |
| 268 // repeatedly with empty |encrypted_buffer| (|data| being NULL) until | |
| 269 // only empty |video_frame| (|format| being kEmpty) is produced. | |
| 270 // Returns kSuccess if decryption and decoding both succeeded, in which case | |
| 271 // the callee should have filled the |video_frame| and passed the ownership of | |
| 272 // |data| in |video_frame| to the caller. | |
| 273 // Returns kNoKey if the CDM did not have the necessary decryption key | |
| 274 // to decrypt. | |
| 275 // Returns kNeedMoreData if more data was needed by the decoder to generate | |
| 276 // a decoded frame (e.g. during initialization). | |
| 277 // Returns kError if any other (decryption or decoding) error happened. | |
| 278 // If the return value is not kSuccess, |video_frame| should be discarded and | |
| 279 // not be used by the caller. | |
| 280 // | |
| 281 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | |
| 282 // allocated memory over library boundaries. Fix it after related PPAPI change | |
| 283 // and sample CDM are landed. | |
| 284 virtual Status DecryptAndDecodeVideo(const InputBuffer& encrypted_buffer, | |
| 285 VideoFrame* video_frame) = 0; | |
| 286 | |
| 287 // Resets the CDM video decoder to an initialized clean state. | |
| 288 virtual void ResetVideoDecoder() = 0; | |
| 289 | |
| 290 // Stops the CDM video decoder and set it to an uninitialized state. Note | |
| 291 // that a VideoDecoder cannot be re-initialized after it has been stopped. | |
| 292 virtual void StopVideoDecoder() = 0; | |
| 293 | |
| 181 virtual ~ContentDecryptionModule() {} | 294 virtual ~ContentDecryptionModule() {} |
| 182 }; | 295 }; |
| 183 | 296 |
| 184 } // namespace cdm | 297 } // namespace cdm |
| 185 | 298 |
| 186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 299 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |