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.
7 * This file defines the <code>PPB_VideoDecoder</code> interface.
13 /** Though not labeled 'channel=dev', 0.1 is a still a 'Dev' only API. */
19 * Video decoder interface.
22 * - Call Create() to create a new video decoder resource.
23 * - Call Initialize() to initialize it with a 3d graphics context and the
24 * desired codec profile.
25 * - Call Decode() continuously (waiting for each previous call to complete) to
26 * push bitstream buffers to the decoder.
27 * - Call GetPicture() continuously (waiting for each previous call to complete)
28 * to pull decoded pictures from the decoder.
29 * - Call Flush() to signal end of stream to the decoder and perform shutdown
31 * - Call Reset() to quickly stop the decoder (e.g. to implement Seek) and wait
32 * for the callback before restarting decoding at another point.
33 * - To destroy the decoder, the plugin should release all of its references to
34 * it. Any pending callbacks will abort before the decoder is destroyed.
36 * Available video codecs vary by platform.
37 * All: theora, vorbis, vp8.
38 * Chrome and ChromeOS: aac, h264.
41 interface PPB_VideoDecoder
{
43 * Creates a new video decoder resource.
45 * @param[in] instance A <code>PP_Instance</code> identifying the instance
46 * with the video decoder.
48 * @return A <code>PP_Resource</code> corresponding to a video decoder if
49 * successful or 0 otherwise.
52 [in] PP_Instance instance
);
55 * Determines if the given resource is a video decoder.
57 * @param[in] resource A <code>PP_Resource</code> identifying a resource.
59 * @return <code>PP_TRUE</code> if the resource is a
60 * <code>PPB_VideoDecoder</code>, <code>PP_FALSE</code> if the resource is
61 * invalid or some other type.
63 PP_Bool IsVideoDecoder
(
64 [in] PP_Resource resource
);
67 * Initializes a video decoder resource. This should be called after Create()
68 * and before any other functions.
70 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
72 * @param[in] graphics3d_context A <code>PPB_Graphics3D</code> resource to use
74 * @param[in] profile A <code>PP_VideoProfile</code> specifying the video
76 * @param[in] allow_software_fallback A <code>PP_Bool</code> specifying
77 * whether the decoder can fall back to software decoding if a suitable
78 * hardware decoder isn't available.
79 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
82 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
83 * Returns PP_ERROR_NOTSUPPORTED if video decoding is not available, or the
84 * requested profile is not supported. In this case, the client may call
85 * Initialize() again with different parameters to find a good configuration.
88 [in] PP_Resource video_decoder
,
89 [in] PP_Resource graphics3d_context
,
90 [in] PP_VideoProfile profile
,
91 [in] PP_Bool allow_software_fallback
,
92 [in] PP_CompletionCallback
callback);
95 * Initializes a video decoder resource. This should be called after Create()
96 * and before any other functions.
98 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
100 * @param[in] graphics3d_context A <code>PPB_Graphics3D</code> resource to use
102 * @param[in] profile A <code>PP_VideoProfile</code> specifying the video
104 * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
105 * whether to use a hardware accelerated or a software implementation.
106 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
109 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
110 * Returns PP_ERROR_NOTSUPPORTED if video decoding is not available, or the
111 * requested profile is not supported. In this case, the client may call
112 * Initialize() again with different parameters to find a good configuration.
116 [in] PP_Resource video_decoder
,
117 [in] PP_Resource graphics3d_context
,
118 [in] PP_VideoProfile profile
,
119 [in] PP_HardwareAcceleration acceleration
,
120 [in] PP_CompletionCallback
callback);
123 * Decodes a bitstream buffer. Copies |size| bytes of data from the plugin's
124 * |buffer|. The plugin should wait until the decoder signals completion by
125 * returning PP_OK or by running |callback| before calling Decode() again.
127 * In general, each bitstream buffer should contain a demuxed bitstream frame
128 * for the selected video codec. For example, H264 decoders expect to receive
129 * one AnnexB NAL unit, including the 4 byte start code prefix, while VP8
130 * decoders expect to receive a bitstream frame without the IVF frame header.
132 * If the call to Decode() eventually results in a picture, the |decode_id|
133 * parameter is copied into the returned picture. The plugin can use this to
134 * associate decoded pictures with Decode() calls (e.g. to assign timestamps
135 * or frame numbers to pictures.) This value is opaque to the API so the
136 * plugin is free to pass any value.
138 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
140 * @param[in] decode_id An optional value, chosen by the plugin, that can be
141 * used to associate calls to Decode() with decoded pictures returned by
143 * @param[in] size Buffer size in bytes.
144 * @param[in] buffer Starting address of buffer.
145 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
148 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
149 * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Flush()
150 * or Reset() call is pending.
151 * Returns PP_ERROR_INPROGRESS if there is another Decode() call pending.
152 * Returns PP_ERROR_NOMEMORY if a bitstream buffer can't be created.
153 * Returns PP_ERROR_ABORTED when Reset() is called while Decode() is pending.
156 [in] PP_Resource video_decoder
,
157 [in] uint32_t decode_id
,
160 [in] PP_CompletionCallback
callback);
163 * Gets the next picture from the decoder. The picture is valid after the
164 * decoder signals completion by returning PP_OK or running |callback|. The
165 * plugin can call GetPicture() again after the decoder signals completion.
166 * When the plugin is finished using the picture, it should return it to the
167 * system by calling RecyclePicture().
169 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
171 * @param[out] picture A <code>PP_VideoPicture</code> to hold the decoded
173 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
176 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
177 * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Reset()
179 * Returns PP_ERROR_INPROGRESS if there is another GetPicture() call pending.
180 * Returns PP_ERROR_ABORTED when Reset() is called, or if a call to Flush()
181 * completes while GetPicture() is pending.
184 [in] PP_Resource video_decoder
,
185 [out] PP_VideoPicture picture
,
186 [in] PP_CompletionCallback
callback);
189 * Recycles a picture that the plugin has received from the decoder.
190 * The plugin should call this as soon as it has finished using the texture so
191 * the decoder can decode more pictures.
193 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
195 * @param[in] picture A <code>PP_VideoPicture</code> to return to
199 [in] PP_Resource video_decoder
,
200 [in] PP_VideoPicture picture
);
203 * Flushes the decoder. The plugin should call Flush() when it reaches the
204 * end of its video stream in order to stop cleanly. The decoder will run any
205 * pending Decode() call to completion. The plugin should make no further
206 * calls to the decoder other than GetPicture() and RecyclePicture() until
207 * the decoder signals completion by running |callback|. Just before
208 * completion, any pending GetPicture() call will complete by running its
209 * callback with result PP_ERROR_ABORTED to signal that no more pictures are
210 * available. Any pictures held by the plugin remain valid during and after
211 * the flush and should be recycled back to the decoder.
213 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
215 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
218 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
219 * Returns PP_ERROR_FAILED if the decoder isn't initialized.
222 [in] PP_Resource video_decoder
,
223 [in] PP_CompletionCallback
callback);
226 * Resets the decoder as quickly as possible. The plugin can call Reset() to
227 * skip to another position in the video stream. After Reset() returns, any
228 * pending calls to Decode() and GetPicture()) abort, causing their callbacks
229 * to run with PP_ERROR_ABORTED. The plugin should not make further calls to
230 * the decoder other than RecyclePicture() until the decoder signals
231 * completion by running |callback|. Any pictures held by the plugin remain
232 * valid during and after the reset and should be recycled back to the
235 * @param[in] video_decoder A <code>PP_Resource</code> identifying the video
237 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on
240 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
241 * Returns PP_ERROR_FAILED if the decoder isn't initialized.
244 [in] PP_Resource video_decoder
,
245 [in] PP_CompletionCallback
callback);