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

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 gyp file (remove cdm_allocator.h). 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;
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::Allocator* 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 12 matching lines...) Expand all
79 // 82 //
80 // TODO(xhwang): Add checks to make sure these structs have fixed layout. 83 // TODO(xhwang): Add checks to make sure these structs have fixed layout.
81 struct SubsampleEntry { 84 struct SubsampleEntry {
82 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) 85 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes)
83 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} 86 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
84 87
85 uint32_t clear_bytes; 88 uint32_t clear_bytes;
86 uint32_t cipher_bytes; 89 uint32_t cipher_bytes;
87 }; 90 };
88 91
92 // Encapsulates all data required to interact with buffers allocated by
93 // Allocator implementations. Note that the buffer described by this object is
94 // not freed when the object is destroyed.
95 class Buffer {
96 public:
97 Buffer() {}
98 virtual ~Buffer() {}
99 virtual uint8_t* buffer() const = 0;
100 virtual int32_t size() const = 0;
dmichael (off chromium) 2012/09/10 16:10:35 Consider disallowing copy and assign here, too.
Tom Finegan 2012/09/11 02:58:06 Done, but did it manually (don't want to add the b
101 };
102
89 // Represents an input buffer to be decrypted (and possibly decoded). It does 103 // Represents an input buffer to be decrypted (and possibly decoded). It does
90 // own any pointers in this struct. 104 // own any pointers in this struct.
91 struct InputBuffer { 105 struct InputBuffer {
92 InputBuffer() 106 InputBuffer()
93 : data(NULL), 107 : data(NULL),
94 data_size(0), 108 data_size(0),
95 data_offset(0), 109 data_offset(0),
96 key_id(NULL), 110 key_id(NULL),
97 key_id_size(0), 111 key_id_size(0),
98 iv(NULL), 112 iv(NULL),
99 iv_size(0), 113 iv_size(0),
100 checksum(NULL), 114 checksum(NULL),
101 checksum_size(0), 115 checksum_size(0),
102 subsamples(NULL), 116 subsamples(NULL),
103 num_subsamples(0), 117 num_subsamples(0),
104 timestamp(0) {} 118 timestamp(0) {}
105 119
106 const uint8_t* data; // Pointer to the beginning of the input data. 120 const uint8_t* data; // Pointer to the beginning of the input data.
107 uint32_t data_size; // Size (in bytes) of |data|. 121 int32_t data_size; // Size (in bytes) of |data|.
108 122
109 uint32_t data_offset; // Number of bytes to be discarded before decryption. 123 int32_t data_offset; // Number of bytes to be discarded before decryption.
110 124
111 const uint8_t* key_id; // Key ID to identify the decryption key. 125 const uint8_t* key_id; // Key ID to identify the decryption key.
112 uint32_t key_id_size; // Size (in bytes) of |key_id|. 126 int32_t key_id_size; // Size (in bytes) of |key_id|.
113 127
114 const uint8_t* iv; // Initialization vector. 128 const uint8_t* iv; // Initialization vector.
115 uint32_t iv_size; // Size (in bytes) of |iv|. 129 int32_t iv_size; // Size (in bytes) of |iv|.
116 130
117 const uint8_t* checksum; 131 const uint8_t* checksum;
118 uint32_t checksum_size; // Size (in bytes) of the |checksum|. 132 int32_t checksum_size; // Size (in bytes) of the |checksum|.
119 133
120 const struct SubsampleEntry* subsamples; 134 const struct SubsampleEntry* subsamples;
121 uint32_t num_subsamples; // Number of subsamples in |subsamples|. 135 int32_t num_subsamples; // Number of subsamples in |subsamples|.
122 136
123 int64_t timestamp; // Presentation timestamp in microseconds. 137 int64_t timestamp; // Presentation timestamp in microseconds.
124 }; 138 };
125 139
126 // Represents an output decrypted buffer. It does not own |data|. 140 // Represents an output decrypted buffer. It does not own |data|.
127 struct OutputBuffer { 141 struct OutputBuffer {
128 OutputBuffer() 142 OutputBuffer()
129 : data(NULL), 143 : timestamp(0),
130 data_size(0), 144 buffer(NULL) {}
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 145
136 int64_t timestamp; // Presentation timestamp in microseconds. 146 int64_t timestamp; // Presentation timestamp in microseconds.
147 cdm::Buffer* buffer;
137 }; 148 };
138 149
139 // Surface formats based on FOURCC labels, see: 150 // Surface formats based on FOURCC labels, see:
140 // http://www.fourcc.org/yuv.php 151 // http://www.fourcc.org/yuv.php
141 enum VideoFormat { 152 enum VideoFormat {
142 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. 153 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
143 kEmptyVideoFrame, // An empty frame. 154 kEmptyVideoFrame, // An empty frame.
144 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. 155 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
145 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. 156 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
146 }; 157 };
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 312
302 // Stops the CDM video decoder and sets it to an uninitialized state. The 313 // Stops the CDM video decoder and sets it to an uninitialized state. The
303 // caller can call InitializeVideoDecoder() again after this call to 314 // caller can call InitializeVideoDecoder() again after this call to
304 // re-initialize the video decoder. This can be used to reconfigure the 315 // re-initialize the video decoder. This can be used to reconfigure the
305 // video decoder if the config changes. 316 // video decoder if the config changes.
306 virtual void StopVideoDecoder() = 0; 317 virtual void StopVideoDecoder() = 0;
307 318
308 virtual ~ContentDecryptionModule() {} 319 virtual ~ContentDecryptionModule() {}
309 }; 320 };
310 321
322 // Interface class that hides cross object memory allocation details from CDMs.
323 // Allocated buffers should only be freed by the CDM wrapper with the single
324 // exception noted by the |ReleaseBuffer()| comment.
325 class Allocator {
326 public:
327 Allocator() {}
328 virtual ~Allocator() {}
329
330 // Returns a Buffer* containing non-zero members upon success, or NULL on
331 // failure. The caller does not own the Buffer*.
332 virtual Buffer* Allocate(int32_t size) = 0;
333
334 // Used by the CDM to release a buffer that will not be delivered to the CDM
335 // wrapper. Returns true when |buffer| is valid, and false otherwise.
336 virtual void ReleaseBuffer(const Buffer& buffer) = 0;
337 };
338
311 } // namespace cdm 339 } // namespace cdm
312 340
313 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ 341 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698