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.
11 /*!\defgroup codec Common Algorithm Interface
12 * This abstraction allows applications to easily support multiple video
13 * formats with minimal code duplication. This section describes the interface
14 * common to all codecs (both encoders and decoders).
19 * \brief Describes the codec algorithm interface to applications.
21 * This file describes the interface between an application and a
22 * video codec algorithm.
24 * An application instantiates a specific codec instance by using
25 * vpx_codec_dec_init() or vpx_codec_enc_init() and a pointer to the
26 * algorithm's interface structure:
29 * extern vpx_codec_iface_t my_codec;
31 * vpx_codec_ctx_t algo;
33 * vpx_codec_dec_cfg_t cfg = { threads, 0, 0 };
34 * res = vpx_codec_dec_init(&algo, &my_codec, &cfg, 0);
38 * Once initialized, the instance is manged using other functions from
39 * the vpx_codec_* family.
41 #ifndef VPX_VPX_VPX_CODEC_H_
42 #define VPX_VPX_VPX_CODEC_H_
48 #include "./vpx_image.h"
49 #include "./vpx_integer.h"
51 /*!\brief Decorator indicating a function is deprecated */
52 #ifndef VPX_DEPRECATED
53 #if defined(__GNUC__) && __GNUC__
54 #define VPX_DEPRECATED __attribute__((deprecated))
55 #elif defined(_MSC_VER)
56 #define VPX_DEPRECATED
58 #define VPX_DEPRECATED
60 #endif /* VPX_DEPRECATED */
62 #ifndef VPX_DECLSPEC_DEPRECATED
63 #if defined(__GNUC__) && __GNUC__
64 #define VPX_DECLSPEC_DEPRECATED /**< \copydoc #VPX_DEPRECATED */
65 #elif defined(_MSC_VER)
66 /*!\brief \copydoc #VPX_DEPRECATED */
67 #define VPX_DECLSPEC_DEPRECATED __declspec(deprecated)
69 #define VPX_DECLSPEC_DEPRECATED /**< \copydoc #VPX_DEPRECATED */
71 #endif /* VPX_DECLSPEC_DEPRECATED */
73 /*!\brief Decorator indicating a function is potentially unused */
75 #if defined(__GNUC__) || defined(__clang__)
76 #define VPX_UNUSED __attribute__((unused))
80 #endif /* VPX_UNUSED */
82 /*!\brief Current ABI version number
85 * If this file is altered in any way that changes the ABI, this value
86 * must be bumped. Examples include, but are not limited to, changing
87 * types, removing or reassigning enums, adding/removing/rearranging
88 * fields to structures
90 #define VPX_CODEC_ABI_VERSION (4 + VPX_IMAGE_ABI_VERSION) /**<\hideinitializer*/
92 /*!\brief Algorithm return codes */
94 /*!\brief Operation completed without error */
97 /*!\brief Unspecified error */
100 /*!\brief Memory operation failed */
103 /*!\brief ABI version mismatch */
104 VPX_CODEC_ABI_MISMATCH,
106 /*!\brief Algorithm does not have required capability */
109 /*!\brief The given bitstream is not supported.
111 * The bitstream was unable to be parsed at the highest level. The decoder
112 * is unable to proceed. This error \ref SHOULD be treated as fatal to the
114 VPX_CODEC_UNSUP_BITSTREAM,
116 /*!\brief Encoded bitstream uses an unsupported feature
118 * The decoder does not implement a feature required by the encoder. This
119 * return code should only be used for features that prevent future
120 * pictures from being properly decoded. This error \ref MAY be treated as
121 * fatal to the stream or \ref MAY be treated as fatal to the current GOP.
123 VPX_CODEC_UNSUP_FEATURE,
125 /*!\brief The coded data for this stream is corrupt or incomplete
127 * There was a problem decoding the current frame. This return code
128 * should only be used for failures that prevent future pictures from
129 * being properly decoded. This error \ref MAY be treated as fatal to the
130 * stream or \ref MAY be treated as fatal to the current GOP. If decoding
131 * is continued for the current GOP, artifacts may be present.
133 VPX_CODEC_CORRUPT_FRAME,
135 /*!\brief An application-supplied parameter is not valid.
138 VPX_CODEC_INVALID_PARAM,
140 /*!\brief An iterator reached the end of list.
147 /*! \brief Codec capabilities bitfield
149 * Each codec advertises the capabilities it supports as part of its
150 * ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces
151 * or functionality, and are not required to be supported.
153 * The available flags are specified by VPX_CODEC_CAP_* defines.
155 typedef long vpx_codec_caps_t;
156 #define VPX_CODEC_CAP_DECODER 0x1 /**< Is a decoder */
157 #define VPX_CODEC_CAP_ENCODER 0x2 /**< Is an encoder */
159 /*! Can support images at greater than 8 bitdepth.
161 #define VPX_CODEC_CAP_HIGHBITDEPTH 0x4
163 /*! \brief Initialization-time Feature Enabling
165 * Certain codec features must be known at initialization time, to allow for
166 * proper memory allocation.
168 * The available flags are specified by VPX_CODEC_USE_* defines.
170 typedef long vpx_codec_flags_t;
172 /*!\brief Codec interface structure.
174 * Contains function pointers and other data private to the codec
175 * implementation. This structure is opaque to the application.
177 typedef const struct vpx_codec_iface vpx_codec_iface_t;
179 /*!\brief Codec private data structure.
181 * Contains data private to the codec implementation. This structure is opaque
182 * to the application.
184 typedef struct vpx_codec_priv vpx_codec_priv_t;
188 * Opaque storage used for iterating over lists.
190 typedef const void *vpx_codec_iter_t;
192 /*!\brief Codec context structure
194 * All codecs \ref MUST support this context structure fully. In general,
195 * this data should be considered private to the codec algorithm, and
196 * not be manipulated or examined by the calling application. Applications
197 * may reference the 'name' member to get a printable description of the
200 typedef struct vpx_codec_ctx {
201 const char *name; /**< Printable interface name */
202 vpx_codec_iface_t *iface; /**< Interface pointers */
203 vpx_codec_err_t err; /**< Last returned error */
204 const char *err_detail; /**< Detailed info, if available */
205 vpx_codec_flags_t init_flags; /**< Flags passed at init time */
207 /**< Decoder Configuration Pointer */
208 const struct vpx_codec_dec_cfg *dec;
209 /**< Encoder Configuration Pointer */
210 const struct vpx_codec_enc_cfg *enc;
212 } config; /**< Configuration pointer aliasing union */
213 vpx_codec_priv_t *priv; /**< Algorithm private storage */
216 /*!\brief Bit depth for codec
218 * This enumeration determines the bit depth of the codec.
220 typedef enum vpx_bit_depth {
221 VPX_BITS_8 = 8, /**< 8 bits */
222 VPX_BITS_10 = 10, /**< 10 bits */
223 VPX_BITS_12 = 12, /**< 12 bits */
227 * Library Version Number Interface
229 * For example, see the following sample return values:
230 * vpx_codec_version() (1<<16 | 2<<8 | 3)
231 * vpx_codec_version_str() "v1.2.3-rc1-16-gec6a1ba"
232 * vpx_codec_version_extra_str() "rc1-16-gec6a1ba"
235 /*!\brief Return the version information (as an integer)
237 * Returns a packed encoding of the library version number. This will only
239 * the major.minor.patch component of the version number. Note that this encoded
240 * value should be accessed through the macros provided, as the encoding may
245 int vpx_codec_version(void);
246 #define VPX_VERSION_MAJOR(v) \
247 (((v) >> 16) & 0xff) /**< extract major from packed version */
248 #define VPX_VERSION_MINOR(v) \
249 (((v) >> 8) & 0xff) /**< extract minor from packed version */
250 #define VPX_VERSION_PATCH(v) \
251 (((v) >> 0) & 0xff) /**< extract patch from packed version */
253 /*!\brief Return the version major number */
254 #define vpx_codec_version_major() ((vpx_codec_version() >> 16) & 0xff)
256 /*!\brief Return the version minor number */
257 #define vpx_codec_version_minor() ((vpx_codec_version() >> 8) & 0xff)
259 /*!\brief Return the version patch number */
260 #define vpx_codec_version_patch() ((vpx_codec_version() >> 0) & 0xff)
262 /*!\brief Return the version information (as a string)
264 * Returns a printable string containing the full library version number. This
266 * contain additional text following the three digit version number, as to
268 * release candidates, prerelease versions, etc.
271 const char *vpx_codec_version_str(void);
273 /*!\brief Return the version information (as a string)
275 * Returns a printable "extra string". This is the component of the string
277 * by vpx_codec_version_str() following the three digit version number.
280 const char *vpx_codec_version_extra_str(void);
282 /*!\brief Return the build configuration
284 * Returns a printable string containing an encoded version of the build
285 * configuration. This may be useful to vpx support.
288 const char *vpx_codec_build_config(void);
290 /*!\brief Return the name for a given interface
292 * Returns a human readable string for name of the given codec interface.
294 * \param[in] iface Interface pointer
297 const char *vpx_codec_iface_name(vpx_codec_iface_t *iface);
299 /*!\brief Convert error number to printable string
301 * Returns a human readable string for the last error returned by the
302 * algorithm. The returned error will be one line and will not contain
303 * any newline characters.
306 * \param[in] err Error number.
309 const char *vpx_codec_err_to_string(vpx_codec_err_t err);
311 /*!\brief Retrieve error synopsis for codec context
313 * Returns a human readable string for the last error returned by the
314 * algorithm. The returned error will be one line and will not contain
315 * any newline characters.
318 * \param[in] ctx Pointer to this instance's context.
321 const char *vpx_codec_error(vpx_codec_ctx_t *ctx);
323 /*!\brief Retrieve detailed error information for codec context
325 * Returns a human readable string providing detailed information about
328 * \param[in] ctx Pointer to this instance's context.
331 * No detailed information is available.
333 const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx);
335 /* REQUIRED FUNCTIONS
337 * The following functions are required to be implemented for all codecs.
338 * They represent the base case functionality expected of all codecs.
341 /*!\brief Destroy a codec instance
343 * Destroys a codec context, freeing any associated memory buffers.
345 * \param[in] ctx Pointer to this instance's context
347 * \retval #VPX_CODEC_OK
348 * The codec algorithm initialized.
349 * \retval #VPX_CODEC_MEM_ERROR
350 * Memory allocation failed.
352 vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx);
354 /*!\brief Get the capabilities of an algorithm.
356 * Retrieves the capabilities bitfield from the algorithm's interface.
358 * \param[in] iface Pointer to the algorithm interface
361 vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface);
363 /*!\brief Control algorithm
365 * This function is used to exchange algorithm specific data with the codec
366 * instance. This can be used to implement features specific to a particular
369 * This wrapper function dispatches the request to the helper function
370 * associated with the given ctrl_id. It tries to call this function
371 * transparently, but will return #VPX_CODEC_ERROR if the request could not
374 * Note that this function should not be used directly. Call the
375 * #vpx_codec_control wrapper macro instead.
377 * \param[in] ctx Pointer to this instance's context
378 * \param[in] ctrl_id Algorithm specific control identifier
380 * \retval #VPX_CODEC_OK
381 * The control request was processed.
382 * \retval #VPX_CODEC_ERROR
383 * The control request was not processed.
384 * \retval #VPX_CODEC_INVALID_PARAM
385 * The data was not valid.
387 vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx, int ctrl_id, ...);
388 #if defined(VPX_DISABLE_CTRL_TYPECHECKS) && VPX_DISABLE_CTRL_TYPECHECKS
389 #define vpx_codec_control(ctx, id, data) vpx_codec_control_(ctx, id, data)
390 #define VPX_CTRL_USE_TYPE(id, typ)
391 #define VPX_CTRL_USE_TYPE_DEPRECATED(id, typ)
392 #define VPX_CTRL_VOID(id, typ)
395 /*!\brief vpx_codec_control wrapper macro
397 * This macro allows for type safe conversions across the variadic parameter
398 * to vpx_codec_control_().
401 * It works by dispatching the call to the control function through a wrapper
402 * function named with the id parameter.
404 #define vpx_codec_control(ctx, id, data) \
405 vpx_codec_control_##id(ctx, id, data) /**<\hideinitializer*/
407 /*!\brief vpx_codec_control type definition macro
409 * This macro allows for type safe conversions across the variadic parameter
410 * to vpx_codec_control_(). It defines the type of the argument for a given
411 * control identifier.
414 * It defines a static function with
415 * the correctly typed arguments as a wrapper to the type-unsafe internal
418 #define VPX_CTRL_USE_TYPE(id, typ) \
419 static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *, int, typ) \
422 static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *ctx, \
423 int ctrl_id, typ data) { \
424 return vpx_codec_control_(ctx, ctrl_id, data); \
425 } /**<\hideinitializer*/
427 /*!\brief vpx_codec_control deprecated type definition macro
429 * Like #VPX_CTRL_USE_TYPE, but indicates that the specified control is
430 * deprecated and should not be used. Consult the documentation for your
431 * codec for more information.
434 * It defines a static function with the correctly typed arguments as a
435 * wrapper to the type-unsafe internal function.
437 #define VPX_CTRL_USE_TYPE_DEPRECATED(id, typ) \
438 VPX_DECLSPEC_DEPRECATED static vpx_codec_err_t vpx_codec_control_##id( \
439 vpx_codec_ctx_t *, int, typ) VPX_DEPRECATED VPX_UNUSED; \
441 VPX_DECLSPEC_DEPRECATED static vpx_codec_err_t vpx_codec_control_##id( \
442 vpx_codec_ctx_t *ctx, int ctrl_id, typ data) { \
443 return vpx_codec_control_(ctx, ctrl_id, data); \
444 } /**<\hideinitializer*/
446 /*!\brief vpx_codec_control void type definition macro
448 * This macro allows for type safe conversions across the variadic parameter
449 * to vpx_codec_control_(). It indicates that a given control identifier takes
453 * It defines a static function without a data argument as a wrapper to the
454 * type-unsafe internal function.
456 #define VPX_CTRL_VOID(id) \
457 static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *, int) \
460 static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *ctx, \
462 return vpx_codec_control_(ctx, ctrl_id); \
463 } /**<\hideinitializer*/
467 /*!@} - end defgroup codec*/
471 #endif // VPX_VPX_VPX_CODEC_H_