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 { | |
| 134 // Surface formats based on FOURCC labels, see: | |
| 135 // http://www.fourcc.org/yuv.php | |
| 136 enum Format { | |
| 137 kInvalidFormat = 0, // Invalid format value. Used for error reporting. | |
| 138 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | |
|
xhwang
2012/09/01 13:14:37
Tom: in vp8, we use I420, not YV12, correct?
| |
| 139 }; | |
| 140 | |
| 141 struct Size { | |
| 142 Size() : width(0), height(0) {} | |
| 143 Size(int32_t width, int32_t height) : width(width), height(height) {} | |
| 144 | |
| 145 int32_t width; | |
| 146 int32_t height; | |
| 147 }; | |
| 148 | |
| 149 static const int32_t kMaxPlanes = 3; | |
| 150 | |
| 151 VideoFrame() | |
| 152 : format(kInvalidFormat), | |
| 153 timestamp(0) { | |
| 154 for (int i = 0; i < kMaxPlanes; ++i) { | |
| 155 strides[i] = 0; | |
| 156 data[i] = NULL; | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 Format format; | |
| 161 | |
| 162 // Width and height of the video frame. | |
| 163 Size data_size; | |
| 164 | |
| 165 // Array of strides for each plane, typically greater or equal to the width | |
| 166 // of the surface divided by the horizontal sampling period. Note that | |
| 167 // strides can be negative. | |
| 168 int32_t strides[kMaxPlanes]; | |
| 169 | |
| 170 // Array of data pointers to each plane. | |
| 171 uint8_t* data[kMaxPlanes]; | |
| 172 | |
| 173 int64_t timestamp; // Presentation timestamp in microseconds. | |
| 174 }; | |
| 175 | |
| 176 struct VideoDeocderConfig { | |
|
scherkus (not reviewing)
2012/09/02 09:13:24
typo
xhwang
2012/09/02 10:40:33
Done.
| |
| 177 enum VideoCodec { | |
| 178 kUnknownVideoCodec = 0, | |
| 179 kCodecVP8 | |
| 180 }; | |
| 181 | |
| 182 enum VideoCodecProfile { | |
| 183 kUnknownVideoCodecProfile = 0, | |
| 184 kVp8ProfileMain | |
| 185 }; | |
| 186 | |
| 187 VideoDeocderConfig() | |
| 188 : codec(kUnknownVideoCodec), | |
| 189 profile(kUnknownVideoCodecProfile), | |
| 190 format(VideoFrame::kInvalidFormat), | |
| 191 extra_data(NULL), | |
| 192 extra_data_size() {} | |
| 193 | |
| 194 VideoCodec codec; | |
| 195 VideoCodecProfile profile; | |
| 196 VideoFrame::Format format; | |
| 197 VideoFrame::Size coded_size; | |
| 198 uint8_t* extra_data; | |
| 199 int32_t extra_data_size; | |
| 200 }; | |
| 201 | |
| 132 class ContentDecryptionModule { | 202 class ContentDecryptionModule { |
| 133 public: | 203 public: |
| 134 // Generates a |key_request| given the |init_data|. | 204 // Generates a |key_request| given the |init_data|. |
| 135 // Returns kSuccess if the key request was successfully generated, | 205 // Returns kSuccess if the key request was successfully generated, |
| 136 // in which case the callee should have allocated memory for the output | 206 // 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 | 207 // parameters (e.g |session_id| in |key_request|) and passed the ownership |
| 138 // to the caller. | 208 // to the caller. |
| 139 // Returns kErrorUnknown otherwise, in which case the output parameters should | 209 // Returns kErrorUnknown otherwise, in which case the output parameters should |
| 140 // not be used by the caller. | 210 // not be used by the caller. |
| 141 // | 211 // |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 171 // to decrypt. | 241 // to decrypt. |
| 172 // Returns kErrorUnknown if any other error happened. | 242 // Returns kErrorUnknown if any other error happened. |
| 173 // In these two cases, |decrypted_buffer| should not be used by the caller. | 243 // In these two cases, |decrypted_buffer| should not be used by the caller. |
| 174 // | 244 // |
| 175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 245 // 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 | 246 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 177 // and sample CDM are landed. | 247 // and sample CDM are landed. |
| 178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 248 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
| 179 OutputBuffer* decrypted_buffer) = 0; | 249 OutputBuffer* decrypted_buffer) = 0; |
| 180 | 250 |
| 251 // Initializes the CDM video decoder with |video_decoder_config|. This | |
| 252 // function must be called before DecryptAndDecode() is called. | |
| 253 // Returns kSuccess if the |video_decoder_config| is supported and the CDM | |
| 254 // video decoder is successfully initialized. | |
| 255 // Returns kErrorDecryptOnly if the |video_decoder_config| is not supported | |
| 256 // but the CDM can still be used to Decrypt() the video stream. | |
| 257 // Returns kErrorUnknown if |video_decoder_config| is not supported and the | |
| 258 // CDM can not be used (or is not allowed) to Decrypt() the video stream. | |
| 259 virtual Status InitializeVideoDecoder( | |
| 260 const VideoDeocderConfig& video_decoder_config) = 0; | |
| 261 | |
| 262 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a | |
| 263 // |video_frame|. Upon end-of-stream, the caller should call this function | |
| 264 // repeatedly with empty |encrypted_buffer| (where |data| is NULL) until | |
| 265 // only empty (|format| being EMPTY) |video_frame| can be produced. | |
|
scherkus (not reviewing)
2012/09/02 09:13:24
what's EMPTY? I only see kInvalidFormat
xhwang
2012/09/02 10:40:33
Done.
| |
| 266 // Returns kSuccess if decryption and decoding both succeeded, in which case | |
| 267 // the callee should have filled the |video_frame| and passed the ownership of | |
| 268 // |data| in |video_frame| to the caller. | |
|
scherkus (not reviewing)
2012/09/02 09:13:24
what about decoders with delay? the first few call
xhwang
2012/09/02 10:40:33
Done.
| |
| 269 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | |
| 270 // to decrypt. | |
| 271 // Returns kErrorUnknown if any other (decryption or decoding) error happened. | |
| 272 // In these two cases, |video_frame| should not be used by the caller. | |
| 273 // | |
| 274 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | |
| 275 // allocated memory over library boundaries. Fix it after related PPAPI change | |
| 276 // and sample CDM are landed. | |
| 277 virtual Status DecryptAndDecodeVideo(const InputBuffer& encrypted_buffer, | |
| 278 VideoFrame* video_frame) = 0; | |
| 279 | |
| 280 // Resets the CDM video decoder to an initialized clean state. | |
| 281 // Returns kSuccess if the video decoder is successfully reset. | |
| 282 // Returns kErrorUnknown otherwise. | |
| 283 virtual Status ResetVideoDecoder() = 0; | |
| 284 | |
| 285 // Stops the CDM video decoder and set it to an uninitialized state. Note | |
| 286 // that a VideoDecoder should/could not be re-initialized after it has been | |
|
scherkus (not reviewing)
2012/09/02 09:13:24
should/could not -> cannot
xhwang
2012/09/02 10:40:33
Done.
| |
| 287 // stopped. | |
| 288 // Returns kSuccess if the video decoder is successfully stopped. | |
| 289 // Returns kErrorUnknown otherwise. | |
| 290 virtual Status StopVideoDecoder() = 0; | |
|
scherkus (not reviewing)
2012/09/02 09:13:24
what does Stop() + kErrorUnknown mean?
xhwang
2012/09/02 10:40:33
Right, in media code the callback is a closure. Up
| |
| 291 | |
| 181 virtual ~ContentDecryptionModule() {} | 292 virtual ~ContentDecryptionModule() {} |
| 182 }; | 293 }; |
| 183 | 294 |
| 184 } // namespace cdm | 295 } // namespace cdm |
| 185 | 296 |
| 186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 297 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |