FFmpeg
Loading...
Searching...
No Matches
hw_base_encode.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_HW_BASE_ENCODE_H
20#define AVCODEC_HW_BASE_ENCODE_H
21
22#include "avcodec.h"
23#include "libavutil/hwcontext.h"
24#include "libavutil/fifo.h"
25
26#define MAX_DPB_SIZE 16
27#define MAX_PICTURE_REFERENCES 2
28#define MAX_REORDER_DELAY 16
29#define MAX_ASYNC_DEPTH 64
30#define MAX_REFERENCE_LIST_NUM 2
31
32static inline const char *ff_hw_base_encode_get_pictype_name(const int type)
33{
34 const char * const picture_type_name[] = { "IDR", "I", "P", "B" };
35 return picture_type_name[type];
36}
37
38enum {
43};
44
45enum {
46 // Codec supports controlling the subdivision of pictures into slices.
48 // Codec only supports constant quality (no rate control).
50 // Codec is intra-only.
52 // Codec supports B-pictures.
54 // Codec supports referencing B-pictures.
56 // Codec supports non-IDR key pictures (that is, key pictures do
57 // not necessarily empty the DPB).
59 // Output is in display order; set DTS = PTS on every packet
60 // (e.g. AV1 hidden anchor frames with show_existing_frame).
62};
63
64typedef struct FFHWBaseEncodePicture {
65 // API-specific private data
66 void *priv;
67 // Codec-specific private data
69
71
77
78 void *opaque;
80
81 int type;
85
88
89 // Whether this picture is a reference picture.
91
92 // The contents of the DPB after this picture has been decoded.
93 // This will contain the picture itself if it is a reference picture,
94 // but not if it isn't.
97 // The reference pictures used in decoding this picture. If they are
98 // used by later pictures they will also appear in the DPB. ref[0][] for
99 // previous reference frames. ref[1][] for future reference frames.
102 // The previous reference picture in encode order. Must be in at least
103 // one of the reference list and DPB list.
105 // Reference count for other pictures referring to this one through
106 // the above pointers, directly from incomplete pictures and indirectly
107 // through completed pictures.
108 int ref_count[2];
111
113 // Size of API-specific internal picture data
114 size_t priv_size;
115 // Initialize API-specific internals
117 // Issue the picture structure, which will send the frame surface to HW Encode API.
119 // Get the output AVPacket.
121 // Free the picture structure.
124
125typedef struct FFHWBaseEncodeContext {
126 const AVClass *class;
127 void *log_ctx;
128
129 // Hardware-specific hooks.
131
132 // Global options.
133
134 // Number of I frames between IDR frames.
136
137 // Desired B frame reference depth.
139
140 // The required size of surfaces. This is probably the input
141 // size (AVCodecContext.width|height) aligned up to whatever
142 // block size is required by the codec.
145
146 // The block size for slice calculations.
149
150 // The hardware device context.
153
154 // The hardware frame context containing the input frames.
157
158 // The hardware frame context containing the reconstructed frames.
161
162 /* Allocates a reconstruction frame; used instead of recon_frames_ref */
164
165 // Current encoding window, in display (input) order.
167 // The next picture to use as the previous reference picture in
168 // encoding order. Order from small to large in encoding order.
171
172 // Next input order index (display order).
174 // Number of frames that output is behind input.
176 // Next encode order index.
178 // Number of frames decode output will need to be delayed.
180 // Next output order index (in encode order).
182
183 // Timestamp handling.
188
189 // Frame type decision.
201
202 // The number of L0/L1 references supported by the driver.
205
206 // Whether the driver supports ROI at all.
208
209 // The encoder does not support cropping information, so warn about
210 // it the first time we encounter any nonzero crop fields.
212 // If the driver does not support ROI then warn the first time we
213 // encounter a frame with ROI side data.
215
216 // The frame to be filled with data.
218
219 // Whether the HW supports sync buffer function.
220 // If supported, encode_fifo/async_depth will be used together.
221 // Used for output buffer synchronization.
223
224 // Store buffered pic.
226 // Max number of frame buffered in encoder.
228
229 /** Tail data of a pic, now only used for av1 repeat frame header. */
232
234 FFHWBaseEncodePicture *pic, AVPacket *pkt, int flag_no_delay);
235
237
239 uint32_t ref_l0, uint32_t ref_l1,
240 int flags, int prediction_pre_only);
241
242int ff_hw_base_get_recon_format(FFHWBaseEncodeContext *ctx, const void *hwconfig,
243 enum AVPixelFormat *fmt);
244
246
248
249#define HW_BASE_ENCODE_COMMON_OPTIONS \
250 { "idr_interval", \
251 "Distance (in I-frames) between key frames", \
252 OFFSET(common.base.idr_interval), AV_OPT_TYPE_INT, \
253 { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
254 { "b_depth", \
255 "Maximum B-frame reference depth", \
256 OFFSET(common.base.desired_b_depth), AV_OPT_TYPE_INT, \
257 { .i64 = 1 }, 1, INT_MAX, FLAGS }, \
258 { "async_depth", "Maximum processing parallelism. " \
259 "Increase this to improve single channel performance.", \
260 OFFSET(common.base.async_depth), AV_OPT_TYPE_INT, \
261 { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }
262
263#endif /* AVCODEC_HW_BASE_ENCODE_H */
static AVFormatContext * ctx
Libavcodec external API header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
A generic FIFO API.
#define MAX_REORDER_DELAY
int ff_hw_base_encode_receive_packet(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, AVPacket *pkt)
#define MAX_PICTURE_REFERENCES
#define MAX_DPB_SIZE
int ff_hw_base_encode_set_output_property(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, FFHWBaseEncodePicture *pic, AVPacket *pkt, int flag_no_delay)
@ FF_HW_FLAG_SLICE_CONTROL
@ FF_HW_FLAG_CONSTANT_QUALITY_ONLY
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_TIMESTAMP_NO_DELAY
@ FF_HW_FLAG_B_PICTURES
@ FF_HW_FLAG_INTRA_ONLY
@ FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_IDR
int ff_hw_base_encode_init(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx)
int ff_hw_base_init_gop_structure(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, uint32_t ref_l0, uint32_t ref_l1, int flags, int prediction_pre_only)
int ff_hw_base_get_recon_format(FFHWBaseEncodeContext *ctx, const void *hwconfig, enum AVPixelFormat *fmt)
#define MAX_REFERENCE_LIST_NUM
#define MAX_ASYNC_DEPTH
static const char * ff_hw_base_encode_get_pictype_name(const int type)
int ff_hw_base_encode_close(FFHWBaseEncodeContext *ctx)
cl_device_type type
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
Definition fifo.c:35
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
This structure stores compressed data.
Definition packet.h:580
AVBufferRef * input_frames_ref
AVBufferRef * recon_frames_ref
int64_t ts_ring[MAX_REORDER_DELAY *3+MAX_ASYNC_DEPTH]
AVHWFramesContext * input_frames
FFHWBaseEncodePicture * next_prev[MAX_PICTURE_REFERENCES]
AVHWDeviceContext * device
FFHWBaseEncodePicture * pic_end
int(* get_recon_frame)(AVCodecContext *avctx, AVFrame *frame)
const struct FFHWEncodePictureOperation * op
AVPacket * tail_pkt
Tail data of a pic, now only used for av1 repeat frame header.
FFHWBaseEncodePicture * pic_start
AVHWFramesContext * recon_frames
struct FFHWBaseEncodePicture * dpb[MAX_DPB_SIZE]
struct FFHWBaseEncodePicture * prev
struct FFHWBaseEncodePicture * next
AVBufferRef * opaque_ref
int nb_refs[MAX_REFERENCE_LIST_NUM]
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
int(* output)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, AVPacket *pkt)
int(* issue)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
int(* free)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
int(* init)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)