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