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.

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