23#ifndef AVCODEC_D3D12VA_ENCODE_H
24#define AVCODEC_D3D12VA_ENCODE_H
39#define MAX_PARAM_BUFFER_SIZE 4096
40#define D3D12VA_VIDEO_ENC_ASYNC_DEPTH 8
57 D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA
pic_ctl;
260 D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS
req;
262 D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS
res_limits;
271 D3D12_VIDEO_ENCODER_RATE_CONTROL
rc;
273 D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE
gop;
275 D3D12_VIDEO_ENCODER_LEVEL_SETTING
level;
369 char *
data,
size_t *data_len);
384 D3D12_VIDEO_ENCODER_VALIDATION_FLAGS
flags);
386#define D3D12VA_ENCODE_INTRA_REFRESH_MODE(name, mode, desc) \
387 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_ ## mode }, \
388 0, 0, FLAGS, .unit = "intra_refresh_mode" }
390#if CONFIG_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
391#define D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAX_VALUE D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_EIGHTH_PIXEL
393#define D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAX_VALUE D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_QUARTER_PIXEL
396#define D3D12VA_ENCODE_ME_PRECISION_MODE(name, mode, desc) \
397 { #name, #desc " pixel precision", 0, AV_OPT_TYPE_CONST, \
398 { .i64 = D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_ ## mode }, \
399 0, 0, FLAGS, .unit = "me_precision" }
401#if CONFIG_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
402#define FFPP_D3D12VA_ME_PRECISION_EIGHTH_PIXEL \
403 , D3D12VA_ENCODE_ME_PRECISION_MODE(eighth_pixel, EIGHTH_PIXEL, Eighth)
405#define FFPP_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
408#define D3D12VA_ENCODE_COMMON_OPTIONS \
409 { "max_frame_size", \
410 "Maximum frame size (in bytes)",\
411 OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
412 { .i64 = 0 }, 0, INT_MAX / 8, FLAGS }, \
413 { "intra_refresh_mode", \
414 "Set intra refresh mode", \
415 OFFSET(common.intra_refresh.Mode), AV_OPT_TYPE_INT, \
416 { .i64 = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE }, \
417 D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE, \
418 D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_ROW_BASED, FLAGS, .unit = "intra_refresh_mode" }, \
419 D3D12VA_ENCODE_INTRA_REFRESH_MODE(none, NONE, "Disable intra refresh"), \
420 D3D12VA_ENCODE_INTRA_REFRESH_MODE(row_based, ROW_BASED, "Row-based intra refresh"), \
421 { "intra_refresh_duration", \
422 "Number of frames over which to spread intra refresh (0 = GOP size)", \
423 OFFSET(common.intra_refresh.IntraRefreshDuration), AV_OPT_TYPE_INT, \
424 { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
425 { "me_precision", "Motion estimation precision mode", \
426 OFFSET(common.me_precision), AV_OPT_TYPE_INT, \
427 { .i64 = D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM }, \
428 D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM, \
429 D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAX_VALUE, \
430 FLAGS, .unit = "me_precision" }, \
431 { "maximum", "Maximum (best quality, slowest)", 0, AV_OPT_TYPE_CONST, \
432 { .i64 = D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM }, \
433 0, 0, FLAGS, .unit = "me_precision" }, \
434 D3D12VA_ENCODE_ME_PRECISION_MODE(full_pixel, FULL_PIXEL, Full), \
435 D3D12VA_ENCODE_ME_PRECISION_MODE(half_pixel, HALF_PIXEL, Half), \
436 D3D12VA_ENCODE_ME_PRECISION_MODE(quarter_pixel, QUARTER_PIXEL, Quarter) \
437 FFPP_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
439#define D3D12VA_ENCODE_RC_MODE(name, desc) \
440 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
441 0, 0, FLAGS, .unit = "rc_mode" }
442#define D3D12VA_ENCODE_RC_OPTIONS \
444 "Set rate control mode", \
445 OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \
446 { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, .unit = "rc_mode" }, \
447 { "auto", "Choose mode automatically based on other parameters", \
448 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, .unit = "rc_mode" }, \
449 D3D12VA_ENCODE_RC_MODE(CQP, "Constant-quality"), \
450 D3D12VA_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \
451 D3D12VA_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
452 D3D12VA_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate")
Libavcodec external API header.
#define flags(name, subs,...)
const AVCodecHWConfigInternal *const ff_d3d12va_encode_hw_configs[]
int ff_d3d12va_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
void ff_d3d12va_encode_check_encoder_feature_flags(void *log_ctx, D3D12_VIDEO_ENCODER_VALIDATION_FLAGS flags)
int ff_d3d12va_encode_init(AVCodecContext *avctx)
int ff_d3d12va_encode_close(AVCodecContext *avctx)
#define MAX_PARAM_BUFFER_SIZE
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
common internal api header.
A reference to a data buffer.
main external API structure.
This struct is allocated as AVHWDeviceContext.hwctx.
D3D12VA frame descriptor for pool allocation.
This struct is used to sync d3d12 execution.
This structure stores compressed data.
ID3D12VideoEncoder * encoder
ID3D12VideoEncodeCommandList2 * command_list
D3D12 video encode command list.
UINT intra_refresh_frame_index
Current frame index within intra refresh cycle.
D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC resolution
D3D12_VIDEO_ENCODER structures.
AVD3D12VADeviceContext * hwctx
D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE me_precision
Motion estimation precision mode.
int is_texture_array
Flag indicates if the HW is texture array mode.
D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION codec_conf
int explicit_rc_mode
Explicitly set RC mode (otherwise attempt to pick from available modes).
ID3D12VideoEncoderHeap * encoder_heap
D3D12 video encoder heap.
D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS req
D3D12_FEATURE structures.
D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE gop
AVD3D12VASyncContext sync_ctx
The sync context used to sync command queue.
int plane_count
The number of planes in the input DXGI FORMAT.
ID3D12Device3 * device3
ID3D12Device3 interface.
D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE subregion_mode
const struct D3D12VAEncodeType * codec
Codec-specific hooks.
D3D12_VIDEO_ENCODER_INTRA_REFRESH intra_refresh
Intra refresh configuration.
int qp_map_region_size
QP map region pixel size (block size for QP map)
int bi_not_empty
The bi_not_empty feature.
D3D12_VIDEO_ENCODER_RATE_CONTROL rc
D3D12_VIDEO_ENCODER_LEVEL_SETTING level
AVBufferRef * encoder_ref
D3D12 video encoder.
int max_frame_size
Max frame size.
const D3D12VAEncodeProfile * profile
Chosen encoding profile details.
int rc_quality
RC quality level - meaning depends on codec and RC mode.
D3D12_VIDEO_ENCODER_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA subregions_layout
AVBufferPool * output_buffer_pool
Pool of (reusable) bitstream output buffers.
ID3D12VideoDevice3 * video_device3
ID3D12VideoDevice3 interface.
D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS res_limits
int explicit_qp
Explicitly-set QP, for use with the "qp" options.
ID3D12CommandQueue * command_queue
D3D12 command queue.
FFHWBaseEncodeContext base
AVFifo * allocator_queue
A cached queue for reusing the D3D12 command allocators.
AVBufferRef * output_buffer_ref
ID3D12Resource * encoded_metadata
int non_independent_frame
char tail_data[MAX_PARAM_BUFFER_SIZE]
D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA pic_ctl
ID3D12Resource * resolved_metadata
AVD3D12VAFrame * recon_surface
AVD3D12VAFrame * input_surface
ID3D12Resource * output_buffer
int depth
Supported bit depth.
int av_profile
lavc profile value (AV_PROFILE_*).
int nb_components
Number of components.
D3D12_VIDEO_ENCODER_PROFILE_DESC d3d12_profile
D3D12 profile value.
int log2_chroma_w
Chroma subsampling in width dimension.
int log2_chroma_h
Chroma subsampling in height dimension.
int hrd
Supports HRD/VBV parameters.
int mode
Mode from above enum (RC_MODE_*).
int quality
Uses quality value.
D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE d3d12_mode
D3D12 mode value.
int maxrate
Supports maxrate distinct from bitrate.
int bitrate
Uses bitrate parameters.
int flags
Codec feature flags.
int(* get_coded_data)(AVCodecContext *avctx, D3D12VAEncodePicture *pic, AVPacket *pkt)
Fill the coded data into AVPacket.
const D3D12VAEncodeProfile * profiles
List of supported profiles.
int(* init_sequence_params)(AVCodecContext *avctx)
Fill the corresponding parameters.
D3D12_VIDEO_ENCODER_CODEC d3d12_codec
D3D12 codec name.
int(* configure)(AVCodecContext *avctx)
Perform any extra codec-specific configuration.
int(* set_tile)(AVCodecContext *avctx)
Set codec-specific tile setting.
void(* free_picture_params)(D3D12VAEncodePicture *pic)
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
Write the packed header data to the provided buffer.
int(* init_picture_params)(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic)
int(* get_encoder_caps)(AVCodecContext *avctx)
Query codec configuration and determine encode parameters like block sizes for surface alignment and ...
size_t picture_priv_data_size
The size of any private data structure associated with each picture (can be zero if not required).
int default_quality
Default quality for this codec - used as quantiser or RC quality factor depending on RC mode.
int(* set_level)(AVCodecContext *avctx)
Set codec-specific level setting.