vpx_codec.h 15 KB

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