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
21#ifndef AVCODEC_PACKET_H
22#define AVCODEC_PACKET_H
23
24#include <stddef.h>
25#include <stdint.h>
26
27#include "libavutil/attributes.h"
28#include "libavutil/buffer.h"
29#include "libavutil/dict.h"
30#include "libavutil/rational.h"
31#include "libavutil/version.h"
32
33#include "libavcodec/version_major.h"
34
35/**
36 * @defgroup lavc_packet_side_data AVPacketSideData
37 *
38 * Types and functions for working with AVPacketSideData.
39 * @{
40 */
41enum AVPacketSideDataType {
42 /**
43 * An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE
44 * bytes worth of palette. This side data signals that a new palette is
45 * present.
46 */
47 AV_PKT_DATA_PALETTE,
48
49 /**
50 * The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format
51 * that the extradata buffer was changed and the receiving side should
52 * act upon it appropriately. The new extradata is embedded in the side
53 * data buffer and should be immediately used for processing the current
54 * frame or packet.
55 */
56 AV_PKT_DATA_NEW_EXTRADATA,
57
58 /**
59 * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
60 * @code
61 * u32le param_flags
62 * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
63 * s32le sample_rate
64 * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
65 * s32le width
66 * s32le height
67 * @endcode
68 */
69 AV_PKT_DATA_PARAM_CHANGE,
70
71 /**
72 * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
73 * structures with info about macroblocks relevant to splitting the
74 * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
75 * That is, it does not necessarily contain info about all macroblocks,
76 * as long as the distance between macroblocks in the info is smaller
77 * than the target payload size.
78 * Each MB info structure is 12 bytes, and is laid out as follows:
79 * @code
80 * u32le bit offset from the start of the packet
81 * u8 current quantizer at the start of the macroblock
82 * u8 GOB number
83 * u16le macroblock address within the GOB
84 * u8 horizontal MV predictor
85 * u8 vertical MV predictor
86 * u8 horizontal MV predictor for block number 3
87 * u8 vertical MV predictor for block number 3
88 * @endcode
89 */
90 AV_PKT_DATA_H263_MB_INFO,
91
92 /**
93 * This side data should be associated with an audio stream and contains
94 * ReplayGain information in form of the AVReplayGain struct.
95 */
96 AV_PKT_DATA_REPLAYGAIN,
97
98 /**
99 * This side data contains a 3x3 transformation matrix describing an affine
100 * transformation that needs to be applied to the decoded video frames for
101 * correct presentation.
102 *
103 * See libavutil/display.h for a detailed description of the data.
104 */
105 AV_PKT_DATA_DISPLAYMATRIX,
106
107 /**
108 * This side data should be associated with a video stream and contains
109 * Stereoscopic 3D information in form of the AVStereo3D struct.
110 */
111 AV_PKT_DATA_STEREO3D,
112
113 /**
114 * This side data should be associated with an audio stream and corresponds
115 * to enum AVAudioServiceType.
116 */
117 AV_PKT_DATA_AUDIO_SERVICE_TYPE,
118
119 /**
120 * This side data contains quality related information from the encoder.
121 * @code
122 * u32le quality factor of the compressed frame. Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad).
123 * u8 picture type
124 * u8 error count
125 * u16 reserved
126 * u64le[error count] sum of squared differences between encoder in and output
127 * @endcode
128 */
129 AV_PKT_DATA_QUALITY_STATS,
130
131 /**
132 * This side data contains an integer value representing the stream index
133 * of a "fallback" track. A fallback track indicates an alternate
134 * track to use when the current track can not be decoded for some reason.
135 * e.g. no decoder available for codec.
136 */
137 AV_PKT_DATA_FALLBACK_TRACK,
138
139 /**
140 * This side data corresponds to the AVCPBProperties struct.
141 */
142 AV_PKT_DATA_CPB_PROPERTIES,
143
144 /**
145 * Recommends skipping the specified number of samples
146 * @code
147 * u32le number of samples to skip from start of this packet
148 * u32le number of samples to skip from end of this packet
149 * u8 reason for start skip
150 * u8 reason for end skip (0=padding silence, 1=convergence)
151 * @endcode
152 */
153 AV_PKT_DATA_SKIP_SAMPLES,
154
155 /**
156 * An AV_PKT_DATA_JP_DUALMONO side data packet indicates that
157 * the packet may contain "dual mono" audio specific to Japanese DTV
158 * and if it is true, recommends only the selected channel to be used.
159 * @code
160 * u8 selected channels (0=main/left, 1=sub/right, 2=both)
161 * @endcode
162 */
163 AV_PKT_DATA_JP_DUALMONO,
164
165 /**
166 * A list of zero terminated key/value strings. There is no end marker for
167 * the list, so it is required to rely on the side data size to stop.
168 */
169 AV_PKT_DATA_STRINGS_METADATA,
170
171 /**
172 * Subtitle event position
173 * @code
174 * u32le x1
175 * u32le y1
176 * u32le x2
177 * u32le y2
178 * @endcode
179 */
180 AV_PKT_DATA_SUBTITLE_POSITION,
181
182 /**
183 * Data found in BlockAdditional element of matroska container. There is
184 * no end marker for the data, so it is required to rely on the side data
185 * size to recognize the end. 8 byte id (as found in BlockAddId) followed
186 * by data.
187 */
188 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
189
190 /**
191 * The optional first identifier line of a WebVTT cue.
192 */
193 AV_PKT_DATA_WEBVTT_IDENTIFIER,
194
195 /**
196 * The optional settings (rendering instructions) that immediately
197 * follow the timestamp specifier of a WebVTT cue.
198 */
199 AV_PKT_DATA_WEBVTT_SETTINGS,
200
201 /**
202 * A list of zero terminated key/value strings. There is no end marker for
203 * the list, so it is required to rely on the side data size to stop. This
204 * side data includes updated metadata which appeared in the stream.
205 */
206 AV_PKT_DATA_METADATA_UPDATE,
207
208 /**
209 * MPEGTS stream ID as uint8_t, this is required to pass the stream ID
210 * information from the demuxer to the corresponding muxer.
211 */
212 AV_PKT_DATA_MPEGTS_STREAM_ID,
213
214 /**
215 * Mastering display metadata (based on SMPTE-2086:2014). This metadata
216 * should be associated with a video stream and contains data in the form
217 * of the AVMasteringDisplayMetadata struct.
218 */
219 AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
220
221 /**
222 * This side data should be associated with a video stream and corresponds
223 * to the AVSphericalMapping structure.
224 */
225 AV_PKT_DATA_SPHERICAL,
226
227 /**
228 * Content light level (based on CTA-861.3). This metadata should be
229 * associated with a video stream and contains data in the form of the
230 * AVContentLightMetadata struct.
231 */
232 AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
233
234 /**
235 * ATSC A53 Part 4 Closed Captions. This metadata should be associated with
236 * a video stream. A53 CC bitstream is stored as uint8_t in AVPacketSideData.data.
237 * The number of bytes of CC data is AVPacketSideData.size.
238 */
239 AV_PKT_DATA_A53_CC,
240
241 /**
242 * This side data is encryption initialization data.
243 * The format is not part of ABI, use av_encryption_init_info_* methods to
244 * access.
245 */
246 AV_PKT_DATA_ENCRYPTION_INIT_INFO,
247
248 /**
249 * This side data contains encryption info for how to decrypt the packet.
250 * The format is not part of ABI, use av_encryption_info_* methods to access.
251 */
252 AV_PKT_DATA_ENCRYPTION_INFO,
253
254 /**
255 * Active Format Description data consisting of a single byte as specified
256 * in ETSI TS 101 154 using AVActiveFormatDescription enum.
257 */
258 AV_PKT_DATA_AFD,
259
260 /**
261 * Producer Reference Time data corresponding to the AVProducerReferenceTime struct,
262 * usually exported by some encoders (on demand through the prft flag set in the
263 * AVCodecContext export_side_data field).
264 */
265 AV_PKT_DATA_PRFT,
266
267 /**
268 * ICC profile data consisting of an opaque octet buffer following the
269 * format described by ISO 15076-1.
270 */
271 AV_PKT_DATA_ICC_PROFILE,
272
273 /**
274 * DOVI configuration
275 * ref:
276 * dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2, section 2.2
277 * dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2, section 3.3
278 * Tags are stored in struct AVDOVIDecoderConfigurationRecord.
279 */
280 AV_PKT_DATA_DOVI_CONF,
281
282 /**
283 * Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t
284 * where the first uint32_t describes how many (1-3) of the other timecodes are used.
285 * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
286 * function in libavutil/timecode.h.
287 */
288 AV_PKT_DATA_S12M_TIMECODE,
289
290 /**
291 * HDR10+ dynamic metadata associated with a video frame. The metadata is in
292 * the form of the AVDynamicHDRPlus struct and contains
293 * information for color volume transform - application 4 of
294 * SMPTE 2094-40:2016 standard.
295 */
296 AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
297
298 /**
299 * IAMF Mix Gain Parameter Data associated with the audio frame. This metadata
300 * is in the form of the AVIAMFParamDefinition struct and contains information
301 * defined in sections 3.6.1 and 3.8.1 of the Immersive Audio Model and
302 * Formats standard.
303 */
304 AV_PKT_DATA_IAMF_MIX_GAIN_PARAM,
305
306 /**
307 * IAMF Demixing Info Parameter Data associated with the audio frame. This
308 * metadata is in the form of the AVIAMFParamDefinition struct and contains
309 * information defined in sections 3.6.1 and 3.8.2 of the Immersive Audio Model
310 * and Formats standard.
311 */
312 AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM,
313
314 /**
315 * IAMF Recon Gain Info Parameter Data associated with the audio frame. This
316 * metadata is in the form of the AVIAMFParamDefinition struct and contains
317 * information defined in sections 3.6.1 and 3.8.3 of the Immersive Audio Model
318 * and Formats standard.
319 */
320 AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM,
321
322 /**
323 * Ambient viewing environment metadata, as defined by H.274. This metadata
324 * should be associated with a video stream and contains data in the form
325 * of the AVAmbientViewingEnvironment struct.
326 */
327 AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,
328
329 /**
330 * The number of pixels to discard from the top/bottom/left/right border of the
331 * decoded frame to obtain the sub-rectangle intended for presentation.
332 *
333 * @code
334 * u32le crop_top
335 * u32le crop_bottom
336 * u32le crop_left
337 * u32le crop_right
338 * @endcode
339 */
340 AV_PKT_DATA_FRAME_CROPPING,
341
342 /**
343 * Raw LCEVC payload data, as a uint8_t array, with NAL emulation
344 * bytes intact.
345 */
346 AV_PKT_DATA_LCEVC,
347
348 /**
349 * This side data contains information about the reference display width(s)
350 * and reference viewing distance(s) as well as information about the
351 * corresponding reference stereo pair(s), i.e., the pair(s) of views to be
352 * displayed for the viewer's left and right eyes on the reference display
353 * at the reference viewing distance.
354 * The payload is the AV3DReferenceDisplaysInfo struct defined in
355 * libavutil/tdrdi.h.
356 */
357 AV_PKT_DATA_3D_REFERENCE_DISPLAYS,
358
359 /**
360 * Contains the last received RTCP SR (Sender Report) information
361 * in the form of the AVRTCPSenderReport struct.
362 */
363 AV_PKT_DATA_RTCP_SR,
364
365 /**
366 * The number of side data types.
367 * This is not part of the public API/ABI in the sense that it may
368 * change when new side data types are added.
369 * This must stay the last enum value.
370 * If its value becomes huge, some code using it
371 * needs to be updated as it assumes it to be smaller than other limits.
372 */
373 AV_PKT_DATA_NB
374};
375
376/**
377 * This structure stores auxiliary information for decoding, presenting, or
378 * otherwise processing the coded stream. It is typically exported by demuxers
379 * and encoders and can be fed to decoders and muxers either in a per packet
380 * basis, or as global side data (applying to the entire coded stream).
381 *
382 * Global side data is handled as follows:
383 * - During demuxing, it may be exported through
384 * @ref AVCodecParameters.coded_side_data "AVStream's codec parameters", which can
385 * then be passed as input to decoders through the
386 * @ref AVCodecContext.coded_side_data "decoder context's side data", for
387 * initialization.
388 * - For muxing, it can be fed through @ref AVCodecParameters.coded_side_data
389 * "AVStream's codec parameters", typically the output of encoders through
390 * the @ref AVCodecContext.coded_side_data "encoder context's side data", for
391 * initialization.
392 *
393 * Packet specific side data is handled as follows:
394 * - During demuxing, it may be exported through @ref AVPacket.side_data
395 * "AVPacket's side data", which can then be passed as input to decoders.
396 * - For muxing, it can be fed through @ref AVPacket.side_data "AVPacket's
397 * side data", typically the output of encoders.
398 *
399 * Different modules may accept or export different types of side data
400 * depending on media type and codec. Refer to @ref AVPacketSideDataType for a
401 * list of defined types and where they may be found or used.
402 */
403typedef struct AVPacketSideData {
404 uint8_t *data;
405 size_t size;
406 enum AVPacketSideDataType type;
407} AVPacketSideData;
408
409/**
410 * Allocate a new packet side data.
411 *
412 * @param sd pointer to an array of side data to which the side data should
413 * be added. *sd may be NULL, in which case the array will be
414 * initialized.
415 * @param nb_sd pointer to an integer containing the number of entries in
416 * the array. The integer value will be increased by 1 on success.
417 * @param type side data type
418 * @param size desired side data size
419 * @param flags currently unused. Must be zero
420 *
421 * @return pointer to freshly allocated side data on success, or NULL otherwise.
422 */
423AVPacketSideData *av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd,
424 enum AVPacketSideDataType type,
425 size_t size, int flags);
426
427/**
428 * Wrap existing data as packet side data.
429 *
430 * @param sd pointer to an array of side data to which the side data should
431 * be added. *sd may be NULL, in which case the array will be
432 * initialized
433 * @param nb_sd pointer to an integer containing the number of entries in
434 * the array. The integer value will be increased by 1 on success.
435 * @param type side data type
436 * @param data a data array. It must be allocated with the av_malloc() family
437 * of functions. The ownership of the data is transferred to the
438 * side data array on success
439 * @param size size of the data array
440 * @param flags currently unused. Must be zero
441 *
442 * @return pointer to freshly allocated side data on success, or NULL otherwise
443 * On failure, the side data array is unchanged and the data remains
444 * owned by the caller.
445 */
446AVPacketSideData *av_packet_side_data_add(AVPacketSideData **sd, int *nb_sd,
447 enum AVPacketSideDataType type,
448 void *data, size_t size, int flags);
449
450/**
451 * Get side information from a side data array.
452 *
453 * @param sd the array from which the side data should be fetched
454 * @param nb_sd value containing the number of entries in the array.
455 * @param type desired side information type
456 *
457 * @return pointer to side data if present or NULL otherwise
458 */
459const AVPacketSideData *av_packet_side_data_get(const AVPacketSideData *sd,
460 int nb_sd,
461 enum AVPacketSideDataType type);
462
463/**
464 * Remove side data of the given type from a side data array.
465 *
466 * @param sd the array from which the side data should be removed
467 * @param nb_sd pointer to an integer containing the number of entries in
468 * the array. Will be reduced by the amount of entries removed
469 * upon return
470 * @param type side information type
471 */
472void av_packet_side_data_remove(AVPacketSideData *sd, int *nb_sd,
473 enum AVPacketSideDataType type);
474
475/**
476 * Convenience function to free all the side data stored in an array, and
477 * the array itself.
478 *
479 * @param sd pointer to array of side data to free. Will be set to NULL
480 * upon return.
481 * @param nb_sd pointer to an integer containing the number of entries in
482 * the array. Will be set to 0 upon return.
483 */
484void av_packet_side_data_free(AVPacketSideData **sd, int *nb_sd);
485
486const char *av_packet_side_data_name(enum AVPacketSideDataType type);
487
488/**
489 * @}
490 */
491
492/**
493 * @defgroup lavc_packet AVPacket
494 *
495 * Types and functions for working with AVPacket.
496 * @{
497 */
498
499/**
500 * This structure stores compressed data. It is typically exported by demuxers
501 * and then passed as input to decoders, or received as output from encoders and
502 * then passed to muxers.
503 *
504 * For video, it should typically contain one compressed frame. For audio it may
505 * contain several compressed frames. Encoders are allowed to output empty
506 * packets, with no compressed data, containing only side data
507 * (e.g. to update some stream parameters at the end of encoding).
508 *
509 * The semantics of data ownership depends on the buf field.
510 * If it is set, the packet data is dynamically allocated and is
511 * valid indefinitely until a call to av_packet_unref() reduces the
512 * reference count to 0.
513 *
514 * If the buf field is not set av_packet_ref() would make a copy instead
515 * of increasing the reference count.
516 *
517 * The side data is always allocated with av_malloc(), copied by
518 * av_packet_ref() and freed by av_packet_unref().
519 *
520 * sizeof(AVPacket) being a part of the public ABI is deprecated. once
521 * av_init_packet() is removed, new packets will only be able to be allocated
522 * with av_packet_alloc(), and new fields may be added to the end of the struct
523 * with a minor bump.
524 *
525 * @see av_packet_alloc
526 * @see av_packet_ref
527 * @see av_packet_unref
528 */
529typedef struct AVPacket {
530 /**
531 * A reference to the reference-counted buffer where the packet data is
532 * stored.
533 * May be NULL, then the packet data is not reference-counted.
534 */
535 AVBufferRef *buf;
536 /**
537 * Presentation timestamp in AVStream->time_base units; the time at which
538 * the decompressed packet will be presented to the user.
539 * Can be AV_NOPTS_VALUE if it is not stored in the file.
540 * pts MUST be larger or equal to dts as presentation cannot happen before
541 * decompression, unless one wants to view hex dumps. Some formats misuse
542 * the terms dts and pts/cts to mean something different. Such timestamps
543 * must be converted to true pts/dts before they are stored in AVPacket.
544 */
545 int64_t pts;
546 /**
547 * Decompression timestamp in AVStream->time_base units; the time at which
548 * the packet is decompressed.
549 * Can be AV_NOPTS_VALUE if it is not stored in the file.
550 */
551 int64_t dts;
552 uint8_t *data;
553 int size;
554 int stream_index;
555 /**
556 * A combination of AV_PKT_FLAG values
557 */
558 int flags;
559 /**
560 * Additional packet data that can be provided by the container.
561 * Packet can contain several types of side information.
562 */
563 AVPacketSideData *side_data;
564 int side_data_elems;
565
566 /**
567 * Duration of this packet in AVStream->time_base units, 0 if unknown.
568 * Equals next_pts - this_pts in presentation order.
569 */
570 int64_t duration;
571
572 int64_t pos; ///< byte position in stream, -1 if unknown
573
574 /**
575 * for some private data of the user
576 */
577 void *opaque;
578
579 /**
580 * AVBufferRef for free use by the API user. FFmpeg will never check the
581 * contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when
582 * the packet is unreferenced. av_packet_copy_props() calls create a new
583 * reference with av_buffer_ref() for the target packet's opaque_ref field.
584 *
585 * This is unrelated to the opaque field, although it serves a similar
586 * purpose.
587 */
588 AVBufferRef *opaque_ref;
589
590 /**
591 * Time base of the packet's timestamps.
592 * In the future, this field may be set on packets output by encoders or
593 * demuxers, but its value will be by default ignored on input to decoders
594 * or muxers.
595 */
596 AVRational time_base;
597} AVPacket;
598
599#if FF_API_INIT_PACKET
600attribute_deprecated
601typedef struct AVPacketList {
602 AVPacket pkt;
603 struct AVPacketList *next;
604} AVPacketList;
605#endif
606
607#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
608#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
609/**
610 * Flag is used to discard packets which are required to maintain valid
611 * decoder state but are not required for output and should be dropped
612 * after decoding.
613 **/
614#define AV_PKT_FLAG_DISCARD 0x0004
615/**
616 * The packet comes from a trusted source.
617 *
618 * Otherwise-unsafe constructs such as arbitrary pointers to data
619 * outside the packet may be followed.
620 */
621#define AV_PKT_FLAG_TRUSTED 0x0008
622/**
623 * Flag is used to indicate packets that contain frames that can
624 * be discarded by the decoder. I.e. Non-reference frames.
625 */
626#define AV_PKT_FLAG_DISPOSABLE 0x0010
627
628enum AVSideDataParamChangeFlags {
629 AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
630 AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
631};
632
633/**
634 * Allocate an AVPacket and set its fields to default values. The resulting
635 * struct must be freed using av_packet_free().
636 *
637 * @return An AVPacket filled with default values or NULL on failure.
638 *
639 * @note this only allocates the AVPacket itself, not the data buffers. Those
640 * must be allocated through other means such as av_new_packet.
641 *
642 * @see av_new_packet
643 */
644AVPacket *av_packet_alloc(void);
645
646/**
647 * Create a new packet that references the same data as src.
648 *
649 * This is a shortcut for av_packet_alloc()+av_packet_ref().
650 *
651 * @return newly created AVPacket on success, NULL on error.
652 *
653 * @see av_packet_alloc
654 * @see av_packet_ref
655 */
656AVPacket *av_packet_clone(const AVPacket *src);
657
658/**
659 * Free the packet, if the packet is reference counted, it will be
660 * unreferenced first.
661 *
662 * @param pkt packet to be freed. The pointer will be set to NULL.
663 * @note passing NULL is a no-op.
664 */
665void av_packet_free(AVPacket **pkt);
666
667#if FF_API_INIT_PACKET
668/**
669 * Initialize optional fields of a packet with default values.
670 *
671 * Note, this does not touch the data and size members, which have to be
672 * initialized separately.
673 *
674 * @param pkt packet
675 *
676 * @see av_packet_alloc
677 * @see av_packet_unref
678 *
679 * @deprecated This function is deprecated. Once it's removed,
680 sizeof(AVPacket) will not be a part of the ABI anymore.
681 */
682attribute_deprecated
683void av_init_packet(AVPacket *pkt);
684#endif
685
686/**
687 * Allocate the payload of a packet and initialize its fields with
688 * default values.
689 *
690 * @param pkt packet
691 * @param size wanted payload size
692 * @return 0 if OK, AVERROR_xxx otherwise
693 */
694int av_new_packet(AVPacket *pkt, int size);
695
696/**
697 * Reduce packet size, correctly zeroing padding
698 *
699 * @param pkt packet
700 * @param size new size
701 */
702void av_shrink_packet(AVPacket *pkt, int size);
703
704/**
705 * Increase packet size, correctly zeroing padding
706 *
707 * @param pkt packet
708 * @param grow_by number of bytes by which to increase the size of the packet
709 */
710int av_grow_packet(AVPacket *pkt, int grow_by);
711
712/**
713 * Initialize a reference-counted packet from av_malloc()ed data.
714 *
715 * @param pkt packet to be initialized. This function will set the data, size,
716 * and buf fields, all others are left untouched.
717 * @param data Data allocated by av_malloc() to be used as packet data. If this
718 * function returns successfully, the data is owned by the underlying AVBuffer.
719 * The caller may not access the data through other means.
720 * @param size size of data in bytes, without the padding. I.e. the full buffer
721 * size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
722 *
723 * @return 0 on success, a negative AVERROR on error
724 */
725int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
726
727/**
728 * Allocate new information of a packet.
729 *
730 * @param pkt packet
731 * @param type side information type
732 * @param size side information size
733 * @return pointer to fresh allocated data or NULL otherwise
734 */
735uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
736 size_t size);
737
738/**
739 * Wrap an existing array as a packet side data.
740 *
741 * @param pkt packet
742 * @param type side information type
743 * @param data the side data array. It must be allocated with the av_malloc()
744 * family of functions. The ownership of the data is transferred to
745 * pkt.
746 * @param size side information size
747 * @return a non-negative number on success, a negative AVERROR code on
748 * failure. On failure, the packet is unchanged and the data remains
749 * owned by the caller.
750 */
751int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
752 uint8_t *data, size_t size);
753
754/**
755 * Shrink the already allocated side data buffer
756 *
757 * @param pkt packet
758 * @param type side information type
759 * @param size new side information size
760 * @return 0 on success, < 0 on failure
761 */
762int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
763 size_t size);
764
765/**
766 * Get side information from packet.
767 *
768 * @param pkt packet
769 * @param type desired side information type
770 * @param size If supplied, *size will be set to the size of the side data
771 * or to zero if the desired side data is not present.
772 * @return pointer to data if present or NULL otherwise
773 */
774uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type,
775 size_t *size);
776
777/**
778 * Pack a dictionary for use in side_data.
779 *
780 * @param dict The dictionary to pack.
781 * @param size pointer to store the size of the returned data
782 * @return pointer to data if successful, NULL otherwise
783 */
784uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size);
785/**
786 * Unpack a dictionary from side_data.
787 *
788 * @param data data from side_data
789 * @param size size of the data
790 * @param dict the metadata storage dictionary
791 * @return 0 on success, < 0 on failure
792 */
793int av_packet_unpack_dictionary(const uint8_t *data, size_t size,
794 AVDictionary **dict);
795
796/**
797 * Convenience function to free all the side data stored.
798 * All the other fields stay untouched.
799 *
800 * @param pkt packet
801 */
802void av_packet_free_side_data(AVPacket *pkt);
803
804/**
805 * Setup a new reference to the data described by a given packet
806 *
807 * If src is reference-counted, setup dst as a new reference to the
808 * buffer in src. Otherwise allocate a new buffer in dst and copy the
809 * data from src into it.
810 *
811 * All the other fields are copied from src.
812 *
813 * @see av_packet_unref
814 *
815 * @param dst Destination packet. Will be completely overwritten.
816 * @param src Source packet
817 *
818 * @return 0 on success, a negative AVERROR on error. On error, dst
819 * will be blank (as if returned by av_packet_alloc()).
820 */
821int av_packet_ref(AVPacket *dst, const AVPacket *src);
822
823/**
824 * Wipe the packet.
825 *
826 * Unreference the buffer referenced by the packet and reset the
827 * remaining packet fields to their default values.
828 *
829 * @param pkt The packet to be unreferenced.
830 */
831void av_packet_unref(AVPacket *pkt);
832
833/**
834 * Move every field in src to dst and reset src.
835 *
836 * @see av_packet_unref
837 *
838 * @param src Source packet, will be reset
839 * @param dst Destination packet
840 */
841void av_packet_move_ref(AVPacket *dst, AVPacket *src);
842
843/**
844 * Copy only "properties" fields from src to dst.
845 *
846 * Properties for the purpose of this function are all the fields
847 * beside those related to the packet data (buf, data, size)
848 *
849 * @param dst Destination packet
850 * @param src Source packet
851 *
852 * @return 0 on success AVERROR on failure.
853 */
854int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
855
856/**
857 * Ensure the data described by a given packet is reference counted.
858 *
859 * @note This function does not ensure that the reference will be writable.
860 * Use av_packet_make_writable instead for that purpose.
861 *
862 * @see av_packet_ref
863 * @see av_packet_make_writable
864 *
865 * @param pkt packet whose data should be made reference counted.
866 *
867 * @return 0 on success, a negative AVERROR on error. On failure, the
868 * packet is unchanged.
869 */
870int av_packet_make_refcounted(AVPacket *pkt);
871
872/**
873 * Create a writable reference for the data described by a given packet,
874 * avoiding data copy if possible.
875 *
876 * @param pkt Packet whose data should be made writable.
877 *
878 * @return 0 on success, a negative AVERROR on failure. On failure, the
879 * packet is unchanged.
880 */
881int av_packet_make_writable(AVPacket *pkt);
882
883/**
884 * Convert valid timing fields (timestamps / durations) in a packet from one
885 * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
886 * ignored.
887 *
888 * @param pkt packet on which the conversion will be performed
889 * @param tb_src source timebase, in which the timing fields in pkt are
890 * expressed
891 * @param tb_dst destination timebase, to which the timing fields will be
892 * converted
893 */
894void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
895
896/**
897 * Allocate an AVContainerFifo instance for AVPacket.
898 *
899 * @param flags currently unused
900 */
901struct AVContainerFifo *av_container_fifo_alloc_avpacket(unsigned flags);
902
903/**
904 * @}
905 */
906
907#endif // AVCODEC_PACKET_H
908