vpx_codec.h 15 KB

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