Home | History | Annotate | Download | only in vpx
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      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
      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 
     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 
     20 /*!\file
     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    *
     51    *  The available flags are specified by VPX_CODEC_CAP_* defines.
     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 */
     56 #define VPX_CODEC_CAP_ERROR_CONCEALMENT   0x80000 /**< Can conceal errors due to
     57   packet loss */
     58 #define VPX_CODEC_CAP_INPUT_FRAGMENTS   0x100000 /**< Can receive encoded frames
     59   one fragment at a time */
     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_CAP_FRAME_THREADING   0x200000 /**< Can support frame-based
     69                                                       multi-threading */
     70 
     71 #define VPX_CODEC_USE_POSTPROC   0x10000 /**< Postprocess decoded frame */
     72 #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded
     73   frames */
     74 #define VPX_CODEC_USE_INPUT_FRAGMENTS   0x40000 /**< The input frame should be
     75   passed to the decoder one
     76   fragment at a time */
     77 #define VPX_CODEC_USE_FRAME_THREADING   0x80000 /**< Enable frame-based
     78                                                      multi-threading */
     79 
     80   /*!\brief Stream properties
     81    *
     82    * This structure is used to query or set properties of the decoded
     83    * stream. Algorithms may extend this structure with data specific
     84    * to their bitstream by setting the sz member appropriately.
     85    */
     86   typedef struct vpx_codec_stream_info {
     87     unsigned int sz;     /**< Size of this structure */
     88     unsigned int w;      /**< Width (or 0 for unknown/default) */
     89     unsigned int h;      /**< Height (or 0 for unknown/default) */
     90     unsigned int is_kf;  /**< Current frame is a keyframe */
     91   } vpx_codec_stream_info_t;
     92 
     93   /* REQUIRED FUNCTIONS
     94    *
     95    * The following functions are required to be implemented for all decoders.
     96    * They represent the base case functionality expected of all decoders.
     97    */
     98 
     99 
    100   /*!\brief Initialization Configurations
    101    *
    102    * This structure is used to pass init time configuration options to the
    103    * decoder.
    104    */
    105   typedef struct vpx_codec_dec_cfg {
    106     unsigned int threads; /**< Maximum number of threads to use, default 1 */
    107     unsigned int w;      /**< Width */
    108     unsigned int h;      /**< Height */
    109   } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */
    110 
    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    * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
    124    * parameter), the storage pointed to by the cfg parameter must be
    125    * kept readable and stable until all memory maps have been set.
    126    *
    127    * \param[in]    ctx     Pointer to this instance's context.
    128    * \param[in]    iface   Pointer to the algorithm interface to use.
    129    * \param[in]    cfg     Configuration to use, if known. May be NULL.
    130    * \param[in]    flags   Bitfield of VPX_CODEC_USE_* flags
    131    * \param[in]    ver     ABI version number. Must be set to
    132    *                       VPX_DECODER_ABI_VERSION
    133    * \retval #VPX_CODEC_OK
    134    *     The decoder algorithm initialized.
    135    * \retval #VPX_CODEC_MEM_ERROR
    136    *     Memory allocation failed.
    137    */
    138   vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t      *ctx,
    139                                          vpx_codec_iface_t    *iface,
    140                                          vpx_codec_dec_cfg_t  *cfg,
    141                                          vpx_codec_flags_t     flags,
    142                                          int                   ver);
    143 
    144   /*!\brief Convenience macro for vpx_codec_dec_init_ver()
    145    *
    146    * Ensures the ABI version parameter is properly set.
    147    */
    148 #define vpx_codec_dec_init(ctx, iface, cfg, flags) \
    149   vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION)
    150 
    151 
    152   /*!\brief Parse stream info from a buffer
    153    *
    154    * Performs high level parsing of the bitstream. Construction of a decoder
    155    * context is not necessary. Can be used to determine if the bitstream is
    156    * of the proper format, and to extract information from the stream.
    157    *
    158    * \param[in]      iface   Pointer to the algorithm interface
    159    * \param[in]      data    Pointer to a block of data to parse
    160    * \param[in]      data_sz Size of the data buffer
    161    * \param[in,out]  si      Pointer to stream info to update. The size member
    162    *                         \ref MUST be properly initialized, but \ref MAY be
    163    *                         clobbered by the algorithm. This parameter \ref MAY
    164    *                         be NULL.
    165    *
    166    * \retval #VPX_CODEC_OK
    167    *     Bitstream is parsable and stream information updated
    168    */
    169   vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t       *iface,
    170                                              const uint8_t           *data,
    171                                              unsigned int             data_sz,
    172                                              vpx_codec_stream_info_t *si);
    173 
    174 
    175   /*!\brief Return information about the current stream.
    176    *
    177    * Returns information about the stream that has been parsed during decoding.
    178    *
    179    * \param[in]      ctx     Pointer to this instance's context
    180    * \param[in,out]  si      Pointer to stream info to update. The size member
    181    *                         \ref MUST be properly initialized, but \ref MAY be
    182    *                         clobbered by the algorithm. This parameter \ref MAY
    183    *                         be NULL.
    184    *
    185    * \retval #VPX_CODEC_OK
    186    *     Bitstream is parsable and stream information updated
    187    */
    188   vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t         *ctx,
    189                                             vpx_codec_stream_info_t *si);
    190 
    191 
    192   /*!\brief Decode data
    193    *
    194    * Processes a buffer of coded data. If the processing results in a new
    195    * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
    196    * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
    197    * time stamp) order. Frames produced will always be in PTS (presentation
    198    * time stamp) order.
    199    * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled,
    200    * data and data_sz can contain a fragment of the encoded frame. Fragment
    201    * \#n must contain at least partition \#n, but can also contain subsequent
    202    * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
    203    * be empty. When no more data is available, this function should be called
    204    * with NULL as data and 0 as data_sz. The memory passed to this function
    205    * must be available until the frame has been decoded.
    206    *
    207    * \param[in] ctx          Pointer to this instance's context
    208    * \param[in] data         Pointer to this block of new coded data. If
    209    *                         NULL, a VPX_CODEC_CB_PUT_FRAME event is posted
    210    *                         for the previously decoded frame.
    211    * \param[in] data_sz      Size of the coded data, in bytes.
    212    * \param[in] user_priv    Application specific data to associate with
    213    *                         this frame.
    214    * \param[in] deadline     Soft deadline the decoder should attempt to meet,
    215    *                         in us. Set to zero for unlimited.
    216    *
    217    * \return Returns #VPX_CODEC_OK if the coded data was processed completely
    218    *         and future pictures can be decoded without error. Otherwise,
    219    *         see the descriptions of the other error codes in ::vpx_codec_err_t
    220    *         for recoverability capabilities.
    221    */
    222   vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t    *ctx,
    223                                    const uint8_t        *data,
    224                                    unsigned int            data_sz,
    225                                    void               *user_priv,
    226                                    long                deadline);
    227 
    228 
    229   /*!\brief Decoded frames iterator
    230    *
    231    * Iterates over a list of the frames available for display. The iterator
    232    * storage should be initialized to NULL to start the iteration. Iteration is
    233    * complete when this function returns NULL.
    234    *
    235    * The list of available frames becomes valid upon completion of the
    236    * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode.
    237    *
    238    * \param[in]     ctx      Pointer to this instance's context
    239    * \param[in,out] iter     Iterator storage, initialized to NULL
    240    *
    241    * \return Returns a pointer to an image, if one is ready for display. Frames
    242    *         produced will always be in PTS (presentation time stamp) order.
    243    */
    244   vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t  *ctx,
    245                                    vpx_codec_iter_t *iter);
    246 
    247 
    248   /*!\defgroup cap_put_frame Frame-Based Decoding Functions
    249    *
    250    * The following functions are required to be implemented for all decoders
    251    * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions
    252    * for codecs that don't advertise this capability will result in an error
    253    * code being returned, usually VPX_CODEC_ERROR
    254    * @{
    255    */
    256 
    257   /*!\brief put frame callback prototype
    258    *
    259    * This callback is invoked by the decoder to notify the application of
    260    * the availability of decoded image data.
    261    */
    262   typedef void (*vpx_codec_put_frame_cb_fn_t)(void        *user_priv,
    263                                               const vpx_image_t *img);
    264 
    265 
    266   /*!\brief Register for notification of frame completion.
    267    *
    268    * Registers a given function to be called when a decoded frame is
    269    * available.
    270    *
    271    * \param[in] ctx          Pointer to this instance's context
    272    * \param[in] cb           Pointer to the callback function
    273    * \param[in] user_priv    User's private data
    274    *
    275    * \retval #VPX_CODEC_OK
    276    *     Callback successfully registered.
    277    * \retval #VPX_CODEC_ERROR
    278    *     Decoder context not initialized, or algorithm not capable of
    279    *     posting slice completion.
    280    */
    281   vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t             *ctx,
    282                                                   vpx_codec_put_frame_cb_fn_t  cb,
    283                                                   void                        *user_priv);
    284 
    285 
    286   /*!@} - end defgroup cap_put_frame */
    287 
    288   /*!\defgroup cap_put_slice Slice-Based Decoding Functions
    289    *
    290    * The following functions are required to be implemented for all decoders
    291    * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions
    292    * for codecs that don't advertise this capability will result in an error
    293    * code being returned, usually VPX_CODEC_ERROR
    294    * @{
    295    */
    296 
    297   /*!\brief put slice callback prototype
    298    *
    299    * This callback is invoked by the decoder to notify the application of
    300    * the availability of partially decoded image data. The
    301    */
    302   typedef void (*vpx_codec_put_slice_cb_fn_t)(void         *user_priv,
    303                                               const vpx_image_t      *img,
    304                                               const vpx_image_rect_t *valid,
    305                                               const vpx_image_rect_t *update);
    306 
    307 
    308   /*!\brief Register for notification of slice completion.
    309    *
    310    * Registers a given function to be called when a decoded slice is
    311    * available.
    312    *
    313    * \param[in] ctx          Pointer to this instance's context
    314    * \param[in] cb           Pointer to the callback function
    315    * \param[in] user_priv    User's private data
    316    *
    317    * \retval #VPX_CODEC_OK
    318    *     Callback successfully registered.
    319    * \retval #VPX_CODEC_ERROR
    320    *     Decoder context not initialized, or algorithm not capable of
    321    *     posting slice completion.
    322    */
    323   vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t             *ctx,
    324                                                   vpx_codec_put_slice_cb_fn_t  cb,
    325                                                   void                        *user_priv);
    326 
    327 
    328   /*!@} - end defgroup cap_put_slice*/
    329 
    330   /*!@} - end defgroup decoder*/
    331 
    332 #endif
    333 
    334 #ifdef __cplusplus
    335 }
    336 #endif
    337