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.

5175 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. /**
  2347. * level
  2348. * - encoding: Set by user.
  2349. * - decoding: Set by libavcodec.
  2350. */
  2351. int level;
  2352. #define FF_LEVEL_UNKNOWN -99
  2353. /**
  2354. * - encoding: unused
  2355. * - decoding: Set by user.
  2356. */
  2357. enum AVDiscard skip_loop_filter;
  2358. /**
  2359. * - encoding: unused
  2360. * - decoding: Set by user.
  2361. */
  2362. enum AVDiscard skip_idct;
  2363. /**
  2364. * - encoding: unused
  2365. * - decoding: Set by user.
  2366. */
  2367. enum AVDiscard skip_frame;
  2368. /**
  2369. * Header containing style information for text subtitles.
  2370. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  2371. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  2372. * the Format line following. It shouldn't include any Dialogue line.
  2373. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  2374. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  2375. */
  2376. uint8_t *subtitle_header;
  2377. int subtitle_header_size;
  2378. #if FF_API_VBV_DELAY
  2379. /**
  2380. * VBV delay coded in the last frame (in periods of a 27 MHz clock).
  2381. * Used for compliant TS muxing.
  2382. * - encoding: Set by libavcodec.
  2383. * - decoding: unused.
  2384. * @deprecated this value is now exported as a part of
  2385. * AV_PKT_DATA_CPB_PROPERTIES packet side data
  2386. */
  2387. attribute_deprecated
  2388. uint64_t vbv_delay;
  2389. #endif
  2390. #if FF_API_SIDEDATA_ONLY_PKT
  2391. /**
  2392. * Encoding only and set by default. Allow encoders to output packets
  2393. * that do not contain any encoded data, only side data.
  2394. *
  2395. * Some encoders need to output such packets, e.g. to update some stream
  2396. * parameters at the end of encoding.
  2397. *
  2398. * @deprecated this field disables the default behaviour and
  2399. * it is kept only for compatibility.
  2400. */
  2401. attribute_deprecated
  2402. int side_data_only_packets;
  2403. #endif
  2404. /**
  2405. * Audio only. The number of "priming" samples (padding) inserted by the
  2406. * encoder at the beginning of the audio. I.e. this number of leading
  2407. * decoded samples must be discarded by the caller to get the original audio
  2408. * without leading padding.
  2409. *
  2410. * - decoding: unused
  2411. * - encoding: Set by libavcodec. The timestamps on the output packets are
  2412. * adjusted by the encoder so that they always refer to the
  2413. * first sample of the data actually contained in the packet,
  2414. * including any added padding. E.g. if the timebase is
  2415. * 1/samplerate and the timestamp of the first input sample is
  2416. * 0, the timestamp of the first output packet will be
  2417. * -initial_padding.
  2418. */
  2419. int initial_padding;
  2420. /*
  2421. * - decoding: For codecs that store a framerate value in the compressed
  2422. * bitstream, the decoder may export it here. { 0, 1} when
  2423. * unknown.
  2424. * - encoding: May be used to signal the framerate of CFR content to an
  2425. * encoder.
  2426. */
  2427. AVRational framerate;
  2428. /**
  2429. * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
  2430. * - encoding: unused.
  2431. * - decoding: Set by libavcodec before calling get_format()
  2432. */
  2433. enum AVPixelFormat sw_pix_fmt;
  2434. /**
  2435. * Additional data associated with the entire coded stream.
  2436. *
  2437. * - decoding: unused
  2438. * - encoding: may be set by libavcodec after avcodec_open2().
  2439. */
  2440. AVPacketSideData *coded_side_data;
  2441. int nb_coded_side_data;
  2442. /**
  2443. * A reference to the AVHWFramesContext describing the input (for encoding)
  2444. * or output (decoding) frames. The reference is set by the caller and
  2445. * afterwards owned (and freed) by libavcodec - it should never be read by
  2446. * the caller after being set.
  2447. *
  2448. * - decoding: This field should be set by the caller from the get_format()
  2449. * callback. The previous reference (if any) will always be
  2450. * unreffed by libavcodec before the get_format() call.
  2451. *
  2452. * If the default get_buffer2() is used with a hwaccel pixel
  2453. * format, then this AVHWFramesContext will be used for
  2454. * allocating the frame buffers.
  2455. *
  2456. * - encoding: For hardware encoders configured to use a hwaccel pixel
  2457. * format, this field should be set by the caller to a reference
  2458. * to the AVHWFramesContext describing input frames.
  2459. * AVHWFramesContext.format must be equal to
  2460. * AVCodecContext.pix_fmt.
  2461. *
  2462. * This field should be set before avcodec_open2() is called.
  2463. */
  2464. AVBufferRef *hw_frames_ctx;
  2465. /**
  2466. * Video decoding only. Certain video codecs support cropping, meaning that
  2467. * only a sub-rectangle of the decoded frame is intended for display. This
  2468. * option controls how cropping is handled by libavcodec.
  2469. *
  2470. * When set to 1 (the default), libavcodec will apply cropping internally.
  2471. * I.e. it will modify the output frame width/height fields and offset the
  2472. * data pointers (only by as much as possible while preserving alignment, or
  2473. * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
  2474. * the frames output by the decoder refer only to the cropped area. The
  2475. * crop_* fields of the output frames will be zero.
  2476. *
  2477. * When set to 0, the width/height fields of the output frames will be set
  2478. * to the coded dimensions and the crop_* fields will describe the cropping
  2479. * rectangle. Applying the cropping is left to the caller.
  2480. *
  2481. * @warning When hardware acceleration with opaque output frames is used,
  2482. * libavcodec is unable to apply cropping from the top/left border.
  2483. *
  2484. * @note when this option is set to zero, the width/height fields of the
  2485. * AVCodecContext and output AVFrames have different meanings. The codec
  2486. * context fields store display dimensions (with the coded dimensions in
  2487. * coded_width/height), while the frame fields store the coded dimensions
  2488. * (with the display dimensions being determined by the crop_* fields).
  2489. */
  2490. int apply_cropping;
  2491. /**
  2492. * A reference to the AVHWDeviceContext describing the device which will
  2493. * be used by a hardware encoder/decoder. The reference is set by the
  2494. * caller and afterwards owned (and freed) by libavcodec.
  2495. *
  2496. * This should be used if either the codec device does not require
  2497. * hardware frames or any that are used are to be allocated internally by
  2498. * libavcodec. If the user wishes to supply any of the frames used as
  2499. * encoder input or decoder output then hw_frames_ctx should be used
  2500. * instead. When hw_frames_ctx is set in get_format() for a decoder, this
  2501. * field will be ignored while decoding the associated stream segment, but
  2502. * may again be used on a following one after another get_format() call.
  2503. *
  2504. * For both encoders and decoders this field should be set before
  2505. * avcodec_open2() is called and must not be written to thereafter.
  2506. *
  2507. * Note that some decoders may require this field to be set initially in
  2508. * order to support hw_frames_ctx at all - in that case, all frames
  2509. * contexts used must be created on the same device.
  2510. */
  2511. AVBufferRef *hw_device_ctx;
  2512. /**
  2513. * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
  2514. * decoding (if active).
  2515. * - encoding: unused
  2516. * - decoding: Set by user (either before avcodec_open2(), or in the
  2517. * AVCodecContext.get_format callback)
  2518. */
  2519. int hwaccel_flags;
  2520. /**
  2521. * Video decoding only. Sets the number of extra hardware frames which
  2522. * the decoder will allocate for use by the caller. This must be set
  2523. * before avcodec_open2() is called.
  2524. *
  2525. * Some hardware decoders require all frames that they will use for
  2526. * output to be defined in advance before decoding starts. For such
  2527. * decoders, the hardware frame pool must therefore be of a fixed size.
  2528. * The extra frames set here are on top of any number that the decoder
  2529. * needs internally in order to operate normally (for example, frames
  2530. * used as reference pictures).
  2531. */
  2532. int extra_hw_frames;
  2533. } AVCodecContext;
  2534. /**
  2535. * AVProfile.
  2536. */
  2537. typedef struct AVProfile {
  2538. int profile;
  2539. const char *name; ///< short name for the profile
  2540. } AVProfile;
  2541. enum {
  2542. /**
  2543. * The codec supports this format via the hw_device_ctx interface.
  2544. *
  2545. * When selecting this format, AVCodecContext.hw_device_ctx should
  2546. * have been set to a device of the specified type before calling
  2547. * avcodec_open2().
  2548. */
  2549. AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01,
  2550. /**
  2551. * The codec supports this format via the hw_frames_ctx interface.
  2552. *
  2553. * When selecting this format for a decoder,
  2554. * AVCodecContext.hw_frames_ctx should be set to a suitable frames
  2555. * context inside the get_format() callback. The frames context
  2556. * must have been created on a device of the specified type.
  2557. */
  2558. AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02,
  2559. /**
  2560. * The codec supports this format by some internal method.
  2561. *
  2562. * This format can be selected without any additional configuration -
  2563. * no device or frames context is required.
  2564. */
  2565. AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 0x04,
  2566. /**
  2567. * The codec supports this format by some ad-hoc method.
  2568. *
  2569. * Additional settings and/or function calls are required. See the
  2570. * codec-specific documentation for details. (Methods requiring
  2571. * this sort of configuration are deprecated and others should be
  2572. * used in preference.)
  2573. */
  2574. AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 0x08,
  2575. };
  2576. typedef struct AVCodecHWConfig {
  2577. /**
  2578. * A hardware pixel format which the codec can use.
  2579. */
  2580. enum AVPixelFormat pix_fmt;
  2581. /**
  2582. * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
  2583. * setup methods which can be used with this configuration.
  2584. */
  2585. int methods;
  2586. /**
  2587. * The device type associated with the configuration.
  2588. *
  2589. * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
  2590. * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
  2591. */
  2592. enum AVHWDeviceType device_type;
  2593. } AVCodecHWConfig;
  2594. typedef struct AVCodecDefault AVCodecDefault;
  2595. struct AVSubtitle;
  2596. /**
  2597. * AVCodec.
  2598. */
  2599. typedef struct AVCodec {
  2600. /**
  2601. * Name of the codec implementation.
  2602. * The name is globally unique among encoders and among decoders (but an
  2603. * encoder and a decoder can share the same name).
  2604. * This is the primary way to find a codec from the user perspective.
  2605. */
  2606. const char *name;
  2607. /**
  2608. * Descriptive name for the codec, meant to be more human readable than name.
  2609. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  2610. */
  2611. const char *long_name;
  2612. enum AVMediaType type;
  2613. enum AVCodecID id;
  2614. /**
  2615. * Codec capabilities.
  2616. * see AV_CODEC_CAP_*
  2617. */
  2618. int capabilities;
  2619. const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
  2620. const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
  2621. const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
  2622. const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
  2623. const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
  2624. const AVClass *priv_class; ///< AVClass for the private context
  2625. const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
  2626. /**
  2627. * Group name of the codec implementation.
  2628. * This is a short symbolic name of the wrapper backing this codec. A
  2629. * wrapper uses some kind of external implementation for the codec, such
  2630. * as an external library, or a codec implementation provided by the OS or
  2631. * the hardware.
  2632. * If this field is NULL, this is a builtin, libavcodec native decoder.
  2633. * If non-NULL, this will be the suffix in AVCodec.name in most cases
  2634. * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
  2635. */
  2636. const char *wrapper_name;
  2637. /*****************************************************************
  2638. * No fields below this line are part of the public API. They
  2639. * may not be used outside of libavcodec and can be changed and
  2640. * removed at will.
  2641. * New public fields should be added right above.
  2642. *****************************************************************
  2643. */
  2644. int priv_data_size;
  2645. struct AVCodec *next;
  2646. /**
  2647. * @name Frame-level threading support functions
  2648. * @{
  2649. */
  2650. /**
  2651. * If defined, called on thread contexts when they are created.
  2652. * If the codec allocates writable tables in init(), re-allocate them here.
  2653. * priv_data will be set to a copy of the original.
  2654. */
  2655. int (*init_thread_copy)(AVCodecContext *);
  2656. /**
  2657. * Copy necessary context variables from a previous thread context to the current one.
  2658. * If not defined, the next thread will start automatically; otherwise, the codec
  2659. * must call ff_thread_finish_setup().
  2660. *
  2661. * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
  2662. */
  2663. int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
  2664. /** @} */
  2665. /**
  2666. * Private codec-specific defaults.
  2667. */
  2668. const AVCodecDefault *defaults;
  2669. /**
  2670. * Initialize codec static data, called from avcodec_register().
  2671. */
  2672. void (*init_static_data)(struct AVCodec *codec);
  2673. int (*init)(AVCodecContext *);
  2674. int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
  2675. const struct AVSubtitle *sub);
  2676. /**
  2677. * Encode data to an AVPacket.
  2678. *
  2679. * @param avctx codec context
  2680. * @param avpkt output AVPacket (may contain a user-provided buffer)
  2681. * @param[in] frame AVFrame containing the raw data to be encoded
  2682. * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
  2683. * non-empty packet was returned in avpkt.
  2684. * @return 0 on success, negative error code on failure
  2685. */
  2686. int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
  2687. int *got_packet_ptr);
  2688. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
  2689. int (*close)(AVCodecContext *);
  2690. /**
  2691. * Encode API with decoupled packet/frame dataflow. The API is the
  2692. * same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except
  2693. * that:
  2694. * - never called if the codec is closed or the wrong type,
  2695. * - if AV_CODEC_CAP_DELAY is not set, drain frames are never sent,
  2696. * - only one drain frame is ever passed down,
  2697. */
  2698. int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
  2699. int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
  2700. /**
  2701. * Decode API with decoupled packet/frame dataflow. This function is called
  2702. * to get one output frame. It should call ff_decode_get_packet() to obtain
  2703. * input data.
  2704. */
  2705. int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
  2706. /**
  2707. * Flush buffers.
  2708. * Will be called when seeking
  2709. */
  2710. void (*flush)(AVCodecContext *);
  2711. /**
  2712. * Internal codec capabilities.
  2713. * See FF_CODEC_CAP_* in internal.h
  2714. */
  2715. int caps_internal;
  2716. /**
  2717. * Decoding only, a comma-separated list of bitstream filters to apply to
  2718. * packets before decoding.
  2719. */
  2720. const char *bsfs;
  2721. /**
  2722. * Array of pointers to hardware configurations supported by the codec,
  2723. * or NULL if no hardware supported. The array is terminated by a NULL
  2724. * pointer.
  2725. *
  2726. * The user can only access this field via avcodec_get_hw_config().
  2727. */
  2728. const struct AVCodecHWConfigInternal **hw_configs;
  2729. } AVCodec;
  2730. /**
  2731. * Retrieve supported hardware configurations for a codec.
  2732. *
  2733. * Values of index from zero to some maximum return the indexed configuration
  2734. * descriptor; all other values return NULL. If the codec does not support
  2735. * any hardware configurations then it will always return NULL.
  2736. */
  2737. const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index);
  2738. /**
  2739. * @defgroup lavc_hwaccel AVHWAccel
  2740. *
  2741. * @note Nothing in this structure should be accessed by the user. At some
  2742. * point in future it will not be externally visible at all.
  2743. *
  2744. * @{
  2745. */
  2746. typedef struct AVHWAccel {
  2747. /**
  2748. * Name of the hardware accelerated codec.
  2749. * The name is globally unique among encoders and among decoders (but an
  2750. * encoder and a decoder can share the same name).
  2751. */
  2752. const char *name;
  2753. /**
  2754. * Type of codec implemented by the hardware accelerator.
  2755. *
  2756. * See AVMEDIA_TYPE_xxx
  2757. */
  2758. enum AVMediaType type;
  2759. /**
  2760. * Codec implemented by the hardware accelerator.
  2761. *
  2762. * See AV_CODEC_ID_xxx
  2763. */
  2764. enum AVCodecID id;
  2765. /**
  2766. * Supported pixel format.
  2767. *
  2768. * Only hardware accelerated formats are supported here.
  2769. */
  2770. enum AVPixelFormat pix_fmt;
  2771. /**
  2772. * Hardware accelerated codec capabilities.
  2773. * see FF_HWACCEL_CODEC_CAP_*
  2774. */
  2775. int capabilities;
  2776. /*****************************************************************
  2777. * No fields below this line are part of the public API. They
  2778. * may not be used outside of libavcodec and can be changed and
  2779. * removed at will.
  2780. * New public fields should be added right above.
  2781. *****************************************************************
  2782. */
  2783. struct AVHWAccel *next;
  2784. /**
  2785. * Allocate a custom buffer
  2786. */
  2787. int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
  2788. /**
  2789. * Called at the beginning of each frame or field picture.
  2790. *
  2791. * Meaningful frame information (codec specific) is guaranteed to
  2792. * be parsed at this point. This function is mandatory.
  2793. *
  2794. * Note that buf can be NULL along with buf_size set to 0.
  2795. * Otherwise, this means the whole frame is available at this point.
  2796. *
  2797. * @param avctx the codec context
  2798. * @param buf the frame data buffer base
  2799. * @param buf_size the size of the frame in bytes
  2800. * @return zero if successful, a negative value otherwise
  2801. */
  2802. int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2803. /**
  2804. * Callback for each slice.
  2805. *
  2806. * Meaningful slice information (codec specific) is guaranteed to
  2807. * be parsed at this point. This function is mandatory.
  2808. *
  2809. * @param avctx the codec context
  2810. * @param buf the slice data buffer base
  2811. * @param buf_size the size of the slice in bytes
  2812. * @return zero if successful, a negative value otherwise
  2813. */
  2814. int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2815. /**
  2816. * Called at the end of each frame or field picture.
  2817. *
  2818. * The whole picture is parsed at this point and can now be sent
  2819. * to the hardware accelerator. This function is mandatory.
  2820. *
  2821. * @param avctx the codec context
  2822. * @return zero if successful, a negative value otherwise
  2823. */
  2824. int (*end_frame)(AVCodecContext *avctx);
  2825. /**
  2826. * Size of per-frame hardware accelerator private data.
  2827. *
  2828. * Private data is allocated with av_mallocz() before
  2829. * AVCodecContext.get_buffer() and deallocated after
  2830. * AVCodecContext.release_buffer().
  2831. */
  2832. int frame_priv_data_size;
  2833. /**
  2834. * Initialize the hwaccel private data.
  2835. *
  2836. * This will be called from ff_get_format(), after hwaccel and
  2837. * hwaccel_context are set and the hwaccel private data in AVCodecInternal
  2838. * is allocated.
  2839. */
  2840. int (*init)(AVCodecContext *avctx);
  2841. /**
  2842. * Uninitialize the hwaccel private data.
  2843. *
  2844. * This will be called from get_format() or avcodec_close(), after hwaccel
  2845. * and hwaccel_context are already uninitialized.
  2846. */
  2847. int (*uninit)(AVCodecContext *avctx);
  2848. /**
  2849. * Size of the private data to allocate in
  2850. * AVCodecInternal.hwaccel_priv_data.
  2851. */
  2852. int priv_data_size;
  2853. /**
  2854. * Internal hwaccel capabilities.
  2855. */
  2856. int caps_internal;
  2857. /**
  2858. * Fill the given hw_frames context with current codec parameters. Called
  2859. * from get_format. Refer to avcodec_get_hw_frames_parameters() for
  2860. * details.
  2861. *
  2862. * This CAN be called before AVHWAccel.init is called, and you must assume
  2863. * that avctx->hwaccel_priv_data is invalid.
  2864. */
  2865. int (*frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
  2866. } AVHWAccel;
  2867. /**
  2868. * Hardware acceleration should be used for decoding even if the codec level
  2869. * used is unknown or higher than the maximum supported level reported by the
  2870. * hardware driver.
  2871. */
  2872. #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
  2873. /**
  2874. * Hardware acceleration can output YUV pixel formats with a different chroma
  2875. * sampling than 4:2:0 and/or other than 8 bits per component.
  2876. */
  2877. #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
  2878. /**
  2879. * Hardware acceleration should still be attempted for decoding when the
  2880. * codec profile does not match the reported capabilities of the hardware.
  2881. *
  2882. * For example, this can be used to try to decode baseline profile H.264
  2883. * streams in hardware - it will often succeed, because many streams marked
  2884. * as baseline profile actually conform to constrained baseline profile.
  2885. *
  2886. * @warning If the stream is actually not supported then the behaviour is
  2887. * undefined, and may include returning entirely incorrect output
  2888. * while indicating success.
  2889. */
  2890. #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2)
  2891. /**
  2892. * @}
  2893. */
  2894. #if FF_API_AVPICTURE
  2895. /**
  2896. * @defgroup lavc_picture AVPicture
  2897. *
  2898. * Functions for working with AVPicture
  2899. * @{
  2900. */
  2901. /**
  2902. * four components are given, that's all.
  2903. * the last component is alpha
  2904. * @deprecated Use the imgutils functions
  2905. */
  2906. typedef struct AVPicture {
  2907. attribute_deprecated
  2908. uint8_t *data[AV_NUM_DATA_POINTERS];
  2909. attribute_deprecated
  2910. int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
  2911. } AVPicture;
  2912. /**
  2913. * @}
  2914. */
  2915. #endif
  2916. #define AVPALETTE_SIZE 1024
  2917. #define AVPALETTE_COUNT 256
  2918. enum AVSubtitleType {
  2919. SUBTITLE_NONE,
  2920. SUBTITLE_BITMAP, ///< A bitmap, pict will be set
  2921. /**
  2922. * Plain text, the text field must be set by the decoder and is
  2923. * authoritative. ass and pict fields may contain approximations.
  2924. */
  2925. SUBTITLE_TEXT,
  2926. /**
  2927. * Formatted text, the ass field must be set by the decoder and is
  2928. * authoritative. pict and text fields may contain approximations.
  2929. */
  2930. SUBTITLE_ASS,
  2931. };
  2932. #define AV_SUBTITLE_FLAG_FORCED 0x00000001
  2933. typedef struct AVSubtitleRect {
  2934. int x; ///< top left corner of pict, undefined when pict is not set
  2935. int y; ///< top left corner of pict, undefined when pict is not set
  2936. int w; ///< width of pict, undefined when pict is not set
  2937. int h; ///< height of pict, undefined when pict is not set
  2938. int nb_colors; ///< number of colors in pict, undefined when pict is not set
  2939. #if FF_API_AVPICTURE
  2940. /**
  2941. * @deprecated unused
  2942. */
  2943. attribute_deprecated
  2944. AVPicture pict;
  2945. #endif
  2946. /**
  2947. * data+linesize for the bitmap of this subtitle.
  2948. * Can be set for text/ass as well once they are rendered.
  2949. */
  2950. uint8_t *data[4];
  2951. int linesize[4];
  2952. enum AVSubtitleType type;
  2953. char *text; ///< 0 terminated plain UTF-8 text
  2954. /**
  2955. * 0 terminated ASS/SSA compatible event line.
  2956. * The presentation of this is unaffected by the other values in this
  2957. * struct.
  2958. */
  2959. char *ass;
  2960. int flags;
  2961. } AVSubtitleRect;
  2962. typedef struct AVSubtitle {
  2963. uint16_t format; /* 0 = graphics */
  2964. uint32_t start_display_time; /* relative to packet pts, in ms */
  2965. uint32_t end_display_time; /* relative to packet pts, in ms */
  2966. unsigned num_rects;
  2967. AVSubtitleRect **rects;
  2968. int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
  2969. } AVSubtitle;
  2970. /**
  2971. * This struct describes the properties of an encoded stream.
  2972. *
  2973. * sizeof(AVCodecParameters) is not a part of the public ABI, this struct must
  2974. * be allocated with avcodec_parameters_alloc() and freed with
  2975. * avcodec_parameters_free().
  2976. */
  2977. typedef struct AVCodecParameters {
  2978. /**
  2979. * General type of the encoded data.
  2980. */
  2981. enum AVMediaType codec_type;
  2982. /**
  2983. * Specific type of the encoded data (the codec used).
  2984. */
  2985. enum AVCodecID codec_id;
  2986. /**
  2987. * Additional information about the codec (corresponds to the AVI FOURCC).
  2988. */
  2989. uint32_t codec_tag;
  2990. /**
  2991. * Extra binary data needed for initializing the decoder, codec-dependent.
  2992. *
  2993. * Must be allocated with av_malloc() and will be freed by
  2994. * avcodec_parameters_free(). The allocated size of extradata must be at
  2995. * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
  2996. * bytes zeroed.
  2997. */
  2998. uint8_t *extradata;
  2999. /**
  3000. * Size of the extradata content in bytes.
  3001. */
  3002. int extradata_size;
  3003. /**
  3004. * - video: the pixel format, the value corresponds to enum AVPixelFormat.
  3005. * - audio: the sample format, the value corresponds to enum AVSampleFormat.
  3006. */
  3007. int format;
  3008. /**
  3009. * The average bitrate of the encoded data (in bits per second).
  3010. */
  3011. int bit_rate;
  3012. int bits_per_coded_sample;
  3013. /**
  3014. * Codec-specific bitstream restrictions that the stream conforms to.
  3015. */
  3016. int profile;
  3017. int level;
  3018. /**
  3019. * Video only. The dimensions of the video frame in pixels.
  3020. */
  3021. int width;
  3022. int height;
  3023. /**
  3024. * Video only. The aspect ratio (width / height) which a single pixel
  3025. * should have when displayed.
  3026. *
  3027. * When the aspect ratio is unknown / undefined, the numerator should be
  3028. * set to 0 (the denominator may have any value).
  3029. */
  3030. AVRational sample_aspect_ratio;
  3031. /**
  3032. * Video only. The order of the fields in interlaced video.
  3033. */
  3034. enum AVFieldOrder field_order;
  3035. /**
  3036. * Video only. Additional colorspace characteristics.
  3037. */
  3038. enum AVColorRange color_range;
  3039. enum AVColorPrimaries color_primaries;
  3040. enum AVColorTransferCharacteristic color_trc;
  3041. enum AVColorSpace color_space;
  3042. enum AVChromaLocation chroma_location;
  3043. /**
  3044. * Audio only. The channel layout bitmask. May be 0 if the channel layout is
  3045. * unknown or unspecified, otherwise the number of bits set must be equal to
  3046. * the channels field.
  3047. */
  3048. uint64_t channel_layout;
  3049. /**
  3050. * Audio only. The number of audio channels.
  3051. */
  3052. int channels;
  3053. /**
  3054. * Audio only. The number of audio samples per second.
  3055. */
  3056. int sample_rate;
  3057. /**
  3058. * Audio only. The number of bytes per coded audio frame, required by some
  3059. * formats.
  3060. *
  3061. * Corresponds to nBlockAlign in WAVEFORMATEX.
  3062. */
  3063. int block_align;
  3064. /**
  3065. * Audio only. The amount of padding (in samples) inserted by the encoder at
  3066. * the beginning of the audio. I.e. this number of leading decoded samples
  3067. * must be discarded by the caller to get the original audio without leading
  3068. * padding.
  3069. */
  3070. int initial_padding;
  3071. /**
  3072. * Audio only. The amount of padding (in samples) appended by the encoder to
  3073. * the end of the audio. I.e. this number of decoded samples must be
  3074. * discarded by the caller from the end of the stream to get the original
  3075. * audio without any trailing padding.
  3076. */
  3077. int trailing_padding;
  3078. } AVCodecParameters;
  3079. /**
  3080. * If c is NULL, returns the first registered codec,
  3081. * if c is non-NULL, returns the next registered codec after c,
  3082. * or NULL if c is the last one.
  3083. */
  3084. AVCodec *av_codec_next(const AVCodec *c);
  3085. /**
  3086. * Return the LIBAVCODEC_VERSION_INT constant.
  3087. */
  3088. unsigned avcodec_version(void);
  3089. /**
  3090. * Return the libavcodec build-time configuration.
  3091. */
  3092. const char *avcodec_configuration(void);
  3093. /**
  3094. * Return the libavcodec license.
  3095. */
  3096. const char *avcodec_license(void);
  3097. /**
  3098. * Register the codec codec and initialize libavcodec.
  3099. *
  3100. * @warning either this function or avcodec_register_all() must be called
  3101. * before any other libavcodec functions.
  3102. *
  3103. * @see avcodec_register_all()
  3104. */
  3105. void avcodec_register(AVCodec *codec);
  3106. /**
  3107. * Register all the codecs, parsers and bitstream filters which were enabled at
  3108. * configuration time. If you do not call this function you can select exactly
  3109. * which formats you want to support, by using the individual registration
  3110. * functions.
  3111. *
  3112. * @see avcodec_register
  3113. * @see av_register_codec_parser
  3114. * @see av_register_bitstream_filter
  3115. */
  3116. void avcodec_register_all(void);
  3117. /**
  3118. * Allocate an AVCodecContext and set its fields to default values. The
  3119. * resulting struct should be freed with avcodec_free_context().
  3120. *
  3121. * @param codec if non-NULL, allocate private data and initialize defaults
  3122. * for the given codec. It is illegal to then call avcodec_open2()
  3123. * with a different codec.
  3124. * If NULL, then the codec-specific defaults won't be initialized,
  3125. * which may result in suboptimal default settings (this is
  3126. * important mainly for encoders, e.g. libx264).
  3127. *
  3128. * @return An AVCodecContext filled with default values or NULL on failure.
  3129. */
  3130. AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
  3131. /**
  3132. * Free the codec context and everything associated with it and write NULL to
  3133. * the provided pointer.
  3134. */
  3135. void avcodec_free_context(AVCodecContext **avctx);
  3136. #if FF_API_GET_CONTEXT_DEFAULTS
  3137. /**
  3138. * @deprecated This function should not be used, as closing and opening a codec
  3139. * context multiple time is not supported. A new codec context should be
  3140. * allocated for each new use.
  3141. */
  3142. int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
  3143. #endif
  3144. /**
  3145. * Get the AVClass for AVCodecContext. It can be used in combination with
  3146. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  3147. *
  3148. * @see av_opt_find().
  3149. */
  3150. const AVClass *avcodec_get_class(void);
  3151. #if FF_API_COPY_CONTEXT
  3152. /**
  3153. * Copy the settings of the source AVCodecContext into the destination
  3154. * AVCodecContext. The resulting destination codec context will be
  3155. * unopened, i.e. you are required to call avcodec_open2() before you
  3156. * can use this AVCodecContext to decode/encode video/audio data.
  3157. *
  3158. * @param dest target codec context, should be initialized with
  3159. * avcodec_alloc_context3(), but otherwise uninitialized
  3160. * @param src source codec context
  3161. * @return AVERROR() on error (e.g. memory allocation error), 0 on success
  3162. *
  3163. * @deprecated The semantics of this function are ill-defined and it should not
  3164. * be used. If you need to transfer the stream parameters from one codec context
  3165. * to another, use an intermediate AVCodecParameters instance and the
  3166. * avcodec_parameters_from_context() / avcodec_parameters_to_context()
  3167. * functions.
  3168. */
  3169. attribute_deprecated
  3170. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
  3171. #endif
  3172. /**
  3173. * Allocate a new AVCodecParameters and set its fields to default values
  3174. * (unknown/invalid/0). The returned struct must be freed with
  3175. * avcodec_parameters_free().
  3176. */
  3177. AVCodecParameters *avcodec_parameters_alloc(void);
  3178. /**
  3179. * Free an AVCodecParameters instance and everything associated with it and
  3180. * write NULL to the supplied pointer.
  3181. */
  3182. void avcodec_parameters_free(AVCodecParameters **par);
  3183. /**
  3184. * Copy the contents of src to dst. Any allocated fields in dst are freed and
  3185. * replaced with newly allocated duplicates of the corresponding fields in src.
  3186. *
  3187. * @return >= 0 on success, a negative AVERROR code on failure.
  3188. */
  3189. int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src);
  3190. /**
  3191. * Fill the parameters struct based on the values from the supplied codec
  3192. * context. Any allocated fields in par are freed and replaced with duplicates
  3193. * of the corresponding fields in codec.
  3194. *
  3195. * @return >= 0 on success, a negative AVERROR code on failure
  3196. */
  3197. int avcodec_parameters_from_context(AVCodecParameters *par,
  3198. const AVCodecContext *codec);
  3199. /**
  3200. * Fill the codec context based on the values from the supplied codec
  3201. * parameters. Any allocated fields in codec that have a corresponding field in
  3202. * par are freed and replaced with duplicates of the corresponding field in par.
  3203. * Fields in codec that do not have a counterpart in par are not touched.
  3204. *
  3205. * @return >= 0 on success, a negative AVERROR code on failure.
  3206. */
  3207. int avcodec_parameters_to_context(AVCodecContext *codec,
  3208. const AVCodecParameters *par);
  3209. /**
  3210. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  3211. * function the context has to be allocated with avcodec_alloc_context3().
  3212. *
  3213. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  3214. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  3215. * retrieving a codec.
  3216. *
  3217. * @warning This function is not thread safe!
  3218. *
  3219. * @note Always call this function before using decoding routines (such as
  3220. * @ref avcodec_receive_frame()).
  3221. *
  3222. * @code
  3223. * avcodec_register_all();
  3224. * av_dict_set(&opts, "b", "2.5M", 0);
  3225. * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
  3226. * if (!codec)
  3227. * exit(1);
  3228. *
  3229. * context = avcodec_alloc_context3(codec);
  3230. *
  3231. * if (avcodec_open2(context, codec, opts) < 0)
  3232. * exit(1);
  3233. * @endcode
  3234. *
  3235. * @param avctx The context to initialize.
  3236. * @param codec The codec to open this context for. If a non-NULL codec has been
  3237. * previously passed to avcodec_alloc_context3() or
  3238. * for this context, then this parameter MUST be either NULL or
  3239. * equal to the previously passed codec.
  3240. * @param options A dictionary filled with AVCodecContext and codec-private options.
  3241. * On return this object will be filled with options that were not found.
  3242. *
  3243. * @return zero on success, a negative value on error
  3244. * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
  3245. * av_dict_set(), av_opt_find().
  3246. */
  3247. int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
  3248. /**
  3249. * Close a given AVCodecContext and free all the data associated with it
  3250. * (but not the AVCodecContext itself).
  3251. *
  3252. * Calling this function on an AVCodecContext that hasn't been opened will free
  3253. * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
  3254. * codec. Subsequent calls will do nothing.
  3255. *
  3256. * @note Do not use this function. Use avcodec_free_context() to destroy a
  3257. * codec context (either open or closed). Opening and closing a codec context
  3258. * multiple times is not supported anymore -- use multiple codec contexts
  3259. * instead.
  3260. */
  3261. int avcodec_close(AVCodecContext *avctx);
  3262. /**
  3263. * Free all allocated data in the given subtitle struct.
  3264. *
  3265. * @param sub AVSubtitle to free.
  3266. */
  3267. void avsubtitle_free(AVSubtitle *sub);
  3268. /**
  3269. * @}
  3270. */
  3271. /**
  3272. * @addtogroup lavc_packet
  3273. * @{
  3274. */
  3275. /**
  3276. * Allocate an AVPacket and set its fields to default values. The resulting
  3277. * struct must be freed using av_packet_free().
  3278. *
  3279. * @return An AVPacket filled with default values or NULL on failure.
  3280. *
  3281. * @note this only allocates the AVPacket itself, not the data buffers. Those
  3282. * must be allocated through other means such as av_new_packet.
  3283. *
  3284. * @see av_new_packet
  3285. */
  3286. AVPacket *av_packet_alloc(void);
  3287. /**
  3288. * Create a new packet that references the same data as src.
  3289. *
  3290. * This is a shortcut for av_packet_alloc()+av_packet_ref().
  3291. *
  3292. * @return newly created AVPacket on success, NULL on error.
  3293. *
  3294. * @see av_packet_alloc
  3295. * @see av_packet_ref
  3296. */
  3297. AVPacket *av_packet_clone(const AVPacket *src);
  3298. /**
  3299. * Free the packet, if the packet is reference counted, it will be
  3300. * unreferenced first.
  3301. *
  3302. * @param pkt packet to be freed. The pointer will be set to NULL.
  3303. * @note passing NULL is a no-op.
  3304. */
  3305. void av_packet_free(AVPacket **pkt);
  3306. /**
  3307. * Initialize optional fields of a packet with default values.
  3308. *
  3309. * Note, this does not touch the data and size members, which have to be
  3310. * initialized separately.
  3311. *
  3312. * @param pkt packet
  3313. */
  3314. void av_init_packet(AVPacket *pkt);
  3315. /**
  3316. * Allocate the payload of a packet and initialize its fields with
  3317. * default values.
  3318. *
  3319. * @param pkt packet
  3320. * @param size wanted payload size
  3321. * @return 0 if OK, AVERROR_xxx otherwise
  3322. */
  3323. int av_new_packet(AVPacket *pkt, int size);
  3324. /**
  3325. * Reduce packet size, correctly zeroing padding
  3326. *
  3327. * @param pkt packet
  3328. * @param size new size
  3329. */
  3330. void av_shrink_packet(AVPacket *pkt, int size);
  3331. /**
  3332. * Increase packet size, correctly zeroing padding
  3333. *
  3334. * @param pkt packet
  3335. * @param grow_by number of bytes by which to increase the size of the packet
  3336. */
  3337. int av_grow_packet(AVPacket *pkt, int grow_by);
  3338. /**
  3339. * Initialize a reference-counted packet from av_malloc()ed data.
  3340. *
  3341. * @param pkt packet to be initialized. This function will set the data, size,
  3342. * buf and destruct fields, all others are left untouched.
  3343. * @param data Data allocated by av_malloc() to be used as packet data. If this
  3344. * function returns successfully, the data is owned by the underlying AVBuffer.
  3345. * The caller may not access the data through other means.
  3346. * @param size size of data in bytes, without the padding. I.e. the full buffer
  3347. * size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
  3348. *
  3349. * @return 0 on success, a negative AVERROR on error
  3350. */
  3351. int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
  3352. #if FF_API_AVPACKET_OLD_API
  3353. /**
  3354. * @warning This is a hack - the packet memory allocation stuff is broken. The
  3355. * packet is allocated if it was not really allocated.
  3356. *
  3357. * @deprecated Use av_packet_ref
  3358. */
  3359. attribute_deprecated
  3360. int av_dup_packet(AVPacket *pkt);
  3361. /**
  3362. * Free a packet.
  3363. *
  3364. * @deprecated Use av_packet_unref
  3365. *
  3366. * @param pkt packet to free
  3367. */
  3368. attribute_deprecated
  3369. void av_free_packet(AVPacket *pkt);
  3370. #endif
  3371. /**
  3372. * Allocate new information of a packet.
  3373. *
  3374. * @param pkt packet
  3375. * @param type side information type
  3376. * @param size side information size
  3377. * @return pointer to fresh allocated data or NULL otherwise
  3378. */
  3379. uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3380. int size);
  3381. /**
  3382. * Wrap an existing array as a packet side data.
  3383. *
  3384. * @param pkt packet
  3385. * @param type side information type
  3386. * @param data the side data array. It must be allocated with the av_malloc()
  3387. * family of functions. The ownership of the data is transferred to
  3388. * pkt.
  3389. * @param size side information size
  3390. * @return a non-negative number on success, a negative AVERROR code on
  3391. * failure. On failure, the packet is unchanged and the data remains
  3392. * owned by the caller.
  3393. */
  3394. int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3395. uint8_t *data, size_t size);
  3396. /**
  3397. * Shrink the already allocated side data buffer
  3398. *
  3399. * @param pkt packet
  3400. * @param type side information type
  3401. * @param size new side information size
  3402. * @return 0 on success, < 0 on failure
  3403. */
  3404. int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3405. int size);
  3406. /**
  3407. * Get side information from packet.
  3408. *
  3409. * @param pkt packet
  3410. * @param type desired side information type
  3411. * @param size pointer for side information size to store (optional)
  3412. * @return pointer to data if present or NULL otherwise
  3413. */
  3414. uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3415. int *size);
  3416. /**
  3417. * Convenience function to free all the side data stored.
  3418. * All the other fields stay untouched.
  3419. *
  3420. * @param pkt packet
  3421. */
  3422. void av_packet_free_side_data(AVPacket *pkt);
  3423. /**
  3424. * Setup a new reference to the data described by a given packet
  3425. *
  3426. * If src is reference-counted, setup dst as a new reference to the
  3427. * buffer in src. Otherwise allocate a new buffer in dst and copy the
  3428. * data from src into it.
  3429. *
  3430. * All the other fields are copied from src.
  3431. *
  3432. * @see av_packet_unref
  3433. *
  3434. * @param dst Destination packet
  3435. * @param src Source packet
  3436. *
  3437. * @return 0 on success, a negative AVERROR on error.
  3438. */
  3439. int av_packet_ref(AVPacket *dst, const AVPacket *src);
  3440. /**
  3441. * Wipe the packet.
  3442. *
  3443. * Unreference the buffer referenced by the packet and reset the
  3444. * remaining packet fields to their default values.
  3445. *
  3446. * @param pkt The packet to be unreferenced.
  3447. */
  3448. void av_packet_unref(AVPacket *pkt);
  3449. /**
  3450. * Move every field in src to dst and reset src.
  3451. *
  3452. * @see av_packet_unref
  3453. *
  3454. * @param src Source packet, will be reset
  3455. * @param dst Destination packet
  3456. */
  3457. void av_packet_move_ref(AVPacket *dst, AVPacket *src);
  3458. /**
  3459. * Copy only "properties" fields from src to dst.
  3460. *
  3461. * Properties for the purpose of this function are all the fields
  3462. * beside those related to the packet data (buf, data, size)
  3463. *
  3464. * @param dst Destination packet
  3465. * @param src Source packet
  3466. *
  3467. * @return 0 on success AVERROR on failure.
  3468. */
  3469. int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
  3470. /**
  3471. * Convert valid timing fields (timestamps / durations) in a packet from one
  3472. * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
  3473. * ignored.
  3474. *
  3475. * @param pkt packet on which the conversion will be performed
  3476. * @param tb_src source timebase, in which the timing fields in pkt are
  3477. * expressed
  3478. * @param tb_dst destination timebase, to which the timing fields will be
  3479. * converted
  3480. */
  3481. void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
  3482. /**
  3483. * @}
  3484. */
  3485. /**
  3486. * @addtogroup lavc_decoding
  3487. * @{
  3488. */
  3489. /**
  3490. * Find a registered decoder with a matching codec ID.
  3491. *
  3492. * @param id AVCodecID of the requested decoder
  3493. * @return A decoder if one was found, NULL otherwise.
  3494. */
  3495. AVCodec *avcodec_find_decoder(enum AVCodecID id);
  3496. /**
  3497. * Find a registered decoder with the specified name.
  3498. *
  3499. * @param name name of the requested decoder
  3500. * @return A decoder if one was found, NULL otherwise.
  3501. */
  3502. AVCodec *avcodec_find_decoder_by_name(const char *name);
  3503. /**
  3504. * The default callback for AVCodecContext.get_buffer2(). It is made public so
  3505. * it can be called by custom get_buffer2() implementations for decoders without
  3506. * AV_CODEC_CAP_DR1 set.
  3507. */
  3508. int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
  3509. /**
  3510. * Modify width and height values so that they will result in a memory
  3511. * buffer that is acceptable for the codec if you do not use any horizontal
  3512. * padding.
  3513. *
  3514. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  3515. */
  3516. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  3517. /**
  3518. * Modify width and height values so that they will result in a memory
  3519. * buffer that is acceptable for the codec if you also ensure that all
  3520. * line sizes are a multiple of the respective linesize_align[i].
  3521. *
  3522. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  3523. */
  3524. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
  3525. int linesize_align[AV_NUM_DATA_POINTERS]);
  3526. /**
  3527. * Decode the audio frame of size avpkt->size from avpkt->data into frame.
  3528. *
  3529. * Some decoders may support multiple frames in a single AVPacket. Such
  3530. * decoders would then just decode the first frame and the return value would be
  3531. * less than the packet size. In this case, avcodec_decode_audio4 has to be
  3532. * called again with an AVPacket containing the remaining data in order to
  3533. * decode the second frame, etc... Even if no frames are returned, the packet
  3534. * needs to be fed to the decoder with remaining data until it is completely
  3535. * consumed or an error occurs.
  3536. *
  3537. * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
  3538. * and output. This means that for some packets they will not immediately
  3539. * produce decoded output and need to be flushed at the end of decoding to get
  3540. * all the decoded data. Flushing is done by calling this function with packets
  3541. * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
  3542. * returning samples. It is safe to flush even those decoders that are not
  3543. * marked with AV_CODEC_CAP_DELAY, then no samples will be returned.
  3544. *
  3545. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  3546. * larger than the actual read bytes because some optimized bitstream
  3547. * readers read 32 or 64 bits at once and could read over the end.
  3548. *
  3549. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3550. * before packets may be fed to the decoder.
  3551. *
  3552. * @param avctx the codec context
  3553. * @param[out] frame The AVFrame in which to store decoded audio samples.
  3554. * The decoder will allocate a buffer for the decoded frame by
  3555. * calling the AVCodecContext.get_buffer2() callback.
  3556. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  3557. * reference counted and the returned reference belongs to the
  3558. * caller. The caller must release the frame using av_frame_unref()
  3559. * when the frame is no longer needed. The caller may safely write
  3560. * to the frame if av_frame_is_writable() returns 1.
  3561. * When AVCodecContext.refcounted_frames is set to 0, the returned
  3562. * reference belongs to the decoder and is valid only until the
  3563. * next call to this function or until closing or flushing the
  3564. * decoder. The caller may not write to it.
  3565. * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
  3566. * non-zero. Note that this field being set to zero
  3567. * does not mean that an error has occurred. For
  3568. * decoders with AV_CODEC_CAP_DELAY set, no given decode
  3569. * call is guaranteed to produce a frame.
  3570. * @param[in] avpkt The input AVPacket containing the input buffer.
  3571. * At least avpkt->data and avpkt->size should be set. Some
  3572. * decoders might also require additional fields to be set.
  3573. * @return A negative error code is returned if an error occurred during
  3574. * decoding, otherwise the number of bytes consumed from the input
  3575. * AVPacket is returned.
  3576. *
  3577. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  3578. */
  3579. attribute_deprecated
  3580. int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
  3581. int *got_frame_ptr, AVPacket *avpkt);
  3582. /**
  3583. * Decode the video frame of size avpkt->size from avpkt->data into picture.
  3584. * Some decoders may support multiple frames in a single AVPacket, such
  3585. * decoders would then just decode the first frame.
  3586. *
  3587. * @warning The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than
  3588. * the actual read bytes because some optimized bitstream readers read 32 or 64
  3589. * bits at once and could read over the end.
  3590. *
  3591. * @warning The end of the input buffer buf should be set to 0 to ensure that
  3592. * no overreading happens for damaged MPEG streams.
  3593. *
  3594. * @note Codecs which have the AV_CODEC_CAP_DELAY capability set have a delay
  3595. * between input and output, these need to be fed with avpkt->data=NULL,
  3596. * avpkt->size=0 at the end to return the remaining frames.
  3597. *
  3598. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3599. * before packets may be fed to the decoder.
  3600. *
  3601. * @param avctx the codec context
  3602. * @param[out] picture The AVFrame in which the decoded video frame will be stored.
  3603. * Use av_frame_alloc() to get an AVFrame. The codec will
  3604. * allocate memory for the actual bitmap by calling the
  3605. * AVCodecContext.get_buffer2() callback.
  3606. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  3607. * reference counted and the returned reference belongs to the
  3608. * caller. The caller must release the frame using av_frame_unref()
  3609. * when the frame is no longer needed. The caller may safely write
  3610. * to the frame if av_frame_is_writable() returns 1.
  3611. * When AVCodecContext.refcounted_frames is set to 0, the returned
  3612. * reference belongs to the decoder and is valid only until the
  3613. * next call to this function or until closing or flushing the
  3614. * decoder. The caller may not write to it.
  3615. *
  3616. * @param[in] avpkt The input AVPacket containing the input buffer.
  3617. * You can create such packet with av_init_packet() and by then setting
  3618. * data and size, some decoders might in addition need other fields like
  3619. * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
  3620. * fields possible.
  3621. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
  3622. * @return On error a negative value is returned, otherwise the number of bytes
  3623. * used or zero if no frame could be decompressed.
  3624. *
  3625. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  3626. */
  3627. attribute_deprecated
  3628. int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  3629. int *got_picture_ptr,
  3630. AVPacket *avpkt);
  3631. /**
  3632. * Decode a subtitle message.
  3633. * Return a negative value on error, otherwise return the number of bytes used.
  3634. * If no subtitle could be decompressed, got_sub_ptr is zero.
  3635. * Otherwise, the subtitle is stored in *sub.
  3636. * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
  3637. * simplicity, because the performance difference is expect to be negligible
  3638. * and reusing a get_buffer written for video codecs would probably perform badly
  3639. * due to a potentially very different allocation pattern.
  3640. *
  3641. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3642. * before packets may be fed to the decoder.
  3643. *
  3644. * @param avctx the codec context
  3645. * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
  3646. freed with avsubtitle_free if *got_sub_ptr is set.
  3647. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
  3648. * @param[in] avpkt The input AVPacket containing the input buffer.
  3649. */
  3650. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  3651. int *got_sub_ptr,
  3652. AVPacket *avpkt);
  3653. /**
  3654. * Supply raw packet data as input to a decoder.
  3655. *
  3656. * Internally, this call will copy relevant AVCodecContext fields, which can
  3657. * influence decoding per-packet, and apply them when the packet is actually
  3658. * decoded. (For example AVCodecContext.skip_frame, which might direct the
  3659. * decoder to drop the frame contained by the packet sent with this function.)
  3660. *
  3661. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  3662. * larger than the actual read bytes because some optimized bitstream
  3663. * readers read 32 or 64 bits at once and could read over the end.
  3664. *
  3665. * @warning Do not mix this API with the legacy API (like avcodec_decode_video2())
  3666. * on the same AVCodecContext. It will return unexpected results now
  3667. * or in future libavcodec versions.
  3668. *
  3669. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3670. * before packets may be fed to the decoder.
  3671. *
  3672. * @param avctx codec context
  3673. * @param[in] avpkt The input AVPacket. Usually, this will be a single video
  3674. * frame, or several complete audio frames.
  3675. * Ownership of the packet remains with the caller, and the
  3676. * decoder will not write to the packet. The decoder may create
  3677. * a reference to the packet data (or copy it if the packet is
  3678. * not reference-counted).
  3679. * Unlike with older APIs, the packet is always fully consumed,
  3680. * and if it contains multiple frames (e.g. some audio codecs),
  3681. * will require you to call avcodec_receive_frame() multiple
  3682. * times afterwards before you can send a new packet.
  3683. * It can be NULL (or an AVPacket with data set to NULL and
  3684. * size set to 0); in this case, it is considered a flush
  3685. * packet, which signals the end of the stream. Sending the
  3686. * first flush packet will return success. Subsequent ones are
  3687. * unnecessary and will return AVERROR_EOF. If the decoder
  3688. * still has frames buffered, it will return them after sending
  3689. * a flush packet.
  3690. *
  3691. * @return 0 on success, otherwise negative error code:
  3692. * AVERROR(EAGAIN): input is not accepted in the current state - user
  3693. * must read output with avcodec_receive_frame() (once
  3694. * all output is read, the packet should be resent, and
  3695. * the call will not fail with EAGAIN).
  3696. * AVERROR_EOF: the decoder has been flushed, and no new packets can
  3697. * be sent to it (also returned if more than 1 flush
  3698. * packet is sent)
  3699. * AVERROR(EINVAL): codec not opened, it is an encoder, or requires flush
  3700. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  3701. * other errors: legitimate decoding errors
  3702. */
  3703. int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  3704. /**
  3705. * Return decoded output data from a decoder.
  3706. *
  3707. * @param avctx codec context
  3708. * @param frame This will be set to a reference-counted video or audio
  3709. * frame (depending on the decoder type) allocated by the
  3710. * decoder. Note that the function will always call
  3711. * av_frame_unref(frame) before doing anything else.
  3712. *
  3713. * @return
  3714. * 0: success, a frame was returned
  3715. * AVERROR(EAGAIN): output is not available in this state - user must try
  3716. * to send new input
  3717. * AVERROR_EOF: the decoder has been fully flushed, and there will be
  3718. * no more output frames
  3719. * AVERROR(EINVAL): codec not opened, or it is an encoder
  3720. * other negative values: legitimate decoding errors
  3721. */
  3722. int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
  3723. /**
  3724. * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
  3725. * to retrieve buffered output packets.
  3726. *
  3727. * @param avctx codec context
  3728. * @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
  3729. * Ownership of the frame remains with the caller, and the
  3730. * encoder will not write to the frame. The encoder may create
  3731. * a reference to the frame data (or copy it if the frame is
  3732. * not reference-counted).
  3733. * It can be NULL, in which case it is considered a flush
  3734. * packet. This signals the end of the stream. If the encoder
  3735. * still has packets buffered, it will return them after this
  3736. * call. Once flushing mode has been entered, additional flush
  3737. * packets are ignored, and sending frames will return
  3738. * AVERROR_EOF.
  3739. *
  3740. * For audio:
  3741. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  3742. * can have any number of samples.
  3743. * If it is not set, frame->nb_samples must be equal to
  3744. * avctx->frame_size for all frames except the last.
  3745. * The final frame may be smaller than avctx->frame_size.
  3746. * @return 0 on success, otherwise negative error code:
  3747. * AVERROR(EAGAIN): input is not accepted in the current state - user
  3748. * must read output with avcodec_receive_packet() (once
  3749. * all output is read, the packet should be resent, and
  3750. * the call will not fail with EAGAIN).
  3751. * AVERROR_EOF: the encoder has been flushed, and no new frames can
  3752. * be sent to it
  3753. * AVERROR(EINVAL): codec not opened, refcounted_frames not set, it is a
  3754. * decoder, or requires flush
  3755. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  3756. * other errors: legitimate decoding errors
  3757. */
  3758. int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  3759. /**
  3760. * Read encoded data from the encoder.
  3761. *
  3762. * @param avctx codec context
  3763. * @param avpkt This will be set to a reference-counted packet allocated by the
  3764. * encoder. Note that the function will always call
  3765. * av_frame_unref(frame) before doing anything else.
  3766. * @return 0 on success, otherwise negative error code:
  3767. * AVERROR(EAGAIN): output is not available in the current state - user
  3768. * must try to send input
  3769. * AVERROR_EOF: the encoder has been fully flushed, and there will be
  3770. * no more output packets
  3771. * AVERROR(EINVAL): codec not opened, or it is an encoder
  3772. * other errors: legitimate decoding errors
  3773. */
  3774. int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  3775. /**
  3776. * Create and return a AVHWFramesContext with values adequate for hardware
  3777. * decoding. This is meant to get called from the get_format callback, and is
  3778. * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx.
  3779. * This API is for decoding with certain hardware acceleration modes/APIs only.
  3780. *
  3781. * The returned AVHWFramesContext is not initialized. The caller must do this
  3782. * with av_hwframe_ctx_init().
  3783. *
  3784. * Calling this function is not a requirement, but makes it simpler to avoid
  3785. * codec or hardware API specific details when manually allocating frames.
  3786. *
  3787. * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx,
  3788. * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes
  3789. * it unnecessary to call this function or having to care about
  3790. * AVHWFramesContext initialization at all.
  3791. *
  3792. * There are a number of requirements for calling this function:
  3793. *
  3794. * - It must be called from get_format with the same avctx parameter that was
  3795. * passed to get_format. Calling it outside of get_format is not allowed, and
  3796. * can trigger undefined behavior.
  3797. * - The function is not always supported (see description of return values).
  3798. * Even if this function returns successfully, hwaccel initialization could
  3799. * fail later. (The degree to which implementations check whether the stream
  3800. * is actually supported varies. Some do this check only after the user's
  3801. * get_format callback returns.)
  3802. * - The hw_pix_fmt must be one of the choices suggested by get_format. If the
  3803. * user decides to use a AVHWFramesContext prepared with this API function,
  3804. * the user must return the same hw_pix_fmt from get_format.
  3805. * - The device_ref passed to this function must support the given hw_pix_fmt.
  3806. * - After calling this API function, it is the user's responsibility to
  3807. * initialize the AVHWFramesContext (returned by the out_frames_ref parameter),
  3808. * and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done
  3809. * before returning from get_format (this is implied by the normal
  3810. * AVCodecContext.hw_frames_ctx API rules).
  3811. * - The AVHWFramesContext parameters may change every time time get_format is
  3812. * called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So
  3813. * you are inherently required to go through this process again on every
  3814. * get_format call.
  3815. * - It is perfectly possible to call this function without actually using
  3816. * the resulting AVHWFramesContext. One use-case might be trying to reuse a
  3817. * previously initialized AVHWFramesContext, and calling this API function
  3818. * only to test whether the required frame parameters have changed.
  3819. * - Fields that use dynamically allocated values of any kind must not be set
  3820. * by the user unless setting them is explicitly allowed by the documentation.
  3821. * If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque,
  3822. * the new free callback must call the potentially set previous free callback.
  3823. * This API call may set any dynamically allocated fields, including the free
  3824. * callback.
  3825. *
  3826. * The function will set at least the following fields on AVHWFramesContext
  3827. * (potentially more, depending on hwaccel API):
  3828. *
  3829. * - All fields set by av_hwframe_ctx_alloc().
  3830. * - Set the format field to hw_pix_fmt.
  3831. * - Set the sw_format field to the most suited and most versatile format. (An
  3832. * implication is that this will prefer generic formats over opaque formats
  3833. * with arbitrary restrictions, if possible.)
  3834. * - Set the width/height fields to the coded frame size, rounded up to the
  3835. * API-specific minimum alignment.
  3836. * - Only _if_ the hwaccel requires a pre-allocated pool: set the initial_pool_size
  3837. * field to the number of maximum reference surfaces possible with the codec,
  3838. * plus 1 surface for the user to work (meaning the user can safely reference
  3839. * at most 1 decoded surface at a time), plus additional buffering introduced
  3840. * by frame threading. If the hwaccel does not require pre-allocation, the
  3841. * field is left to 0, and the decoder will allocate new surfaces on demand
  3842. * during decoding.
  3843. * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying
  3844. * hardware API.
  3845. *
  3846. * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but
  3847. * with basic frame parameters set.
  3848. *
  3849. * The function is stateless, and does not change the AVCodecContext or the
  3850. * device_ref AVHWDeviceContext.
  3851. *
  3852. * @param avctx The context which is currently calling get_format, and which
  3853. * implicitly contains all state needed for filling the returned
  3854. * AVHWFramesContext properly.
  3855. * @param device_ref A reference to the AVHWDeviceContext describing the device
  3856. * which will be used by the hardware decoder.
  3857. * @param hw_pix_fmt The hwaccel format you are going to return from get_format.
  3858. * @param out_frames_ref On success, set to a reference to an _uninitialized_
  3859. * AVHWFramesContext, created from the given device_ref.
  3860. * Fields will be set to values required for decoding.
  3861. * Not changed if an error is returned.
  3862. * @return zero on success, a negative value on error. The following error codes
  3863. * have special semantics:
  3864. * AVERROR(ENOENT): the decoder does not support this functionality. Setup
  3865. * is always manual, or it is a decoder which does not
  3866. * support setting AVCodecContext.hw_frames_ctx at all,
  3867. * or it is a software format.
  3868. * AVERROR(EINVAL): it is known that hardware decoding is not supported for
  3869. * this configuration, or the device_ref is not supported
  3870. * for the hwaccel referenced by hw_pix_fmt.
  3871. */
  3872. int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
  3873. AVBufferRef *device_ref,
  3874. enum AVPixelFormat hw_pix_fmt,
  3875. AVBufferRef **out_frames_ref);
  3876. /**
  3877. * @defgroup lavc_parsing Frame parsing
  3878. * @{
  3879. */
  3880. enum AVPictureStructure {
  3881. AV_PICTURE_STRUCTURE_UNKNOWN, //< unknown
  3882. AV_PICTURE_STRUCTURE_TOP_FIELD, //< coded as top field
  3883. AV_PICTURE_STRUCTURE_BOTTOM_FIELD, //< coded as bottom field
  3884. AV_PICTURE_STRUCTURE_FRAME, //< coded as frame
  3885. };
  3886. typedef struct AVCodecParserContext {
  3887. void *priv_data;
  3888. struct AVCodecParser *parser;
  3889. int64_t frame_offset; /* offset of the current frame */
  3890. int64_t cur_offset; /* current offset
  3891. (incremented by each av_parser_parse()) */
  3892. int64_t next_frame_offset; /* offset of the next frame */
  3893. /* video info */
  3894. int pict_type; /* XXX: Put it back in AVCodecContext. */
  3895. /**
  3896. * This field is used for proper frame duration computation in lavf.
  3897. * It signals, how much longer the frame duration of the current frame
  3898. * is compared to normal frame duration.
  3899. *
  3900. * frame_duration = (1 + repeat_pict) * time_base
  3901. *
  3902. * It is used by codecs like H.264 to display telecined material.
  3903. */
  3904. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  3905. int64_t pts; /* pts of the current frame */
  3906. int64_t dts; /* dts of the current frame */
  3907. /* private data */
  3908. int64_t last_pts;
  3909. int64_t last_dts;
  3910. int fetch_timestamp;
  3911. #define AV_PARSER_PTS_NB 4
  3912. int cur_frame_start_index;
  3913. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  3914. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  3915. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  3916. int flags;
  3917. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  3918. #define PARSER_FLAG_ONCE 0x0002
  3919. /// Set if the parser has a valid file offset
  3920. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
  3921. int64_t offset; ///< byte offset from starting packet start
  3922. int64_t cur_frame_end[AV_PARSER_PTS_NB];
  3923. /**
  3924. * Set by parser to 1 for key frames and 0 for non-key frames.
  3925. * It is initialized to -1, so if the parser doesn't set this flag,
  3926. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
  3927. * will be used.
  3928. */
  3929. int key_frame;
  3930. #if FF_API_CONVERGENCE_DURATION
  3931. /**
  3932. * @deprecated unused
  3933. */
  3934. attribute_deprecated
  3935. int64_t convergence_duration;
  3936. #endif
  3937. // Timestamp generation support:
  3938. /**
  3939. * Synchronization point for start of timestamp generation.
  3940. *
  3941. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
  3942. * (default).
  3943. *
  3944. * For example, this corresponds to presence of H.264 buffering period
  3945. * SEI message.
  3946. */
  3947. int dts_sync_point;
  3948. /**
  3949. * Offset of the current timestamp against last timestamp sync point in
  3950. * units of AVCodecContext.time_base.
  3951. *
  3952. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3953. * contain a valid timestamp offset.
  3954. *
  3955. * Note that the timestamp of sync point has usually a nonzero
  3956. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
  3957. * the next frame after timestamp sync point will be usually 1.
  3958. *
  3959. * For example, this corresponds to H.264 cpb_removal_delay.
  3960. */
  3961. int dts_ref_dts_delta;
  3962. /**
  3963. * Presentation delay of current frame in units of AVCodecContext.time_base.
  3964. *
  3965. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3966. * contain valid non-negative timestamp delta (presentation time of a frame
  3967. * must not lie in the past).
  3968. *
  3969. * This delay represents the difference between decoding and presentation
  3970. * time of the frame.
  3971. *
  3972. * For example, this corresponds to H.264 dpb_output_delay.
  3973. */
  3974. int pts_dts_delta;
  3975. /**
  3976. * Position of the packet in file.
  3977. *
  3978. * Analogous to cur_frame_pts/dts
  3979. */
  3980. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
  3981. /**
  3982. * Byte position of currently parsed frame in stream.
  3983. */
  3984. int64_t pos;
  3985. /**
  3986. * Previous frame byte position.
  3987. */
  3988. int64_t last_pos;
  3989. /**
  3990. * Duration of the current frame.
  3991. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
  3992. * For all other types, this is in units of AVCodecContext.time_base.
  3993. */
  3994. int duration;
  3995. enum AVFieldOrder field_order;
  3996. /**
  3997. * Indicate whether a picture is coded as a frame, top field or bottom field.
  3998. *
  3999. * For example, H.264 field_pic_flag equal to 0 corresponds to
  4000. * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
  4001. * equal to 1 and bottom_field_flag equal to 0 corresponds to
  4002. * AV_PICTURE_STRUCTURE_TOP_FIELD.
  4003. */
  4004. enum AVPictureStructure picture_structure;
  4005. /**
  4006. * Picture number incremented in presentation or output order.
  4007. * This field may be reinitialized at the first picture of a new sequence.
  4008. *
  4009. * For example, this corresponds to H.264 PicOrderCnt.
  4010. */
  4011. int output_picture_number;
  4012. /**
  4013. * Dimensions of the decoded video intended for presentation.
  4014. */
  4015. int width;
  4016. int height;
  4017. /**
  4018. * Dimensions of the coded video.
  4019. */
  4020. int coded_width;
  4021. int coded_height;
  4022. /**
  4023. * The format of the coded data, corresponds to enum AVPixelFormat for video
  4024. * and for enum AVSampleFormat for audio.
  4025. *
  4026. * Note that a decoder can have considerable freedom in how exactly it
  4027. * decodes the data, so the format reported here might be different from the
  4028. * one returned by a decoder.
  4029. */
  4030. int format;
  4031. } AVCodecParserContext;
  4032. typedef struct AVCodecParser {
  4033. int codec_ids[5]; /* several codec IDs are permitted */
  4034. int priv_data_size;
  4035. int (*parser_init)(AVCodecParserContext *s);
  4036. /* This callback never returns an error, a negative value means that
  4037. * the frame start was in a previous packet. */
  4038. int (*parser_parse)(AVCodecParserContext *s,
  4039. AVCodecContext *avctx,
  4040. const uint8_t **poutbuf, int *poutbuf_size,
  4041. const uint8_t *buf, int buf_size);
  4042. void (*parser_close)(AVCodecParserContext *s);
  4043. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  4044. struct AVCodecParser *next;
  4045. } AVCodecParser;
  4046. AVCodecParser *av_parser_next(const AVCodecParser *c);
  4047. void av_register_codec_parser(AVCodecParser *parser);
  4048. AVCodecParserContext *av_parser_init(int codec_id);
  4049. /**
  4050. * Parse a packet.
  4051. *
  4052. * @param s parser context.
  4053. * @param avctx codec context.
  4054. * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
  4055. * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
  4056. * @param buf input buffer.
  4057. * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
  4058. * @param pts input presentation timestamp.
  4059. * @param dts input decoding timestamp.
  4060. * @param pos input byte position in stream.
  4061. * @return the number of bytes of the input bitstream used.
  4062. *
  4063. * Example:
  4064. * @code
  4065. * while(in_len){
  4066. * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  4067. * in_data, in_len,
  4068. * pts, dts, pos);
  4069. * in_data += len;
  4070. * in_len -= len;
  4071. *
  4072. * if(size)
  4073. * decode_frame(data, size);
  4074. * }
  4075. * @endcode
  4076. */
  4077. int av_parser_parse2(AVCodecParserContext *s,
  4078. AVCodecContext *avctx,
  4079. uint8_t **poutbuf, int *poutbuf_size,
  4080. const uint8_t *buf, int buf_size,
  4081. int64_t pts, int64_t dts,
  4082. int64_t pos);
  4083. /**
  4084. * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
  4085. * @deprecated use AVBitstreamFilter
  4086. */
  4087. int av_parser_change(AVCodecParserContext *s,
  4088. AVCodecContext *avctx,
  4089. uint8_t **poutbuf, int *poutbuf_size,
  4090. const uint8_t *buf, int buf_size, int keyframe);
  4091. void av_parser_close(AVCodecParserContext *s);
  4092. /**
  4093. * @}
  4094. * @}
  4095. */
  4096. /**
  4097. * @addtogroup lavc_encoding
  4098. * @{
  4099. */
  4100. /**
  4101. * Find a registered encoder with a matching codec ID.
  4102. *
  4103. * @param id AVCodecID of the requested encoder
  4104. * @return An encoder if one was found, NULL otherwise.
  4105. */
  4106. AVCodec *avcodec_find_encoder(enum AVCodecID id);
  4107. /**
  4108. * Find a registered encoder with the specified name.
  4109. *
  4110. * @param name name of the requested encoder
  4111. * @return An encoder if one was found, NULL otherwise.
  4112. */
  4113. AVCodec *avcodec_find_encoder_by_name(const char *name);
  4114. /**
  4115. * Encode a frame of audio.
  4116. *
  4117. * Takes input samples from frame and writes the next output packet, if
  4118. * available, to avpkt. The output packet does not necessarily contain data for
  4119. * the most recent frame, as encoders can delay, split, and combine input frames
  4120. * internally as needed.
  4121. *
  4122. * @param avctx codec context
  4123. * @param avpkt output AVPacket.
  4124. * The user can supply an output buffer by setting
  4125. * avpkt->data and avpkt->size prior to calling the
  4126. * function, but if the size of the user-provided data is not
  4127. * large enough, encoding will fail. All other AVPacket fields
  4128. * will be reset by the encoder using av_init_packet(). If
  4129. * avpkt->data is NULL, the encoder will allocate it.
  4130. * The encoder will set avpkt->size to the size of the
  4131. * output packet.
  4132. *
  4133. * If this function fails or produces no output, avpkt will be
  4134. * freed using av_packet_unref().
  4135. * @param[in] frame AVFrame containing the raw audio data to be encoded.
  4136. * May be NULL when flushing an encoder that has the
  4137. * AV_CODEC_CAP_DELAY capability set.
  4138. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  4139. * can have any number of samples.
  4140. * If it is not set, frame->nb_samples must be equal to
  4141. * avctx->frame_size for all frames except the last.
  4142. * The final frame may be smaller than avctx->frame_size.
  4143. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  4144. * output packet is non-empty, and to 0 if it is
  4145. * empty. If the function returns an error, the
  4146. * packet can be assumed to be invalid, and the
  4147. * value of got_packet_ptr is undefined and should
  4148. * not be used.
  4149. * @return 0 on success, negative error code on failure
  4150. *
  4151. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  4152. */
  4153. attribute_deprecated
  4154. int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
  4155. const AVFrame *frame, int *got_packet_ptr);
  4156. /**
  4157. * Encode a frame of video.
  4158. *
  4159. * Takes input raw video data from frame and writes the next output packet, if
  4160. * available, to avpkt. The output packet does not necessarily contain data for
  4161. * the most recent frame, as encoders can delay and reorder input frames
  4162. * internally as needed.
  4163. *
  4164. * @param avctx codec context
  4165. * @param avpkt output AVPacket.
  4166. * The user can supply an output buffer by setting
  4167. * avpkt->data and avpkt->size prior to calling the
  4168. * function, but if the size of the user-provided data is not
  4169. * large enough, encoding will fail. All other AVPacket fields
  4170. * will be reset by the encoder using av_init_packet(). If
  4171. * avpkt->data is NULL, the encoder will allocate it.
  4172. * The encoder will set avpkt->size to the size of the
  4173. * output packet. The returned data (if any) belongs to the
  4174. * caller, he is responsible for freeing it.
  4175. *
  4176. * If this function fails or produces no output, avpkt will be
  4177. * freed using av_packet_unref().
  4178. * @param[in] frame AVFrame containing the raw video data to be encoded.
  4179. * May be NULL when flushing an encoder that has the
  4180. * AV_CODEC_CAP_DELAY capability set.
  4181. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  4182. * output packet is non-empty, and to 0 if it is
  4183. * empty. If the function returns an error, the
  4184. * packet can be assumed to be invalid, and the
  4185. * value of got_packet_ptr is undefined and should
  4186. * not be used.
  4187. * @return 0 on success, negative error code on failure
  4188. *
  4189. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  4190. */
  4191. attribute_deprecated
  4192. int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
  4193. const AVFrame *frame, int *got_packet_ptr);
  4194. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  4195. const AVSubtitle *sub);
  4196. /**
  4197. * @}
  4198. */
  4199. #if FF_API_AVPICTURE
  4200. /**
  4201. * @addtogroup lavc_picture
  4202. * @{
  4203. */
  4204. /**
  4205. * @deprecated unused
  4206. */
  4207. attribute_deprecated
  4208. int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
  4209. /**
  4210. * @deprecated unused
  4211. */
  4212. attribute_deprecated
  4213. void avpicture_free(AVPicture *picture);
  4214. /**
  4215. * @deprecated use av_image_fill_arrays() instead.
  4216. */
  4217. attribute_deprecated
  4218. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  4219. enum AVPixelFormat pix_fmt, int width, int height);
  4220. /**
  4221. * @deprecated use av_image_copy_to_buffer() instead.
  4222. */
  4223. attribute_deprecated
  4224. int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,
  4225. int width, int height,
  4226. unsigned char *dest, int dest_size);
  4227. /**
  4228. * @deprecated use av_image_get_buffer_size() instead.
  4229. */
  4230. attribute_deprecated
  4231. int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
  4232. /**
  4233. * @deprecated av_image_copy() instead.
  4234. */
  4235. attribute_deprecated
  4236. void av_picture_copy(AVPicture *dst, const AVPicture *src,
  4237. enum AVPixelFormat pix_fmt, int width, int height);
  4238. /**
  4239. * @deprecated unused
  4240. */
  4241. attribute_deprecated
  4242. int av_picture_crop(AVPicture *dst, const AVPicture *src,
  4243. enum AVPixelFormat pix_fmt, int top_band, int left_band);
  4244. /**
  4245. * @deprecated unused
  4246. */
  4247. attribute_deprecated
  4248. int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
  4249. int padtop, int padbottom, int padleft, int padright, int *color);
  4250. /**
  4251. * @}
  4252. */
  4253. #endif
  4254. /**
  4255. * @defgroup lavc_misc Utility functions
  4256. * @ingroup libavc
  4257. *
  4258. * Miscellaneous utility functions related to both encoding and decoding
  4259. * (or neither).
  4260. * @{
  4261. */
  4262. /**
  4263. * @defgroup lavc_misc_pixfmt Pixel formats
  4264. *
  4265. * Functions for working with pixel formats.
  4266. * @{
  4267. */
  4268. /**
  4269. * Return a value representing the fourCC code associated to the
  4270. * pixel format pix_fmt, or 0 if no associated fourCC code can be
  4271. * found.
  4272. */
  4273. unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
  4274. #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
  4275. #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
  4276. #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
  4277. #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
  4278. #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
  4279. #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
  4280. /**
  4281. * Compute what kind of losses will occur when converting from one specific
  4282. * pixel format to another.
  4283. * When converting from one pixel format to another, information loss may occur.
  4284. * For example, when converting from RGB24 to GRAY, the color information will
  4285. * be lost. Similarly, other losses occur when converting from some formats to
  4286. * other formats. These losses can involve loss of chroma, but also loss of
  4287. * resolution, loss of color depth, loss due to the color space conversion, loss
  4288. * of the alpha bits or loss due to color quantization.
  4289. * avcodec_get_fix_fmt_loss() informs you about the various types of losses
  4290. * which will occur when converting from one pixel format to another.
  4291. *
  4292. * @param[in] dst_pix_fmt destination pixel format
  4293. * @param[in] src_pix_fmt source pixel format
  4294. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  4295. * @return Combination of flags informing you what kind of losses will occur.
  4296. */
  4297. int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
  4298. int has_alpha);
  4299. /**
  4300. * Find the best pixel format to convert to given a certain source pixel
  4301. * format. When converting from one pixel format to another, information loss
  4302. * may occur. For example, when converting from RGB24 to GRAY, the color
  4303. * information will be lost. Similarly, other losses occur when converting from
  4304. * some formats to other formats. avcodec_find_best_pix_fmt2() searches which of
  4305. * the given pixel formats should be used to suffer the least amount of loss.
  4306. * The pixel formats from which it chooses one, are determined by the
  4307. * pix_fmt_list parameter.
  4308. *
  4309. *
  4310. * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
  4311. * @param[in] src_pix_fmt source pixel format
  4312. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  4313. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  4314. * @return The best pixel format to convert to or -1 if none was found.
  4315. */
  4316. enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat *pix_fmt_list,
  4317. enum AVPixelFormat src_pix_fmt,
  4318. int has_alpha, int *loss_ptr);
  4319. enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  4320. /**
  4321. * @}
  4322. */
  4323. /**
  4324. * Put a string representing the codec tag codec_tag in buf.
  4325. *
  4326. * @param buf buffer to place codec tag in
  4327. * @param buf_size size in bytes of buf
  4328. * @param codec_tag codec tag to assign
  4329. * @return the length of the string that would have been generated if
  4330. * enough space had been available, excluding the trailing null
  4331. */
  4332. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
  4333. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  4334. /**
  4335. * Return a name for the specified profile, if available.
  4336. *
  4337. * @param codec the codec that is searched for the given profile
  4338. * @param profile the profile value for which a name is requested
  4339. * @return A name for the profile if found, NULL otherwise.
  4340. */
  4341. const char *av_get_profile_name(const AVCodec *codec, int profile);
  4342. /**
  4343. * Return a name for the specified profile, if available.
  4344. *
  4345. * @param codec_id the ID of the codec to which the requested profile belongs
  4346. * @param profile the profile value for which a name is requested
  4347. * @return A name for the profile if found, NULL otherwise.
  4348. *
  4349. * @note unlike av_get_profile_name(), which searches a list of profiles
  4350. * supported by a specific decoder or encoder implementation, this
  4351. * function searches the list of profiles from the AVCodecDescriptor
  4352. */
  4353. const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
  4354. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
  4355. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
  4356. //FIXME func typedef
  4357. /**
  4358. * Fill audio frame data and linesize.
  4359. * AVFrame extended_data channel pointers are allocated if necessary for
  4360. * planar audio.
  4361. *
  4362. * @param frame the AVFrame
  4363. * frame->nb_samples must be set prior to calling the
  4364. * function. This function fills in frame->data,
  4365. * frame->extended_data, frame->linesize[0].
  4366. * @param nb_channels channel count
  4367. * @param sample_fmt sample format
  4368. * @param buf buffer to use for frame data
  4369. * @param buf_size size of buffer
  4370. * @param align plane size sample alignment (0 = default)
  4371. * @return 0 on success, negative error code on failure
  4372. */
  4373. int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
  4374. enum AVSampleFormat sample_fmt, const uint8_t *buf,
  4375. int buf_size, int align);
  4376. /**
  4377. * Reset the internal decoder state / flush internal buffers. Should be called
  4378. * e.g. when seeking or when switching to a different stream.
  4379. *
  4380. * @note when refcounted frames are not used (i.e. avctx->refcounted_frames is 0),
  4381. * this invalidates the frames previously returned from the decoder. When
  4382. * refcounted frames are used, the decoder just releases any references it might
  4383. * keep internally, but the caller's reference remains valid.
  4384. */
  4385. void avcodec_flush_buffers(AVCodecContext *avctx);
  4386. /**
  4387. * Return codec bits per sample.
  4388. *
  4389. * @param[in] codec_id the codec
  4390. * @return Number of bits per sample or zero if unknown for the given codec.
  4391. */
  4392. int av_get_bits_per_sample(enum AVCodecID codec_id);
  4393. /**
  4394. * Return codec bits per sample.
  4395. * Only return non-zero if the bits per sample is exactly correct, not an
  4396. * approximation.
  4397. *
  4398. * @param[in] codec_id the codec
  4399. * @return Number of bits per sample or zero if unknown for the given codec.
  4400. */
  4401. int av_get_exact_bits_per_sample(enum AVCodecID codec_id);
  4402. /**
  4403. * Return audio frame duration.
  4404. *
  4405. * @param avctx codec context
  4406. * @param frame_bytes size of the frame, or 0 if unknown
  4407. * @return frame duration, in samples, if known. 0 if not able to
  4408. * determine.
  4409. */
  4410. int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
  4411. /**
  4412. * This function is the same as av_get_audio_frame_duration(), except it works
  4413. * with AVCodecParameters instead of an AVCodecContext.
  4414. */
  4415. int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
  4416. #if FF_API_OLD_BSF
  4417. typedef struct AVBitStreamFilterContext {
  4418. void *priv_data;
  4419. struct AVBitStreamFilter *filter;
  4420. AVCodecParserContext *parser;
  4421. struct AVBitStreamFilterContext *next;
  4422. } AVBitStreamFilterContext;
  4423. #endif
  4424. typedef struct AVBSFInternal AVBSFInternal;
  4425. /**
  4426. * The bitstream filter state.
  4427. *
  4428. * This struct must be allocated with av_bsf_alloc() and freed with
  4429. * av_bsf_free().
  4430. *
  4431. * The fields in the struct will only be changed (by the caller or by the
  4432. * filter) as described in their documentation, and are to be considered
  4433. * immutable otherwise.
  4434. */
  4435. typedef struct AVBSFContext {
  4436. /**
  4437. * A class for logging and AVOptions
  4438. */
  4439. const AVClass *av_class;
  4440. /**
  4441. * The bitstream filter this context is an instance of.
  4442. */
  4443. const struct AVBitStreamFilter *filter;
  4444. /**
  4445. * Opaque libavcodec internal data. Must not be touched by the caller in any
  4446. * way.
  4447. */
  4448. AVBSFInternal *internal;
  4449. /**
  4450. * Opaque filter-specific private data. If filter->priv_class is non-NULL,
  4451. * this is an AVOptions-enabled struct.
  4452. */
  4453. void *priv_data;
  4454. /**
  4455. * Parameters of the input stream. This field is allocated in
  4456. * av_bsf_alloc(), it needs to be filled by the caller before
  4457. * av_bsf_init().
  4458. */
  4459. AVCodecParameters *par_in;
  4460. /**
  4461. * Parameters of the output stream. This field is allocated in
  4462. * av_bsf_alloc(), it is set by the filter in av_bsf_init().
  4463. */
  4464. AVCodecParameters *par_out;
  4465. /**
  4466. * The timebase used for the timestamps of the input packets. Set by the
  4467. * caller before av_bsf_init().
  4468. */
  4469. AVRational time_base_in;
  4470. /**
  4471. * The timebase used for the timestamps of the output packets. Set by the
  4472. * filter in av_bsf_init().
  4473. */
  4474. AVRational time_base_out;
  4475. } AVBSFContext;
  4476. typedef struct AVBitStreamFilter {
  4477. const char *name;
  4478. /**
  4479. * A list of codec ids supported by the filter, terminated by
  4480. * AV_CODEC_ID_NONE.
  4481. * May be NULL, in that case the bitstream filter works with any codec id.
  4482. */
  4483. const enum AVCodecID *codec_ids;
  4484. /**
  4485. * A class for the private data, used to declare bitstream filter private
  4486. * AVOptions. This field is NULL for bitstream filters that do not declare
  4487. * any options.
  4488. *
  4489. * If this field is non-NULL, the first member of the filter private data
  4490. * must be a pointer to AVClass, which will be set by libavcodec generic
  4491. * code to this class.
  4492. */
  4493. const AVClass *priv_class;
  4494. /*****************************************************************
  4495. * No fields below this line are part of the public API. They
  4496. * may not be used outside of libavcodec and can be changed and
  4497. * removed at will.
  4498. * New public fields should be added right above.
  4499. *****************************************************************
  4500. */
  4501. int priv_data_size;
  4502. int (*init)(AVBSFContext *ctx);
  4503. int (*filter)(AVBSFContext *ctx, AVPacket *pkt);
  4504. void (*close)(AVBSFContext *ctx);
  4505. } AVBitStreamFilter;
  4506. #if FF_API_OLD_BSF
  4507. /**
  4508. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  4509. * is deprecated. Use the new bitstream filtering API (using AVBSFContext).
  4510. */
  4511. attribute_deprecated
  4512. void av_register_bitstream_filter(AVBitStreamFilter *bsf);
  4513. attribute_deprecated
  4514. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
  4515. attribute_deprecated
  4516. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  4517. AVCodecContext *avctx, const char *args,
  4518. uint8_t **poutbuf, int *poutbuf_size,
  4519. const uint8_t *buf, int buf_size, int keyframe);
  4520. attribute_deprecated
  4521. void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
  4522. attribute_deprecated
  4523. AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);
  4524. #endif
  4525. /**
  4526. * @return a bitstream filter with the specified name or NULL if no such
  4527. * bitstream filter exists.
  4528. */
  4529. const AVBitStreamFilter *av_bsf_get_by_name(const char *name);
  4530. /**
  4531. * Iterate over all registered bitstream filters.
  4532. *
  4533. * @param opaque a pointer where libavcodec will store the iteration state. Must
  4534. * point to NULL to start the iteration.
  4535. *
  4536. * @return the next registered bitstream filter or NULL when the iteration is
  4537. * finished
  4538. */
  4539. const AVBitStreamFilter *av_bsf_next(void **opaque);
  4540. /**
  4541. * Allocate a context for a given bitstream filter. The caller must fill in the
  4542. * context parameters as described in the documentation and then call
  4543. * av_bsf_init() before sending any data to the filter.
  4544. *
  4545. * @param filter the filter for which to allocate an instance.
  4546. * @param ctx a pointer into which the pointer to the newly-allocated context
  4547. * will be written. It must be freed with av_bsf_free() after the
  4548. * filtering is done.
  4549. *
  4550. * @return 0 on success, a negative AVERROR code on failure
  4551. */
  4552. int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx);
  4553. /**
  4554. * Prepare the filter for use, after all the parameters and options have been
  4555. * set.
  4556. */
  4557. int av_bsf_init(AVBSFContext *ctx);
  4558. /**
  4559. * Submit a packet for filtering.
  4560. *
  4561. * After sending each packet, the filter must be completely drained by calling
  4562. * av_bsf_receive_packet() repeatedly until it returns AVERROR(EAGAIN) or
  4563. * AVERROR_EOF.
  4564. *
  4565. * @param pkt the packet to filter. The bitstream filter will take ownership of
  4566. * the packet and reset the contents of pkt. pkt is not touched if an error occurs.
  4567. * This parameter may be NULL, which signals the end of the stream (i.e. no more
  4568. * packets will be sent). That will cause the filter to output any packets it
  4569. * may have buffered internally.
  4570. *
  4571. * @return 0 on success, a negative AVERROR on error.
  4572. */
  4573. int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);
  4574. /**
  4575. * Retrieve a filtered packet.
  4576. *
  4577. * @param[out] pkt this struct will be filled with the contents of the filtered
  4578. * packet. It is owned by the caller and must be freed using
  4579. * av_packet_unref() when it is no longer needed.
  4580. * This parameter should be "clean" (i.e. freshly allocated
  4581. * with av_packet_alloc() or unreffed with av_packet_unref())
  4582. * when this function is called. If this function returns
  4583. * successfully, the contents of pkt will be completely
  4584. * overwritten by the returned data. On failure, pkt is not
  4585. * touched.
  4586. *
  4587. * @return 0 on success. AVERROR(EAGAIN) if more packets need to be sent to the
  4588. * filter (using av_bsf_send_packet()) to get more output. AVERROR_EOF if there
  4589. * will be no further output from the filter. Another negative AVERROR value if
  4590. * an error occurs.
  4591. *
  4592. * @note one input packet may result in several output packets, so after sending
  4593. * a packet with av_bsf_send_packet(), this function needs to be called
  4594. * repeatedly until it stops returning 0. It is also possible for a filter to
  4595. * output fewer packets than were sent to it, so this function may return
  4596. * AVERROR(EAGAIN) immediately after a successful av_bsf_send_packet() call.
  4597. */
  4598. int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);
  4599. /**
  4600. * Free a bitstream filter context and everything associated with it; write NULL
  4601. * into the supplied pointer.
  4602. */
  4603. void av_bsf_free(AVBSFContext **ctx);
  4604. /**
  4605. * Get the AVClass for AVBSFContext. It can be used in combination with
  4606. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  4607. *
  4608. * @see av_opt_find().
  4609. */
  4610. const AVClass *av_bsf_get_class(void);
  4611. /* memory */
  4612. /**
  4613. * Allocate a buffer with padding, reusing the given one if large enough.
  4614. *
  4615. * Same behaviour av_fast_malloc but the buffer has additional
  4616. * AV_INPUT_PADDING_SIZE at the end which will always memset to 0.
  4617. */
  4618. void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  4619. /**
  4620. * Encode extradata length to a buffer. Used by xiph codecs.
  4621. *
  4622. * @param s buffer to write to; must be at least (v/255+1) bytes long
  4623. * @param v size of extradata in bytes
  4624. * @return number of bytes written to the buffer.
  4625. */
  4626. unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
  4627. #if FF_API_USER_VISIBLE_AVHWACCEL
  4628. /**
  4629. * Register the hardware accelerator hwaccel.
  4630. *
  4631. * @deprecated This function doesn't do anything.
  4632. */
  4633. attribute_deprecated
  4634. void av_register_hwaccel(AVHWAccel *hwaccel);
  4635. /**
  4636. * If hwaccel is NULL, returns the first registered hardware accelerator,
  4637. * if hwaccel is non-NULL, returns the next registered hardware accelerator
  4638. * after hwaccel, or NULL if hwaccel is the last one.
  4639. *
  4640. * @deprecated AVHWaccel structures contain no user-serviceable parts, so
  4641. * this function should not be used.
  4642. */
  4643. attribute_deprecated
  4644. AVHWAccel *av_hwaccel_next(const AVHWAccel *hwaccel);
  4645. #endif
  4646. /**
  4647. * Lock operation used by lockmgr
  4648. */
  4649. enum AVLockOp {
  4650. AV_LOCK_CREATE, ///< Create a mutex
  4651. AV_LOCK_OBTAIN, ///< Lock the mutex
  4652. AV_LOCK_RELEASE, ///< Unlock the mutex
  4653. AV_LOCK_DESTROY, ///< Free mutex resources
  4654. };
  4655. /**
  4656. * Register a user provided lock manager supporting the operations
  4657. * specified by AVLockOp. The "mutex" argument to the function points
  4658. * to a (void *) where the lockmgr should store/get a pointer to a user
  4659. * allocated mutex. It is NULL upon AV_LOCK_CREATE and equal to the
  4660. * value left by the last call for all other ops. If the lock manager is
  4661. * unable to perform the op then it should leave the mutex in the same
  4662. * state as when it was called and return a non-zero value. However,
  4663. * when called with AV_LOCK_DESTROY the mutex will always be assumed to
  4664. * have been successfully destroyed. If av_lockmgr_register succeeds
  4665. * it will return a non-negative value, if it fails it will return a
  4666. * negative value and destroy all mutex and unregister all callbacks.
  4667. * av_lockmgr_register is not thread-safe, it must be called from a
  4668. * single thread before any calls which make use of locking are used.
  4669. *
  4670. * @param cb User defined callback. av_lockmgr_register invokes calls
  4671. * to this callback and the previously registered callback.
  4672. * The callback will be used to create more than one mutex
  4673. * each of which must be backed by its own underlying locking
  4674. * mechanism (i.e. do not use a single static object to
  4675. * implement your lock manager). If cb is set to NULL the
  4676. * lockmgr will be unregistered.
  4677. */
  4678. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
  4679. /**
  4680. * Get the type of the given codec.
  4681. */
  4682. enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
  4683. /**
  4684. * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  4685. * with no corresponding avcodec_close()), 0 otherwise.
  4686. */
  4687. int avcodec_is_open(AVCodecContext *s);
  4688. /**
  4689. * @return a non-zero number if codec is an encoder, zero otherwise
  4690. */
  4691. int av_codec_is_encoder(const AVCodec *codec);
  4692. /**
  4693. * @return a non-zero number if codec is a decoder, zero otherwise
  4694. */
  4695. int av_codec_is_decoder(const AVCodec *codec);
  4696. /**
  4697. * @return descriptor for given codec ID or NULL if no descriptor exists.
  4698. */
  4699. const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id);
  4700. /**
  4701. * Iterate over all codec descriptors known to libavcodec.
  4702. *
  4703. * @param prev previous descriptor. NULL to get the first descriptor.
  4704. *
  4705. * @return next descriptor or NULL after the last descriptor
  4706. */
  4707. const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev);
  4708. /**
  4709. * @return codec descriptor with the given name or NULL if no such descriptor
  4710. * exists.
  4711. */
  4712. const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
  4713. /**
  4714. * Allocate a CPB properties structure and initialize its fields to default
  4715. * values.
  4716. *
  4717. * @param size if non-NULL, the size of the allocated struct will be written
  4718. * here. This is useful for embedding it in side data.
  4719. *
  4720. * @return the newly allocated struct or NULL on failure
  4721. */
  4722. AVCPBProperties *av_cpb_properties_alloc(size_t *size);
  4723. /**
  4724. * @}
  4725. */
  4726. #endif /* AVCODEC_AVCODEC_H */