vpx_codec.h 15 KB

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