Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ppapi / c / ppb_video_decoder.h
1 /* Copyright (c) 2014 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 ppb_video_decoder.idl modified Wed Nov  5 14:04:14 2014. */
7
8 #ifndef PPAPI_C_PPB_VIDEO_DECODER_H_
9 #define PPAPI_C_PPB_VIDEO_DECODER_H_
10
11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_codecs.h"
13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/pp_macros.h"
16 #include "ppapi/c/pp_point.h"
17 #include "ppapi/c/pp_rect.h"
18 #include "ppapi/c/pp_resource.h"
19 #include "ppapi/c/pp_size.h"
20 #include "ppapi/c/pp_stdint.h"
21
22 #define PPB_VIDEODECODER_INTERFACE_0_1 "PPB_VideoDecoder;0.1"
23 #define PPB_VIDEODECODER_INTERFACE_0_2 "PPB_VideoDecoder;0.2"
24 #define PPB_VIDEODECODER_INTERFACE_1_0 "PPB_VideoDecoder;1.0"
25 #define PPB_VIDEODECODER_INTERFACE PPB_VIDEODECODER_INTERFACE_1_0
26
27 /**
28  * @file
29  * This file defines the <code>PPB_VideoDecoder</code> interface.
30  */
31
32
33 /**
34  * @addtogroup Interfaces
35  * @{
36  */
37 /**
38  * Video decoder interface.
39  *
40  * Typical usage:
41  * - Call Create() to create a new video decoder resource.
42  * - Call Initialize() to initialize it with a 3d graphics context and the
43  *   desired codec profile.
44  * - Call Decode() continuously (waiting for each previous call to complete) to
45  *   push bitstream buffers to the decoder.
46  * - Call GetPicture() continuously (waiting for each previous call to complete)
47  *   to pull decoded pictures from the decoder.
48  * - Call Flush() to signal end of stream to the decoder and perform shutdown
49  *   when it completes.
50  * - Call Reset() to quickly stop the decoder (e.g. to implement Seek) and wait
51  *   for the callback before restarting decoding at another point.
52  * - To destroy the decoder, the plugin should release all of its references to
53  *   it. Any pending callbacks will abort before the decoder is destroyed.
54  *
55  * Available video codecs vary by platform.
56  * All: theora, vorbis, vp8.
57  * Chrome and ChromeOS: aac, h264.
58  * ChromeOS: mpeg4.
59  */
60 struct PPB_VideoDecoder_1_0 {
61   /**
62    * Creates a new video decoder resource.
63    *
64    * @param[in] instance A <code>PP_Instance</code> identifying the instance
65    * with the video decoder.
66    *
67    * @return A <code>PP_Resource</code> corresponding to a video decoder if
68    * successful or 0 otherwise.
69    */
70   PP_Resource (*Create)(PP_Instance instance);
71   /**
72    * Determines if the given resource is a video decoder.
73    *
74    * @param[in] resource A <code>PP_Resource</code> identifying a resource.
75    *
76    * @return <code>PP_TRUE</code> if the resource is a
77    * <code>PPB_VideoDecoder</code>, <code>PP_FALSE</code> if the resource is
78    * invalid or some other type.
79    */
80   PP_Bool (*IsVideoDecoder)(PP_Resource resource);
81   /**
82    * Initializes a video decoder resource. This should be called after Create()
83    * and before any other functions.
84    *
85    * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
86    * decoder.
87    * @param[in] graphics3d_context A <code>PPB_Graphics3D</code> resource to use
88    * during decoding.
89    * @param[in] profile A <code>PP_VideoProfile</code> specifying the video
90    * codec profile.
91    * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
92    * whether to use a hardware accelerated or a software implementation.
93    * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
94    * completion.
95    *
96    * @return An int32_t containing an error code from <code>pp_errors.h</code>.
97    * Returns PP_ERROR_NOTSUPPORTED if video decoding is not available, or the
98    * requested profile is not supported. In this case, the client may call
99    * Initialize() again with different parameters to find a good configuration.
100    */
101   int32_t (*Initialize)(PP_Resource video_decoder,
102                         PP_Resource graphics3d_context,
103                         PP_VideoProfile profile,
104                         PP_HardwareAcceleration acceleration,
105                         struct PP_CompletionCallback callback);
106   /**
107    * Decodes a bitstream buffer. Copies |size| bytes of data from the plugin's
108    * |buffer|. The plugin should wait until the decoder signals completion by
109    * returning PP_OK or by running |callback| before calling Decode() again.
110    *
111    * In general, each bitstream buffer should contain a demuxed bitstream frame
112    * for the selected video codec. For example, H264 decoders expect to receive
113    * one AnnexB NAL unit, including the 4 byte start code prefix, while VP8
114    * decoders expect to receive a bitstream frame without the IVF frame header.
115    *
116    * If the call to Decode() eventually results in a picture, the |decode_id|
117    * parameter is copied into the returned picture. The plugin can use this to
118    * associate decoded pictures with Decode() calls (e.g. to assign timestamps
119    * or frame numbers to pictures.) This value is opaque to the API so the
120    * plugin is free to pass any value.
121    *
122    * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
123    * decoder.
124    * @param[in] decode_id An optional value, chosen by the plugin, that can be
125    * used to associate calls to Decode() with decoded pictures returned by
126    * GetPicture().
127    * @param[in] size Buffer size in bytes.
128    * @param[in] buffer Starting address of buffer.
129    * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
130    * completion.
131    *
132    * @return An int32_t containing an error code from <code>pp_errors.h</code>.
133    * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Flush()
134    * or Reset() call is pending.
135    * Returns PP_ERROR_INPROGRESS if there is another Decode() call pending.
136    * Returns PP_ERROR_NOMEMORY if a bitstream buffer can't be created.
137    * Returns PP_ERROR_ABORTED when Reset() is called while Decode() is pending.
138    */
139   int32_t (*Decode)(PP_Resource video_decoder,
140                     uint32_t decode_id,
141                     uint32_t size,
142                     const void* buffer,
143                     struct PP_CompletionCallback callback);
144   /**
145    * Gets the next picture from the decoder. The picture is valid after the
146    * decoder signals completion by returning PP_OK or running |callback|. The
147    * plugin can call GetPicture() again after the decoder signals completion.
148    * When the plugin is finished using the picture, it should return it to the
149    * system by calling RecyclePicture().
150    *
151    * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
152    * decoder.
153    * @param[out] picture A <code>PP_VideoPicture</code> to hold the decoded
154    * picture.
155    * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
156    * completion.
157    *
158    * @return An int32_t containing an error code from <code>pp_errors.h</code>.
159    * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Reset()
160    * call is pending.
161    * Returns PP_ERROR_INPROGRESS if there is another GetPicture() call pending.
162    * Returns PP_ERROR_ABORTED when Reset() is called, or if a call to Flush()
163    * completes while GetPicture() is pending.
164    */
165   int32_t (*GetPicture)(PP_Resource video_decoder,
166                         struct PP_VideoPicture* picture,
167                         struct PP_CompletionCallback callback);
168   /**
169    * Recycles a picture that the plugin has received from the decoder.
170    * The plugin should call this as soon as it has finished using the texture so
171    * the decoder can decode more pictures.
172    *
173    * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
174    * decoder.
175    * @param[in] picture A <code>PP_VideoPicture</code> to return to
176    * the decoder.
177    */
178   void (*RecyclePicture)(PP_Resource video_decoder,
179                          const struct PP_VideoPicture* picture);
180   /**
181    * Flushes the decoder. The plugin should call Flush() when it reaches the
182    * end of its video stream in order to stop cleanly. The decoder will run any
183    * pending Decode() call to completion. The plugin should make no further
184    * calls to the decoder other than GetPicture() and RecyclePicture() until
185    * the decoder signals completion by running |callback|. Just before
186    * completion, any pending GetPicture() call will complete by running its
187    * callback with result PP_ERROR_ABORTED to signal that no more pictures are
188    * available. Any pictures held by the plugin remain valid during and after
189    * the flush and should be recycled back to the decoder.
190    *
191    * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
192    * decoder.
193    * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
194    * completion.
195    *
196    * @return An int32_t containing an error code from <code>pp_errors.h</code>.
197    * Returns PP_ERROR_FAILED if the decoder isn't initialized.
198    */
199   int32_t (*Flush)(PP_Resource video_decoder,
200                    struct PP_CompletionCallback callback);
201   /**
202    * Resets the decoder as quickly as possible. The plugin can call Reset() to
203    * skip to another position in the video stream. After Reset() returns, any
204    * pending calls to Decode() and GetPicture()) abort, causing their callbacks
205    * to run with PP_ERROR_ABORTED. The plugin should not make further calls to
206    * the decoder other than RecyclePicture() until the decoder signals
207    * completion by running |callback|. Any pictures held by the plugin remain
208    * valid during and after the reset and should be recycled back to the
209    * decoder.
210    *
211    * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
212    * decoder.
213    * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
214    * completion.
215    *
216    * @return An int32_t containing an error code from <code>pp_errors.h</code>.
217    * Returns PP_ERROR_FAILED if the decoder isn't initialized.
218    */
219   int32_t (*Reset)(PP_Resource video_decoder,
220                    struct PP_CompletionCallback callback);
221 };
222
223 typedef struct PPB_VideoDecoder_1_0 PPB_VideoDecoder;
224
225 struct PPB_VideoDecoder_0_1 {
226   PP_Resource (*Create)(PP_Instance instance);
227   PP_Bool (*IsVideoDecoder)(PP_Resource resource);
228   int32_t (*Initialize)(PP_Resource video_decoder,
229                         PP_Resource graphics3d_context,
230                         PP_VideoProfile profile,
231                         PP_Bool allow_software_fallback,
232                         struct PP_CompletionCallback callback);
233   int32_t (*Decode)(PP_Resource video_decoder,
234                     uint32_t decode_id,
235                     uint32_t size,
236                     const void* buffer,
237                     struct PP_CompletionCallback callback);
238   int32_t (*GetPicture)(PP_Resource video_decoder,
239                         struct PP_VideoPicture_0_1* picture,
240                         struct PP_CompletionCallback callback);
241   void (*RecyclePicture)(PP_Resource video_decoder,
242                          const struct PP_VideoPicture* picture);
243   int32_t (*Flush)(PP_Resource video_decoder,
244                    struct PP_CompletionCallback callback);
245   int32_t (*Reset)(PP_Resource video_decoder,
246                    struct PP_CompletionCallback callback);
247 };
248
249 struct PPB_VideoDecoder_0_2 {
250   PP_Resource (*Create)(PP_Instance instance);
251   PP_Bool (*IsVideoDecoder)(PP_Resource resource);
252   int32_t (*Initialize)(PP_Resource video_decoder,
253                         PP_Resource graphics3d_context,
254                         PP_VideoProfile profile,
255                         PP_HardwareAcceleration acceleration,
256                         struct PP_CompletionCallback callback);
257   int32_t (*Decode)(PP_Resource video_decoder,
258                     uint32_t decode_id,
259                     uint32_t size,
260                     const void* buffer,
261                     struct PP_CompletionCallback callback);
262   int32_t (*GetPicture)(PP_Resource video_decoder,
263                         struct PP_VideoPicture_0_1* picture,
264                         struct PP_CompletionCallback callback);
265   void (*RecyclePicture)(PP_Resource video_decoder,
266                          const struct PP_VideoPicture* picture);
267   int32_t (*Flush)(PP_Resource video_decoder,
268                    struct PP_CompletionCallback callback);
269   int32_t (*Reset)(PP_Resource video_decoder,
270                    struct PP_CompletionCallback callback);
271 };
272 /**
273  * @}
274  */
275
276 #endif  /* PPAPI_C_PPB_VIDEO_DECODER_H_ */
277