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

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

Issue 10914028: Add CDM allocator interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix double delete, and possible KeyMessage leak. 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 int int32_t;
12 typedef __int64 int64_t; 12 typedef __int64 int64_t;
13 #else 13 #else
14 #include <stdint.h> 14 #include <stdint.h>
15 #endif 15 #endif
16 16
17 #include "webkit/media/crypto/ppapi/cdm_export.h" 17 #include "webkit/media/crypto/ppapi/cdm_export.h"
18 18
19 namespace cdm { 19 namespace cdm {
20 class Allocator;
21 class Buffer;
20 class ContentDecryptionModule; 22 class ContentDecryptionModule;
23 struct KeyMessage;
24 struct OutputBuffer;
21 } 25 }
22 26
23 extern "C" { 27 extern "C" {
24 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); 28 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(
29 cdm::Allocator* allocator);
25 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); 30 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance);
26 CDM_EXPORT const char* GetCdmVersion(); 31 CDM_EXPORT const char* GetCdmVersion();
27 } 32 }
28 33
29 namespace cdm { 34 namespace cdm {
30 35
31 enum Status { 36 enum Status {
32 kSuccess = 0, 37 kSuccess = 0,
33 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. 38 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample.
34 kNoKey, // The required decryption key is not available. 39 kNoKey, // The required decryption key is not available.
35 kError 40 kError
36 }; 41 };
37 42
38 // Represents a key message sent by the CDM. It does not own any pointers in
39 // this struct.
40 // TODO(xhwang): Use int32_t instead of uint32_t for sizes here and below and
41 // update checks to include <0.
42 struct KeyMessage {
43 KeyMessage()
44 : session_id(NULL),
45 session_id_size(0),
46 message(NULL),
47 message_size(0),
48 default_url(NULL),
49 default_url_size(0) {}
50
51 char* session_id;
52 uint32_t session_id_size;
53 uint8_t* message;
54 uint32_t message_size;
55 char* default_url;
56 uint32_t default_url_size;
57 };
58
59 // An input buffer can be split into several continuous subsamples. 43 // An input buffer can be split into several continuous subsamples.
60 // A SubsampleEntry specifies the number of clear and cipher bytes in each 44 // A SubsampleEntry specifies the number of clear and cipher bytes in each
61 // subsample. For example, the following buffer has three subsamples: 45 // subsample. For example, the following buffer has three subsamples:
62 // 46 //
63 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| 47 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
64 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | 48 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 |
65 // 49 //
66 // For decryption, all of the cipher bytes in a buffer should be concatenated 50 // For decryption, all of the cipher bytes in a buffer should be concatenated
67 // (in the subsample order) into a single logical stream. The clear bytes should 51 // (in the subsample order) into a single logical stream. The clear bytes should
68 // not be considered as part of decryption. 52 // not be considered as part of decryption.
(...skipping 28 matching lines...) Expand all
97 key_id_size(0), 81 key_id_size(0),
98 iv(NULL), 82 iv(NULL),
99 iv_size(0), 83 iv_size(0),
100 checksum(NULL), 84 checksum(NULL),
101 checksum_size(0), 85 checksum_size(0),
102 subsamples(NULL), 86 subsamples(NULL),
103 num_subsamples(0), 87 num_subsamples(0),
104 timestamp(0) {} 88 timestamp(0) {}
105 89
106 const uint8_t* data; // Pointer to the beginning of the input data. 90 const uint8_t* data; // Pointer to the beginning of the input data.
107 uint32_t data_size; // Size (in bytes) of |data|. 91 int32_t data_size; // Size (in bytes) of |data|.
xhwang 2012/09/13 14:35:45 Thanks for the change to from uint32_t to int32_t.
Tom Finegan 2012/09/15 08:03:14 Done.
108 92
109 uint32_t data_offset; // Number of bytes to be discarded before decryption. 93 int32_t data_offset; // Number of bytes to be discarded before decryption.
110 94
111 const uint8_t* key_id; // Key ID to identify the decryption key. 95 const uint8_t* key_id; // Key ID to identify the decryption key.
112 uint32_t key_id_size; // Size (in bytes) of |key_id|. 96 int32_t key_id_size; // Size (in bytes) of |key_id|.
113 97
114 const uint8_t* iv; // Initialization vector. 98 const uint8_t* iv; // Initialization vector.
115 uint32_t iv_size; // Size (in bytes) of |iv|. 99 int32_t iv_size; // Size (in bytes) of |iv|.
116 100
117 const uint8_t* checksum; 101 const uint8_t* checksum;
118 uint32_t checksum_size; // Size (in bytes) of the |checksum|. 102 int32_t checksum_size; // Size (in bytes) of the |checksum|.
119 103
120 const struct SubsampleEntry* subsamples; 104 const struct SubsampleEntry* subsamples;
121 uint32_t num_subsamples; // Number of subsamples in |subsamples|. 105 int32_t num_subsamples; // Number of subsamples in |subsamples|.
122 106
123 int64_t timestamp; // Presentation timestamp in microseconds. 107 int64_t timestamp; // Presentation timestamp in microseconds.
124 }; 108 };
125
126 // Represents an output decrypted buffer. It does not own |data|.
127 struct OutputBuffer {
128 OutputBuffer()
129 : data(NULL),
130 data_size(0),
131 timestamp(0) {}
132
133 const uint8_t* data; // Pointer to the beginning of the output data.
134 uint32_t data_size; // Size (in bytes) of |data|.
135
136 int64_t timestamp; // Presentation timestamp in microseconds.
137 };
138 109
139 // Surface formats based on FOURCC labels, see: 110 // Surface formats based on FOURCC labels, see:
140 // http://www.fourcc.org/yuv.php 111 // http://www.fourcc.org/yuv.php
141 enum VideoFormat { 112 enum VideoFormat {
142 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. 113 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
143 kEmptyVideoFrame, // An empty frame. 114 kEmptyVideoFrame, // An empty frame.
144 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. 115 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
145 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. 116 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
146 }; 117 };
147 118
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 272
302 // Stops the CDM video decoder and sets it to an uninitialized state. The 273 // Stops the CDM video decoder and sets it to an uninitialized state. The
303 // caller can call InitializeVideoDecoder() again after this call to 274 // caller can call InitializeVideoDecoder() again after this call to
304 // re-initialize the video decoder. This can be used to reconfigure the 275 // re-initialize the video decoder. This can be used to reconfigure the
305 // video decoder if the config changes. 276 // video decoder if the config changes.
306 virtual void StopVideoDecoder() = 0; 277 virtual void StopVideoDecoder() = 0;
307 278
308 virtual ~ContentDecryptionModule() {} 279 virtual ~ContentDecryptionModule() {}
309 }; 280 };
310 281
282 // Encapsulates all data required to interact with buffers allocated by
ddorwin 2012/09/13 19:47:00 How about: Represents a buffer created by Alocator
Tom Finegan 2012/09/15 08:03:14 Done.
283 // Allocator implementations. Note that the buffer described by this object is
ddorwin 2012/09/13 19:47:00 Isn't the second sentence an implementation detail
284 // not freed when the object is destroyed.
285 class Buffer {
286 public:
287 virtual ~Buffer() {}
ddorwin 2012/09/13 19:47:00 Make this protected for the reasons described in c
Tom Finegan 2012/09/15 08:03:14 Done.
288 virtual uint8_t* buffer() const = 0;
289 virtual int32_t size() const = 0;
290
291 protected:
292 Buffer() {}
293
294 private:
295 Buffer(const Buffer&);
296 void operator=(const Buffer&);
297 };
298
299 // Interface class that hides cross object memory allocation details from CDMs.
300 // Allocated buffers should only be freed by the CDM wrapper with the single
301 // exception noted by the |ReleaseBuffer()| comment.
302 class Allocator {
303 public:
304 Allocator() {}
305 virtual ~Allocator() {}
306
307 // Returns a Buffer* containing non-zero members upon success, or NULL on
308 // failure. The caller owns the Buffer* until it is passed back to the CDM
309 // wrapper.
310 virtual Buffer* Allocate(int32_t size) = 0;
311
312 // Releases a Buffer that will not be delivered to the CDM wrapper, and sets
ddorwin 2012/09/13 19:47:00 Release a Buffer returned by Allocate(). The |buff
Tom Finegan 2012/09/15 08:03:14 Done.
313 // your Buffer* to NULL.
314 virtual void ReleaseBuffer(const Buffer* buffer) = 0;
xhwang 2012/09/13 14:35:45 I am a little confused here. Can ReleaseBuffer's i
Tom Finegan 2012/09/15 08:03:14 Two things: 1) Deleting memory allocated in anothe
ddorwin 2012/09/17 21:19:23 Also, the PpbBuffer may not actually be deleted si
315 };
316
317 // Represents a key message sent by the CDM. It does not own any pointers in
ddorwin 2012/09/13 19:47:00 It does own the pointers now.
Tom Finegan 2012/09/15 08:03:14 This is now an interface.
318 // this struct.
319 struct KeyMessage {
320 KeyMessage(Allocator* allocator_)
ddorwin 2012/09/13 19:47:00 need a different name than ending with an undersco
Tom Finegan 2012/09/15 08:03:14 Removed.
321 : session_id(NULL),
322 session_id_size(0),
323 allocator(allocator_),
324 message(NULL),
325 default_url(NULL),
326 default_url_size(0) {}
327 ~KeyMessage() {
328 delete[] session_id;
xhwang 2012/09/13 14:35:45 What's the plan for session_id and default_url?
ddorwin 2012/09/13 19:47:00 As noted in cdm_wrapper.cc, they need to be alloca
329 session_id = NULL;
330 allocator->ReleaseBuffer(message);
331 message = NULL;
332 delete default_url;
333 default_url = NULL;
334 }
335
336 char* session_id;
337 int32_t session_id_size;
338
339 Allocator* const allocator;
340 Buffer* message;
341
342 char* default_url;
343 int32_t default_url_size;
344 };
345
346 // Represents an output decrypted buffer. It does not own |data|.
ddorwin 2012/09/13 19:47:00 |data| does not exist. It appears that |buffer| is
Tom Finegan 2012/09/15 08:03:14 Ditto, now an interface.
347 struct OutputBuffer {
ddorwin 2012/09/14 00:20:39 If we keep this struct, we should change the name
Tom Finegan 2012/09/15 08:03:14 Haven't renamed it yet... maybe I'm overly fond of
348 explicit OutputBuffer(Allocator* allocator_)
349 : timestamp(0),
350 allocator(allocator_),
351 buffer(NULL) {}
352 ~OutputBuffer() {
353 allocator->ReleaseBuffer(buffer);
354 }
355
356 int64_t timestamp; // Presentation timestamp in microseconds.
ddorwin 2012/09/14 00:20:39 Do we really need a timestamp for Decrypt()? Since
Tom Finegan 2012/09/15 08:03:14 I'll look into this some time Saturday.
357 Allocator* const allocator;
358 Buffer* buffer;
ddorwin 2012/09/13 19:47:00 I wonder if we should have a ScopedBuffer that con
Tom Finegan 2012/09/15 08:03:14 After changing KeyMessage and OutputBuffer to inte
359 };
360
311 } // namespace cdm 361 } // namespace cdm
312 362
313 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ 363 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698