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

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: Address 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
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() {}
ddorwin 2012/09/12 23:53:01 Do we need this? It can't be constructed because i
Tom Finegan 2012/09/13 10:33:40 Need it to construct PpbCdmBuffer, but I made it p
98 virtual ~Buffer() {}
99 virtual uint8_t* buffer() const = 0;
100 virtual int32_t size() const = 0;
101
102 private:
103 Buffer(const Buffer&);
104 void operator=(const Buffer&);
105 };
106
89 // Represents an input buffer to be decrypted (and possibly decoded). It does 107 // Represents an input buffer to be decrypted (and possibly decoded). It does
90 // own any pointers in this struct. 108 // own any pointers in this struct.
91 struct InputBuffer { 109 struct InputBuffer {
92 InputBuffer() 110 InputBuffer()
93 : data(NULL), 111 : data(NULL),
94 data_size(0), 112 data_size(0),
95 data_offset(0), 113 data_offset(0),
96 key_id(NULL), 114 key_id(NULL),
97 key_id_size(0), 115 key_id_size(0),
98 iv(NULL), 116 iv(NULL),
99 iv_size(0), 117 iv_size(0),
100 checksum(NULL), 118 checksum(NULL),
101 checksum_size(0), 119 checksum_size(0),
102 subsamples(NULL), 120 subsamples(NULL),
103 num_subsamples(0), 121 num_subsamples(0),
104 timestamp(0) {} 122 timestamp(0) {}
105 123
106 const uint8_t* data; // Pointer to the beginning of the input data. 124 const uint8_t* data; // Pointer to the beginning of the input data.
107 uint32_t data_size; // Size (in bytes) of |data|. 125 int32_t data_size; // Size (in bytes) of |data|.
108 126
109 uint32_t data_offset; // Number of bytes to be discarded before decryption. 127 int32_t data_offset; // Number of bytes to be discarded before decryption.
110 128
111 const uint8_t* key_id; // Key ID to identify the decryption key. 129 const uint8_t* key_id; // Key ID to identify the decryption key.
112 uint32_t key_id_size; // Size (in bytes) of |key_id|. 130 int32_t key_id_size; // Size (in bytes) of |key_id|.
113 131
114 const uint8_t* iv; // Initialization vector. 132 const uint8_t* iv; // Initialization vector.
115 uint32_t iv_size; // Size (in bytes) of |iv|. 133 int32_t iv_size; // Size (in bytes) of |iv|.
116 134
117 const uint8_t* checksum; 135 const uint8_t* checksum;
118 uint32_t checksum_size; // Size (in bytes) of the |checksum|. 136 int32_t checksum_size; // Size (in bytes) of the |checksum|.
119 137
120 const struct SubsampleEntry* subsamples; 138 const struct SubsampleEntry* subsamples;
121 uint32_t num_subsamples; // Number of subsamples in |subsamples|. 139 int32_t num_subsamples; // Number of subsamples in |subsamples|.
122 140
123 int64_t timestamp; // Presentation timestamp in microseconds. 141 int64_t timestamp; // Presentation timestamp in microseconds.
124 }; 142 };
125 143
126 // Represents an output decrypted buffer. It does not own |data|. 144 // Represents an output decrypted buffer. It does not own |data|.
127 struct OutputBuffer { 145 struct OutputBuffer {
128 OutputBuffer() 146 OutputBuffer()
129 : data(NULL), 147 : timestamp(0),
130 data_size(0), 148 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 149
136 int64_t timestamp; // Presentation timestamp in microseconds. 150 int64_t timestamp; // Presentation timestamp in microseconds.
151 cdm::Buffer* buffer;
137 }; 152 };
138 153
139 // Surface formats based on FOURCC labels, see: 154 // Surface formats based on FOURCC labels, see:
140 // http://www.fourcc.org/yuv.php 155 // http://www.fourcc.org/yuv.php
141 enum VideoFormat { 156 enum VideoFormat {
142 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting. 157 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
143 kEmptyVideoFrame, // An empty frame. 158 kEmptyVideoFrame, // An empty frame.
144 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. 159 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
145 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples. 160 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
146 }; 161 };
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 316
302 // Stops the CDM video decoder and sets it to an uninitialized state. The 317 // Stops the CDM video decoder and sets it to an uninitialized state. The
303 // caller can call InitializeVideoDecoder() again after this call to 318 // caller can call InitializeVideoDecoder() again after this call to
304 // re-initialize the video decoder. This can be used to reconfigure the 319 // re-initialize the video decoder. This can be used to reconfigure the
305 // video decoder if the config changes. 320 // video decoder if the config changes.
306 virtual void StopVideoDecoder() = 0; 321 virtual void StopVideoDecoder() = 0;
307 322
308 virtual ~ContentDecryptionModule() {} 323 virtual ~ContentDecryptionModule() {}
309 }; 324 };
310 325
326 // Interface class that hides cross object memory allocation details from CDMs.
327 // Allocated buffers should only be freed by the CDM wrapper with the single
328 // exception noted by the |ReleaseBuffer()| comment.
ddorwin 2012/09/12 23:53:01 Is that really an exception? ReleaseBuffer() frees
Tom Finegan 2012/09/13 10:33:40 Done.
329 class Allocator {
330 public:
331 Allocator() {}
332 virtual ~Allocator() {}
333
334 // Returns a Buffer* containing non-zero members upon success, or NULL on
335 // failure. The caller does not own the Buffer*.
ddorwin 2012/09/12 23:53:01 The caller does own the Buffer* but not the underl
Tom Finegan 2012/09/13 10:33:40 Done.
336 virtual Buffer* Allocate(int32_t size) = 0;
337
338 // Used by the CDM to release a buffer that will not be delivered to the CDM
339 // wrapper. Returns true when |buffer| is valid, and false otherwise.
ddorwin 2012/09/12 23:53:01 No return value now
Tom Finegan 2012/09/13 10:33:40 Done.
340 virtual void ReleaseBuffer(const Buffer& buffer) = 0;
341 };
342
311 } // namespace cdm 343 } // namespace cdm
312 344
313 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_ 345 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CONTENT_DECRYPTION_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698