Revert of Move NumberOfPlanesForGpuMemoryBufferFormat to gfx (patchset #4 id:120001...
[chromium-blink-merge.git] / ppapi / c / ppb_video_decoder.h
blob91b200813d565e7bf61400ff2d16b305bdc7339d
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 */
6 /* From ppb_video_decoder.idl modified Wed Nov 5 14:04:14 2014. */
8 #ifndef PPAPI_C_PPB_VIDEO_DECODER_H_
9 #define PPAPI_C_PPB_VIDEO_DECODER_H_
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"
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
27 /**
28 * @file
29 * This file defines the <code>PPB_VideoDecoder</code> interface.
33 /**
34 * @addtogroup Interfaces
35 * @{
37 /**
38 * Video decoder interface.
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.
55 * Available video codecs vary by platform.
56 * All: theora, vorbis, vp8.
57 * Chrome and ChromeOS: aac, h264.
58 * ChromeOS: mpeg4.
60 struct PPB_VideoDecoder_1_0 {
61 /**
62 * Creates a new video decoder resource.
64 * @param[in] instance A <code>PP_Instance</code> identifying the instance
65 * with the video decoder.
67 * @return A <code>PP_Resource</code> corresponding to a video decoder if
68 * successful or 0 otherwise.
70 PP_Resource (*Create)(PP_Instance instance);
71 /**
72 * Determines if the given resource is a video decoder.
74 * @param[in] resource A <code>PP_Resource</code> identifying a resource.
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.
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.
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.
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.
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);
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.
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.
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.
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.
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.
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);
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().
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.
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.
165 int32_t (*GetPicture)(PP_Resource video_decoder,
166 struct PP_VideoPicture* picture,
167 struct PP_CompletionCallback callback);
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.
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.
178 void (*RecyclePicture)(PP_Resource video_decoder,
179 const struct PP_VideoPicture* picture);
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.
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.
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.
199 int32_t (*Flush)(PP_Resource video_decoder,
200 struct PP_CompletionCallback callback);
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.
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.
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.
219 int32_t (*Reset)(PP_Resource video_decoder,
220 struct PP_CompletionCallback callback);
223 typedef struct PPB_VideoDecoder_1_0 PPB_VideoDecoder;
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);
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);
273 * @}
276 #endif /* PPAPI_C_PPB_VIDEO_DECODER_H_ */