Path: blob/a-new-beginning/libavcodec.xcframework/ios-arm64-simulator/libavcodec.framework/Headers/packet.h
2 views
/*1* AVPacket public API2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#ifndef AVCODEC_PACKET_H21#define AVCODEC_PACKET_H2223#include <stddef.h>24#include <stdint.h>2526#include "libavutil/attributes.h"27#include "libavutil/buffer.h"28#include "libavutil/dict.h"29#include "libavutil/rational.h"30#include "libavutil/version.h"3132#include "libavcodec/version_major.h"3334/**35* @defgroup lavc_packet AVPacket36*37* Types and functions for working with AVPacket.38* @{39*/40enum AVPacketSideDataType {41/**42* An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE43* bytes worth of palette. This side data signals that a new palette is44* present.45*/46AV_PKT_DATA_PALETTE,4748/**49* The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format50* that the extradata buffer was changed and the receiving side should51* act upon it appropriately. The new extradata is embedded in the side52* data buffer and should be immediately used for processing the current53* frame or packet.54*/55AV_PKT_DATA_NEW_EXTRADATA,5657/**58* An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:59* @code60* u32le param_flags61* if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)62* s32le channel_count63* if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)64* u64le channel_layout65* if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)66* s32le sample_rate67* if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)68* s32le width69* s32le height70* @endcode71*/72AV_PKT_DATA_PARAM_CHANGE,7374/**75* An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of76* structures with info about macroblocks relevant to splitting the77* packet into smaller packets on macroblock edges (e.g. as for RFC 2190).78* That is, it does not necessarily contain info about all macroblocks,79* as long as the distance between macroblocks in the info is smaller80* than the target payload size.81* Each MB info structure is 12 bytes, and is laid out as follows:82* @code83* u32le bit offset from the start of the packet84* u8 current quantizer at the start of the macroblock85* u8 GOB number86* u16le macroblock address within the GOB87* u8 horizontal MV predictor88* u8 vertical MV predictor89* u8 horizontal MV predictor for block number 390* u8 vertical MV predictor for block number 391* @endcode92*/93AV_PKT_DATA_H263_MB_INFO,9495/**96* This side data should be associated with an audio stream and contains97* ReplayGain information in form of the AVReplayGain struct.98*/99AV_PKT_DATA_REPLAYGAIN,100101/**102* This side data contains a 3x3 transformation matrix describing an affine103* transformation that needs to be applied to the decoded video frames for104* correct presentation.105*106* See libavutil/display.h for a detailed description of the data.107*/108AV_PKT_DATA_DISPLAYMATRIX,109110/**111* This side data should be associated with a video stream and contains112* Stereoscopic 3D information in form of the AVStereo3D struct.113*/114AV_PKT_DATA_STEREO3D,115116/**117* This side data should be associated with an audio stream and corresponds118* to enum AVAudioServiceType.119*/120AV_PKT_DATA_AUDIO_SERVICE_TYPE,121122/**123* This side data contains quality related information from the encoder.124* @code125* u32le quality factor of the compressed frame. Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad).126* u8 picture type127* u8 error count128* u16 reserved129* u64le[error count] sum of squared differences between encoder in and output130* @endcode131*/132AV_PKT_DATA_QUALITY_STATS,133134/**135* This side data contains an integer value representing the stream index136* of a "fallback" track. A fallback track indicates an alternate137* track to use when the current track can not be decoded for some reason.138* e.g. no decoder available for codec.139*/140AV_PKT_DATA_FALLBACK_TRACK,141142/**143* This side data corresponds to the AVCPBProperties struct.144*/145AV_PKT_DATA_CPB_PROPERTIES,146147/**148* Recommmends skipping the specified number of samples149* @code150* u32le number of samples to skip from start of this packet151* u32le number of samples to skip from end of this packet152* u8 reason for start skip153* u8 reason for end skip (0=padding silence, 1=convergence)154* @endcode155*/156AV_PKT_DATA_SKIP_SAMPLES,157158/**159* An AV_PKT_DATA_JP_DUALMONO side data packet indicates that160* the packet may contain "dual mono" audio specific to Japanese DTV161* and if it is true, recommends only the selected channel to be used.162* @code163* u8 selected channels (0=main/left, 1=sub/right, 2=both)164* @endcode165*/166AV_PKT_DATA_JP_DUALMONO,167168/**169* A list of zero terminated key/value strings. There is no end marker for170* the list, so it is required to rely on the side data size to stop.171*/172AV_PKT_DATA_STRINGS_METADATA,173174/**175* Subtitle event position176* @code177* u32le x1178* u32le y1179* u32le x2180* u32le y2181* @endcode182*/183AV_PKT_DATA_SUBTITLE_POSITION,184185/**186* Data found in BlockAdditional element of matroska container. There is187* no end marker for the data, so it is required to rely on the side data188* size to recognize the end. 8 byte id (as found in BlockAddId) followed189* by data.190*/191AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,192193/**194* The optional first identifier line of a WebVTT cue.195*/196AV_PKT_DATA_WEBVTT_IDENTIFIER,197198/**199* The optional settings (rendering instructions) that immediately200* follow the timestamp specifier of a WebVTT cue.201*/202AV_PKT_DATA_WEBVTT_SETTINGS,203204/**205* A list of zero terminated key/value strings. There is no end marker for206* the list, so it is required to rely on the side data size to stop. This207* side data includes updated metadata which appeared in the stream.208*/209AV_PKT_DATA_METADATA_UPDATE,210211/**212* MPEGTS stream ID as uint8_t, this is required to pass the stream ID213* information from the demuxer to the corresponding muxer.214*/215AV_PKT_DATA_MPEGTS_STREAM_ID,216217/**218* Mastering display metadata (based on SMPTE-2086:2014). This metadata219* should be associated with a video stream and contains data in the form220* of the AVMasteringDisplayMetadata struct.221*/222AV_PKT_DATA_MASTERING_DISPLAY_METADATA,223224/**225* This side data should be associated with a video stream and corresponds226* to the AVSphericalMapping structure.227*/228AV_PKT_DATA_SPHERICAL,229230/**231* Content light level (based on CTA-861.3). This metadata should be232* associated with a video stream and contains data in the form of the233* AVContentLightMetadata struct.234*/235AV_PKT_DATA_CONTENT_LIGHT_LEVEL,236237/**238* ATSC A53 Part 4 Closed Captions. This metadata should be associated with239* a video stream. A53 CC bitstream is stored as uint8_t in AVPacketSideData.data.240* The number of bytes of CC data is AVPacketSideData.size.241*/242AV_PKT_DATA_A53_CC,243244/**245* This side data is encryption initialization data.246* The format is not part of ABI, use av_encryption_init_info_* methods to247* access.248*/249AV_PKT_DATA_ENCRYPTION_INIT_INFO,250251/**252* This side data contains encryption info for how to decrypt the packet.253* The format is not part of ABI, use av_encryption_info_* methods to access.254*/255AV_PKT_DATA_ENCRYPTION_INFO,256257/**258* Active Format Description data consisting of a single byte as specified259* in ETSI TS 101 154 using AVActiveFormatDescription enum.260*/261AV_PKT_DATA_AFD,262263/**264* Producer Reference Time data corresponding to the AVProducerReferenceTime struct,265* usually exported by some encoders (on demand through the prft flag set in the266* AVCodecContext export_side_data field).267*/268AV_PKT_DATA_PRFT,269270/**271* ICC profile data consisting of an opaque octet buffer following the272* format described by ISO 15076-1.273*/274AV_PKT_DATA_ICC_PROFILE,275276/**277* DOVI configuration278* ref:279* dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2, section 2.2280* dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2, section 3.3281* Tags are stored in struct AVDOVIDecoderConfigurationRecord.282*/283AV_PKT_DATA_DOVI_CONF,284285/**286* Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t287* where the first uint32_t describes how many (1-3) of the other timecodes are used.288* The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()289* function in libavutil/timecode.h.290*/291AV_PKT_DATA_S12M_TIMECODE,292293/**294* HDR10+ dynamic metadata associated with a video frame. The metadata is in295* the form of the AVDynamicHDRPlus struct and contains296* information for color volume transform - application 4 of297* SMPTE 2094-40:2016 standard.298*/299AV_PKT_DATA_DYNAMIC_HDR10_PLUS,300301/**302* The number of side data types.303* This is not part of the public API/ABI in the sense that it may304* change when new side data types are added.305* This must stay the last enum value.306* If its value becomes huge, some code using it307* needs to be updated as it assumes it to be smaller than other limits.308*/309AV_PKT_DATA_NB310};311312#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED313314typedef struct AVPacketSideData {315uint8_t *data;316size_t size;317enum AVPacketSideDataType type;318} AVPacketSideData;319320/**321* This structure stores compressed data. It is typically exported by demuxers322* and then passed as input to decoders, or received as output from encoders and323* then passed to muxers.324*325* For video, it should typically contain one compressed frame. For audio it may326* contain several compressed frames. Encoders are allowed to output empty327* packets, with no compressed data, containing only side data328* (e.g. to update some stream parameters at the end of encoding).329*330* The semantics of data ownership depends on the buf field.331* If it is set, the packet data is dynamically allocated and is332* valid indefinitely until a call to av_packet_unref() reduces the333* reference count to 0.334*335* If the buf field is not set av_packet_ref() would make a copy instead336* of increasing the reference count.337*338* The side data is always allocated with av_malloc(), copied by339* av_packet_ref() and freed by av_packet_unref().340*341* sizeof(AVPacket) being a part of the public ABI is deprecated. once342* av_init_packet() is removed, new packets will only be able to be allocated343* with av_packet_alloc(), and new fields may be added to the end of the struct344* with a minor bump.345*346* @see av_packet_alloc347* @see av_packet_ref348* @see av_packet_unref349*/350typedef struct AVPacket {351/**352* A reference to the reference-counted buffer where the packet data is353* stored.354* May be NULL, then the packet data is not reference-counted.355*/356AVBufferRef *buf;357/**358* Presentation timestamp in AVStream->time_base units; the time at which359* the decompressed packet will be presented to the user.360* Can be AV_NOPTS_VALUE if it is not stored in the file.361* pts MUST be larger or equal to dts as presentation cannot happen before362* decompression, unless one wants to view hex dumps. Some formats misuse363* the terms dts and pts/cts to mean something different. Such timestamps364* must be converted to true pts/dts before they are stored in AVPacket.365*/366int64_t pts;367/**368* Decompression timestamp in AVStream->time_base units; the time at which369* the packet is decompressed.370* Can be AV_NOPTS_VALUE if it is not stored in the file.371*/372int64_t dts;373uint8_t *data;374int size;375int stream_index;376/**377* A combination of AV_PKT_FLAG values378*/379int flags;380/**381* Additional packet data that can be provided by the container.382* Packet can contain several types of side information.383*/384AVPacketSideData *side_data;385int side_data_elems;386387/**388* Duration of this packet in AVStream->time_base units, 0 if unknown.389* Equals next_pts - this_pts in presentation order.390*/391int64_t duration;392393int64_t pos; ///< byte position in stream, -1 if unknown394395/**396* for some private data of the user397*/398void *opaque;399400/**401* AVBufferRef for free use by the API user. FFmpeg will never check the402* contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when403* the packet is unreferenced. av_packet_copy_props() calls create a new404* reference with av_buffer_ref() for the target packet's opaque_ref field.405*406* This is unrelated to the opaque field, although it serves a similar407* purpose.408*/409AVBufferRef *opaque_ref;410411/**412* Time base of the packet's timestamps.413* In the future, this field may be set on packets output by encoders or414* demuxers, but its value will be by default ignored on input to decoders415* or muxers.416*/417AVRational time_base;418} AVPacket;419420#if FF_API_INIT_PACKET421attribute_deprecated422typedef struct AVPacketList {423AVPacket pkt;424struct AVPacketList *next;425} AVPacketList;426#endif427428#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe429#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted430/**431* Flag is used to discard packets which are required to maintain valid432* decoder state but are not required for output and should be dropped433* after decoding.434**/435#define AV_PKT_FLAG_DISCARD 0x0004436/**437* The packet comes from a trusted source.438*439* Otherwise-unsafe constructs such as arbitrary pointers to data440* outside the packet may be followed.441*/442#define AV_PKT_FLAG_TRUSTED 0x0008443/**444* Flag is used to indicate packets that contain frames that can445* be discarded by the decoder. I.e. Non-reference frames.446*/447#define AV_PKT_FLAG_DISPOSABLE 0x0010448449enum AVSideDataParamChangeFlags {450#if FF_API_OLD_CHANNEL_LAYOUT451/**452* @deprecated those are not used by any decoder453*/454AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,455AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,456#endif457AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,458AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,459};460461/**462* Allocate an AVPacket and set its fields to default values. The resulting463* struct must be freed using av_packet_free().464*465* @return An AVPacket filled with default values or NULL on failure.466*467* @note this only allocates the AVPacket itself, not the data buffers. Those468* must be allocated through other means such as av_new_packet.469*470* @see av_new_packet471*/472AVPacket *av_packet_alloc(void);473474/**475* Create a new packet that references the same data as src.476*477* This is a shortcut for av_packet_alloc()+av_packet_ref().478*479* @return newly created AVPacket on success, NULL on error.480*481* @see av_packet_alloc482* @see av_packet_ref483*/484AVPacket *av_packet_clone(const AVPacket *src);485486/**487* Free the packet, if the packet is reference counted, it will be488* unreferenced first.489*490* @param pkt packet to be freed. The pointer will be set to NULL.491* @note passing NULL is a no-op.492*/493void av_packet_free(AVPacket **pkt);494495#if FF_API_INIT_PACKET496/**497* Initialize optional fields of a packet with default values.498*499* Note, this does not touch the data and size members, which have to be500* initialized separately.501*502* @param pkt packet503*504* @see av_packet_alloc505* @see av_packet_unref506*507* @deprecated This function is deprecated. Once it's removed,508sizeof(AVPacket) will not be a part of the ABI anymore.509*/510attribute_deprecated511void av_init_packet(AVPacket *pkt);512#endif513514/**515* Allocate the payload of a packet and initialize its fields with516* default values.517*518* @param pkt packet519* @param size wanted payload size520* @return 0 if OK, AVERROR_xxx otherwise521*/522int av_new_packet(AVPacket *pkt, int size);523524/**525* Reduce packet size, correctly zeroing padding526*527* @param pkt packet528* @param size new size529*/530void av_shrink_packet(AVPacket *pkt, int size);531532/**533* Increase packet size, correctly zeroing padding534*535* @param pkt packet536* @param grow_by number of bytes by which to increase the size of the packet537*/538int av_grow_packet(AVPacket *pkt, int grow_by);539540/**541* Initialize a reference-counted packet from av_malloc()ed data.542*543* @param pkt packet to be initialized. This function will set the data, size,544* and buf fields, all others are left untouched.545* @param data Data allocated by av_malloc() to be used as packet data. If this546* function returns successfully, the data is owned by the underlying AVBuffer.547* The caller may not access the data through other means.548* @param size size of data in bytes, without the padding. I.e. the full buffer549* size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.550*551* @return 0 on success, a negative AVERROR on error552*/553int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);554555/**556* Allocate new information of a packet.557*558* @param pkt packet559* @param type side information type560* @param size side information size561* @return pointer to fresh allocated data or NULL otherwise562*/563uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,564size_t size);565566/**567* Wrap an existing array as a packet side data.568*569* @param pkt packet570* @param type side information type571* @param data the side data array. It must be allocated with the av_malloc()572* family of functions. The ownership of the data is transferred to573* pkt.574* @param size side information size575* @return a non-negative number on success, a negative AVERROR code on576* failure. On failure, the packet is unchanged and the data remains577* owned by the caller.578*/579int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,580uint8_t *data, size_t size);581582/**583* Shrink the already allocated side data buffer584*585* @param pkt packet586* @param type side information type587* @param size new side information size588* @return 0 on success, < 0 on failure589*/590int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,591size_t size);592593/**594* Get side information from packet.595*596* @param pkt packet597* @param type desired side information type598* @param size If supplied, *size will be set to the size of the side data599* or to zero if the desired side data is not present.600* @return pointer to data if present or NULL otherwise601*/602uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type,603size_t *size);604605const char *av_packet_side_data_name(enum AVPacketSideDataType type);606607/**608* Pack a dictionary for use in side_data.609*610* @param dict The dictionary to pack.611* @param size pointer to store the size of the returned data612* @return pointer to data if successful, NULL otherwise613*/614uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size);615/**616* Unpack a dictionary from side_data.617*618* @param data data from side_data619* @param size size of the data620* @param dict the metadata storage dictionary621* @return 0 on success, < 0 on failure622*/623int av_packet_unpack_dictionary(const uint8_t *data, size_t size,624AVDictionary **dict);625626/**627* Convenience function to free all the side data stored.628* All the other fields stay untouched.629*630* @param pkt packet631*/632void av_packet_free_side_data(AVPacket *pkt);633634/**635* Setup a new reference to the data described by a given packet636*637* If src is reference-counted, setup dst as a new reference to the638* buffer in src. Otherwise allocate a new buffer in dst and copy the639* data from src into it.640*641* All the other fields are copied from src.642*643* @see av_packet_unref644*645* @param dst Destination packet. Will be completely overwritten.646* @param src Source packet647*648* @return 0 on success, a negative AVERROR on error. On error, dst649* will be blank (as if returned by av_packet_alloc()).650*/651int av_packet_ref(AVPacket *dst, const AVPacket *src);652653/**654* Wipe the packet.655*656* Unreference the buffer referenced by the packet and reset the657* remaining packet fields to their default values.658*659* @param pkt The packet to be unreferenced.660*/661void av_packet_unref(AVPacket *pkt);662663/**664* Move every field in src to dst and reset src.665*666* @see av_packet_unref667*668* @param src Source packet, will be reset669* @param dst Destination packet670*/671void av_packet_move_ref(AVPacket *dst, AVPacket *src);672673/**674* Copy only "properties" fields from src to dst.675*676* Properties for the purpose of this function are all the fields677* beside those related to the packet data (buf, data, size)678*679* @param dst Destination packet680* @param src Source packet681*682* @return 0 on success AVERROR on failure.683*/684int av_packet_copy_props(AVPacket *dst, const AVPacket *src);685686/**687* Ensure the data described by a given packet is reference counted.688*689* @note This function does not ensure that the reference will be writable.690* Use av_packet_make_writable instead for that purpose.691*692* @see av_packet_ref693* @see av_packet_make_writable694*695* @param pkt packet whose data should be made reference counted.696*697* @return 0 on success, a negative AVERROR on error. On failure, the698* packet is unchanged.699*/700int av_packet_make_refcounted(AVPacket *pkt);701702/**703* Create a writable reference for the data described by a given packet,704* avoiding data copy if possible.705*706* @param pkt Packet whose data should be made writable.707*708* @return 0 on success, a negative AVERROR on failure. On failure, the709* packet is unchanged.710*/711int av_packet_make_writable(AVPacket *pkt);712713/**714* Convert valid timing fields (timestamps / durations) in a packet from one715* timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be716* ignored.717*718* @param pkt packet on which the conversion will be performed719* @param tb_src source timebase, in which the timing fields in pkt are720* expressed721* @param tb_dst destination timebase, to which the timing fields will be722* converted723*/724void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);725726/**727* @}728*/729730#endif // AVCODEC_PACKET_H731732733