FFmpeg
decode.h
Go to the documentation of this file.
1 /*
2  * generic decoding-related code
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_DECODE_H
22 #define AVCODEC_DECODE_H
23 
24 #include "libavutil/frame.h"
25 #include "libavutil/hwcontext.h"
26 
27 #include "avcodec.h"
28 
29 /**
30  * This struct stores per-frame lavc-internal data and is attached to it via
31  * private_ref.
32  */
33 typedef struct FrameDecodeData {
34  /**
35  * The callback to perform some delayed processing on the frame right
36  * before it is returned to the caller.
37  *
38  * @note This code is called at some unspecified point after the frame is
39  * returned from the decoder's decode/receive_frame call. Therefore it cannot rely
40  * on AVCodecContext being in any specific state, so it does not get to
41  * access AVCodecContext directly at all. All the state it needs must be
42  * stored in the post_process_opaque object.
43  */
44  int (*post_process)(void *logctx, AVFrame *frame);
46  void (*post_process_opaque_free)(void *opaque);
47 
48  /**
49  * Per-frame private data for hwaccels.
50  *
51  * Same as @ref post_process, but used only by some hwaccels to retrieve or
52  * finalize frames, and executed first.
53  */
54  int (*hwaccel_priv_post_process)(void *logctx, AVFrame *frame);
55  void *hwaccel_priv;
56  void (*hwaccel_priv_free)(void *priv);
58 
59 /**
60  * Called by decoders to get the next packet for decoding.
61  *
62  * @param pkt An empty packet to be filled with data.
63  * @return 0 if a new reference has been successfully written to pkt
64  * AVERROR(EAGAIN) if no data is currently available
65  * AVERROR_EOF if and end of stream has been reached, so no more data
66  * will be available
67  */
69 
70 /**
71  * Set various frame properties from the provided packet.
72  */
74  AVFrame *frame, const AVPacket *pkt);
75 
76 /**
77  * Set various frame properties from the codec context / packet data.
78  */
80 
81 /**
82  * Make sure avctx.hw_frames_ctx is set. If it's not set, the function will
83  * try to allocate it from hw_device_ctx. If that is not possible, an error
84  * message is printed, and an error code is returned.
85  */
87  enum AVHWDeviceType dev_type);
88 
90 
91 /**
92  * Check whether the side-data of src contains a palette of
93  * size AVPALETTE_SIZE; if so, copy it to dst and return 1;
94  * else return 0.
95  * Also emit an error message upon encountering a palette
96  * with invalid size.
97  */
98 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx);
99 
100 /**
101  * Check that the provided frame dimensions are valid and set them on the codec
102  * context.
103  */
105 
106 /**
107  * Check that the provided sample aspect ratio is valid and set it on the codec
108  * context.
109  */
110 int ff_set_sar(AVCodecContext *avctx, AVRational sar);
111 
112 /**
113  * Select the (possibly hardware accelerated) pixel format.
114  * This is a wrapper around AVCodecContext.get_format() and should be used
115  * instead of calling get_format() directly.
116  *
117  * The list of pixel formats must contain at least one valid entry, and is
118  * terminated with AV_PIX_FMT_NONE. If it is possible to decode to software,
119  * the first entry after the last hwaccel one in the list must be the most
120  * accurate software format, followed by less accurate ones in order of
121  * preference.
122  * If it is not possible to decode to software, AVCodecContext.sw_pix_fmt
123  * must be set before calling this function.
124  */
125 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt);
126 
127 /**
128  * Get a buffer for a frame. This is a wrapper around
129  * AVCodecContext.get_buffer() and should be used instead calling get_buffer()
130  * directly.
131  */
132 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
133 
134 #define FF_REGET_BUFFER_FLAG_READONLY 1 ///< the returned buffer does not need to be writable
135 /**
136  * Identical in function to ff_get_buffer(), except it reuses the existing buffer
137  * if available.
138  */
140 
141 /**
142  * Add or update AV_FRAME_DATA_MATRIXENCODING side data.
143  */
145  enum AVMatrixEncoding matrix_encoding);
146 
147 /**
148  * Allocate a hwaccel frame private data if the provided avctx
149  * uses a hwaccel method that needs it. The returned data is
150  * a RefStruct reference (if allocated).
151  *
152  * @param avctx The codec context
153  * @param hwaccel_picture_private Pointer to return hwaccel_picture_private
154  * @return 0 on success, < 0 on error
155  */
156 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private);
157 
158 /**
159  * Get side data of the given type from a decoding context.
160  */
163 
164 /**
165  * Wrapper around av_frame_new_side_data, which rejects side data overridden by
166  * the demuxer. Returns 0 on success, and a negative error code otherwise.
167  * If successful and sd is not NULL, *sd may either contain a pointer to the new
168  * side data, or NULL in case the side data was already present.
169  */
171  enum AVFrameSideDataType type, size_t size,
172  AVFrameSideData **sd);
173 
174 /**
175  * Similar to `ff_frame_new_side_data`, but using an existing buffer ref.
176  *
177  * *buf is ALWAYS consumed by this function and NULL written in its place, even
178  * on failure.
179  */
182  AVBufferRef **buf);
183 
184 /**
185  * Same as `ff_frame_new_side_data_from_buf`, but taking a AVFrameSideData
186  * array directly instead of an AVFrame.
187  */
189  AVFrameSideData ***sd, int *nb_sd,
191  AVBufferRef **buf);
192 
195 
196 /**
197  * Wrapper around av_mastering_display_metadata_create_side_data(), which
198  * rejects side data overridden by the demuxer. Returns 0 on success, and a
199  * negative error code otherwise. If successful, *mdm may either be a pointer to
200  * the new side data, or NULL in case the side data was already present.
201  */
203  struct AVMasteringDisplayMetadata **mdm);
204 
205 /**
206  * Same as `ff_decode_mastering_display_new`, but taking a AVFrameSideData
207  * array directly instead of an AVFrame.
208  */
210  AVFrameSideData ***sd, int *nb_sd,
211  struct AVMasteringDisplayMetadata **mdm);
212 
213 /**
214  * Wrapper around av_content_light_metadata_create_side_data(), which
215  * rejects side data overridden by the demuxer. Returns 0 on success, and a
216  * negative error code otherwise. If successful, *clm may either be a pointer to
217  * the new side data, or NULL in case the side data was already present.
218  */
220  struct AVContentLightMetadata **clm);
221 
222 /**
223  * Same as `ff_decode_content_light_new`, but taking a AVFrameSideData
224  * array directly instead of an AVFrame.
225  */
227  AVFrameSideData ***sd, int *nb_sd,
228  struct AVContentLightMetadata **clm);
229 
230 enum AVExifHeaderMode;
231 
232 /**
233  * Attach the data buffer to the frame. This is mostly a wrapper for
234  * av_side_data_new_from_buffer, but it checks if the orientation tag is
235  * present in the provided EXIF buffer. If it is, it zeroes it out and
236  * attaches that information as an AV_FRAME_DATA_DISPLAYMATRIX instead
237  * of including it in the AV_FRAME_DATA_EXIF side data buffer.
238  *
239  * *buf is ALWAYS consumed by this function and NULL written in its place, even
240  * on failure.
241  */
243  enum AVExifHeaderMode header_mode);
244 
245 struct AVExifMetadata;
246 
247 /**
248  * Attach an already-parsed EXIF metadata struct to the frame as a side data
249  * buffer. It writes the EXIF IFD into the buffer and attaches the buffer to
250  * the frame.
251  *
252  * If the metadata struct contains an orientation tag, it will be zeroed before
253  * writing, and instead, an AV_FRAME_DATA_DISPLAYMATRIX will be attached in
254  * addition to the AV_FRAME_DATA_EXIF side data.
255  */
257  const struct AVExifMetadata *ifd);
258 
259 #endif /* AVCODEC_DECODE_H */
flags
const SwsFlags flags[]
Definition: swscale.c:71
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1218
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_hwaccel_frame_priv_alloc
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition: decode.c:2309
AVExifMetadata
Definition: exif.h:76
AVExifHeaderMode
AVExifHeaderMode
Definition: exif.h:58
FrameDecodeData
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:33
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:409
ff_decode_exif_attach_buffer
int ff_decode_exif_attach_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferRef **buf, enum AVExifHeaderMode header_mode)
Attach the data buffer to the frame.
Definition: decode.c:2468
ff_decode_exif_attach_ifd
int ff_decode_exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const struct AVExifMetadata *ifd)
Attach an already-parsed EXIF metadata struct to the frame as a side data buffer.
FrameDecodeData::hwaccel_priv_free
void(* hwaccel_priv_free)(void *priv)
Definition: decode.h:56
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:91
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
FrameDecodeData::post_process_opaque_free
void(* post_process_opaque_free)(void *opaque)
Definition: decode.h:46
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AVFrameSideDataType
AVFrameSideDataType
Definition: frame.h:49
ff_decode_frame_props
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: decode.c:1581
ff_side_data_update_matrix_encoding
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
Definition: utils.c:121
ff_frame_new_side_data_from_buf
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition: decode.c:2195
FrameDecodeData::hwaccel_priv_post_process
int(* hwaccel_priv_post_process)(void *logctx, AVFrame *frame)
Per-frame private data for hwaccels.
Definition: decode.h:54
s
#define s(width, name)
Definition: cbs_vp9.c:198
FrameDecodeData::post_process_opaque
void * post_process_opaque
Definition: decode.h:45
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
ff_decode_frame_props_from_pkt
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
Set various frame properties from the provided packet.
Definition: decode.c:1539
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1764
AVMatrixEncoding
AVMatrixEncoding
Definition: channel_layout.h:260
ff_frame_new_side_data_from_buf_ext
int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf)
Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AV...
Definition: decode.c:2176
ff_decode_get_hw_frames_ctx
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
Definition: decode.c:1058
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_set_sar
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:106
ff_decode_mastering_display_new
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, struct AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition: decode.c:2236
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:251
ff_decode_content_light_new
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, struct AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition: decode.c:2281
height
#define height
Definition: dsp.h:89
FrameDecodeData::post_process
int(* post_process)(void *logctx, AVFrame *frame)
The callback to perform some delayed processing on the frame right before it is returned to the calle...
Definition: decode.h:44
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
size
int size
Definition: twinvq_data.h:10344
frame.h
ff_reget_buffer
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
Definition: decode.c:1879
ff_copy_palette
int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
Check whether the side-data of src contains a palette of size AVPALETTE_SIZE; if so,...
Definition: decode.c:2294
ff_decode_content_light_new_ext
int ff_decode_content_light_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, struct AVContentLightMetadata **clm)
Same as ff_decode_content_light_new, but taking a AVFrameSideData array directly instead of an AVFram...
Definition: decode.c:2249
ff_get_coded_side_data
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
Definition: decode.c:1367
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
ff_attach_decode_data
int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1685
avcodec.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AVCodecContext
main external API structure.
Definition: avcodec.h:439
ff_decode_mastering_display_new_ext
int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, struct AVMasteringDisplayMetadata **mdm)
Same as ff_decode_mastering_display_new, but taking a AVFrameSideData array directly instead of an AV...
Definition: decode.c:2204
ff_frame_new_side_data
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **sd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
Definition: decode.c:2157
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:282
AVPacket
This structure stores compressed data.
Definition: packet.h:565
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Definition: decode.h:55
hwcontext.h
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
width
#define width
Definition: dsp.h:89
src
#define src
Definition: vp8dsp.c:248