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
33
36
39
40 enum {
47 // A.4.1: table A.6 allows at most 22 tile rows for any level.
49 // A.4.1: table A.6 allows at most 20 tile columns for any level.
52 };
53
55
56 enum {
61 };
62
71
74
80
83
84 #if VA_CHECK_VERSION(1, 0, 0)
85 // ROI regions.
87 #else
89 #endif
90
95
98
101
104
107
110
111 // Whether this picture is a reference picture.
113
114 // The contents of the DPB after this picture has been decoded.
115 // This will contain the picture itself if it is a reference picture,
116 // but not if it isn't.
119 // The reference pictures used in decoding this picture. If they are
120 // used by later pictures they will also appear in the DPB.
123 // The previous reference picture in encode order. Must be in at least
124 // one of the reference list and DPB list.
126 // Reference count for other pictures referring to this one through
127 // the above pointers, directly from incomplete pictures and indirectly
128 // through completed pictures.
131
135
137 // lavc profile value (FF_PROFILE_*).
139 // Supported bit depth.
141 // Number of components.
143 // Chroma subsampling in width dimension.
145 // Chroma subsampling in height dimension.
147 // VAAPI profile value.
150
151 enum {
160 };
161
163 // Mode from above enum (RC_MODE_*).
165 // Name.
167 // Supported in the compile-time VAAPI version.
169 // VA mode value (VA_RC_*).
171 // Uses bitrate parameters.
173 // Supports maxrate distinct from bitrate.
175 // Uses quality value.
177 // Supports HRD/VBV parameters.
180
183
184 // Codec-specific hooks.
186
187 // Global options.
188
189 // Use low power encoding mode.
191
192 // Number of I frames between IDR frames.
194
195 // Desired B frame reference depth.
197
198 // Max Frame Size
200
201 // Explicitly set RC mode (otherwise attempt to pick from
202 // available modes).
204
205 // Explicitly-set QP, for use with the "qp" options.
206 // (Forces CQP mode when set, overriding everything else.)
208
209 // Desired packed headers.
211
212 // The required size of surfaces. This is probably the input
213 // size (AVCodecContext.width|height) aligned up to whatever
214 // block size is required by the codec.
217
218 // The block size for slice calculations.
221
222 // Everything above this point must be set before calling
223 // ff_vaapi_encode_init().
224
225 // Chosen encoding profile details.
227
228 // Chosen rate control mode details.
230 // RC quality level - meaning depends on codec and RC mode.
231 // In CQP mode this sets the fixed quantiser value.
233
234 // Encoding profile (VAProfile*).
236 // Encoding entrypoint (VAEntryoint*).
238 // Rate control mode.
240 // Bitrate for codec-specific encoder parameters.
242 // Packed headers which will actually be sent.
244
245 // Configuration attributes to use when creating va_config.
248
251
255
256 // The hardware frame context containing the input frames.
259
260 // The hardware frame context containing the reconstructed frames.
263
264 // Pool of (reusable) bitstream output buffers.
266
267 // Global parameters which will be applied at the start of the
268 // sequence (includes rate control parameters below).
273
274 // Rate control parameters.
279 #if VA_CHECK_VERSION(0, 36, 0)
280 VAEncMiscParameterBufferQualityLevel quality_params;
281 #endif
282
283 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
285
286 // Per-sequence parameters found in the per-picture parameter
287 // structure (VAEncPictureParameterBuffer*).
289
290 // Current encoding window, in display (input) order.
292 // The next picture to use as the previous reference picture in
293 // encoding order.
295
296 // Next input order index (display order).
298 // Number of frames that output is behind input.
300 // Next encode order index.
302 // Number of frames decode output will need to be delayed.
304 // Next output order index (in encode order).
306
307 // Timestamp handling.
312
313 // Slice structure.
318
319 // Tile encoding.
322 // Tile width of the i-th column.
324 // Tile height of i-th row.
326 // Location of the i-th tile column boundary.
328 // Location of the i-th tile row boundary.
330
331 // Frame type decision.
343
344 // Whether the driver supports ROI at all.
346 // Maximum number of regions supported by the driver.
348 // Quantisation range for offset calculations. Set by codec-specific
349 // code, as it may change based on parameters.
351
352 // The encoder does not support cropping information, so warn about
353 // it the first time we encounter any nonzero crop fields.
355 // If the driver does not support ROI then warn the first time we
356 // encounter a frame with ROI side data.
358
360
361 // Whether the driver support vaSyncBuffer
363 // Store buffered pic
365 // Max number of frame buffered in encoder.
368
369 enum {
370 // Codec supports controlling the subdivision of pictures into slices.
372 // Codec only supports constant quality (no rate control).
374 // Codec is intra-only.
376 // Codec supports B-pictures.
378 // Codec supports referencing B-pictures.
380 // Codec supports non-IDR key pictures (that is, key pictures do
381 // not necessarily empty the DPB).
383 };
384
386 // List of supported profiles and corresponding VAAPI profiles.
387 // (Must end with FF_PROFILE_UNKNOWN.)
389
390 // Codec feature flags.
392
393 // Default quality for this codec - used as quantiser or RC quality
394 // factor depending on RC mode.
396
397 // Determine encode parameters like block sizes for surface alignment
398 // and slices. This may need to query the profile and entrypoint,
399 // which will be available when this function is called. If not set,
400 // assume that all blocks are 16x16 and that surfaces should be
401 // aligned to match this.
403
404 // Perform any extra codec-specific configuration after the
405 // codec context is initialised (set up the private data and
406 // add any necessary global parameters).
408
409 // The size of any private data structure associated with each
410 // picture (can be zero if not required).
412
413 // The size of the parameter structures:
414 // sizeof(VAEnc{type}ParameterBuffer{codec}).
418
419 // Fill the parameter structures.
426
427 // The type used by the packed header: this should look like
428 // VAEncPackedHeader{something}.
432
433 // Write the packed header data to the provided buffer.
434 // The sequence header is also used to fill the codec extradata
435 // when the encoder is starting.
437 char *
data,
size_t *data_len);
440 char *
data,
size_t *data_len);
444 char *
data,
size_t *data_len);
445
446 // Fill an extra parameter structure, which will then be
447 // passed to vaRenderPicture(). Will be called repeatedly
448 // with increasing index argument until AVERROR_EOF is
449 // returned.
453 char *
data,
size_t *data_len);
454
455 // Write an extra packed header. Will be called repeatedly
456 // with increasing index argument until AVERROR_EOF is
457 // returned.
461 char *
data,
size_t *data_len);
463
464
466
469
470
471 #define VAAPI_ENCODE_COMMON_OPTIONS \
472 { "low_power", \
473 "Use low-power encoding mode (only available on some platforms; " \
474 "may not support all encoding features)", \
475 OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \
476 { .i64 = 0 }, 0, 1, FLAGS }, \
477 { "idr_interval", \
478 "Distance (in I-frames) between IDR frames", \
479 OFFSET(common.idr_interval), AV_OPT_TYPE_INT, \
480 { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
481 { "b_depth", \
482 "Maximum B-frame reference depth", \
483 OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \
484 { .i64 = 1 }, 1, INT_MAX, FLAGS }, \
485 { "async_depth", "Maximum processing parallelism. " \
486 "Increase this to improve single channel performance. This option " \
487 "doesn't work if driver doesn't implement vaSyncBuffer function.", \
488 OFFSET(common.async_depth), AV_OPT_TYPE_INT, \
489 { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }, \
490 { "max_frame_size", \
491 "Maximum frame size (in bytes)",\
492 OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
493 { .i64 = 0 }, 0, INT_MAX, FLAGS }
494
495 #define VAAPI_ENCODE_RC_MODE(name, desc) \
496 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
497 0, 0, FLAGS, "rc_mode" }
498 #define VAAPI_ENCODE_RC_OPTIONS \
499 { "rc_mode",\
500 "Set rate control mode", \
501 OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \
502 { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, "rc_mode" }, \
503 { "auto", "Choose mode automatically based on other parameters", \
504 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, "rc_mode" }, \
505 VAAPI_ENCODE_RC_MODE(CQP, "Constant-quality"), \
506 VAAPI_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \
507 VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
508 VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \
509 VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
510 VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate")
511
512
513 #endif /* AVCODEC_VAAPI_ENCODE_H */