| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | #ifndef VPX_VPX_VPX_DECODER_H_ |
| 11 | #define VPX_VPX_VPX_DECODER_H_ |
| 12 |
| 13 | /*!\defgroup decoder Decoder Algorithm Interface |
| 14 | * \ingroup codec |
| 15 | * This abstraction allows applications using this decoder to easily support |
| 16 | * multiple video formats with minimal code duplication. This section describes |
| 17 | * the interface common to all decoders. |
| 18 | * @{ |
| 19 | */ |
| 20 |
| 21 | /*!\file |
| 22 | * \brief Describes the decoder algorithm interface to applications. |
| 23 | * |
| 24 | * This file describes the interface between an application and a |
| 25 | * video decoder algorithm. |
| 26 | * |
| 27 | */ |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 |
| 32 | #include "./vpx_codec.h" // IWYU pragma: export |
| 33 | #include "./vpx_frame_buffer.h" |
| 34 |
| 35 | /*!\brief Current ABI version number |
| 36 | * |
| 37 | * \internal |
| 38 | * If this file is altered in any way that changes the ABI, this value |
| 39 | * must be bumped. Examples include, but are not limited to, changing |
| 40 | * types, removing or reassigning enums, adding/removing/rearranging |
| 41 | * fields to structures |
| 42 | */ |
| 43 | #define VPX_DECODER_ABI_VERSION \ |
| 44 | (3 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/ |
| 45 |
| 46 | /*! \brief Decoder capabilities bitfield |
| 47 | * |
| 48 | * Each decoder advertises the capabilities it supports as part of its |
| 49 | * ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces |
| 50 | * or functionality, and are not required to be supported by a decoder. |
| 51 | * |
| 52 | * The available flags are specified by VPX_CODEC_CAP_* defines. |
| 53 | */ |
| 54 | #define VPX_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */ |
| 55 | #define VPX_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */ |
| 56 | #define VPX_CODEC_CAP_POSTPROC 0x40000 /**< Can postprocess decoded frame */ |
| 57 | /*!\brief Can conceal errors due to packet loss */ |
| 58 | #define VPX_CODEC_CAP_ERROR_CONCEALMENT 0x80000 |
| 59 | /*!\brief Can receive encoded frames one fragment at a time */ |
| 60 | #define VPX_CODEC_CAP_INPUT_FRAGMENTS 0x100000 |
| 61 | /*!\brief Can support frame-based multi-threading */ |
| 62 | #define VPX_CODEC_CAP_FRAME_THREADING 0x200000 |
| 63 | /*!\brief Can support external frame buffers */ |
| 64 | #define VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000 |
| 65 |
| 66 | /*! \brief Initialization-time Feature Enabling |
| 67 | * |
| 68 | * Certain codec features must be known at initialization time, to allow for |
| 69 | * proper memory allocation. |
| 70 | * |
| 71 | * The available flags are specified by VPX_CODEC_USE_* defines. |
| 72 | */ |
| 73 | #define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */ |
| 74 | /*!\brief Conceal errors in decoded frames */ |
| 75 | #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 |
| 76 | /*!\brief The input frame should be passed to the decoder one fragment at a |
| 77 | * time */ |
| 78 | #define VPX_CODEC_USE_INPUT_FRAGMENTS 0x40000 |
| 79 | /*!\brief Enable frame-based multi-threading */ |
| 80 | #define VPX_CODEC_USE_FRAME_THREADING 0x80000 |
| 81 |
| 82 | /*!\brief Stream properties |
| 83 | * |
| 84 | * This structure is used to query or set properties of the decoded |
| 85 | * stream. Algorithms may extend this structure with data specific |
| 86 | * to their bitstream by setting the sz member appropriately. |
| 87 | */ |
| 88 | typedef struct vpx_codec_stream_info { |
| 89 | unsigned int sz; /**< Size of this structure */ |
| 90 | unsigned int w; /**< Width (or 0 for unknown/default) */ |
| 91 | unsigned int h; /**< Height (or 0 for unknown/default) */ |
| 92 | unsigned int is_kf; /**< Current frame is a keyframe */ |
| 93 | } vpx_codec_stream_info_t; |
| 94 |
| 95 | /* REQUIRED FUNCTIONS |
| 96 | * |
| 97 | * The following functions are required to be implemented for all decoders. |
| 98 | * They represent the base case functionality expected of all decoders. |
| 99 | */ |
| 100 |
| 101 | /*!\brief Initialization Configurations |
| 102 | * |
| 103 | * This structure is used to pass init time configuration options to the |
| 104 | * decoder. |
| 105 | */ |
| 106 | typedef struct vpx_codec_dec_cfg { |
| 107 | unsigned int threads; /**< Maximum number of threads to use, default 1 */ |
| 108 | unsigned int w; /**< Width */ |
| 109 | unsigned int h; /**< Height */ |
| 110 | } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */ |
| 111 |
| 112 | /*!\brief Initialize a decoder instance |
| 113 | * |
| 114 | * Initializes a decoder context using the given interface. Applications |
| 115 | * should call the vpx_codec_dec_init convenience macro instead of this |
| 116 | * function directly, to ensure that the ABI version number parameter |
| 117 | * is properly initialized. |
| 118 | * |
| 119 | * If the library was configured with --disable-multithread, this call |
| 120 | * is not thread safe and should be guarded with a lock if being used |
| 121 | * in a multithreaded context. |
| 122 | * |
| 123 | * \param[in] ctx Pointer to this instance's context. |
| 124 | * \param[in] iface Pointer to the algorithm interface to use. |
| 125 | * \param[in] cfg Configuration to use, if known. May be NULL. |
| 126 | * \param[in] flags Bitfield of VPX_CODEC_USE_* flags |
| 127 | * \param[in] ver ABI version number. Must be set to |
| 128 | * VPX_DECODER_ABI_VERSION |
| 129 | * \retval #VPX_CODEC_OK |
| 130 | * The decoder algorithm has been initialized. |
| 131 | * \retval #VPX_CODEC_MEM_ERROR |
| 132 | * Memory allocation failed. |
| 133 | */ |
| 134 | vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, |
| 135 | vpx_codec_iface_t *iface, |
| 136 | const vpx_codec_dec_cfg_t *cfg, |
| 137 | vpx_codec_flags_t flags, int ver); |
| 138 |
| 139 | /*!\brief Convenience macro for vpx_codec_dec_init_ver() |
| 140 | * |
| 141 | * Ensures the ABI version parameter is properly set. |
| 142 | */ |
| 143 | #define vpx_codec_dec_init(ctx, iface, cfg, flags) \ |
| 144 | vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION) |
| 145 |
| 146 | /*!\brief Parse stream info from a buffer |
| 147 | * |
| 148 | * Performs high level parsing of the bitstream. Construction of a decoder |
| 149 | * context is not necessary. Can be used to determine if the bitstream is |
| 150 | * of the proper format, and to extract information from the stream. |
| 151 | * |
| 152 | * \param[in] iface Pointer to the algorithm interface |
| 153 | * \param[in] data Pointer to a block of data to parse |
| 154 | * \param[in] data_sz Size of the data buffer |
| 155 | * \param[in,out] si Pointer to stream info to update. The sz member |
| 156 | * \ref MUST be properly initialized, but \ref MAY be |
| 157 | * clobbered by the algorithm. This parameter \ref MAY |
| 158 | * be NULL. |
| 159 | * |
| 160 | * \retval #VPX_CODEC_OK |
| 161 | * Bitstream is parsable and stream information updated |
| 162 | */ |
| 163 | vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, |
| 164 | const uint8_t *data, |
| 165 | unsigned int data_sz, |
| 166 | vpx_codec_stream_info_t *si); |
| 167 |
| 168 | /*!\brief Return information about the current stream. |
| 169 | * |
| 170 | * Returns information about the stream that has been parsed during decoding. |
| 171 | * |
| 172 | * \param[in] ctx Pointer to this instance's context |
| 173 | * \param[in,out] si Pointer to stream info to update. The sz member |
| 174 | * \ref MUST be properly initialized, but \ref MAY be |
| 175 | * clobbered by the algorithm. This parameter \ref MAY |
| 176 | * be NULL. |
| 177 | * |
| 178 | * \retval #VPX_CODEC_OK |
| 179 | * Bitstream is parsable and stream information updated |
| 180 | */ |
| 181 | vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx, |
| 182 | vpx_codec_stream_info_t *si); |
| 183 |
| 184 | /*!\brief Decode data |
| 185 | * |
| 186 | * Processes a buffer of coded data. If the processing results in a new |
| 187 | * decoded frame becoming available, put_slice and put_frame callbacks may be |
| 188 | * invoked, as appropriate. Encoded data \ref MUST be passed in DTS (decode |
| 189 | * time stamp) order. Frames produced will always be in PTS (presentation |
| 190 | * time stamp) order. |
| 191 | * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled, |
| 192 | * data and data_sz can contain a fragment of the encoded frame. Fragment |
| 193 | * \#n must contain at least partition \#n, but can also contain subsequent |
| 194 | * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must |
| 195 | * be empty. When no more data is available, this function should be called |
| 196 | * with NULL as data and 0 as data_sz. The memory passed to this function |
| 197 | * must be available until the frame has been decoded. |
| 198 | * |
| 199 | * \param[in] ctx Pointer to this instance's context |
| 200 | * \param[in] data Pointer to this block of new coded data. If |
| 201 | * NULL, the put_frame callback is invoked for |
| 202 | * the previously decoded frame. |
| 203 | * \param[in] data_sz Size of the coded data, in bytes. |
| 204 | * \param[in] user_priv Application specific data to associate with |
| 205 | * this frame. |
| 206 | * \param[in] deadline Soft deadline the decoder should attempt to meet, |
| 207 | * in us. Set to zero for unlimited. |
| 208 | * NOTE: The deadline parameter is ignored. Always |
| 209 | * pass 0. |
| 210 | * |
| 211 | * \return Returns #VPX_CODEC_OK if the coded data was processed completely |
| 212 | * and future pictures can be decoded without error. Otherwise, |
| 213 | * see the descriptions of the other error codes in ::vpx_codec_err_t |
| 214 | * for recoverability capabilities. |
| 215 | */ |
| 216 | vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, |
| 217 | unsigned int data_sz, void *user_priv, |
| 218 | long deadline); |
| 219 |
| 220 | /*!\brief Decoded frames iterator |
| 221 | * |
| 222 | * Iterates over a list of the frames available for display. The iterator |
| 223 | * storage should be initialized to NULL to start the iteration. Iteration is |
| 224 | * complete when this function returns NULL. |
| 225 | * |
| 226 | * The list of available frames becomes valid upon completion of the |
| 227 | * vpx_codec_decode call, and remains valid until the next call to |
| 228 | * vpx_codec_decode. |
| 229 | * |
| 230 | * \param[in] ctx Pointer to this instance's context |
| 231 | * \param[in,out] iter Iterator storage, initialized to NULL |
| 232 | * |
| 233 | * \return Returns a pointer to an image, if one is ready for display. Frames |
| 234 | * produced will always be in PTS (presentation time stamp) order. |
| 235 | */ |
| 236 | vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter); |
| 237 |
| 238 | /*!\defgroup cap_put_frame Frame-Based Decoding Functions |
| 239 | * |
| 240 | * The following function is required to be implemented for all decoders |
| 241 | * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling this |
| 242 | * function for codecs that don't advertise this capability will result in |
| 243 | * an error code being returned, usually VPX_CODEC_INCAPABLE. |
| 244 | * @{ |
| 245 | */ |
| 246 |
| 247 | /*!\brief put frame callback prototype |
| 248 | * |
| 249 | * This callback is invoked by the decoder to notify the application of |
| 250 | * the availability of decoded image data. |
| 251 | */ |
| 252 | typedef void (*vpx_codec_put_frame_cb_fn_t)(void *user_priv, |
| 253 | const vpx_image_t *img); |
| 254 |
| 255 | /*!\brief Register for notification of frame completion. |
| 256 | * |
| 257 | * Registers a given function to be called when a decoded frame is |
| 258 | * available. |
| 259 | * |
| 260 | * \param[in] ctx Pointer to this instance's context |
| 261 | * \param[in] cb Pointer to the callback function |
| 262 | * \param[in] user_priv User's private data |
| 263 | * |
| 264 | * \retval #VPX_CODEC_OK |
| 265 | * Callback successfully registered. |
| 266 | * \retval #VPX_CODEC_ERROR |
| 267 | * Decoder context not initialized. |
| 268 | * \retval #VPX_CODEC_INCAPABLE |
| 269 | * Algorithm not capable of posting frame completion. |
| 270 | */ |
| 271 | vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx, |
| 272 | vpx_codec_put_frame_cb_fn_t cb, |
| 273 | void *user_priv); |
| 274 |
| 275 | /*!@} - end defgroup cap_put_frame */ |
| 276 |
| 277 | /*!\defgroup cap_put_slice Slice-Based Decoding Functions |
| 278 | * |
| 279 | * The following function is required to be implemented for all decoders |
| 280 | * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling this |
| 281 | * function for codecs that don't advertise this capability will result in |
| 282 | * an error code being returned, usually VPX_CODEC_INCAPABLE. |
| 283 | * @{ |
| 284 | */ |
| 285 |
| 286 | /*!\brief put slice callback prototype |
| 287 | * |
| 288 | * This callback is invoked by the decoder to notify the application of |
| 289 | * the availability of partially decoded image data. |
| 290 | */ |
| 291 | typedef void (*vpx_codec_put_slice_cb_fn_t)(void *user_priv, |
| 292 | const vpx_image_t *img, |
| 293 | const vpx_image_rect_t *valid, |
| 294 | const vpx_image_rect_t *update); |
| 295 |
| 296 | /*!\brief Register for notification of slice completion. |
| 297 | * |
| 298 | * Registers a given function to be called when a decoded slice is |
| 299 | * available. |
| 300 | * |
| 301 | * \param[in] ctx Pointer to this instance's context |
| 302 | * \param[in] cb Pointer to the callback function |
| 303 | * \param[in] user_priv User's private data |
| 304 | * |
| 305 | * \retval #VPX_CODEC_OK |
| 306 | * Callback successfully registered. |
| 307 | * \retval #VPX_CODEC_ERROR |
| 308 | * Decoder context not initialized. |
| 309 | * \retval #VPX_CODEC_INCAPABLE |
| 310 | * Algorithm not capable of posting slice completion. |
| 311 | */ |
| 312 | vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx, |
| 313 | vpx_codec_put_slice_cb_fn_t cb, |
| 314 | void *user_priv); |
| 315 |
| 316 | /*!@} - end defgroup cap_put_slice*/ |
| 317 |
| 318 | /*!\defgroup cap_external_frame_buffer External Frame Buffer Functions |
| 319 | * |
| 320 | * The following function is required to be implemented for all decoders |
| 321 | * that advertise the VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER capability. |
| 322 | * Calling this function for codecs that don't advertise this capability |
| 323 | * will result in an error code being returned, usually VPX_CODEC_INCAPABLE. |
| 324 | * |
| 325 | * \note |
| 326 | * Currently this only works with VP9. |
| 327 | * @{ |
| 328 | */ |
| 329 |
| 330 | /*!\brief Pass in external frame buffers for the decoder to use. |
| 331 | * |
| 332 | * Registers functions to be called when libvpx needs a frame buffer |
| 333 | * to decode the current frame and a function to be called when libvpx does |
| 334 | * not internally reference the frame buffer. This set function must |
| 335 | * be called before the first call to decode or libvpx will assume the |
| 336 | * default behavior of allocating frame buffers internally. |
| 337 | * |
| 338 | * \param[in] ctx Pointer to this instance's context |
| 339 | * \param[in] cb_get Pointer to the get callback function |
| 340 | * \param[in] cb_release Pointer to the release callback function |
| 341 | * \param[in] cb_priv Callback's private data |
| 342 | * |
| 343 | * \retval #VPX_CODEC_OK |
| 344 | * External frame buffers will be used by libvpx. |
| 345 | * \retval #VPX_CODEC_INVALID_PARAM |
| 346 | * One or more of the callbacks were NULL. |
| 347 | * \retval #VPX_CODEC_ERROR |
| 348 | * Decoder context not initialized. |
| 349 | * \retval #VPX_CODEC_INCAPABLE |
| 350 | * Algorithm not capable of using external frame buffers. |
| 351 | * |
| 352 | * \note |
| 353 | * When decoding VP9, the application may be required to pass in at least |
| 354 | * #VP9_MAXIMUM_REF_BUFFERS + #VPX_MAXIMUM_WORK_BUFFERS external frame |
| 355 | * buffers. |
| 356 | */ |
| 357 | vpx_codec_err_t vpx_codec_set_frame_buffer_functions( |
| 358 | vpx_codec_ctx_t *ctx, vpx_get_frame_buffer_cb_fn_t cb_get, |
| 359 | vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv); |
| 360 |
| 361 | /*!@} - end defgroup cap_external_frame_buffer */ |
| 362 |
| 363 | /*!@} - end defgroup decoder*/ |
| 364 | #ifdef __cplusplus |
| 365 | } |
| 366 | #endif |
| 367 | #endif // VPX_VPX_VPX_DECODER_H_ |
| 368 |