You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

376 lines
13KB

  1. /*
  2. * AVCodec public API
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_CODEC_H
  21. #define AVCODEC_CODEC_H
  22. #include <stdint.h>
  23. #include "libavutil/avutil.h"
  24. #include "libavutil/hwcontext.h"
  25. #include "libavutil/log.h"
  26. #include "libavutil/pixfmt.h"
  27. #include "libavutil/rational.h"
  28. #include "libavutil/samplefmt.h"
  29. #include "libavcodec/codec_id.h"
  30. #include "libavcodec/version_major.h"
  31. /**
  32. * @addtogroup lavc_core
  33. * @{
  34. */
  35. /**
  36. * Decoder can use draw_horiz_band callback.
  37. */
  38. #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
  39. /**
  40. * Codec uses get_buffer() or get_encode_buffer() for allocating buffers and
  41. * supports custom allocators.
  42. * If not set, it might not use get_buffer() or get_encode_buffer() at all, or
  43. * use operations that assume the buffer was allocated by
  44. * avcodec_default_get_buffer2 or avcodec_default_get_encode_buffer.
  45. */
  46. #define AV_CODEC_CAP_DR1 (1 << 1)
  47. /**
  48. * Encoder or decoder requires flushing with NULL input at the end in order to
  49. * give the complete and correct output.
  50. *
  51. * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
  52. * with NULL data. The user can still send NULL data to the public encode
  53. * or decode function, but libavcodec will not pass it along to the codec
  54. * unless this flag is set.
  55. *
  56. * Decoders:
  57. * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
  58. * avpkt->size=0 at the end to get the delayed data until the decoder no longer
  59. * returns frames.
  60. *
  61. * Encoders:
  62. * The encoder needs to be fed with NULL data at the end of encoding until the
  63. * encoder no longer returns data.
  64. *
  65. * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
  66. * flag also means that the encoder must set the pts and duration for
  67. * each output packet. If this flag is not set, the pts and duration will
  68. * be determined by libavcodec from the input frame.
  69. */
  70. #define AV_CODEC_CAP_DELAY (1 << 5)
  71. /**
  72. * Codec can be fed a final frame with a smaller size.
  73. * This can be used to prevent truncation of the last audio samples.
  74. */
  75. #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
  76. /**
  77. * Codec can output multiple frames per AVPacket
  78. * Normally demuxers return one frame at a time, demuxers which do not do
  79. * are connected to a parser to split what they return into proper frames.
  80. * This flag is reserved to the very rare category of codecs which have a
  81. * bitstream that cannot be split into frames without timeconsuming
  82. * operations like full decoding. Demuxers carrying such bitstreams thus
  83. * may return multiple frames in a packet. This has many disadvantages like
  84. * prohibiting stream copy in many cases thus it should only be considered
  85. * as a last resort.
  86. */
  87. #define AV_CODEC_CAP_SUBFRAMES (1 << 8)
  88. /**
  89. * Codec is experimental and is thus avoided in favor of non experimental
  90. * encoders
  91. */
  92. #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
  93. /**
  94. * Codec should fill in channel configuration and samplerate instead of container
  95. */
  96. #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
  97. /**
  98. * Codec supports frame-level multithreading.
  99. */
  100. #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
  101. /**
  102. * Codec supports slice-based (or partition-based) multithreading.
  103. */
  104. #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
  105. /**
  106. * Codec supports changed parameters at any point.
  107. */
  108. #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
  109. /**
  110. * Codec supports multithreading through a method other than slice- or
  111. * frame-level multithreading. Typically this marks wrappers around
  112. * multithreading-capable external libraries.
  113. */
  114. #define AV_CODEC_CAP_OTHER_THREADS (1 << 15)
  115. /**
  116. * Audio encoder supports receiving a different number of samples in each call.
  117. */
  118. #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
  119. /**
  120. * Decoder is not a preferred choice for probing.
  121. * This indicates that the decoder is not a good choice for probing.
  122. * It could for example be an expensive to spin up hardware decoder,
  123. * or it could simply not provide a lot of useful information about
  124. * the stream.
  125. * A decoder marked with this flag should only be used as last resort
  126. * choice for probing.
  127. */
  128. #define AV_CODEC_CAP_AVOID_PROBING (1 << 17)
  129. /**
  130. * Codec is backed by a hardware implementation. Typically used to
  131. * identify a non-hwaccel hardware decoder. For information about hwaccels, use
  132. * avcodec_get_hw_config() instead.
  133. */
  134. #define AV_CODEC_CAP_HARDWARE (1 << 18)
  135. /**
  136. * Codec is potentially backed by a hardware implementation, but not
  137. * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
  138. * implementation provides some sort of internal fallback.
  139. */
  140. #define AV_CODEC_CAP_HYBRID (1 << 19)
  141. /**
  142. * This encoder can reorder user opaque values from input AVFrames and return
  143. * them with corresponding output packets.
  144. * @see AV_CODEC_FLAG_COPY_OPAQUE
  145. */
  146. #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
  147. /**
  148. * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
  149. * not set, the encoder must be closed and reopened to ensure that no frames
  150. * remain pending.
  151. */
  152. #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
  153. /**
  154. * The encoder is able to output reconstructed frame data, i.e. raw frames that
  155. * would be produced by decoding the encoded bitstream.
  156. *
  157. * Reconstructed frame output is enabled by the AV_CODEC_FLAG_RECON_FRAME flag.
  158. */
  159. #define AV_CODEC_CAP_ENCODER_RECON_FRAME (1 << 22)
  160. /**
  161. * AVProfile.
  162. */
  163. typedef struct AVProfile {
  164. int profile;
  165. const char *name; ///< short name for the profile
  166. } AVProfile;
  167. /**
  168. * AVCodec.
  169. */
  170. typedef struct AVCodec {
  171. /**
  172. * Name of the codec implementation.
  173. * The name is globally unique among encoders and among decoders (but an
  174. * encoder and a decoder can share the same name).
  175. * This is the primary way to find a codec from the user perspective.
  176. */
  177. const char *name;
  178. /**
  179. * Descriptive name for the codec, meant to be more human readable than name.
  180. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  181. */
  182. const char *long_name;
  183. enum AVMediaType type;
  184. enum AVCodecID id;
  185. /**
  186. * Codec capabilities.
  187. * see AV_CODEC_CAP_*
  188. */
  189. int capabilities;
  190. uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
  191. const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
  192. const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
  193. const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
  194. const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
  195. #if FF_API_OLD_CHANNEL_LAYOUT
  196. /**
  197. * @deprecated use ch_layouts instead
  198. */
  199. attribute_deprecated
  200. const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
  201. #endif
  202. const AVClass *priv_class; ///< AVClass for the private context
  203. const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
  204. /**
  205. * Group name of the codec implementation.
  206. * This is a short symbolic name of the wrapper backing this codec. A
  207. * wrapper uses some kind of external implementation for the codec, such
  208. * as an external library, or a codec implementation provided by the OS or
  209. * the hardware.
  210. * If this field is NULL, this is a builtin, libavcodec native codec.
  211. * If non-NULL, this will be the suffix in AVCodec.name in most cases
  212. * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
  213. */
  214. const char *wrapper_name;
  215. /**
  216. * Array of supported channel layouts, terminated with a zeroed layout.
  217. */
  218. const AVChannelLayout *ch_layouts;
  219. } AVCodec;
  220. /**
  221. * Iterate over all registered codecs.
  222. *
  223. * @param opaque a pointer where libavcodec will store the iteration state. Must
  224. * point to NULL to start the iteration.
  225. *
  226. * @return the next registered codec or NULL when the iteration is
  227. * finished
  228. */
  229. const AVCodec *av_codec_iterate(void **opaque);
  230. /**
  231. * Find a registered decoder with a matching codec ID.
  232. *
  233. * @param id AVCodecID of the requested decoder
  234. * @return A decoder if one was found, NULL otherwise.
  235. */
  236. const AVCodec *avcodec_find_decoder(enum AVCodecID id);
  237. /**
  238. * Find a registered decoder with the specified name.
  239. *
  240. * @param name name of the requested decoder
  241. * @return A decoder if one was found, NULL otherwise.
  242. */
  243. const AVCodec *avcodec_find_decoder_by_name(const char *name);
  244. /**
  245. * Find a registered encoder with a matching codec ID.
  246. *
  247. * @param id AVCodecID of the requested encoder
  248. * @return An encoder if one was found, NULL otherwise.
  249. */
  250. const AVCodec *avcodec_find_encoder(enum AVCodecID id);
  251. /**
  252. * Find a registered encoder with the specified name.
  253. *
  254. * @param name name of the requested encoder
  255. * @return An encoder if one was found, NULL otherwise.
  256. */
  257. const AVCodec *avcodec_find_encoder_by_name(const char *name);
  258. /**
  259. * @return a non-zero number if codec is an encoder, zero otherwise
  260. */
  261. int av_codec_is_encoder(const AVCodec *codec);
  262. /**
  263. * @return a non-zero number if codec is a decoder, zero otherwise
  264. */
  265. int av_codec_is_decoder(const AVCodec *codec);
  266. /**
  267. * Return a name for the specified profile, if available.
  268. *
  269. * @param codec the codec that is searched for the given profile
  270. * @param profile the profile value for which a name is requested
  271. * @return A name for the profile if found, NULL otherwise.
  272. */
  273. const char *av_get_profile_name(const AVCodec *codec, int profile);
  274. enum {
  275. /**
  276. * The codec supports this format via the hw_device_ctx interface.
  277. *
  278. * When selecting this format, AVCodecContext.hw_device_ctx should
  279. * have been set to a device of the specified type before calling
  280. * avcodec_open2().
  281. */
  282. AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01,
  283. /**
  284. * The codec supports this format via the hw_frames_ctx interface.
  285. *
  286. * When selecting this format for a decoder,
  287. * AVCodecContext.hw_frames_ctx should be set to a suitable frames
  288. * context inside the get_format() callback. The frames context
  289. * must have been created on a device of the specified type.
  290. *
  291. * When selecting this format for an encoder,
  292. * AVCodecContext.hw_frames_ctx should be set to the context which
  293. * will be used for the input frames before calling avcodec_open2().
  294. */
  295. AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02,
  296. /**
  297. * The codec supports this format by some internal method.
  298. *
  299. * This format can be selected without any additional configuration -
  300. * no device or frames context is required.
  301. */
  302. AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 0x04,
  303. /**
  304. * The codec supports this format by some ad-hoc method.
  305. *
  306. * Additional settings and/or function calls are required. See the
  307. * codec-specific documentation for details. (Methods requiring
  308. * this sort of configuration are deprecated and others should be
  309. * used in preference.)
  310. */
  311. AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 0x08,
  312. };
  313. typedef struct AVCodecHWConfig {
  314. /**
  315. * For decoders, a hardware pixel format which that decoder may be
  316. * able to decode to if suitable hardware is available.
  317. *
  318. * For encoders, a pixel format which the encoder may be able to
  319. * accept. If set to AV_PIX_FMT_NONE, this applies to all pixel
  320. * formats supported by the codec.
  321. */
  322. enum AVPixelFormat pix_fmt;
  323. /**
  324. * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
  325. * setup methods which can be used with this configuration.
  326. */
  327. int methods;
  328. /**
  329. * The device type associated with the configuration.
  330. *
  331. * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
  332. * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
  333. */
  334. enum AVHWDeviceType device_type;
  335. } AVCodecHWConfig;
  336. /**
  337. * Retrieve supported hardware configurations for a codec.
  338. *
  339. * Values of index from zero to some maximum return the indexed configuration
  340. * descriptor; all other values return NULL. If the codec does not support
  341. * any hardware configurations then it will always return NULL.
  342. */
  343. const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index);
  344. /**
  345. * @}
  346. */
  347. #endif /* AVCODEC_CODEC_H */