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;
255 D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS
req;
257 D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS
res_limits;
266 D3D12_VIDEO_ENCODER_RATE_CONTROL
rc;
268 D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE
gop;
270 D3D12_VIDEO_ENCODER_LEVEL_SETTING
level;
364 char *
data,
size_t *data_len);
379 D3D12_VIDEO_ENCODER_VALIDATION_FLAGS
flags);
381#define D3D12VA_ENCODE_INTRA_REFRESH_MODE(name, mode, desc) \
382 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_ ## mode }, \
383 0, 0, FLAGS, .unit = "intra_refresh_mode" }
385#if CONFIG_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
386#define D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAX_VALUE D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_EIGHTH_PIXEL
388#define D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAX_VALUE D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_QUARTER_PIXEL
391#define D3D12VA_ENCODE_ME_PRECISION_MODE(name, mode, desc) \
392 { #name, #desc " pixel precision", 0, AV_OPT_TYPE_CONST, \
393 { .i64 = D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_ ## mode }, \
394 0, 0, FLAGS, .unit = "me_precision" }
396#if CONFIG_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
397#define FFPP_D3D12VA_ME_PRECISION_EIGHTH_PIXEL \
398 , D3D12VA_ENCODE_ME_PRECISION_MODE(eighth_pixel, EIGHTH_PIXEL, Eighth)
400#define FFPP_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
403#define D3D12VA_ENCODE_COMMON_OPTIONS \
404 { "max_frame_size", \
405 "Maximum frame size (in bytes)",\
406 OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
407 { .i64 = 0 }, 0, INT_MAX / 8, FLAGS }, \
408 { "intra_refresh_mode", \
409 "Set intra refresh mode", \
410 OFFSET(common.intra_refresh.Mode), AV_OPT_TYPE_INT, \
411 { .i64 = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE }, \
412 D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE, \
413 D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_ROW_BASED, FLAGS, .unit = "intra_refresh_mode" }, \
414 D3D12VA_ENCODE_INTRA_REFRESH_MODE(none, NONE, "Disable intra refresh"), \
415 D3D12VA_ENCODE_INTRA_REFRESH_MODE(row_based, ROW_BASED, "Row-based intra refresh"), \
416 { "intra_refresh_duration", \
417 "Number of frames over which to spread intra refresh (0 = GOP size)", \
418 OFFSET(common.intra_refresh.IntraRefreshDuration), AV_OPT_TYPE_INT, \
419 { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
420 { "me_precision", "Motion estimation precision mode", \
421 OFFSET(common.me_precision), AV_OPT_TYPE_INT, \
422 { .i64 = D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM }, \
423 D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM, \
424 D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAX_VALUE, \
425 FLAGS, .unit = "me_precision" }, \
426 { "maximum", "Maximum (best quality, slowest)", 0, AV_OPT_TYPE_CONST, \
427 { .i64 = D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM }, \
428 0, 0, FLAGS, .unit = "me_precision" }, \
429 D3D12VA_ENCODE_ME_PRECISION_MODE(full_pixel, FULL_PIXEL, Full), \
430 D3D12VA_ENCODE_ME_PRECISION_MODE(half_pixel, HALF_PIXEL, Half), \
431 D3D12VA_ENCODE_ME_PRECISION_MODE(quarter_pixel, QUARTER_PIXEL, Quarter) \
432 FFPP_D3D12VA_ME_PRECISION_EIGHTH_PIXEL
434#define D3D12VA_ENCODE_RC_MODE(name, desc) \
435 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
436 0, 0, FLAGS, .unit = "rc_mode" }
437#define D3D12VA_ENCODE_RC_OPTIONS \
439 "Set rate control mode", \
440 OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \
441 { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, .unit = "rc_mode" }, \
442 { "auto", "Choose mode automatically based on other parameters", \
443 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, .unit = "rc_mode" }, \
444 D3D12VA_ENCODE_RC_MODE(CQP, "Constant-quality"), \
445 D3D12VA_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \
446 D3D12VA_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
447 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)
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
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.