FFmpeg
Loading...
Searching...
No Matches
vaapi_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_VAAPI_ENCODE_H
20#define AVCODEC_VAAPI_ENCODE_H
21
22#include <stdint.h>
23
24#include <va/va.h>
25
26#if VA_CHECK_VERSION(1, 0, 0)
27#include <va/va_str.h>
28#endif
29
30#include "libavutil/hwcontext.h"
32
33#include "avcodec.h"
34#include "hwconfig.h"
35#include "hw_base_encode.h"
36
37struct VAAPIEncodeType;
39
40// Codec output packet without timestamp delay, which means the
41// output packet has same PTS and DTS.
42#define FLAG_TIMESTAMP_NO_DELAY 1 << 6
43
44enum {
48 // A.4.1: table A.6 allows at most 22 tile rows for any level.
50 // A.4.1: table A.6 allows at most 20 tile columns for any level.
52};
53
55
64
65typedef struct VAAPIEncodePicture {
66#if VA_CHECK_VERSION(1, 0, 0)
67 // ROI regions.
68 VAEncROI *roi;
69#else
70 void *roi;
71#endif
72
73 VASurfaceID input_surface;
74 VASurfaceID recon_surface;
75
77 VABufferID *param_buffers;
78
79 /* Refcounted via the refstruct-API */
80 VABufferID *output_buffer_ref;
81 VABufferID output_buffer;
82
84
87
88 /**
89 * indicate if current frame is an independent frame that the coded data
90 * can be pushed to downstream directly. Coded of non-independent frame
91 * data will be concatenated into next independent frame.
92 */
94 /** Tail data of current pic, used only for repeat header of AV1. */
96 /** Byte length of tail_data. */
97 size_t tail_size;
99
100typedef struct VAAPIEncodeProfile {
101 // lavc profile value (AV_PROFILE_*).
103 // Supported bit depth.
104 int depth;
105 // Number of components.
107 // Chroma subsampling in width dimension.
109 // Chroma subsampling in height dimension.
111 // VAAPI profile value.
112 VAProfile va_profile;
114
115enum {
124};
125
126typedef struct VAAPIEncodeRCMode {
127 // Mode from above enum (RC_MODE_*).
128 int mode;
129 // Name.
130 const char *name;
131 // Supported in the compile-time VAAPI version.
133 // VA mode value (VA_RC_*).
134 uint32_t va_mode;
135 // Uses bitrate parameters.
137 // Supports maxrate distinct from bitrate.
139 // Uses quality value.
141 // Supports HRD/VBV parameters.
142 int hrd;
144
145typedef struct VAAPIEncodeContext {
146 // Base context.
148
149 // Codec-specific hooks.
150 const struct VAAPIEncodeType *codec;
151
152 // Use low power encoding mode.
154
155 // Max Frame Size
157
158 // Explicitly set RC mode (otherwise attempt to pick from
159 // available modes).
161
162 // Block Level based bitrate control.
163 int blbrc;
164
165 // Explicitly-set QP, for use with the "qp" options.
166 // (Forces CQP mode when set, overriding everything else.)
168
169 // Desired packed headers.
171
172 // Everything above this point must be set before calling
173 // ff_vaapi_encode_init().
174
175 // Chosen encoding profile details.
177
178 // Chosen rate control mode details.
180 // RC quality level - meaning depends on codec and RC mode.
181 // In CQP mode this sets the fixed quantiser value.
183
184 // Encoding profile (VAProfile*).
185 VAProfile va_profile;
186 // Encoding entrypoint (VAEntryoint*).
187 VAEntrypoint va_entrypoint;
188 // Rate control mode.
189 unsigned int va_rc_mode;
190 // Bitrate for codec-specific encoder parameters.
191 unsigned int va_bit_rate;
192 // Packed headers which will actually be sent.
193 unsigned int va_packed_headers;
194
195 // Configuration attributes to use when creating va_config.
198
199 VAConfigID va_config;
200 VAContextID va_context;
201
203
204 // Pool of (reusable) bitstream output buffers.
206
207 // Global parameters which will be applied at the start of the
208 // sequence (includes rate control parameters below).
213
214 // Rate control parameters.
215 VAEncMiscParameterRateControl rc_params;
216 VAEncMiscParameterHRD hrd_params;
217 VAEncMiscParameterFrameRate fr_params;
218 VAEncMiscParameterBufferMaxFrameSize mfs_params;
219#if VA_CHECK_VERSION(0, 36, 0)
220 VAEncMiscParameterBufferQualityLevel quality_params;
221#endif
222
223 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
225
226 // Per-sequence parameters found in the per-picture parameter
227 // structure (VAEncPictureParameterBuffer*).
229
230 // Slice structure.
235
236 // Tile encoding.
239 // Tile width of the i-th column.
241 // Tile height of i-th row.
243 // Location of the i-th tile column boundary.
245 // Location of the i-th tile row boundary.
247
248 // Maximum number of regions supported by the driver.
250 // Quantisation range for offset calculations. Set by codec-specific
251 // code, as it may change based on parameters.
253
254 /** Head data for current output pkt, used only for AV1. */
255 //void *header_data;
256 //size_t header_data_size;
257
258 /**
259 * Buffered coded data of a pic if it is an non-independent frame.
260 * This is a RefStruct reference.
261 */
262 VABufferID *coded_buffer_ref;
263
264 // Surface alignment required by driver.
268
269typedef struct VAAPIEncodeType {
270 // List of supported profiles and corresponding VAAPI profiles.
271 // (Must end with AV_PROFILE_UNKNOWN.)
273
274 // Codec feature flags.
275 int flags;
276
277 // Default quality for this codec - used as quantiser or RC quality
278 // factor depending on RC mode.
280
281 // Determine encode parameters like block sizes for surface alignment
282 // and slices. This may need to query the profile and entrypoint,
283 // which will be available when this function is called. If not set,
284 // assume that all blocks are 16x16 and that surfaces should be
285 // aligned to match this.
287
288 // Perform any extra codec-specific configuration after the
289 // codec context is initialised (set up the private data and
290 // add any necessary global parameters).
291 int (*configure)(AVCodecContext *avctx);
292
293 // The size of any private data structure associated with each
294 // picture (can be zero if not required).
296
297 // The size of the parameter structures:
298 // sizeof(VAEnc{type}ParameterBuffer{codec}).
302
303 // Fill the parameter structures.
309 VAAPIEncodeSlice *slice);
310
311 // The type used by the packed header: this should look like
312 // VAEncPackedHeader{something}.
316
317 // Write the packed header data to the provided buffer.
318 // The sequence header is also used to fill the codec extradata
319 // when the encoder is starting.
321 char *data, size_t *data_len);
324 char *data, size_t *data_len);
327 VAAPIEncodeSlice *slice,
328 char *data, size_t *data_len);
329
330 // Fill an extra parameter structure, which will then be
331 // passed to vaRenderPicture(). Will be called repeatedly
332 // with increasing index argument until AVERROR_EOF is
333 // returned.
336 int index, int *type,
337 char *data, size_t *data_len);
338
339 // Write an extra packed header. Will be called repeatedly
340 // with increasing index argument until AVERROR_EOF is
341 // returned.
344 int index, int *type,
345 char *data, size_t *data_len);
347
349
352
353
354#define VAAPI_ENCODE_COMMON_OPTIONS \
355 { "low_power", \
356 "Use low-power encoding mode (only available on some platforms; " \
357 "may not support all encoding features)", \
358 OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \
359 { .i64 = 0 }, 0, 1, FLAGS }, \
360 { "max_frame_size", \
361 "Maximum frame size (in bytes)",\
362 OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
363 { .i64 = 0 }, 0, INT_MAX / 8, FLAGS }
364
365#define VAAPI_ENCODE_RC_MODE(name, desc) \
366 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
367 0, 0, FLAGS, .unit = "rc_mode" }
368#define VAAPI_ENCODE_RC_OPTIONS \
369 { "rc_mode",\
370 "Set rate control mode", \
371 OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \
372 { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, .unit = "rc_mode" }, \
373 { "auto", "Choose mode automatically based on other parameters", \
374 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, .unit = "rc_mode" }, \
375 VAAPI_ENCODE_RC_MODE(CQP, "Constant-quality"), \
376 VAAPI_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \
377 VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
378 VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \
379 VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
380 VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate"), \
381 { "blbrc", \
382 "Block level based bitrate control",\
383 OFFSET(common.blbrc), AV_OPT_TYPE_BOOL, \
384 { .i64 = 0 }, 0, 1, FLAGS }
385
386
387#endif /* AVCODEC_VAAPI_ENCODE_H */
Libavcodec external API header.
@ RC_MODE_MAX
@ RC_MODE_AUTO
@ RC_MODE_CQP
@ RC_MODE_QVBR
@ RC_MODE_CBR
@ RC_MODE_VBR
#define MAX_PARAM_BUFFER_SIZE
static AVPacket * pkt
int index
Definition gxfenc.c:90
cl_device_type type
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
const char data[16]
Definition mxf.c:149
main external API structure.
Definition avcodec.h:443
This structure stores compressed data.
Definition packet.h:580
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:183
VAAPI connection details.
int row_height[MAX_TILE_ROWS]
const void * global_params[MAX_GLOBAL_PARAMS]
VAEncMiscParameterHRD hrd_params
int row_bd[MAX_TILE_ROWS+1]
VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES]
VAEncMiscParameterFrameRate fr_params
VAEncMiscParameterBufferMaxFrameSize mfs_params
unsigned int va_rc_mode
int global_params_type[MAX_GLOBAL_PARAMS]
FFHWBaseEncodeContext base
size_t global_params_size[MAX_GLOBAL_PARAMS]
VAEntrypoint va_entrypoint
unsigned int desired_packed_headers
VABufferID * coded_buffer_ref
Head data for current output pkt, used only for AV1.
struct AVRefStructPool * output_buffer_pool
int col_width[MAX_TILE_COLS]
AVVAAPIDeviceContext * hwctx
unsigned int va_packed_headers
const VAAPIEncodeRCMode * rc_mode
const VAAPIEncodeProfile * profile
VAContextID va_context
VAEncMiscParameterRateControl rc_params
int col_bd[MAX_TILE_COLS+1]
unsigned int va_bit_rate
const struct VAAPIEncodeType * codec
void * codec_picture_params
int non_independent_frame
indicate if current frame is an independent frame that the coded data can be pushed to downstream dir...
size_t tail_size
Byte length of tail_data.
char tail_data[MAX_PARAM_BUFFER_SIZE]
Tail data of current pic, used only for repeat header of AV1.
VASurfaceID recon_surface
VAAPIEncodeSlice * slices
VABufferID output_buffer
VASurfaceID input_surface
VABufferID * param_buffers
VABufferID * output_buffer_ref
const char * name
void * codec_slice_params
int(* write_slice_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
size_t picture_params_size
size_t sequence_params_size
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
int(* init_picture_params)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
int(* write_extra_header)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
const VAAPIEncodeProfile * profiles
int(* init_sequence_params)(AVCodecContext *avctx)
int(* write_extra_buffer)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
size_t slice_params_size
int(* configure)(AVCodecContext *avctx)
int(* write_picture_header)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, char *data, size_t *data_len)
int(* get_encoder_caps)(AVCodecContext *avctx)
int(* init_slice_params)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VAAPIEncodeSlice *slice)
size_t picture_priv_data_size
int ff_vaapi_encode_init(AVCodecContext *avctx)
int ff_vaapi_encode_close(AVCodecContext *avctx)
@ MAX_TILE_ROWS
@ MAX_CONFIG_ATTRIBUTES
@ MAX_GLOBAL_PARAMS
@ MAX_TILE_COLS
@ MAX_PARAM_BUFFER_SIZE
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
@ RC_MODE_ICQ
@ RC_MODE_AVBR