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

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

Issue 10899021: Add CDM video decoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compiles, does nothing. 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
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;
11 typedef int int32_t;
11 typedef __int64 int64_t; 12 typedef __int64 int64_t;
12 #else 13 #else
13 #include <stdint.h> 14 #include <stdint.h>
14 #endif 15 #endif
15 16
17 #include "base/time.h"
16 #include "webkit/media/crypto/ppapi/cdm_export.h" 18 #include "webkit/media/crypto/ppapi/cdm_export.h"
17 19
18 namespace cdm { 20 namespace cdm {
19 class ContentDecryptionModule; 21 class ContentDecryptionModule;
20 } 22 }
21 23
22 extern "C" { 24 extern "C" {
23 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); 25 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance();
24 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); 26 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance);
25 CDM_EXPORT const char* GetCdmVersion(); 27 CDM_EXPORT const char* GetCdmVersion();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 : data(NULL), 124 : data(NULL),
123 data_size(0), 125 data_size(0),
124 timestamp(0) {} 126 timestamp(0) {}
125 127
126 const uint8_t* data; // Pointer to the beginning of the output data. 128 const uint8_t* data; // Pointer to the beginning of the output data.
127 uint32_t data_size; // Size (in bytes) of |data|. 129 uint32_t data_size; // Size (in bytes) of |data|.
128 130
129 int64_t timestamp; // Presentation timestamp in microseconds. 131 int64_t timestamp; // Presentation timestamp in microseconds.
130 }; 132 };
131 133
134 struct VideoFrame {
135 // Surface formats roughly based on FOURCC labels, see:
136 // http://www.fourcc.org/rgb.php
137 // http://www.fourcc.org/yuv.php
138 enum ColorFormat {
139 // Values are skipped in here to keep them synchronized with
ddorwin 2012/09/02 21:39:08 Is there a reason these need to be synchronized? A
140 // media::VideoFrame::Format.
141 kFormatInvalid = 0, // Invalid format value. Used for error reporting.
142 kFormatYv12 = 2, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
143 kFormatEmpty = 4, // An empty frame.
144 kFormatI420 = 5, // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
145 };
146
147 struct Size {
148 Size() : width(0), height(0) {}
149 Size(int32_t width, int32_t height) : width(width), height(height) {}
150
151 int32_t width;
152 int32_t height;
153 };
154
155 const static int32_t kMaxPlanes = 3;
156
157 VideoFrame() : format(kFormatInvalid) {
158 for (int i = 0; i < kMaxPlanes; ++i) {
159 strides[i] = 0;
160 data[i] = NULL;
161 }
162 }
163
164 ColorFormat format;
165
166 // Width and height of the video frame.
167 Size frame_size;
168
169 // Array of strides for each plane, typically greater or equal to the width
170 // of the surface divided by the horizontal sampling period. Note that
171 // strides can be negative.
172 int32_t strides[kMaxPlanes];
173
174 // Array of data pointers to each plane.
175 uint8_t* data[kMaxPlanes];
176
177 base::TimeDelta timestamp; // Presentation timestamp in microseconds.
178 };
179
180 struct VideoDecoderConfig {
181 enum VideoCodec {
182 kCodecUnknown = 0,
183 kCodecH264,
184 kCodecVp8 = 6 // matches value from media::VideoCodec.
185 };
186
187 enum VideoCodecProfile {
188 VIDEO_CODEC_PROFILE_UNKNOWN = -1,
189 H264PROFILE_MIN = 0,
190 H264PROFILE_BASELINE = H264PROFILE_MIN,
191 H264PROFILE_MAIN = 1,
192 H264PROFILE_EXTENDED = 2,
193 H264PROFILE_HIGH = 3,
194 H264PROFILE_HIGH10PROFILE = 4,
195 H264PROFILE_HIGH422PROFILE = 5,
196 H264PROFILE_HIGH444PREDICTIVEPROFILE = 6,
197 H264PROFILE_SCALABLEBASELINE = 7,
198 H264PROFILE_SCALABLEHIGH = 8,
199 H264PROFILE_STEREOHIGH = 9,
200 H264PROFILE_MULTIVIEWHIGH = 10,
201 H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH,
202 VP8PROFILE_MIN = 11,
203 VP8PROFILE_MAIN = VP8PROFILE_MIN,
204 VP8PROFILE_MAX = VP8PROFILE_MAIN,
205 VIDEO_CODEC_PROFILE_MAX = VP8PROFILE_MAX
206 };
207
208 VideoCodec codec;
209 VideoCodecProfile profile;
210 VideoFrame::ColorFormat format;
ddorwin 2012/09/02 21:39:08 Odd that we have to use the other class's enum. Ma
xhwang 2012/09/04 14:50:21 Done in http://codereview.chromium.org/10900007/
211 VideoFrame::Size frame_size;
212 uint8_t* extra_data;
213 int32_t extra_data_size;
214
215 VideoDecoderConfig()
216 : codec(kCodecUnknown),
217 profile(VIDEO_CODEC_PROFILE_UNKNOWN),
218 format(VideoFrame::kFormatInvalid),
219 frame_size(0, 0),
220 extra_data(NULL),
221 extra_data_size(0) {}
222 };
223
132 class ContentDecryptionModule { 224 class ContentDecryptionModule {
133 public: 225 public:
134 // Generates a |key_request| given the |init_data|. 226 // Generates a |key_request| given the |init_data|.
135 // Returns kSuccess if the key request was successfully generated, 227 // Returns kSuccess if the key request was successfully generated,
136 // in which case the callee should have allocated memory for the output 228 // 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 229 // parameters (e.g |session_id| in |key_request|) and passed the ownership
138 // to the caller. 230 // to the caller.
139 // Returns kErrorUnknown otherwise, in which case the output parameters should 231 // Returns kErrorUnknown otherwise, in which case the output parameters should
140 // not be used by the caller. 232 // not be used by the caller.
141 // 233 //
(...skipping 14 matching lines...) Expand all
156 const uint8_t* key_id, 248 const uint8_t* key_id,
157 int key_id_size) = 0; 249 int key_id_size) = 0;
158 250
159 // Cancels any pending key request made to the CDM for |session_id|. 251 // Cancels any pending key request made to the CDM for |session_id|.
160 // Returns kSuccess if all pending key requests for |session_id| were 252 // Returns kSuccess if all pending key requests for |session_id| were
161 // successfully canceled or there was no key request to be canceled. 253 // successfully canceled or there was no key request to be canceled.
162 // Returns kErrorUnknown otherwise. 254 // Returns kErrorUnknown otherwise.
163 virtual Status CancelKeyRequest(const char* session_id, 255 virtual Status CancelKeyRequest(const char* session_id,
164 int session_id_size) = 0; 256 int session_id_size) = 0;
165 257
258 // Initializes the CDM video decoder with |video_decoder_config|. This
259 // function must be called before DecryptAndDecode is called.
260 // Returns kSuccess if the |video_decoder_config| is supported and the CDM
261 // video decoder is successfully initialized.
262 // Returns kErrorUnknown otherwise.
263 virtual Status InitializeVideoDecoder(
264 const VideoDecoderConfig& video_decoder_config) = 0;
265
266 // Flushes decoded video buffers stored by the CDM video decoder. This
267 // function should be called after seeking to ensure that frames decoded
268 // before seeking are not displayed.
269 virtual Status FlushVideoDecoder() = 0;
ddorwin 2012/09/02 21:39:08 Should we just have one Flush() for all streams? I
xhwang 2012/09/04 14:50:21 From media pipeline, the flush calls come from Vid
270
166 // Decrypts the |encrypted_buffer|. 271 // Decrypts the |encrypted_buffer|.
167 // Returns kSuccess if decryption succeeded, in which case the callee 272 // Returns kSuccess if decryption succeeded, in which case the callee
168 // should have filled the |decrypted_buffer| and passed the ownership of 273 // should have filled the |decrypted_buffer| and passed the ownership of
169 // |data| in |decrypted_buffer| to the caller. 274 // |data| in |decrypted_buffer| to the caller.
170 // Returns kErrorNoKey if the CDM did not have the necessary decryption key 275 // Returns kErrorNoKey if the CDM did not have the necessary decryption key
171 // to decrypt. 276 // to decrypt.
172 // Returns kErrorUnknown if any other error happened. 277 // Returns kErrorUnknown if any other error happened.
173 // In these two cases, |decrypted_buffer| should not be used by the caller. 278 // In these two cases, |decrypted_buffer| should not be used by the caller.
174 // 279 //
175 // TODO(xhwang): It's not safe to pass the ownership of the dynamically 280 // 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 281 // allocated memory over library boundaries. Fix it after related PPAPI change
177 // and sample CDM are landed. 282 // and sample CDM are landed.
178 virtual Status Decrypt(const InputBuffer& encrypted_buffer, 283 virtual Status Decrypt(const InputBuffer& encrypted_buffer,
179 OutputBuffer* decrypted_buffer) = 0; 284 OutputBuffer* decrypted_buffer) = 0;
180 285
286 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
287 // |video_frame|. Upon end-of-stream, the caller should call this function
288 // repeatedly with empty |encrypted_buffer| (where |data| is NULL) until
289 // only empty (|format| being EMPTY) |video_frame| can be produced.
290 // Returns kSuccess if decryption and decoding both succeeded, in which case
291 // the callee should have filled the |video_frame| and passed the ownership of
292 // |data| in |video_frame| to the caller.
293 // Returns kErrorNoKey if the CDM did not have the necessary decryption key
294 // to decrypt.
295 // Returns kErrorUnknown if any other (decryption or decoding) error happened.
296 // In these two cases, |video_frame| should not be used by the caller.
297 //
298 // TODO(xhwang): It's not safe to pass the ownership of the dynamically
299 // allocated memory over library boundaries. Fix it after related PPAPI change
300 // and sample CDM are landed.
301 virtual Status DecryptAndDecode(const InputBuffer& encrypted_buffer,
302 VideoFrame* video_frame) = 0;
303
181 virtual ~ContentDecryptionModule() {} 304 virtual ~ContentDecryptionModule() {}
182 }; 305 };
183 306
184 } // namespace cdm 307 } // namespace cdm
185 308
186 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ 309 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698