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.

5179 lines
176KB

  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_AVCODEC_H
  21. #define AVCODEC_AVCODEC_H
  22. /**
  23. * @file
  24. * @ingroup libavc
  25. * Libavcodec external API header
  26. */
  27. #include <errno.h>
  28. #include "libavutil/samplefmt.h"
  29. #include "libavutil/attributes.h"
  30. #include "libavutil/avutil.h"
  31. #include "libavutil/buffer.h"
  32. #include "libavutil/cpu.h"
  33. #include "libavutil/dict.h"
  34. #include "libavutil/frame.h"
  35. #include "libavutil/hwcontext.h"
  36. #include "libavutil/log.h"
  37. #include "libavutil/pixfmt.h"
  38. #include "libavutil/rational.h"
  39. #include "version.h"
  40. /**
  41. * @defgroup libavc Encoding/Decoding Library
  42. * @{
  43. *
  44. * @defgroup lavc_decoding Decoding
  45. * @{
  46. * @}
  47. *
  48. * @defgroup lavc_encoding Encoding
  49. * @{
  50. * @}
  51. *
  52. * @defgroup lavc_codec Codecs
  53. * @{
  54. * @defgroup lavc_codec_native Native Codecs
  55. * @{
  56. * @}
  57. * @defgroup lavc_codec_wrappers External library wrappers
  58. * @{
  59. * @}
  60. * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
  61. * @{
  62. * @}
  63. * @}
  64. * @defgroup lavc_internal Internal
  65. * @{
  66. * @}
  67. * @}
  68. */
  69. /**
  70. * @ingroup libavc
  71. * @defgroup lavc_encdec send/receive encoding and decoding API overview
  72. * @{
  73. *
  74. * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/
  75. * avcodec_receive_packet() functions provide an encode/decode API, which
  76. * decouples input and output.
  77. *
  78. * The API is very similar for encoding/decoding and audio/video, and works as
  79. * follows:
  80. * - Set up and open the AVCodecContext as usual.
  81. * - Send valid input:
  82. * - For decoding, call avcodec_send_packet() to give the decoder raw
  83. * compressed data in an AVPacket.
  84. * - For encoding, call avcodec_send_frame() to give the decoder an AVFrame
  85. * containing uncompressed audio or video.
  86. * In both cases, it is recommended that AVPackets and AVFrames are
  87. * refcounted, or libavcodec might have to copy the input data. (libavformat
  88. * always returns refcounted AVPackets, and av_frame_get_buffer() allocates
  89. * refcounted AVFrames.)
  90. * - Receive output in a loop. Periodically call one of the avcodec_receive_*()
  91. * functions and process their output:
  92. * - For decoding, call avcodec_receive_frame(). On success, it will return
  93. * an AVFrame containing uncompressed audio or video data.
  94. * - For encoding, call avcodec_receive_packet(). On success, it will return
  95. * an AVPacket with a compressed frame.
  96. * Repeat this call until it returns AVERROR(EAGAIN) or an error. The
  97. * AVERROR(EAGAIN) return value means that new input data is required to
  98. * return new output. In this case, continue with sending input. For each
  99. * input frame/packet, the codec will typically return 1 output frame/packet,
  100. * but it can also be 0 or more than 1.
  101. *
  102. * At the beginning of decoding or encoding, the codec might accept multiple
  103. * input frames/packets without returning a frame, until its internal buffers
  104. * are filled. This situation is handled transparently if you follow the steps
  105. * outlined above.
  106. *
  107. * In theory, sending input can result in EAGAIN - this should happen only if
  108. * not all output was received. You can use this to structure alternative decode
  109. * or encode loops other than the one suggested above. For example, you could
  110. * try sending new input on each iteration, and try to receive output if that
  111. * returns EAGAIN.
  112. *
  113. * End of stream situations. These require "flushing" (aka draining) the codec,
  114. * as the codec might buffer multiple frames or packets internally for
  115. * performance or out of necessity (consider B-frames).
  116. * This is handled as follows:
  117. * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding)
  118. * or avcodec_send_frame() (encoding) functions. This will enter draining
  119. * mode.
  120. * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet()
  121. * (encoding) in a loop until AVERROR_EOF is returned. The functions will
  122. * not return AVERROR(EAGAIN), unless you forgot to enter draining mode.
  123. * - Before decoding can be resumed again, the codec has to be reset with
  124. * avcodec_flush_buffers().
  125. *
  126. * Using the API as outlined above is highly recommended. But it is also
  127. * possible to call functions outside of this rigid schema. For example, you can
  128. * call avcodec_send_packet() repeatedly without calling
  129. * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed
  130. * until the codec's internal buffer has been filled up (which is typically of
  131. * size 1 per output frame, after initial input), and then reject input with
  132. * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to
  133. * read at least some output.
  134. *
  135. * Not all codecs will follow a rigid and predictable dataflow; the only
  136. * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on
  137. * one end implies that a receive/send call on the other end will succeed. In
  138. * general, no codec will permit unlimited buffering of input or output.
  139. *
  140. * This API replaces the following legacy functions:
  141. * - avcodec_decode_video2() and avcodec_decode_audio4():
  142. * Use avcodec_send_packet() to feed input to the decoder, then use
  143. * avcodec_receive_frame() to receive decoded frames after each packet.
  144. * Unlike with the old video decoding API, multiple frames might result from
  145. * a packet. For audio, splitting the input packet into frames by partially
  146. * decoding packets becomes transparent to the API user. You never need to
  147. * feed an AVPacket to the API twice (unless it is rejected with EAGAIN - then
  148. * no data was read from the packet).
  149. * Additionally, sending a flush/draining packet is required only once.
  150. * - avcodec_encode_video2()/avcodec_encode_audio2():
  151. * Use avcodec_send_frame() to feed input to the encoder, then use
  152. * avcodec_receive_packet() to receive encoded packets.
  153. * Providing user-allocated buffers for avcodec_receive_packet() is not
  154. * possible.
  155. * - The new API does not handle subtitles yet.
  156. *
  157. * Mixing new and old function calls on the same AVCodecContext is not allowed,
  158. * and will result in arbitrary behavior.
  159. *
  160. * Some codecs might require using the new API; using the old API will return
  161. * an error when calling it. All codecs support the new API.
  162. *
  163. * A codec is not allowed to return EAGAIN for both sending and receiving. This
  164. * would be an invalid state, which could put the codec user into an endless
  165. * loop. The API has no concept of time either: it cannot happen that trying to
  166. * do avcodec_send_packet() results in EAGAIN, but a repeated call 1 second
  167. * later accepts the packet (with no other receive/flush API calls involved).
  168. * The API is a strict state machine, and the passage of time is not supposed
  169. * to influence it. Some timing-dependent behavior might still be deemed
  170. * acceptable in certain cases. But it must never result in both send/receive
  171. * returning EAGAIN at the same time at any point. It must also absolutely be
  172. * avoided that the current state is "unstable" and can "flip-flop" between
  173. * the send/receive APIs allowing progress. For example, it's not allowed that
  174. * the codec randomly decides that it actually wants to consume a packet now
  175. * instead of returning a frame, after it just returned EAGAIN on an
  176. * avcodec_send_packet() call.
  177. * @}
  178. */
  179. /**
  180. * @defgroup lavc_core Core functions/structures.
  181. * @ingroup libavc
  182. *
  183. * Basic definitions, functions for querying libavcodec capabilities,
  184. * allocating core structures, etc.
  185. * @{
  186. */
  187. /**
  188. * Identify the syntax and semantics of the bitstream.
  189. * The principle is roughly:
  190. * Two decoders with the same ID can decode the same streams.
  191. * Two encoders with the same ID can encode compatible streams.
  192. * There may be slight deviations from the principle due to implementation
  193. * details.
  194. *
  195. * If you add a codec ID to this list, add it so that
  196. * 1. no value of a existing codec ID changes (that would break ABI),
  197. * 2. it is as close as possible to similar codecs.
  198. *
  199. * After adding new codec IDs, do not forget to add an entry to the codec
  200. * descriptor list and bump libavcodec minor version.
  201. */
  202. enum AVCodecID {
  203. AV_CODEC_ID_NONE,
  204. /* video codecs */
  205. AV_CODEC_ID_MPEG1VIDEO,
  206. AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
  207. AV_CODEC_ID_H261,
  208. AV_CODEC_ID_H263,
  209. AV_CODEC_ID_RV10,
  210. AV_CODEC_ID_RV20,
  211. AV_CODEC_ID_MJPEG,
  212. AV_CODEC_ID_MJPEGB,
  213. AV_CODEC_ID_LJPEG,
  214. AV_CODEC_ID_SP5X,
  215. AV_CODEC_ID_JPEGLS,
  216. AV_CODEC_ID_MPEG4,
  217. AV_CODEC_ID_RAWVIDEO,
  218. AV_CODEC_ID_MSMPEG4V1,
  219. AV_CODEC_ID_MSMPEG4V2,
  220. AV_CODEC_ID_MSMPEG4V3,
  221. AV_CODEC_ID_WMV1,
  222. AV_CODEC_ID_WMV2,
  223. AV_CODEC_ID_H263P,
  224. AV_CODEC_ID_H263I,
  225. AV_CODEC_ID_FLV1,
  226. AV_CODEC_ID_SVQ1,
  227. AV_CODEC_ID_SVQ3,
  228. AV_CODEC_ID_DVVIDEO,
  229. AV_CODEC_ID_HUFFYUV,
  230. AV_CODEC_ID_CYUV,
  231. AV_CODEC_ID_H264,
  232. AV_CODEC_ID_INDEO3,
  233. AV_CODEC_ID_VP3,
  234. AV_CODEC_ID_THEORA,
  235. AV_CODEC_ID_ASV1,
  236. AV_CODEC_ID_ASV2,
  237. AV_CODEC_ID_FFV1,
  238. AV_CODEC_ID_4XM,
  239. AV_CODEC_ID_VCR1,
  240. AV_CODEC_ID_CLJR,
  241. AV_CODEC_ID_MDEC,
  242. AV_CODEC_ID_ROQ,
  243. AV_CODEC_ID_INTERPLAY_VIDEO,
  244. AV_CODEC_ID_XAN_WC3,
  245. AV_CODEC_ID_XAN_WC4,
  246. AV_CODEC_ID_RPZA,
  247. AV_CODEC_ID_CINEPAK,
  248. AV_CODEC_ID_WS_VQA,
  249. AV_CODEC_ID_MSRLE,
  250. AV_CODEC_ID_MSVIDEO1,
  251. AV_CODEC_ID_IDCIN,
  252. AV_CODEC_ID_8BPS,
  253. AV_CODEC_ID_SMC,
  254. AV_CODEC_ID_FLIC,
  255. AV_CODEC_ID_TRUEMOTION1,
  256. AV_CODEC_ID_VMDVIDEO,
  257. AV_CODEC_ID_MSZH,
  258. AV_CODEC_ID_ZLIB,
  259. AV_CODEC_ID_QTRLE,
  260. AV_CODEC_ID_TSCC,
  261. AV_CODEC_ID_ULTI,
  262. AV_CODEC_ID_QDRAW,
  263. AV_CODEC_ID_VIXL,
  264. AV_CODEC_ID_QPEG,
  265. AV_CODEC_ID_PNG,
  266. AV_CODEC_ID_PPM,
  267. AV_CODEC_ID_PBM,
  268. AV_CODEC_ID_PGM,
  269. AV_CODEC_ID_PGMYUV,
  270. AV_CODEC_ID_PAM,
  271. AV_CODEC_ID_FFVHUFF,
  272. AV_CODEC_ID_RV30,
  273. AV_CODEC_ID_RV40,
  274. AV_CODEC_ID_VC1,
  275. AV_CODEC_ID_WMV3,
  276. AV_CODEC_ID_LOCO,
  277. AV_CODEC_ID_WNV1,
  278. AV_CODEC_ID_AASC,
  279. AV_CODEC_ID_INDEO2,
  280. AV_CODEC_ID_FRAPS,
  281. AV_CODEC_ID_TRUEMOTION2,
  282. AV_CODEC_ID_BMP,
  283. AV_CODEC_ID_CSCD,
  284. AV_CODEC_ID_MMVIDEO,
  285. AV_CODEC_ID_ZMBV,
  286. AV_CODEC_ID_AVS,
  287. AV_CODEC_ID_SMACKVIDEO,
  288. AV_CODEC_ID_NUV,
  289. AV_CODEC_ID_KMVC,
  290. AV_CODEC_ID_FLASHSV,
  291. AV_CODEC_ID_CAVS,
  292. AV_CODEC_ID_JPEG2000,
  293. AV_CODEC_ID_VMNC,
  294. AV_CODEC_ID_VP5,
  295. AV_CODEC_ID_VP6,
  296. AV_CODEC_ID_VP6F,
  297. AV_CODEC_ID_TARGA,
  298. AV_CODEC_ID_DSICINVIDEO,
  299. AV_CODEC_ID_TIERTEXSEQVIDEO,
  300. AV_CODEC_ID_TIFF,
  301. AV_CODEC_ID_GIF,
  302. AV_CODEC_ID_DXA,
  303. AV_CODEC_ID_DNXHD,
  304. AV_CODEC_ID_THP,
  305. AV_CODEC_ID_SGI,
  306. AV_CODEC_ID_C93,
  307. AV_CODEC_ID_BETHSOFTVID,
  308. AV_CODEC_ID_PTX,
  309. AV_CODEC_ID_TXD,
  310. AV_CODEC_ID_VP6A,
  311. AV_CODEC_ID_AMV,
  312. AV_CODEC_ID_VB,
  313. AV_CODEC_ID_PCX,
  314. AV_CODEC_ID_SUNRAST,
  315. AV_CODEC_ID_INDEO4,
  316. AV_CODEC_ID_INDEO5,
  317. AV_CODEC_ID_MIMIC,
  318. AV_CODEC_ID_RL2,
  319. AV_CODEC_ID_ESCAPE124,
  320. AV_CODEC_ID_DIRAC,
  321. AV_CODEC_ID_BFI,
  322. AV_CODEC_ID_CMV,
  323. AV_CODEC_ID_MOTIONPIXELS,
  324. AV_CODEC_ID_TGV,
  325. AV_CODEC_ID_TGQ,
  326. AV_CODEC_ID_TQI,
  327. AV_CODEC_ID_AURA,
  328. AV_CODEC_ID_AURA2,
  329. AV_CODEC_ID_V210X,
  330. AV_CODEC_ID_TMV,
  331. AV_CODEC_ID_V210,
  332. AV_CODEC_ID_DPX,
  333. AV_CODEC_ID_MAD,
  334. AV_CODEC_ID_FRWU,
  335. AV_CODEC_ID_FLASHSV2,
  336. AV_CODEC_ID_CDGRAPHICS,
  337. AV_CODEC_ID_R210,
  338. AV_CODEC_ID_ANM,
  339. AV_CODEC_ID_BINKVIDEO,
  340. AV_CODEC_ID_IFF_ILBM,
  341. AV_CODEC_ID_IFF_BYTERUN1,
  342. AV_CODEC_ID_KGV1,
  343. AV_CODEC_ID_YOP,
  344. AV_CODEC_ID_VP8,
  345. AV_CODEC_ID_PICTOR,
  346. AV_CODEC_ID_ANSI,
  347. AV_CODEC_ID_A64_MULTI,
  348. AV_CODEC_ID_A64_MULTI5,
  349. AV_CODEC_ID_R10K,
  350. AV_CODEC_ID_MXPEG,
  351. AV_CODEC_ID_LAGARITH,
  352. AV_CODEC_ID_PRORES,
  353. AV_CODEC_ID_JV,
  354. AV_CODEC_ID_DFA,
  355. AV_CODEC_ID_WMV3IMAGE,
  356. AV_CODEC_ID_VC1IMAGE,
  357. AV_CODEC_ID_UTVIDEO,
  358. AV_CODEC_ID_BMV_VIDEO,
  359. AV_CODEC_ID_VBLE,
  360. AV_CODEC_ID_DXTORY,
  361. AV_CODEC_ID_V410,
  362. AV_CODEC_ID_XWD,
  363. AV_CODEC_ID_CDXL,
  364. AV_CODEC_ID_XBM,
  365. AV_CODEC_ID_ZEROCODEC,
  366. AV_CODEC_ID_MSS1,
  367. AV_CODEC_ID_MSA1,
  368. AV_CODEC_ID_TSCC2,
  369. AV_CODEC_ID_MTS2,
  370. AV_CODEC_ID_CLLC,
  371. AV_CODEC_ID_MSS2,
  372. AV_CODEC_ID_VP9,
  373. AV_CODEC_ID_AIC,
  374. AV_CODEC_ID_ESCAPE130,
  375. AV_CODEC_ID_G2M,
  376. AV_CODEC_ID_WEBP,
  377. AV_CODEC_ID_HNM4_VIDEO,
  378. AV_CODEC_ID_HEVC,
  379. AV_CODEC_ID_FIC,
  380. AV_CODEC_ID_ALIAS_PIX,
  381. AV_CODEC_ID_BRENDER_PIX,
  382. AV_CODEC_ID_PAF_VIDEO,
  383. AV_CODEC_ID_EXR,
  384. AV_CODEC_ID_VP7,
  385. AV_CODEC_ID_SANM,
  386. AV_CODEC_ID_SGIRLE,
  387. AV_CODEC_ID_MVC1,
  388. AV_CODEC_ID_MVC2,
  389. AV_CODEC_ID_HQX,
  390. AV_CODEC_ID_TDSC,
  391. AV_CODEC_ID_HQ_HQA,
  392. AV_CODEC_ID_HAP,
  393. AV_CODEC_ID_DDS,
  394. AV_CODEC_ID_DXV,
  395. AV_CODEC_ID_SCREENPRESSO,
  396. AV_CODEC_ID_RSCC,
  397. AV_CODEC_ID_MAGICYUV,
  398. AV_CODEC_ID_TRUEMOTION2RT,
  399. AV_CODEC_ID_AV1,
  400. AV_CODEC_ID_PIXLET,
  401. AV_CODEC_ID_CFHD,
  402. AV_CODEC_ID_FMVC,
  403. AV_CODEC_ID_CLEARVIDEO,
  404. /* various PCM "codecs" */
  405. AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
  406. AV_CODEC_ID_PCM_S16LE = 0x10000,
  407. AV_CODEC_ID_PCM_S16BE,
  408. AV_CODEC_ID_PCM_U16LE,
  409. AV_CODEC_ID_PCM_U16BE,
  410. AV_CODEC_ID_PCM_S8,
  411. AV_CODEC_ID_PCM_U8,
  412. AV_CODEC_ID_PCM_MULAW,
  413. AV_CODEC_ID_PCM_ALAW,
  414. AV_CODEC_ID_PCM_S32LE,
  415. AV_CODEC_ID_PCM_S32BE,
  416. AV_CODEC_ID_PCM_U32LE,
  417. AV_CODEC_ID_PCM_U32BE,
  418. AV_CODEC_ID_PCM_S24LE,
  419. AV_CODEC_ID_PCM_S24BE,
  420. AV_CODEC_ID_PCM_U24LE,
  421. AV_CODEC_ID_PCM_U24BE,
  422. AV_CODEC_ID_PCM_S24DAUD,
  423. AV_CODEC_ID_PCM_ZORK,
  424. AV_CODEC_ID_PCM_S16LE_PLANAR,
  425. AV_CODEC_ID_PCM_DVD,
  426. AV_CODEC_ID_PCM_F32BE,
  427. AV_CODEC_ID_PCM_F32LE,
  428. AV_CODEC_ID_PCM_F64BE,
  429. AV_CODEC_ID_PCM_F64LE,
  430. AV_CODEC_ID_PCM_BLURAY,
  431. AV_CODEC_ID_PCM_LXF,
  432. AV_CODEC_ID_S302M,
  433. AV_CODEC_ID_PCM_S8_PLANAR,
  434. AV_CODEC_ID_PCM_S24LE_PLANAR,
  435. AV_CODEC_ID_PCM_S32LE_PLANAR,
  436. AV_CODEC_ID_PCM_S16BE_PLANAR,
  437. /* various ADPCM codecs */
  438. AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
  439. AV_CODEC_ID_ADPCM_IMA_WAV,
  440. AV_CODEC_ID_ADPCM_IMA_DK3,
  441. AV_CODEC_ID_ADPCM_IMA_DK4,
  442. AV_CODEC_ID_ADPCM_IMA_WS,
  443. AV_CODEC_ID_ADPCM_IMA_SMJPEG,
  444. AV_CODEC_ID_ADPCM_MS,
  445. AV_CODEC_ID_ADPCM_4XM,
  446. AV_CODEC_ID_ADPCM_XA,
  447. AV_CODEC_ID_ADPCM_ADX,
  448. AV_CODEC_ID_ADPCM_EA,
  449. AV_CODEC_ID_ADPCM_G726,
  450. AV_CODEC_ID_ADPCM_CT,
  451. AV_CODEC_ID_ADPCM_SWF,
  452. AV_CODEC_ID_ADPCM_YAMAHA,
  453. AV_CODEC_ID_ADPCM_SBPRO_4,
  454. AV_CODEC_ID_ADPCM_SBPRO_3,
  455. AV_CODEC_ID_ADPCM_SBPRO_2,
  456. AV_CODEC_ID_ADPCM_THP,
  457. AV_CODEC_ID_ADPCM_IMA_AMV,
  458. AV_CODEC_ID_ADPCM_EA_R1,
  459. AV_CODEC_ID_ADPCM_EA_R3,
  460. AV_CODEC_ID_ADPCM_EA_R2,
  461. AV_CODEC_ID_ADPCM_IMA_EA_SEAD,
  462. AV_CODEC_ID_ADPCM_IMA_EA_EACS,
  463. AV_CODEC_ID_ADPCM_EA_XAS,
  464. AV_CODEC_ID_ADPCM_EA_MAXIS_XA,
  465. AV_CODEC_ID_ADPCM_IMA_ISS,
  466. AV_CODEC_ID_ADPCM_G722,
  467. AV_CODEC_ID_ADPCM_IMA_APC,
  468. AV_CODEC_ID_ADPCM_VIMA,
  469. /* AMR */
  470. AV_CODEC_ID_AMR_NB = 0x12000,
  471. AV_CODEC_ID_AMR_WB,
  472. /* RealAudio codecs*/
  473. AV_CODEC_ID_RA_144 = 0x13000,
  474. AV_CODEC_ID_RA_288,
  475. /* various DPCM codecs */
  476. AV_CODEC_ID_ROQ_DPCM = 0x14000,
  477. AV_CODEC_ID_INTERPLAY_DPCM,
  478. AV_CODEC_ID_XAN_DPCM,
  479. AV_CODEC_ID_SOL_DPCM,
  480. /* audio codecs */
  481. AV_CODEC_ID_MP2 = 0x15000,
  482. AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
  483. AV_CODEC_ID_AAC,
  484. AV_CODEC_ID_AC3,
  485. AV_CODEC_ID_DTS,
  486. AV_CODEC_ID_VORBIS,
  487. AV_CODEC_ID_DVAUDIO,
  488. AV_CODEC_ID_WMAV1,
  489. AV_CODEC_ID_WMAV2,
  490. AV_CODEC_ID_MACE3,
  491. AV_CODEC_ID_MACE6,
  492. AV_CODEC_ID_VMDAUDIO,
  493. AV_CODEC_ID_FLAC,
  494. AV_CODEC_ID_MP3ADU,
  495. AV_CODEC_ID_MP3ON4,
  496. AV_CODEC_ID_SHORTEN,
  497. AV_CODEC_ID_ALAC,
  498. AV_CODEC_ID_WESTWOOD_SND1,
  499. AV_CODEC_ID_GSM, ///< as in Berlin toast format
  500. AV_CODEC_ID_QDM2,
  501. AV_CODEC_ID_COOK,
  502. AV_CODEC_ID_TRUESPEECH,
  503. AV_CODEC_ID_TTA,
  504. AV_CODEC_ID_SMACKAUDIO,
  505. AV_CODEC_ID_QCELP,
  506. AV_CODEC_ID_WAVPACK,
  507. AV_CODEC_ID_DSICINAUDIO,
  508. AV_CODEC_ID_IMC,
  509. AV_CODEC_ID_MUSEPACK7,
  510. AV_CODEC_ID_MLP,
  511. AV_CODEC_ID_GSM_MS, /* as found in WAV */
  512. AV_CODEC_ID_ATRAC3,
  513. AV_CODEC_ID_APE,
  514. AV_CODEC_ID_NELLYMOSER,
  515. AV_CODEC_ID_MUSEPACK8,
  516. AV_CODEC_ID_SPEEX,
  517. AV_CODEC_ID_WMAVOICE,
  518. AV_CODEC_ID_WMAPRO,
  519. AV_CODEC_ID_WMALOSSLESS,
  520. AV_CODEC_ID_ATRAC3P,
  521. AV_CODEC_ID_EAC3,
  522. AV_CODEC_ID_SIPR,
  523. AV_CODEC_ID_MP1,
  524. AV_CODEC_ID_TWINVQ,
  525. AV_CODEC_ID_TRUEHD,
  526. AV_CODEC_ID_MP4ALS,
  527. AV_CODEC_ID_ATRAC1,
  528. AV_CODEC_ID_BINKAUDIO_RDFT,
  529. AV_CODEC_ID_BINKAUDIO_DCT,
  530. AV_CODEC_ID_AAC_LATM,
  531. AV_CODEC_ID_QDMC,
  532. AV_CODEC_ID_CELT,
  533. AV_CODEC_ID_G723_1,
  534. AV_CODEC_ID_G729,
  535. AV_CODEC_ID_8SVX_EXP,
  536. AV_CODEC_ID_8SVX_FIB,
  537. AV_CODEC_ID_BMV_AUDIO,
  538. AV_CODEC_ID_RALF,
  539. AV_CODEC_ID_IAC,
  540. AV_CODEC_ID_ILBC,
  541. AV_CODEC_ID_OPUS,
  542. AV_CODEC_ID_COMFORT_NOISE,
  543. AV_CODEC_ID_TAK,
  544. AV_CODEC_ID_METASOUND,
  545. AV_CODEC_ID_PAF_AUDIO,
  546. AV_CODEC_ID_ON2AVC,
  547. AV_CODEC_ID_DSS_SP,
  548. /* subtitle codecs */
  549. AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
  550. AV_CODEC_ID_DVD_SUBTITLE = 0x17000,
  551. AV_CODEC_ID_DVB_SUBTITLE,
  552. AV_CODEC_ID_TEXT, ///< raw UTF-8 text
  553. AV_CODEC_ID_XSUB,
  554. AV_CODEC_ID_SSA,
  555. AV_CODEC_ID_MOV_TEXT,
  556. AV_CODEC_ID_HDMV_PGS_SUBTITLE,
  557. AV_CODEC_ID_DVB_TELETEXT,
  558. AV_CODEC_ID_SRT,
  559. /* other specific kind of codecs (generally used for attachments) */
  560. AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
  561. AV_CODEC_ID_TTF = 0x18000,
  562. AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
  563. AV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
  564. * stream (only used by libavformat) */
  565. AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
  566. * stream (only used by libavformat) */
  567. AV_CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information.
  568. AV_CODEC_ID_WRAPPED_AVFRAME = 0x21001, ///< Passthrough codec, AVFrames wrapped in AVPacket
  569. };
  570. /**
  571. * This struct describes the properties of a single codec described by an
  572. * AVCodecID.
  573. * @see avcodec_descriptor_get()
  574. */
  575. typedef struct AVCodecDescriptor {
  576. enum AVCodecID id;
  577. enum AVMediaType type;
  578. /**
  579. * Name of the codec described by this descriptor. It is non-empty and
  580. * unique for each codec descriptor. It should contain alphanumeric
  581. * characters and '_' only.
  582. */
  583. const char *name;
  584. /**
  585. * A more descriptive name for this codec. May be NULL.
  586. */
  587. const char *long_name;
  588. /**
  589. * Codec properties, a combination of AV_CODEC_PROP_* flags.
  590. */
  591. int props;
  592. /**
  593. * If non-NULL, an array of profiles recognized for this codec.
  594. * Terminated with FF_PROFILE_UNKNOWN.
  595. */
  596. const struct AVProfile *profiles;
  597. } AVCodecDescriptor;
  598. /**
  599. * Codec uses only intra compression.
  600. * Video codecs only.
  601. */
  602. #define AV_CODEC_PROP_INTRA_ONLY (1 << 0)
  603. /**
  604. * Codec supports lossy compression. Audio and video codecs only.
  605. * @note a codec may support both lossy and lossless
  606. * compression modes
  607. */
  608. #define AV_CODEC_PROP_LOSSY (1 << 1)
  609. /**
  610. * Codec supports lossless compression. Audio and video codecs only.
  611. */
  612. #define AV_CODEC_PROP_LOSSLESS (1 << 2)
  613. /**
  614. * Codec supports frame reordering. That is, the coded order (the order in which
  615. * the encoded packets are output by the encoders / stored / input to the
  616. * decoders) may be different from the presentation order of the corresponding
  617. * frames.
  618. *
  619. * For codecs that do not have this property set, PTS and DTS should always be
  620. * equal.
  621. */
  622. #define AV_CODEC_PROP_REORDER (1 << 3)
  623. /**
  624. * @ingroup lavc_decoding
  625. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  626. * This is mainly needed because some optimized bitstream readers read
  627. * 32 or 64 bit at once and could read over the end.<br>
  628. * Note: If the first 23 bits of the additional bytes are not 0, then damaged
  629. * MPEG bitstreams could cause overread and segfault.
  630. */
  631. #define AV_INPUT_BUFFER_PADDING_SIZE 8
  632. /**
  633. * @ingroup lavc_encoding
  634. * minimum encoding buffer size
  635. * Used to avoid some checks during header writing.
  636. */
  637. #define AV_INPUT_BUFFER_MIN_SIZE 16384
  638. /**
  639. * @ingroup lavc_decoding
  640. */
  641. enum AVDiscard{
  642. /* We leave some space between them for extensions (drop some
  643. * keyframes for intra-only or drop just some bidir frames). */
  644. AVDISCARD_NONE =-16, ///< discard nothing
  645. AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
  646. AVDISCARD_NONREF = 8, ///< discard all non reference
  647. AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
  648. AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
  649. AVDISCARD_ALL = 48, ///< discard all
  650. };
  651. enum AVAudioServiceType {
  652. AV_AUDIO_SERVICE_TYPE_MAIN = 0,
  653. AV_AUDIO_SERVICE_TYPE_EFFECTS = 1,
  654. AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
  655. AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = 3,
  656. AV_AUDIO_SERVICE_TYPE_DIALOGUE = 4,
  657. AV_AUDIO_SERVICE_TYPE_COMMENTARY = 5,
  658. AV_AUDIO_SERVICE_TYPE_EMERGENCY = 6,
  659. AV_AUDIO_SERVICE_TYPE_VOICE_OVER = 7,
  660. AV_AUDIO_SERVICE_TYPE_KARAOKE = 8,
  661. AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI
  662. };
  663. /**
  664. * @ingroup lavc_encoding
  665. */
  666. typedef struct RcOverride{
  667. int start_frame;
  668. int end_frame;
  669. int qscale; // If this is 0 then quality_factor will be used instead.
  670. float quality_factor;
  671. } RcOverride;
  672. /* encoding support
  673. These flags can be passed in AVCodecContext.flags before initialization.
  674. Note: Not everything is supported yet.
  675. */
  676. /**
  677. * Allow decoders to produce frames with data planes that are not aligned
  678. * to CPU requirements (e.g. due to cropping).
  679. */
  680. #define AV_CODEC_FLAG_UNALIGNED (1 << 0)
  681. /**
  682. * Use fixed qscale.
  683. */
  684. #define AV_CODEC_FLAG_QSCALE (1 << 1)
  685. /**
  686. * 4 MV per MB allowed / advanced prediction for H.263.
  687. */
  688. #define AV_CODEC_FLAG_4MV (1 << 2)
  689. /**
  690. * Output even those frames that might be corrupted.
  691. */
  692. #define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3)
  693. /**
  694. * Use qpel MC.
  695. */
  696. #define AV_CODEC_FLAG_QPEL (1 << 4)
  697. /**
  698. * Use internal 2pass ratecontrol in first pass mode.
  699. */
  700. #define AV_CODEC_FLAG_PASS1 (1 << 9)
  701. /**
  702. * Use internal 2pass ratecontrol in second pass mode.
  703. */
  704. #define AV_CODEC_FLAG_PASS2 (1 << 10)
  705. /**
  706. * loop filter.
  707. */
  708. #define AV_CODEC_FLAG_LOOP_FILTER (1 << 11)
  709. /**
  710. * Only decode/encode grayscale.
  711. */
  712. #define AV_CODEC_FLAG_GRAY (1 << 13)
  713. /**
  714. * error[?] variables will be set during encoding.
  715. */
  716. #define AV_CODEC_FLAG_PSNR (1 << 15)
  717. /**
  718. * Input bitstream might be truncated at a random location
  719. * instead of only at frame boundaries.
  720. */
  721. #define AV_CODEC_FLAG_TRUNCATED (1 << 16)
  722. /**
  723. * Use interlaced DCT.
  724. */
  725. #define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18)
  726. /**
  727. * Force low delay.
  728. */
  729. #define AV_CODEC_FLAG_LOW_DELAY (1 << 19)
  730. /**
  731. * Place global headers in extradata instead of every keyframe.
  732. */
  733. #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
  734. /**
  735. * Use only bitexact stuff (except (I)DCT).
  736. */
  737. #define AV_CODEC_FLAG_BITEXACT (1 << 23)
  738. /* Fx : Flag for H.263+ extra options */
  739. /**
  740. * H.263 advanced intra coding / MPEG-4 AC prediction
  741. */
  742. #define AV_CODEC_FLAG_AC_PRED (1 << 24)
  743. /**
  744. * interlaced motion estimation
  745. */
  746. #define AV_CODEC_FLAG_INTERLACED_ME (1 << 29)
  747. #define AV_CODEC_FLAG_CLOSED_GOP (1 << 31)
  748. /**
  749. * Allow non spec compliant speedup tricks.
  750. */
  751. #define AV_CODEC_FLAG2_FAST (1 << 0)
  752. /**
  753. * Skip bitstream encoding.
  754. */
  755. #define AV_CODEC_FLAG2_NO_OUTPUT (1 << 2)
  756. /**
  757. * Place global headers at every keyframe instead of in extradata.
  758. */
  759. #define AV_CODEC_FLAG2_LOCAL_HEADER (1 << 3)
  760. /**
  761. * Input bitstream might be truncated at a packet boundaries
  762. * instead of only at frame boundaries.
  763. */
  764. #define AV_CODEC_FLAG2_CHUNKS (1 << 15)
  765. /**
  766. * Discard cropping information from SPS.
  767. */
  768. #define AV_CODEC_FLAG2_IGNORE_CROP (1 << 16)
  769. /* Unsupported options :
  770. * Syntax Arithmetic coding (SAC)
  771. * Reference Picture Selection
  772. * Independent Segment Decoding */
  773. /* /Fx */
  774. /* codec capabilities */
  775. /**
  776. * Decoder can use draw_horiz_band callback.
  777. */
  778. #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
  779. /**
  780. * Codec uses get_buffer() for allocating buffers and supports custom allocators.
  781. * If not set, it might not use get_buffer() at all or use operations that
  782. * assume the buffer was allocated by avcodec_default_get_buffer.
  783. */
  784. #define AV_CODEC_CAP_DR1 (1 << 1)
  785. #define AV_CODEC_CAP_TRUNCATED (1 << 3)
  786. /**
  787. * Encoder or decoder requires flushing with NULL input at the end in order to
  788. * give the complete and correct output.
  789. *
  790. * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
  791. * with NULL data. The user can still send NULL data to the public encode
  792. * or decode function, but libavcodec will not pass it along to the codec
  793. * unless this flag is set.
  794. *
  795. * Decoders:
  796. * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
  797. * avpkt->size=0 at the end to get the delayed data until the decoder no longer
  798. * returns frames.
  799. *
  800. * Encoders:
  801. * The encoder needs to be fed with NULL data at the end of encoding until the
  802. * encoder no longer returns data.
  803. *
  804. * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
  805. * flag also means that the encoder must set the pts and duration for
  806. * each output packet. If this flag is not set, the pts and duration will
  807. * be determined by libavcodec from the input frame.
  808. */
  809. #define AV_CODEC_CAP_DELAY (1 << 5)
  810. /**
  811. * Codec can be fed a final frame with a smaller size.
  812. * This can be used to prevent truncation of the last audio samples.
  813. */
  814. #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
  815. /**
  816. * Codec can output multiple frames per AVPacket
  817. * Normally demuxers return one frame at a time, demuxers which do not do
  818. * are connected to a parser to split what they return into proper frames.
  819. * This flag is reserved to the very rare category of codecs which have a
  820. * bitstream that cannot be split into frames without timeconsuming
  821. * operations like full decoding. Demuxers carrying such bitstreams thus
  822. * may return multiple frames in a packet. This has many disadvantages like
  823. * prohibiting stream copy in many cases thus it should only be considered
  824. * as a last resort.
  825. */
  826. #define AV_CODEC_CAP_SUBFRAMES (1 << 8)
  827. /**
  828. * Codec is experimental and is thus avoided in favor of non experimental
  829. * encoders
  830. */
  831. #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
  832. /**
  833. * Codec should fill in channel configuration and samplerate instead of container
  834. */
  835. #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
  836. /**
  837. * Codec supports frame-level multithreading.
  838. */
  839. #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
  840. /**
  841. * Codec supports slice-based (or partition-based) multithreading.
  842. */
  843. #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
  844. /**
  845. * Codec supports changed parameters at any point.
  846. */
  847. #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
  848. /**
  849. * Codec supports avctx->thread_count == 0 (auto).
  850. */
  851. #define AV_CODEC_CAP_AUTO_THREADS (1 << 15)
  852. /**
  853. * Audio encoder supports receiving a different number of samples in each call.
  854. */
  855. #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
  856. /**
  857. * Codec is backed by a hardware implementation. Typically used to
  858. * identify a non-hwaccel hardware decoder.
  859. */
  860. #define AV_CODEC_CAP_HARDWARE (1 << 17)
  861. /**
  862. * Codec is potentially backed by a hardware implementation, but not
  863. * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
  864. * implementation provides some sort of internal fallback.
  865. */
  866. #define AV_CODEC_CAP_HYBRID (1 << 18)
  867. /**
  868. * Pan Scan area.
  869. * This specifies the area which should be displayed.
  870. * Note there may be multiple such areas for one frame.
  871. */
  872. typedef struct AVPanScan{
  873. /**
  874. * id
  875. * - encoding: Set by user.
  876. * - decoding: Set by libavcodec.
  877. */
  878. int id;
  879. /**
  880. * width and height in 1/16 pel
  881. * - encoding: Set by user.
  882. * - decoding: Set by libavcodec.
  883. */
  884. int width;
  885. int height;
  886. /**
  887. * position of the top left corner in 1/16 pel for up to 3 fields/frames
  888. * - encoding: Set by user.
  889. * - decoding: Set by libavcodec.
  890. */
  891. int16_t position[3][2];
  892. }AVPanScan;
  893. /**
  894. * This structure describes the bitrate properties of an encoded bitstream. It
  895. * roughly corresponds to a subset the VBV parameters for MPEG-2 or HRD
  896. * parameters for H.264/HEVC.
  897. */
  898. typedef struct AVCPBProperties {
  899. /**
  900. * Maximum bitrate of the stream, in bits per second.
  901. * Zero if unknown or unspecified.
  902. */
  903. int max_bitrate;
  904. /**
  905. * Minimum bitrate of the stream, in bits per second.
  906. * Zero if unknown or unspecified.
  907. */
  908. int min_bitrate;
  909. /**
  910. * Average bitrate of the stream, in bits per second.
  911. * Zero if unknown or unspecified.
  912. */
  913. int avg_bitrate;
  914. /**
  915. * The size of the buffer to which the ratecontrol is applied, in bits.
  916. * Zero if unknown or unspecified.
  917. */
  918. int buffer_size;
  919. /**
  920. * The delay between the time the packet this structure is associated with
  921. * is received and the time when it should be decoded, in periods of a 27MHz
  922. * clock.
  923. *
  924. * UINT64_MAX when unknown or unspecified.
  925. */
  926. uint64_t vbv_delay;
  927. } AVCPBProperties;
  928. /**
  929. * The decoder will keep a reference to the frame and may reuse it later.
  930. */
  931. #define AV_GET_BUFFER_FLAG_REF (1 << 0)
  932. /**
  933. * @defgroup lavc_packet AVPacket
  934. *
  935. * Types and functions for working with AVPacket.
  936. * @{
  937. */
  938. enum AVPacketSideDataType {
  939. /**
  940. * An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE
  941. * bytes worth of palette. This side data signals that a new palette is
  942. * present.
  943. */
  944. AV_PKT_DATA_PALETTE,
  945. /**
  946. * The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format
  947. * that the extradata buffer was changed and the receiving side should
  948. * act upon it appropriately. The new extradata is embedded in the side
  949. * data buffer and should be immediately used for processing the current
  950. * frame or packet.
  951. */
  952. AV_PKT_DATA_NEW_EXTRADATA,
  953. /**
  954. * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
  955. * @code
  956. * u32le param_flags
  957. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
  958. * s32le channel_count
  959. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
  960. * u64le channel_layout
  961. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
  962. * s32le sample_rate
  963. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
  964. * s32le width
  965. * s32le height
  966. * @endcode
  967. */
  968. AV_PKT_DATA_PARAM_CHANGE,
  969. /**
  970. * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
  971. * structures with info about macroblocks relevant to splitting the
  972. * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
  973. * That is, it does not necessarily contain info about all macroblocks,
  974. * as long as the distance between macroblocks in the info is smaller
  975. * than the target payload size.
  976. * Each MB info structure is 12 bytes, and is laid out as follows:
  977. * @code
  978. * u32le bit offset from the start of the packet
  979. * u8 current quantizer at the start of the macroblock
  980. * u8 GOB number
  981. * u16le macroblock address within the GOB
  982. * u8 horizontal MV predictor
  983. * u8 vertical MV predictor
  984. * u8 horizontal MV predictor for block number 3
  985. * u8 vertical MV predictor for block number 3
  986. * @endcode
  987. */
  988. AV_PKT_DATA_H263_MB_INFO,
  989. /**
  990. * This side data should be associated with an audio stream and contains
  991. * ReplayGain information in form of the AVReplayGain struct.
  992. */
  993. AV_PKT_DATA_REPLAYGAIN,
  994. /**
  995. * This side data contains a 3x3 transformation matrix describing an affine
  996. * transformation that needs to be applied to the decoded video frames for
  997. * correct presentation.
  998. *
  999. * See libavutil/display.h for a detailed description of the data.
  1000. */
  1001. AV_PKT_DATA_DISPLAYMATRIX,
  1002. /**
  1003. * This side data should be associated with a video stream and contains
  1004. * Stereoscopic 3D information in form of the AVStereo3D struct.
  1005. */
  1006. AV_PKT_DATA_STEREO3D,
  1007. /**
  1008. * This side data should be associated with an audio stream and corresponds
  1009. * to enum AVAudioServiceType.
  1010. */
  1011. AV_PKT_DATA_AUDIO_SERVICE_TYPE,
  1012. /**
  1013. * This side data contains an integer value representing the quality
  1014. * factor of the compressed frame. Allowed range is between 1 (good)
  1015. * and FF_LAMBDA_MAX (bad).
  1016. */
  1017. AV_PKT_DATA_QUALITY_FACTOR,
  1018. /**
  1019. * This side data contains an integer value representing the stream index
  1020. * of a "fallback" track. A fallback track indicates an alternate
  1021. * track to use when the current track can not be decoded for some reason.
  1022. * e.g. no decoder available for codec.
  1023. */
  1024. AV_PKT_DATA_FALLBACK_TRACK,
  1025. /**
  1026. * This side data corresponds to the AVCPBProperties struct.
  1027. */
  1028. AV_PKT_DATA_CPB_PROPERTIES,
  1029. /**
  1030. * This side data should be associated with a video stream and corresponds
  1031. * to the AVSphericalMapping structure.
  1032. */
  1033. AV_PKT_DATA_SPHERICAL,
  1034. };
  1035. typedef struct AVPacketSideData {
  1036. uint8_t *data;
  1037. int size;
  1038. enum AVPacketSideDataType type;
  1039. } AVPacketSideData;
  1040. /**
  1041. * This structure stores compressed data. It is typically exported by demuxers
  1042. * and then passed as input to decoders, or received as output from encoders and
  1043. * then passed to muxers.
  1044. *
  1045. * For video, it should typically contain one compressed frame. For audio it may
  1046. * contain several compressed frames. Encoders are allowed to output empty
  1047. * packets, with no compressed data, containing only side data
  1048. * (e.g. to update some stream parameters at the end of encoding).
  1049. *
  1050. * AVPacket is one of the few structs in Libav, whose size is a part of public
  1051. * ABI. Thus it may be allocated on stack and no new fields can be added to it
  1052. * without libavcodec and libavformat major bump.
  1053. *
  1054. * The semantics of data ownership depends on the buf field.
  1055. * If it is set, the packet data is dynamically allocated and is
  1056. * valid indefinitely until a call to av_packet_unref() reduces the
  1057. * reference count to 0.
  1058. *
  1059. * If the buf field is not set av_packet_ref() would make a copy instead
  1060. * of increasing the reference count.
  1061. *
  1062. * The side data is always allocated with av_malloc(), copied by
  1063. * av_packet_ref() and freed by av_packet_unref().
  1064. *
  1065. * @see av_packet_ref
  1066. * @see av_packet_unref
  1067. */
  1068. typedef struct AVPacket {
  1069. /**
  1070. * A reference to the reference-counted buffer where the packet data is
  1071. * stored.
  1072. * May be NULL, then the packet data is not reference-counted.
  1073. */
  1074. AVBufferRef *buf;
  1075. /**
  1076. * Presentation timestamp in AVStream->time_base units; the time at which
  1077. * the decompressed packet will be presented to the user.
  1078. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  1079. * pts MUST be larger or equal to dts as presentation cannot happen before
  1080. * decompression, unless one wants to view hex dumps. Some formats misuse
  1081. * the terms dts and pts/cts to mean something different. Such timestamps
  1082. * must be converted to true pts/dts before they are stored in AVPacket.
  1083. */
  1084. int64_t pts;
  1085. /**
  1086. * Decompression timestamp in AVStream->time_base units; the time at which
  1087. * the packet is decompressed.
  1088. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  1089. */
  1090. int64_t dts;
  1091. uint8_t *data;
  1092. int size;
  1093. int stream_index;
  1094. /**
  1095. * A combination of AV_PKT_FLAG values
  1096. */
  1097. int flags;
  1098. /**
  1099. * Additional packet data that can be provided by the container.
  1100. * Packet can contain several types of side information.
  1101. */
  1102. AVPacketSideData *side_data;
  1103. int side_data_elems;
  1104. /**
  1105. * Duration of this packet in AVStream->time_base units, 0 if unknown.
  1106. * Equals next_pts - this_pts in presentation order.
  1107. */
  1108. int64_t duration;
  1109. int64_t pos; ///< byte position in stream, -1 if unknown
  1110. #if FF_API_CONVERGENCE_DURATION
  1111. /**
  1112. * @deprecated Same as the duration field, but as int64_t. This was required
  1113. * for Matroska subtitles, whose duration values could overflow when the
  1114. * duration field was still an int.
  1115. */
  1116. attribute_deprecated
  1117. int64_t convergence_duration;
  1118. #endif
  1119. } AVPacket;
  1120. #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
  1121. #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
  1122. enum AVSideDataParamChangeFlags {
  1123. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,
  1124. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
  1125. AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
  1126. AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
  1127. };
  1128. /**
  1129. * @}
  1130. */
  1131. struct AVCodecInternal;
  1132. enum AVFieldOrder {
  1133. AV_FIELD_UNKNOWN,
  1134. AV_FIELD_PROGRESSIVE,
  1135. AV_FIELD_TT, //< Top coded_first, top displayed first
  1136. AV_FIELD_BB, //< Bottom coded first, bottom displayed first
  1137. AV_FIELD_TB, //< Top coded first, bottom displayed first
  1138. AV_FIELD_BT, //< Bottom coded first, top displayed first
  1139. };
  1140. /**
  1141. * main external API structure.
  1142. * New fields can be added to the end with minor version bumps.
  1143. * Removal, reordering and changes to existing fields require a major
  1144. * version bump.
  1145. * sizeof(AVCodecContext) must not be used outside libav*.
  1146. */
  1147. typedef struct AVCodecContext {
  1148. /**
  1149. * information on struct for av_log
  1150. * - set by avcodec_alloc_context3
  1151. */
  1152. const AVClass *av_class;
  1153. int log_level_offset;
  1154. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  1155. const struct AVCodec *codec;
  1156. enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
  1157. /**
  1158. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1159. * This is used to work around some encoder bugs.
  1160. * A demuxer should set this to what is stored in the field used to identify the codec.
  1161. * If there are multiple such fields in a container then the demuxer should choose the one
  1162. * which maximizes the information about the used codec.
  1163. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  1164. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  1165. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  1166. * first.
  1167. * - encoding: Set by user, if not then the default based on codec_id will be used.
  1168. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  1169. */
  1170. unsigned int codec_tag;
  1171. void *priv_data;
  1172. /**
  1173. * Private context used for internal data.
  1174. *
  1175. * Unlike priv_data, this is not codec-specific. It is used in general
  1176. * libavcodec functions.
  1177. */
  1178. struct AVCodecInternal *internal;
  1179. /**
  1180. * Private data of the user, can be used to carry app specific stuff.
  1181. * - encoding: Set by user.
  1182. * - decoding: Set by user.
  1183. */
  1184. void *opaque;
  1185. /**
  1186. * the average bitrate
  1187. * - encoding: Set by user; unused for constant quantizer encoding.
  1188. * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
  1189. */
  1190. int bit_rate;
  1191. /**
  1192. * number of bits the bitstream is allowed to diverge from the reference.
  1193. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  1194. * - encoding: Set by user; unused for constant quantizer encoding.
  1195. * - decoding: unused
  1196. */
  1197. int bit_rate_tolerance;
  1198. /**
  1199. * Global quality for codecs which cannot change it per frame.
  1200. * This should be proportional to MPEG-1/2/4 qscale.
  1201. * - encoding: Set by user.
  1202. * - decoding: unused
  1203. */
  1204. int global_quality;
  1205. /**
  1206. * - encoding: Set by user.
  1207. * - decoding: unused
  1208. */
  1209. int compression_level;
  1210. #define FF_COMPRESSION_DEFAULT -1
  1211. /**
  1212. * AV_CODEC_FLAG_*.
  1213. * - encoding: Set by user.
  1214. * - decoding: Set by user.
  1215. */
  1216. int flags;
  1217. /**
  1218. * AV_CODEC_FLAG2_*
  1219. * - encoding: Set by user.
  1220. * - decoding: Set by user.
  1221. */
  1222. int flags2;
  1223. /**
  1224. * some codecs need / can use extradata like Huffman tables.
  1225. * MJPEG: Huffman tables
  1226. * rv10: additional flags
  1227. * MPEG-4: global headers (they can be in the bitstream or here)
  1228. * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
  1229. * than extradata_size to avoid problems if it is read with the bitstream reader.
  1230. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  1231. * - encoding: Set/allocated/freed by libavcodec.
  1232. * - decoding: Set/allocated/freed by user.
  1233. */
  1234. uint8_t *extradata;
  1235. int extradata_size;
  1236. /**
  1237. * This is the fundamental unit of time (in seconds) in terms
  1238. * of which frame timestamps are represented. For fixed-fps content,
  1239. * timebase should be 1/framerate and timestamp increments should be
  1240. * identically 1.
  1241. * - encoding: MUST be set by user.
  1242. * - decoding: the use of this field for decoding is deprecated.
  1243. * Use framerate instead.
  1244. */
  1245. AVRational time_base;
  1246. /**
  1247. * For some codecs, the time base is closer to the field rate than the frame rate.
  1248. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  1249. * if no telecine is used ...
  1250. *
  1251. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  1252. */
  1253. int ticks_per_frame;
  1254. /**
  1255. * Codec delay.
  1256. *
  1257. * Video:
  1258. * Number of frames the decoded output will be delayed relative to the
  1259. * encoded input.
  1260. *
  1261. * Audio:
  1262. * For encoding, this field is unused (see initial_padding).
  1263. *
  1264. * For decoding, this is the number of samples the decoder needs to
  1265. * output before the decoder's output is valid. When seeking, you should
  1266. * start decoding this many samples prior to your desired seek point.
  1267. *
  1268. * - encoding: Set by libavcodec.
  1269. * - decoding: Set by libavcodec.
  1270. */
  1271. int delay;
  1272. /* video only */
  1273. /**
  1274. * picture width / height.
  1275. *
  1276. * @note Those fields may not match the values of the last
  1277. * AVFrame output by avcodec_decode_video2 due frame
  1278. * reordering.
  1279. *
  1280. * - encoding: MUST be set by user.
  1281. * - decoding: May be set by the user before opening the decoder if known e.g.
  1282. * from the container. Some decoders will require the dimensions
  1283. * to be set by the caller. During decoding, the decoder may
  1284. * overwrite those values as required while parsing the data.
  1285. */
  1286. int width, height;
  1287. /**
  1288. * Bitstream width / height, may be different from width/height e.g. when
  1289. * the decoded frame is cropped before being output.
  1290. *
  1291. * @note Those field may not match the value of the last
  1292. * AVFrame output by avcodec_receive_frame() due frame
  1293. * reordering.
  1294. *
  1295. * - encoding: unused
  1296. * - decoding: May be set by the user before opening the decoder if known
  1297. * e.g. from the container. During decoding, the decoder may
  1298. * overwrite those values as required while parsing the data.
  1299. */
  1300. int coded_width, coded_height;
  1301. /**
  1302. * the number of pictures in a group of pictures, or 0 for intra_only
  1303. * - encoding: Set by user.
  1304. * - decoding: unused
  1305. */
  1306. int gop_size;
  1307. /**
  1308. * Pixel format, see AV_PIX_FMT_xxx.
  1309. * May be set by the demuxer if known from headers.
  1310. * May be overridden by the decoder if it knows better.
  1311. *
  1312. * @note This field may not match the value of the last
  1313. * AVFrame output by avcodec_receive_frame() due frame
  1314. * reordering.
  1315. *
  1316. * - encoding: Set by user.
  1317. * - decoding: Set by user if known, overridden by libavcodec while
  1318. * parsing the data.
  1319. */
  1320. enum AVPixelFormat pix_fmt;
  1321. /**
  1322. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  1323. * decoder to draw a horizontal band. It improves cache usage. Not
  1324. * all codecs can do that. You must check the codec capabilities
  1325. * beforehand.
  1326. * When multithreading is used, it may be called from multiple threads
  1327. * at the same time; threads might draw different parts of the same AVFrame,
  1328. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  1329. * in order.
  1330. * The function is also used by hardware acceleration APIs.
  1331. * It is called at least once during frame decoding to pass
  1332. * the data needed for hardware render.
  1333. * In that mode instead of pixel data, AVFrame points to
  1334. * a structure specific to the acceleration API. The application
  1335. * reads the structure and can change some fields to indicate progress
  1336. * or mark state.
  1337. * - encoding: unused
  1338. * - decoding: Set by user.
  1339. * @param height the height of the slice
  1340. * @param y the y position of the slice
  1341. * @param type 1->top field, 2->bottom field, 3->frame
  1342. * @param offset offset into the AVFrame.data from which the slice should be read
  1343. */
  1344. void (*draw_horiz_band)(struct AVCodecContext *s,
  1345. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  1346. int y, int type, int height);
  1347. /**
  1348. * callback to negotiate the pixelFormat
  1349. * @param fmt is the list of formats which are supported by the codec,
  1350. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  1351. * The first is always the native one.
  1352. * @note The callback may be called again immediately if initialization for
  1353. * the selected (hardware-accelerated) pixel format failed.
  1354. * @warning Behavior is undefined if the callback returns a value not
  1355. * in the fmt list of formats.
  1356. * @return the chosen format
  1357. * - encoding: unused
  1358. * - decoding: Set by user, if not set the native format will be chosen.
  1359. */
  1360. enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  1361. /**
  1362. * maximum number of B-frames between non-B-frames
  1363. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  1364. * - encoding: Set by user.
  1365. * - decoding: unused
  1366. */
  1367. int max_b_frames;
  1368. /**
  1369. * qscale factor between IP and B-frames
  1370. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  1371. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1372. * - encoding: Set by user.
  1373. * - decoding: unused
  1374. */
  1375. float b_quant_factor;
  1376. #if FF_API_PRIVATE_OPT
  1377. /** @deprecated use encoder private options instead */
  1378. attribute_deprecated
  1379. int b_frame_strategy;
  1380. #endif
  1381. /**
  1382. * qscale offset between IP and B-frames
  1383. * - encoding: Set by user.
  1384. * - decoding: unused
  1385. */
  1386. float b_quant_offset;
  1387. /**
  1388. * Size of the frame reordering buffer in the decoder.
  1389. * For MPEG-2 it is 1 IPB or 0 low delay IP.
  1390. * - encoding: Set by libavcodec.
  1391. * - decoding: Set by libavcodec.
  1392. */
  1393. int has_b_frames;
  1394. #if FF_API_PRIVATE_OPT
  1395. /** @deprecated use encoder private options instead */
  1396. attribute_deprecated
  1397. int mpeg_quant;
  1398. #endif
  1399. /**
  1400. * qscale factor between P- and I-frames
  1401. * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset).
  1402. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1403. * - encoding: Set by user.
  1404. * - decoding: unused
  1405. */
  1406. float i_quant_factor;
  1407. /**
  1408. * qscale offset between P and I-frames
  1409. * - encoding: Set by user.
  1410. * - decoding: unused
  1411. */
  1412. float i_quant_offset;
  1413. /**
  1414. * luminance masking (0-> disabled)
  1415. * - encoding: Set by user.
  1416. * - decoding: unused
  1417. */
  1418. float lumi_masking;
  1419. /**
  1420. * temporary complexity masking (0-> disabled)
  1421. * - encoding: Set by user.
  1422. * - decoding: unused
  1423. */
  1424. float temporal_cplx_masking;
  1425. /**
  1426. * spatial complexity masking (0-> disabled)
  1427. * - encoding: Set by user.
  1428. * - decoding: unused
  1429. */
  1430. float spatial_cplx_masking;
  1431. /**
  1432. * p block masking (0-> disabled)
  1433. * - encoding: Set by user.
  1434. * - decoding: unused
  1435. */
  1436. float p_masking;
  1437. /**
  1438. * darkness masking (0-> disabled)
  1439. * - encoding: Set by user.
  1440. * - decoding: unused
  1441. */
  1442. float dark_masking;
  1443. /**
  1444. * slice count
  1445. * - encoding: Set by libavcodec.
  1446. * - decoding: Set by user (or 0).
  1447. */
  1448. int slice_count;
  1449. #if FF_API_PRIVATE_OPT
  1450. /** @deprecated use encoder private options instead */
  1451. attribute_deprecated
  1452. int prediction_method;
  1453. #define FF_PRED_LEFT 0
  1454. #define FF_PRED_PLANE 1
  1455. #define FF_PRED_MEDIAN 2
  1456. #endif
  1457. /**
  1458. * slice offsets in the frame in bytes
  1459. * - encoding: Set/allocated by libavcodec.
  1460. * - decoding: Set/allocated by user (or NULL).
  1461. */
  1462. int *slice_offset;
  1463. /**
  1464. * sample aspect ratio (0 if unknown)
  1465. * That is the width of a pixel divided by the height of the pixel.
  1466. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  1467. * - encoding: Set by user.
  1468. * - decoding: Set by libavcodec.
  1469. */
  1470. AVRational sample_aspect_ratio;
  1471. /**
  1472. * motion estimation comparison function
  1473. * - encoding: Set by user.
  1474. * - decoding: unused
  1475. */
  1476. int me_cmp;
  1477. /**
  1478. * subpixel motion estimation comparison function
  1479. * - encoding: Set by user.
  1480. * - decoding: unused
  1481. */
  1482. int me_sub_cmp;
  1483. /**
  1484. * macroblock comparison function (not supported yet)
  1485. * - encoding: Set by user.
  1486. * - decoding: unused
  1487. */
  1488. int mb_cmp;
  1489. /**
  1490. * interlaced DCT comparison function
  1491. * - encoding: Set by user.
  1492. * - decoding: unused
  1493. */
  1494. int ildct_cmp;
  1495. #define FF_CMP_SAD 0
  1496. #define FF_CMP_SSE 1
  1497. #define FF_CMP_SATD 2
  1498. #define FF_CMP_DCT 3
  1499. #define FF_CMP_PSNR 4
  1500. #define FF_CMP_BIT 5
  1501. #define FF_CMP_RD 6
  1502. #define FF_CMP_ZERO 7
  1503. #define FF_CMP_VSAD 8
  1504. #define FF_CMP_VSSE 9
  1505. #define FF_CMP_NSSE 10
  1506. #define FF_CMP_DCTMAX 13
  1507. #define FF_CMP_DCT264 14
  1508. #define FF_CMP_CHROMA 256
  1509. /**
  1510. * ME diamond size & shape
  1511. * - encoding: Set by user.
  1512. * - decoding: unused
  1513. */
  1514. int dia_size;
  1515. /**
  1516. * amount of previous MV predictors (2a+1 x 2a+1 square)
  1517. * - encoding: Set by user.
  1518. * - decoding: unused
  1519. */
  1520. int last_predictor_count;
  1521. #if FF_API_PRIVATE_OPT
  1522. /** @deprecated use encoder private options instead */
  1523. attribute_deprecated
  1524. int pre_me;
  1525. #endif
  1526. /**
  1527. * motion estimation prepass comparison function
  1528. * - encoding: Set by user.
  1529. * - decoding: unused
  1530. */
  1531. int me_pre_cmp;
  1532. /**
  1533. * ME prepass diamond size & shape
  1534. * - encoding: Set by user.
  1535. * - decoding: unused
  1536. */
  1537. int pre_dia_size;
  1538. /**
  1539. * subpel ME quality
  1540. * - encoding: Set by user.
  1541. * - decoding: unused
  1542. */
  1543. int me_subpel_quality;
  1544. /**
  1545. * maximum motion estimation search range in subpel units
  1546. * If 0 then no limit.
  1547. *
  1548. * - encoding: Set by user.
  1549. * - decoding: unused
  1550. */
  1551. int me_range;
  1552. /**
  1553. * slice flags
  1554. * - encoding: unused
  1555. * - decoding: Set by user.
  1556. */
  1557. int slice_flags;
  1558. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  1559. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
  1560. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  1561. /**
  1562. * macroblock decision mode
  1563. * - encoding: Set by user.
  1564. * - decoding: unused
  1565. */
  1566. int mb_decision;
  1567. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  1568. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  1569. #define FF_MB_DECISION_RD 2 ///< rate distortion
  1570. /**
  1571. * custom intra quantization matrix
  1572. * - encoding: Set by user, can be NULL.
  1573. * - decoding: Set by libavcodec.
  1574. */
  1575. uint16_t *intra_matrix;
  1576. /**
  1577. * custom inter quantization matrix
  1578. * - encoding: Set by user, can be NULL.
  1579. * - decoding: Set by libavcodec.
  1580. */
  1581. uint16_t *inter_matrix;
  1582. #if FF_API_PRIVATE_OPT
  1583. /** @deprecated use encoder private options instead */
  1584. attribute_deprecated
  1585. int scenechange_threshold;
  1586. /** @deprecated use encoder private options instead */
  1587. attribute_deprecated
  1588. int noise_reduction;
  1589. #endif
  1590. /**
  1591. * precision of the intra DC coefficient - 8
  1592. * - encoding: Set by user.
  1593. * - decoding: unused
  1594. */
  1595. int intra_dc_precision;
  1596. /**
  1597. * Number of macroblock rows at the top which are skipped.
  1598. * - encoding: unused
  1599. * - decoding: Set by user.
  1600. */
  1601. int skip_top;
  1602. /**
  1603. * Number of macroblock rows at the bottom which are skipped.
  1604. * - encoding: unused
  1605. * - decoding: Set by user.
  1606. */
  1607. int skip_bottom;
  1608. /**
  1609. * minimum MB Lagrange multiplier
  1610. * - encoding: Set by user.
  1611. * - decoding: unused
  1612. */
  1613. int mb_lmin;
  1614. /**
  1615. * maximum MB Lagrange multiplier
  1616. * - encoding: Set by user.
  1617. * - decoding: unused
  1618. */
  1619. int mb_lmax;
  1620. #if FF_API_PRIVATE_OPT
  1621. /**
  1622. * @deprecated use encoder private options instead
  1623. */
  1624. attribute_deprecated
  1625. int me_penalty_compensation;
  1626. #endif
  1627. /**
  1628. * - encoding: Set by user.
  1629. * - decoding: unused
  1630. */
  1631. int bidir_refine;
  1632. #if FF_API_PRIVATE_OPT
  1633. /** @deprecated use encoder private options instead */
  1634. attribute_deprecated
  1635. int brd_scale;
  1636. #endif
  1637. /**
  1638. * minimum GOP size
  1639. * - encoding: Set by user.
  1640. * - decoding: unused
  1641. */
  1642. int keyint_min;
  1643. /**
  1644. * number of reference frames
  1645. * - encoding: Set by user.
  1646. * - decoding: Set by lavc.
  1647. */
  1648. int refs;
  1649. #if FF_API_PRIVATE_OPT
  1650. /** @deprecated use encoder private options instead */
  1651. attribute_deprecated
  1652. int chromaoffset;
  1653. #endif
  1654. /**
  1655. * Note: Value depends upon the compare function used for fullpel ME.
  1656. * - encoding: Set by user.
  1657. * - decoding: unused
  1658. */
  1659. int mv0_threshold;
  1660. #if FF_API_PRIVATE_OPT
  1661. /** @deprecated use encoder private options instead */
  1662. attribute_deprecated
  1663. int b_sensitivity;
  1664. #endif
  1665. /**
  1666. * Chromaticity coordinates of the source primaries.
  1667. * - encoding: Set by user
  1668. * - decoding: Set by libavcodec
  1669. */
  1670. enum AVColorPrimaries color_primaries;
  1671. /**
  1672. * Color Transfer Characteristic.
  1673. * - encoding: Set by user
  1674. * - decoding: Set by libavcodec
  1675. */
  1676. enum AVColorTransferCharacteristic color_trc;
  1677. /**
  1678. * YUV colorspace type.
  1679. * - encoding: Set by user
  1680. * - decoding: Set by libavcodec
  1681. */
  1682. enum AVColorSpace colorspace;
  1683. /**
  1684. * MPEG vs JPEG YUV range.
  1685. * - encoding: Set by user
  1686. * - decoding: Set by libavcodec
  1687. */
  1688. enum AVColorRange color_range;
  1689. /**
  1690. * This defines the location of chroma samples.
  1691. * - encoding: Set by user
  1692. * - decoding: Set by libavcodec
  1693. */
  1694. enum AVChromaLocation chroma_sample_location;
  1695. /**
  1696. * Number of slices.
  1697. * Indicates number of picture subdivisions. Used for parallelized
  1698. * decoding.
  1699. * - encoding: Set by user
  1700. * - decoding: unused
  1701. */
  1702. int slices;
  1703. /** Field order
  1704. * - encoding: set by libavcodec
  1705. * - decoding: Set by libavcodec
  1706. */
  1707. enum AVFieldOrder field_order;
  1708. /* audio only */
  1709. int sample_rate; ///< samples per second
  1710. int channels; ///< number of audio channels
  1711. /**
  1712. * audio sample format
  1713. * - encoding: Set by user.
  1714. * - decoding: Set by libavcodec.
  1715. */
  1716. enum AVSampleFormat sample_fmt; ///< sample format
  1717. /* The following data should not be initialized. */
  1718. /**
  1719. * Number of samples per channel in an audio frame.
  1720. *
  1721. * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
  1722. * except the last must contain exactly frame_size samples per channel.
  1723. * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
  1724. * frame size is not restricted.
  1725. * - decoding: may be set by some decoders to indicate constant frame size
  1726. */
  1727. int frame_size;
  1728. /**
  1729. * Frame counter, set by libavcodec.
  1730. *
  1731. * - decoding: total number of frames returned from the decoder so far.
  1732. * - encoding: total number of frames passed to the encoder so far.
  1733. *
  1734. * @note the counter is not incremented if encoding/decoding resulted in
  1735. * an error.
  1736. */
  1737. int frame_number;
  1738. /**
  1739. * number of bytes per packet if constant and known or 0
  1740. * Used by some WAV based audio codecs.
  1741. */
  1742. int block_align;
  1743. /**
  1744. * Audio cutoff bandwidth (0 means "automatic")
  1745. * - encoding: Set by user.
  1746. * - decoding: unused
  1747. */
  1748. int cutoff;
  1749. /**
  1750. * Audio channel layout.
  1751. * - encoding: set by user.
  1752. * - decoding: set by libavcodec.
  1753. */
  1754. uint64_t channel_layout;
  1755. /**
  1756. * Request decoder to use this channel layout if it can (0 for default)
  1757. * - encoding: unused
  1758. * - decoding: Set by user.
  1759. */
  1760. uint64_t request_channel_layout;
  1761. /**
  1762. * Type of service that the audio stream conveys.
  1763. * - encoding: Set by user.
  1764. * - decoding: Set by libavcodec.
  1765. */
  1766. enum AVAudioServiceType audio_service_type;
  1767. /**
  1768. * Used to request a sample format from the decoder.
  1769. * - encoding: unused.
  1770. * - decoding: Set by user.
  1771. */
  1772. enum AVSampleFormat request_sample_fmt;
  1773. /**
  1774. * This callback is called at the beginning of each frame to get data
  1775. * buffer(s) for it. There may be one contiguous buffer for all the data or
  1776. * there may be a buffer per each data plane or anything in between. What
  1777. * this means is, you may set however many entries in buf[] you feel necessary.
  1778. * Each buffer must be reference-counted using the AVBuffer API (see description
  1779. * of buf[] below).
  1780. *
  1781. * The following fields will be set in the frame before this callback is
  1782. * called:
  1783. * - format
  1784. * - width, height (video only)
  1785. * - sample_rate, channel_layout, nb_samples (audio only)
  1786. * Their values may differ from the corresponding values in
  1787. * AVCodecContext. This callback must use the frame values, not the codec
  1788. * context values, to calculate the required buffer size.
  1789. *
  1790. * This callback must fill the following fields in the frame:
  1791. * - data[]
  1792. * - linesize[]
  1793. * - extended_data:
  1794. * * if the data is planar audio with more than 8 channels, then this
  1795. * callback must allocate and fill extended_data to contain all pointers
  1796. * to all data planes. data[] must hold as many pointers as it can.
  1797. * extended_data must be allocated with av_malloc() and will be freed in
  1798. * av_frame_unref().
  1799. * * otherwise extended_data must point to data
  1800. * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
  1801. * the frame's data and extended_data pointers must be contained in these. That
  1802. * is, one AVBufferRef for each allocated chunk of memory, not necessarily one
  1803. * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
  1804. * and av_buffer_ref().
  1805. * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
  1806. * this callback and filled with the extra buffers if there are more
  1807. * buffers than buf[] can hold. extended_buf will be freed in
  1808. * av_frame_unref().
  1809. *
  1810. * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
  1811. * avcodec_default_get_buffer2() instead of providing buffers allocated by
  1812. * some other means.
  1813. *
  1814. * Each data plane must be aligned to the maximum required by the target
  1815. * CPU.
  1816. *
  1817. * @see avcodec_default_get_buffer2()
  1818. *
  1819. * Video:
  1820. *
  1821. * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
  1822. * (read and/or written to if it is writable) later by libavcodec.
  1823. *
  1824. * avcodec_align_dimensions2() should be used to find the required width and
  1825. * height, as they normally need to be rounded up to the next multiple of 16.
  1826. *
  1827. * If frame multithreading is used and thread_safe_callbacks is set,
  1828. * this callback may be called from a different thread, but not from more
  1829. * than one at once. Does not need to be reentrant.
  1830. *
  1831. * @see avcodec_align_dimensions2()
  1832. *
  1833. * Audio:
  1834. *
  1835. * Decoders request a buffer of a particular size by setting
  1836. * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
  1837. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  1838. * to a smaller value in the output frame.
  1839. *
  1840. * As a convenience, av_samples_get_buffer_size() and
  1841. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
  1842. * functions to find the required data size and to fill data pointers and
  1843. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  1844. * since all planes must be the same size.
  1845. *
  1846. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  1847. *
  1848. * - encoding: unused
  1849. * - decoding: Set by libavcodec, user can override.
  1850. */
  1851. int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
  1852. /**
  1853. * If non-zero, the decoded audio and video frames returned from
  1854. * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
  1855. * and are valid indefinitely. The caller must free them with
  1856. * av_frame_unref() when they are not needed anymore.
  1857. * Otherwise, the decoded frames must not be freed by the caller and are
  1858. * only valid until the next decode call.
  1859. *
  1860. * This is always automatically enabled if avcodec_receive_frame() is used.
  1861. *
  1862. * - encoding: unused
  1863. * - decoding: set by the caller before avcodec_open2().
  1864. */
  1865. attribute_deprecated int refcounted_frames;
  1866. /* - encoding parameters */
  1867. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  1868. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  1869. /**
  1870. * minimum quantizer
  1871. * - encoding: Set by user.
  1872. * - decoding: unused
  1873. */
  1874. int qmin;
  1875. /**
  1876. * maximum quantizer
  1877. * - encoding: Set by user.
  1878. * - decoding: unused
  1879. */
  1880. int qmax;
  1881. /**
  1882. * maximum quantizer difference between frames
  1883. * - encoding: Set by user.
  1884. * - decoding: unused
  1885. */
  1886. int max_qdiff;
  1887. /**
  1888. * decoder bitstream buffer size
  1889. * - encoding: Set by user.
  1890. * - decoding: unused
  1891. */
  1892. int rc_buffer_size;
  1893. /**
  1894. * ratecontrol override, see RcOverride
  1895. * - encoding: Allocated/set/freed by user.
  1896. * - decoding: unused
  1897. */
  1898. int rc_override_count;
  1899. RcOverride *rc_override;
  1900. /**
  1901. * maximum bitrate
  1902. * - encoding: Set by user.
  1903. * - decoding: unused
  1904. */
  1905. int rc_max_rate;
  1906. /**
  1907. * minimum bitrate
  1908. * - encoding: Set by user.
  1909. * - decoding: unused
  1910. */
  1911. int rc_min_rate;
  1912. /**
  1913. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  1914. * - encoding: Set by user.
  1915. * - decoding: unused.
  1916. */
  1917. float rc_max_available_vbv_use;
  1918. /**
  1919. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  1920. * - encoding: Set by user.
  1921. * - decoding: unused.
  1922. */
  1923. float rc_min_vbv_overflow_use;
  1924. /**
  1925. * Number of bits which should be loaded into the rc buffer before decoding starts.
  1926. * - encoding: Set by user.
  1927. * - decoding: unused
  1928. */
  1929. int rc_initial_buffer_occupancy;
  1930. #if FF_API_CODER_TYPE
  1931. #define FF_CODER_TYPE_VLC 0
  1932. #define FF_CODER_TYPE_AC 1
  1933. #define FF_CODER_TYPE_RAW 2
  1934. #define FF_CODER_TYPE_RLE 3
  1935. /**
  1936. * @deprecated use encoder private options instead
  1937. */
  1938. attribute_deprecated
  1939. int coder_type;
  1940. #endif /* FF_API_CODER_TYPE */
  1941. #if FF_API_PRIVATE_OPT
  1942. /** @deprecated use encoder private options instead */
  1943. attribute_deprecated
  1944. int context_model;
  1945. #endif
  1946. #if FF_API_PRIVATE_OPT
  1947. /** @deprecated use encoder private options instead */
  1948. attribute_deprecated
  1949. int frame_skip_threshold;
  1950. /** @deprecated use encoder private options instead */
  1951. attribute_deprecated
  1952. int frame_skip_factor;
  1953. /** @deprecated use encoder private options instead */
  1954. attribute_deprecated
  1955. int frame_skip_exp;
  1956. /** @deprecated use encoder private options instead */
  1957. attribute_deprecated
  1958. int frame_skip_cmp;
  1959. #endif /* FF_API_PRIVATE_OPT */
  1960. /**
  1961. * trellis RD quantization
  1962. * - encoding: Set by user.
  1963. * - decoding: unused
  1964. */
  1965. int trellis;
  1966. #if FF_API_PRIVATE_OPT
  1967. /** @deprecated use encoder private options instead */
  1968. attribute_deprecated
  1969. int min_prediction_order;
  1970. /** @deprecated use encoder private options instead */
  1971. attribute_deprecated
  1972. int max_prediction_order;
  1973. /** @deprecated use encoder private options instead */
  1974. attribute_deprecated
  1975. int64_t timecode_frame_start;
  1976. #endif
  1977. #if FF_API_RTP_CALLBACK
  1978. /**
  1979. * @deprecated unused
  1980. */
  1981. /* The RTP callback: This function is called */
  1982. /* every time the encoder has a packet to send. */
  1983. /* It depends on the encoder if the data starts */
  1984. /* with a Start Code (it should). H.263 does. */
  1985. /* mb_nb contains the number of macroblocks */
  1986. /* encoded in the RTP payload. */
  1987. attribute_deprecated
  1988. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  1989. #endif
  1990. #if FF_API_PRIVATE_OPT
  1991. /** @deprecated use encoder private options instead */
  1992. attribute_deprecated
  1993. int rtp_payload_size; /* The size of the RTP payload: the coder will */
  1994. /* do its best to deliver a chunk with size */
  1995. /* below rtp_payload_size, the chunk will start */
  1996. /* with a start code on some codecs like H.263. */
  1997. /* This doesn't take account of any particular */
  1998. /* headers inside the transmitted RTP payload. */
  1999. #endif
  2000. #if FF_API_STAT_BITS
  2001. /* statistics, used for 2-pass encoding */
  2002. attribute_deprecated
  2003. int mv_bits;
  2004. attribute_deprecated
  2005. int header_bits;
  2006. attribute_deprecated
  2007. int i_tex_bits;
  2008. attribute_deprecated
  2009. int p_tex_bits;
  2010. attribute_deprecated
  2011. int i_count;
  2012. attribute_deprecated
  2013. int p_count;
  2014. attribute_deprecated
  2015. int skip_count;
  2016. attribute_deprecated
  2017. int misc_bits;
  2018. /** @deprecated this field is unused */
  2019. attribute_deprecated
  2020. int frame_bits;
  2021. #endif
  2022. /**
  2023. * pass1 encoding statistics output buffer
  2024. * - encoding: Set by libavcodec.
  2025. * - decoding: unused
  2026. */
  2027. char *stats_out;
  2028. /**
  2029. * pass2 encoding statistics input buffer
  2030. * Concatenated stuff from stats_out of pass1 should be placed here.
  2031. * - encoding: Allocated/set/freed by user.
  2032. * - decoding: unused
  2033. */
  2034. char *stats_in;
  2035. /**
  2036. * Work around bugs in encoders which sometimes cannot be detected automatically.
  2037. * - encoding: Set by user
  2038. * - decoding: Set by user
  2039. */
  2040. int workaround_bugs;
  2041. #define FF_BUG_AUTODETECT 1 ///< autodetection
  2042. #define FF_BUG_XVID_ILACE 4
  2043. #define FF_BUG_UMP4 8
  2044. #define FF_BUG_NO_PADDING 16
  2045. #define FF_BUG_AMV 32
  2046. #define FF_BUG_QPEL_CHROMA 64
  2047. #define FF_BUG_STD_QPEL 128
  2048. #define FF_BUG_QPEL_CHROMA2 256
  2049. #define FF_BUG_DIRECT_BLOCKSIZE 512
  2050. #define FF_BUG_EDGE 1024
  2051. #define FF_BUG_HPEL_CHROMA 2048
  2052. #define FF_BUG_DC_CLIP 4096
  2053. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  2054. #define FF_BUG_TRUNCATED 16384
  2055. /**
  2056. * strictly follow the standard (MPEG-4, ...).
  2057. * - encoding: Set by user.
  2058. * - decoding: Set by user.
  2059. * Setting this to STRICT or higher means the encoder and decoder will
  2060. * generally do stupid things, whereas setting it to unofficial or lower
  2061. * will mean the encoder might produce output that is not supported by all
  2062. * spec-compliant decoders. Decoders don't differentiate between normal,
  2063. * unofficial and experimental (that is, they always try to decode things
  2064. * when they can) unless they are explicitly asked to behave stupidly
  2065. * (=strictly conform to the specs)
  2066. */
  2067. int strict_std_compliance;
  2068. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
  2069. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  2070. #define FF_COMPLIANCE_NORMAL 0
  2071. #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
  2072. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  2073. /**
  2074. * error concealment flags
  2075. * - encoding: unused
  2076. * - decoding: Set by user.
  2077. */
  2078. int error_concealment;
  2079. #define FF_EC_GUESS_MVS 1
  2080. #define FF_EC_DEBLOCK 2
  2081. /**
  2082. * debug
  2083. * - encoding: Set by user.
  2084. * - decoding: Set by user.
  2085. */
  2086. int debug;
  2087. #define FF_DEBUG_PICT_INFO 1
  2088. #define FF_DEBUG_RC 2
  2089. #define FF_DEBUG_BITSTREAM 4
  2090. #define FF_DEBUG_MB_TYPE 8
  2091. #define FF_DEBUG_QP 16
  2092. #define FF_DEBUG_DCT_COEFF 0x00000040
  2093. #define FF_DEBUG_SKIP 0x00000080
  2094. #define FF_DEBUG_STARTCODE 0x00000100
  2095. #define FF_DEBUG_ER 0x00000400
  2096. #define FF_DEBUG_MMCO 0x00000800
  2097. #define FF_DEBUG_BUGS 0x00001000
  2098. #define FF_DEBUG_BUFFERS 0x00008000
  2099. #define FF_DEBUG_THREADS 0x00010000
  2100. /**
  2101. * Error recognition; may misdetect some more or less valid parts as errors.
  2102. * - encoding: unused
  2103. * - decoding: Set by user.
  2104. */
  2105. int err_recognition;
  2106. /**
  2107. * Verify checksums embedded in the bitstream (could be of either encoded or
  2108. * decoded data, depending on the codec) and print an error message on mismatch.
  2109. * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
  2110. * decoder returning an error.
  2111. */
  2112. #define AV_EF_CRCCHECK (1<<0)
  2113. #define AV_EF_BITSTREAM (1<<1)
  2114. #define AV_EF_BUFFER (1<<2)
  2115. #define AV_EF_EXPLODE (1<<3)
  2116. /**
  2117. * opaque 64-bit number (generally a PTS) that will be reordered and
  2118. * output in AVFrame.reordered_opaque
  2119. * - encoding: unused
  2120. * - decoding: Set by user.
  2121. */
  2122. int64_t reordered_opaque;
  2123. /**
  2124. * Hardware accelerator in use
  2125. * - encoding: unused.
  2126. * - decoding: Set by libavcodec
  2127. */
  2128. const struct AVHWAccel *hwaccel;
  2129. /**
  2130. * Hardware accelerator context.
  2131. * For some hardware accelerators, a global context needs to be
  2132. * provided by the user. In that case, this holds display-dependent
  2133. * data Libav cannot instantiate itself. Please refer to the
  2134. * Libav HW accelerator documentation to know how to fill this
  2135. * is. e.g. for VA API, this is a struct vaapi_context.
  2136. * - encoding: unused
  2137. * - decoding: Set by user
  2138. */
  2139. void *hwaccel_context;
  2140. /**
  2141. * error
  2142. * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
  2143. * - decoding: unused
  2144. */
  2145. uint64_t error[AV_NUM_DATA_POINTERS];
  2146. /**
  2147. * DCT algorithm, see FF_DCT_* below
  2148. * - encoding: Set by user.
  2149. * - decoding: unused
  2150. */
  2151. int dct_algo;
  2152. #define FF_DCT_AUTO 0
  2153. #define FF_DCT_FASTINT 1
  2154. #define FF_DCT_INT 2
  2155. #define FF_DCT_MMX 3
  2156. #define FF_DCT_ALTIVEC 5
  2157. #define FF_DCT_FAAN 6
  2158. /**
  2159. * IDCT algorithm, see FF_IDCT_* below.
  2160. * - encoding: Set by user.
  2161. * - decoding: Set by user.
  2162. */
  2163. int idct_algo;
  2164. #define FF_IDCT_AUTO 0
  2165. #define FF_IDCT_INT 1
  2166. #define FF_IDCT_SIMPLE 2
  2167. #define FF_IDCT_SIMPLEMMX 3
  2168. #define FF_IDCT_ARM 7
  2169. #define FF_IDCT_ALTIVEC 8
  2170. #define FF_IDCT_SIMPLEARM 10
  2171. #define FF_IDCT_XVID 14
  2172. #define FF_IDCT_SIMPLEARMV5TE 16
  2173. #define FF_IDCT_SIMPLEARMV6 17
  2174. #define FF_IDCT_FAAN 20
  2175. #define FF_IDCT_SIMPLENEON 22
  2176. /**
  2177. * bits per sample/pixel from the demuxer (needed for huffyuv).
  2178. * - encoding: Set by libavcodec.
  2179. * - decoding: Set by user.
  2180. */
  2181. int bits_per_coded_sample;
  2182. /**
  2183. * Bits per sample/pixel of internal libavcodec pixel/sample format.
  2184. * - encoding: set by user.
  2185. * - decoding: set by libavcodec.
  2186. */
  2187. int bits_per_raw_sample;
  2188. #if FF_API_CODED_FRAME
  2189. /**
  2190. * the picture in the bitstream
  2191. * - encoding: Set by libavcodec.
  2192. * - decoding: unused
  2193. *
  2194. * @deprecated use the quality factor packet side data instead
  2195. */
  2196. attribute_deprecated AVFrame *coded_frame;
  2197. #endif
  2198. /**
  2199. * thread count
  2200. * is used to decide how many independent tasks should be passed to execute()
  2201. * - encoding: Set by user.
  2202. * - decoding: Set by user.
  2203. */
  2204. int thread_count;
  2205. /**
  2206. * Which multithreading methods to use.
  2207. * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
  2208. * so clients which cannot provide future frames should not use it.
  2209. *
  2210. * - encoding: Set by user, otherwise the default is used.
  2211. * - decoding: Set by user, otherwise the default is used.
  2212. */
  2213. int thread_type;
  2214. #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
  2215. #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
  2216. /**
  2217. * Which multithreading methods are in use by the codec.
  2218. * - encoding: Set by libavcodec.
  2219. * - decoding: Set by libavcodec.
  2220. */
  2221. int active_thread_type;
  2222. /**
  2223. * Set by the client if its custom get_buffer() callback can be called
  2224. * synchronously from another thread, which allows faster multithreaded decoding.
  2225. * draw_horiz_band() will be called from other threads regardless of this setting.
  2226. * Ignored if the default get_buffer() is used.
  2227. * - encoding: Set by user.
  2228. * - decoding: Set by user.
  2229. */
  2230. int thread_safe_callbacks;
  2231. /**
  2232. * The codec may call this to execute several independent things.
  2233. * It will return only after finishing all tasks.
  2234. * The user may replace this with some multithreaded implementation,
  2235. * the default implementation will execute the parts serially.
  2236. * @param count the number of things to execute
  2237. * - encoding: Set by libavcodec, user can override.
  2238. * - decoding: Set by libavcodec, user can override.
  2239. */
  2240. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
  2241. /**
  2242. * The codec may call this to execute several independent things.
  2243. * It will return only after finishing all tasks.
  2244. * The user may replace this with some multithreaded implementation,
  2245. * the default implementation will execute the parts serially.
  2246. * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
  2247. * @param c context passed also to func
  2248. * @param count the number of things to execute
  2249. * @param arg2 argument passed unchanged to func
  2250. * @param ret return values of executed functions, must have space for "count" values. May be NULL.
  2251. * @param func function that will be called count times, with jobnr from 0 to count-1.
  2252. * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
  2253. * two instances of func executing at the same time will have the same threadnr.
  2254. * @return always 0 currently, but code should handle a future improvement where when any call to func
  2255. * returns < 0 no further calls to func may be done and < 0 is returned.
  2256. * - encoding: Set by libavcodec, user can override.
  2257. * - decoding: Set by libavcodec, user can override.
  2258. */
  2259. int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
  2260. /**
  2261. * noise vs. sse weight for the nsse comparison function
  2262. * - encoding: Set by user.
  2263. * - decoding: unused
  2264. */
  2265. int nsse_weight;
  2266. /**
  2267. * profile
  2268. * - encoding: Set by user.
  2269. * - decoding: Set by libavcodec.
  2270. */
  2271. int profile;
  2272. #define FF_PROFILE_UNKNOWN -99
  2273. #define FF_PROFILE_RESERVED -100
  2274. #define FF_PROFILE_AAC_MAIN 0
  2275. #define FF_PROFILE_AAC_LOW 1
  2276. #define FF_PROFILE_AAC_SSR 2
  2277. #define FF_PROFILE_AAC_LTP 3
  2278. #define FF_PROFILE_AAC_HE 4
  2279. #define FF_PROFILE_AAC_HE_V2 28
  2280. #define FF_PROFILE_AAC_LD 22
  2281. #define FF_PROFILE_AAC_ELD 38
  2282. #define FF_PROFILE_MPEG2_AAC_LOW 128
  2283. #define FF_PROFILE_MPEG2_AAC_HE 131
  2284. #define FF_PROFILE_DTS 20
  2285. #define FF_PROFILE_DTS_ES 30
  2286. #define FF_PROFILE_DTS_96_24 40
  2287. #define FF_PROFILE_DTS_HD_HRA 50
  2288. #define FF_PROFILE_DTS_HD_MA 60
  2289. #define FF_PROFILE_DTS_EXPRESS 70
  2290. #define FF_PROFILE_MPEG2_422 0
  2291. #define FF_PROFILE_MPEG2_HIGH 1
  2292. #define FF_PROFILE_MPEG2_SS 2
  2293. #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
  2294. #define FF_PROFILE_MPEG2_MAIN 4
  2295. #define FF_PROFILE_MPEG2_SIMPLE 5
  2296. #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
  2297. #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
  2298. #define FF_PROFILE_H264_BASELINE 66
  2299. #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
  2300. #define FF_PROFILE_H264_MAIN 77
  2301. #define FF_PROFILE_H264_EXTENDED 88
  2302. #define FF_PROFILE_H264_HIGH 100
  2303. #define FF_PROFILE_H264_HIGH_10 110
  2304. #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
  2305. #define FF_PROFILE_H264_MULTIVIEW_HIGH 118
  2306. #define FF_PROFILE_H264_HIGH_422 122
  2307. #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
  2308. #define FF_PROFILE_H264_STEREO_HIGH 128
  2309. #define FF_PROFILE_H264_HIGH_444 144
  2310. #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
  2311. #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
  2312. #define FF_PROFILE_H264_CAVLC_444 44
  2313. #define FF_PROFILE_VC1_SIMPLE 0
  2314. #define FF_PROFILE_VC1_MAIN 1
  2315. #define FF_PROFILE_VC1_COMPLEX 2
  2316. #define FF_PROFILE_VC1_ADVANCED 3
  2317. #define FF_PROFILE_MPEG4_SIMPLE 0
  2318. #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
  2319. #define FF_PROFILE_MPEG4_CORE 2
  2320. #define FF_PROFILE_MPEG4_MAIN 3
  2321. #define FF_PROFILE_MPEG4_N_BIT 4
  2322. #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
  2323. #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
  2324. #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
  2325. #define FF_PROFILE_MPEG4_HYBRID 8
  2326. #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
  2327. #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
  2328. #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
  2329. #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
  2330. #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
  2331. #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
  2332. #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
  2333. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 1
  2334. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 2
  2335. #define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION 32768
  2336. #define FF_PROFILE_JPEG2000_DCINEMA_2K 3
  2337. #define FF_PROFILE_JPEG2000_DCINEMA_4K 4
  2338. #define FF_PROFILE_VP9_0 0
  2339. #define FF_PROFILE_VP9_1 1
  2340. #define FF_PROFILE_VP9_2 2
  2341. #define FF_PROFILE_VP9_3 3
  2342. #define FF_PROFILE_HEVC_MAIN 1
  2343. #define FF_PROFILE_HEVC_MAIN_10 2
  2344. #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
  2345. #define FF_PROFILE_HEVC_REXT 4
  2346. #define FF_PROFILE_AV1_0 0
  2347. #define FF_PROFILE_AV1_1 1
  2348. #define FF_PROFILE_AV1_2 2
  2349. /**
  2350. * level
  2351. * - encoding: Set by user.
  2352. * - decoding: Set by libavcodec.
  2353. */
  2354. int level;
  2355. #define FF_LEVEL_UNKNOWN -99
  2356. /**
  2357. * - encoding: unused
  2358. * - decoding: Set by user.
  2359. */
  2360. enum AVDiscard skip_loop_filter;
  2361. /**
  2362. * - encoding: unused
  2363. * - decoding: Set by user.
  2364. */
  2365. enum AVDiscard skip_idct;
  2366. /**
  2367. * - encoding: unused
  2368. * - decoding: Set by user.
  2369. */
  2370. enum AVDiscard skip_frame;
  2371. /**
  2372. * Header containing style information for text subtitles.
  2373. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  2374. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  2375. * the Format line following. It shouldn't include any Dialogue line.
  2376. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  2377. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  2378. */
  2379. uint8_t *subtitle_header;
  2380. int subtitle_header_size;
  2381. #if FF_API_VBV_DELAY
  2382. /**
  2383. * VBV delay coded in the last frame (in periods of a 27 MHz clock).
  2384. * Used for compliant TS muxing.
  2385. * - encoding: Set by libavcodec.
  2386. * - decoding: unused.
  2387. * @deprecated this value is now exported as a part of
  2388. * AV_PKT_DATA_CPB_PROPERTIES packet side data
  2389. */
  2390. attribute_deprecated
  2391. uint64_t vbv_delay;
  2392. #endif
  2393. #if FF_API_SIDEDATA_ONLY_PKT
  2394. /**
  2395. * Encoding only and set by default. Allow encoders to output packets
  2396. * that do not contain any encoded data, only side data.
  2397. *
  2398. * Some encoders need to output such packets, e.g. to update some stream
  2399. * parameters at the end of encoding.
  2400. *
  2401. * @deprecated this field disables the default behaviour and
  2402. * it is kept only for compatibility.
  2403. */
  2404. attribute_deprecated
  2405. int side_data_only_packets;
  2406. #endif
  2407. /**
  2408. * Audio only. The number of "priming" samples (padding) inserted by the
  2409. * encoder at the beginning of the audio. I.e. this number of leading
  2410. * decoded samples must be discarded by the caller to get the original audio
  2411. * without leading padding.
  2412. *
  2413. * - decoding: unused
  2414. * - encoding: Set by libavcodec. The timestamps on the output packets are
  2415. * adjusted by the encoder so that they always refer to the
  2416. * first sample of the data actually contained in the packet,
  2417. * including any added padding. E.g. if the timebase is
  2418. * 1/samplerate and the timestamp of the first input sample is
  2419. * 0, the timestamp of the first output packet will be
  2420. * -initial_padding.
  2421. */
  2422. int initial_padding;
  2423. /*
  2424. * - decoding: For codecs that store a framerate value in the compressed
  2425. * bitstream, the decoder may export it here. { 0, 1} when
  2426. * unknown.
  2427. * - encoding: May be used to signal the framerate of CFR content to an
  2428. * encoder.
  2429. */
  2430. AVRational framerate;
  2431. /**
  2432. * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
  2433. * - encoding: unused.
  2434. * - decoding: Set by libavcodec before calling get_format()
  2435. */
  2436. enum AVPixelFormat sw_pix_fmt;
  2437. /**
  2438. * Additional data associated with the entire coded stream.
  2439. *
  2440. * - decoding: unused
  2441. * - encoding: may be set by libavcodec after avcodec_open2().
  2442. */
  2443. AVPacketSideData *coded_side_data;
  2444. int nb_coded_side_data;
  2445. /**
  2446. * A reference to the AVHWFramesContext describing the input (for encoding)
  2447. * or output (decoding) frames. The reference is set by the caller and
  2448. * afterwards owned (and freed) by libavcodec - it should never be read by
  2449. * the caller after being set.
  2450. *
  2451. * - decoding: This field should be set by the caller from the get_format()
  2452. * callback. The previous reference (if any) will always be
  2453. * unreffed by libavcodec before the get_format() call.
  2454. *
  2455. * If the default get_buffer2() is used with a hwaccel pixel
  2456. * format, then this AVHWFramesContext will be used for
  2457. * allocating the frame buffers.
  2458. *
  2459. * - encoding: For hardware encoders configured to use a hwaccel pixel
  2460. * format, this field should be set by the caller to a reference
  2461. * to the AVHWFramesContext describing input frames.
  2462. * AVHWFramesContext.format must be equal to
  2463. * AVCodecContext.pix_fmt.
  2464. *
  2465. * This field should be set before avcodec_open2() is called.
  2466. */
  2467. AVBufferRef *hw_frames_ctx;
  2468. /**
  2469. * Video decoding only. Certain video codecs support cropping, meaning that
  2470. * only a sub-rectangle of the decoded frame is intended for display. This
  2471. * option controls how cropping is handled by libavcodec.
  2472. *
  2473. * When set to 1 (the default), libavcodec will apply cropping internally.
  2474. * I.e. it will modify the output frame width/height fields and offset the
  2475. * data pointers (only by as much as possible while preserving alignment, or
  2476. * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
  2477. * the frames output by the decoder refer only to the cropped area. The
  2478. * crop_* fields of the output frames will be zero.
  2479. *
  2480. * When set to 0, the width/height fields of the output frames will be set
  2481. * to the coded dimensions and the crop_* fields will describe the cropping
  2482. * rectangle. Applying the cropping is left to the caller.
  2483. *
  2484. * @warning When hardware acceleration with opaque output frames is used,
  2485. * libavcodec is unable to apply cropping from the top/left border.
  2486. *
  2487. * @note when this option is set to zero, the width/height fields of the
  2488. * AVCodecContext and output AVFrames have different meanings. The codec
  2489. * context fields store display dimensions (with the coded dimensions in
  2490. * coded_width/height), while the frame fields store the coded dimensions
  2491. * (with the display dimensions being determined by the crop_* fields).
  2492. */
  2493. int apply_cropping;
  2494. /**
  2495. * A reference to the AVHWDeviceContext describing the device which will
  2496. * be used by a hardware encoder/decoder. The reference is set by the
  2497. * caller and afterwards owned (and freed) by libavcodec.
  2498. *
  2499. * This should be used if either the codec device does not require
  2500. * hardware frames or any that are used are to be allocated internally by
  2501. * libavcodec. If the user wishes to supply any of the frames used as
  2502. * encoder input or decoder output then hw_frames_ctx should be used
  2503. * instead. When hw_frames_ctx is set in get_format() for a decoder, this
  2504. * field will be ignored while decoding the associated stream segment, but
  2505. * may again be used on a following one after another get_format() call.
  2506. *
  2507. * For both encoders and decoders this field should be set before
  2508. * avcodec_open2() is called and must not be written to thereafter.
  2509. *
  2510. * Note that some decoders may require this field to be set initially in
  2511. * order to support hw_frames_ctx at all - in that case, all frames
  2512. * contexts used must be created on the same device.
  2513. */
  2514. AVBufferRef *hw_device_ctx;
  2515. /**
  2516. * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
  2517. * decoding (if active).
  2518. * - encoding: unused
  2519. * - decoding: Set by user (either before avcodec_open2(), or in the
  2520. * AVCodecContext.get_format callback)
  2521. */
  2522. int hwaccel_flags;
  2523. /**
  2524. * Video decoding only. Sets the number of extra hardware frames which
  2525. * the decoder will allocate for use by the caller. This must be set
  2526. * before avcodec_open2() is called.
  2527. *
  2528. * Some hardware decoders require all frames that they will use for
  2529. * output to be defined in advance before decoding starts. For such
  2530. * decoders, the hardware frame pool must therefore be of a fixed size.
  2531. * The extra frames set here are on top of any number that the decoder
  2532. * needs internally in order to operate normally (for example, frames
  2533. * used as reference pictures).
  2534. */
  2535. int extra_hw_frames;
  2536. } AVCodecContext;
  2537. /**
  2538. * AVProfile.
  2539. */
  2540. typedef struct AVProfile {
  2541. int profile;
  2542. const char *name; ///< short name for the profile
  2543. } AVProfile;
  2544. enum {
  2545. /**
  2546. * The codec supports this format via the hw_device_ctx interface.
  2547. *
  2548. * When selecting this format, AVCodecContext.hw_device_ctx should
  2549. * have been set to a device of the specified type before calling
  2550. * avcodec_open2().
  2551. */
  2552. AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01,
  2553. /**
  2554. * The codec supports this format via the hw_frames_ctx interface.
  2555. *
  2556. * When selecting this format for a decoder,
  2557. * AVCodecContext.hw_frames_ctx should be set to a suitable frames
  2558. * context inside the get_format() callback. The frames context
  2559. * must have been created on a device of the specified type.
  2560. */
  2561. AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02,
  2562. /**
  2563. * The codec supports this format by some internal method.
  2564. *
  2565. * This format can be selected without any additional configuration -
  2566. * no device or frames context is required.
  2567. */
  2568. AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 0x04,
  2569. /**
  2570. * The codec supports this format by some ad-hoc method.
  2571. *
  2572. * Additional settings and/or function calls are required. See the
  2573. * codec-specific documentation for details. (Methods requiring
  2574. * this sort of configuration are deprecated and others should be
  2575. * used in preference.)
  2576. */
  2577. AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 0x08,
  2578. };
  2579. typedef struct AVCodecHWConfig {
  2580. /**
  2581. * A hardware pixel format which the codec can use.
  2582. */
  2583. enum AVPixelFormat pix_fmt;
  2584. /**
  2585. * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
  2586. * setup methods which can be used with this configuration.
  2587. */
  2588. int methods;
  2589. /**
  2590. * The device type associated with the configuration.
  2591. *
  2592. * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
  2593. * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
  2594. */
  2595. enum AVHWDeviceType device_type;
  2596. } AVCodecHWConfig;
  2597. typedef struct AVCodecDefault AVCodecDefault;
  2598. struct AVSubtitle;
  2599. /**
  2600. * AVCodec.
  2601. */
  2602. typedef struct AVCodec {
  2603. /**
  2604. * Name of the codec implementation.
  2605. * The name is globally unique among encoders and among decoders (but an
  2606. * encoder and a decoder can share the same name).
  2607. * This is the primary way to find a codec from the user perspective.
  2608. */
  2609. const char *name;
  2610. /**
  2611. * Descriptive name for the codec, meant to be more human readable than name.
  2612. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  2613. */
  2614. const char *long_name;
  2615. enum AVMediaType type;
  2616. enum AVCodecID id;
  2617. /**
  2618. * Codec capabilities.
  2619. * see AV_CODEC_CAP_*
  2620. */
  2621. int capabilities;
  2622. const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
  2623. const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
  2624. const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
  2625. const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
  2626. const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
  2627. const AVClass *priv_class; ///< AVClass for the private context
  2628. const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
  2629. /**
  2630. * Group name of the codec implementation.
  2631. * This is a short symbolic name of the wrapper backing this codec. A
  2632. * wrapper uses some kind of external implementation for the codec, such
  2633. * as an external library, or a codec implementation provided by the OS or
  2634. * the hardware.
  2635. * If this field is NULL, this is a builtin, libavcodec native decoder.
  2636. * If non-NULL, this will be the suffix in AVCodec.name in most cases
  2637. * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
  2638. */
  2639. const char *wrapper_name;
  2640. /*****************************************************************
  2641. * No fields below this line are part of the public API. They
  2642. * may not be used outside of libavcodec and can be changed and
  2643. * removed at will.
  2644. * New public fields should be added right above.
  2645. *****************************************************************
  2646. */
  2647. int priv_data_size;
  2648. struct AVCodec *next;
  2649. /**
  2650. * @name Frame-level threading support functions
  2651. * @{
  2652. */
  2653. /**
  2654. * If defined, called on thread contexts when they are created.
  2655. * If the codec allocates writable tables in init(), re-allocate them here.
  2656. * priv_data will be set to a copy of the original.
  2657. */
  2658. int (*init_thread_copy)(AVCodecContext *);
  2659. /**
  2660. * Copy necessary context variables from a previous thread context to the current one.
  2661. * If not defined, the next thread will start automatically; otherwise, the codec
  2662. * must call ff_thread_finish_setup().
  2663. *
  2664. * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
  2665. */
  2666. int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
  2667. /** @} */
  2668. /**
  2669. * Private codec-specific defaults.
  2670. */
  2671. const AVCodecDefault *defaults;
  2672. /**
  2673. * Initialize codec static data, called from avcodec_register().
  2674. */
  2675. void (*init_static_data)(struct AVCodec *codec);
  2676. int (*init)(AVCodecContext *);
  2677. int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
  2678. const struct AVSubtitle *sub);
  2679. /**
  2680. * Encode data to an AVPacket.
  2681. *
  2682. * @param avctx codec context
  2683. * @param avpkt output AVPacket (may contain a user-provided buffer)
  2684. * @param[in] frame AVFrame containing the raw data to be encoded
  2685. * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
  2686. * non-empty packet was returned in avpkt.
  2687. * @return 0 on success, negative error code on failure
  2688. */
  2689. int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
  2690. int *got_packet_ptr);
  2691. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
  2692. int (*close)(AVCodecContext *);
  2693. /**
  2694. * Encode API with decoupled packet/frame dataflow. The API is the
  2695. * same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except
  2696. * that:
  2697. * - never called if the codec is closed or the wrong type,
  2698. * - if AV_CODEC_CAP_DELAY is not set, drain frames are never sent,
  2699. * - only one drain frame is ever passed down,
  2700. */
  2701. int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
  2702. int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
  2703. /**
  2704. * Decode API with decoupled packet/frame dataflow. This function is called
  2705. * to get one output frame. It should call ff_decode_get_packet() to obtain
  2706. * input data.
  2707. */
  2708. int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
  2709. /**
  2710. * Flush buffers.
  2711. * Will be called when seeking
  2712. */
  2713. void (*flush)(AVCodecContext *);
  2714. /**
  2715. * Internal codec capabilities.
  2716. * See FF_CODEC_CAP_* in internal.h
  2717. */
  2718. int caps_internal;
  2719. /**
  2720. * Decoding only, a comma-separated list of bitstream filters to apply to
  2721. * packets before decoding.
  2722. */
  2723. const char *bsfs;
  2724. /**
  2725. * Array of pointers to hardware configurations supported by the codec,
  2726. * or NULL if no hardware supported. The array is terminated by a NULL
  2727. * pointer.
  2728. *
  2729. * The user can only access this field via avcodec_get_hw_config().
  2730. */
  2731. const struct AVCodecHWConfigInternal **hw_configs;
  2732. } AVCodec;
  2733. /**
  2734. * Retrieve supported hardware configurations for a codec.
  2735. *
  2736. * Values of index from zero to some maximum return the indexed configuration
  2737. * descriptor; all other values return NULL. If the codec does not support
  2738. * any hardware configurations then it will always return NULL.
  2739. */
  2740. const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index);
  2741. /**
  2742. * @defgroup lavc_hwaccel AVHWAccel
  2743. *
  2744. * @note Nothing in this structure should be accessed by the user. At some
  2745. * point in future it will not be externally visible at all.
  2746. *
  2747. * @{
  2748. */
  2749. typedef struct AVHWAccel {
  2750. /**
  2751. * Name of the hardware accelerated codec.
  2752. * The name is globally unique among encoders and among decoders (but an
  2753. * encoder and a decoder can share the same name).
  2754. */
  2755. const char *name;
  2756. /**
  2757. * Type of codec implemented by the hardware accelerator.
  2758. *
  2759. * See AVMEDIA_TYPE_xxx
  2760. */
  2761. enum AVMediaType type;
  2762. /**
  2763. * Codec implemented by the hardware accelerator.
  2764. *
  2765. * See AV_CODEC_ID_xxx
  2766. */
  2767. enum AVCodecID id;
  2768. /**
  2769. * Supported pixel format.
  2770. *
  2771. * Only hardware accelerated formats are supported here.
  2772. */
  2773. enum AVPixelFormat pix_fmt;
  2774. /**
  2775. * Hardware accelerated codec capabilities.
  2776. * see FF_HWACCEL_CODEC_CAP_*
  2777. */
  2778. int capabilities;
  2779. /*****************************************************************
  2780. * No fields below this line are part of the public API. They
  2781. * may not be used outside of libavcodec and can be changed and
  2782. * removed at will.
  2783. * New public fields should be added right above.
  2784. *****************************************************************
  2785. */
  2786. struct AVHWAccel *next;
  2787. /**
  2788. * Allocate a custom buffer
  2789. */
  2790. int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
  2791. /**
  2792. * Called at the beginning of each frame or field picture.
  2793. *
  2794. * Meaningful frame information (codec specific) is guaranteed to
  2795. * be parsed at this point. This function is mandatory.
  2796. *
  2797. * Note that buf can be NULL along with buf_size set to 0.
  2798. * Otherwise, this means the whole frame is available at this point.
  2799. *
  2800. * @param avctx the codec context
  2801. * @param buf the frame data buffer base
  2802. * @param buf_size the size of the frame in bytes
  2803. * @return zero if successful, a negative value otherwise
  2804. */
  2805. int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2806. /**
  2807. * Callback for each slice.
  2808. *
  2809. * Meaningful slice information (codec specific) is guaranteed to
  2810. * be parsed at this point. This function is mandatory.
  2811. *
  2812. * @param avctx the codec context
  2813. * @param buf the slice data buffer base
  2814. * @param buf_size the size of the slice in bytes
  2815. * @return zero if successful, a negative value otherwise
  2816. */
  2817. int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2818. /**
  2819. * Called at the end of each frame or field picture.
  2820. *
  2821. * The whole picture is parsed at this point and can now be sent
  2822. * to the hardware accelerator. This function is mandatory.
  2823. *
  2824. * @param avctx the codec context
  2825. * @return zero if successful, a negative value otherwise
  2826. */
  2827. int (*end_frame)(AVCodecContext *avctx);
  2828. /**
  2829. * Size of per-frame hardware accelerator private data.
  2830. *
  2831. * Private data is allocated with av_mallocz() before
  2832. * AVCodecContext.get_buffer() and deallocated after
  2833. * AVCodecContext.release_buffer().
  2834. */
  2835. int frame_priv_data_size;
  2836. /**
  2837. * Initialize the hwaccel private data.
  2838. *
  2839. * This will be called from ff_get_format(), after hwaccel and
  2840. * hwaccel_context are set and the hwaccel private data in AVCodecInternal
  2841. * is allocated.
  2842. */
  2843. int (*init)(AVCodecContext *avctx);
  2844. /**
  2845. * Uninitialize the hwaccel private data.
  2846. *
  2847. * This will be called from get_format() or avcodec_close(), after hwaccel
  2848. * and hwaccel_context are already uninitialized.
  2849. */
  2850. int (*uninit)(AVCodecContext *avctx);
  2851. /**
  2852. * Size of the private data to allocate in
  2853. * AVCodecInternal.hwaccel_priv_data.
  2854. */
  2855. int priv_data_size;
  2856. /**
  2857. * Internal hwaccel capabilities.
  2858. */
  2859. int caps_internal;
  2860. /**
  2861. * Fill the given hw_frames context with current codec parameters. Called
  2862. * from get_format. Refer to avcodec_get_hw_frames_parameters() for
  2863. * details.
  2864. *
  2865. * This CAN be called before AVHWAccel.init is called, and you must assume
  2866. * that avctx->hwaccel_priv_data is invalid.
  2867. */
  2868. int (*frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
  2869. } AVHWAccel;
  2870. /**
  2871. * Hardware acceleration should be used for decoding even if the codec level
  2872. * used is unknown or higher than the maximum supported level reported by the
  2873. * hardware driver.
  2874. */
  2875. #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
  2876. /**
  2877. * Hardware acceleration can output YUV pixel formats with a different chroma
  2878. * sampling than 4:2:0 and/or other than 8 bits per component.
  2879. */
  2880. #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
  2881. /**
  2882. * Hardware acceleration should still be attempted for decoding when the
  2883. * codec profile does not match the reported capabilities of the hardware.
  2884. *
  2885. * For example, this can be used to try to decode baseline profile H.264
  2886. * streams in hardware - it will often succeed, because many streams marked
  2887. * as baseline profile actually conform to constrained baseline profile.
  2888. *
  2889. * @warning If the stream is actually not supported then the behaviour is
  2890. * undefined, and may include returning entirely incorrect output
  2891. * while indicating success.
  2892. */
  2893. #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2)
  2894. /**
  2895. * @}
  2896. */
  2897. #if FF_API_AVPICTURE
  2898. /**
  2899. * @defgroup lavc_picture AVPicture
  2900. *
  2901. * Functions for working with AVPicture
  2902. * @{
  2903. */
  2904. /**
  2905. * four components are given, that's all.
  2906. * the last component is alpha
  2907. * @deprecated Use the imgutils functions
  2908. */
  2909. typedef struct AVPicture {
  2910. attribute_deprecated
  2911. uint8_t *data[AV_NUM_DATA_POINTERS];
  2912. attribute_deprecated
  2913. int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
  2914. } AVPicture;
  2915. /**
  2916. * @}
  2917. */
  2918. #endif
  2919. #define AVPALETTE_SIZE 1024
  2920. #define AVPALETTE_COUNT 256
  2921. enum AVSubtitleType {
  2922. SUBTITLE_NONE,
  2923. SUBTITLE_BITMAP, ///< A bitmap, pict will be set
  2924. /**
  2925. * Plain text, the text field must be set by the decoder and is
  2926. * authoritative. ass and pict fields may contain approximations.
  2927. */
  2928. SUBTITLE_TEXT,
  2929. /**
  2930. * Formatted text, the ass field must be set by the decoder and is
  2931. * authoritative. pict and text fields may contain approximations.
  2932. */
  2933. SUBTITLE_ASS,
  2934. };
  2935. #define AV_SUBTITLE_FLAG_FORCED 0x00000001
  2936. typedef struct AVSubtitleRect {
  2937. int x; ///< top left corner of pict, undefined when pict is not set
  2938. int y; ///< top left corner of pict, undefined when pict is not set
  2939. int w; ///< width of pict, undefined when pict is not set
  2940. int h; ///< height of pict, undefined when pict is not set
  2941. int nb_colors; ///< number of colors in pict, undefined when pict is not set
  2942. #if FF_API_AVPICTURE
  2943. /**
  2944. * @deprecated unused
  2945. */
  2946. attribute_deprecated
  2947. AVPicture pict;
  2948. #endif
  2949. /**
  2950. * data+linesize for the bitmap of this subtitle.
  2951. * Can be set for text/ass as well once they are rendered.
  2952. */
  2953. uint8_t *data[4];
  2954. int linesize[4];
  2955. enum AVSubtitleType type;
  2956. char *text; ///< 0 terminated plain UTF-8 text
  2957. /**
  2958. * 0 terminated ASS/SSA compatible event line.
  2959. * The presentation of this is unaffected by the other values in this
  2960. * struct.
  2961. */
  2962. char *ass;
  2963. int flags;
  2964. } AVSubtitleRect;
  2965. typedef struct AVSubtitle {
  2966. uint16_t format; /* 0 = graphics */
  2967. uint32_t start_display_time; /* relative to packet pts, in ms */
  2968. uint32_t end_display_time; /* relative to packet pts, in ms */
  2969. unsigned num_rects;
  2970. AVSubtitleRect **rects;
  2971. int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
  2972. } AVSubtitle;
  2973. /**
  2974. * This struct describes the properties of an encoded stream.
  2975. *
  2976. * sizeof(AVCodecParameters) is not a part of the public ABI, this struct must
  2977. * be allocated with avcodec_parameters_alloc() and freed with
  2978. * avcodec_parameters_free().
  2979. */
  2980. typedef struct AVCodecParameters {
  2981. /**
  2982. * General type of the encoded data.
  2983. */
  2984. enum AVMediaType codec_type;
  2985. /**
  2986. * Specific type of the encoded data (the codec used).
  2987. */
  2988. enum AVCodecID codec_id;
  2989. /**
  2990. * Additional information about the codec (corresponds to the AVI FOURCC).
  2991. */
  2992. uint32_t codec_tag;
  2993. /**
  2994. * Extra binary data needed for initializing the decoder, codec-dependent.
  2995. *
  2996. * Must be allocated with av_malloc() and will be freed by
  2997. * avcodec_parameters_free(). The allocated size of extradata must be at
  2998. * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
  2999. * bytes zeroed.
  3000. */
  3001. uint8_t *extradata;
  3002. /**
  3003. * Size of the extradata content in bytes.
  3004. */
  3005. int extradata_size;
  3006. /**
  3007. * - video: the pixel format, the value corresponds to enum AVPixelFormat.
  3008. * - audio: the sample format, the value corresponds to enum AVSampleFormat.
  3009. */
  3010. int format;
  3011. /**
  3012. * The average bitrate of the encoded data (in bits per second).
  3013. */
  3014. int bit_rate;
  3015. int bits_per_coded_sample;
  3016. /**
  3017. * Codec-specific bitstream restrictions that the stream conforms to.
  3018. */
  3019. int profile;
  3020. int level;
  3021. /**
  3022. * Video only. The dimensions of the video frame in pixels.
  3023. */
  3024. int width;
  3025. int height;
  3026. /**
  3027. * Video only. The aspect ratio (width / height) which a single pixel
  3028. * should have when displayed.
  3029. *
  3030. * When the aspect ratio is unknown / undefined, the numerator should be
  3031. * set to 0 (the denominator may have any value).
  3032. */
  3033. AVRational sample_aspect_ratio;
  3034. /**
  3035. * Video only. The order of the fields in interlaced video.
  3036. */
  3037. enum AVFieldOrder field_order;
  3038. /**
  3039. * Video only. Additional colorspace characteristics.
  3040. */
  3041. enum AVColorRange color_range;
  3042. enum AVColorPrimaries color_primaries;
  3043. enum AVColorTransferCharacteristic color_trc;
  3044. enum AVColorSpace color_space;
  3045. enum AVChromaLocation chroma_location;
  3046. /**
  3047. * Audio only. The channel layout bitmask. May be 0 if the channel layout is
  3048. * unknown or unspecified, otherwise the number of bits set must be equal to
  3049. * the channels field.
  3050. */
  3051. uint64_t channel_layout;
  3052. /**
  3053. * Audio only. The number of audio channels.
  3054. */
  3055. int channels;
  3056. /**
  3057. * Audio only. The number of audio samples per second.
  3058. */
  3059. int sample_rate;
  3060. /**
  3061. * Audio only. The number of bytes per coded audio frame, required by some
  3062. * formats.
  3063. *
  3064. * Corresponds to nBlockAlign in WAVEFORMATEX.
  3065. */
  3066. int block_align;
  3067. /**
  3068. * Audio only. The amount of padding (in samples) inserted by the encoder at
  3069. * the beginning of the audio. I.e. this number of leading decoded samples
  3070. * must be discarded by the caller to get the original audio without leading
  3071. * padding.
  3072. */
  3073. int initial_padding;
  3074. /**
  3075. * Audio only. The amount of padding (in samples) appended by the encoder to
  3076. * the end of the audio. I.e. this number of decoded samples must be
  3077. * discarded by the caller from the end of the stream to get the original
  3078. * audio without any trailing padding.
  3079. */
  3080. int trailing_padding;
  3081. } AVCodecParameters;
  3082. /**
  3083. * If c is NULL, returns the first registered codec,
  3084. * if c is non-NULL, returns the next registered codec after c,
  3085. * or NULL if c is the last one.
  3086. */
  3087. AVCodec *av_codec_next(const AVCodec *c);
  3088. /**
  3089. * Return the LIBAVCODEC_VERSION_INT constant.
  3090. */
  3091. unsigned avcodec_version(void);
  3092. /**
  3093. * Return the libavcodec build-time configuration.
  3094. */
  3095. const char *avcodec_configuration(void);
  3096. /**
  3097. * Return the libavcodec license.
  3098. */
  3099. const char *avcodec_license(void);
  3100. /**
  3101. * Register the codec codec and initialize libavcodec.
  3102. *
  3103. * @warning either this function or avcodec_register_all() must be called
  3104. * before any other libavcodec functions.
  3105. *
  3106. * @see avcodec_register_all()
  3107. */
  3108. void avcodec_register(AVCodec *codec);
  3109. /**
  3110. * Register all the codecs, parsers and bitstream filters which were enabled at
  3111. * configuration time. If you do not call this function you can select exactly
  3112. * which formats you want to support, by using the individual registration
  3113. * functions.
  3114. *
  3115. * @see avcodec_register
  3116. * @see av_register_codec_parser
  3117. * @see av_register_bitstream_filter
  3118. */
  3119. void avcodec_register_all(void);
  3120. /**
  3121. * Allocate an AVCodecContext and set its fields to default values. The
  3122. * resulting struct should be freed with avcodec_free_context().
  3123. *
  3124. * @param codec if non-NULL, allocate private data and initialize defaults
  3125. * for the given codec. It is illegal to then call avcodec_open2()
  3126. * with a different codec.
  3127. * If NULL, then the codec-specific defaults won't be initialized,
  3128. * which may result in suboptimal default settings (this is
  3129. * important mainly for encoders, e.g. libx264).
  3130. *
  3131. * @return An AVCodecContext filled with default values or NULL on failure.
  3132. */
  3133. AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
  3134. /**
  3135. * Free the codec context and everything associated with it and write NULL to
  3136. * the provided pointer.
  3137. */
  3138. void avcodec_free_context(AVCodecContext **avctx);
  3139. #if FF_API_GET_CONTEXT_DEFAULTS
  3140. /**
  3141. * @deprecated This function should not be used, as closing and opening a codec
  3142. * context multiple time is not supported. A new codec context should be
  3143. * allocated for each new use.
  3144. */
  3145. int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
  3146. #endif
  3147. /**
  3148. * Get the AVClass for AVCodecContext. It can be used in combination with
  3149. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  3150. *
  3151. * @see av_opt_find().
  3152. */
  3153. const AVClass *avcodec_get_class(void);
  3154. #if FF_API_COPY_CONTEXT
  3155. /**
  3156. * Copy the settings of the source AVCodecContext into the destination
  3157. * AVCodecContext. The resulting destination codec context will be
  3158. * unopened, i.e. you are required to call avcodec_open2() before you
  3159. * can use this AVCodecContext to decode/encode video/audio data.
  3160. *
  3161. * @param dest target codec context, should be initialized with
  3162. * avcodec_alloc_context3(), but otherwise uninitialized
  3163. * @param src source codec context
  3164. * @return AVERROR() on error (e.g. memory allocation error), 0 on success
  3165. *
  3166. * @deprecated The semantics of this function are ill-defined and it should not
  3167. * be used. If you need to transfer the stream parameters from one codec context
  3168. * to another, use an intermediate AVCodecParameters instance and the
  3169. * avcodec_parameters_from_context() / avcodec_parameters_to_context()
  3170. * functions.
  3171. */
  3172. attribute_deprecated
  3173. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
  3174. #endif
  3175. /**
  3176. * Allocate a new AVCodecParameters and set its fields to default values
  3177. * (unknown/invalid/0). The returned struct must be freed with
  3178. * avcodec_parameters_free().
  3179. */
  3180. AVCodecParameters *avcodec_parameters_alloc(void);
  3181. /**
  3182. * Free an AVCodecParameters instance and everything associated with it and
  3183. * write NULL to the supplied pointer.
  3184. */
  3185. void avcodec_parameters_free(AVCodecParameters **par);
  3186. /**
  3187. * Copy the contents of src to dst. Any allocated fields in dst are freed and
  3188. * replaced with newly allocated duplicates of the corresponding fields in src.
  3189. *
  3190. * @return >= 0 on success, a negative AVERROR code on failure.
  3191. */
  3192. int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src);
  3193. /**
  3194. * Fill the parameters struct based on the values from the supplied codec
  3195. * context. Any allocated fields in par are freed and replaced with duplicates
  3196. * of the corresponding fields in codec.
  3197. *
  3198. * @return >= 0 on success, a negative AVERROR code on failure
  3199. */
  3200. int avcodec_parameters_from_context(AVCodecParameters *par,
  3201. const AVCodecContext *codec);
  3202. /**
  3203. * Fill the codec context based on the values from the supplied codec
  3204. * parameters. Any allocated fields in codec that have a corresponding field in
  3205. * par are freed and replaced with duplicates of the corresponding field in par.
  3206. * Fields in codec that do not have a counterpart in par are not touched.
  3207. *
  3208. * @return >= 0 on success, a negative AVERROR code on failure.
  3209. */
  3210. int avcodec_parameters_to_context(AVCodecContext *codec,
  3211. const AVCodecParameters *par);
  3212. /**
  3213. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  3214. * function the context has to be allocated with avcodec_alloc_context3().
  3215. *
  3216. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  3217. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  3218. * retrieving a codec.
  3219. *
  3220. * @warning This function is not thread safe!
  3221. *
  3222. * @note Always call this function before using decoding routines (such as
  3223. * @ref avcodec_receive_frame()).
  3224. *
  3225. * @code
  3226. * avcodec_register_all();
  3227. * av_dict_set(&opts, "b", "2.5M", 0);
  3228. * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
  3229. * if (!codec)
  3230. * exit(1);
  3231. *
  3232. * context = avcodec_alloc_context3(codec);
  3233. *
  3234. * if (avcodec_open2(context, codec, opts) < 0)
  3235. * exit(1);
  3236. * @endcode
  3237. *
  3238. * @param avctx The context to initialize.
  3239. * @param codec The codec to open this context for. If a non-NULL codec has been
  3240. * previously passed to avcodec_alloc_context3() or
  3241. * for this context, then this parameter MUST be either NULL or
  3242. * equal to the previously passed codec.
  3243. * @param options A dictionary filled with AVCodecContext and codec-private options.
  3244. * On return this object will be filled with options that were not found.
  3245. *
  3246. * @return zero on success, a negative value on error
  3247. * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
  3248. * av_dict_set(), av_opt_find().
  3249. */
  3250. int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
  3251. /**
  3252. * Close a given AVCodecContext and free all the data associated with it
  3253. * (but not the AVCodecContext itself).
  3254. *
  3255. * Calling this function on an AVCodecContext that hasn't been opened will free
  3256. * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
  3257. * codec. Subsequent calls will do nothing.
  3258. *
  3259. * @note Do not use this function. Use avcodec_free_context() to destroy a
  3260. * codec context (either open or closed). Opening and closing a codec context
  3261. * multiple times is not supported anymore -- use multiple codec contexts
  3262. * instead.
  3263. */
  3264. int avcodec_close(AVCodecContext *avctx);
  3265. /**
  3266. * Free all allocated data in the given subtitle struct.
  3267. *
  3268. * @param sub AVSubtitle to free.
  3269. */
  3270. void avsubtitle_free(AVSubtitle *sub);
  3271. /**
  3272. * @}
  3273. */
  3274. /**
  3275. * @addtogroup lavc_packet
  3276. * @{
  3277. */
  3278. /**
  3279. * Allocate an AVPacket and set its fields to default values. The resulting
  3280. * struct must be freed using av_packet_free().
  3281. *
  3282. * @return An AVPacket filled with default values or NULL on failure.
  3283. *
  3284. * @note this only allocates the AVPacket itself, not the data buffers. Those
  3285. * must be allocated through other means such as av_new_packet.
  3286. *
  3287. * @see av_new_packet
  3288. */
  3289. AVPacket *av_packet_alloc(void);
  3290. /**
  3291. * Create a new packet that references the same data as src.
  3292. *
  3293. * This is a shortcut for av_packet_alloc()+av_packet_ref().
  3294. *
  3295. * @return newly created AVPacket on success, NULL on error.
  3296. *
  3297. * @see av_packet_alloc
  3298. * @see av_packet_ref
  3299. */
  3300. AVPacket *av_packet_clone(const AVPacket *src);
  3301. /**
  3302. * Free the packet, if the packet is reference counted, it will be
  3303. * unreferenced first.
  3304. *
  3305. * @param pkt packet to be freed. The pointer will be set to NULL.
  3306. * @note passing NULL is a no-op.
  3307. */
  3308. void av_packet_free(AVPacket **pkt);
  3309. /**
  3310. * Initialize optional fields of a packet with default values.
  3311. *
  3312. * Note, this does not touch the data and size members, which have to be
  3313. * initialized separately.
  3314. *
  3315. * @param pkt packet
  3316. */
  3317. void av_init_packet(AVPacket *pkt);
  3318. /**
  3319. * Allocate the payload of a packet and initialize its fields with
  3320. * default values.
  3321. *
  3322. * @param pkt packet
  3323. * @param size wanted payload size
  3324. * @return 0 if OK, AVERROR_xxx otherwise
  3325. */
  3326. int av_new_packet(AVPacket *pkt, int size);
  3327. /**
  3328. * Reduce packet size, correctly zeroing padding
  3329. *
  3330. * @param pkt packet
  3331. * @param size new size
  3332. */
  3333. void av_shrink_packet(AVPacket *pkt, int size);
  3334. /**
  3335. * Increase packet size, correctly zeroing padding
  3336. *
  3337. * @param pkt packet
  3338. * @param grow_by number of bytes by which to increase the size of the packet
  3339. */
  3340. int av_grow_packet(AVPacket *pkt, int grow_by);
  3341. /**
  3342. * Initialize a reference-counted packet from av_malloc()ed data.
  3343. *
  3344. * @param pkt packet to be initialized. This function will set the data, size,
  3345. * buf and destruct fields, all others are left untouched.
  3346. * @param data Data allocated by av_malloc() to be used as packet data. If this
  3347. * function returns successfully, the data is owned by the underlying AVBuffer.
  3348. * The caller may not access the data through other means.
  3349. * @param size size of data in bytes, without the padding. I.e. the full buffer
  3350. * size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
  3351. *
  3352. * @return 0 on success, a negative AVERROR on error
  3353. */
  3354. int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
  3355. #if FF_API_AVPACKET_OLD_API
  3356. /**
  3357. * @warning This is a hack - the packet memory allocation stuff is broken. The
  3358. * packet is allocated if it was not really allocated.
  3359. *
  3360. * @deprecated Use av_packet_ref
  3361. */
  3362. attribute_deprecated
  3363. int av_dup_packet(AVPacket *pkt);
  3364. /**
  3365. * Free a packet.
  3366. *
  3367. * @deprecated Use av_packet_unref
  3368. *
  3369. * @param pkt packet to free
  3370. */
  3371. attribute_deprecated
  3372. void av_free_packet(AVPacket *pkt);
  3373. #endif
  3374. /**
  3375. * Allocate new information of a packet.
  3376. *
  3377. * @param pkt packet
  3378. * @param type side information type
  3379. * @param size side information size
  3380. * @return pointer to fresh allocated data or NULL otherwise
  3381. */
  3382. uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3383. int size);
  3384. /**
  3385. * Wrap an existing array as a packet side data.
  3386. *
  3387. * @param pkt packet
  3388. * @param type side information type
  3389. * @param data the side data array. It must be allocated with the av_malloc()
  3390. * family of functions. The ownership of the data is transferred to
  3391. * pkt.
  3392. * @param size side information size
  3393. * @return a non-negative number on success, a negative AVERROR code on
  3394. * failure. On failure, the packet is unchanged and the data remains
  3395. * owned by the caller.
  3396. */
  3397. int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3398. uint8_t *data, size_t size);
  3399. /**
  3400. * Shrink the already allocated side data buffer
  3401. *
  3402. * @param pkt packet
  3403. * @param type side information type
  3404. * @param size new side information size
  3405. * @return 0 on success, < 0 on failure
  3406. */
  3407. int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3408. int size);
  3409. /**
  3410. * Get side information from packet.
  3411. *
  3412. * @param pkt packet
  3413. * @param type desired side information type
  3414. * @param size pointer for side information size to store (optional)
  3415. * @return pointer to data if present or NULL otherwise
  3416. */
  3417. uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3418. int *size);
  3419. /**
  3420. * Convenience function to free all the side data stored.
  3421. * All the other fields stay untouched.
  3422. *
  3423. * @param pkt packet
  3424. */
  3425. void av_packet_free_side_data(AVPacket *pkt);
  3426. /**
  3427. * Setup a new reference to the data described by a given packet
  3428. *
  3429. * If src is reference-counted, setup dst as a new reference to the
  3430. * buffer in src. Otherwise allocate a new buffer in dst and copy the
  3431. * data from src into it.
  3432. *
  3433. * All the other fields are copied from src.
  3434. *
  3435. * @see av_packet_unref
  3436. *
  3437. * @param dst Destination packet
  3438. * @param src Source packet
  3439. *
  3440. * @return 0 on success, a negative AVERROR on error.
  3441. */
  3442. int av_packet_ref(AVPacket *dst, const AVPacket *src);
  3443. /**
  3444. * Wipe the packet.
  3445. *
  3446. * Unreference the buffer referenced by the packet and reset the
  3447. * remaining packet fields to their default values.
  3448. *
  3449. * @param pkt The packet to be unreferenced.
  3450. */
  3451. void av_packet_unref(AVPacket *pkt);
  3452. /**
  3453. * Move every field in src to dst and reset src.
  3454. *
  3455. * @see av_packet_unref
  3456. *
  3457. * @param src Source packet, will be reset
  3458. * @param dst Destination packet
  3459. */
  3460. void av_packet_move_ref(AVPacket *dst, AVPacket *src);
  3461. /**
  3462. * Copy only "properties" fields from src to dst.
  3463. *
  3464. * Properties for the purpose of this function are all the fields
  3465. * beside those related to the packet data (buf, data, size)
  3466. *
  3467. * @param dst Destination packet
  3468. * @param src Source packet
  3469. *
  3470. * @return 0 on success AVERROR on failure.
  3471. */
  3472. int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
  3473. /**
  3474. * Convert valid timing fields (timestamps / durations) in a packet from one
  3475. * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
  3476. * ignored.
  3477. *
  3478. * @param pkt packet on which the conversion will be performed
  3479. * @param tb_src source timebase, in which the timing fields in pkt are
  3480. * expressed
  3481. * @param tb_dst destination timebase, to which the timing fields will be
  3482. * converted
  3483. */
  3484. void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
  3485. /**
  3486. * @}
  3487. */
  3488. /**
  3489. * @addtogroup lavc_decoding
  3490. * @{
  3491. */
  3492. /**
  3493. * Find a registered decoder with a matching codec ID.
  3494. *
  3495. * @param id AVCodecID of the requested decoder
  3496. * @return A decoder if one was found, NULL otherwise.
  3497. */
  3498. AVCodec *avcodec_find_decoder(enum AVCodecID id);
  3499. /**
  3500. * Find a registered decoder with the specified name.
  3501. *
  3502. * @param name name of the requested decoder
  3503. * @return A decoder if one was found, NULL otherwise.
  3504. */
  3505. AVCodec *avcodec_find_decoder_by_name(const char *name);
  3506. /**
  3507. * The default callback for AVCodecContext.get_buffer2(). It is made public so
  3508. * it can be called by custom get_buffer2() implementations for decoders without
  3509. * AV_CODEC_CAP_DR1 set.
  3510. */
  3511. int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
  3512. /**
  3513. * Modify width and height values so that they will result in a memory
  3514. * buffer that is acceptable for the codec if you do not use any horizontal
  3515. * padding.
  3516. *
  3517. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  3518. */
  3519. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  3520. /**
  3521. * Modify width and height values so that they will result in a memory
  3522. * buffer that is acceptable for the codec if you also ensure that all
  3523. * line sizes are a multiple of the respective linesize_align[i].
  3524. *
  3525. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  3526. */
  3527. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
  3528. int linesize_align[AV_NUM_DATA_POINTERS]);
  3529. /**
  3530. * Decode the audio frame of size avpkt->size from avpkt->data into frame.
  3531. *
  3532. * Some decoders may support multiple frames in a single AVPacket. Such
  3533. * decoders would then just decode the first frame and the return value would be
  3534. * less than the packet size. In this case, avcodec_decode_audio4 has to be
  3535. * called again with an AVPacket containing the remaining data in order to
  3536. * decode the second frame, etc... Even if no frames are returned, the packet
  3537. * needs to be fed to the decoder with remaining data until it is completely
  3538. * consumed or an error occurs.
  3539. *
  3540. * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
  3541. * and output. This means that for some packets they will not immediately
  3542. * produce decoded output and need to be flushed at the end of decoding to get
  3543. * all the decoded data. Flushing is done by calling this function with packets
  3544. * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
  3545. * returning samples. It is safe to flush even those decoders that are not
  3546. * marked with AV_CODEC_CAP_DELAY, then no samples will be returned.
  3547. *
  3548. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  3549. * larger than the actual read bytes because some optimized bitstream
  3550. * readers read 32 or 64 bits at once and could read over the end.
  3551. *
  3552. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3553. * before packets may be fed to the decoder.
  3554. *
  3555. * @param avctx the codec context
  3556. * @param[out] frame The AVFrame in which to store decoded audio samples.
  3557. * The decoder will allocate a buffer for the decoded frame by
  3558. * calling the AVCodecContext.get_buffer2() callback.
  3559. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  3560. * reference counted and the returned reference belongs to the
  3561. * caller. The caller must release the frame using av_frame_unref()
  3562. * when the frame is no longer needed. The caller may safely write
  3563. * to the frame if av_frame_is_writable() returns 1.
  3564. * When AVCodecContext.refcounted_frames is set to 0, the returned
  3565. * reference belongs to the decoder and is valid only until the
  3566. * next call to this function or until closing or flushing the
  3567. * decoder. The caller may not write to it.
  3568. * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
  3569. * non-zero. Note that this field being set to zero
  3570. * does not mean that an error has occurred. For
  3571. * decoders with AV_CODEC_CAP_DELAY set, no given decode
  3572. * call is guaranteed to produce a frame.
  3573. * @param[in] avpkt The input AVPacket containing the input buffer.
  3574. * At least avpkt->data and avpkt->size should be set. Some
  3575. * decoders might also require additional fields to be set.
  3576. * @return A negative error code is returned if an error occurred during
  3577. * decoding, otherwise the number of bytes consumed from the input
  3578. * AVPacket is returned.
  3579. *
  3580. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  3581. */
  3582. attribute_deprecated
  3583. int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
  3584. int *got_frame_ptr, AVPacket *avpkt);
  3585. /**
  3586. * Decode the video frame of size avpkt->size from avpkt->data into picture.
  3587. * Some decoders may support multiple frames in a single AVPacket, such
  3588. * decoders would then just decode the first frame.
  3589. *
  3590. * @warning The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than
  3591. * the actual read bytes because some optimized bitstream readers read 32 or 64
  3592. * bits at once and could read over the end.
  3593. *
  3594. * @warning The end of the input buffer buf should be set to 0 to ensure that
  3595. * no overreading happens for damaged MPEG streams.
  3596. *
  3597. * @note Codecs which have the AV_CODEC_CAP_DELAY capability set have a delay
  3598. * between input and output, these need to be fed with avpkt->data=NULL,
  3599. * avpkt->size=0 at the end to return the remaining frames.
  3600. *
  3601. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3602. * before packets may be fed to the decoder.
  3603. *
  3604. * @param avctx the codec context
  3605. * @param[out] picture The AVFrame in which the decoded video frame will be stored.
  3606. * Use av_frame_alloc() to get an AVFrame. The codec will
  3607. * allocate memory for the actual bitmap by calling the
  3608. * AVCodecContext.get_buffer2() callback.
  3609. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  3610. * reference counted and the returned reference belongs to the
  3611. * caller. The caller must release the frame using av_frame_unref()
  3612. * when the frame is no longer needed. The caller may safely write
  3613. * to the frame if av_frame_is_writable() returns 1.
  3614. * When AVCodecContext.refcounted_frames is set to 0, the returned
  3615. * reference belongs to the decoder and is valid only until the
  3616. * next call to this function or until closing or flushing the
  3617. * decoder. The caller may not write to it.
  3618. *
  3619. * @param[in] avpkt The input AVPacket containing the input buffer.
  3620. * You can create such packet with av_init_packet() and by then setting
  3621. * data and size, some decoders might in addition need other fields like
  3622. * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
  3623. * fields possible.
  3624. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
  3625. * @return On error a negative value is returned, otherwise the number of bytes
  3626. * used or zero if no frame could be decompressed.
  3627. *
  3628. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  3629. */
  3630. attribute_deprecated
  3631. int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  3632. int *got_picture_ptr,
  3633. AVPacket *avpkt);
  3634. /**
  3635. * Decode a subtitle message.
  3636. * Return a negative value on error, otherwise return the number of bytes used.
  3637. * If no subtitle could be decompressed, got_sub_ptr is zero.
  3638. * Otherwise, the subtitle is stored in *sub.
  3639. * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
  3640. * simplicity, because the performance difference is expect to be negligible
  3641. * and reusing a get_buffer written for video codecs would probably perform badly
  3642. * due to a potentially very different allocation pattern.
  3643. *
  3644. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3645. * before packets may be fed to the decoder.
  3646. *
  3647. * @param avctx the codec context
  3648. * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
  3649. freed with avsubtitle_free if *got_sub_ptr is set.
  3650. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
  3651. * @param[in] avpkt The input AVPacket containing the input buffer.
  3652. */
  3653. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  3654. int *got_sub_ptr,
  3655. AVPacket *avpkt);
  3656. /**
  3657. * Supply raw packet data as input to a decoder.
  3658. *
  3659. * Internally, this call will copy relevant AVCodecContext fields, which can
  3660. * influence decoding per-packet, and apply them when the packet is actually
  3661. * decoded. (For example AVCodecContext.skip_frame, which might direct the
  3662. * decoder to drop the frame contained by the packet sent with this function.)
  3663. *
  3664. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  3665. * larger than the actual read bytes because some optimized bitstream
  3666. * readers read 32 or 64 bits at once and could read over the end.
  3667. *
  3668. * @warning Do not mix this API with the legacy API (like avcodec_decode_video2())
  3669. * on the same AVCodecContext. It will return unexpected results now
  3670. * or in future libavcodec versions.
  3671. *
  3672. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3673. * before packets may be fed to the decoder.
  3674. *
  3675. * @param avctx codec context
  3676. * @param[in] avpkt The input AVPacket. Usually, this will be a single video
  3677. * frame, or several complete audio frames.
  3678. * Ownership of the packet remains with the caller, and the
  3679. * decoder will not write to the packet. The decoder may create
  3680. * a reference to the packet data (or copy it if the packet is
  3681. * not reference-counted).
  3682. * Unlike with older APIs, the packet is always fully consumed,
  3683. * and if it contains multiple frames (e.g. some audio codecs),
  3684. * will require you to call avcodec_receive_frame() multiple
  3685. * times afterwards before you can send a new packet.
  3686. * It can be NULL (or an AVPacket with data set to NULL and
  3687. * size set to 0); in this case, it is considered a flush
  3688. * packet, which signals the end of the stream. Sending the
  3689. * first flush packet will return success. Subsequent ones are
  3690. * unnecessary and will return AVERROR_EOF. If the decoder
  3691. * still has frames buffered, it will return them after sending
  3692. * a flush packet.
  3693. *
  3694. * @return 0 on success, otherwise negative error code:
  3695. * AVERROR(EAGAIN): input is not accepted in the current state - user
  3696. * must read output with avcodec_receive_frame() (once
  3697. * all output is read, the packet should be resent, and
  3698. * the call will not fail with EAGAIN).
  3699. * AVERROR_EOF: the decoder has been flushed, and no new packets can
  3700. * be sent to it (also returned if more than 1 flush
  3701. * packet is sent)
  3702. * AVERROR(EINVAL): codec not opened, it is an encoder, or requires flush
  3703. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  3704. * other errors: legitimate decoding errors
  3705. */
  3706. int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  3707. /**
  3708. * Return decoded output data from a decoder.
  3709. *
  3710. * @param avctx codec context
  3711. * @param frame This will be set to a reference-counted video or audio
  3712. * frame (depending on the decoder type) allocated by the
  3713. * decoder. Note that the function will always call
  3714. * av_frame_unref(frame) before doing anything else.
  3715. *
  3716. * @return
  3717. * 0: success, a frame was returned
  3718. * AVERROR(EAGAIN): output is not available in this state - user must try
  3719. * to send new input
  3720. * AVERROR_EOF: the decoder has been fully flushed, and there will be
  3721. * no more output frames
  3722. * AVERROR(EINVAL): codec not opened, or it is an encoder
  3723. * other negative values: legitimate decoding errors
  3724. */
  3725. int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
  3726. /**
  3727. * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
  3728. * to retrieve buffered output packets.
  3729. *
  3730. * @param avctx codec context
  3731. * @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
  3732. * Ownership of the frame remains with the caller, and the
  3733. * encoder will not write to the frame. The encoder may create
  3734. * a reference to the frame data (or copy it if the frame is
  3735. * not reference-counted).
  3736. * It can be NULL, in which case it is considered a flush
  3737. * packet. This signals the end of the stream. If the encoder
  3738. * still has packets buffered, it will return them after this
  3739. * call. Once flushing mode has been entered, additional flush
  3740. * packets are ignored, and sending frames will return
  3741. * AVERROR_EOF.
  3742. *
  3743. * For audio:
  3744. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  3745. * can have any number of samples.
  3746. * If it is not set, frame->nb_samples must be equal to
  3747. * avctx->frame_size for all frames except the last.
  3748. * The final frame may be smaller than avctx->frame_size.
  3749. * @return 0 on success, otherwise negative error code:
  3750. * AVERROR(EAGAIN): input is not accepted in the current state - user
  3751. * must read output with avcodec_receive_packet() (once
  3752. * all output is read, the packet should be resent, and
  3753. * the call will not fail with EAGAIN).
  3754. * AVERROR_EOF: the encoder has been flushed, and no new frames can
  3755. * be sent to it
  3756. * AVERROR(EINVAL): codec not opened, refcounted_frames not set, it is a
  3757. * decoder, or requires flush
  3758. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  3759. * other errors: legitimate decoding errors
  3760. */
  3761. int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  3762. /**
  3763. * Read encoded data from the encoder.
  3764. *
  3765. * @param avctx codec context
  3766. * @param avpkt This will be set to a reference-counted packet allocated by the
  3767. * encoder. Note that the function will always call
  3768. * av_frame_unref(frame) before doing anything else.
  3769. * @return 0 on success, otherwise negative error code:
  3770. * AVERROR(EAGAIN): output is not available in the current state - user
  3771. * must try to send input
  3772. * AVERROR_EOF: the encoder has been fully flushed, and there will be
  3773. * no more output packets
  3774. * AVERROR(EINVAL): codec not opened, or it is an encoder
  3775. * other errors: legitimate decoding errors
  3776. */
  3777. int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  3778. /**
  3779. * Create and return a AVHWFramesContext with values adequate for hardware
  3780. * decoding. This is meant to get called from the get_format callback, and is
  3781. * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx.
  3782. * This API is for decoding with certain hardware acceleration modes/APIs only.
  3783. *
  3784. * The returned AVHWFramesContext is not initialized. The caller must do this
  3785. * with av_hwframe_ctx_init().
  3786. *
  3787. * Calling this function is not a requirement, but makes it simpler to avoid
  3788. * codec or hardware API specific details when manually allocating frames.
  3789. *
  3790. * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx,
  3791. * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes
  3792. * it unnecessary to call this function or having to care about
  3793. * AVHWFramesContext initialization at all.
  3794. *
  3795. * There are a number of requirements for calling this function:
  3796. *
  3797. * - It must be called from get_format with the same avctx parameter that was
  3798. * passed to get_format. Calling it outside of get_format is not allowed, and
  3799. * can trigger undefined behavior.
  3800. * - The function is not always supported (see description of return values).
  3801. * Even if this function returns successfully, hwaccel initialization could
  3802. * fail later. (The degree to which implementations check whether the stream
  3803. * is actually supported varies. Some do this check only after the user's
  3804. * get_format callback returns.)
  3805. * - The hw_pix_fmt must be one of the choices suggested by get_format. If the
  3806. * user decides to use a AVHWFramesContext prepared with this API function,
  3807. * the user must return the same hw_pix_fmt from get_format.
  3808. * - The device_ref passed to this function must support the given hw_pix_fmt.
  3809. * - After calling this API function, it is the user's responsibility to
  3810. * initialize the AVHWFramesContext (returned by the out_frames_ref parameter),
  3811. * and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done
  3812. * before returning from get_format (this is implied by the normal
  3813. * AVCodecContext.hw_frames_ctx API rules).
  3814. * - The AVHWFramesContext parameters may change every time time get_format is
  3815. * called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So
  3816. * you are inherently required to go through this process again on every
  3817. * get_format call.
  3818. * - It is perfectly possible to call this function without actually using
  3819. * the resulting AVHWFramesContext. One use-case might be trying to reuse a
  3820. * previously initialized AVHWFramesContext, and calling this API function
  3821. * only to test whether the required frame parameters have changed.
  3822. * - Fields that use dynamically allocated values of any kind must not be set
  3823. * by the user unless setting them is explicitly allowed by the documentation.
  3824. * If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque,
  3825. * the new free callback must call the potentially set previous free callback.
  3826. * This API call may set any dynamically allocated fields, including the free
  3827. * callback.
  3828. *
  3829. * The function will set at least the following fields on AVHWFramesContext
  3830. * (potentially more, depending on hwaccel API):
  3831. *
  3832. * - All fields set by av_hwframe_ctx_alloc().
  3833. * - Set the format field to hw_pix_fmt.
  3834. * - Set the sw_format field to the most suited and most versatile format. (An
  3835. * implication is that this will prefer generic formats over opaque formats
  3836. * with arbitrary restrictions, if possible.)
  3837. * - Set the width/height fields to the coded frame size, rounded up to the
  3838. * API-specific minimum alignment.
  3839. * - Only _if_ the hwaccel requires a pre-allocated pool: set the initial_pool_size
  3840. * field to the number of maximum reference surfaces possible with the codec,
  3841. * plus 1 surface for the user to work (meaning the user can safely reference
  3842. * at most 1 decoded surface at a time), plus additional buffering introduced
  3843. * by frame threading. If the hwaccel does not require pre-allocation, the
  3844. * field is left to 0, and the decoder will allocate new surfaces on demand
  3845. * during decoding.
  3846. * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying
  3847. * hardware API.
  3848. *
  3849. * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but
  3850. * with basic frame parameters set.
  3851. *
  3852. * The function is stateless, and does not change the AVCodecContext or the
  3853. * device_ref AVHWDeviceContext.
  3854. *
  3855. * @param avctx The context which is currently calling get_format, and which
  3856. * implicitly contains all state needed for filling the returned
  3857. * AVHWFramesContext properly.
  3858. * @param device_ref A reference to the AVHWDeviceContext describing the device
  3859. * which will be used by the hardware decoder.
  3860. * @param hw_pix_fmt The hwaccel format you are going to return from get_format.
  3861. * @param out_frames_ref On success, set to a reference to an _uninitialized_
  3862. * AVHWFramesContext, created from the given device_ref.
  3863. * Fields will be set to values required for decoding.
  3864. * Not changed if an error is returned.
  3865. * @return zero on success, a negative value on error. The following error codes
  3866. * have special semantics:
  3867. * AVERROR(ENOENT): the decoder does not support this functionality. Setup
  3868. * is always manual, or it is a decoder which does not
  3869. * support setting AVCodecContext.hw_frames_ctx at all,
  3870. * or it is a software format.
  3871. * AVERROR(EINVAL): it is known that hardware decoding is not supported for
  3872. * this configuration, or the device_ref is not supported
  3873. * for the hwaccel referenced by hw_pix_fmt.
  3874. */
  3875. int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
  3876. AVBufferRef *device_ref,
  3877. enum AVPixelFormat hw_pix_fmt,
  3878. AVBufferRef **out_frames_ref);
  3879. /**
  3880. * @defgroup lavc_parsing Frame parsing
  3881. * @{
  3882. */
  3883. enum AVPictureStructure {
  3884. AV_PICTURE_STRUCTURE_UNKNOWN, //< unknown
  3885. AV_PICTURE_STRUCTURE_TOP_FIELD, //< coded as top field
  3886. AV_PICTURE_STRUCTURE_BOTTOM_FIELD, //< coded as bottom field
  3887. AV_PICTURE_STRUCTURE_FRAME, //< coded as frame
  3888. };
  3889. typedef struct AVCodecParserContext {
  3890. void *priv_data;
  3891. struct AVCodecParser *parser;
  3892. int64_t frame_offset; /* offset of the current frame */
  3893. int64_t cur_offset; /* current offset
  3894. (incremented by each av_parser_parse()) */
  3895. int64_t next_frame_offset; /* offset of the next frame */
  3896. /* video info */
  3897. int pict_type; /* XXX: Put it back in AVCodecContext. */
  3898. /**
  3899. * This field is used for proper frame duration computation in lavf.
  3900. * It signals, how much longer the frame duration of the current frame
  3901. * is compared to normal frame duration.
  3902. *
  3903. * frame_duration = (1 + repeat_pict) * time_base
  3904. *
  3905. * It is used by codecs like H.264 to display telecined material.
  3906. */
  3907. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  3908. int64_t pts; /* pts of the current frame */
  3909. int64_t dts; /* dts of the current frame */
  3910. /* private data */
  3911. int64_t last_pts;
  3912. int64_t last_dts;
  3913. int fetch_timestamp;
  3914. #define AV_PARSER_PTS_NB 4
  3915. int cur_frame_start_index;
  3916. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  3917. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  3918. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  3919. int flags;
  3920. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  3921. #define PARSER_FLAG_ONCE 0x0002
  3922. /// Set if the parser has a valid file offset
  3923. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
  3924. int64_t offset; ///< byte offset from starting packet start
  3925. int64_t cur_frame_end[AV_PARSER_PTS_NB];
  3926. /**
  3927. * Set by parser to 1 for key frames and 0 for non-key frames.
  3928. * It is initialized to -1, so if the parser doesn't set this flag,
  3929. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
  3930. * will be used.
  3931. */
  3932. int key_frame;
  3933. #if FF_API_CONVERGENCE_DURATION
  3934. /**
  3935. * @deprecated unused
  3936. */
  3937. attribute_deprecated
  3938. int64_t convergence_duration;
  3939. #endif
  3940. // Timestamp generation support:
  3941. /**
  3942. * Synchronization point for start of timestamp generation.
  3943. *
  3944. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
  3945. * (default).
  3946. *
  3947. * For example, this corresponds to presence of H.264 buffering period
  3948. * SEI message.
  3949. */
  3950. int dts_sync_point;
  3951. /**
  3952. * Offset of the current timestamp against last timestamp sync point in
  3953. * units of AVCodecContext.time_base.
  3954. *
  3955. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3956. * contain a valid timestamp offset.
  3957. *
  3958. * Note that the timestamp of sync point has usually a nonzero
  3959. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
  3960. * the next frame after timestamp sync point will be usually 1.
  3961. *
  3962. * For example, this corresponds to H.264 cpb_removal_delay.
  3963. */
  3964. int dts_ref_dts_delta;
  3965. /**
  3966. * Presentation delay of current frame in units of AVCodecContext.time_base.
  3967. *
  3968. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3969. * contain valid non-negative timestamp delta (presentation time of a frame
  3970. * must not lie in the past).
  3971. *
  3972. * This delay represents the difference between decoding and presentation
  3973. * time of the frame.
  3974. *
  3975. * For example, this corresponds to H.264 dpb_output_delay.
  3976. */
  3977. int pts_dts_delta;
  3978. /**
  3979. * Position of the packet in file.
  3980. *
  3981. * Analogous to cur_frame_pts/dts
  3982. */
  3983. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
  3984. /**
  3985. * Byte position of currently parsed frame in stream.
  3986. */
  3987. int64_t pos;
  3988. /**
  3989. * Previous frame byte position.
  3990. */
  3991. int64_t last_pos;
  3992. /**
  3993. * Duration of the current frame.
  3994. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
  3995. * For all other types, this is in units of AVCodecContext.time_base.
  3996. */
  3997. int duration;
  3998. enum AVFieldOrder field_order;
  3999. /**
  4000. * Indicate whether a picture is coded as a frame, top field or bottom field.
  4001. *
  4002. * For example, H.264 field_pic_flag equal to 0 corresponds to
  4003. * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
  4004. * equal to 1 and bottom_field_flag equal to 0 corresponds to
  4005. * AV_PICTURE_STRUCTURE_TOP_FIELD.
  4006. */
  4007. enum AVPictureStructure picture_structure;
  4008. /**
  4009. * Picture number incremented in presentation or output order.
  4010. * This field may be reinitialized at the first picture of a new sequence.
  4011. *
  4012. * For example, this corresponds to H.264 PicOrderCnt.
  4013. */
  4014. int output_picture_number;
  4015. /**
  4016. * Dimensions of the decoded video intended for presentation.
  4017. */
  4018. int width;
  4019. int height;
  4020. /**
  4021. * Dimensions of the coded video.
  4022. */
  4023. int coded_width;
  4024. int coded_height;
  4025. /**
  4026. * The format of the coded data, corresponds to enum AVPixelFormat for video
  4027. * and for enum AVSampleFormat for audio.
  4028. *
  4029. * Note that a decoder can have considerable freedom in how exactly it
  4030. * decodes the data, so the format reported here might be different from the
  4031. * one returned by a decoder.
  4032. */
  4033. int format;
  4034. } AVCodecParserContext;
  4035. typedef struct AVCodecParser {
  4036. int codec_ids[5]; /* several codec IDs are permitted */
  4037. int priv_data_size;
  4038. int (*parser_init)(AVCodecParserContext *s);
  4039. /* This callback never returns an error, a negative value means that
  4040. * the frame start was in a previous packet. */
  4041. int (*parser_parse)(AVCodecParserContext *s,
  4042. AVCodecContext *avctx,
  4043. const uint8_t **poutbuf, int *poutbuf_size,
  4044. const uint8_t *buf, int buf_size);
  4045. void (*parser_close)(AVCodecParserContext *s);
  4046. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  4047. struct AVCodecParser *next;
  4048. } AVCodecParser;
  4049. AVCodecParser *av_parser_next(const AVCodecParser *c);
  4050. void av_register_codec_parser(AVCodecParser *parser);
  4051. AVCodecParserContext *av_parser_init(int codec_id);
  4052. /**
  4053. * Parse a packet.
  4054. *
  4055. * @param s parser context.
  4056. * @param avctx codec context.
  4057. * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
  4058. * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
  4059. * @param buf input buffer.
  4060. * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
  4061. * @param pts input presentation timestamp.
  4062. * @param dts input decoding timestamp.
  4063. * @param pos input byte position in stream.
  4064. * @return the number of bytes of the input bitstream used.
  4065. *
  4066. * Example:
  4067. * @code
  4068. * while(in_len){
  4069. * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  4070. * in_data, in_len,
  4071. * pts, dts, pos);
  4072. * in_data += len;
  4073. * in_len -= len;
  4074. *
  4075. * if(size)
  4076. * decode_frame(data, size);
  4077. * }
  4078. * @endcode
  4079. */
  4080. int av_parser_parse2(AVCodecParserContext *s,
  4081. AVCodecContext *avctx,
  4082. uint8_t **poutbuf, int *poutbuf_size,
  4083. const uint8_t *buf, int buf_size,
  4084. int64_t pts, int64_t dts,
  4085. int64_t pos);
  4086. /**
  4087. * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
  4088. * @deprecated use AVBitstreamFilter
  4089. */
  4090. int av_parser_change(AVCodecParserContext *s,
  4091. AVCodecContext *avctx,
  4092. uint8_t **poutbuf, int *poutbuf_size,
  4093. const uint8_t *buf, int buf_size, int keyframe);
  4094. void av_parser_close(AVCodecParserContext *s);
  4095. /**
  4096. * @}
  4097. * @}
  4098. */
  4099. /**
  4100. * @addtogroup lavc_encoding
  4101. * @{
  4102. */
  4103. /**
  4104. * Find a registered encoder with a matching codec ID.
  4105. *
  4106. * @param id AVCodecID of the requested encoder
  4107. * @return An encoder if one was found, NULL otherwise.
  4108. */
  4109. AVCodec *avcodec_find_encoder(enum AVCodecID id);
  4110. /**
  4111. * Find a registered encoder with the specified name.
  4112. *
  4113. * @param name name of the requested encoder
  4114. * @return An encoder if one was found, NULL otherwise.
  4115. */
  4116. AVCodec *avcodec_find_encoder_by_name(const char *name);
  4117. /**
  4118. * Encode a frame of audio.
  4119. *
  4120. * Takes input samples from frame and writes the next output packet, if
  4121. * available, to avpkt. The output packet does not necessarily contain data for
  4122. * the most recent frame, as encoders can delay, split, and combine input frames
  4123. * internally as needed.
  4124. *
  4125. * @param avctx codec context
  4126. * @param avpkt output AVPacket.
  4127. * The user can supply an output buffer by setting
  4128. * avpkt->data and avpkt->size prior to calling the
  4129. * function, but if the size of the user-provided data is not
  4130. * large enough, encoding will fail. All other AVPacket fields
  4131. * will be reset by the encoder using av_init_packet(). If
  4132. * avpkt->data is NULL, the encoder will allocate it.
  4133. * The encoder will set avpkt->size to the size of the
  4134. * output packet.
  4135. *
  4136. * If this function fails or produces no output, avpkt will be
  4137. * freed using av_packet_unref().
  4138. * @param[in] frame AVFrame containing the raw audio data to be encoded.
  4139. * May be NULL when flushing an encoder that has the
  4140. * AV_CODEC_CAP_DELAY capability set.
  4141. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  4142. * can have any number of samples.
  4143. * If it is not set, frame->nb_samples must be equal to
  4144. * avctx->frame_size for all frames except the last.
  4145. * The final frame may be smaller than avctx->frame_size.
  4146. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  4147. * output packet is non-empty, and to 0 if it is
  4148. * empty. If the function returns an error, the
  4149. * packet can be assumed to be invalid, and the
  4150. * value of got_packet_ptr is undefined and should
  4151. * not be used.
  4152. * @return 0 on success, negative error code on failure
  4153. *
  4154. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  4155. */
  4156. attribute_deprecated
  4157. int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
  4158. const AVFrame *frame, int *got_packet_ptr);
  4159. /**
  4160. * Encode a frame of video.
  4161. *
  4162. * Takes input raw video data from frame and writes the next output packet, if
  4163. * available, to avpkt. The output packet does not necessarily contain data for
  4164. * the most recent frame, as encoders can delay and reorder input frames
  4165. * internally as needed.
  4166. *
  4167. * @param avctx codec context
  4168. * @param avpkt output AVPacket.
  4169. * The user can supply an output buffer by setting
  4170. * avpkt->data and avpkt->size prior to calling the
  4171. * function, but if the size of the user-provided data is not
  4172. * large enough, encoding will fail. All other AVPacket fields
  4173. * will be reset by the encoder using av_init_packet(). If
  4174. * avpkt->data is NULL, the encoder will allocate it.
  4175. * The encoder will set avpkt->size to the size of the
  4176. * output packet. The returned data (if any) belongs to the
  4177. * caller, he is responsible for freeing it.
  4178. *
  4179. * If this function fails or produces no output, avpkt will be
  4180. * freed using av_packet_unref().
  4181. * @param[in] frame AVFrame containing the raw video data to be encoded.
  4182. * May be NULL when flushing an encoder that has the
  4183. * AV_CODEC_CAP_DELAY capability set.
  4184. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  4185. * output packet is non-empty, and to 0 if it is
  4186. * empty. If the function returns an error, the
  4187. * packet can be assumed to be invalid, and the
  4188. * value of got_packet_ptr is undefined and should
  4189. * not be used.
  4190. * @return 0 on success, negative error code on failure
  4191. *
  4192. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  4193. */
  4194. attribute_deprecated
  4195. int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
  4196. const AVFrame *frame, int *got_packet_ptr);
  4197. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  4198. const AVSubtitle *sub);
  4199. /**
  4200. * @}
  4201. */
  4202. #if FF_API_AVPICTURE
  4203. /**
  4204. * @addtogroup lavc_picture
  4205. * @{
  4206. */
  4207. /**
  4208. * @deprecated unused
  4209. */
  4210. attribute_deprecated
  4211. int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
  4212. /**
  4213. * @deprecated unused
  4214. */
  4215. attribute_deprecated
  4216. void avpicture_free(AVPicture *picture);
  4217. /**
  4218. * @deprecated use av_image_fill_arrays() instead.
  4219. */
  4220. attribute_deprecated
  4221. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  4222. enum AVPixelFormat pix_fmt, int width, int height);
  4223. /**
  4224. * @deprecated use av_image_copy_to_buffer() instead.
  4225. */
  4226. attribute_deprecated
  4227. int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,
  4228. int width, int height,
  4229. unsigned char *dest, int dest_size);
  4230. /**
  4231. * @deprecated use av_image_get_buffer_size() instead.
  4232. */
  4233. attribute_deprecated
  4234. int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
  4235. /**
  4236. * @deprecated av_image_copy() instead.
  4237. */
  4238. attribute_deprecated
  4239. void av_picture_copy(AVPicture *dst, const AVPicture *src,
  4240. enum AVPixelFormat pix_fmt, int width, int height);
  4241. /**
  4242. * @deprecated unused
  4243. */
  4244. attribute_deprecated
  4245. int av_picture_crop(AVPicture *dst, const AVPicture *src,
  4246. enum AVPixelFormat pix_fmt, int top_band, int left_band);
  4247. /**
  4248. * @deprecated unused
  4249. */
  4250. attribute_deprecated
  4251. int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
  4252. int padtop, int padbottom, int padleft, int padright, int *color);
  4253. /**
  4254. * @}
  4255. */
  4256. #endif
  4257. /**
  4258. * @defgroup lavc_misc Utility functions
  4259. * @ingroup libavc
  4260. *
  4261. * Miscellaneous utility functions related to both encoding and decoding
  4262. * (or neither).
  4263. * @{
  4264. */
  4265. /**
  4266. * @defgroup lavc_misc_pixfmt Pixel formats
  4267. *
  4268. * Functions for working with pixel formats.
  4269. * @{
  4270. */
  4271. /**
  4272. * Return a value representing the fourCC code associated to the
  4273. * pixel format pix_fmt, or 0 if no associated fourCC code can be
  4274. * found.
  4275. */
  4276. unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
  4277. #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
  4278. #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
  4279. #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
  4280. #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
  4281. #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
  4282. #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
  4283. /**
  4284. * Compute what kind of losses will occur when converting from one specific
  4285. * pixel format to another.
  4286. * When converting from one pixel format to another, information loss may occur.
  4287. * For example, when converting from RGB24 to GRAY, the color information will
  4288. * be lost. Similarly, other losses occur when converting from some formats to
  4289. * other formats. These losses can involve loss of chroma, but also loss of
  4290. * resolution, loss of color depth, loss due to the color space conversion, loss
  4291. * of the alpha bits or loss due to color quantization.
  4292. * avcodec_get_fix_fmt_loss() informs you about the various types of losses
  4293. * which will occur when converting from one pixel format to another.
  4294. *
  4295. * @param[in] dst_pix_fmt destination pixel format
  4296. * @param[in] src_pix_fmt source pixel format
  4297. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  4298. * @return Combination of flags informing you what kind of losses will occur.
  4299. */
  4300. int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
  4301. int has_alpha);
  4302. /**
  4303. * Find the best pixel format to convert to given a certain source pixel
  4304. * format. When converting from one pixel format to another, information loss
  4305. * may occur. For example, when converting from RGB24 to GRAY, the color
  4306. * information will be lost. Similarly, other losses occur when converting from
  4307. * some formats to other formats. avcodec_find_best_pix_fmt2() searches which of
  4308. * the given pixel formats should be used to suffer the least amount of loss.
  4309. * The pixel formats from which it chooses one, are determined by the
  4310. * pix_fmt_list parameter.
  4311. *
  4312. *
  4313. * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
  4314. * @param[in] src_pix_fmt source pixel format
  4315. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  4316. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  4317. * @return The best pixel format to convert to or -1 if none was found.
  4318. */
  4319. enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat *pix_fmt_list,
  4320. enum AVPixelFormat src_pix_fmt,
  4321. int has_alpha, int *loss_ptr);
  4322. enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  4323. /**
  4324. * @}
  4325. */
  4326. /**
  4327. * Put a string representing the codec tag codec_tag in buf.
  4328. *
  4329. * @param buf buffer to place codec tag in
  4330. * @param buf_size size in bytes of buf
  4331. * @param codec_tag codec tag to assign
  4332. * @return the length of the string that would have been generated if
  4333. * enough space had been available, excluding the trailing null
  4334. */
  4335. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
  4336. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  4337. /**
  4338. * Return a name for the specified profile, if available.
  4339. *
  4340. * @param codec the codec that is searched for the given profile
  4341. * @param profile the profile value for which a name is requested
  4342. * @return A name for the profile if found, NULL otherwise.
  4343. */
  4344. const char *av_get_profile_name(const AVCodec *codec, int profile);
  4345. /**
  4346. * Return a name for the specified profile, if available.
  4347. *
  4348. * @param codec_id the ID of the codec to which the requested profile belongs
  4349. * @param profile the profile value for which a name is requested
  4350. * @return A name for the profile if found, NULL otherwise.
  4351. *
  4352. * @note unlike av_get_profile_name(), which searches a list of profiles
  4353. * supported by a specific decoder or encoder implementation, this
  4354. * function searches the list of profiles from the AVCodecDescriptor
  4355. */
  4356. const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
  4357. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
  4358. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
  4359. //FIXME func typedef
  4360. /**
  4361. * Fill audio frame data and linesize.
  4362. * AVFrame extended_data channel pointers are allocated if necessary for
  4363. * planar audio.
  4364. *
  4365. * @param frame the AVFrame
  4366. * frame->nb_samples must be set prior to calling the
  4367. * function. This function fills in frame->data,
  4368. * frame->extended_data, frame->linesize[0].
  4369. * @param nb_channels channel count
  4370. * @param sample_fmt sample format
  4371. * @param buf buffer to use for frame data
  4372. * @param buf_size size of buffer
  4373. * @param align plane size sample alignment (0 = default)
  4374. * @return 0 on success, negative error code on failure
  4375. */
  4376. int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
  4377. enum AVSampleFormat sample_fmt, const uint8_t *buf,
  4378. int buf_size, int align);
  4379. /**
  4380. * Reset the internal decoder state / flush internal buffers. Should be called
  4381. * e.g. when seeking or when switching to a different stream.
  4382. *
  4383. * @note when refcounted frames are not used (i.e. avctx->refcounted_frames is 0),
  4384. * this invalidates the frames previously returned from the decoder. When
  4385. * refcounted frames are used, the decoder just releases any references it might
  4386. * keep internally, but the caller's reference remains valid.
  4387. */
  4388. void avcodec_flush_buffers(AVCodecContext *avctx);
  4389. /**
  4390. * Return codec bits per sample.
  4391. *
  4392. * @param[in] codec_id the codec
  4393. * @return Number of bits per sample or zero if unknown for the given codec.
  4394. */
  4395. int av_get_bits_per_sample(enum AVCodecID codec_id);
  4396. /**
  4397. * Return codec bits per sample.
  4398. * Only return non-zero if the bits per sample is exactly correct, not an
  4399. * approximation.
  4400. *
  4401. * @param[in] codec_id the codec
  4402. * @return Number of bits per sample or zero if unknown for the given codec.
  4403. */
  4404. int av_get_exact_bits_per_sample(enum AVCodecID codec_id);
  4405. /**
  4406. * Return audio frame duration.
  4407. *
  4408. * @param avctx codec context
  4409. * @param frame_bytes size of the frame, or 0 if unknown
  4410. * @return frame duration, in samples, if known. 0 if not able to
  4411. * determine.
  4412. */
  4413. int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
  4414. /**
  4415. * This function is the same as av_get_audio_frame_duration(), except it works
  4416. * with AVCodecParameters instead of an AVCodecContext.
  4417. */
  4418. int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
  4419. #if FF_API_OLD_BSF
  4420. typedef struct AVBitStreamFilterContext {
  4421. void *priv_data;
  4422. struct AVBitStreamFilter *filter;
  4423. AVCodecParserContext *parser;
  4424. struct AVBitStreamFilterContext *next;
  4425. } AVBitStreamFilterContext;
  4426. #endif
  4427. typedef struct AVBSFInternal AVBSFInternal;
  4428. /**
  4429. * The bitstream filter state.
  4430. *
  4431. * This struct must be allocated with av_bsf_alloc() and freed with
  4432. * av_bsf_free().
  4433. *
  4434. * The fields in the struct will only be changed (by the caller or by the
  4435. * filter) as described in their documentation, and are to be considered
  4436. * immutable otherwise.
  4437. */
  4438. typedef struct AVBSFContext {
  4439. /**
  4440. * A class for logging and AVOptions
  4441. */
  4442. const AVClass *av_class;
  4443. /**
  4444. * The bitstream filter this context is an instance of.
  4445. */
  4446. const struct AVBitStreamFilter *filter;
  4447. /**
  4448. * Opaque libavcodec internal data. Must not be touched by the caller in any
  4449. * way.
  4450. */
  4451. AVBSFInternal *internal;
  4452. /**
  4453. * Opaque filter-specific private data. If filter->priv_class is non-NULL,
  4454. * this is an AVOptions-enabled struct.
  4455. */
  4456. void *priv_data;
  4457. /**
  4458. * Parameters of the input stream. This field is allocated in
  4459. * av_bsf_alloc(), it needs to be filled by the caller before
  4460. * av_bsf_init().
  4461. */
  4462. AVCodecParameters *par_in;
  4463. /**
  4464. * Parameters of the output stream. This field is allocated in
  4465. * av_bsf_alloc(), it is set by the filter in av_bsf_init().
  4466. */
  4467. AVCodecParameters *par_out;
  4468. /**
  4469. * The timebase used for the timestamps of the input packets. Set by the
  4470. * caller before av_bsf_init().
  4471. */
  4472. AVRational time_base_in;
  4473. /**
  4474. * The timebase used for the timestamps of the output packets. Set by the
  4475. * filter in av_bsf_init().
  4476. */
  4477. AVRational time_base_out;
  4478. } AVBSFContext;
  4479. typedef struct AVBitStreamFilter {
  4480. const char *name;
  4481. /**
  4482. * A list of codec ids supported by the filter, terminated by
  4483. * AV_CODEC_ID_NONE.
  4484. * May be NULL, in that case the bitstream filter works with any codec id.
  4485. */
  4486. const enum AVCodecID *codec_ids;
  4487. /**
  4488. * A class for the private data, used to declare bitstream filter private
  4489. * AVOptions. This field is NULL for bitstream filters that do not declare
  4490. * any options.
  4491. *
  4492. * If this field is non-NULL, the first member of the filter private data
  4493. * must be a pointer to AVClass, which will be set by libavcodec generic
  4494. * code to this class.
  4495. */
  4496. const AVClass *priv_class;
  4497. /*****************************************************************
  4498. * No fields below this line are part of the public API. They
  4499. * may not be used outside of libavcodec and can be changed and
  4500. * removed at will.
  4501. * New public fields should be added right above.
  4502. *****************************************************************
  4503. */
  4504. int priv_data_size;
  4505. int (*init)(AVBSFContext *ctx);
  4506. int (*filter)(AVBSFContext *ctx, AVPacket *pkt);
  4507. void (*close)(AVBSFContext *ctx);
  4508. } AVBitStreamFilter;
  4509. #if FF_API_OLD_BSF
  4510. /**
  4511. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  4512. * is deprecated. Use the new bitstream filtering API (using AVBSFContext).
  4513. */
  4514. attribute_deprecated
  4515. void av_register_bitstream_filter(AVBitStreamFilter *bsf);
  4516. attribute_deprecated
  4517. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
  4518. attribute_deprecated
  4519. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  4520. AVCodecContext *avctx, const char *args,
  4521. uint8_t **poutbuf, int *poutbuf_size,
  4522. const uint8_t *buf, int buf_size, int keyframe);
  4523. attribute_deprecated
  4524. void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
  4525. attribute_deprecated
  4526. AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);
  4527. #endif
  4528. /**
  4529. * @return a bitstream filter with the specified name or NULL if no such
  4530. * bitstream filter exists.
  4531. */
  4532. const AVBitStreamFilter *av_bsf_get_by_name(const char *name);
  4533. /**
  4534. * Iterate over all registered bitstream filters.
  4535. *
  4536. * @param opaque a pointer where libavcodec will store the iteration state. Must
  4537. * point to NULL to start the iteration.
  4538. *
  4539. * @return the next registered bitstream filter or NULL when the iteration is
  4540. * finished
  4541. */
  4542. const AVBitStreamFilter *av_bsf_next(void **opaque);
  4543. /**
  4544. * Allocate a context for a given bitstream filter. The caller must fill in the
  4545. * context parameters as described in the documentation and then call
  4546. * av_bsf_init() before sending any data to the filter.
  4547. *
  4548. * @param filter the filter for which to allocate an instance.
  4549. * @param ctx a pointer into which the pointer to the newly-allocated context
  4550. * will be written. It must be freed with av_bsf_free() after the
  4551. * filtering is done.
  4552. *
  4553. * @return 0 on success, a negative AVERROR code on failure
  4554. */
  4555. int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx);
  4556. /**
  4557. * Prepare the filter for use, after all the parameters and options have been
  4558. * set.
  4559. */
  4560. int av_bsf_init(AVBSFContext *ctx);
  4561. /**
  4562. * Submit a packet for filtering.
  4563. *
  4564. * After sending each packet, the filter must be completely drained by calling
  4565. * av_bsf_receive_packet() repeatedly until it returns AVERROR(EAGAIN) or
  4566. * AVERROR_EOF.
  4567. *
  4568. * @param pkt the packet to filter. The bitstream filter will take ownership of
  4569. * the packet and reset the contents of pkt. pkt is not touched if an error occurs.
  4570. * This parameter may be NULL, which signals the end of the stream (i.e. no more
  4571. * packets will be sent). That will cause the filter to output any packets it
  4572. * may have buffered internally.
  4573. *
  4574. * @return 0 on success, a negative AVERROR on error.
  4575. */
  4576. int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);
  4577. /**
  4578. * Retrieve a filtered packet.
  4579. *
  4580. * @param[out] pkt this struct will be filled with the contents of the filtered
  4581. * packet. It is owned by the caller and must be freed using
  4582. * av_packet_unref() when it is no longer needed.
  4583. * This parameter should be "clean" (i.e. freshly allocated
  4584. * with av_packet_alloc() or unreffed with av_packet_unref())
  4585. * when this function is called. If this function returns
  4586. * successfully, the contents of pkt will be completely
  4587. * overwritten by the returned data. On failure, pkt is not
  4588. * touched.
  4589. *
  4590. * @return 0 on success. AVERROR(EAGAIN) if more packets need to be sent to the
  4591. * filter (using av_bsf_send_packet()) to get more output. AVERROR_EOF if there
  4592. * will be no further output from the filter. Another negative AVERROR value if
  4593. * an error occurs.
  4594. *
  4595. * @note one input packet may result in several output packets, so after sending
  4596. * a packet with av_bsf_send_packet(), this function needs to be called
  4597. * repeatedly until it stops returning 0. It is also possible for a filter to
  4598. * output fewer packets than were sent to it, so this function may return
  4599. * AVERROR(EAGAIN) immediately after a successful av_bsf_send_packet() call.
  4600. */
  4601. int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);
  4602. /**
  4603. * Free a bitstream filter context and everything associated with it; write NULL
  4604. * into the supplied pointer.
  4605. */
  4606. void av_bsf_free(AVBSFContext **ctx);
  4607. /**
  4608. * Get the AVClass for AVBSFContext. It can be used in combination with
  4609. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  4610. *
  4611. * @see av_opt_find().
  4612. */
  4613. const AVClass *av_bsf_get_class(void);
  4614. /* memory */
  4615. /**
  4616. * Allocate a buffer with padding, reusing the given one if large enough.
  4617. *
  4618. * Same behaviour av_fast_malloc but the buffer has additional
  4619. * AV_INPUT_PADDING_SIZE at the end which will always memset to 0.
  4620. */
  4621. void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  4622. /**
  4623. * Encode extradata length to a buffer. Used by xiph codecs.
  4624. *
  4625. * @param s buffer to write to; must be at least (v/255+1) bytes long
  4626. * @param v size of extradata in bytes
  4627. * @return number of bytes written to the buffer.
  4628. */
  4629. unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
  4630. #if FF_API_USER_VISIBLE_AVHWACCEL
  4631. /**
  4632. * Register the hardware accelerator hwaccel.
  4633. *
  4634. * @deprecated This function doesn't do anything.
  4635. */
  4636. attribute_deprecated
  4637. void av_register_hwaccel(AVHWAccel *hwaccel);
  4638. /**
  4639. * If hwaccel is NULL, returns the first registered hardware accelerator,
  4640. * if hwaccel is non-NULL, returns the next registered hardware accelerator
  4641. * after hwaccel, or NULL if hwaccel is the last one.
  4642. *
  4643. * @deprecated AVHWaccel structures contain no user-serviceable parts, so
  4644. * this function should not be used.
  4645. */
  4646. attribute_deprecated
  4647. AVHWAccel *av_hwaccel_next(const AVHWAccel *hwaccel);
  4648. #endif
  4649. /**
  4650. * Lock operation used by lockmgr
  4651. */
  4652. enum AVLockOp {
  4653. AV_LOCK_CREATE, ///< Create a mutex
  4654. AV_LOCK_OBTAIN, ///< Lock the mutex
  4655. AV_LOCK_RELEASE, ///< Unlock the mutex
  4656. AV_LOCK_DESTROY, ///< Free mutex resources
  4657. };
  4658. /**
  4659. * Register a user provided lock manager supporting the operations
  4660. * specified by AVLockOp. The "mutex" argument to the function points
  4661. * to a (void *) where the lockmgr should store/get a pointer to a user
  4662. * allocated mutex. It is NULL upon AV_LOCK_CREATE and equal to the
  4663. * value left by the last call for all other ops. If the lock manager is
  4664. * unable to perform the op then it should leave the mutex in the same
  4665. * state as when it was called and return a non-zero value. However,
  4666. * when called with AV_LOCK_DESTROY the mutex will always be assumed to
  4667. * have been successfully destroyed. If av_lockmgr_register succeeds
  4668. * it will return a non-negative value, if it fails it will return a
  4669. * negative value and destroy all mutex and unregister all callbacks.
  4670. * av_lockmgr_register is not thread-safe, it must be called from a
  4671. * single thread before any calls which make use of locking are used.
  4672. *
  4673. * @param cb User defined callback. av_lockmgr_register invokes calls
  4674. * to this callback and the previously registered callback.
  4675. * The callback will be used to create more than one mutex
  4676. * each of which must be backed by its own underlying locking
  4677. * mechanism (i.e. do not use a single static object to
  4678. * implement your lock manager). If cb is set to NULL the
  4679. * lockmgr will be unregistered.
  4680. */
  4681. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
  4682. /**
  4683. * Get the type of the given codec.
  4684. */
  4685. enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
  4686. /**
  4687. * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  4688. * with no corresponding avcodec_close()), 0 otherwise.
  4689. */
  4690. int avcodec_is_open(AVCodecContext *s);
  4691. /**
  4692. * @return a non-zero number if codec is an encoder, zero otherwise
  4693. */
  4694. int av_codec_is_encoder(const AVCodec *codec);
  4695. /**
  4696. * @return a non-zero number if codec is a decoder, zero otherwise
  4697. */
  4698. int av_codec_is_decoder(const AVCodec *codec);
  4699. /**
  4700. * @return descriptor for given codec ID or NULL if no descriptor exists.
  4701. */
  4702. const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id);
  4703. /**
  4704. * Iterate over all codec descriptors known to libavcodec.
  4705. *
  4706. * @param prev previous descriptor. NULL to get the first descriptor.
  4707. *
  4708. * @return next descriptor or NULL after the last descriptor
  4709. */
  4710. const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev);
  4711. /**
  4712. * @return codec descriptor with the given name or NULL if no such descriptor
  4713. * exists.
  4714. */
  4715. const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
  4716. /**
  4717. * Allocate a CPB properties structure and initialize its fields to default
  4718. * values.
  4719. *
  4720. * @param size if non-NULL, the size of the allocated struct will be written
  4721. * here. This is useful for embedding it in side data.
  4722. *
  4723. * @return the newly allocated struct or NULL on failure
  4724. */
  4725. AVCPBProperties *av_cpb_properties_alloc(size_t *size);
  4726. /**
  4727. * @}
  4728. */
  4729. #endif /* AVCODEC_AVCODEC_H */