packet.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * AVPacket public API
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_PACKET_H
  21. #define AVCODEC_PACKET_H
  22. #include <stddef.h>
  23. #include <stdint.h>
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/buffer.h"
  26. #include "libavutil/dict.h"
  27. #include "libavutil/rational.h"
  28. #include "libavcodec/version.h"
  29. /**
  30. * @defgroup lavc_packet AVPacket
  31. *
  32. * Types and functions for working with AVPacket.
  33. * @{
  34. */
  35. enum AVPacketSideDataType {
  36. /**
  37. * An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE
  38. * bytes worth of palette. This side data signals that a new palette is
  39. * present.
  40. */
  41. AV_PKT_DATA_PALETTE,
  42. /**
  43. * The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format
  44. * that the extradata buffer was changed and the receiving side should
  45. * act upon it appropriately. The new extradata is embedded in the side
  46. * data buffer and should be immediately used for processing the current
  47. * frame or packet.
  48. */
  49. AV_PKT_DATA_NEW_EXTRADATA,
  50. /**
  51. * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
  52. * @code
  53. * u32le param_flags
  54. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
  55. * s32le channel_count
  56. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
  57. * u64le channel_layout
  58. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
  59. * s32le sample_rate
  60. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
  61. * s32le width
  62. * s32le height
  63. * @endcode
  64. */
  65. AV_PKT_DATA_PARAM_CHANGE,
  66. /**
  67. * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
  68. * structures with info about macroblocks relevant to splitting the
  69. * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
  70. * That is, it does not necessarily contain info about all macroblocks,
  71. * as long as the distance between macroblocks in the info is smaller
  72. * than the target payload size.
  73. * Each MB info structure is 12 bytes, and is laid out as follows:
  74. * @code
  75. * u32le bit offset from the start of the packet
  76. * u8 current quantizer at the start of the macroblock
  77. * u8 GOB number
  78. * u16le macroblock address within the GOB
  79. * u8 horizontal MV predictor
  80. * u8 vertical MV predictor
  81. * u8 horizontal MV predictor for block number 3
  82. * u8 vertical MV predictor for block number 3
  83. * @endcode
  84. */
  85. AV_PKT_DATA_H263_MB_INFO,
  86. /**
  87. * This side data should be associated with an audio stream and contains
  88. * ReplayGain information in form of the AVReplayGain struct.
  89. */
  90. AV_PKT_DATA_REPLAYGAIN,
  91. /**
  92. * This side data contains a 3x3 transformation matrix describing an affine
  93. * transformation that needs to be applied to the decoded video frames for
  94. * correct presentation.
  95. *
  96. * See libavutil/display.h for a detailed description of the data.
  97. */
  98. AV_PKT_DATA_DISPLAYMATRIX,
  99. /**
  100. * This side data should be associated with a video stream and contains
  101. * Stereoscopic 3D information in form of the AVStereo3D struct.
  102. */
  103. AV_PKT_DATA_STEREO3D,
  104. /**
  105. * This side data should be associated with an audio stream and corresponds
  106. * to enum AVAudioServiceType.
  107. */
  108. AV_PKT_DATA_AUDIO_SERVICE_TYPE,
  109. /**
  110. * This side data contains quality related information from the encoder.
  111. * @code
  112. * u32le quality factor of the compressed frame. Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad).
  113. * u8 picture type
  114. * u8 error count
  115. * u16 reserved
  116. * u64le[error count] sum of squared differences between encoder in and output
  117. * @endcode
  118. */
  119. AV_PKT_DATA_QUALITY_STATS,
  120. /**
  121. * This side data contains an integer value representing the stream index
  122. * of a "fallback" track. A fallback track indicates an alternate
  123. * track to use when the current track can not be decoded for some reason.
  124. * e.g. no decoder available for codec.
  125. */
  126. AV_PKT_DATA_FALLBACK_TRACK,
  127. /**
  128. * This side data corresponds to the AVCPBProperties struct.
  129. */
  130. AV_PKT_DATA_CPB_PROPERTIES,
  131. /**
  132. * Recommmends skipping the specified number of samples
  133. * @code
  134. * u32le number of samples to skip from start of this packet
  135. * u32le number of samples to skip from end of this packet
  136. * u8 reason for start skip
  137. * u8 reason for end skip (0=padding silence, 1=convergence)
  138. * @endcode
  139. */
  140. AV_PKT_DATA_SKIP_SAMPLES,
  141. /**
  142. * An AV_PKT_DATA_JP_DUALMONO side data packet indicates that
  143. * the packet may contain "dual mono" audio specific to Japanese DTV
  144. * and if it is true, recommends only the selected channel to be used.
  145. * @code
  146. * u8 selected channels (0=mail/left, 1=sub/right, 2=both)
  147. * @endcode
  148. */
  149. AV_PKT_DATA_JP_DUALMONO,
  150. /**
  151. * A list of zero terminated key/value strings. There is no end marker for
  152. * the list, so it is required to rely on the side data size to stop.
  153. */
  154. AV_PKT_DATA_STRINGS_METADATA,
  155. /**
  156. * Subtitle event position
  157. * @code
  158. * u32le x1
  159. * u32le y1
  160. * u32le x2
  161. * u32le y2
  162. * @endcode
  163. */
  164. AV_PKT_DATA_SUBTITLE_POSITION,
  165. /**
  166. * Data found in BlockAdditional element of matroska container. There is
  167. * no end marker for the data, so it is required to rely on the side data
  168. * size to recognize the end. 8 byte id (as found in BlockAddId) followed
  169. * by data.
  170. */
  171. AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
  172. /**
  173. * The optional first identifier line of a WebVTT cue.
  174. */
  175. AV_PKT_DATA_WEBVTT_IDENTIFIER,
  176. /**
  177. * The optional settings (rendering instructions) that immediately
  178. * follow the timestamp specifier of a WebVTT cue.
  179. */
  180. AV_PKT_DATA_WEBVTT_SETTINGS,
  181. /**
  182. * A list of zero terminated key/value strings. There is no end marker for
  183. * the list, so it is required to rely on the side data size to stop. This
  184. * side data includes updated metadata which appeared in the stream.
  185. */
  186. AV_PKT_DATA_METADATA_UPDATE,
  187. /**
  188. * MPEGTS stream ID as uint8_t, this is required to pass the stream ID
  189. * information from the demuxer to the corresponding muxer.
  190. */
  191. AV_PKT_DATA_MPEGTS_STREAM_ID,
  192. /**
  193. * Mastering display metadata (based on SMPTE-2086:2014). This metadata
  194. * should be associated with a video stream and contains data in the form
  195. * of the AVMasteringDisplayMetadata struct.
  196. */
  197. AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
  198. /**
  199. * This side data should be associated with a video stream and corresponds
  200. * to the AVSphericalMapping structure.
  201. */
  202. AV_PKT_DATA_SPHERICAL,
  203. /**
  204. * Content light level (based on CTA-861.3). This metadata should be
  205. * associated with a video stream and contains data in the form of the
  206. * AVContentLightMetadata struct.
  207. */
  208. AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
  209. /**
  210. * ATSC A53 Part 4 Closed Captions. This metadata should be associated with
  211. * a video stream. A53 CC bitstream is stored as uint8_t in AVPacketSideData.data.
  212. * The number of bytes of CC data is AVPacketSideData.size.
  213. */
  214. AV_PKT_DATA_A53_CC,
  215. /**
  216. * This side data is encryption initialization data.
  217. * The format is not part of ABI, use av_encryption_init_info_* methods to
  218. * access.
  219. */
  220. AV_PKT_DATA_ENCRYPTION_INIT_INFO,
  221. /**
  222. * This side data contains encryption info for how to decrypt the packet.
  223. * The format is not part of ABI, use av_encryption_info_* methods to access.
  224. */
  225. AV_PKT_DATA_ENCRYPTION_INFO,
  226. /**
  227. * Active Format Description data consisting of a single byte as specified
  228. * in ETSI TS 101 154 using AVActiveFormatDescription enum.
  229. */
  230. AV_PKT_DATA_AFD,
  231. /**
  232. * Producer Reference Time data corresponding to the AVProducerReferenceTime struct,
  233. * usually exported by some encoders (on demand through the prft flag set in the
  234. * AVCodecContext export_side_data field).
  235. */
  236. AV_PKT_DATA_PRFT,
  237. /**
  238. * ICC profile data consisting of an opaque octet buffer following the
  239. * format described by ISO 15076-1.
  240. */
  241. AV_PKT_DATA_ICC_PROFILE,
  242. /**
  243. * DOVI configuration
  244. * ref:
  245. * dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2, section 2.2
  246. * dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2, section 3.3
  247. * Tags are stored in struct AVDOVIDecoderConfigurationRecord.
  248. */
  249. AV_PKT_DATA_DOVI_CONF,
  250. /**
  251. * Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t
  252. * where the first uint32_t describes how many (1-3) of the other timecodes are used.
  253. * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
  254. * function in libavutil/timecode.h.
  255. */
  256. AV_PKT_DATA_S12M_TIMECODE,
  257. /**
  258. * The number of side data types.
  259. * This is not part of the public API/ABI in the sense that it may
  260. * change when new side data types are added.
  261. * This must stay the last enum value.
  262. * If its value becomes huge, some code using it
  263. * needs to be updated as it assumes it to be smaller than other limits.
  264. */
  265. AV_PKT_DATA_NB
  266. };
  267. #define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
  268. typedef struct AVPacketSideData {
  269. uint8_t *data;
  270. #if FF_API_BUFFER_SIZE_T
  271. int size;
  272. #else
  273. size_t size;
  274. #endif
  275. enum AVPacketSideDataType type;
  276. } AVPacketSideData;
  277. /**
  278. * This structure stores compressed data. It is typically exported by demuxers
  279. * and then passed as input to decoders, or received as output from encoders and
  280. * then passed to muxers.
  281. *
  282. * For video, it should typically contain one compressed frame. For audio it may
  283. * contain several compressed frames. Encoders are allowed to output empty
  284. * packets, with no compressed data, containing only side data
  285. * (e.g. to update some stream parameters at the end of encoding).
  286. *
  287. * The semantics of data ownership depends on the buf field.
  288. * If it is set, the packet data is dynamically allocated and is
  289. * valid indefinitely until a call to av_packet_unref() reduces the
  290. * reference count to 0.
  291. *
  292. * If the buf field is not set av_packet_ref() would make a copy instead
  293. * of increasing the reference count.
  294. *
  295. * The side data is always allocated with av_malloc(), copied by
  296. * av_packet_ref() and freed by av_packet_unref().
  297. *
  298. * sizeof(AVPacket) being a part of the public ABI is deprecated. once
  299. * av_init_packet() is removed, new packets will only be able to be allocated
  300. * with av_packet_alloc(), and new fields may be added to the end of the struct
  301. * with a minor bump.
  302. *
  303. * @see av_packet_alloc
  304. * @see av_packet_ref
  305. * @see av_packet_unref
  306. */
  307. typedef struct AVPacket {
  308. /**
  309. * A reference to the reference-counted buffer where the packet data is
  310. * stored.
  311. * May be NULL, then the packet data is not reference-counted.
  312. */
  313. AVBufferRef *buf;
  314. /**
  315. * Presentation timestamp in AVStream->time_base units; the time at which
  316. * the decompressed packet will be presented to the user.
  317. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  318. * pts MUST be larger or equal to dts as presentation cannot happen before
  319. * decompression, unless one wants to view hex dumps. Some formats misuse
  320. * the terms dts and pts/cts to mean something different. Such timestamps
  321. * must be converted to true pts/dts before they are stored in AVPacket.
  322. */
  323. int64_t pts;
  324. /**
  325. * Decompression timestamp in AVStream->time_base units; the time at which
  326. * the packet is decompressed.
  327. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  328. */
  329. int64_t dts;
  330. uint8_t *data;
  331. int size;
  332. int stream_index;
  333. /**
  334. * A combination of AV_PKT_FLAG values
  335. */
  336. int flags;
  337. /**
  338. * Additional packet data that can be provided by the container.
  339. * Packet can contain several types of side information.
  340. */
  341. AVPacketSideData *side_data;
  342. int side_data_elems;
  343. /**
  344. * Duration of this packet in AVStream->time_base units, 0 if unknown.
  345. * Equals next_pts - this_pts in presentation order.
  346. */
  347. int64_t duration;
  348. int64_t pos; ///< byte position in stream, -1 if unknown
  349. #if FF_API_CONVERGENCE_DURATION
  350. /**
  351. * @deprecated Same as the duration field, but as int64_t. This was required
  352. * for Matroska subtitles, whose duration values could overflow when the
  353. * duration field was still an int.
  354. */
  355. attribute_deprecated
  356. int64_t convergence_duration;
  357. #endif
  358. } AVPacket;
  359. #if FF_API_INIT_PACKET
  360. attribute_deprecated
  361. typedef struct AVPacketList {
  362. AVPacket pkt;
  363. struct AVPacketList *next;
  364. } AVPacketList;
  365. #endif
  366. #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
  367. #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
  368. /**
  369. * Flag is used to discard packets which are required to maintain valid
  370. * decoder state but are not required for output and should be dropped
  371. * after decoding.
  372. **/
  373. #define AV_PKT_FLAG_DISCARD 0x0004
  374. /**
  375. * The packet comes from a trusted source.
  376. *
  377. * Otherwise-unsafe constructs such as arbitrary pointers to data
  378. * outside the packet may be followed.
  379. */
  380. #define AV_PKT_FLAG_TRUSTED 0x0008
  381. /**
  382. * Flag is used to indicate packets that contain frames that can
  383. * be discarded by the decoder. I.e. Non-reference frames.
  384. */
  385. #define AV_PKT_FLAG_DISPOSABLE 0x0010
  386. enum AVSideDataParamChangeFlags {
  387. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,
  388. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
  389. AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
  390. AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
  391. };
  392. /**
  393. * Allocate an AVPacket and set its fields to default values. The resulting
  394. * struct must be freed using av_packet_free().
  395. *
  396. * @return An AVPacket filled with default values or NULL on failure.
  397. *
  398. * @note this only allocates the AVPacket itself, not the data buffers. Those
  399. * must be allocated through other means such as av_new_packet.
  400. *
  401. * @see av_new_packet
  402. */
  403. AVPacket *av_packet_alloc(void);
  404. /**
  405. * Create a new packet that references the same data as src.
  406. *
  407. * This is a shortcut for av_packet_alloc()+av_packet_ref().
  408. *
  409. * @return newly created AVPacket on success, NULL on error.
  410. *
  411. * @see av_packet_alloc
  412. * @see av_packet_ref
  413. */
  414. AVPacket *av_packet_clone(const AVPacket *src);
  415. /**
  416. * Free the packet, if the packet is reference counted, it will be
  417. * unreferenced first.
  418. *
  419. * @param pkt packet to be freed. The pointer will be set to NULL.
  420. * @note passing NULL is a no-op.
  421. */
  422. void av_packet_free(AVPacket **pkt);
  423. #if FF_API_INIT_PACKET
  424. /**
  425. * Initialize optional fields of a packet with default values.
  426. *
  427. * Note, this does not touch the data and size members, which have to be
  428. * initialized separately.
  429. *
  430. * @param pkt packet
  431. *
  432. * @see av_packet_alloc
  433. * @see av_packet_unref
  434. *
  435. * @deprecated This function is deprecated. Once it's removed,
  436. sizeof(AVPacket) will not be a part of the ABI anymore.
  437. */
  438. attribute_deprecated
  439. void av_init_packet(AVPacket *pkt);
  440. #endif
  441. /**
  442. * Allocate the payload of a packet and initialize its fields with
  443. * default values.
  444. *
  445. * @param pkt packet
  446. * @param size wanted payload size
  447. * @return 0 if OK, AVERROR_xxx otherwise
  448. */
  449. int av_new_packet(AVPacket *pkt, int size);
  450. /**
  451. * Reduce packet size, correctly zeroing padding
  452. *
  453. * @param pkt packet
  454. * @param size new size
  455. */
  456. void av_shrink_packet(AVPacket *pkt, int size);
  457. /**
  458. * Increase packet size, correctly zeroing padding
  459. *
  460. * @param pkt packet
  461. * @param grow_by number of bytes by which to increase the size of the packet
  462. */
  463. int av_grow_packet(AVPacket *pkt, int grow_by);
  464. /**
  465. * Initialize a reference-counted packet from av_malloc()ed data.
  466. *
  467. * @param pkt packet to be initialized. This function will set the data, size,
  468. * and buf fields, all others are left untouched.
  469. * @param data Data allocated by av_malloc() to be used as packet data. If this
  470. * function returns successfully, the data is owned by the underlying AVBuffer.
  471. * The caller may not access the data through other means.
  472. * @param size size of data in bytes, without the padding. I.e. the full buffer
  473. * size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
  474. *
  475. * @return 0 on success, a negative AVERROR on error
  476. */
  477. int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
  478. #if FF_API_AVPACKET_OLD_API
  479. /**
  480. * @warning This is a hack - the packet memory allocation stuff is broken. The
  481. * packet is allocated if it was not really allocated.
  482. *
  483. * @deprecated Use av_packet_ref or av_packet_make_refcounted
  484. */
  485. attribute_deprecated
  486. int av_dup_packet(AVPacket *pkt);
  487. /**
  488. * Copy packet, including contents
  489. *
  490. * @return 0 on success, negative AVERROR on fail
  491. *
  492. * @deprecated Use av_packet_ref
  493. */
  494. attribute_deprecated
  495. int av_copy_packet(AVPacket *dst, const AVPacket *src);
  496. /**
  497. * Copy packet side data
  498. *
  499. * @return 0 on success, negative AVERROR on fail
  500. *
  501. * @deprecated Use av_packet_copy_props
  502. */
  503. attribute_deprecated
  504. int av_copy_packet_side_data(AVPacket *dst, const AVPacket *src);
  505. /**
  506. * Free a packet.
  507. *
  508. * @deprecated Use av_packet_unref
  509. *
  510. * @param pkt packet to free
  511. */
  512. attribute_deprecated
  513. void av_free_packet(AVPacket *pkt);
  514. #endif
  515. /**
  516. * Allocate new information of a packet.
  517. *
  518. * @param pkt packet
  519. * @param type side information type
  520. * @param size side information size
  521. * @return pointer to fresh allocated data or NULL otherwise
  522. */
  523. uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  524. #if FF_API_BUFFER_SIZE_T
  525. int size);
  526. #else
  527. size_t size);
  528. #endif
  529. /**
  530. * Wrap an existing array as a packet side data.
  531. *
  532. * @param pkt packet
  533. * @param type side information type
  534. * @param data the side data array. It must be allocated with the av_malloc()
  535. * family of functions. The ownership of the data is transferred to
  536. * pkt.
  537. * @param size side information size
  538. * @return a non-negative number on success, a negative AVERROR code on
  539. * failure. On failure, the packet is unchanged and the data remains
  540. * owned by the caller.
  541. */
  542. int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  543. uint8_t *data, size_t size);
  544. /**
  545. * Shrink the already allocated side data buffer
  546. *
  547. * @param pkt packet
  548. * @param type side information type
  549. * @param size new side information size
  550. * @return 0 on success, < 0 on failure
  551. */
  552. int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  553. #if FF_API_BUFFER_SIZE_T
  554. int size);
  555. #else
  556. size_t size);
  557. #endif
  558. /**
  559. * Get side information from packet.
  560. *
  561. * @param pkt packet
  562. * @param type desired side information type
  563. * @param size If supplied, *size will be set to the size of the side data
  564. * or to zero if the desired side data is not present.
  565. * @return pointer to data if present or NULL otherwise
  566. */
  567. uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type,
  568. #if FF_API_BUFFER_SIZE_T
  569. int *size);
  570. #else
  571. size_t *size);
  572. #endif
  573. #if FF_API_MERGE_SD_API
  574. attribute_deprecated
  575. int av_packet_merge_side_data(AVPacket *pkt);
  576. attribute_deprecated
  577. int av_packet_split_side_data(AVPacket *pkt);
  578. #endif
  579. const char *av_packet_side_data_name(enum AVPacketSideDataType type);
  580. /**
  581. * Pack a dictionary for use in side_data.
  582. *
  583. * @param dict The dictionary to pack.
  584. * @param size pointer to store the size of the returned data
  585. * @return pointer to data if successful, NULL otherwise
  586. */
  587. #if FF_API_BUFFER_SIZE_T
  588. uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size);
  589. #else
  590. uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size);
  591. #endif
  592. /**
  593. * Unpack a dictionary from side_data.
  594. *
  595. * @param data data from side_data
  596. * @param size size of the data
  597. * @param dict the metadata storage dictionary
  598. * @return 0 on success, < 0 on failure
  599. */
  600. #if FF_API_BUFFER_SIZE_T
  601. int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict);
  602. #else
  603. int av_packet_unpack_dictionary(const uint8_t *data, size_t size,
  604. AVDictionary **dict);
  605. #endif
  606. /**
  607. * Convenience function to free all the side data stored.
  608. * All the other fields stay untouched.
  609. *
  610. * @param pkt packet
  611. */
  612. void av_packet_free_side_data(AVPacket *pkt);
  613. /**
  614. * Setup a new reference to the data described by a given packet
  615. *
  616. * If src is reference-counted, setup dst as a new reference to the
  617. * buffer in src. Otherwise allocate a new buffer in dst and copy the
  618. * data from src into it.
  619. *
  620. * All the other fields are copied from src.
  621. *
  622. * @see av_packet_unref
  623. *
  624. * @param dst Destination packet. Will be completely overwritten.
  625. * @param src Source packet
  626. *
  627. * @return 0 on success, a negative AVERROR on error. On error, dst
  628. * will be blank (as if returned by av_packet_alloc()).
  629. */
  630. int av_packet_ref(AVPacket *dst, const AVPacket *src);
  631. /**
  632. * Wipe the packet.
  633. *
  634. * Unreference the buffer referenced by the packet and reset the
  635. * remaining packet fields to their default values.
  636. *
  637. * @param pkt The packet to be unreferenced.
  638. */
  639. void av_packet_unref(AVPacket *pkt);
  640. /**
  641. * Move every field in src to dst and reset src.
  642. *
  643. * @see av_packet_unref
  644. *
  645. * @param src Source packet, will be reset
  646. * @param dst Destination packet
  647. */
  648. void av_packet_move_ref(AVPacket *dst, AVPacket *src);
  649. /**
  650. * Copy only "properties" fields from src to dst.
  651. *
  652. * Properties for the purpose of this function are all the fields
  653. * beside those related to the packet data (buf, data, size)
  654. *
  655. * @param dst Destination packet
  656. * @param src Source packet
  657. *
  658. * @return 0 on success AVERROR on failure.
  659. */
  660. int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
  661. /**
  662. * Ensure the data described by a given packet is reference counted.
  663. *
  664. * @note This function does not ensure that the reference will be writable.
  665. * Use av_packet_make_writable instead for that purpose.
  666. *
  667. * @see av_packet_ref
  668. * @see av_packet_make_writable
  669. *
  670. * @param pkt packet whose data should be made reference counted.
  671. *
  672. * @return 0 on success, a negative AVERROR on error. On failure, the
  673. * packet is unchanged.
  674. */
  675. int av_packet_make_refcounted(AVPacket *pkt);
  676. /**
  677. * Create a writable reference for the data described by a given packet,
  678. * avoiding data copy if possible.
  679. *
  680. * @param pkt Packet whose data should be made writable.
  681. *
  682. * @return 0 on success, a negative AVERROR on failure. On failure, the
  683. * packet is unchanged.
  684. */
  685. int av_packet_make_writable(AVPacket *pkt);
  686. /**
  687. * Convert valid timing fields (timestamps / durations) in a packet from one
  688. * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
  689. * ignored.
  690. *
  691. * @param pkt packet on which the conversion will be performed
  692. * @param tb_src source timebase, in which the timing fields in pkt are
  693. * expressed
  694. * @param tb_dst destination timebase, to which the timing fields will be
  695. * converted
  696. */
  697. void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
  698. /**
  699. * @}
  700. */
  701. #endif // AVCODEC_PACKET_H