Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 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 | |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 6 | /* From ppb_video_decoder.idl modified Fri Jul 11 18:06:37 2014. */ |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 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_resource.h" |
| 17 | #include "ppapi/c/pp_size.h" |
| 18 | #include "ppapi/c/pp_stdint.h" |
| 19 | |
| 20 | #define PPB_VIDEODECODER_INTERFACE_0_1 "PPB_VideoDecoder;0.1" /* dev */ |
| 21 | /** |
| 22 | * @file |
| 23 | * This file defines the <code>PPB_VideoDecoder</code> interface. |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * @addtogroup Interfaces |
| 29 | * @{ |
| 30 | */ |
| 31 | /** |
| 32 | * Video decoder interface. |
| 33 | * |
| 34 | * Typical usage: |
| 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 |
| 43 | * when it completes. |
| 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. |
| 48 | * |
| 49 | * Available video codecs vary by platform. |
| 50 | * All: theora, vorbis, vp8. |
| 51 | * Chrome and ChromeOS: aac, h264. |
| 52 | * ChromeOS: mpeg4. |
| 53 | */ |
| 54 | struct PPB_VideoDecoder_0_1 { /* dev */ |
| 55 | /** |
| 56 | * Creates a new video decoder resource. |
| 57 | * |
| 58 | * @param[in] instance A <code>PP_Instance</code> identifying the instance |
| 59 | * with the video decoder. |
| 60 | * |
| 61 | * @return A <code>PP_Resource</code> corresponding to a video decoder if |
| 62 | * successful or 0 otherwise. |
| 63 | */ |
| 64 | PP_Resource (*Create)(PP_Instance instance); |
| 65 | /** |
| 66 | * Determines if the given resource is a video decoder. |
| 67 | * |
| 68 | * @param[in] resource A <code>PP_Resource</code> identifying a resource. |
| 69 | * |
| 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. |
| 73 | */ |
| 74 | PP_Bool (*IsVideoDecoder)(PP_Resource resource); |
| 75 | /** |
| 76 | * Initializes a video decoder resource. This should be called after Create() |
| 77 | * and before any other functions. |
| 78 | * |
| 79 | * @param[in] video_decoder A <code>PP_Resource</code> identifying the video |
| 80 | * decoder. |
| 81 | * @param[in] graphics3d_context A <code>PPB_Graphics3D</code> resource to use |
| 82 | * during decoding. |
| 83 | * @param[in] profile A <code>PP_VideoProfile</code> specifying the video |
| 84 | * codec profile. |
| 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 |
| 89 | * completion. |
| 90 | * |
| 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. |
| 95 | */ |
| 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); |
| 101 | /** |
| 102 | * Decodes a bitstream buffer. Copies |size| bytes of data from the plugin's |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 103 | * |buffer|. The plugin should wait until the decoder signals completion by |
| 104 | * returning PP_OK or by running |callback| before calling Decode() again. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 105 | * |
| 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. |
| 110 | * |
| 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. |
| 116 | * |
| 117 | * @param[in] video_decoder A <code>PP_Resource</code> identifying the video |
| 118 | * decoder. |
| 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 |
| 121 | * GetPicture(). |
| 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 |
| 125 | * completion. |
| 126 | * |
| 127 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 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. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 133 | */ |
| 134 | int32_t (*Decode)(PP_Resource video_decoder, |
| 135 | uint32_t decode_id, |
| 136 | uint32_t size, |
| 137 | const void* buffer, |
| 138 | struct PP_CompletionCallback callback); |
| 139 | /** |
| 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(). |
| 145 | * |
| 146 | * @param[in] video_decoder A <code>PP_Resource</code> identifying the video |
| 147 | * decoder. |
| 148 | * @param[out] picture A <code>PP_VideoPicture</code> to hold the decoded |
| 149 | * picture. |
| 150 | * @param[in] callback A <code>PP_CompletionCallback</code> to be called on |
| 151 | * completion. |
| 152 | * |
| 153 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 154 | * Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Reset() |
| 155 | * call is pending. |
| 156 | * Returns PP_ERROR_INPROGRESS if there is another GetPicture() call pending. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 157 | * Returns PP_ERROR_ABORTED when Reset() is called, or if a call to Flush() |
| 158 | * completes while GetPicture() is pending. |
| 159 | */ |
| 160 | int32_t (*GetPicture)(PP_Resource video_decoder, |
| 161 | struct PP_VideoPicture* picture, |
| 162 | struct PP_CompletionCallback callback); |
| 163 | /** |
| 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. |
| 167 | * |
| 168 | * @param[in] video_decoder A <code>PP_Resource</code> identifying the video |
| 169 | * decoder. |
| 170 | * @param[in] picture A <code>PP_VideoPicture</code> to return to |
| 171 | * the decoder. |
| 172 | */ |
| 173 | void (*RecyclePicture)(PP_Resource video_decoder, |
| 174 | const struct PP_VideoPicture* picture); |
| 175 | /** |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 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 |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 183 | * available. Any pictures held by the plugin remain valid during and after |
| 184 | * the flush and should be recycled back to the decoder. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 185 | * |
| 186 | * @param[in] video_decoder A <code>PP_Resource</code> identifying the video |
| 187 | * decoder. |
| 188 | * @param[in] callback A <code>PP_CompletionCallback</code> to be called on |
| 189 | * completion. |
| 190 | * |
| 191 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 192 | * Returns PP_ERROR_FAILED if the decoder isn't initialized. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 193 | */ |
| 194 | int32_t (*Flush)(PP_Resource video_decoder, |
| 195 | struct PP_CompletionCallback callback); |
| 196 | /** |
| 197 | * Resets the decoder as quickly as possible. The plugin can call Reset() to |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 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 |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 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 |
| 204 | * decoder. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 205 | * |
| 206 | * @param[in] video_decoder A <code>PP_Resource</code> identifying the video |
| 207 | * decoder. |
| 208 | * @param[in] callback A <code>PP_CompletionCallback</code> to be called on |
| 209 | * completion. |
| 210 | * |
| 211 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 212 | * Returns PP_ERROR_FAILED if the decoder isn't initialized. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 213 | */ |
| 214 | int32_t (*Reset)(PP_Resource video_decoder, |
| 215 | struct PP_CompletionCallback callback); |
| 216 | }; |
| 217 | /** |
| 218 | * @} |
| 219 | */ |
| 220 | |
| 221 | #endif /* PPAPI_C_PPB_VIDEO_DECODER_H_ */ |
| 222 | |