2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
10 #ifndef VPX_VPX_DECODER_H_
11 #define VPX_VPX_DECODER_H_
13 /*!\defgroup decoder Decoder Algorithm Interface
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.
22 * \brief Describes the decoder algorithm interface to applications.
24 * This file describes the interface between an application and a
25 * video decoder algorithm.
32 #include "./vpx_codec.h"
33 #include "./vpx_frame_buffer.h"
35 /*!\brief Current ABI version number
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
43 #define VPX_DECODER_ABI_VERSION (3 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
45 /*! \brief Decoder capabilities bitfield
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.
51 * The available flags are specified by VPX_CODEC_CAP_* defines.
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
58 #define VPX_CODEC_CAP_INPUT_FRAGMENTS 0x100000 /**< Can receive encoded frames
59 one fragment at a time */
61 /*! \brief Initialization-time Feature Enabling
63 * Certain codec features must be known at initialization time, to allow for
64 * proper memory allocation.
66 * The available flags are specified by VPX_CODEC_USE_* defines.
68 #define VPX_CODEC_CAP_FRAME_THREADING 0x200000 /**< Can support frame-based
70 #define VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000 /**< Can support external
73 #define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
74 #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded
76 #define VPX_CODEC_USE_INPUT_FRAGMENTS 0x40000 /**< The input frame should be
77 passed to the decoder one
79 #define VPX_CODEC_USE_FRAME_THREADING 0x80000 /**< Enable frame-based
82 /*!\brief Stream properties
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.
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
;
97 * The following functions are required to be implemented for all decoders.
98 * They represent the base case functionality expected of all decoders.
102 /*!\brief Initialization Configurations
104 * This structure is used to pass init time configuration options to the
107 typedef struct vpx_codec_dec_cfg
{
108 unsigned int threads
; /**< Maximum number of threads to use, default 1 */
109 unsigned int w
; /**< Width */
110 unsigned int h
; /**< Height */
111 } vpx_codec_dec_cfg_t
; /**< alias for struct vpx_codec_dec_cfg */
114 /*!\brief Initialize a decoder instance
116 * Initializes a decoder context using the given interface. Applications
117 * should call the vpx_codec_dec_init convenience macro instead of this
118 * function directly, to ensure that the ABI version number parameter
119 * is properly initialized.
121 * If the library was configured with --disable-multithread, this call
122 * is not thread safe and should be guarded with a lock if being used
123 * in a multithreaded context.
125 * \param[in] ctx Pointer to this instance's context.
126 * \param[in] iface Pointer to the algorithm interface to use.
127 * \param[in] cfg Configuration to use, if known. May be NULL.
128 * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
129 * \param[in] ver ABI version number. Must be set to
130 * VPX_DECODER_ABI_VERSION
131 * \retval #VPX_CODEC_OK
132 * The decoder algorithm initialized.
133 * \retval #VPX_CODEC_MEM_ERROR
134 * Memory allocation failed.
136 vpx_codec_err_t
vpx_codec_dec_init_ver(vpx_codec_ctx_t
*ctx
,
137 vpx_codec_iface_t
*iface
,
138 const vpx_codec_dec_cfg_t
*cfg
,
139 vpx_codec_flags_t flags
,
142 /*!\brief Convenience macro for vpx_codec_dec_init_ver()
144 * Ensures the ABI version parameter is properly set.
146 #define vpx_codec_dec_init(ctx, iface, cfg, flags) \
147 vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION)
150 /*!\brief Parse stream info from a buffer
152 * Performs high level parsing of the bitstream. Construction of a decoder
153 * context is not necessary. Can be used to determine if the bitstream is
154 * of the proper format, and to extract information from the stream.
156 * \param[in] iface Pointer to the algorithm interface
157 * \param[in] data Pointer to a block of data to parse
158 * \param[in] data_sz Size of the data buffer
159 * \param[in,out] si Pointer to stream info to update. The size member
160 * \ref MUST be properly initialized, but \ref MAY be
161 * clobbered by the algorithm. This parameter \ref MAY
164 * \retval #VPX_CODEC_OK
165 * Bitstream is parsable and stream information updated
167 vpx_codec_err_t
vpx_codec_peek_stream_info(vpx_codec_iface_t
*iface
,
169 unsigned int data_sz
,
170 vpx_codec_stream_info_t
*si
);
173 /*!\brief Return information about the current stream.
175 * Returns information about the stream that has been parsed during decoding.
177 * \param[in] ctx Pointer to this instance's context
178 * \param[in,out] si Pointer to stream info to update. The size member
179 * \ref MUST be properly initialized, but \ref MAY be
180 * clobbered by the algorithm. This parameter \ref MAY
183 * \retval #VPX_CODEC_OK
184 * Bitstream is parsable and stream information updated
186 vpx_codec_err_t
vpx_codec_get_stream_info(vpx_codec_ctx_t
*ctx
,
187 vpx_codec_stream_info_t
*si
);
190 /*!\brief Decode data
192 * Processes a buffer of coded data. If the processing results in a new
193 * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
194 * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
195 * time stamp) order. Frames produced will always be in PTS (presentation
197 * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled,
198 * data and data_sz can contain a fragment of the encoded frame. Fragment
199 * \#n must contain at least partition \#n, but can also contain subsequent
200 * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
201 * be empty. When no more data is available, this function should be called
202 * with NULL as data and 0 as data_sz. The memory passed to this function
203 * must be available until the frame has been decoded.
205 * \param[in] ctx Pointer to this instance's context
206 * \param[in] data Pointer to this block of new coded data. If
207 * NULL, a VPX_CODEC_CB_PUT_FRAME event is posted
208 * for the previously decoded frame.
209 * \param[in] data_sz Size of the coded data, in bytes.
210 * \param[in] user_priv Application specific data to associate with
212 * \param[in] deadline Soft deadline the decoder should attempt to meet,
213 * in us. Set to zero for unlimited.
215 * \return Returns #VPX_CODEC_OK if the coded data was processed completely
216 * and future pictures can be decoded without error. Otherwise,
217 * see the descriptions of the other error codes in ::vpx_codec_err_t
218 * for recoverability capabilities.
220 vpx_codec_err_t
vpx_codec_decode(vpx_codec_ctx_t
*ctx
,
222 unsigned int data_sz
,
227 /*!\brief Decoded frames iterator
229 * Iterates over a list of the frames available for display. The iterator
230 * storage should be initialized to NULL to start the iteration. Iteration is
231 * complete when this function returns NULL.
233 * The list of available frames becomes valid upon completion of the
234 * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode.
236 * \param[in] ctx Pointer to this instance's context
237 * \param[in,out] iter Iterator storage, initialized to NULL
239 * \return Returns a pointer to an image, if one is ready for display. Frames
240 * produced will always be in PTS (presentation time stamp) order.
242 vpx_image_t
*vpx_codec_get_frame(vpx_codec_ctx_t
*ctx
,
243 vpx_codec_iter_t
*iter
);
246 /*!\defgroup cap_put_frame Frame-Based Decoding Functions
248 * The following functions are required to be implemented for all decoders
249 * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions
250 * for codecs that don't advertise this capability will result in an error
251 * code being returned, usually VPX_CODEC_ERROR
255 /*!\brief put frame callback prototype
257 * This callback is invoked by the decoder to notify the application of
258 * the availability of decoded image data.
260 typedef void (*vpx_codec_put_frame_cb_fn_t
)(void *user_priv
,
261 const vpx_image_t
*img
);
264 /*!\brief Register for notification of frame completion.
266 * Registers a given function to be called when a decoded frame is
269 * \param[in] ctx Pointer to this instance's context
270 * \param[in] cb Pointer to the callback function
271 * \param[in] user_priv User's private data
273 * \retval #VPX_CODEC_OK
274 * Callback successfully registered.
275 * \retval #VPX_CODEC_ERROR
276 * Decoder context not initialized, or algorithm not capable of
277 * posting slice completion.
279 vpx_codec_err_t
vpx_codec_register_put_frame_cb(vpx_codec_ctx_t
*ctx
,
280 vpx_codec_put_frame_cb_fn_t cb
,
284 /*!@} - end defgroup cap_put_frame */
286 /*!\defgroup cap_put_slice Slice-Based Decoding Functions
288 * The following functions are required to be implemented for all decoders
289 * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions
290 * for codecs that don't advertise this capability will result in an error
291 * code being returned, usually VPX_CODEC_ERROR
295 /*!\brief put slice callback prototype
297 * This callback is invoked by the decoder to notify the application of
298 * the availability of partially decoded image data. The
300 typedef void (*vpx_codec_put_slice_cb_fn_t
)(void *user_priv
,
301 const vpx_image_t
*img
,
302 const vpx_image_rect_t
*valid
,
303 const vpx_image_rect_t
*update
);
306 /*!\brief Register for notification of slice completion.
308 * Registers a given function to be called when a decoded slice is
311 * \param[in] ctx Pointer to this instance's context
312 * \param[in] cb Pointer to the callback function
313 * \param[in] user_priv User's private data
315 * \retval #VPX_CODEC_OK
316 * Callback successfully registered.
317 * \retval #VPX_CODEC_ERROR
318 * Decoder context not initialized, or algorithm not capable of
319 * posting slice completion.
321 vpx_codec_err_t
vpx_codec_register_put_slice_cb(vpx_codec_ctx_t
*ctx
,
322 vpx_codec_put_slice_cb_fn_t cb
,
326 /*!@} - end defgroup cap_put_slice*/
328 /*!\defgroup cap_external_frame_buffer External Frame Buffer Functions
330 * The following section is required to be implemented for all decoders
331 * that advertise the VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER capability.
332 * Calling this function for codecs that don't advertise this capability
333 * will result in an error code being returned, usually VPX_CODEC_ERROR.
336 * Currently this only works with VP9.
340 /*!\brief Pass in external frame buffers for the decoder to use.
342 * Registers functions to be called when libvpx needs a frame buffer
343 * to decode the current frame and a function to be called when libvpx does
344 * not internally reference the frame buffer. This set function must
345 * be called before the first call to decode or libvpx will assume the
346 * default behavior of allocating frame buffers internally.
348 * \param[in] ctx Pointer to this instance's context
349 * \param[in] cb_get Pointer to the get callback function
350 * \param[in] cb_release Pointer to the release callback function
351 * \param[in] cb_priv Callback's private data
353 * \retval #VPX_CODEC_OK
354 * External frame buffers will be used by libvpx.
355 * \retval #VPX_CODEC_INVALID_PARAM
356 * One or more of the callbacks were NULL.
357 * \retval #VPX_CODEC_ERROR
358 * Decoder context not initialized, or algorithm not capable of
359 * using external frame buffers.
362 * When decoding VP9, the application may be required to pass in at least
363 * #VP9_MAXIMUM_REF_BUFFERS + #VPX_MAXIMUM_WORK_BUFFERS external frame
366 vpx_codec_err_t
vpx_codec_set_frame_buffer_functions(
367 vpx_codec_ctx_t
*ctx
,
368 vpx_get_frame_buffer_cb_fn_t cb_get
,
369 vpx_release_frame_buffer_cb_fn_t cb_release
, void *cb_priv
);
371 /*!@} - end defgroup cap_external_frame_buffer */
373 /*!@} - end defgroup decoder*/
377 #endif // VPX_VPX_DECODER_H_