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 doing DecryptAndDecode() for the |
| 33 kErrorNoKey | 33 // requested decoder config but can still be used to do |
| 34 // Decrypt() only. | |
| 35 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. | |
| 36 kNoKey, // The decryption key is not available for decryption. | |
|
ddorwin
2012/09/05 09:37:58
The required decryption key is not available.
xhwang
2012/09/05 14:02:00
Done.
| |
| 37 kError | |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and | 40 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and |
| 37 // update checks to include <0. | 41 // update checks to include <0. |
| 38 struct KeyMessage { | 42 struct KeyMessage { |
| 39 KeyMessage() | 43 KeyMessage() |
| 40 : session_id(NULL), | 44 : session_id(NULL), |
| 41 session_id_size(0), | 45 session_id_size(0), |
| 42 message(NULL), | 46 message(NULL), |
| 43 message_size(0), | 47 message_size(0), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 114 |
| 111 const uint8_t* checksum; | 115 const uint8_t* checksum; |
| 112 uint32_t checksum_size; // Size (in bytes) of the |checksum|. | 116 uint32_t checksum_size; // Size (in bytes) of the |checksum|. |
| 113 | 117 |
| 114 const struct SubsampleEntry* subsamples; | 118 const struct SubsampleEntry* subsamples; |
| 115 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | 119 uint32_t num_subsamples; // Number of subsamples in |subsamples|. |
| 116 | 120 |
| 117 int64_t timestamp; // Presentation timestamp in microseconds. | 121 int64_t timestamp; // Presentation timestamp in microseconds. |
| 118 }; | 122 }; |
| 119 | 123 |
| 120 struct OutputBuffer { | 124 struct OutputBuffer { |
|
ddorwin
2012/09/05 09:37:58
// Represents an output buffer.
// Does not own th
xhwang
2012/09/05 14:02:00
Done.
| |
| 121 OutputBuffer() | 125 OutputBuffer() |
| 122 : data(NULL), | 126 : data(NULL), |
| 123 data_size(0), | 127 data_size(0), |
| 124 timestamp(0) {} | 128 timestamp(0) {} |
| 125 | 129 |
| 126 const uint8_t* data; // Pointer to the beginning of the output data. | 130 const uint8_t* data; // Pointer to the beginning of the output data. |
| 127 uint32_t data_size; // Size (in bytes) of |data|. | 131 uint32_t data_size; // Size (in bytes) of |data|. |
| 128 | 132 |
| 129 int64_t timestamp; // Presentation timestamp in microseconds. | 133 int64_t timestamp; // Presentation timestamp in microseconds. |
| 130 }; | 134 }; |
| 131 | 135 |
| 136 // Surface formats based on FOURCC labels, see: | |
| 137 // http://www.fourcc.org/yuv.php | |
| 138 enum VideoFormat { | |
| 139 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. | |
| 140 kEmptyVideoFrame, // An empty frame. | |
| 141 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. | |
| 142 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | |
|
xhwang
2012/09/04 15:08:18
I am not totally clear about what formats we will
| |
| 143 }; | |
| 144 | |
| 145 struct VideoSize { | |
| 146 VideoSize() : width(0), height(0) {} | |
| 147 VideoSize(int32_t width, int32_t height) : width(width), height(height) {} | |
| 148 | |
| 149 int32_t width; | |
| 150 int32_t height; | |
| 151 }; | |
| 152 | |
| 153 struct VideoFrame { | |
| 154 static const int32_t kMaxPlanes = 3; | |
| 155 | |
| 156 VideoFrame() | |
| 157 : format(kUnknownVideoFormat), | |
| 158 timestamp(0) { | |
| 159 for (int i = 0; i < kMaxPlanes; ++i) { | |
| 160 strides[i] = 0; | |
| 161 data[i] = NULL; | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 VideoFormat format; | |
|
ddorwin
2012/09/05 09:37:58
As discussed in 10899021, why do we need format an
xhwang
2012/09/05 14:02:00
In src/media, video decoder config is only used in
| |
| 166 | |
| 167 // Width and height of the video frame. | |
| 168 VideoSize data_size; | |
|
xhwang
2012/09/04 15:08:18
scherkus@: my understanding is that this is the sa
| |
| 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 VideoDecoderConfig { | |
| 182 enum VideoCodec { | |
| 183 kUnknownVideoCodec = 0, | |
| 184 kCodecVP8 | |
| 185 }; | |
| 186 | |
| 187 enum VideoCodecProfile { | |
| 188 kUnknownVideoCodecProfile = 0, | |
| 189 kVp8ProfileMain | |
| 190 }; | |
| 191 | |
| 192 VideoDecoderConfig() | |
| 193 : codec(kUnknownVideoCodec), | |
| 194 profile(kUnknownVideoCodecProfile), | |
| 195 format(kUnknownVideoFormat), | |
| 196 extra_data(NULL), | |
| 197 extra_data_size() {} | |
| 198 | |
| 199 VideoCodec codec; | |
| 200 VideoCodecProfile profile; | |
| 201 VideoFormat format; | |
| 202 | |
| 203 // Width and height of video frame immediately post-decode. Not all pixels | |
| 204 // in this region are valid. | |
| 205 VideoSize coded_size; | |
| 206 | |
| 207 // Optional byte data required to initialize video decoders, such as H.264 | |
| 208 // AAVC data. | |
| 209 uint8_t* extra_data; | |
| 210 int32_t extra_data_size; | |
| 211 }; | |
| 212 | |
| 132 class ContentDecryptionModule { | 213 class ContentDecryptionModule { |
| 133 public: | 214 public: |
| 134 // Generates a |key_request| given the |init_data|. | 215 // Generates a |key_request| given the |init_data|. |
| 135 // Returns kSuccess if the key request was successfully generated, | 216 // Returns kSuccess if the key request was successfully generated, |
| 136 // in which case the callee should have allocated memory for the output | 217 // 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 | 218 // parameters (e.g |session_id| in |key_request|) and passed the ownership |
| 138 // to the caller. | 219 // to the caller. |
| 139 // Returns kErrorUnknown otherwise, in which case the output parameters should | 220 // Returns kError otherwise, in which case the output parameters should |
| 140 // not be used by the caller. | 221 // not be used by the caller. |
| 141 // | 222 // |
| 142 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 223 // 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 | 224 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 144 // and sample CDM are landed. | 225 // and sample CDM are landed. |
| 145 virtual Status GenerateKeyRequest(const uint8_t* init_data, | 226 virtual Status GenerateKeyRequest(const uint8_t* init_data, |
| 146 int init_data_size, | 227 int init_data_size, |
| 147 KeyMessage* key_request) = 0; | 228 KeyMessage* key_request) = 0; |
| 148 | 229 |
| 149 // Adds the |key| to the CDM to be associated with |key_id|. | 230 // Adds the |key| to the CDM to be associated with |key_id|. |
| 150 // Returns kSuccess if the key was successfully added. | 231 // Returns kSuccess if the key was successfully added. |
| 151 // Returns kErrorUnknown otherwise. | 232 // Returns kError otherwise. |
| 152 virtual Status AddKey(const char* session_id, | 233 virtual Status AddKey(const char* session_id, |
| 153 int session_id_size, | 234 int session_id_size, |
| 154 const uint8_t* key, | 235 const uint8_t* key, |
| 155 int key_size, | 236 int key_size, |
| 156 const uint8_t* key_id, | 237 const uint8_t* key_id, |
| 157 int key_id_size) = 0; | 238 int key_id_size) = 0; |
| 158 | 239 |
| 159 // Cancels any pending key request made to the CDM for |session_id|. | 240 // Cancels any pending key request made to the CDM for |session_id|. |
| 160 // Returns kSuccess if all pending key requests for |session_id| were | 241 // Returns kSuccess if all pending key requests for |session_id| were |
| 161 // successfully canceled or there was no key request to be canceled. | 242 // successfully canceled or there was no key request to be canceled. |
| 162 // Returns kErrorUnknown otherwise. | 243 // Returns kError otherwise. |
| 163 virtual Status CancelKeyRequest(const char* session_id, | 244 virtual Status CancelKeyRequest(const char* session_id, |
| 164 int session_id_size) = 0; | 245 int session_id_size) = 0; |
| 165 | 246 |
| 166 // Decrypts the |encrypted_buffer|. | 247 // Decrypts the |encrypted_buffer|. |
| 167 // Returns kSuccess if decryption succeeded, in which case the callee | 248 // Returns kSuccess if decryption succeeded, in which case the callee |
| 168 // should have filled the |decrypted_buffer| and passed the ownership of | 249 // should have filled the |decrypted_buffer| and passed the ownership of |
| 169 // |data| in |decrypted_buffer| to the caller. | 250 // |data| in |decrypted_buffer| to the caller. |
| 170 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | 251 // Returns kNoKey if the CDM did not have the necessary decryption key |
| 171 // to decrypt. | 252 // to decrypt. |
| 172 // Returns kErrorUnknown if any other error happened. | 253 // Returns kError if any other error happened. |
| 173 // In these two cases, |decrypted_buffer| should not be used by the caller. | 254 // If the return value is not kSuccess, |decrypted_buffer| should be discarded |
|
ddorwin
2012/09/05 09:37:58
What does "discarded" mean exactly? Ignored or des
xhwang
2012/09/05 14:02:00
Done.
| |
| 255 // and not be used by the caller. | |
| 174 // | 256 // |
| 175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 257 // 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 | 258 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 177 // and sample CDM are landed. | 259 // and sample CDM are landed. |
| 178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 260 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
| 179 OutputBuffer* decrypted_buffer) = 0; | 261 OutputBuffer* decrypted_buffer) = 0; |
| 180 | 262 |
| 263 // Initializes the CDM video decoder with |video_decoder_config|. This | |
|
ddorwin
2012/09/05 09:37:58
In 10899021, I suggested moving this up so that De
xhwang
2012/09/05 14:02:00
I am grouping *Video* together. Later will also gr
| |
| 264 // function must be called before DecryptAndDecodeVideo() is called. | |
| 265 // Returns kSuccess if the |video_decoder_config| is supported and the CDM | |
| 266 // video decoder is successfully initialized. | |
| 267 // Returns kDecryptOnly if the |video_decoder_config| is not supported | |
| 268 // but the CDM can still be used to Decrypt() the video stream. | |
| 269 // Returns kError if |video_decoder_config| is not supported and the | |
| 270 // CDM can not be used (or is not allowed) to Decrypt() the video stream. | |
|
ddorwin
2012/09/05 09:37:58
Can "allowed" really be determined during initiali
xhwang
2012/09/05 14:02:00
Removed kDecryptOnly. If InitializeVideoDecoder()
| |
| 271 virtual Status InitializeVideoDecoder( | |
|
ddorwin
2012/09/05 09:37:58
Nothing to do now, but something to consider when
xhwang
2012/09/05 14:02:00
Good point. Added a todo.
| |
| 272 const VideoDecoderConfig& video_decoder_config) = 0; | |
| 273 | |
| 274 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a | |
| 275 // |video_frame|. Upon end-of-stream, the caller should call this function | |
| 276 // repeatedly with empty |encrypted_buffer| (|data| being NULL) until | |
|
ddorwin
2012/09/05 09:37:58
Suggestion: The following might be easier to read.
xhwang
2012/09/05 14:02:00
Done.
| |
| 277 // only empty |video_frame| (|format| being kEmptyVideoFrame) is produced. | |
| 278 // Returns kSuccess if decryption and decoding both succeeded, in which case | |
| 279 // the callee should have filled the |video_frame| and passed the ownership of | |
| 280 // |data| in |video_frame| to the caller. | |
| 281 // Returns kNoKey if the CDM did not have the necessary decryption key | |
| 282 // to decrypt. | |
| 283 // Returns kNeedMoreData if more data was needed by the decoder to generate | |
| 284 // a decoded frame (e.g. during initialization). | |
| 285 // Returns kError if any other (decryption or decoding) error happened. | |
| 286 // If the return value is not kSuccess, |video_frame| should be discarded and | |
|
ddorwin
2012/09/05 09:37:58
Same wrt "discarded".
xhwang
2012/09/05 14:02:00
Done.
| |
| 287 // not be used by the caller. | |
| 288 // | |
| 289 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | |
| 290 // allocated memory over library boundaries. Fix it after related PPAPI change | |
| 291 // and sample CDM are landed. | |
| 292 virtual Status DecryptAndDecodeVideo(const InputBuffer& encrypted_buffer, | |
| 293 VideoFrame* video_frame) = 0; | |
| 294 | |
| 295 // Resets the CDM video decoder to an initialized clean state. | |
|
ddorwin
2012/09/05 09:37:58
... Any in-process frames are flushed.
^ or so
xhwang
2012/09/05 14:02:00
Done.
| |
| 296 virtual void ResetVideoDecoder() = 0; | |
|
xhwang
2012/09/04 15:08:18
In 10899021 it's changed to Flush*.
AudioDecoder/
| |
| 297 | |
| 298 // Stops the CDM video decoder and set it to an uninitialized state. Note | |
|
ddorwin
2012/09/05 09:37:58
s/set/sets/
xhwang
2012/09/05 14:02:00
Done.
| |
| 299 // that a VideoDecoder cannot be re-initialized after it has been stopped. | |
|
xhwang
2012/09/04 15:08:18
This will not be true in the future if we need to
ddorwin
2012/09/05 09:37:58
We do. I think this is likely to be a V1 requireme
xhwang
2012/09/05 14:02:00
I chatted w/ acolwell@ offline. We are not doing s
| |
| 300 virtual void StopVideoDecoder() = 0; | |
| 301 | |
| 181 virtual ~ContentDecryptionModule() {} | 302 virtual ~ContentDecryptionModule() {} |
| 182 }; | 303 }; |
| 183 | 304 |
| 184 } // namespace cdm | 305 } // namespace cdm |
| 185 | 306 |
| 186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ | 307 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |