John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | |
| 12 | /*!\defgroup decoder Decoder Algorithm Interface |
| 13 | * \ingroup codec |
| 14 | * This abstraction allows applications using this decoder to easily support |
| 15 | * multiple video formats with minimal code duplication. This section describes |
| 16 | * the interface common to all decoders. |
| 17 | * @{ |
| 18 | */ |
| 19 | |
James Zern | f42d52e | 2011-02-16 17:54:49 -0800 | [diff] [blame] | 20 | /*!\file |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 21 | * \brief Describes the decoder algorithm interface to applications. |
| 22 | * |
| 23 | * This file describes the interface between an application and a |
| 24 | * video decoder algorithm. |
| 25 | * |
| 26 | */ |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | #ifndef VPX_DECODER_H |
| 32 | #define VPX_DECODER_H |
| 33 | #include "vpx_codec.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 (2 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/ |
| 44 | |
| 45 | /*! \brief Decoder capabilities bitfield |
| 46 | * |
| 47 | * Each decoder advertises the capabilities it supports as part of its |
| 48 | * ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces |
| 49 | * or functionality, and are not required to be supported by a decoder. |
| 50 | * |
James Zern | f42d52e | 2011-02-16 17:54:49 -0800 | [diff] [blame] | 51 | * The available flags are specified by VPX_CODEC_CAP_* defines. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 52 | */ |
| 53 | #define VPX_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */ |
| 54 | #define VPX_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */ |
| 55 | #define VPX_CODEC_CAP_POSTPROC 0x40000 /**< Can postprocess decoded frame */ |
Stefan Holmer | d04f852 | 2011-05-02 15:30:51 +0200 | [diff] [blame] | 56 | #define VPX_CODEC_CAP_ERROR_CONCEALMENT 0x80000 /**< Can conceal errors due to |
| 57 | packet loss */ |
Stefan Holmer | b433e12 | 2011-06-10 15:58:22 +0200 | [diff] [blame] | 58 | #define VPX_CODEC_CAP_INPUT_PARTITION 0x100000 /**< Can receive encoded frames |
| 59 | one partition at a time */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 60 | |
| 61 | /*! \brief Initialization-time Feature Enabling |
| 62 | * |
| 63 | * Certain codec features must be known at initialization time, to allow for |
| 64 | * proper memory allocation. |
| 65 | * |
| 66 | * The available flags are specified by VPX_CODEC_USE_* defines. |
| 67 | */ |
| 68 | #define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */ |
Stefan Holmer | d04f852 | 2011-05-02 15:30:51 +0200 | [diff] [blame] | 69 | #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded |
| 70 | frames */ |
Stefan Holmer | b433e12 | 2011-06-10 15:58:22 +0200 | [diff] [blame] | 71 | #define VPX_CODEC_USE_INPUT_PARTITION 0x40000 /**< The input frame should be |
| 72 | passed to the decoder one |
| 73 | partition at a time */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 74 | |
| 75 | /*!\brief Stream properties |
| 76 | * |
| 77 | * This structure is used to query or set properties of the decoded |
| 78 | * stream. Algorithms may extend this structure with data specific |
| 79 | * to their bitstream by setting the sz member appropriately. |
| 80 | */ |
James Zern | f767a5a | 2010-05-20 13:14:17 -0400 | [diff] [blame] | 81 | typedef struct vpx_codec_stream_info |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 82 | { |
| 83 | unsigned int sz; /**< Size of this structure */ |
| 84 | unsigned int w; /**< Width (or 0 for unknown/default) */ |
| 85 | unsigned int h; /**< Height (or 0 for unknown/default) */ |
| 86 | unsigned int is_kf; /**< Current frame is a keyframe */ |
| 87 | } vpx_codec_stream_info_t; |
| 88 | |
| 89 | /* REQUIRED FUNCTIONS |
| 90 | * |
| 91 | * The following functions are required to be implemented for all decoders. |
| 92 | * They represent the base case functionality expected of all decoders. |
| 93 | */ |
| 94 | |
| 95 | |
| 96 | /*!\brief Initialization Configurations |
| 97 | * |
| 98 | * This structure is used to pass init time configuration options to the |
| 99 | * decoder. |
| 100 | */ |
| 101 | typedef struct vpx_codec_dec_cfg |
| 102 | { |
| 103 | unsigned int threads; /**< Maximum number of threads to use, default 1 */ |
| 104 | unsigned int w; /**< Width */ |
| 105 | unsigned int h; /**< Height */ |
| 106 | } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */ |
| 107 | |
| 108 | |
| 109 | /*!\brief Initialize a decoder instance |
| 110 | * |
| 111 | * Initializes a decoder context using the given interface. Applications |
| 112 | * should call the vpx_codec_dec_init convenience macro instead of this |
| 113 | * function directly, to ensure that the ABI version number parameter |
| 114 | * is properly initialized. |
| 115 | * |
| 116 | * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags |
| 117 | * parameter), the storage pointed to by the cfg parameter must be |
| 118 | * kept readable and stable until all memory maps have been set. |
| 119 | * |
| 120 | * \param[in] ctx Pointer to this instance's context. |
James Zern | f42d52e | 2011-02-16 17:54:49 -0800 | [diff] [blame] | 121 | * \param[in] iface Pointer to the algorithm interface to use. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 122 | * \param[in] cfg Configuration to use, if known. May be NULL. |
| 123 | * \param[in] flags Bitfield of VPX_CODEC_USE_* flags |
| 124 | * \param[in] ver ABI version number. Must be set to |
| 125 | * VPX_DECODER_ABI_VERSION |
| 126 | * \retval #VPX_CODEC_OK |
| 127 | * The decoder algorithm initialized. |
| 128 | * \retval #VPX_CODEC_MEM_ERROR |
| 129 | * Memory allocation failed. |
| 130 | */ |
| 131 | vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, |
| 132 | vpx_codec_iface_t *iface, |
| 133 | vpx_codec_dec_cfg_t *cfg, |
| 134 | vpx_codec_flags_t flags, |
| 135 | int ver); |
| 136 | |
| 137 | /*!\brief Convenience macro for vpx_codec_dec_init_ver() |
| 138 | * |
| 139 | * Ensures the ABI version parameter is properly set. |
| 140 | */ |
| 141 | #define vpx_codec_dec_init(ctx, iface, cfg, flags) \ |
| 142 | vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION) |
| 143 | |
| 144 | |
| 145 | /*!\brief Parse stream info from a buffer |
| 146 | * |
| 147 | * Performs high level parsing of the bitstream. Construction of a decoder |
| 148 | * context is not necessary. Can be used to determine if the bitstream is |
| 149 | * of the proper format, and to extract information from the stream. |
| 150 | * |
James Zern | f42d52e | 2011-02-16 17:54:49 -0800 | [diff] [blame] | 151 | * \param[in] iface Pointer to the algorithm interface |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 152 | * \param[in] data Pointer to a block of data to parse |
| 153 | * \param[in] data_sz Size of the data buffer |
| 154 | * \param[in,out] si Pointer to stream info to update. The size member |
| 155 | * \ref MUST be properly initialized, but \ref MAY be |
| 156 | * clobbered by the algorithm. This parameter \ref MAY |
| 157 | * be NULL. |
| 158 | * |
| 159 | * \retval #VPX_CODEC_OK |
| 160 | * Bitstream is parsable and stream information updated |
| 161 | */ |
| 162 | vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, |
| 163 | const uint8_t *data, |
| 164 | unsigned int data_sz, |
| 165 | vpx_codec_stream_info_t *si); |
| 166 | |
| 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 size 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 | |
| 185 | /*!\brief Decode data |
| 186 | * |
| 187 | * Processes a buffer of coded data. If the processing results in a new |
| 188 | * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be |
| 189 | * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode |
| 190 | * time stamp) order. Frames produced will always be in PTS (presentation |
| 191 | * time stamp) order. |
Stefan Holmer | b433e12 | 2011-06-10 15:58:22 +0200 | [diff] [blame] | 192 | * If the decoder is configured with VPX_CODEC_USE_INPUT_PARTITION enabled, |
| 193 | * data and data_sz must contain at most one encoded partition. When no more |
| 194 | * data is available, this function should be called with NULL as data and 0 |
| 195 | * as data_sz. The memory passed to this function must be available until |
| 196 | * the frame has been decoded. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 197 | * |
| 198 | * \param[in] ctx Pointer to this instance's context |
| 199 | * \param[in] data Pointer to this block of new coded data. If |
| 200 | * NULL, a VPX_CODEC_CB_PUT_FRAME event is posted |
| 201 | * for the previously decoded frame. |
| 202 | * \param[in] data_sz Size of the coded data, in bytes. |
| 203 | * \param[in] user_priv Application specific data to associate with |
| 204 | * this frame. |
| 205 | * \param[in] deadline Soft deadline the decoder should attempt to meet, |
| 206 | * in us. Set to zero for unlimited. |
| 207 | * |
| 208 | * \return Returns #VPX_CODEC_OK if the coded data was processed completely |
| 209 | * and future pictures can be decoded without error. Otherwise, |
| 210 | * see the descriptions of the other error codes in ::vpx_codec_err_t |
| 211 | * for recoverability capabilities. |
| 212 | */ |
| 213 | vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, |
| 214 | const uint8_t *data, |
| 215 | unsigned int data_sz, |
| 216 | void *user_priv, |
| 217 | long deadline); |
| 218 | |
| 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 vpx_codec_decode. |
| 228 | * |
| 229 | * \param[in] ctx Pointer to this instance's context |
| 230 | * \param[in,out] iter Iterator storage, initialized to NULL |
| 231 | * |
| 232 | * \return Returns a pointer to an image, if one is ready for display. Frames |
| 233 | * produced will always be in PTS (presentation time stamp) order. |
| 234 | */ |
| 235 | vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, |
| 236 | vpx_codec_iter_t *iter); |
| 237 | |
| 238 | |
| 239 | /*!\defgroup cap_put_frame Frame-Based Decoding Functions |
| 240 | * |
| 241 | * The following functions are required to be implemented for all decoders |
| 242 | * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions |
| 243 | * for codecs that don't advertise this capability will result in an error |
| 244 | * code being returned, usually VPX_CODEC_ERROR |
| 245 | * @{ |
| 246 | */ |
| 247 | |
| 248 | /*!\brief put frame callback prototype |
| 249 | * |
| 250 | * This callback is invoked by the decoder to notify the application of |
| 251 | * the availability of decoded image data. |
| 252 | */ |
| 253 | typedef void (*vpx_codec_put_frame_cb_fn_t)(void *user_priv, |
| 254 | const vpx_image_t *img); |
| 255 | |
| 256 | |
| 257 | /*!\brief Register for notification of frame completion. |
| 258 | * |
| 259 | * Registers a given function to be called when a decoded frame is |
| 260 | * available. |
| 261 | * |
| 262 | * \param[in] ctx Pointer to this instance's context |
| 263 | * \param[in] cb Pointer to the callback function |
| 264 | * \param[in] user_priv User's private data |
| 265 | * |
| 266 | * \retval #VPX_CODEC_OK |
| 267 | * Callback successfully registered. |
| 268 | * \retval #VPX_CODEC_ERROR |
| 269 | * Decoder context not initialized, or algorithm not capable of |
| 270 | * posting slice completion. |
| 271 | */ |
| 272 | vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx, |
| 273 | vpx_codec_put_frame_cb_fn_t cb, |
| 274 | void *user_priv); |
| 275 | |
| 276 | |
| 277 | /*!@} - end defgroup cap_put_frame */ |
| 278 | |
| 279 | /*!\defgroup cap_put_slice Slice-Based Decoding Functions |
| 280 | * |
| 281 | * The following functions are required to be implemented for all decoders |
| 282 | * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions |
| 283 | * for codecs that don't advertise this capability will result in an error |
| 284 | * code being returned, usually VPX_CODEC_ERROR |
| 285 | * @{ |
| 286 | */ |
| 287 | |
| 288 | /*!\brief put slice callback prototype |
| 289 | * |
| 290 | * This callback is invoked by the decoder to notify the application of |
| 291 | * the availability of partially decoded image data. The |
| 292 | */ |
| 293 | typedef void (*vpx_codec_put_slice_cb_fn_t)(void *user_priv, |
| 294 | const vpx_image_t *img, |
| 295 | const vpx_image_rect_t *valid, |
| 296 | const vpx_image_rect_t *update); |
| 297 | |
| 298 | |
| 299 | /*!\brief Register for notification of slice completion. |
| 300 | * |
| 301 | * Registers a given function to be called when a decoded slice is |
| 302 | * available. |
| 303 | * |
| 304 | * \param[in] ctx Pointer to this instance's context |
| 305 | * \param[in] cb Pointer to the callback function |
| 306 | * \param[in] user_priv User's private data |
| 307 | * |
| 308 | * \retval #VPX_CODEC_OK |
| 309 | * Callback successfully registered. |
| 310 | * \retval #VPX_CODEC_ERROR |
| 311 | * Decoder context not initialized, or algorithm not capable of |
| 312 | * posting slice completion. |
| 313 | */ |
| 314 | vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx, |
| 315 | vpx_codec_put_slice_cb_fn_t cb, |
| 316 | void *user_priv); |
| 317 | |
| 318 | |
| 319 | /*!@} - end defgroup cap_put_slice*/ |
| 320 | |
| 321 | /*!@} - end defgroup decoder*/ |
| 322 | |
| 323 | #endif |
| 324 | |
| 325 | #ifdef __cplusplus |
| 326 | } |
| 327 | #endif |
| 328 | |
| 329 | #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT |
| 330 | #include "vpx_decoder_compat.h" |
| 331 | #endif |