FFmpeg
d3d12va_encode_hevc.c
Go to the documentation of this file.
1 /*
2  * Direct3D 12 HW acceleration video encoder
3  *
4  * Copyright (c) 2024 Intel Corporation
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #include "libavutil/opt.h"
23 #include "libavutil/common.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/pixdesc.h"
27 
28 #include "avcodec.h"
29 #include "cbs.h"
30 #include "cbs_h265.h"
31 #include "hw_base_encode_h265.h"
32 #include "h2645data.h"
33 #include "h265_profile_level.h"
34 #include "codec_internal.h"
35 #include "d3d12va_encode.h"
36 
37 typedef struct D3D12VAEncodeHEVCPicture {
41 
42 typedef struct D3D12VAEncodeHEVCContext {
44 
45  // User options.
46  int qp;
47  int profile;
48  int level;
49 
50  // Writer structures.
53 
57 
58 typedef struct D3D12VAEncodeHEVCLevel {
59  int level;
60  D3D12_VIDEO_ENCODER_LEVELS_HEVC d3d12_level;
62 
63 static const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC hevc_config_support_sets[] =
64 {
65  {
66  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
67  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
68  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32,
69  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
70  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
71  3,
72  3,
73  },
74  {
75  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
76  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
77  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32,
78  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
79  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
80  0,
81  0,
82  },
83  {
84  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
85  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
86  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32,
87  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
88  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
89  2,
90  2,
91  },
92  {
93  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
94  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
95  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_64x64,
96  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
97  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
98  2,
99  2,
100  },
101  {
102  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
103  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
104  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_64x64,
105  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
106  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
107  4,
108  4,
109  },
110 };
111 
113  { 30, D3D12_VIDEO_ENCODER_LEVELS_HEVC_1 },
114  { 60, D3D12_VIDEO_ENCODER_LEVELS_HEVC_2 },
115  { 63, D3D12_VIDEO_ENCODER_LEVELS_HEVC_21 },
116  { 90, D3D12_VIDEO_ENCODER_LEVELS_HEVC_3 },
117  { 93, D3D12_VIDEO_ENCODER_LEVELS_HEVC_31 },
118  { 120, D3D12_VIDEO_ENCODER_LEVELS_HEVC_4 },
119  { 123, D3D12_VIDEO_ENCODER_LEVELS_HEVC_41 },
120  { 150, D3D12_VIDEO_ENCODER_LEVELS_HEVC_5 },
121  { 153, D3D12_VIDEO_ENCODER_LEVELS_HEVC_51 },
122  { 156, D3D12_VIDEO_ENCODER_LEVELS_HEVC_52 },
123  { 180, D3D12_VIDEO_ENCODER_LEVELS_HEVC_6 },
124  { 183, D3D12_VIDEO_ENCODER_LEVELS_HEVC_61 },
125  { 186, D3D12_VIDEO_ENCODER_LEVELS_HEVC_62 },
126 };
127 
128 static const D3D12_VIDEO_ENCODER_PROFILE_HEVC profile_main = D3D12_VIDEO_ENCODER_PROFILE_HEVC_MAIN;
129 static const D3D12_VIDEO_ENCODER_PROFILE_HEVC profile_main10 = D3D12_VIDEO_ENCODER_PROFILE_HEVC_MAIN10;
130 
131 #define D3D_PROFILE_DESC(name) \
132  { sizeof(D3D12_VIDEO_ENCODER_PROFILE_HEVC), { .pHEVCProfile = (D3D12_VIDEO_ENCODER_PROFILE_HEVC *)&profile_ ## name } }
134  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, D3D_PROFILE_DESC(main) },
135  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, D3D_PROFILE_DESC(main10) },
136  { AV_PROFILE_UNKNOWN },
137 };
138 
139 static uint8_t d3d12va_encode_hevc_map_cusize(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE cusize)
140 {
141  switch (cusize) {
142  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8: return 8;
143  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_16x16: return 16;
144  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32: return 32;
145  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_64x64: return 64;
146  default: av_assert0(0);
147  }
148  return 0;
149 }
150 
151 static uint8_t d3d12va_encode_hevc_map_tusize(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE tusize)
152 {
153  switch (tusize) {
154  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4: return 4;
155  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_8x8: return 8;
156  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_16x16: return 16;
157  case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32: return 32;
158  default: av_assert0(0);
159  }
160  return 0;
161 }
162 
164  char *data, size_t *data_len,
166 {
167  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
168  int err;
169 
170  err = ff_cbs_write_fragment_data(priv->cbc, au);
171  if (err < 0) {
172  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
173  return err;
174  }
175 
176  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
177  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
178  "%zu < %zu.\n", *data_len,
179  8 * au->data_size - au->data_bit_padding);
180  return AVERROR(ENOSPC);
181  }
182 
183  memcpy(data, au->data, au->data_size);
184  *data_len = 8 * au->data_size - au->data_bit_padding;
185 
186  return 0;
187 }
188 
191  void *nal_unit)
192 {
193  H265RawNALUnitHeader *header = nal_unit;
194  int err;
195 
196  err = ff_cbs_insert_unit_content(au, -1,
197  header->nal_unit_type, nal_unit, NULL);
198  if (err < 0) {
199  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
200  "type = %d.\n", header->nal_unit_type);
201  return err;
202  }
203 
204  return 0;
205 }
206 
208  char *data, size_t *data_len)
209 {
210  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
212  int err;
213 
214  err = d3d12va_encode_hevc_add_nal(avctx, au, &priv->units.raw_vps);
215  if (err < 0)
216  goto fail;
217 
218  err = d3d12va_encode_hevc_add_nal(avctx, au, &priv->units.raw_sps);
219  if (err < 0)
220  goto fail;
221 
222  err = d3d12va_encode_hevc_add_nal(avctx, au, &priv->units.raw_pps);
223  if (err < 0)
224  goto fail;
225 
226  err = d3d12va_encode_hevc_write_access_unit(avctx, data, data_len, au);
227 fail:
228  ff_cbs_fragment_reset(au);
229  return err;
230 
231 }
232 
234 {
235  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
237  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
238  AVD3D12VAFramesContext *hwctx = base_ctx->input_frames->hwctx;
239  H265RawSPS *sps = &priv->units.raw_sps;
240  H265RawPPS *pps = &priv->units.raw_pps;
241  D3D12_VIDEO_ENCODER_PROFILE_HEVC profile = D3D12_VIDEO_ENCODER_PROFILE_HEVC_MAIN;
242  D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC level = { 0 };
243  const AVPixFmtDescriptor *desc;
244  uint8_t min_cu_size, max_cu_size, min_tu_size, max_tu_size;
245  HRESULT hr;
246  int err;
247 
248  D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT support = {
249  .NodeIndex = 0,
250  .Codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
251  .InputFormat = hwctx->format,
252  .RateControl = ctx->rc,
253  .IntraRefresh = ctx->intra_refresh.Mode,
254  .SubregionFrameEncoding = D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE_FULL_FRAME,
255  .ResolutionsListCount = 1,
256  .pResolutionList = &ctx->resolution,
257  .CodecGopSequence = ctx->gop,
258  .MaxReferenceFramesInDPB = MAX_DPB_SIZE - 1,
259  .CodecConfiguration = ctx->codec_conf,
260  .SuggestedProfile.DataSize = sizeof(D3D12_VIDEO_ENCODER_PROFILE_HEVC),
261  .SuggestedProfile.pHEVCProfile = &profile,
262  .SuggestedLevel.DataSize = sizeof(D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC),
263  .SuggestedLevel.pHEVCLevelSetting = &level,
264  .pResolutionDependentSupport = &ctx->res_limits,
265  };
266 
267  hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_SUPPORT,
268  &support, sizeof(support));
269 
270  if (FAILED(hr)) {
271  av_log(avctx, AV_LOG_ERROR, "Failed to check encoder support(%lx).\n", (long)hr);
272  return AVERROR(EINVAL);
273  }
274 
275  if (!(support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK)) {
276  av_log(avctx, AV_LOG_ERROR, "Driver does not support some request features. %#x\n",
277  support.ValidationFlags);
278  return AVERROR(EINVAL);
279  }
280 
281  if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RECONSTRUCTED_FRAMES_REQUIRE_TEXTURE_ARRAYS) {
282  ctx->is_texture_array = 1;
283  av_log(avctx, AV_LOG_DEBUG, "D3D12 video encode on this device uses texture array mode.\n");
284  }
285 
286  // Check if the configuration with DELTA_QP is supported
287  if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_DELTA_QP_AVAILABLE) {
288  base_ctx->roi_allowed = 1;
289  // Store the QP map region size from resolution limits
290  ctx->qp_map_region_size = ctx->res_limits.QPMapRegionPixelsSize;
291  av_log(avctx, AV_LOG_DEBUG, "ROI encoding is supported via delta QP "
292  "(QP map region size: %d pixels).\n", ctx->qp_map_region_size);
293  } else {
294  base_ctx->roi_allowed = 0;
295  av_log(avctx, AV_LOG_DEBUG, "ROI encoding not supported by hardware for current rate control mode \n");
296  }
297 
299  av_assert0(desc);
300 
301  min_cu_size = d3d12va_encode_hevc_map_cusize(ctx->codec_conf.pHEVCConfig->MinLumaCodingUnitSize);
302  max_cu_size = d3d12va_encode_hevc_map_cusize(ctx->codec_conf.pHEVCConfig->MaxLumaCodingUnitSize);
303  min_tu_size = d3d12va_encode_hevc_map_tusize(ctx->codec_conf.pHEVCConfig->MinLumaTransformUnitSize);
304  max_tu_size = d3d12va_encode_hevc_map_tusize(ctx->codec_conf.pHEVCConfig->MaxLumaTransformUnitSize);
305 
306  // cu_qp_delta always required to be 1 in https://github.com/microsoft/DirectX-Specs/blob/master/d3d/D3D12VideoEncoding.md
308  priv->unit_opts.nb_slices = 1;
309 
310  err = ff_hw_base_encode_init_params_h265(base_ctx, avctx,
311  &priv->units, &priv->unit_opts);
312  if (err < 0)
313  return err;
314 
316 
317  av_assert0(ctx->res_limits.SubregionBlockPixelsSize % min_cu_size == 0);
318 
319  sps->pic_width_in_luma_samples = FFALIGN(base_ctx->surface_width,
320  ctx->res_limits.SubregionBlockPixelsSize);
321  sps->pic_height_in_luma_samples = FFALIGN(base_ctx->surface_height,
322  ctx->res_limits.SubregionBlockPixelsSize);
323 
324  if (avctx->width != sps->pic_width_in_luma_samples ||
325  avctx->height != sps->pic_height_in_luma_samples) {
326  sps->conformance_window_flag = 1;
327  sps->conf_win_left_offset = 0;
328  sps->conf_win_right_offset =
329  (sps->pic_width_in_luma_samples - avctx->width) >> desc->log2_chroma_w;
330  sps->conf_win_top_offset = 0;
331  sps->conf_win_bottom_offset =
332  (sps->pic_height_in_luma_samples - avctx->height) >> desc->log2_chroma_h;
333  } else {
334  sps->conformance_window_flag = 0;
335  }
336 
337  sps->log2_max_pic_order_cnt_lsb_minus4 = ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4;
338 
339  sps->log2_min_luma_coding_block_size_minus3 = (uint8_t)(av_log2(min_cu_size) - 3);
340  sps->log2_diff_max_min_luma_coding_block_size = (uint8_t)(av_log2(max_cu_size) - av_log2(min_cu_size));
341  sps->log2_min_luma_transform_block_size_minus2 = (uint8_t)(av_log2(min_tu_size) - 2);
342  sps->log2_diff_max_min_luma_transform_block_size = (uint8_t)(av_log2(max_tu_size) - av_log2(min_tu_size));
343 
344  sps->max_transform_hierarchy_depth_inter = ctx->codec_conf.pHEVCConfig->max_transform_hierarchy_depth_inter;
345  sps->max_transform_hierarchy_depth_intra = ctx->codec_conf.pHEVCConfig->max_transform_hierarchy_depth_intra;
346 
347  sps->amp_enabled_flag = !!(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
348  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_USE_ASYMETRIC_MOTION_PARTITION);
349  sps->sample_adaptive_offset_enabled_flag = !!(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
350  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_SAO_FILTER);
351 
352  pps->cabac_init_present_flag = 1;
353 
354  pps->init_qp_minus26 = 0;
355 
356  pps->transform_skip_enabled_flag = !!(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
357  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_TRANSFORM_SKIPPING);
358 
359  pps->pps_slice_chroma_qp_offsets_present_flag = 1;
360 
361  pps->tiles_enabled_flag = 0; // no tiling in D3D12
362 
363  pps->pps_loop_filter_across_slices_enabled_flag = !(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
364  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_DISABLE_LOOP_FILTER_ACROSS_SLICES);
365 
366  pps->deblocking_filter_control_present_flag = 1;
367 
368  return 0;
369 }
370 
372 {
373  int i;
374  HRESULT hr;
375  uint8_t min_cu_size, max_cu_size;
376  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
378  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC *config;
379  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC hevc_caps;
380 
381  D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT codec_caps = {
382  .NodeIndex = 0,
383  .Codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
384  .Profile = ctx->profile->d3d12_profile,
385  .CodecSupportLimits.DataSize = sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC),
386  };
387 
388  for (i = 0; i < FF_ARRAY_ELEMS(hevc_config_support_sets); i++) {
389  hevc_caps = hevc_config_support_sets[i];
390  codec_caps.CodecSupportLimits.pHEVCSupport = &hevc_caps;
391  hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT,
392  &codec_caps, sizeof(codec_caps));
393  if (SUCCEEDED(hr) && codec_caps.IsSupported)
394  break;
395  }
396 
398  av_log(avctx, AV_LOG_ERROR, "Unsupported codec configuration\n");
399  return AVERROR(EINVAL);
400  }
401 
402  ctx->codec_conf.DataSize = sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC);
403  ctx->codec_conf.pHEVCConfig = av_mallocz(ctx->codec_conf.DataSize);
404  if (!ctx->codec_conf.pHEVCConfig)
405  return AVERROR(ENOMEM);
406 
407  config = ctx->codec_conf.pHEVCConfig;
408 
409  config->ConfigurationFlags = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_NONE;
410  config->MinLumaCodingUnitSize = hevc_caps.MinLumaCodingUnitSize;
411  config->MaxLumaCodingUnitSize = hevc_caps.MaxLumaCodingUnitSize;
412  config->MinLumaTransformUnitSize = hevc_caps.MinLumaTransformUnitSize;
413  config->MaxLumaTransformUnitSize = hevc_caps.MaxLumaTransformUnitSize;
414  config->max_transform_hierarchy_depth_inter = hevc_caps.max_transform_hierarchy_depth_inter;
415  config->max_transform_hierarchy_depth_intra = hevc_caps.max_transform_hierarchy_depth_intra;
416 
417  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_ASYMETRIC_MOTION_PARTITION_SUPPORT ||
418  hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_ASYMETRIC_MOTION_PARTITION_REQUIRED)
419  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_USE_ASYMETRIC_MOTION_PARTITION;
420 
421  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_SAO_FILTER_SUPPORT)
422  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_SAO_FILTER;
423 
424  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_DISABLING_LOOP_FILTER_ACROSS_SLICES_SUPPORT)
425  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_DISABLE_LOOP_FILTER_ACROSS_SLICES;
426 
427  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_TRANSFORM_SKIP_SUPPORT)
428  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_TRANSFORM_SKIPPING;
429 
430  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_P_FRAMES_IMPLEMENTED_AS_LOW_DELAY_B_FRAMES)
431  ctx->bi_not_empty = 1;
432 
433  // block sizes
434  min_cu_size = d3d12va_encode_hevc_map_cusize(hevc_caps.MinLumaCodingUnitSize);
435  max_cu_size = d3d12va_encode_hevc_map_cusize(hevc_caps.MaxLumaCodingUnitSize);
436 
437  av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, "
438  "min CB size %dx%d.\n", max_cu_size, max_cu_size,
439  min_cu_size, min_cu_size);
440 
441  base_ctx->surface_width = FFALIGN(avctx->width, min_cu_size);
442  base_ctx->surface_height = FFALIGN(avctx->height, min_cu_size);
443 
444  return 0;
445 }
446 
448 {
449  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
451  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
452  int fixed_qp_idr, fixed_qp_p, fixed_qp_b;
453  int err;
454 
455  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
456  if (err < 0)
457  return err;
458 
459  // Rate control
460  if (ctx->rc.Mode == D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP) {
461  D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP *cqp_ctl;
462  fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
463  if (avctx->i_quant_factor > 0.0)
464  fixed_qp_idr = av_clip((avctx->i_quant_factor * fixed_qp_p +
465  avctx->i_quant_offset) + 0.5, 1, 51);
466  else
467  fixed_qp_idr = fixed_qp_p;
468  if (avctx->b_quant_factor > 0.0)
469  fixed_qp_b = av_clip((avctx->b_quant_factor * fixed_qp_p +
470  avctx->b_quant_offset) + 0.5, 1, 51);
471  else
472  fixed_qp_b = fixed_qp_p;
473 
474  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
475  "%d / %d / %d for IDR- / P- / B-frames.\n",
476  fixed_qp_idr, fixed_qp_p, fixed_qp_b);
477 
478  ctx->rc.ConfigParams.DataSize = sizeof(D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP);
479  cqp_ctl = av_mallocz(ctx->rc.ConfigParams.DataSize);
480  if (!cqp_ctl)
481  return AVERROR(ENOMEM);
482 
483  cqp_ctl->ConstantQP_FullIntracodedFrame = fixed_qp_idr;
484  cqp_ctl->ConstantQP_InterPredictedFrame_PrevRefOnly = fixed_qp_p;
485  cqp_ctl->ConstantQP_InterPredictedFrame_BiDirectionalRef = fixed_qp_b;
486 
487  ctx->rc.ConfigParams.pConfiguration_CQP = cqp_ctl;
488  }
489 
490  // GOP
491  ctx->gop.DataSize = sizeof(D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_HEVC);
492  ctx->gop.pHEVCGroupOfPictures = av_mallocz(ctx->gop.DataSize);
493  if (!ctx->gop.pHEVCGroupOfPictures)
494  return AVERROR(ENOMEM);
495 
496  ctx->gop.pHEVCGroupOfPictures->GOPLength = base_ctx->gop_size;
497  ctx->gop.pHEVCGroupOfPictures->PPicturePeriod = base_ctx->b_per_p + 1;
498  // Power of 2
499  if (base_ctx->gop_size & base_ctx->gop_size - 1 == 0)
500  ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4 =
501  FFMAX(av_log2(base_ctx->gop_size) - 4, 0);
502  else
503  ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4 =
504  FFMAX(av_log2(base_ctx->gop_size) - 3, 0);
505 
506  return 0;
507 }
508 
510 {
512  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
513  int i;
514 
515  ctx->level.DataSize = sizeof(D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC);
516  ctx->level.pHEVCLevelSetting = av_mallocz(ctx->level.DataSize);
517  if (!ctx->level.pHEVCLevelSetting)
518  return AVERROR(ENOMEM);
519 
520  for (i = 0; i < FF_ARRAY_ELEMS(hevc_levels); i++) {
521  if (avctx->level == hevc_levels[i].level) {
522  ctx->level.pHEVCLevelSetting->Level = hevc_levels[i].d3d12_level;
523  break;
524  }
525  }
526 
527  if (i == FF_ARRAY_ELEMS(hevc_levels)) {
528  av_log(avctx, AV_LOG_ERROR, "Invalid level %d.\n", avctx->level);
529  return AVERROR(EINVAL);
530  }
531 
532  ctx->level.pHEVCLevelSetting->Tier = priv->units.raw_vps.profile_tier_level.general_tier_flag == 0 ?
533  D3D12_VIDEO_ENCODER_TIER_HEVC_MAIN :
534  D3D12_VIDEO_ENCODER_TIER_HEVC_HIGH;
535 
536  return 0;
537 }
538 
540 {
541  if (!pic->pic_ctl.pHEVCPicData)
542  return;
543 
544  av_freep(&pic->pic_ctl.pHEVCPicData->pList0ReferenceFrames);
545  av_freep(&pic->pic_ctl.pHEVCPicData->pList1ReferenceFrames);
546  av_freep(&pic->pic_ctl.pHEVCPicData->pReferenceFramesReconPictureDescriptors);
547  av_freep(&pic->pic_ctl.pHEVCPicData);
548 }
549 
551  FFHWBaseEncodePicture *base_pic)
552 {
553  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
554  D3D12VAEncodePicture *pic = base_pic->priv;
555  D3D12VAEncodeHEVCPicture *hpic = base_pic->codec_priv;
556  FFHWBaseEncodePicture *prev = base_pic->prev;
557  D3D12VAEncodeHEVCPicture *hprev = prev ? prev->codec_priv : NULL;
558  D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC *pd = NULL;
559  UINT *ref_list0 = NULL, *ref_list1 = NULL;
560  int i, idx = 0;
561 
562  pic->pic_ctl.DataSize = sizeof(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_HEVC);
563  pic->pic_ctl.pHEVCPicData = av_mallocz(pic->pic_ctl.DataSize);
564  if (!pic->pic_ctl.pHEVCPicData)
565  return AVERROR(ENOMEM);
566 
567  if (base_pic->type == FF_HW_PICTURE_TYPE_IDR) {
568  av_assert0(base_pic->display_order == base_pic->encode_order);
569  hpic->last_idr_frame = base_pic->display_order;
570  } else {
571  av_assert0(prev);
572  hpic->last_idr_frame = hprev->last_idr_frame;
573  }
574  hpic->pic_order_cnt = base_pic->display_order - hpic->last_idr_frame;
575 
576  switch(base_pic->type) {
578  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_IDR_FRAME;
579  break;
581  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_I_FRAME;
582  break;
584  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_P_FRAME;
585  break;
587  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_B_FRAME;
588  break;
589  default:
590  av_assert0(0 && "invalid picture type");
591  }
592 
593  pic->pic_ctl.pHEVCPicData->slice_pic_parameter_set_id = 0;
594  pic->pic_ctl.pHEVCPicData->PictureOrderCountNumber = hpic->pic_order_cnt;
595 
596  if (base_pic->type == FF_HW_PICTURE_TYPE_P || base_pic->type == FF_HW_PICTURE_TYPE_B) {
597  pd = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*pd));
598  if (!pd)
599  return AVERROR(ENOMEM);
600 
601  ref_list0 = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*ref_list0));
602  if (!ref_list0)
603  return AVERROR(ENOMEM);
604 
605  pic->pic_ctl.pHEVCPicData->List0ReferenceFramesCount = base_pic->nb_refs[0];
606  for (i = 0; i < base_pic->nb_refs[0]; i++) {
607  FFHWBaseEncodePicture *ref = base_pic->refs[0][i];
609 
610  av_assert0(ref && ref->encode_order < base_pic->encode_order);
611  href = ref->codec_priv;
612 
613  ref_list0[i] = idx;
614  pd[idx].ReconstructedPictureResourceIndex = idx;
615  pd[idx].IsRefUsedByCurrentPic = TRUE;
616  pd[idx].PictureOrderCountNumber = href->pic_order_cnt;
617  idx++;
618  }
619  }
620 
621  if (base_pic->type == FF_HW_PICTURE_TYPE_B) {
622  ref_list1 = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*ref_list1));
623  if (!ref_list1)
624  return AVERROR(ENOMEM);
625 
626  pic->pic_ctl.pHEVCPicData->List1ReferenceFramesCount = base_pic->nb_refs[1];
627  for (i = 0; i < base_pic->nb_refs[1]; i++) {
628  FFHWBaseEncodePicture *ref = base_pic->refs[1][i];
630 
631  av_assert0(ref && ref->encode_order < base_pic->encode_order);
632  href = ref->codec_priv;
633 
634  ref_list1[i] = idx;
635  pd[idx].ReconstructedPictureResourceIndex = idx;
636  pd[idx].IsRefUsedByCurrentPic = TRUE;
637  pd[idx].PictureOrderCountNumber = href->pic_order_cnt;
638  idx++;
639  }
640  }
641 
642  pic->pic_ctl.pHEVCPicData->pList0ReferenceFrames = ref_list0;
643  pic->pic_ctl.pHEVCPicData->pList1ReferenceFrames = ref_list1;
644  pic->pic_ctl.pHEVCPicData->ReferenceFramesReconPictureDescriptorsCount = idx;
645  pic->pic_ctl.pHEVCPicData->pReferenceFramesReconPictureDescriptors = pd;
646 
647  // Process ROI side data if present and supported
648  if (base_ctx->roi_allowed && pic->qp_map && pic->qp_map_size > 0) {
649  pic->pic_ctl.pHEVCPicData->QPMapValuesCount = pic->qp_map_size;
650  pic->pic_ctl.pHEVCPicData->pRateControlQPMap = (INT8 *)pic->qp_map;
651  }
652 
653  return 0;
654 }
655 
658 
659  .d3d12_codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
660 
661  .flags = FF_HW_FLAG_B_PICTURES |
664 
665  .default_quality = 25,
666 
667  .get_encoder_caps = &d3d12va_encode_hevc_get_encoder_caps,
668 
669  .configure = &d3d12va_encode_hevc_configure,
670 
671  .set_level = &d3d12va_encode_hevc_set_level,
672 
673  .picture_priv_data_size = sizeof(D3D12VAEncodeHEVCPicture),
674 
675  .init_sequence_params = &d3d12va_encode_hevc_init_sequence_params,
676 
677  .init_picture_params = &d3d12va_encode_hevc_init_picture_params,
678 
679  .free_picture_params = &d3d12va_encode_hevc_free_picture_params,
680 
682 };
683 
685 {
687  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
688 
689  ctx->codec = &d3d12va_encode_type_hevc;
690 
691  if (avctx->profile == AV_PROFILE_UNKNOWN)
692  avctx->profile = priv->profile;
693  if (avctx->level == AV_LEVEL_UNKNOWN)
694  avctx->level = priv->level;
695 
696  if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
697  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
698  "in 8-bit unsigned integer.\n", avctx->level);
699  return AVERROR(EINVAL);
700  }
701 
702  if (priv->qp > 0)
703  ctx->explicit_qp = priv->qp;
704 
705  return ff_d3d12va_encode_init(avctx);
706 }
707 
709 {
710  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
711 
712  ff_cbs_fragment_free(&priv->current_access_unit);
713  ff_cbs_close(&priv->cbc);
714 
715  av_freep(&priv->common.codec_conf.pHEVCConfig);
716  av_freep(&priv->common.gop.pHEVCGroupOfPictures);
717  av_freep(&priv->common.level.pHEVCLevelSetting);
718 
719  return ff_d3d12va_encode_close(avctx);
720 }
721 
722 #define OFFSET(x) offsetof(D3D12VAEncodeHEVCContext, x)
723 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
728 
729  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
730  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
731 
732  { "profile", "Set profile (general_profile_idc)",
734  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
735 
736 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
737  { .i64 = value }, 0, 0, FLAGS, "profile"
738  { PROFILE("main", AV_PROFILE_HEVC_MAIN) },
739  { PROFILE("main10", AV_PROFILE_HEVC_MAIN_10) },
740 #undef PROFILE
741 
742  { "tier", "Set tier (general_tier_flag)",
743  OFFSET(unit_opts.tier), AV_OPT_TYPE_INT,
744  { .i64 = 0 }, 0, 1, FLAGS, "tier" },
745  { "main", NULL, 0, AV_OPT_TYPE_CONST,
746  { .i64 = 0 }, 0, 0, FLAGS, "tier" },
747  { "high", NULL, 0, AV_OPT_TYPE_CONST,
748  { .i64 = 1 }, 0, 0, FLAGS, "tier" },
749 
750  { "level", "Set level (general_level_idc)",
752  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
753 
754 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
755  { .i64 = value }, 0, 0, FLAGS, "level"
756  { LEVEL("1", 30) },
757  { LEVEL("2", 60) },
758  { LEVEL("2.1", 63) },
759  { LEVEL("3", 90) },
760  { LEVEL("3.1", 93) },
761  { LEVEL("4", 120) },
762  { LEVEL("4.1", 123) },
763  { LEVEL("5", 150) },
764  { LEVEL("5.1", 153) },
765  { LEVEL("5.2", 156) },
766  { LEVEL("6", 180) },
767  { LEVEL("6.1", 183) },
768  { LEVEL("6.2", 186) },
769 #undef LEVEL
770 
771  { NULL },
772 };
773 
775  { "b", "0" },
776  { "bf", "2" },
777  { "g", "120" },
778  { "i_qfactor", "1" },
779  { "i_qoffset", "0" },
780  { "b_qfactor", "1" },
781  { "b_qoffset", "0" },
782  { "qmin", "-1" },
783  { "qmax", "-1" },
784  { "refs", "0" },
785  { NULL },
786 };
787 
789  .class_name = "hevc_d3d12va",
790  .item_name = av_default_item_name,
791  .option = d3d12va_encode_hevc_options,
792  .version = LIBAVUTIL_VERSION_INT,
793 };
794 
796  .p.name = "hevc_d3d12va",
797  CODEC_LONG_NAME("D3D12VA hevc encoder"),
798  .p.type = AVMEDIA_TYPE_VIDEO,
799  .p.id = AV_CODEC_ID_HEVC,
800  .priv_data_size = sizeof(D3D12VAEncodeHEVCContext),
803  .close = &d3d12va_encode_hevc_close,
804  .p.priv_class = &d3d12va_encode_hevc_class,
805  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
807  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
809  .defaults = d3d12va_encode_hevc_defaults,
811  .hw_configs = ff_d3d12va_encode_hw_configs,
812  .p.wrapper_name = "d3d12va",
813 };
cbs.h
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:392
level
uint8_t level
Definition: svq3.c:208
av_clip
#define av_clip
Definition: common.h:100
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
d3d12va_encode_hevc_write_sequence_header
static int d3d12va_encode_hevc_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: d3d12va_encode_hevc.c:207
H265RawProfileTierLevel::general_level_idc
uint8_t general_level_idc
Definition: cbs_h265.h:61
FFHWBaseEncodePicture::priv
void * priv
Definition: hw_base_encode.h:63
FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_I
Definition: hw_base_encode.h:40
d3d12va_encode_hevc_init_sequence_params
static int d3d12va_encode_hevc_init_sequence_params(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:233
FFHWBaseEncodePicture::codec_priv
void * codec_priv
Definition: hw_base_encode.h:65
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:130
int64_t
long long int64_t
Definition: coverity.c:34
D3D12VAEncodeHEVCLevel::d3d12_level
D3D12_VIDEO_ENCODER_LEVELS_HEVC d3d12_level
Definition: d3d12va_encode_hevc.c:60
FFHWBaseEncodeH265::raw_vps
H265RawVPS raw_vps
Definition: hw_base_encode_h265.h:26
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:159
pixdesc.h
d3d12va_encode_hevc_class
static const AVClass d3d12va_encode_hevc_class
Definition: d3d12va_encode_hevc.c:788
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
AVOption
AVOption.
Definition: opt.h:429
D3D12VAEncodeHEVCPicture::last_idr_frame
int64_t last_idr_frame
Definition: d3d12va_encode_hevc.c:39
d3d12va_encode.h
data
const char data[16]
Definition: mxf.c:149
d3d12va_encode_hevc_add_nal
static int d3d12va_encode_hevc_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: d3d12va_encode_hevc.c:189
d3d12va_encode_hevc_map_cusize
static uint8_t d3d12va_encode_hevc_map_cusize(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE cusize)
Definition: d3d12va_encode_hevc.c:139
AVCodecContext::b_quant_offset
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:793
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
FFCodec
Definition: codec_internal.h:127
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
d3d12va_encode_hevc_write_access_unit
static int d3d12va_encode_hevc_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
Definition: d3d12va_encode_hevc.c:163
D3D12VAEncodePicture::qp_map_size
int qp_map_size
Definition: d3d12va_encode.h:63
cbs_h265.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
FF_HW_FLAG_B_PICTURES
@ FF_HW_FLAG_B_PICTURES
Definition: hw_base_encode.h:53
D3D12VAEncodeHEVCContext
Definition: d3d12va_encode_hevc.c:42
tf_sess_config.config
config
Definition: tf_sess_config.py:33
H265RawSPS
Definition: cbs_h265.h:245
H265RawPPS
Definition: cbs_h265.h:356
FFHWBaseEncodeContext
Definition: hw_base_encode.h:122
d3d12va_encode_hevc_map_tusize
static uint8_t d3d12va_encode_hevc_map_tusize(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE tusize)
Definition: d3d12va_encode_hevc.c:151
D3D12VAEncodeHEVCContext::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: d3d12va_encode_hevc.c:55
ff_d3d12va_encode_hw_configs
const AVCodecHWConfigInternal *const ff_d3d12va_encode_hw_configs[]
Definition: d3d12va_encode.c:37
AVCodecContext::i_quant_factor
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
Definition: avcodec.h:802
FFCodecDefault
Definition: codec_internal.h:96
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
FFHWBaseEncodePicture::type
int type
Definition: hw_base_encode.h:78
fail
#define fail()
Definition: checkasm.h:216
profile_main10
static const D3D12_VIDEO_ENCODER_PROFILE_HEVC profile_main10
Definition: d3d12va_encode_hevc.c:129
FFHWBaseEncodeH265::raw_pps
H265RawPPS raw_pps
Definition: hw_base_encode_h265.h:28
ff_hw_base_encode_init_params_h265
int ff_hw_base_encode_init_params_h265(FFHWBaseEncodeContext *base_ctx, AVCodecContext *avctx, FFHWBaseEncodeH265 *common, FFHWBaseEncodeH265Opts *opts)
Definition: hw_base_encode_h265.c:26
D3D12VAEncodeHEVCContext::qp
int qp
Definition: d3d12va_encode_hevc.c:46
D3D12VA_ENCODE_RC_OPTIONS
#define D3D12VA_ENCODE_RC_OPTIONS
Definition: d3d12va_encode.h:430
D3D12VAEncodeHEVCContext::level
int level
Definition: d3d12va_encode_hevc.c:48
d3d12va_encode_hevc_free_picture_params
static void d3d12va_encode_hevc_free_picture_params(D3D12VAEncodePicture *pic)
Definition: d3d12va_encode_hevc.c:539
d3d12va_encode_hevc_close
static int d3d12va_encode_hevc_close(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:708
D3D12VAEncodeHEVCContext::common
D3D12VAEncodeContext common
Definition: d3d12va_encode_hevc.c:43
FFHWBaseEncodePicture::prev
struct FFHWBaseEncodePicture * prev
Definition: hw_base_encode.h:101
d3d12va_encode_hevc_get_encoder_caps
static int d3d12va_encode_hevc_get_encoder_caps(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:371
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
main
int main
Definition: dovi_rpuenc.c:38
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
D3D12VA_ENCODE_COMMON_OPTIONS
#define D3D12VA_ENCODE_COMMON_OPTIONS
Definition: d3d12va_encode.h:396
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:142
H265RawVPS::profile_tier_level
H265RawProfileTierLevel profile_tier_level
Definition: cbs_h265.h:195
hevc_config_support_sets
static const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC hevc_config_support_sets[]
Definition: d3d12va_encode_hevc.c:63
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:144
D3D12VAEncodeHEVCPicture
Definition: d3d12va_encode_hevc.c:37
FLAGS
#define FLAGS
Definition: d3d12va_encode_hevc.c:723
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
D3D12VAEncodeHEVCContext::cbc
CodedBitstreamContext * cbc
Definition: d3d12va_encode_hevc.c:54
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
AVFormatContext * ctx
Definition: movenc.c:49
PROFILE
#define PROFILE(name, value)
D3D12VAEncodePicture::pic_ctl
D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA pic_ctl
Definition: d3d12va_encode.h:57
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:146
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
h2645data.h
FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_P
Definition: hw_base_encode.h:41
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
FFHWBaseEncodeContext::b_per_p
int b_per_p
Definition: hw_base_encode.h:189
hw_base_encode_h265.h
FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
Definition: hw_base_encode.h:55
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
FFHWBaseEncodeH265Opts
Definition: hw_base_encode_h265.h:33
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:209
d3d12va_encode_hevc_set_level
static int d3d12va_encode_hevc_set_level(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:509
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:367
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
Definition: hw_base_encode.h:58
AVD3D12VAFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_d3d12va.h:172
AV_PIX_FMT_D3D12
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition: pixfmt.h:440
H265RawProfileTierLevel::general_tier_flag
uint8_t general_tier_flag
Definition: cbs_h265.h:38
D3D12VAEncodeHEVCContext::unit_opts
FFHWBaseEncodeH265Opts unit_opts
Definition: d3d12va_encode_hevc.c:52
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1636
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:160
H265RawNALUnitHeader
Definition: cbs_h265.h:30
D3D12VAEncodeContext::codec_conf
D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION codec_conf
Definition: d3d12va_encode.h:264
D3D12VAEncodeHEVCLevel
Definition: d3d12va_encode_hevc.c:58
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
codec_internal.h
ff_d3d12va_encode_init
int ff_d3d12va_encode_init(AVCodecContext *avctx)
Definition: d3d12va_encode.c:1788
FFHWBaseEncodePicture::nb_refs
int nb_refs[MAX_REFERENCE_LIST_NUM]
Definition: hw_base_encode.h:97
MAX_DPB_SIZE
#define MAX_DPB_SIZE
Definition: hw_base_encode.h:26
D3D12VAEncodeProfile
Definition: d3d12va_encode.h:66
D3D12VAEncodeHEVCContext::units
FFHWBaseEncodeH265 units
Definition: d3d12va_encode_hevc.c:51
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:135
D3D12VAEncodeHEVCContext::profile
int profile
Definition: d3d12va_encode_hevc.c:47
FFHWBaseEncodeH265
Definition: hw_base_encode_h265.h:25
d3d12va_encode_hevc_init
static int d3d12va_encode_hevc_init(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:684
h265_profile_level.h
d3d12va_encode_hevc_options
static const AVOption d3d12va_encode_hevc_options[]
Definition: d3d12va_encode_hevc.c:724
header
static const uint8_t header[24]
Definition: sdr2.c:68
FFHWBaseEncodePicture::encode_order
int64_t encode_order
Definition: hw_base_encode.h:70
ff_hevc_d3d12va_encoder
const FFCodec ff_hevc_d3d12va_encoder
Definition: d3d12va_encode_hevc.c:795
FFHWBaseEncodeH265Opts::cu_qp_delta_enabled_flag
int cu_qp_delta_enabled_flag
Definition: hw_base_encode_h265.h:36
d3d12va_encode_hevc_defaults
static const FFCodecDefault d3d12va_encode_hevc_defaults[]
Definition: d3d12va_encode_hevc.c:774
FFHWBaseEncodeContext::roi_allowed
int roi_allowed
Definition: hw_base_encode.h:201
D3D12VAEncodePicture
Definition: d3d12va_encode.h:42
AVCodecContext::b_quant_factor
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
Definition: avcodec.h:786
D3D12VAEncodeContext::level
D3D12_VIDEO_ENCODER_LEVEL_SETTING level
Definition: d3d12va_encode.h:270
D3D12VAEncodePicture::qp_map
void * qp_map
Definition: d3d12va_encode.h:62
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
FFHWBaseEncodeH265Opts::nb_slices
int nb_slices
Definition: hw_base_encode_h265.h:41
d3d12va_encode_hevc_init_picture_params
static int d3d12va_encode_hevc_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic)
Definition: d3d12va_encode_hevc.c:550
common.h
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
FFHWBaseEncodePicture::refs
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
Definition: hw_base_encode.h:98
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
profile
int profile
Definition: mxfenc.c:2297
AVCodecContext::height
int height
Definition: avcodec.h:600
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
avcodec.h
AVD3D12VAFramesContext::format
DXGI_FORMAT format
DXGI_FORMAT format.
Definition: hwcontext_d3d12va.h:177
FFHWBaseEncodeContext::gop_size
int gop_size
Definition: hw_base_encode.h:184
FFHWBaseEncodePicture
Definition: hw_base_encode.h:61
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:153
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
D3D12VAEncodeContext
Definition: d3d12va_encode.h:150
d3d12va_encode_type_hevc
static const D3D12VAEncodeType d3d12va_encode_type_hevc
Definition: d3d12va_encode_hevc.c:656
profile_main
static const D3D12_VIDEO_ENCODER_PROFILE_HEVC profile_main
Definition: d3d12va_encode_hevc.c:128
D3D12VAEncodeHEVCLevel::level
int level
Definition: d3d12va_encode_hevc.c:59
OFFSET
#define OFFSET(x)
Definition: d3d12va_encode_hevc.c:722
FF_HW_PICTURE_TYPE_IDR
@ FF_HW_PICTURE_TYPE_IDR
Definition: hw_base_encode.h:39
FFHWBaseEncodeContext::surface_height
int surface_height
Definition: hw_base_encode.h:141
AVCodecContext
main external API structure.
Definition: avcodec.h:439
write_sequence_header
static int write_sequence_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, uint8_t *data, size_t *data_len)
Definition: vulkan_encode_av1.c:1095
FFHWBaseEncodeH265::raw_sps
H265RawSPS raw_sps
Definition: hw_base_encode_h265.h:27
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1626
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:809
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
D3D_PROFILE_DESC
#define D3D_PROFILE_DESC(name)
Definition: d3d12va_encode_hevc.c:131
pps
uint64_t pps
Definition: dovi_rpuenc.c:36
FFHWBaseEncodeContext::input_frames
AVHWFramesContext * input_frames
Definition: hw_base_encode.h:153
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
FFHWBaseEncodeContext::surface_width
int surface_width
Definition: hw_base_encode.h:140
D3D12VAEncodeContext::gop
D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE gop
Definition: d3d12va_encode.h:268
desc
const char * desc
Definition: libsvtav1.c:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_B
Definition: hw_base_encode.h:42
mem.h
D3D12VAEncodeHEVCPicture::pic_order_cnt
int pic_order_cnt
Definition: d3d12va_encode_hevc.c:38
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
LEVEL
#define LEVEL(name, value)
ff_d3d12va_encode_close
int ff_d3d12va_encode_close(AVCodecContext *avctx)
Definition: d3d12va_encode.c:1931
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
ff_d3d12va_encode_receive_packet
int ff_d3d12va_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: d3d12va_encode.c:1783
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
D3D12VAEncodeType::profiles
const D3D12VAEncodeProfile * profiles
List of supported profiles.
Definition: d3d12va_encode.h:299
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:600
d3d12va_encode_hevc_configure
static int d3d12va_encode_hevc_configure(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:447
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HW_BASE_ENCODE_COMMON_OPTIONS
#define HW_BASE_ENCODE_COMMON_OPTIONS
Definition: hw_base_encode.h:243
D3D12VAEncodeType
Definition: d3d12va_encode.h:295
d3d12va_encode_hevc_profiles
static const D3D12VAEncodeProfile d3d12va_encode_hevc_profiles[]
Definition: d3d12va_encode_hevc.c:133
hwcontext_d3d12va_internal.h
FFHWBaseEncodePicture::display_order
int64_t display_order
Definition: hw_base_encode.h:69
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
hevc_levels
static const D3D12VAEncodeHEVCLevel hevc_levels[]
Definition: d3d12va_encode_hevc.c:112
MAX_PICTURE_REFERENCES
#define MAX_PICTURE_REFERENCES
Definition: hw_base_encode.h:27