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

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: Refactored... quite a bit. Sorry for rebase noise on top of everything else! 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 CdmAllocator;
ddorwin 2012/09/07 09:48:48 "Cdm" is redundant in the "cdm" interface.
Tom Finegan 2012/09/08 01:02:47 Done. Also renamed CdmBuffer to Buffer. For the sa
20 class ContentDecryptionModule; 21 class ContentDecryptionModule;
21 } 22 }
22 23
23 extern "C" { 24 extern "C" {
24 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); 25 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(
26 cdm::CdmAllocator* allocator);
25 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); 27 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance);
26 CDM_EXPORT const char* GetCdmVersion(); 28 CDM_EXPORT const char* GetCdmVersion();
27 } 29 }
28 30
29 namespace cdm { 31 namespace cdm {
30 32
31 enum Status { 33 enum Status {
32 kSuccess = 0, 34 kSuccess = 0,
33 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample. 35 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample.
34 kNoKey, // The required decryption key is not available. 36 kNoKey, // The required decryption key is not available.
35 kError 37 kError
36 }; 38 };
37 39
38 // Represents a key message sent by the CDM. It does not own any pointers in 40 // Represents a key message sent by the CDM. It does not own any pointers in
39 // this struct. 41 // 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 { 42 struct KeyMessage {
43 KeyMessage() 43 KeyMessage()
44 : session_id(NULL), 44 : session_id(NULL),
45 session_id_size(0), 45 session_id_size(0),
46 message(NULL), 46 message(NULL),
47 message_size(0), 47 message_size(0),
48 default_url(NULL), 48 default_url(NULL),
49 default_url_size(0) {} 49 default_url_size(0) {}
50 50
51 char* session_id; 51 char* session_id;
52 uint32_t session_id_size; 52 int32_t session_id_size;
53
54 // TODO(tomfinegan): Replace |message| and |message_size| with a CdmBuffer.
53 uint8_t* message; 55 uint8_t* message;
54 uint32_t message_size; 56 int32_t message_size;
57
55 char* default_url; 58 char* default_url;
56 uint32_t default_url_size; 59 int32_t default_url_size;
57 }; 60 };
58 61
59 // An input buffer can be split into several continuous subsamples. 62 // An input buffer can be split into several continuous subsamples.
60 // A SubsampleEntry specifies the number of clear and cipher bytes in each 63 // A SubsampleEntry specifies the number of clear and cipher bytes in each
61 // subsample. For example, the following buffer has three subsamples: 64 // subsample. For example, the following buffer has three subsamples:
62 // 65 //
63 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| 66 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
64 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | 67 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 |
65 // 68 //
66 // For decryption, all of the cipher bytes in a buffer should be concatenated 69 // For decryption, all of the cipher bytes in a buffer should be concatenated
(...skipping 30 matching lines...) Expand all
97 key_id_size(0), 100 key_id_size(0),
98 iv(NULL), 101 iv(NULL),
99 iv_size(0), 102 iv_size(0),
100 checksum(NULL), 103 checksum(NULL),
101 checksum_size(0), 104 checksum_size(0),
102 subsamples(NULL), 105 subsamples(NULL),
103 num_subsamples(0), 106 num_subsamples(0),
104 timestamp(0) {} 107 timestamp(0) {}
105 108
106 const uint8_t* data; // Pointer to the beginning of the input data. 109 const uint8_t* data; // Pointer to the beginning of the input data.
107 uint32_t data_size; // Size (in bytes) of |data|. 110 int32_t data_size; // Size (in bytes) of |data|.
108 111
109 uint32_t data_offset; // Number of bytes to be discarded before decryption. 112 int32_t data_offset; // Number of bytes to be discarded before decryption.
110 113
111 const uint8_t* key_id; // Key ID to identify the decryption key. 114 const uint8_t* key_id; // Key ID to identify the decryption key.
112 uint32_t key_id_size; // Size (in bytes) of |key_id|. 115 int32_t key_id_size; // Size (in bytes) of |key_id|.
113 116
114 const uint8_t* iv; // Initialization vector. 117 const uint8_t* iv; // Initialization vector.
115 uint32_t iv_size; // Size (in bytes) of |iv|. 118 int32_t iv_size; // Size (in bytes) of |iv|.
116 119
117 const uint8_t* checksum; 120 const uint8_t* checksum;
118 uint32_t checksum_size; // Size (in bytes) of the |checksum|. 121 int32_t checksum_size; // Size (in bytes) of the |checksum|.
119 122
120 const struct SubsampleEntry* subsamples; 123 const struct SubsampleEntry* subsamples;
121 uint32_t num_subsamples; // Number of subsamples in |subsamples|. 124 int32_t num_subsamples; // Number of subsamples in |subsamples|.
122 125
123 int64_t timestamp; // Presentation timestamp in microseconds. 126 int64_t timestamp; // Presentation timestamp in microseconds.
124 }; 127 };
125 128
126 // Represents an output decrypted buffer. It does not own |data|. 129 // Represents an output decrypted buffer. It does not own |data|.
127 struct OutputBuffer { 130 struct OutputBuffer {
128 OutputBuffer() 131 OutputBuffer()
129 : data(NULL), 132 : data(NULL),
130 data_size(0), 133 data_size(0),
131 timestamp(0) {} 134 timestamp(0),
135 buffer_id(0) {}
132 136
133 const uint8_t* data; // Pointer to the beginning of the output data. 137 uint8_t* data; // Pointer to the beginning of the output data.
134 uint32_t data_size; // Size (in bytes) of |data|. 138 int32_t data_size; // Size (in bytes) of |data|.
135 139
136 int64_t timestamp; // Presentation timestamp in microseconds. 140 int64_t timestamp; // Presentation timestamp in microseconds.
141 int32_t buffer_id; // Buffer identifier. Issued by CdmAllocator, and used by
ddorwin 2012/09/07 09:48:48 Why is this not just a CdmBuffer?
Tom Finegan 2012/09/08 01:02:47 Removed data, data_size, and buffer_id. Replaced w
142 // the CDM wrapper.
137 }; 143 };
138 144
139 // Surface formats based on FOURCC labels, see: 145 // Surface formats based on FOURCC labels, see:
140 // http://www.fourcc.org/yuv.php 146 // http://www.fourcc.org/yuv.php
141 enum VideoFormat { 147 enum VideoFormat {
142 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. 148 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
143 kEmptyVideoFrame, // An empty frame. 149 kEmptyVideoFrame, // An empty frame.
144 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. 150 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
145 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. 151 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
146 }; 152 };
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 virtual void ResetVideoDecoder() = 0; 306 virtual void ResetVideoDecoder() = 0;
301 307
302 // Stops the CDM video decoder and sets it to an uninitialized state. The 308 // Stops the CDM video decoder and sets it to an uninitialized state. The
303 // caller can call InitializeVideoDecoder() again after this call to 309 // caller can call InitializeVideoDecoder() again after this call to
304 // re-initialize the video decoder. This can be used to reconfigure the 310 // re-initialize the video decoder. This can be used to reconfigure the
305 // video decoder if the config changes. 311 // video decoder if the config changes.
306 virtual void StopVideoDecoder() = 0; 312 virtual void StopVideoDecoder() = 0;
307 313
308 virtual ~ContentDecryptionModule() {} 314 virtual ~ContentDecryptionModule() {}
309 }; 315 };
310 316
ddorwin 2012/09/07 09:48:48 The comment should probably document the behavior.
Tom Finegan 2012/09/08 01:02:47 Added note saying that the buffer is not freed.
317 // Utility class that encapsulates all data required to interact with buffers
ddorwin 2012/09/07 09:48:48 Remove "Utility class that ".
Tom Finegan 2012/09/08 01:02:47 Done.
318 // allocated by |CdmAllocator|s.
ddorwin 2012/09/07 09:48:48 I don't think | is necessary around class names.
Tom Finegan 2012/09/08 01:02:47 Done.
319 class CdmBuffer {
ddorwin 2012/09/07 09:48:48 This should be an abstract class that only exposes
Tom Finegan 2012/09/08 01:02:47 I left the size method in the class since doing so
320 public:
321 // Constructs an empty buffer.
ddorwin 2012/09/07 09:48:48 Constructing a buffer sounds like allocation. But
Tom Finegan 2012/09/08 01:02:47 Removed.
322 CdmBuffer() : buffer_(0), id_(0), size_(0) {}
323
324 // Constructs a buffer object containing all information necessary for a
325 // user writable buffer.
ddorwin 2012/09/07 09:48:48 "user"?
Tom Finegan 2012/09/08 01:02:47 Meant writable by user of the class, but I dropped
326 CdmBuffer(uint8_t* buffer, int32_t id, int32_t size)
327 : buffer_(buffer), id_(id), size_(size) {}
328
329 // Constructs a buffer containing only a valid ID. Provided for the
ddorwin 2012/09/07 09:48:48 This seems odd. Maybe it's not necessary if we sto
Tom Finegan 2012/09/08 01:02:47 You were right: storing the cdm::Buffer in OutputB
330 // sake of convenience. For example, allows caller of
331 // CdmAllocator::ReleaseBuffer to pass CdmBuffer(value) when concerned only
332 // with releasing the buffer wrapped by this object.
333 explicit CdmBuffer(int32_t id) : buffer_(0), id_(id), size_(0) {}
334 ~CdmBuffer() {}
ddorwin 2012/09/07 09:48:48 Be sure this is virtual after making this a base c
Tom Finegan 2012/09/08 01:02:47 Done.
335
336 uint8_t* buffer() const { return buffer_; }
337 int32_t id() const { return id_; }
338 int32_t size() const { return size_; }
339
340 private:
341 uint8_t* buffer_;
ddorwin 2012/09/07 09:48:48 *const
Tom Finegan 2012/09/08 01:02:47 cdm::Buffer no longer has data members.
342 const int32_t id_;
343 const int32_t size_;
344 };
345
346 // Interface class intended to hide cross object memory allocation details from
ddorwin 2012/09/07 09:48:48 s/intended to/that/
Tom Finegan 2012/09/08 01:02:47 Done.
347 // CDMs. The CDM wrapper takes ownership of the allocated data when it is
ddorwin 2012/09/07 09:48:48 This sentence sounds like it should be on those me
Tom Finegan 2012/09/08 01:02:47 Used your comment, but added a little bit...
348 // returned to the wrapper by the CDM (i.e. via OutputBuffer in Decrypt()).
ddorwin 2012/09/07 09:48:48 Allocated buffers should only be freed by the CDM
Tom Finegan 2012/09/08 01:02:47 Done.
349 class CdmAllocator {
350 public:
351 CdmAllocator() {}
352 virtual ~CdmAllocator() {}
353
354 // Returns a CdmBuffer containing non-zero members upon success. Returns an
355 // empty CdmBuffer with all members equal to zero on failure.
356 virtual CdmBuffer Allocate(int32_t size) = 0;
357
358 // Used by the CDM to release a buffer that will not be delivered to the CDM
359 // wrapper. Returns true when |buffer| contains a valid buffer identifier,
360 // false otherwise.
361 virtual bool ReleaseBuffer(const CdmBuffer& buffer) = 0;
362 };
363
311 } // namespace cdm 364 } // namespace cdm
312 365
313 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ 366 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698