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.
6 /* From ppb_video_decoder.idl modified Fri Jul 11 18:06:37 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_resource.h"
17 #include "ppapi/c/pp_size.h"
18 #include "ppapi/c/pp_stdint.h"
20 #define PPB_VIDEODECODER_INTERFACE_0_1 "PPB_VideoDecoder;0.1" /* dev */
23 * This file defines the <code>PPB_VideoDecoder</code> interface.
28 * @addtogroup Interfaces
32 * Video decoder interface.
35 * - Call Create() to create a new video decoder resource.
36 * - Call Initialize() to initialize it with a 3d graphics context and the
37 * desired codec profile.
38 * - Call Decode() continuously (waiting for each previous call to complete) to
39 * push bitstream buffers to the decoder.
40 * - Call GetPicture() continuously (waiting for each previous call to complete)
41 * to pull decoded pictures from the decoder.
42 * - Call Flush() to signal end of stream to the decoder and perform shutdown
44 * - Call Reset() to quickly stop the decoder (e.g. to implement Seek) and wait
45 * for the callback before restarting decoding at another point.
46 * - To destroy the decoder, the plugin should release all of its references to
47 * it. Any pending callbacks will abort before the decoder is destroyed.
49 * Available video codecs vary by platform.
50 * All: theora, vorbis, vp8.
51 * Chrome and ChromeOS: aac, h264.
54 struct PPB_VideoDecoder_0_1
{ /* dev */
56 * Creates a new video decoder resource.
58 * @param[in] instance A <code>PP_Instance</code> identifying the instance
59 * with the video decoder.
61 * @return A <code>PP_Resource</code> corresponding to a video decoder if
62 * successful or 0 otherwise.
64 PP_Resource (*Create
)(PP_Instance instance
);
66 * Determines if the given resource is a video decoder.
68 * @param[in] resource A <code>PP_Resource</code> identifying a resource.
70 * @return <code>PP_TRUE</code> if the resource is a
71 * <code>PPB_VideoDecoder</code>, <code>PP_FALSE</code> if the resource is
72 * invalid or some other type.
74 PP_Bool (*IsVideoDecoder
)(PP_Resource resource
);
76 * Initializes a video decoder resource. This should be called after Create()
77 * and before any other functions.
79 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
81 * @param[in] graphics3d_context A <code>PPB_Graphics3D</code> resource to use
83 * @param[in] profile A <code>PP_VideoProfile</code> specifying the video
85 * @param[in] allow_software_fallback A <code>PP_Bool</code> specifying
86 * whether the decoder can fall back to software decoding if a suitable
87 * hardware decoder isn't available.
88 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
91 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
92 * Returns PP_ERROR_NOTSUPPORTED if video decoding is not available, or the
93 * requested profile is not supported. In this case, the client may call
94 * Initialize() again with different parameters to find a good configuration.
96 int32_t (*Initialize
)(PP_Resource video_decoder
,
97 PP_Resource graphics3d_context
,
98 PP_VideoProfile profile
,
99 PP_Bool allow_software_fallback
,
100 struct PP_CompletionCallback callback
);
102 * Decodes a bitstream buffer. Copies |size| bytes of data from the plugin's
103 * |buffer|. The plugin should wait until the decoder signals completion by
104 * returning PP_OK or by running |callback| before calling Decode() again.
106 * In general, each bitstream buffer should contain a demuxed bitstream frame
107 * for the selected video codec. For example, H264 decoders expect to receive
108 * one AnnexB NAL unit, including the 4 byte start code prefix, while VP8
109 * decoders expect to receive a bitstream frame without the IVF frame header.
111 * If the call to Decode() eventually results in a picture, the |decode_id|
112 * parameter is copied into the returned picture. The plugin can use this to
113 * associate decoded pictures with Decode() calls (e.g. to assign timestamps
114 * or frame numbers to pictures.) This value is opaque to the API so the
115 * plugin is free to pass any value.
117 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
119 * @param[in] decode_id An optional value, chosen by the plugin, that can be
120 * used to associate calls to Decode() with decoded pictures returned by
122 * @param[in] size Buffer size in bytes.
123 * @param[in] buffer Starting address of buffer.
124 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
127 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
128 * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Flush()
129 * or Reset() call is pending.
130 * Returns PP_ERROR_INPROGRESS if there is another Decode() call pending.
131 * Returns PP_ERROR_NOMEMORY if a bitstream buffer can't be created.
132 * Returns PP_ERROR_ABORTED when Reset() is called while Decode() is pending.
134 int32_t (*Decode
)(PP_Resource video_decoder
,
138 struct PP_CompletionCallback callback
);
140 * Gets the next picture from the decoder. The picture is valid after the
141 * decoder signals completion by returning PP_OK or running |callback|. The
142 * plugin can call GetPicture() again after the decoder signals completion.
143 * When the plugin is finished using the picture, it should return it to the
144 * system by calling RecyclePicture().
146 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
148 * @param[out] picture A <code>PP_VideoPicture</code> to hold the decoded
150 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
153 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
154 * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Reset()
156 * Returns PP_ERROR_INPROGRESS if there is another GetPicture() call pending.
157 * Returns PP_ERROR_ABORTED when Reset() is called, or if a call to Flush()
158 * completes while GetPicture() is pending.
160 int32_t (*GetPicture
)(PP_Resource video_decoder
,
161 struct PP_VideoPicture
* picture
,
162 struct PP_CompletionCallback callback
);
164 * Recycles a picture that the plugin has received from the decoder.
165 * The plugin should call this as soon as it has finished using the texture so
166 * the decoder can decode more pictures.
168 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
170 * @param[in] picture A <code>PP_VideoPicture</code> to return to
173 void (*RecyclePicture
)(PP_Resource video_decoder
,
174 const struct PP_VideoPicture
* picture
);
176 * Flushes the decoder. The plugin should call Flush() when it reaches the
177 * end of its video stream in order to stop cleanly. The decoder will run any
178 * pending Decode() call to completion. The plugin should make no further
179 * calls to the decoder other than GetPicture() and RecyclePicture() until
180 * the decoder signals completion by running |callback|. Just before
181 * completion, any pending GetPicture() call will complete by running its
182 * callback with result PP_ERROR_ABORTED to signal that no more pictures are
183 * available. Any pictures held by the plugin remain valid during and after
184 * the flush and should be recycled back to the decoder.
186 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
188 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
191 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
192 * Returns PP_ERROR_FAILED if the decoder isn't initialized.
194 int32_t (*Flush
)(PP_Resource video_decoder
,
195 struct PP_CompletionCallback callback
);
197 * Resets the decoder as quickly as possible. The plugin can call Reset() to
198 * skip to another position in the video stream. After Reset() returns, any
199 * pending calls to Decode() and GetPicture()) abort, causing their callbacks
200 * to run with PP_ERROR_ABORTED. The plugin should not make further calls to
201 * the decoder other than RecyclePicture() until the decoder signals
202 * completion by running |callback|. Any pictures held by the plugin remain
203 * valid during and after the reset and should be recycled back to the
206 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
208 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
211 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
212 * Returns PP_ERROR_FAILED if the decoder isn't initialized.
214 int32_t (*Reset
)(PP_Resource video_decoder
,
215 struct PP_CompletionCallback callback
);
221 #endif /* PPAPI_C_PPB_VIDEO_DECODER_H_ */