michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: #ifndef VPX_DECODER_H michael@0: #define VPX_DECODER_H michael@0: michael@0: /*!\defgroup decoder Decoder Algorithm Interface michael@0: * \ingroup codec michael@0: * This abstraction allows applications using this decoder to easily support michael@0: * multiple video formats with minimal code duplication. This section describes michael@0: * the interface common to all decoders. michael@0: * @{ michael@0: */ michael@0: michael@0: /*!\file michael@0: * \brief Describes the decoder algorithm interface to applications. michael@0: * michael@0: * This file describes the interface between an application and a michael@0: * video decoder algorithm. michael@0: * michael@0: */ michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: #include "vpx_codec.h" michael@0: michael@0: /*!\brief Current ABI version number michael@0: * michael@0: * \internal michael@0: * If this file is altered in any way that changes the ABI, this value michael@0: * must be bumped. Examples include, but are not limited to, changing michael@0: * types, removing or reassigning enums, adding/removing/rearranging michael@0: * fields to structures michael@0: */ michael@0: #define VPX_DECODER_ABI_VERSION (2 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/ michael@0: michael@0: /*! \brief Decoder capabilities bitfield michael@0: * michael@0: * Each decoder advertises the capabilities it supports as part of its michael@0: * ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces michael@0: * or functionality, and are not required to be supported by a decoder. michael@0: * michael@0: * The available flags are specified by VPX_CODEC_CAP_* defines. michael@0: */ michael@0: #define VPX_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */ michael@0: #define VPX_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */ michael@0: #define VPX_CODEC_CAP_POSTPROC 0x40000 /**< Can postprocess decoded frame */ michael@0: #define VPX_CODEC_CAP_ERROR_CONCEALMENT 0x80000 /**< Can conceal errors due to michael@0: packet loss */ michael@0: #define VPX_CODEC_CAP_INPUT_FRAGMENTS 0x100000 /**< Can receive encoded frames michael@0: one fragment at a time */ michael@0: michael@0: /*! \brief Initialization-time Feature Enabling michael@0: * michael@0: * Certain codec features must be known at initialization time, to allow for michael@0: * proper memory allocation. michael@0: * michael@0: * The available flags are specified by VPX_CODEC_USE_* defines. michael@0: */ michael@0: #define VPX_CODEC_CAP_FRAME_THREADING 0x200000 /**< Can support frame-based michael@0: multi-threading */ michael@0: michael@0: #define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */ michael@0: #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded michael@0: frames */ michael@0: #define VPX_CODEC_USE_INPUT_FRAGMENTS 0x40000 /**< The input frame should be michael@0: passed to the decoder one michael@0: fragment at a time */ michael@0: #define VPX_CODEC_USE_FRAME_THREADING 0x80000 /**< Enable frame-based michael@0: multi-threading */ michael@0: michael@0: /*!\brief Stream properties michael@0: * michael@0: * This structure is used to query or set properties of the decoded michael@0: * stream. Algorithms may extend this structure with data specific michael@0: * to their bitstream by setting the sz member appropriately. michael@0: */ michael@0: typedef struct vpx_codec_stream_info { michael@0: unsigned int sz; /**< Size of this structure */ michael@0: unsigned int w; /**< Width (or 0 for unknown/default) */ michael@0: unsigned int h; /**< Height (or 0 for unknown/default) */ michael@0: unsigned int is_kf; /**< Current frame is a keyframe */ michael@0: } vpx_codec_stream_info_t; michael@0: michael@0: /* REQUIRED FUNCTIONS michael@0: * michael@0: * The following functions are required to be implemented for all decoders. michael@0: * They represent the base case functionality expected of all decoders. michael@0: */ michael@0: michael@0: michael@0: /*!\brief Initialization Configurations michael@0: * michael@0: * This structure is used to pass init time configuration options to the michael@0: * decoder. michael@0: */ michael@0: typedef struct vpx_codec_dec_cfg { michael@0: unsigned int threads; /**< Maximum number of threads to use, default 1 */ michael@0: unsigned int w; /**< Width */ michael@0: unsigned int h; /**< Height */ michael@0: } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */ michael@0: michael@0: michael@0: /*!\brief Initialize a decoder instance michael@0: * michael@0: * Initializes a decoder context using the given interface. Applications michael@0: * should call the vpx_codec_dec_init convenience macro instead of this michael@0: * function directly, to ensure that the ABI version number parameter michael@0: * is properly initialized. michael@0: * michael@0: * If the library was configured with --disable-multithread, this call michael@0: * is not thread safe and should be guarded with a lock if being used michael@0: * in a multithreaded context. michael@0: * michael@0: * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags michael@0: * parameter), the storage pointed to by the cfg parameter must be michael@0: * kept readable and stable until all memory maps have been set. michael@0: * michael@0: * \param[in] ctx Pointer to this instance's context. michael@0: * \param[in] iface Pointer to the algorithm interface to use. michael@0: * \param[in] cfg Configuration to use, if known. May be NULL. michael@0: * \param[in] flags Bitfield of VPX_CODEC_USE_* flags michael@0: * \param[in] ver ABI version number. Must be set to michael@0: * VPX_DECODER_ABI_VERSION michael@0: * \retval #VPX_CODEC_OK michael@0: * The decoder algorithm initialized. michael@0: * \retval #VPX_CODEC_MEM_ERROR michael@0: * Memory allocation failed. michael@0: */ michael@0: vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_iface_t *iface, michael@0: vpx_codec_dec_cfg_t *cfg, michael@0: vpx_codec_flags_t flags, michael@0: int ver); michael@0: michael@0: /*!\brief Convenience macro for vpx_codec_dec_init_ver() michael@0: * michael@0: * Ensures the ABI version parameter is properly set. michael@0: */ michael@0: #define vpx_codec_dec_init(ctx, iface, cfg, flags) \ michael@0: vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION) michael@0: michael@0: michael@0: /*!\brief Parse stream info from a buffer michael@0: * michael@0: * Performs high level parsing of the bitstream. Construction of a decoder michael@0: * context is not necessary. Can be used to determine if the bitstream is michael@0: * of the proper format, and to extract information from the stream. michael@0: * michael@0: * \param[in] iface Pointer to the algorithm interface michael@0: * \param[in] data Pointer to a block of data to parse michael@0: * \param[in] data_sz Size of the data buffer michael@0: * \param[in,out] si Pointer to stream info to update. The size member michael@0: * \ref MUST be properly initialized, but \ref MAY be michael@0: * clobbered by the algorithm. This parameter \ref MAY michael@0: * be NULL. michael@0: * michael@0: * \retval #VPX_CODEC_OK michael@0: * Bitstream is parsable and stream information updated michael@0: */ michael@0: vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, michael@0: const uint8_t *data, michael@0: unsigned int data_sz, michael@0: vpx_codec_stream_info_t *si); michael@0: michael@0: michael@0: /*!\brief Return information about the current stream. michael@0: * michael@0: * Returns information about the stream that has been parsed during decoding. michael@0: * michael@0: * \param[in] ctx Pointer to this instance's context michael@0: * \param[in,out] si Pointer to stream info to update. The size member michael@0: * \ref MUST be properly initialized, but \ref MAY be michael@0: * clobbered by the algorithm. This parameter \ref MAY michael@0: * be NULL. michael@0: * michael@0: * \retval #VPX_CODEC_OK michael@0: * Bitstream is parsable and stream information updated michael@0: */ michael@0: vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_stream_info_t *si); michael@0: michael@0: michael@0: /*!\brief Decode data michael@0: * michael@0: * Processes a buffer of coded data. If the processing results in a new michael@0: * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be michael@0: * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode michael@0: * time stamp) order. Frames produced will always be in PTS (presentation michael@0: * time stamp) order. michael@0: * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled, michael@0: * data and data_sz can contain a fragment of the encoded frame. Fragment michael@0: * \#n must contain at least partition \#n, but can also contain subsequent michael@0: * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must michael@0: * be empty. When no more data is available, this function should be called michael@0: * with NULL as data and 0 as data_sz. The memory passed to this function michael@0: * must be available until the frame has been decoded. michael@0: * michael@0: * \param[in] ctx Pointer to this instance's context michael@0: * \param[in] data Pointer to this block of new coded data. If michael@0: * NULL, a VPX_CODEC_CB_PUT_FRAME event is posted michael@0: * for the previously decoded frame. michael@0: * \param[in] data_sz Size of the coded data, in bytes. michael@0: * \param[in] user_priv Application specific data to associate with michael@0: * this frame. michael@0: * \param[in] deadline Soft deadline the decoder should attempt to meet, michael@0: * in us. Set to zero for unlimited. michael@0: * michael@0: * \return Returns #VPX_CODEC_OK if the coded data was processed completely michael@0: * and future pictures can be decoded without error. Otherwise, michael@0: * see the descriptions of the other error codes in ::vpx_codec_err_t michael@0: * for recoverability capabilities. michael@0: */ michael@0: vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, michael@0: const uint8_t *data, michael@0: unsigned int data_sz, michael@0: void *user_priv, michael@0: long deadline); michael@0: michael@0: michael@0: /*!\brief Decoded frames iterator michael@0: * michael@0: * Iterates over a list of the frames available for display. The iterator michael@0: * storage should be initialized to NULL to start the iteration. Iteration is michael@0: * complete when this function returns NULL. michael@0: * michael@0: * The list of available frames becomes valid upon completion of the michael@0: * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode. michael@0: * michael@0: * \param[in] ctx Pointer to this instance's context michael@0: * \param[in,out] iter Iterator storage, initialized to NULL michael@0: * michael@0: * \return Returns a pointer to an image, if one is ready for display. Frames michael@0: * produced will always be in PTS (presentation time stamp) order. michael@0: */ michael@0: vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_iter_t *iter); michael@0: michael@0: michael@0: /*!\defgroup cap_put_frame Frame-Based Decoding Functions michael@0: * michael@0: * The following functions are required to be implemented for all decoders michael@0: * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions michael@0: * for codecs that don't advertise this capability will result in an error michael@0: * code being returned, usually VPX_CODEC_ERROR michael@0: * @{ michael@0: */ michael@0: michael@0: /*!\brief put frame callback prototype michael@0: * michael@0: * This callback is invoked by the decoder to notify the application of michael@0: * the availability of decoded image data. michael@0: */ michael@0: typedef void (*vpx_codec_put_frame_cb_fn_t)(void *user_priv, michael@0: const vpx_image_t *img); michael@0: michael@0: michael@0: /*!\brief Register for notification of frame completion. michael@0: * michael@0: * Registers a given function to be called when a decoded frame is michael@0: * available. michael@0: * michael@0: * \param[in] ctx Pointer to this instance's context michael@0: * \param[in] cb Pointer to the callback function michael@0: * \param[in] user_priv User's private data michael@0: * michael@0: * \retval #VPX_CODEC_OK michael@0: * Callback successfully registered. michael@0: * \retval #VPX_CODEC_ERROR michael@0: * Decoder context not initialized, or algorithm not capable of michael@0: * posting slice completion. michael@0: */ michael@0: vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_put_frame_cb_fn_t cb, michael@0: void *user_priv); michael@0: michael@0: michael@0: /*!@} - end defgroup cap_put_frame */ michael@0: michael@0: /*!\defgroup cap_put_slice Slice-Based Decoding Functions michael@0: * michael@0: * The following functions are required to be implemented for all decoders michael@0: * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions michael@0: * for codecs that don't advertise this capability will result in an error michael@0: * code being returned, usually VPX_CODEC_ERROR michael@0: * @{ michael@0: */ michael@0: michael@0: /*!\brief put slice callback prototype michael@0: * michael@0: * This callback is invoked by the decoder to notify the application of michael@0: * the availability of partially decoded image data. The michael@0: */ michael@0: typedef void (*vpx_codec_put_slice_cb_fn_t)(void *user_priv, michael@0: const vpx_image_t *img, michael@0: const vpx_image_rect_t *valid, michael@0: const vpx_image_rect_t *update); michael@0: michael@0: michael@0: /*!\brief Register for notification of slice completion. michael@0: * michael@0: * Registers a given function to be called when a decoded slice is michael@0: * available. michael@0: * michael@0: * \param[in] ctx Pointer to this instance's context michael@0: * \param[in] cb Pointer to the callback function michael@0: * \param[in] user_priv User's private data michael@0: * michael@0: * \retval #VPX_CODEC_OK michael@0: * Callback successfully registered. michael@0: * \retval #VPX_CODEC_ERROR michael@0: * Decoder context not initialized, or algorithm not capable of michael@0: * posting slice completion. michael@0: */ michael@0: vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_put_slice_cb_fn_t cb, michael@0: void *user_priv); michael@0: michael@0: michael@0: /*!@} - end defgroup cap_put_slice*/ michael@0: michael@0: /*!@} - end defgroup decoder*/ michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: #endif michael@0: