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};
60
61typedef struct FFHWBaseEncodePicture {
62 // API-specific private data
63 void *priv;
64 // Codec-specific private data
66
68
74
75 void *opaque;
77
78 int type;
82
85
86 // Whether this picture is a reference picture.
88
89 // The contents of the DPB after this picture has been decoded.
90 // This will contain the picture itself if it is a reference picture,
91 // but not if it isn't.
94 // The reference pictures used in decoding this picture. If they are
95 // used by later pictures they will also appear in the DPB. ref[0][] for
96 // previous reference frames. ref[1][] for future reference frames.
99 // The previous reference picture in encode order. Must be in at least
100 // one of the reference list and DPB list.
102 // Reference count for other pictures referring to this one through
103 // the above pointers, directly from incomplete pictures and indirectly
104 // through completed pictures.
105 int ref_count[2];
108
110 // Size of API-specific internal picture data
111 size_t priv_size;
112 // Initialize API-specific internals
114 // Issue the picture structure, which will send the frame surface to HW Encode API.
116 // Get the output AVPacket.
118 // Free the picture structure.
121
122typedef struct FFHWBaseEncodeContext {
123 const AVClass *class;
124 void *log_ctx;
125
126 // Hardware-specific hooks.
128
129 // Global options.
130
131 // Number of I frames between IDR frames.
133
134 // Desired B frame reference depth.
136
137 // The required size of surfaces. This is probably the input
138 // size (AVCodecContext.width|height) aligned up to whatever
139 // block size is required by the codec.
142
143 // The block size for slice calculations.
146
147 // The hardware device context.
150
151 // The hardware frame context containing the input frames.
154
155 // The hardware frame context containing the reconstructed frames.
158
159 /* Allocates a reconstruction frame; used instead of recon_frames_ref */
161
162 // Current encoding window, in display (input) order.
164 // The next picture to use as the previous reference picture in
165 // encoding order. Order from small to large in encoding order.
168
169 // Next input order index (display order).
171 // Number of frames that output is behind input.
173 // Next encode order index.
175 // Number of frames decode output will need to be delayed.
177 // Next output order index (in encode order).
179
180 // Timestamp handling.
185
186 // Frame type decision.
198
199 // The number of L0/L1 references supported by the driver.
202
203 // Whether the driver supports ROI at all.
205
206 // The encoder does not support cropping information, so warn about
207 // it the first time we encounter any nonzero crop fields.
209 // If the driver does not support ROI then warn the first time we
210 // encounter a frame with ROI side data.
212
213 // The frame to be filled with data.
215
216 // Whether the HW supports sync buffer function.
217 // If supported, encode_fifo/async_depth will be used together.
218 // Used for output buffer synchronization.
220
221 // Store buffered pic.
223 // Max number of frame buffered in encoder.
225
226 /** Tail data of a pic, now only used for av1 repeat frame header. */
229
231 FFHWBaseEncodePicture *pic, AVPacket *pkt, int flag_no_delay);
232
234
236 uint32_t ref_l0, uint32_t ref_l1,
237 int flags, int prediction_pre_only);
238
239int ff_hw_base_get_recon_format(FFHWBaseEncodeContext *ctx, const void *hwconfig,
240 enum AVPixelFormat *fmt);
241
243
245
246#define HW_BASE_ENCODE_COMMON_OPTIONS \
247 { "idr_interval", \
248 "Distance (in I-frames) between key frames", \
249 OFFSET(common.base.idr_interval), AV_OPT_TYPE_INT, \
250 { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
251 { "b_depth", \
252 "Maximum B-frame reference depth", \
253 OFFSET(common.base.desired_b_depth), AV_OPT_TYPE_INT, \
254 { .i64 = 1 }, 1, INT_MAX, FLAGS }, \
255 { "async_depth", "Maximum processing parallelism. " \
256 "Increase this to improve single channel performance.", \
257 OFFSET(common.base.async_depth), AV_OPT_TYPE_INT, \
258 { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }
259
260#endif /* AVCODEC_HW_BASE_ENCODE_H */
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_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)
static AVFormatContext * ctx
Definition movenc.c:49