FFmpeg
Loading...
Searching...
No Matches
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 */
33typedef 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);
45 void *post_process_opaque; ///< RefStruct reference
46
47 /**
48 * Per-frame private data for hwaccels.
49 *
50 * Same as @ref post_process, but used only by some hwaccels to retrieve or
51 * finalize frames, and executed first.
52 */
53 int (*hwaccel_priv_post_process)(void *logctx, AVFrame *frame);
55 void (*hwaccel_priv_free)(void *priv);
57
58/**
59 * Called by decoders to get the next packet for decoding.
60 *
61 * @param pkt An empty packet to be filled with data.
62 * @return 0 if a new reference has been successfully written to pkt
63 * AVERROR(EAGAIN) if no data is currently available
64 * AVERROR_EOF if and end of stream has been reached, so no more data
65 * will be available
66 */
68
69/**
70 * Set various frame properties from the provided packet.
71 */
73 AVFrame *frame, const AVPacket *pkt);
74
75/**
76 * Set various frame properties from the codec context / packet data.
77 */
79
80static inline int ff_decode_skip_all_pixels(const AVCodecContext *avctx)
81{
82 return avctx->skip_pred >= AVDISCARD_ALL &&
83 avctx->skip_idct >= AVDISCARD_ALL &&
84 !avctx->err_recognition &&
85 !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) &&
88 !(avctx->debug & (FF_DEBUG_QP | FF_DEBUG_MB_TYPE));
89}
90
91/**
92 * Make sure avctx.hw_frames_ctx is set. If it's not set, the function will
93 * try to allocate it from hw_device_ctx. If that is not possible, an error
94 * message is printed, and an error code is returned.
95 */
97 enum AVHWDeviceType dev_type);
98
100
101/**
102 * Check whether the side-data of src contains a palette of
103 * size AVPALETTE_SIZE; if so, copy it to dst and return 1;
104 * else return 0.
105 * Also emit an error message upon encountering a palette
106 * with invalid size.
107 */
108int ff_copy_palette(void *dst, const AVPacket *src, void *logctx);
109
110/*
111 * Validate and set video frame dimensions on AVCodecContext.
112 *
113 * Dimensions accepted here satisfy FFmpeg's generic image-size validation
114 * (see av_image_check_size2()). Decoder code normally should not duplicate
115 * generic width/height overflow checks before ff_get_buffer(); add local
116 * checks only for codec-specific derived sizes or complexity bounds.
117 */
119
120/**
121 * Check that the provided sample aspect ratio is valid and set it on the codec
122 * context.
123 */
124int ff_set_sar(AVCodecContext *avctx, AVRational sar);
125
126/**
127 * Select the (possibly hardware accelerated) pixel format.
128 * This is a wrapper around AVCodecContext.get_format() and should be used
129 * instead of calling get_format() directly.
130 *
131 * The list of pixel formats must contain at least one valid entry, and is
132 * terminated with AV_PIX_FMT_NONE. If it is possible to decode to software,
133 * the first entry after the last hwaccel one in the list must be the most
134 * accurate software format, followed by less accurate ones in order of
135 * preference.
136 * If it is not possible to decode to software, AVCodecContext.sw_pix_fmt
137 * must be set before calling this function.
138 */
139int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt);
140
141/**
142 * Get a buffer for a frame. This is a wrapper around
143 * AVCodecContext.get_buffer() and should be used instead calling get_buffer()
144 * directly.
145 */
147
148#define FF_REGET_BUFFER_FLAG_READONLY 1 ///< the returned buffer does not need to be writable
149/**
150 * Identical in function to ff_get_buffer(), except it reuses the existing buffer
151 * if available.
152 */
154
155/**
156 * Add or update AV_FRAME_DATA_MATRIXENCODING side data.
157 */
159 enum AVMatrixEncoding matrix_encoding);
160
161/**
162 * Allocate a hwaccel frame private data if the provided avctx
163 * uses a hwaccel method that needs it. The returned data is
164 * a RefStruct reference (if allocated).
165 *
166 * @param avctx The codec context
167 * @param hwaccel_picture_private Pointer to return hwaccel_picture_private
168 * @return 0 on success, < 0 on error
169 */
170int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private);
171
172/**
173 * Get side data of the given type from a decoding context.
174 */
177
178/**
179 * Wrapper around av_frame_new_side_data, which rejects side data overridden by
180 * the demuxer. Returns 0 on success, and a negative error code otherwise.
181 * If successful and sd is not NULL, *sd may either contain a pointer to the new
182 * side data, or NULL in case the side data was already present.
183 */
185 enum AVFrameSideDataType type, size_t size,
186 AVFrameSideData **sd);
187
188/**
189 * Similar to `ff_frame_new_side_data`, but using an existing buffer ref.
190 *
191 * *buf is ALWAYS consumed by this function and NULL written in its place, even
192 * on failure.
193 */
196 AVBufferRef **buf);
197
198/**
199 * Same as `ff_frame_new_side_data_from_buf`, but taking a AVFrameSideData
200 * array directly instead of an AVFrame.
201 */
203 AVFrameSideData ***sd, int *nb_sd,
205 AVBufferRef **buf);
206
209
210/**
211 * Wrapper around av_mastering_display_metadata_create_side_data(), which
212 * rejects side data overridden by the demuxer. Returns 0 on success, and a
213 * negative error code otherwise. If successful, *mdm may either be a pointer to
214 * the new side data, or NULL in case the side data was already present.
215 */
217 struct AVMasteringDisplayMetadata **mdm);
218
219/**
220 * Same as `ff_decode_mastering_display_new`, but taking a AVFrameSideData
221 * array directly instead of an AVFrame.
222 */
224 AVFrameSideData ***sd, int *nb_sd,
225 struct AVMasteringDisplayMetadata **mdm);
226
227/**
228 * Wrapper around av_content_light_metadata_create_side_data(), which
229 * rejects side data overridden by the demuxer. Returns 0 on success, and a
230 * negative error code otherwise. If successful, *clm may either be a pointer to
231 * the new side data, or NULL in case the side data was already present.
232 */
234 struct AVContentLightMetadata **clm);
235
236/**
237 * Same as `ff_decode_content_light_new`, but taking a AVFrameSideData
238 * array directly instead of an AVFrame.
239 */
241 AVFrameSideData ***sd, int *nb_sd,
242 struct AVContentLightMetadata **clm);
243
244#endif /* AVCODEC_DECODE_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
Libavcodec external API header.
#define FF_DEBUG_QP
Definition avcodec.h:1398
#define FF_DEBUG_MB_TYPE
Definition avcodec.h:1397
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1781
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
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:2226
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:2188
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition decode.c:1602
static int ff_decode_skip_all_pixels(const AVCodecContext *avctx)
Definition decode.h:80
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:1910
int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:1708
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:2207
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:1382
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:2267
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
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition decode.c:254
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition decode.c:1233
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:2235
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:2325
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:1554
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:2340
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:2312
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
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:2280
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
Definition decode.c:1073
static AVPacket * pkt
static AVFrame * frame
reference-counted frame API
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
Definition avcodec.h:351
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition avcodec.h:390
#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
Decoding only.
Definition avcodec.h:399
@ AVDISCARD_ALL
discard all
Definition defs.h:246
AVPacketSideDataType
Definition packet.h:41
AVMatrixEncoding
AVFrameSideDataType
Definition frame.h:49
AVHWDeviceType
Definition hwcontext.h:27
uint32_t type
Definition jpegmpfenc.c:80
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
int flags2
AV_CODEC_FLAG2_*.
Definition avcodec.h:507
int debug
debug
Definition avcodec.h:1393
enum AVDiscard skip_pred
Skip prediction (intra prediction and motion compensation) for selected frames.
Definition avcodec.h:1952
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition avcodec.h:1784
enum AVDiscard skip_idct
Skip IDCT/dequantization for selected frames.
Definition avcodec.h:1665
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition avcodec.h:1417
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Structure to hold side data for an AVFrame.
Definition frame.h:334
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
Mastering display metadata capable of representing the color volume of the display used to master the...
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:424
This structure stores compressed data.
Definition packet.h:580
Rational number (pair of numerator and denominator).
Definition rational.h:58
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition decode.h:33
void(* hwaccel_priv_free)(void *priv)
Definition decode.h:55
int(* hwaccel_priv_post_process)(void *logctx, AVFrame *frame)
Per-frame private data for hwaccels.
Definition decode.h:53
void * post_process_opaque
RefStruct reference.
Definition decode.h:45
void * hwaccel_priv
Definition decode.h:54
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
#define src
Definition vp8dsp.c:248
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
int size