blob: 62fd919756426a8ba881d376227ab784a468584b [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
John Koleszarc2140b82010-09-09 08:16:39 -04002 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
John Koleszar94c52e42010-06-18 12:39:21 -04004 * Use of this source code is governed by a BSD-style license
John Koleszar09202d82010-06-04 16:19:40 -04005 * 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 Koleszar94c52e42010-06-18 12:39:21 -04007 * in the file PATENTS. All contributing project authors may
John Koleszar09202d82010-06-04 16:19:40 -04008 * be found in the AUTHORS file in the root of the source tree.
John Koleszar0ea50ce2010-05-18 11:58:33 -04009 */
James Zern7386bde2013-12-15 18:26:15 -080010#ifndef VPX_VPX_DECODER_H_
11#define VPX_VPX_DECODER_H_
John Koleszar0ea50ce2010-05-18 11:58:33 -040012
13/*!\defgroup decoder Decoder Algorithm Interface
14 * \ingroup codec
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.
18 * @{
19 */
20
James Zernf42d52e2011-02-16 17:54:49 -080021/*!\file
John Koleszar0ea50ce2010-05-18 11:58:33 -040022 * \brief Describes the decoder algorithm interface to applications.
23 *
24 * This file describes the interface between an application and a
25 * video decoder algorithm.
26 *
27 */
28#ifdef __cplusplus
29extern "C" {
30#endif
31
Johanne883c742013-12-16 13:15:26 -080032#include "./vpx_codec.h"
Frank Galligana4f30a52014-02-06 17:13:08 -080033#include "./vpx_frame_buffer.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040034
John Koleszarc6b90392012-07-13 15:21:29 -070035 /*!\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 */
Frank Galligana4f30a52014-02-06 17:13:08 -080043#define VPX_DECODER_ABI_VERSION (3 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
John Koleszar0ea50ce2010-05-18 11:58:33 -040044
John Koleszarc6b90392012-07-13 15:21:29 -070045 /*! \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 */
John Koleszar0ea50ce2010-05-18 11:58:33 -040053#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 */
John Koleszar83b1d902012-11-05 12:37:14 -080056#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 */
John Koleszar0ea50ce2010-05-18 11:58:33 -040060
John Koleszarc6b90392012-07-13 15:21:29 -070061 /*! \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 */
Scott LaVarnway75f647f2012-10-03 10:07:13 -070068#define VPX_CODEC_CAP_FRAME_THREADING 0x200000 /**< Can support frame-based
69 multi-threading */
Frank Galligana4f30a52014-02-06 17:13:08 -080070#define VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000 /**< Can support external
71 frame buffers */
Scott LaVarnway75f647f2012-10-03 10:07:13 -070072
John Koleszar0ea50ce2010-05-18 11:58:33 -040073#define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
John Koleszar83b1d902012-11-05 12:37:14 -080074#define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded
75 frames */
76#define VPX_CODEC_USE_INPUT_FRAGMENTS 0x40000 /**< The input frame should be
John Koleszarc6b90392012-07-13 15:21:29 -070077 passed to the decoder one
John Koleszar83b1d902012-11-05 12:37:14 -080078 fragment at a time */
Scott LaVarnway75f647f2012-10-03 10:07:13 -070079#define VPX_CODEC_USE_FRAME_THREADING 0x80000 /**< Enable frame-based
80 multi-threading */
John Koleszar0ea50ce2010-05-18 11:58:33 -040081
John Koleszarc6b90392012-07-13 15:21:29 -070082 /*!\brief Stream properties
83 *
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.
87 */
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;
John Koleszar0ea50ce2010-05-18 11:58:33 -040094
John Koleszarc6b90392012-07-13 15:21:29 -070095 /* REQUIRED FUNCTIONS
96 *
97 * The following functions are required to be implemented for all decoders.
98 * They represent the base case functionality expected of all decoders.
99 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400100
101
John Koleszarc6b90392012-07-13 15:21:29 -0700102 /*!\brief Initialization Configurations
103 *
104 * This structure is used to pass init time configuration options to the
105 * decoder.
106 */
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 */
John Koleszarc6b90392012-07-13 15:21:29 -0700111 } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400112
113
John Koleszarc6b90392012-07-13 15:21:29 -0700114 /*!\brief Initialize a decoder instance
115 *
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.
120 *
John Koleszar83b1d902012-11-05 12:37:14 -0800121 * 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.
124 *
John Koleszarc6b90392012-07-13 15:21:29 -0700125 * \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.
135 */
136 vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
137 vpx_codec_iface_t *iface,
Dmitry Kovalev44609652014-08-25 14:02:53 -0700138 const vpx_codec_dec_cfg_t *cfg,
John Koleszarc6b90392012-07-13 15:21:29 -0700139 vpx_codec_flags_t flags,
140 int ver);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400141
John Koleszarc6b90392012-07-13 15:21:29 -0700142 /*!\brief Convenience macro for vpx_codec_dec_init_ver()
143 *
144 * Ensures the ABI version parameter is properly set.
145 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400146#define vpx_codec_dec_init(ctx, iface, cfg, flags) \
John Koleszarc6b90392012-07-13 15:21:29 -0700147 vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400148
149
John Koleszarc6b90392012-07-13 15:21:29 -0700150 /*!\brief Parse stream info from a buffer
151 *
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.
155 *
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
162 * be NULL.
163 *
164 * \retval #VPX_CODEC_OK
165 * Bitstream is parsable and stream information updated
166 */
167 vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
168 const uint8_t *data,
169 unsigned int data_sz,
170 vpx_codec_stream_info_t *si);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400171
172
John Koleszarc6b90392012-07-13 15:21:29 -0700173 /*!\brief Return information about the current stream.
174 *
175 * Returns information about the stream that has been parsed during decoding.
176 *
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
181 * be NULL.
182 *
183 * \retval #VPX_CODEC_OK
184 * Bitstream is parsable and stream information updated
185 */
186 vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
187 vpx_codec_stream_info_t *si);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400188
189
John Koleszarc6b90392012-07-13 15:21:29 -0700190 /*!\brief Decode data
191 *
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
196 * time stamp) order.
John Koleszar83b1d902012-11-05 12:37:14 -0800197 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700204 *
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
211 * this frame.
212 * \param[in] deadline Soft deadline the decoder should attempt to meet,
213 * in us. Set to zero for unlimited.
214 *
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.
219 */
220 vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
221 const uint8_t *data,
222 unsigned int data_sz,
223 void *user_priv,
224 long deadline);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400225
226
John Koleszarc6b90392012-07-13 15:21:29 -0700227 /*!\brief Decoded frames iterator
228 *
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.
232 *
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.
235 *
236 * \param[in] ctx Pointer to this instance's context
237 * \param[in,out] iter Iterator storage, initialized to NULL
238 *
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.
241 */
242 vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
243 vpx_codec_iter_t *iter);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400244
245
John Koleszarc6b90392012-07-13 15:21:29 -0700246 /*!\defgroup cap_put_frame Frame-Based Decoding Functions
247 *
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
252 * @{
253 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400254
John Koleszarc6b90392012-07-13 15:21:29 -0700255 /*!\brief put frame callback prototype
256 *
257 * This callback is invoked by the decoder to notify the application of
258 * the availability of decoded image data.
259 */
260 typedef void (*vpx_codec_put_frame_cb_fn_t)(void *user_priv,
261 const vpx_image_t *img);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400262
263
John Koleszarc6b90392012-07-13 15:21:29 -0700264 /*!\brief Register for notification of frame completion.
265 *
266 * Registers a given function to be called when a decoded frame is
267 * available.
268 *
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
272 *
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.
278 */
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,
281 void *user_priv);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400282
283
John Koleszarc6b90392012-07-13 15:21:29 -0700284 /*!@} - end defgroup cap_put_frame */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400285
John Koleszarc6b90392012-07-13 15:21:29 -0700286 /*!\defgroup cap_put_slice Slice-Based Decoding Functions
287 *
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
292 * @{
293 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400294
John Koleszarc6b90392012-07-13 15:21:29 -0700295 /*!\brief put slice callback prototype
296 *
297 * This callback is invoked by the decoder to notify the application of
298 * the availability of partially decoded image data. The
299 */
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);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400304
305
John Koleszarc6b90392012-07-13 15:21:29 -0700306 /*!\brief Register for notification of slice completion.
307 *
308 * Registers a given function to be called when a decoded slice is
309 * available.
310 *
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
314 *
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.
320 */
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,
323 void *user_priv);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400324
325
John Koleszarc6b90392012-07-13 15:21:29 -0700326 /*!@} - end defgroup cap_put_slice*/
John Koleszar0ea50ce2010-05-18 11:58:33 -0400327
Frank Galligana4f30a52014-02-06 17:13:08 -0800328 /*!\defgroup cap_external_frame_buffer External Frame Buffer Functions
329 *
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.
334 *
335 * \note
336 * Currently this only works with VP9.
337 * @{
338 */
339
340 /*!\brief Pass in external frame buffers for the decoder to use.
341 *
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.
347 *
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
352 *
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.
360 *
361 * \note
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
364 * buffers.
365 */
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);
370
371 /*!@} - end defgroup cap_external_frame_buffer */
372
John Koleszarc6b90392012-07-13 15:21:29 -0700373 /*!@} - end defgroup decoder*/
John Koleszar0ea50ce2010-05-18 11:58:33 -0400374#ifdef __cplusplus
375}
376#endif
James Zern7386bde2013-12-15 18:26:15 -0800377#endif // VPX_VPX_DECODER_H_
Adrian Grangef58eca92013-10-24 15:11:36 -0700378