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 12 matching lines...) Expand all Loading... | |
| 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 kErrorUnknown, |
| 33 kErrorNoKey | 33 kErrorNoKey, |
| 34 kErrorDecryptOnly | |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and | 37 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and |
| 37 // update checks to include <0. | 38 // update checks to include <0. |
| 38 struct KeyMessage { | 39 struct KeyMessage { |
| 39 KeyMessage() | 40 KeyMessage() |
| 40 : session_id(NULL), | 41 : session_id(NULL), |
| 41 session_id_size(0), | 42 session_id_size(0), |
| 42 message(NULL), | 43 message(NULL), |
| 43 message_size(0), | 44 message_size(0), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 : data(NULL), | 123 : data(NULL), |
| 123 data_size(0), | 124 data_size(0), |
| 124 timestamp(0) {} | 125 timestamp(0) {} |
| 125 | 126 |
| 126 const uint8_t* data; // Pointer to the beginning of the output data. | 127 const uint8_t* data; // Pointer to the beginning of the output data. |
| 127 uint32_t data_size; // Size (in bytes) of |data|. | 128 uint32_t data_size; // Size (in bytes) of |data|. |
| 128 | 129 |
| 129 int64_t timestamp; // Presentation timestamp in microseconds. | 130 int64_t timestamp; // Presentation timestamp in microseconds. |
| 130 }; | 131 }; |
| 131 | 132 |
| 133 struct VideoFrame { | |
|
scherkus (not reviewing)
2012/09/01 12:33:08
this looks copied from media/base/video_frame.h
c
xhwang
2012/09/01 13:05:24
Done.
| |
| 134 // Surface formats roughly based on FOURCC labels, see: | |
| 135 // http://www.fourcc.org/rgb.php | |
| 136 // http://www.fourcc.org/yuv.php | |
| 137 enum Format { | |
| 138 INVALID = 0, // Invalid format value. Used for error reporting. | |
| 139 RGB32, // 32bpp RGB packed with extra byte 8:8:8. | |
| 140 YV12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. | |
| 141 YV16, // 16bpp YVU planar 1x1 Y, 2x1 VU samples. | |
| 142 EMPTY, // An empty frame. | |
| 143 I420, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | |
| 144 }; | |
| 145 | |
| 146 struct Size { | |
| 147 Size() : width(0), height(0) {} | |
| 148 Size(int32_t width, int32_t height) : width(width), height(height) {} | |
| 149 | |
| 150 int32_t width; | |
| 151 int32_t height; | |
| 152 }; | |
| 153 | |
| 154 static const int32_t kMaxPlanes = 3; | |
| 155 | |
| 156 VideoFrame() | |
| 157 : format(INVALID), | |
| 158 timestamp(0) { | |
| 159 for (int i = 0; i < kMaxPlanes; ++i) { | |
| 160 strides[i] = 0; | |
| 161 data[i] = NULL; | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 Format format; | |
| 166 | |
| 167 // Width and height of the video frame. | |
| 168 Size data_size; | |
| 169 | |
| 170 // Array of strides for each plane, typically greater or equal to the width | |
| 171 // of the surface divided by the horizontal sampling period. Note that | |
| 172 // strides can be negative. | |
| 173 int32_t strides[kMaxPlanes]; | |
| 174 | |
| 175 // Array of data pointers to each plane. | |
| 176 uint8_t* data[kMaxPlanes]; | |
| 177 | |
| 178 int64_t timestamp; // Presentation timestamp in microseconds. | |
| 179 }; | |
| 180 | |
| 181 struct VideoDeocderConfig { | |
| 182 enum VideoCodec { | |
| 183 kUnknownVideoCodec = 0, | |
| 184 kCodecH264, | |
| 185 kCodecVC1, | |
| 186 kCodecMPEG2, | |
| 187 kCodecMPEG4, | |
| 188 kCodecTheora, | |
|
scherkus (not reviewing)
2012/09/01 12:33:08
ditto
xhwang
2012/09/01 13:05:24
Done.
| |
| 189 kCodecVP8 | |
| 190 }; | |
| 191 | |
| 192 enum VideoCodecProfile { | |
| 193 VIDEO_CODEC_PROFILE_UNKNOWN = -1, | |
| 194 H264PROFILE_MIN = 0, | |
| 195 H264PROFILE_BASELINE = H264PROFILE_MIN, | |
| 196 H264PROFILE_MAIN = 1, | |
| 197 H264PROFILE_EXTENDED = 2, | |
| 198 H264PROFILE_HIGH = 3, | |
| 199 H264PROFILE_HIGH10PROFILE = 4, | |
| 200 H264PROFILE_HIGH422PROFILE = 5, | |
| 201 H264PROFILE_HIGH444PREDICTIVEPROFILE = 6, | |
| 202 H264PROFILE_SCALABLEBASELINE = 7, | |
| 203 H264PROFILE_SCALABLEHIGH = 8, | |
| 204 H264PROFILE_STEREOHIGH = 9, | |
| 205 H264PROFILE_MULTIVIEWHIGH = 10, | |
| 206 H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH, | |
| 207 VP8PROFILE_MIN = 11, | |
| 208 VP8PROFILE_MAIN = VP8PROFILE_MIN, | |
| 209 VP8PROFILE_MAX = VP8PROFILE_MAIN, | |
| 210 VIDEO_CODEC_PROFILE_MAX = VP8PROFILE_MAX | |
| 211 }; | |
| 212 | |
| 213 VideoCodec codec_; | |
| 214 VideoCodecProfile profile_; | |
| 215 VideoFrame::Format format; | |
| 216 VideoFrame::Size coded_size; | |
| 217 uint8_t* extra_data; | |
| 218 int32_t extra_data_size; | |
| 219 }; | |
| 220 | |
| 132 class ContentDecryptionModule { | 221 class ContentDecryptionModule { |
| 133 public: | 222 public: |
| 134 // Generates a |key_request| given the |init_data|. | 223 // Generates a |key_request| given the |init_data|. |
| 135 // Returns kSuccess if the key request was successfully generated, | 224 // Returns kSuccess if the key request was successfully generated, |
| 136 // in which case the callee should have allocated memory for the output | 225 // 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 | 226 // parameters (e.g |session_id| in |key_request|) and passed the ownership |
| 138 // to the caller. | 227 // to the caller. |
| 139 // Returns kErrorUnknown otherwise, in which case the output parameters should | 228 // Returns kErrorUnknown otherwise, in which case the output parameters should |
| 140 // not be used by the caller. | 229 // not be used by the caller. |
| 141 // | 230 // |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 171 // to decrypt. | 260 // to decrypt. |
| 172 // Returns kErrorUnknown if any other error happened. | 261 // Returns kErrorUnknown if any other error happened. |
| 173 // In these two cases, |decrypted_buffer| should not be used by the caller. | 262 // In these two cases, |decrypted_buffer| should not be used by the caller. |
| 174 // | 263 // |
| 175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 264 // 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 | 265 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 177 // and sample CDM are landed. | 266 // and sample CDM are landed. |
| 178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 267 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
| 179 OutputBuffer* decrypted_buffer) = 0; | 268 OutputBuffer* decrypted_buffer) = 0; |
| 180 | 269 |
| 270 // Initializes the CDM video decoder with |video_decoder_config|. This | |
| 271 // function must be called before DecryptAndDecode is called. | |
|
scherkus (not reviewing)
2012/09/01 12:33:08
append () to function names in comments
xhwang
2012/09/01 13:05:24
Done.
| |
| 272 // Returns kSuccess if the |video_decoder_config| is supported and the CDM | |
| 273 // video decoder is successfully initialized. | |
| 274 // Returns kErrorDecryptOnly if the |video_decoder_config| is not supported | |
| 275 // but the CDM can still be used to Decrypt() the video stream. | |
| 276 // Returns kErrorUnknown if |video_decoder_config| is not supported and the | |
| 277 // CDM can not be used (or is not allowed) to decrypt the video stream. | |
| 278 virtual Status InitializeVideoDecoder( | |
| 279 const VideoDeocderConfig& video_decoder_config) = 0; | |
| 280 | |
| 281 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a | |
| 282 // |video_frame|. Upon end-of-stream, the caller should call this function | |
| 283 // repeatedly with empty |encrypted_buffer| (where |data| is NULL) until | |
| 284 // only empty (|format| being EMPTY) |video_frame| can be produced. | |
| 285 // Returns kSuccess if decryption and decoding both succeeded, in which case | |
| 286 // the callee should have filled the |video_frame| and passed the ownership of | |
| 287 // |data| in |video_frame| to the caller. | |
| 288 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | |
| 289 // to decrypt. | |
| 290 // Returns kErrorUnknown if any other (decryption or decoding) error happened. | |
| 291 // In these two cases, |video_frame| should not be used by the caller. | |
| 292 // | |
| 293 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | |
| 294 // allocated memory over library boundaries. Fix it after related PPAPI change | |
| 295 // and sample CDM are landed. | |
| 296 virtual Status DecryptAndDecodeVideo(const InputBuffer& encrypted_buffer, | |
| 297 VideoFrame* video_frame) = 0; | |
| 298 | |
| 299 // Resets the CDM video decoder to an initialized clean state. | |
| 300 // Returns kSuccess if the video decoder is successfully reset. | |
| 301 // Returns kErrorUnknown otherwise. | |
| 302 virtual Status ResetVideoDecoder() = 0; | |
| 303 | |
| 304 // Stops the CDM video decoder and set it to an uninitialized state. Note | |
| 305 // that a VideoDecoder should/could not be re-initialized after it has been | |
| 306 // stopped. | |
| 307 // Returns kSuccess if the video decoder is successfully stopped. | |
| 308 // Returns kErrorUnknown otherwise. | |
| 309 virtual Status StopVideoDecoder() = 0; | |
| 310 | |
| 181 virtual ~ContentDecryptionModule() {} | 311 virtual ~ContentDecryptionModule() {} |
| 182 }; | 312 }; |
| 183 | 313 |
| 184 } // namespace cdm | 314 } // namespace cdm |
| 185 | 315 |
| 186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 316 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |