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
32
36
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
44 enum {
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
66 #if VA_CHECK_VERSION(1, 0, 0)
67 // ROI regions.
69 #else
71 #endif
72
75
78
79 /* Refcounted via the refstruct-API */
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. */
99
101 // lavc profile value (AV_PROFILE_*).
103 // Supported bit depth.
105 // Number of components.
107 // Chroma subsampling in width dimension.
109 // Chroma subsampling in height dimension.
111 // VAAPI profile value.
114
115 enum {
124 };
125
127 // Mode from above enum (RC_MODE_*).
129 // Name.
131 // Supported in the compile-time VAAPI version.
133 // VA mode value (VA_RC_*).
135 // Uses bitrate parameters.
137 // Supports maxrate distinct from bitrate.
139 // Uses quality value.
141 // Supports HRD/VBV parameters.
144
146 // Base context.
148
149 // Codec-specific hooks.
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.
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*).
186 // Encoding entrypoint (VAEntryoint*).
188 // Rate control mode.
190 // Bitrate for codec-specific encoder parameters.
192 // Packed headers which will actually be sent.
194
195 // Configuration attributes to use when creating va_config.
198
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.
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 */
264
266 // List of supported profiles and corresponding VAAPI profiles.
267 // (Must end with AV_PROFILE_UNKNOWN.)
269
270 // Codec feature flags.
272
273 // Default quality for this codec - used as quantiser or RC quality
274 // factor depending on RC mode.
276
277 // Determine encode parameters like block sizes for surface alignment
278 // and slices. This may need to query the profile and entrypoint,
279 // which will be available when this function is called. If not set,
280 // assume that all blocks are 16x16 and that surfaces should be
281 // aligned to match this.
283
284 // Perform any extra codec-specific configuration after the
285 // codec context is initialised (set up the private data and
286 // add any necessary global parameters).
288
289 // The size of any private data structure associated with each
290 // picture (can be zero if not required).
292
293 // The size of the parameter structures:
294 // sizeof(VAEnc{type}ParameterBuffer{codec}).
298
299 // Fill the parameter structures.
306
307 // The type used by the packed header: this should look like
308 // VAEncPackedHeader{something}.
312
313 // Write the packed header data to the provided buffer.
314 // The sequence header is also used to fill the codec extradata
315 // when the encoder is starting.
317 char *
data,
size_t *data_len);
320 char *
data,
size_t *data_len);
324 char *
data,
size_t *data_len);
325
326 // Fill an extra parameter structure, which will then be
327 // passed to vaRenderPicture(). Will be called repeatedly
328 // with increasing index argument until AVERROR_EOF is
329 // returned.
333 char *
data,
size_t *data_len);
334
335 // Write an extra packed header. Will be called repeatedly
336 // with increasing index argument until AVERROR_EOF is
337 // returned.
341 char *
data,
size_t *data_len);
343
345
348
349
350 #define VAAPI_ENCODE_COMMON_OPTIONS \
351 { "low_power", \
352 "Use low-power encoding mode (only available on some platforms; " \
353 "may not support all encoding features)", \
354 OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \
355 { .i64 = 0 }, 0, 1, FLAGS }, \
356 { "max_frame_size", \
357 "Maximum frame size (in bytes)",\
358 OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
359 { .i64 = 0 }, 0, INT_MAX, FLAGS }
360
361 #define VAAPI_ENCODE_RC_MODE(name, desc) \
362 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
363 0, 0, FLAGS, .unit = "rc_mode" }
364 #define VAAPI_ENCODE_RC_OPTIONS \
365 { "rc_mode",\
366 "Set rate control mode", \
367 OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \
368 { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, .unit = "rc_mode" }, \
369 { "auto", "Choose mode automatically based on other parameters", \
370 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, .unit = "rc_mode" }, \
371 VAAPI_ENCODE_RC_MODE(CQP, "Constant-quality"), \
372 VAAPI_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \
373 VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
374 VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \
375 VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
376 VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate"), \
377 { "blbrc", \
378 "Block level based bitrate control",\
379 OFFSET(common.blbrc), AV_OPT_TYPE_BOOL, \
380 { .i64 = 0 }, 0, 1, FLAGS }
381
382
383 #endif /* AVCODEC_VAAPI_ENCODE_H */