Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: webkit/media/crypto/ppapi/content_decryption_module.h

Issue 10900007: Add video decoding support in the CDM interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve ddorwin's comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/media/crypto/ppapi/clear_key_cdm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
xhwang 2012/09/05 15:36:50 Will add typedef for int32_t here.
xhwang 2012/09/05 17:13:30 Done.
11 typedef __int64 int64_t; 11 typedef __int64 int64_t;
12 #else 12 #else
13 #include <stdint.h> 13 #include <stdint.h>
14 #endif 14 #endif
15 15
16 #include "webkit/media/crypto/ppapi/cdm_export.h" 16 #include "webkit/media/crypto/ppapi/cdm_export.h"
17 17
18 namespace cdm { 18 namespace cdm {
19 class ContentDecryptionModule; 19 class ContentDecryptionModule;
20 } 20 }
21 21
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 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample.
33 kErrorNoKey 33 kNoKey, // The required decryption key is not available.
34 kError
34 }; 35 };
35 36
37 // Represents a key message sent by the CDM. It does not own any pointers in
38 // this struct.
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),
44 default_url(NULL), 47 default_url(NULL),
45 default_url_size(0) {} 48 default_url_size(0) {}
(...skipping 29 matching lines...) Expand all
75 // 78 //
76 // TODO(xhwang): Add checks to make sure these structs have fixed layout. 79 // TODO(xhwang): Add checks to make sure these structs have fixed layout.
77 struct SubsampleEntry { 80 struct SubsampleEntry {
78 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) 81 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes)
79 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} 82 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
80 83
81 uint32_t clear_bytes; 84 uint32_t clear_bytes;
82 uint32_t cipher_bytes; 85 uint32_t cipher_bytes;
83 }; 86 };
84 87
88 // Represents an input buffer to be decrypted (and possibly decoded). It does
89 // own any pointers in this struct.
85 struct InputBuffer { 90 struct InputBuffer {
86 InputBuffer() 91 InputBuffer()
87 : data(NULL), 92 : data(NULL),
88 data_size(0), 93 data_size(0),
89 data_offset(0), 94 data_offset(0),
90 key_id(NULL), 95 key_id(NULL),
91 key_id_size(0), 96 key_id_size(0),
92 iv(NULL), 97 iv(NULL),
93 iv_size(0), 98 iv_size(0),
94 checksum(NULL), 99 checksum(NULL),
(...skipping 15 matching lines...) Expand all
110 115
111 const uint8_t* checksum; 116 const uint8_t* checksum;
112 uint32_t checksum_size; // Size (in bytes) of the |checksum|. 117 uint32_t checksum_size; // Size (in bytes) of the |checksum|.
113 118
114 const struct SubsampleEntry* subsamples; 119 const struct SubsampleEntry* subsamples;
115 uint32_t num_subsamples; // Number of subsamples in |subsamples|. 120 uint32_t num_subsamples; // Number of subsamples in |subsamples|.
116 121
117 int64_t timestamp; // Presentation timestamp in microseconds. 122 int64_t timestamp; // Presentation timestamp in microseconds.
118 }; 123 };
119 124
125 // Represents an output decrypted buffer. It does not own |data|.
120 struct OutputBuffer { 126 struct OutputBuffer {
121 OutputBuffer() 127 OutputBuffer()
122 : data(NULL), 128 : data(NULL),
123 data_size(0), 129 data_size(0),
124 timestamp(0) {} 130 timestamp(0) {}
125 131
126 const uint8_t* data; // Pointer to the beginning of the output data. 132 const uint8_t* data; // Pointer to the beginning of the output data.
127 uint32_t data_size; // Size (in bytes) of |data|. 133 uint32_t data_size; // Size (in bytes) of |data|.
128 134
129 int64_t timestamp; // Presentation timestamp in microseconds. 135 int64_t timestamp; // Presentation timestamp in microseconds.
130 }; 136 };
131 137
138 // Surface formats based on FOURCC labels, see:
139 // http://www.fourcc.org/yuv.php
140 enum VideoFormat {
141 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
142 kEmptyVideoFrame, // An empty frame.
143 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
144 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
145 };
146
147 struct VideoSize {
scherkus (not reviewing) 2012/09/05 16:43:43 this looks like a general purpose size struct to m
xhwang 2012/09/05 17:13:30 Done.
148 VideoSize() : width(0), height(0) {}
149 VideoSize(int32_t width, int32_t height) : width(width), height(height) {}
150
151 int32_t width;
152 int32_t height;
153 };
154
155 struct VideoFrame {
156 static const int32_t kMaxPlanes = 3;
157
158 VideoFrame()
159 : timestamp(0) {
160 for (int i = 0; i < kMaxPlanes; ++i) {
161 strides[i] = 0;
162 data[i] = NULL;
163 }
164 }
165
166 // Array of strides for each plane, typically greater or equal to the width
167 // of the surface divided by the horizontal sampling period. Note that
168 // strides can be negative.
169 int32_t strides[kMaxPlanes];
170
171 // Array of data pointers to each plane.
172 uint8_t* data[kMaxPlanes];
173
174 int64_t timestamp; // Presentation timestamp in microseconds.
175 };
176
177 struct VideoDecoderConfig {
178 enum VideoCodec {
179 kUnknownVideoCodec = 0,
180 kCodecVP8
181 };
182
183 enum VideoCodecProfile {
184 kUnknownVideoCodecProfile = 0,
185 kVp8ProfileMain
186 };
187
188 VideoDecoderConfig()
189 : codec(kUnknownVideoCodec),
190 profile(kUnknownVideoCodecProfile),
191 format(kUnknownVideoFormat),
192 extra_data(NULL),
193 extra_data_size() {}
194
195 VideoCodec codec;
196 VideoCodecProfile profile;
197 VideoFormat format;
198
199 // Width and height of video frame immediately post-decode. Not all pixels
200 // in this region are valid.
201 VideoSize coded_size;
202
203 // Optional byte data required to initialize video decoders, such as H.264
204 // AAVC data.
205 uint8_t* extra_data;
206 int32_t extra_data_size;
207 };
208
132 class ContentDecryptionModule { 209 class ContentDecryptionModule {
133 public: 210 public:
134 // Generates a |key_request| given the |init_data|. 211 // Generates a |key_request| given the |init_data|.
scherkus (not reviewing) 2012/09/05 16:43:43 add blank line below to separate function summary
xhwang 2012/09/05 17:13:30 Done.
135 // Returns kSuccess if the key request was successfully generated, 212 // Returns kSuccess if the key request was successfully generated,
136 // in which case the callee should have allocated memory for the output 213 // 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 214 // parameters (e.g |session_id| in |key_request|) and passed the ownership
138 // to the caller. 215 // to the caller.
139 // Returns kErrorUnknown otherwise, in which case the output parameters should 216 // Returns kError otherwise, in which case the output parameters should
140 // not be used by the caller. 217 // not be used by the caller.
141 // 218 //
142 // TODO(xhwang): It's not safe to pass the ownership of the dynamically 219 // 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 220 // allocated memory over library boundaries. Fix it after related PPAPI change
144 // and sample CDM are landed. 221 // and sample CDM are landed.
145 virtual Status GenerateKeyRequest(const uint8_t* init_data, 222 virtual Status GenerateKeyRequest(const uint8_t* init_data,
146 int init_data_size, 223 int init_data_size,
147 KeyMessage* key_request) = 0; 224 KeyMessage* key_request) = 0;
148 225
149 // Adds the |key| to the CDM to be associated with |key_id|. 226 // Adds the |key| to the CDM to be associated with |key_id|.
scherkus (not reviewing) 2012/09/05 16:43:43 add blank line below to separate function summary
xhwang 2012/09/05 17:13:30 Done.
150 // Returns kSuccess if the key was successfully added. 227 // Returns kSuccess if the key was successfully added.
151 // Returns kErrorUnknown otherwise. 228 // Returns kError otherwise.
scherkus (not reviewing) 2012/09/05 16:43:43 this isn't a sentence -- I'd rewrite this as: Ret
xhwang 2012/09/05 17:13:30 Done.
152 virtual Status AddKey(const char* session_id, 229 virtual Status AddKey(const char* session_id,
153 int session_id_size, 230 int session_id_size,
154 const uint8_t* key, 231 const uint8_t* key,
155 int key_size, 232 int key_size,
156 const uint8_t* key_id, 233 const uint8_t* key_id,
157 int key_id_size) = 0; 234 int key_id_size) = 0;
158 235
159 // Cancels any pending key request made to the CDM for |session_id|. 236 // Cancels any pending key request made to the CDM for |session_id|.
scherkus (not reviewing) 2012/09/05 16:43:43 add blank line below to separate function summary
xhwang 2012/09/05 17:13:30 Done.
160 // Returns kSuccess if all pending key requests for |session_id| were 237 // Returns kSuccess if all pending key requests for |session_id| were
161 // successfully canceled or there was no key request to be canceled. 238 // successfully canceled or there was no key request to be canceled.
162 // Returns kErrorUnknown otherwise. 239 // Returns kError otherwise.
scherkus (not reviewing) 2012/09/05 16:43:43 ditto
xhwang 2012/09/05 17:13:30 Done.
163 virtual Status CancelKeyRequest(const char* session_id, 240 virtual Status CancelKeyRequest(const char* session_id,
164 int session_id_size) = 0; 241 int session_id_size) = 0;
165 242
166 // Decrypts the |encrypted_buffer|. 243 // Decrypts the |encrypted_buffer|.
scherkus (not reviewing) 2012/09/05 16:43:43 add blank line below to separate function summary
xhwang 2012/09/05 17:13:30 Done.
167 // Returns kSuccess if decryption succeeded, in which case the callee 244 // Returns kSuccess if decryption succeeded, in which case the callee
168 // should have filled the |decrypted_buffer| and passed the ownership of 245 // should have filled the |decrypted_buffer| and passed the ownership of
169 // |data| in |decrypted_buffer| to the caller. 246 // |data| in |decrypted_buffer| to the caller.
170 // Returns kErrorNoKey if the CDM did not have the necessary decryption key 247 // Returns kNoKey if the CDM did not have the necessary decryption key
171 // to decrypt. 248 // to decrypt.
172 // Returns kErrorUnknown if any other error happened. 249 // Returns kError if any other error happened.
scherkus (not reviewing) 2012/09/05 16:43:43 Returns kSuccess if the key was successfully added
xhwang 2012/09/05 17:13:30 This doesn't apply directly. I'll keep it as is.
173 // In these two cases, |decrypted_buffer| should not be used by the caller. 250 // If the return value is not kSuccess, |decrypted_buffer| should be ignored
251 // by the caller.
174 // 252 //
175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically 253 // 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 254 // allocated memory over library boundaries. Fix it after related PPAPI change
177 // and sample CDM are landed. 255 // and sample CDM are landed.
178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, 256 virtual Status Decrypt(const InputBuffer& encrypted_buffer,
179 OutputBuffer* decrypted_buffer) = 0; 257 OutputBuffer* decrypted_buffer) = 0;
180 258
259 // Initializes the CDM video decoder with |video_decoder_config|. This
260 // function must be called before DecryptAndDecodeVideo() is called.
scherkus (not reviewing) 2012/09/05 16:43:43 add blank line below to separate function summary
xhwang 2012/09/05 17:13:30 Done.
261 // Returns kSuccess if the |video_decoder_config| is supported and the CDM
262 // video decoder is successfully initialized.
263 // Returns kError if |video_decoder_config| is not supported. The CDM may
264 // still be able to do Decrypt().
265 //
266 // TODO(xhwang): Add stream ID here and in the following video decoder
267 // functions when we need to support multiple video streams in one CDM.
268 virtual Status InitializeVideoDecoder(
269 const VideoDecoderConfig& video_decoder_config) = 0;
270
271 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
272 // |video_frame|. Upon end-of-stream, the caller should call this function
273 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
274 // |video_frame| (|format| == kEmptyVideoFrame) is produced.
scherkus (not reviewing) 2012/09/05 16:43:43 add blank line below to separate function summary
xhwang 2012/09/05 17:13:30 Done.
275 // Returns kSuccess if decryption and decoding both succeeded, in which case
scherkus (not reviewing) 2012/09/05 16:43:43 ditto for vertical whitespacing
xhwang 2012/09/05 17:13:30 ?
276 // the callee should have filled the |video_frame| and passed the ownership of
277 // |data| in |video_frame| to the caller.
278 // Returns kNoKey if the CDM did not have the necessary decryption key
279 // to decrypt.
280 // Returns kNeedMoreData if more data was needed by the decoder to generate
281 // a decoded frame (e.g. during initialization).
282 // Returns kError if any other (decryption or decoding) error happened.
283 // If the return value is not kSuccess, |video_frame| should be ignored by
284 // the caller.
285 //
286 // TODO(xhwang): It's not safe to pass the ownership of the dynamically
287 // allocated memory over library boundaries. Fix it after related PPAPI change
288 // and sample CDM are landed.
289 virtual Status DecryptAndDecodeVideo(const InputBuffer& encrypted_buffer,
290 VideoFrame* video_frame) = 0;
291
292 // Resets the CDM video decoder to an initialized clean state. All internally
ddorwin 2012/09/05 14:52:29 s/internally/internal/
xhwang 2012/09/05 17:13:30 Done.
293 // buffers will be flushed.
294 virtual void ResetVideoDecoder() = 0;
295
296 // Stops the CDM video decoder and sets it to an uninitialized state. The
297 // caller can call InitializeVideoDecoder() again after this call to
scherkus (not reviewing) 2012/09/05 16:43:43 do you have a use case for this? if not I'd recom
xhwang 2012/09/05 17:13:30 This will be used for config change, in which case
298 // re-initialize the video decoder.
299 virtual void StopVideoDecoder() = 0;
300
181 virtual ~ContentDecryptionModule() {} 301 virtual ~ContentDecryptionModule() {}
182 }; 302 };
183 303
184 } // namespace cdm 304 } // namespace cdm
185 305
186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ 306 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_
OLDNEW
« no previous file with comments | « webkit/media/crypto/ppapi/clear_key_cdm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698