]> granicus.if.org Git - libvpx/blob - vpx/vpx_codec.h
Merge "vpx_idct32x32_34_add_sse2: rm unneeded transposes"
[libvpx] / vpx / vpx_codec.h
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 /*!\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).
15  * @{
16  */
17
18 /*!\file
19  * \brief Describes the codec algorithm interface to applications.
20  *
21  * This file describes the interface between an application and a
22  * video codec algorithm.
23  *
24  * An application instantiates a specific codec instance by using
25  * vpx_codec_init() and a pointer to the algorithm's interface structure:
26  *     <pre>
27  *     my_app.c:
28  *       extern vpx_codec_iface_t my_codec;
29  *       {
30  *           vpx_codec_ctx_t algo;
31  *           res = vpx_codec_init(&algo, &my_codec);
32  *       }
33  *     </pre>
34  *
35  * Once initialized, the instance is manged using other functions from
36  * the vpx_codec_* family.
37  */
38 #ifndef VPX_VPX_CODEC_H_
39 #define VPX_VPX_CODEC_H_
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 #include "./vpx_integer.h"
46 #include "./vpx_image.h"
47
48 /*!\brief Decorator indicating a function is deprecated */
49 #ifndef DEPRECATED
50 #if defined(__GNUC__) && __GNUC__
51 #define DEPRECATED __attribute__((deprecated))
52 #elif defined(_MSC_VER)
53 #define DEPRECATED
54 #else
55 #define DEPRECATED
56 #endif
57 #endif /* DEPRECATED */
58
59 #ifndef DECLSPEC_DEPRECATED
60 #if defined(__GNUC__) && __GNUC__
61 #define DECLSPEC_DEPRECATED /**< \copydoc #DEPRECATED */
62 #elif defined(_MSC_VER)
63 /*!\brief \copydoc #DEPRECATED */
64 #define DECLSPEC_DEPRECATED __declspec(deprecated)
65 #else
66 #define DECLSPEC_DEPRECATED /**< \copydoc #DEPRECATED */
67 #endif
68 #endif /* DECLSPEC_DEPRECATED */
69
70 /*!\brief Decorator indicating a function is potentially unused */
71 #ifdef UNUSED
72 #elif defined(__GNUC__) || defined(__clang__)
73 #define UNUSED __attribute__((unused))
74 #else
75 #define UNUSED
76 #endif
77
78 /*!\brief Current ABI version number
79  *
80  * \internal
81  * If this file is altered in any way that changes the ABI, this value
82  * must be bumped.  Examples include, but are not limited to, changing
83  * types, removing or reassigning enums, adding/removing/rearranging
84  * fields to structures
85  */
86 #define VPX_CODEC_ABI_VERSION (3 + VPX_IMAGE_ABI_VERSION) /**<\hideinitializer*/
87
88 /*!\brief Algorithm return codes */
89 typedef enum {
90   /*!\brief Operation completed without error */
91   VPX_CODEC_OK,
92
93   /*!\brief Unspecified error */
94   VPX_CODEC_ERROR,
95
96   /*!\brief Memory operation failed */
97   VPX_CODEC_MEM_ERROR,
98
99   /*!\brief ABI version mismatch */
100   VPX_CODEC_ABI_MISMATCH,
101
102   /*!\brief Algorithm does not have required capability */
103   VPX_CODEC_INCAPABLE,
104
105   /*!\brief The given bitstream is not supported.
106    *
107    * The bitstream was unable to be parsed at the highest level. The decoder
108    * is unable to proceed. This error \ref SHOULD be treated as fatal to the
109    * stream. */
110   VPX_CODEC_UNSUP_BITSTREAM,
111
112   /*!\brief Encoded bitstream uses an unsupported feature
113    *
114    * The decoder does not implement a feature required by the encoder. This
115    * return code should only be used for features that prevent future
116    * pictures from being properly decoded. This error \ref MAY be treated as
117    * fatal to the stream or \ref MAY be treated as fatal to the current GOP.
118    */
119   VPX_CODEC_UNSUP_FEATURE,
120
121   /*!\brief The coded data for this stream is corrupt or incomplete
122    *
123    * There was a problem decoding the current frame.  This return code
124    * should only be used for failures that prevent future pictures from
125    * being properly decoded. This error \ref MAY be treated as fatal to the
126    * stream or \ref MAY be treated as fatal to the current GOP. If decoding
127    * is continued for the current GOP, artifacts may be present.
128    */
129   VPX_CODEC_CORRUPT_FRAME,
130
131   /*!\brief An application-supplied parameter is not valid.
132    *
133    */
134   VPX_CODEC_INVALID_PARAM,
135
136   /*!\brief An iterator reached the end of list.
137    *
138    */
139   VPX_CODEC_LIST_END
140
141 } vpx_codec_err_t;
142
143 /*! \brief Codec capabilities bitfield
144  *
145  *  Each codec advertises the capabilities it supports as part of its
146  *  ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces
147  *  or functionality, and are not required to be supported.
148  *
149  *  The available flags are specified by VPX_CODEC_CAP_* defines.
150  */
151 typedef long vpx_codec_caps_t;
152 #define VPX_CODEC_CAP_DECODER 0x1 /**< Is a decoder */
153 #define VPX_CODEC_CAP_ENCODER 0x2 /**< Is an encoder */
154
155 /*! \brief Initialization-time Feature Enabling
156  *
157  *  Certain codec features must be known at initialization time, to allow for
158  *  proper memory allocation.
159  *
160  *  The available flags are specified by VPX_CODEC_USE_* defines.
161  */
162 typedef long vpx_codec_flags_t;
163
164 /*!\brief Codec interface structure.
165  *
166  * Contains function pointers and other data private to the codec
167  * implementation. This structure is opaque to the application.
168  */
169 typedef const struct vpx_codec_iface vpx_codec_iface_t;
170
171 /*!\brief Codec private data structure.
172  *
173  * Contains data private to the codec implementation. This structure is opaque
174  * to the application.
175  */
176 typedef struct vpx_codec_priv vpx_codec_priv_t;
177
178 /*!\brief Iterator
179  *
180  * Opaque storage used for iterating over lists.
181  */
182 typedef const void *vpx_codec_iter_t;
183
184 /*!\brief Codec context structure
185  *
186  * All codecs \ref MUST support this context structure fully. In general,
187  * this data should be considered private to the codec algorithm, and
188  * not be manipulated or examined by the calling application. Applications
189  * may reference the 'name' member to get a printable description of the
190  * algorithm.
191  */
192 typedef struct vpx_codec_ctx {
193   const char *name;             /**< Printable interface name */
194   vpx_codec_iface_t *iface;     /**< Interface pointers */
195   vpx_codec_err_t err;          /**< Last returned error */
196   const char *err_detail;       /**< Detailed info, if available */
197   vpx_codec_flags_t init_flags; /**< Flags passed at init time */
198   union {
199     /**< Decoder Configuration Pointer */
200     const struct vpx_codec_dec_cfg *dec;
201     /**< Encoder Configuration Pointer */
202     const struct vpx_codec_enc_cfg *enc;
203     const void *raw;
204   } config;               /**< Configuration pointer aliasing union */
205   vpx_codec_priv_t *priv; /**< Algorithm private storage */
206 } vpx_codec_ctx_t;
207
208 /*!\brief Bit depth for codec
209  * *
210  * This enumeration determines the bit depth of the codec.
211  */
212 typedef enum vpx_bit_depth {
213   VPX_BITS_8 = 8,   /**<  8 bits */
214   VPX_BITS_10 = 10, /**< 10 bits */
215   VPX_BITS_12 = 12, /**< 12 bits */
216 } vpx_bit_depth_t;
217
218 /*
219  * Library Version Number Interface
220  *
221  * For example, see the following sample return values:
222  *     vpx_codec_version()           (1<<16 | 2<<8 | 3)
223  *     vpx_codec_version_str()       "v1.2.3-rc1-16-gec6a1ba"
224  *     vpx_codec_version_extra_str() "rc1-16-gec6a1ba"
225  */
226
227 /*!\brief Return the version information (as an integer)
228  *
229  * Returns a packed encoding of the library version number. This will only
230  * include
231  * the major.minor.patch component of the version number. Note that this encoded
232  * value should be accessed through the macros provided, as the encoding may
233  * change
234  * in the future.
235  *
236  */
237 int vpx_codec_version(void);
238 #define VPX_VERSION_MAJOR(v) \
239   ((v >> 16) & 0xff) /**< extract major from packed version */
240 #define VPX_VERSION_MINOR(v) \
241   ((v >> 8) & 0xff) /**< extract minor from packed version */
242 #define VPX_VERSION_PATCH(v) \
243   ((v >> 0) & 0xff) /**< extract patch from packed version */
244
245 /*!\brief Return the version major number */
246 #define vpx_codec_version_major() ((vpx_codec_version() >> 16) & 0xff)
247
248 /*!\brief Return the version minor number */
249 #define vpx_codec_version_minor() ((vpx_codec_version() >> 8) & 0xff)
250
251 /*!\brief Return the version patch number */
252 #define vpx_codec_version_patch() ((vpx_codec_version() >> 0) & 0xff)
253
254 /*!\brief Return the version information (as a string)
255  *
256  * Returns a printable string containing the full library version number. This
257  * may
258  * contain additional text following the three digit version number, as to
259  * indicate
260  * release candidates, prerelease versions, etc.
261  *
262  */
263 const char *vpx_codec_version_str(void);
264
265 /*!\brief Return the version information (as a string)
266  *
267  * Returns a printable "extra string". This is the component of the string
268  * returned
269  * by vpx_codec_version_str() following the three digit version number.
270  *
271  */
272 const char *vpx_codec_version_extra_str(void);
273
274 /*!\brief Return the build configuration
275  *
276  * Returns a printable string containing an encoded version of the build
277  * configuration. This may be useful to vpx support.
278  *
279  */
280 const char *vpx_codec_build_config(void);
281
282 /*!\brief Return the name for a given interface
283  *
284  * Returns a human readable string for name of the given codec interface.
285  *
286  * \param[in]    iface     Interface pointer
287  *
288  */
289 const char *vpx_codec_iface_name(vpx_codec_iface_t *iface);
290
291 /*!\brief Convert error number to printable string
292  *
293  * Returns a human readable string for the last error returned by the
294  * algorithm. The returned error will be one line and will not contain
295  * any newline characters.
296  *
297  *
298  * \param[in]    err     Error number.
299  *
300  */
301 const char *vpx_codec_err_to_string(vpx_codec_err_t err);
302
303 /*!\brief Retrieve error synopsis for codec context
304  *
305  * Returns a human readable string for the last error returned by the
306  * algorithm. The returned error will be one line and will not contain
307  * any newline characters.
308  *
309  *
310  * \param[in]    ctx     Pointer to this instance's context.
311  *
312  */
313 const char *vpx_codec_error(vpx_codec_ctx_t *ctx);
314
315 /*!\brief Retrieve detailed error information for codec context
316  *
317  * Returns a human readable string providing detailed information about
318  * the last error.
319  *
320  * \param[in]    ctx     Pointer to this instance's context.
321  *
322  * \retval NULL
323  *     No detailed information is available.
324  */
325 const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx);
326
327 /* REQUIRED FUNCTIONS
328  *
329  * The following functions are required to be implemented for all codecs.
330  * They represent the base case functionality expected of all codecs.
331  */
332
333 /*!\brief Destroy a codec instance
334  *
335  * Destroys a codec context, freeing any associated memory buffers.
336  *
337  * \param[in] ctx   Pointer to this instance's context
338  *
339  * \retval #VPX_CODEC_OK
340  *     The codec algorithm initialized.
341  * \retval #VPX_CODEC_MEM_ERROR
342  *     Memory allocation failed.
343  */
344 vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx);
345
346 /*!\brief Get the capabilities of an algorithm.
347  *
348  * Retrieves the capabilities bitfield from the algorithm's interface.
349  *
350  * \param[in] iface   Pointer to the algorithm interface
351  *
352  */
353 vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface);
354
355 /*!\brief Control algorithm
356  *
357  * This function is used to exchange algorithm specific data with the codec
358  * instance. This can be used to implement features specific to a particular
359  * algorithm.
360  *
361  * This wrapper function dispatches the request to the helper function
362  * associated with the given ctrl_id. It tries to call this function
363  * transparently, but will return #VPX_CODEC_ERROR if the request could not
364  * be dispatched.
365  *
366  * Note that this function should not be used directly. Call the
367  * #vpx_codec_control wrapper macro instead.
368  *
369  * \param[in]     ctx              Pointer to this instance's context
370  * \param[in]     ctrl_id          Algorithm specific control identifier
371  *
372  * \retval #VPX_CODEC_OK
373  *     The control request was processed.
374  * \retval #VPX_CODEC_ERROR
375  *     The control request was not processed.
376  * \retval #VPX_CODEC_INVALID_PARAM
377  *     The data was not valid.
378  */
379 vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx, int ctrl_id, ...);
380 #if defined(VPX_DISABLE_CTRL_TYPECHECKS) && VPX_DISABLE_CTRL_TYPECHECKS
381 #define vpx_codec_control(ctx, id, data) vpx_codec_control_(ctx, id, data)
382 #define VPX_CTRL_USE_TYPE(id, typ)
383 #define VPX_CTRL_USE_TYPE_DEPRECATED(id, typ)
384 #define VPX_CTRL_VOID(id, typ)
385
386 #else
387 /*!\brief vpx_codec_control wrapper macro
388  *
389  * This macro allows for type safe conversions across the variadic parameter
390  * to vpx_codec_control_().
391  *
392  * \internal
393  * It works by dispatching the call to the control function through a wrapper
394  * function named with the id parameter.
395  */
396 #define vpx_codec_control(ctx, id, data) \
397   vpx_codec_control_##id(ctx, id, data) /**<\hideinitializer*/
398
399 /*!\brief vpx_codec_control type definition macro
400  *
401  * This macro allows for type safe conversions across the variadic parameter
402  * to vpx_codec_control_(). It defines the type of the argument for a given
403  * control identifier.
404  *
405  * \internal
406  * It defines a static function with
407  * the correctly typed arguments as a wrapper to the type-unsafe internal
408  * function.
409  */
410 #define VPX_CTRL_USE_TYPE(id, typ)                                           \
411   static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *, int, typ) \
412       UNUSED;                                                                \
413                                                                              \
414   static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *ctx,        \
415                                                 int ctrl_id, typ data) {     \
416     return vpx_codec_control_(ctx, ctrl_id, data);                           \
417   } /**<\hideinitializer*/
418
419 /*!\brief vpx_codec_control deprecated type definition macro
420  *
421  * Like #VPX_CTRL_USE_TYPE, but indicates that the specified control is
422  * deprecated and should not be used. Consult the documentation for your
423  * codec for more information.
424  *
425  * \internal
426  * It defines a static function with the correctly typed arguments as a
427  * wrapper to the type-unsafe internal function.
428  */
429 #define VPX_CTRL_USE_TYPE_DEPRECATED(id, typ)                        \
430   DECLSPEC_DEPRECATED static vpx_codec_err_t vpx_codec_control_##id( \
431       vpx_codec_ctx_t *, int, typ) DEPRECATED UNUSED;                \
432                                                                      \
433   DECLSPEC_DEPRECATED static vpx_codec_err_t vpx_codec_control_##id( \
434       vpx_codec_ctx_t *ctx, int ctrl_id, typ data) {                 \
435     return vpx_codec_control_(ctx, ctrl_id, data);                   \
436   } /**<\hideinitializer*/
437
438 /*!\brief vpx_codec_control void type definition macro
439  *
440  * This macro allows for type safe conversions across the variadic parameter
441  * to vpx_codec_control_(). It indicates that a given control identifier takes
442  * no argument.
443  *
444  * \internal
445  * It defines a static function without a data argument as a wrapper to the
446  * type-unsafe internal function.
447  */
448 #define VPX_CTRL_VOID(id)                                               \
449   static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *, int) \
450       UNUSED;                                                           \
451                                                                         \
452   static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *ctx,   \
453                                                 int ctrl_id) {          \
454     return vpx_codec_control_(ctx, ctrl_id);                            \
455   } /**<\hideinitializer*/
456
457 #endif
458
459 /*!@} - end defgroup codec*/
460 #ifdef __cplusplus
461 }
462 #endif
463 #endif  // VPX_VPX_CODEC_H_