- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / c / private / pp_content_decryptor.h
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
3  * found in the LICENSE file.
4  */
5
6 /* From private/pp_content_decryptor.idl modified Mon Oct 21 18:38:44 2013. */
7
8 #ifndef PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_
9 #define PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_
10
11 #include "ppapi/c/pp_macros.h"
12 #include "ppapi/c/pp_stdint.h"
13
14 /**
15  * @file
16  * The <code>PP_DecryptTrackingInfo</code> struct contains necessary information
17  * that can be used to associate the decrypted block with a decrypt request
18  * and/or an input block.
19  */
20
21
22 /**
23  * @addtogroup Structs
24  * @{
25  */
26 struct PP_DecryptTrackingInfo {
27   /**
28    * Client-specified identifier for the associated decrypt request. By using
29    * this value, the client can associate the decrypted block with a decryption
30    * request.
31    */
32   uint32_t request_id;
33   /**
34    * A unique buffer ID to identify a PPB_Buffer_Dev. Unlike a PP_Resource,
35    * this ID is identical at both the renderer side and the plugin side.
36    * In <code>PPB_ContentDecryptor_Private</code> calls, this is the ID of the
37    * buffer associated with the decrypted block/frame/samples.
38    * In <code>PPP_ContentDecryptor_Private</code> calls, this is the ID of a
39    * buffer that is no longer need at the renderer side, which can be released
40    * or recycled by the plugin. This ID can be 0 if there is no buffer to be
41    * released or recycled.
42    */
43   uint32_t buffer_id;
44   /**
45    * Timestamp in microseconds of the associated block. By using this value,
46    * the client can associate the decrypted (and decoded) data with an input
47    * block. This is needed because buffers may be delivered out of order and
48    * not in response to the <code>request_id</code> they were provided with.
49    */
50   int64_t timestamp;
51 };
52 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_DecryptTrackingInfo, 16);
53
54 /**
55  * The <code>PP_DecryptSubsampleDescription</code> struct contains information
56  * to support subsample decryption.
57  *
58  * An input block can be split into several continuous subsamples.
59  * A <code>PP_DecryptSubsampleEntry</code> specifies the number of clear and
60  * cipher bytes in each subsample. For example, the following block has three
61  * subsamples:
62  *
63  * |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
64  * |   clear1   |  cipher1  |  clear2  |   cipher2   | clear3 |    cipher3    |
65  *
66  * For decryption, all of the cipher bytes in a block should be treated as a
67  * contiguous (in the subsample order) logical stream. The clear bytes should
68  * not be considered as part of decryption.
69  *
70  * Logical stream to decrypt:   |  cipher1  |   cipher2   |    cipher3    |
71  * Decrypted stream:            | decrypted1|  decrypted2 |   decrypted3  |
72  *
73  * After decryption, the decrypted bytes should be copied over the position
74  * of the corresponding cipher bytes in the original block to form the output
75  * block. Following the above example, the decrypted block should be:
76  *
77  * |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
78  * |   clear1   | decrypted1|  clear2  |  decrypted2 | clear3 |   decrypted3  |
79  */
80 struct PP_DecryptSubsampleDescription {
81   /**
82    * Size in bytes of clear data in a subsample entry.
83    */
84   uint32_t clear_bytes;
85   /**
86    * Size in bytes of encrypted data in a subsample entry.
87    */
88   uint32_t cipher_bytes;
89 };
90 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_DecryptSubsampleDescription, 8);
91
92 /**
93  * The <code>PP_EncryptedBlockInfo</code> struct contains all the information
94  * needed to decrypt an encrypted block.
95  */
96 struct PP_EncryptedBlockInfo {
97   /**
98    * Information needed by the client to track the block to be decrypted.
99    */
100   struct PP_DecryptTrackingInfo tracking_info;
101   /**
102    * Size in bytes of data to be decrypted (data_offset included).
103    */
104   uint32_t data_size;
105   /**
106    * Size in bytes of data to be discarded before applying the decryption.
107    */
108   uint32_t data_offset;
109   /**
110    * Key ID of the block to be decrypted.
111    *
112    * TODO(xhwang): For WebM the key ID can be as large as 2048 bytes in theory.
113    * But it's not used in current implementations. If we really need to support
114    * it, we should move key ID out as a separate parameter, e.g.
115    * as a <code>PP_Var</code>, or make the whole
116    * <code>PP_EncryptedBlockInfo</code> as a <code>PP_Resource</code>.
117    */
118   uint8_t key_id[64];
119   uint32_t key_id_size;
120   /**
121    * Initialization vector of the block to be decrypted.
122    */
123   uint8_t iv[16];
124   uint32_t iv_size;
125   /**
126    * Subsample information of the block to be decrypted.
127    */
128   struct PP_DecryptSubsampleDescription subsamples[16];
129   uint32_t num_subsamples;
130   /**
131    * 4-byte padding to make the size of <code>PP_EncryptedBlockInfo</code>
132    * a multiple of 8 bytes. The value of this field should not be used.
133    */
134   uint32_t padding;
135 };
136 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_EncryptedBlockInfo, 248);
137 /**
138  * @}
139  */
140
141 /**
142  * @addtogroup Enums
143  * @{
144  */
145 /**
146  * <code>PP_DecryptedFrameFormat</code> contains video frame formats.
147  */
148 typedef enum {
149   PP_DECRYPTEDFRAMEFORMAT_UNKNOWN = 0,
150   PP_DECRYPTEDFRAMEFORMAT_YV12 = 1,
151   PP_DECRYPTEDFRAMEFORMAT_I420 = 2
152 } PP_DecryptedFrameFormat;
153 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_DecryptedFrameFormat, 4);
154
155 /**
156  * <code>PP_DecryptedSampleFormat</code> contains audio sample formats.
157  */
158 typedef enum {
159   PP_DECRYPTEDSAMPLEFORMAT_UNKNOWN = 0,
160   PP_DECRYPTEDSAMPLEFORMAT_U8 = 1,
161   PP_DECRYPTEDSAMPLEFORMAT_S16 = 2,
162   PP_DECRYPTEDSAMPLEFORMAT_S32 = 3,
163   PP_DECRYPTEDSAMPLEFORMAT_F32 = 4,
164   PP_DECRYPTEDSAMPLEFORMAT_PLANAR_S16 = 5,
165   PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32 = 6
166 } PP_DecryptedSampleFormat;
167 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_DecryptedSampleFormat, 4);
168
169 /**
170  * The <code>PP_DecryptResult</code> enum contains decryption and decoding
171  * result constants.
172  */
173 typedef enum {
174   /** The decryption (and/or decoding) operation finished successfully. */
175   PP_DECRYPTRESULT_SUCCESS = 0,
176   /** The decryptor did not have the necessary decryption key. */
177   PP_DECRYPTRESULT_DECRYPT_NOKEY = 1,
178   /** The input was accepted by the decoder but no frame(s) can be produced. */
179   PP_DECRYPTRESULT_NEEDMOREDATA = 2,
180   /** An unexpected error happened during decryption. */
181   PP_DECRYPTRESULT_DECRYPT_ERROR = 3,
182   /** An unexpected error happened during decoding. */
183   PP_DECRYPTRESULT_DECODE_ERROR = 4
184 } PP_DecryptResult;
185 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_DecryptResult, 4);
186 /**
187  * @}
188  */
189
190 /**
191  * @addtogroup Structs
192  * @{
193  */
194 /**
195  * <code>PP_DecryptedBlockInfo</code> struct contains the decryption result and
196  * tracking info associated with the decrypted block.
197  */
198 struct PP_DecryptedBlockInfo {
199   /**
200    * Result of the decryption (and/or decoding) operation.
201    */
202   PP_DecryptResult result;
203   /**
204    * Size in bytes of decrypted data, which may be less than the size of the
205    * corresponding buffer.
206    */
207   uint32_t data_size;
208   /**
209    * Information needed by the client to track the block to be decrypted.
210    */
211   struct PP_DecryptTrackingInfo tracking_info;
212 };
213 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_DecryptedBlockInfo, 24);
214 /**
215  * @}
216  */
217
218 /**
219  * @addtogroup Enums
220  * @{
221  */
222 /**
223  * <code>PP_DecryptedFramePlanes</code> provides YUV plane index values for
224  * accessing plane offsets stored in <code>PP_DecryptedFrameInfo</code>.
225  */
226 typedef enum {
227   PP_DECRYPTEDFRAMEPLANES_Y = 0,
228   PP_DECRYPTEDFRAMEPLANES_U = 1,
229   PP_DECRYPTEDFRAMEPLANES_V = 2
230 } PP_DecryptedFramePlanes;
231 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_DecryptedFramePlanes, 4);
232 /**
233  * @}
234  */
235
236 /**
237  * @addtogroup Structs
238  * @{
239  */
240 /**
241  * <code>PP_DecryptedFrameInfo</code> contains the result of the
242  * decrypt and decode operation on the associated frame, information required
243  * to access the frame data in buffer, and tracking info.
244  */
245 struct PP_DecryptedFrameInfo {
246   /**
247    * Result of the decrypt and decode operation.
248    */
249   PP_DecryptResult result;
250   /**
251    * Format of the decrypted frame.
252    */
253   PP_DecryptedFrameFormat format;
254   /**
255    * Offsets into the buffer resource for accessing video planes.
256    */
257   int32_t plane_offsets[3];
258   /**
259    * Stride of each plane.
260    */
261   int32_t strides[3];
262   /**
263    * Width of the video frame, in pixels.
264    */
265   int32_t width;
266   /**
267    * Height of the video frame, in pixels.
268    */
269   int32_t height;
270   /**
271    * Information needed by the client to track the decrypted frame.
272    */
273   struct PP_DecryptTrackingInfo tracking_info;
274 };
275 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_DecryptedFrameInfo, 56);
276
277 /**
278  * <code>PP_DecryptedSampleInfo</code> contains the result of the
279  * decrypt and decode operation on the associated samples, information required
280  * to access the sample data in buffer, and tracking info.
281  */
282 struct PP_DecryptedSampleInfo {
283   /**
284    * Result of the decrypt and decode operation.
285    */
286   PP_DecryptResult result;
287   /**
288    * Format of the decrypted samples.
289    */
290   PP_DecryptedSampleFormat format;
291   /**
292    * Size in bytes of decrypted samples.
293    */
294   uint32_t data_size;
295   /**
296    * 4-byte padding to make the size of <code>PP_DecryptedSampleInfo</code>
297    * a multiple of 8 bytes. The value of this field should not be used.
298    */
299   uint32_t padding;
300   /**
301    * Information needed by the client to track the decrypted samples.
302    */
303   struct PP_DecryptTrackingInfo tracking_info;
304 };
305 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_DecryptedSampleInfo, 32);
306 /**
307  * @}
308  */
309
310 /**
311  * @addtogroup Enums
312  * @{
313  */
314 /**
315  * <code>PP_AudioCodec</code> contains audio codec type constants.
316  */
317 typedef enum {
318   PP_AUDIOCODEC_UNKNOWN = 0,
319   PP_AUDIOCODEC_VORBIS = 1,
320   PP_AUDIOCODEC_AAC = 2
321 } PP_AudioCodec;
322 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_AudioCodec, 4);
323 /**
324  * @}
325  */
326
327 /**
328  * @addtogroup Structs
329  * @{
330  */
331 /**
332  * <code>PP_AudioDecoderConfig</code> contains audio decoder configuration
333  * information required to initialize audio decoders, and a request ID
334  * that allows clients to associate a decoder initialization request with a
335  * status response. Note: When <code>codec</code> requires extra data for
336  * initialization, the data is sent as a <code>PP_Resource</code> carried
337  * alongside <code>PP_AudioDecoderConfig</code>.
338  */
339 struct PP_AudioDecoderConfig {
340   /**
341    * The audio codec to initialize.
342    */
343   PP_AudioCodec codec;
344   /**
345    * Number of audio channels.
346    */
347   int32_t channel_count;
348   /**
349    * Size of each audio channel.
350    */
351   int32_t bits_per_channel;
352   /**
353    * Audio sampling rate.
354    */
355   int32_t samples_per_second;
356   /**
357    * Client-specified identifier for the associated audio decoder initialization
358    * request. By using this value, the client can associate a decoder
359    * initialization status response with an initialization request.
360    */
361   uint32_t request_id;
362 };
363 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_AudioDecoderConfig, 20);
364 /**
365  * @}
366  */
367
368 /**
369  * @addtogroup Enums
370  * @{
371  */
372 /**
373  * <code>PP_VideoCodec</code> contains video codec type constants.
374  */
375 typedef enum {
376   PP_VIDEOCODEC_UNKNOWN = 0,
377   PP_VIDEOCODEC_VP8 = 1,
378   PP_VIDEOCODEC_H264 = 2
379 } PP_VideoCodec;
380 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoCodec, 4);
381
382 /**
383  * <code>PP_VideoCodecProfile</code> contains video codec profile type
384  * constants required for video decoder configuration.
385  *.
386  */
387 typedef enum {
388   PP_VIDEOCODECPROFILE_UNKNOWN = 0,
389   PP_VIDEOCODECPROFILE_VP8_MAIN = 1,
390   PP_VIDEOCODECPROFILE_H264_BASELINE = 2,
391   PP_VIDEOCODECPROFILE_H264_MAIN = 3,
392   PP_VIDEOCODECPROFILE_H264_EXTENDED = 4,
393   PP_VIDEOCODECPROFILE_H264_HIGH = 5,
394   PP_VIDEOCODECPROFILE_H264_HIGH_10 = 6,
395   PP_VIDEOCODECPROFILE_H264_HIGH_422 = 7,
396   PP_VIDEOCODECPROFILE_H264_HIGH_444_PREDICTIVE = 8
397 } PP_VideoCodecProfile;
398 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoCodecProfile, 4);
399 /**
400  * @}
401  */
402
403 /**
404  * @addtogroup Structs
405  * @{
406  */
407 /**
408  * <code>PP_VideoDecoderConfig</code> contains video decoder configuration
409  * information required to initialize video decoders, and a request ID
410  * that allows clients to associate a decoder initialization request with a
411  * status response. Note: When <code>codec</code> requires extra data for
412  * initialization, the data is sent as a <code>PP_Resource</code> carried
413  * alongside <code>PP_VideoDecoderConfig</code>.
414  */
415 struct PP_VideoDecoderConfig {
416   /**
417    * The video codec to initialize.
418    */
419   PP_VideoCodec codec;
420   /**
421    * Profile to use when initializing the video codec.
422    */
423   PP_VideoCodecProfile profile;
424   /**
425    * Output video format.
426    */
427   PP_DecryptedFrameFormat format;
428   /**
429    * Width of decoded video frames, in pixels.
430    */
431   int32_t width;
432   /**
433    * Height of decoded video frames, in pixels.
434    */
435   int32_t height;
436   /**
437    * Client-specified identifier for the associated video decoder initialization
438    * request. By using this value, the client can associate a decoder
439    * initialization status response with an initialization request.
440    */
441   uint32_t request_id;
442 };
443 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoDecoderConfig, 24);
444 /**
445  * @}
446  */
447
448 /**
449  * @addtogroup Enums
450  * @{
451  */
452 /**
453  * <code>PP_DecryptorStreamType</code> contains stream type constants.
454  */
455 typedef enum {
456   PP_DECRYPTORSTREAMTYPE_AUDIO = 0,
457   PP_DECRYPTORSTREAMTYPE_VIDEO = 1
458 } PP_DecryptorStreamType;
459 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_DecryptorStreamType, 4);
460 /**
461  * @}
462  */
463
464 #endif  /* PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_ */
465