FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE,
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  av_log(avctx, AV_LOG_ERROR, "D3D12 video encode on this device requires texture array support, "
283  "but it's not implemented.\n");
284  return AVERROR_PATCHWELCOME;
285  }
286 
288  av_assert0(desc);
289 
290  min_cu_size = d3d12va_encode_hevc_map_cusize(ctx->codec_conf.pHEVCConfig->MinLumaCodingUnitSize);
291  max_cu_size = d3d12va_encode_hevc_map_cusize(ctx->codec_conf.pHEVCConfig->MaxLumaCodingUnitSize);
292  min_tu_size = d3d12va_encode_hevc_map_tusize(ctx->codec_conf.pHEVCConfig->MinLumaTransformUnitSize);
293  max_tu_size = d3d12va_encode_hevc_map_tusize(ctx->codec_conf.pHEVCConfig->MaxLumaTransformUnitSize);
294 
295  // cu_qp_delta always required to be 1 in https://github.com/microsoft/DirectX-Specs/blob/master/d3d/D3D12VideoEncoding.md
297  priv->unit_opts.nb_slices = 1;
298 
299  err = ff_hw_base_encode_init_params_h265(base_ctx, avctx,
300  &priv->units, &priv->unit_opts);
301  if (err < 0)
302  return err;
303 
305 
306  av_assert0(ctx->res_limits.SubregionBlockPixelsSize % min_cu_size == 0);
307 
308  sps->pic_width_in_luma_samples = FFALIGN(base_ctx->surface_width,
309  ctx->res_limits.SubregionBlockPixelsSize);
310  sps->pic_height_in_luma_samples = FFALIGN(base_ctx->surface_height,
311  ctx->res_limits.SubregionBlockPixelsSize);
312 
313  if (avctx->width != sps->pic_width_in_luma_samples ||
314  avctx->height != sps->pic_height_in_luma_samples) {
315  sps->conformance_window_flag = 1;
316  sps->conf_win_left_offset = 0;
317  sps->conf_win_right_offset =
318  (sps->pic_width_in_luma_samples - avctx->width) >> desc->log2_chroma_w;
319  sps->conf_win_top_offset = 0;
320  sps->conf_win_bottom_offset =
321  (sps->pic_height_in_luma_samples - avctx->height) >> desc->log2_chroma_h;
322  } else {
323  sps->conformance_window_flag = 0;
324  }
325 
326  sps->log2_max_pic_order_cnt_lsb_minus4 = ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4;
327 
328  sps->log2_min_luma_coding_block_size_minus3 = (uint8_t)(av_log2(min_cu_size) - 3);
329  sps->log2_diff_max_min_luma_coding_block_size = (uint8_t)(av_log2(max_cu_size) - av_log2(min_cu_size));
330  sps->log2_min_luma_transform_block_size_minus2 = (uint8_t)(av_log2(min_tu_size) - 2);
331  sps->log2_diff_max_min_luma_transform_block_size = (uint8_t)(av_log2(max_tu_size) - av_log2(min_tu_size));
332 
333  sps->max_transform_hierarchy_depth_inter = ctx->codec_conf.pHEVCConfig->max_transform_hierarchy_depth_inter;
334  sps->max_transform_hierarchy_depth_intra = ctx->codec_conf.pHEVCConfig->max_transform_hierarchy_depth_intra;
335 
336  sps->amp_enabled_flag = !!(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
337  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_USE_ASYMETRIC_MOTION_PARTITION);
338  sps->sample_adaptive_offset_enabled_flag = !!(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
339  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_SAO_FILTER);
340 
341  pps->cabac_init_present_flag = 1;
342 
343  pps->init_qp_minus26 = 0;
344 
345  pps->transform_skip_enabled_flag = !!(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
346  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_TRANSFORM_SKIPPING);
347 
348  pps->pps_slice_chroma_qp_offsets_present_flag = 1;
349 
350  pps->tiles_enabled_flag = 0; // no tiling in D3D12
351 
352  pps->pps_loop_filter_across_slices_enabled_flag = !(ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
353  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_DISABLE_LOOP_FILTER_ACROSS_SLICES);
354 
355  pps->deblocking_filter_control_present_flag = 1;
356 
357  return 0;
358 }
359 
361 {
362  int i;
363  HRESULT hr;
364  uint8_t min_cu_size, max_cu_size;
365  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
367  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC *config;
368  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC hevc_caps;
369 
370  D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT codec_caps = {
371  .NodeIndex = 0,
372  .Codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
373  .Profile = ctx->profile->d3d12_profile,
374  .CodecSupportLimits.DataSize = sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC),
375  };
376 
377  for (i = 0; i < FF_ARRAY_ELEMS(hevc_config_support_sets); i++) {
378  hevc_caps = hevc_config_support_sets[i];
379  codec_caps.CodecSupportLimits.pHEVCSupport = &hevc_caps;
380  hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT,
381  &codec_caps, sizeof(codec_caps));
382  if (SUCCEEDED(hr) && codec_caps.IsSupported)
383  break;
384  }
385 
387  av_log(avctx, AV_LOG_ERROR, "Unsupported codec configuration\n");
388  return AVERROR(EINVAL);
389  }
390 
391  ctx->codec_conf.DataSize = sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC);
392  ctx->codec_conf.pHEVCConfig = av_mallocz(ctx->codec_conf.DataSize);
393  if (!ctx->codec_conf.pHEVCConfig)
394  return AVERROR(ENOMEM);
395 
396  config = ctx->codec_conf.pHEVCConfig;
397 
398  config->ConfigurationFlags = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_NONE;
399  config->MinLumaCodingUnitSize = hevc_caps.MinLumaCodingUnitSize;
400  config->MaxLumaCodingUnitSize = hevc_caps.MaxLumaCodingUnitSize;
401  config->MinLumaTransformUnitSize = hevc_caps.MinLumaTransformUnitSize;
402  config->MaxLumaTransformUnitSize = hevc_caps.MaxLumaTransformUnitSize;
403  config->max_transform_hierarchy_depth_inter = hevc_caps.max_transform_hierarchy_depth_inter;
404  config->max_transform_hierarchy_depth_intra = hevc_caps.max_transform_hierarchy_depth_intra;
405 
406  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_ASYMETRIC_MOTION_PARTITION_SUPPORT ||
407  hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_ASYMETRIC_MOTION_PARTITION_REQUIRED)
408  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_USE_ASYMETRIC_MOTION_PARTITION;
409 
410  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_SAO_FILTER_SUPPORT)
411  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_SAO_FILTER;
412 
413  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_DISABLING_LOOP_FILTER_ACROSS_SLICES_SUPPORT)
414  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_DISABLE_LOOP_FILTER_ACROSS_SLICES;
415 
416  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_TRANSFORM_SKIP_SUPPORT)
417  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_TRANSFORM_SKIPPING;
418 
419  if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_P_FRAMES_IMPLEMENTED_AS_LOW_DELAY_B_FRAMES)
420  ctx->bi_not_empty = 1;
421 
422  // block sizes
423  min_cu_size = d3d12va_encode_hevc_map_cusize(hevc_caps.MinLumaCodingUnitSize);
424  max_cu_size = d3d12va_encode_hevc_map_cusize(hevc_caps.MaxLumaCodingUnitSize);
425 
426  av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, "
427  "min CB size %dx%d.\n", max_cu_size, max_cu_size,
428  min_cu_size, min_cu_size);
429 
430  base_ctx->surface_width = FFALIGN(avctx->width, min_cu_size);
431  base_ctx->surface_height = FFALIGN(avctx->height, min_cu_size);
432 
433  return 0;
434 }
435 
437 {
438  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
440  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
441  int fixed_qp_idr, fixed_qp_p, fixed_qp_b;
442  int err;
443 
444  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
445  if (err < 0)
446  return err;
447 
448  // Rate control
449  if (ctx->rc.Mode == D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP) {
450  D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP *cqp_ctl;
451  fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
452  if (avctx->i_quant_factor > 0.0)
453  fixed_qp_idr = av_clip((avctx->i_quant_factor * fixed_qp_p +
454  avctx->i_quant_offset) + 0.5, 1, 51);
455  else
456  fixed_qp_idr = fixed_qp_p;
457  if (avctx->b_quant_factor > 0.0)
458  fixed_qp_b = av_clip((avctx->b_quant_factor * fixed_qp_p +
459  avctx->b_quant_offset) + 0.5, 1, 51);
460  else
461  fixed_qp_b = fixed_qp_p;
462 
463  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
464  "%d / %d / %d for IDR- / P- / B-frames.\n",
465  fixed_qp_idr, fixed_qp_p, fixed_qp_b);
466 
467  ctx->rc.ConfigParams.DataSize = sizeof(D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP);
468  cqp_ctl = av_mallocz(ctx->rc.ConfigParams.DataSize);
469  if (!cqp_ctl)
470  return AVERROR(ENOMEM);
471 
472  cqp_ctl->ConstantQP_FullIntracodedFrame = fixed_qp_idr;
473  cqp_ctl->ConstantQP_InterPredictedFrame_PrevRefOnly = fixed_qp_p;
474  cqp_ctl->ConstantQP_InterPredictedFrame_BiDirectionalRef = fixed_qp_b;
475 
476  ctx->rc.ConfigParams.pConfiguration_CQP = cqp_ctl;
477  }
478 
479  // GOP
480  ctx->gop.DataSize = sizeof(D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_HEVC);
481  ctx->gop.pHEVCGroupOfPictures = av_mallocz(ctx->gop.DataSize);
482  if (!ctx->gop.pHEVCGroupOfPictures)
483  return AVERROR(ENOMEM);
484 
485  ctx->gop.pHEVCGroupOfPictures->GOPLength = base_ctx->gop_size;
486  ctx->gop.pHEVCGroupOfPictures->PPicturePeriod = base_ctx->b_per_p + 1;
487  // Power of 2
488  if (base_ctx->gop_size & base_ctx->gop_size - 1 == 0)
489  ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4 =
490  FFMAX(av_log2(base_ctx->gop_size) - 4, 0);
491  else
492  ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4 =
493  FFMAX(av_log2(base_ctx->gop_size) - 3, 0);
494 
495  return 0;
496 }
497 
499 {
501  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
502  int i;
503 
504  ctx->level.DataSize = sizeof(D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC);
505  ctx->level.pHEVCLevelSetting = av_mallocz(ctx->level.DataSize);
506  if (!ctx->level.pHEVCLevelSetting)
507  return AVERROR(ENOMEM);
508 
509  for (i = 0; i < FF_ARRAY_ELEMS(hevc_levels); i++) {
510  if (avctx->level == hevc_levels[i].level) {
511  ctx->level.pHEVCLevelSetting->Level = hevc_levels[i].d3d12_level;
512  break;
513  }
514  }
515 
516  if (i == FF_ARRAY_ELEMS(hevc_levels)) {
517  av_log(avctx, AV_LOG_ERROR, "Invalid level %d.\n", avctx->level);
518  return AVERROR(EINVAL);
519  }
520 
521  ctx->level.pHEVCLevelSetting->Tier = priv->units.raw_vps.profile_tier_level.general_tier_flag == 0 ?
522  D3D12_VIDEO_ENCODER_TIER_HEVC_MAIN :
523  D3D12_VIDEO_ENCODER_TIER_HEVC_HIGH;
524 
525  return 0;
526 }
527 
529 {
530  if (!pic->pic_ctl.pHEVCPicData)
531  return;
532 
533  av_freep(&pic->pic_ctl.pHEVCPicData->pList0ReferenceFrames);
534  av_freep(&pic->pic_ctl.pHEVCPicData->pList1ReferenceFrames);
535  av_freep(&pic->pic_ctl.pHEVCPicData->pReferenceFramesReconPictureDescriptors);
536  av_freep(&pic->pic_ctl.pHEVCPicData);
537 }
538 
540  FFHWBaseEncodePicture *base_pic)
541 {
542  D3D12VAEncodePicture *pic = base_pic->priv;
543  D3D12VAEncodeHEVCPicture *hpic = base_pic->codec_priv;
544  FFHWBaseEncodePicture *prev = base_pic->prev;
545  D3D12VAEncodeHEVCPicture *hprev = prev ? prev->codec_priv : NULL;
546  D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC *pd = NULL;
547  UINT *ref_list0 = NULL, *ref_list1 = NULL;
548  int i, idx = 0;
549 
550  pic->pic_ctl.DataSize = sizeof(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_HEVC);
551  pic->pic_ctl.pHEVCPicData = av_mallocz(pic->pic_ctl.DataSize);
552  if (!pic->pic_ctl.pHEVCPicData)
553  return AVERROR(ENOMEM);
554 
555  if (base_pic->type == FF_HW_PICTURE_TYPE_IDR) {
556  av_assert0(base_pic->display_order == base_pic->encode_order);
557  hpic->last_idr_frame = base_pic->display_order;
558  } else {
559  av_assert0(prev);
560  hpic->last_idr_frame = hprev->last_idr_frame;
561  }
562  hpic->pic_order_cnt = base_pic->display_order - hpic->last_idr_frame;
563 
564  switch(base_pic->type) {
566  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_IDR_FRAME;
567  break;
569  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_I_FRAME;
570  break;
572  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_P_FRAME;
573  break;
575  pic->pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_B_FRAME;
576  break;
577  default:
578  av_assert0(0 && "invalid picture type");
579  }
580 
581  pic->pic_ctl.pHEVCPicData->slice_pic_parameter_set_id = 0;
582  pic->pic_ctl.pHEVCPicData->PictureOrderCountNumber = hpic->pic_order_cnt;
583 
584  if (base_pic->type == FF_HW_PICTURE_TYPE_P || base_pic->type == FF_HW_PICTURE_TYPE_B) {
585  pd = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*pd));
586  if (!pd)
587  return AVERROR(ENOMEM);
588 
589  ref_list0 = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*ref_list0));
590  if (!ref_list0)
591  return AVERROR(ENOMEM);
592 
593  pic->pic_ctl.pHEVCPicData->List0ReferenceFramesCount = base_pic->nb_refs[0];
594  for (i = 0; i < base_pic->nb_refs[0]; i++) {
595  FFHWBaseEncodePicture *ref = base_pic->refs[0][i];
597 
598  av_assert0(ref && ref->encode_order < base_pic->encode_order);
599  href = ref->codec_priv;
600 
601  ref_list0[i] = idx;
602  pd[idx].ReconstructedPictureResourceIndex = idx;
603  pd[idx].IsRefUsedByCurrentPic = TRUE;
604  pd[idx].PictureOrderCountNumber = href->pic_order_cnt;
605  idx++;
606  }
607  }
608 
609  if (base_pic->type == FF_HW_PICTURE_TYPE_B) {
610  ref_list1 = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*ref_list1));
611  if (!ref_list1)
612  return AVERROR(ENOMEM);
613 
614  pic->pic_ctl.pHEVCPicData->List1ReferenceFramesCount = base_pic->nb_refs[1];
615  for (i = 0; i < base_pic->nb_refs[1]; i++) {
616  FFHWBaseEncodePicture *ref = base_pic->refs[1][i];
618 
619  av_assert0(ref && ref->encode_order < base_pic->encode_order);
620  href = ref->codec_priv;
621 
622  ref_list1[i] = idx;
623  pd[idx].ReconstructedPictureResourceIndex = idx;
624  pd[idx].IsRefUsedByCurrentPic = TRUE;
625  pd[idx].PictureOrderCountNumber = href->pic_order_cnt;
626  idx++;
627  }
628  }
629 
630  pic->pic_ctl.pHEVCPicData->pList0ReferenceFrames = ref_list0;
631  pic->pic_ctl.pHEVCPicData->pList1ReferenceFrames = ref_list1;
632  pic->pic_ctl.pHEVCPicData->ReferenceFramesReconPictureDescriptorsCount = idx;
633  pic->pic_ctl.pHEVCPicData->pReferenceFramesReconPictureDescriptors = pd;
634 
635  return 0;
636 }
637 
640 
641  .d3d12_codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
642 
643  .flags = FF_HW_FLAG_B_PICTURES |
646 
647  .default_quality = 25,
648 
649  .get_encoder_caps = &d3d12va_encode_hevc_get_encoder_caps,
650 
651  .configure = &d3d12va_encode_hevc_configure,
652 
653  .set_level = &d3d12va_encode_hevc_set_level,
654 
655  .picture_priv_data_size = sizeof(D3D12VAEncodeHEVCPicture),
656 
657  .init_sequence_params = &d3d12va_encode_hevc_init_sequence_params,
658 
659  .init_picture_params = &d3d12va_encode_hevc_init_picture_params,
660 
661  .free_picture_params = &d3d12va_encode_hevc_free_picture_params,
662 
663  .write_sequence_header = &d3d12va_encode_hevc_write_sequence_header,
664 };
665 
667 {
669  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
670 
671  ctx->codec = &d3d12va_encode_type_hevc;
672 
673  if (avctx->profile == AV_PROFILE_UNKNOWN)
674  avctx->profile = priv->profile;
675  if (avctx->level == AV_LEVEL_UNKNOWN)
676  avctx->level = priv->level;
677 
678  if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
679  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
680  "in 8-bit unsigned integer.\n", avctx->level);
681  return AVERROR(EINVAL);
682  }
683 
684  if (priv->qp > 0)
685  ctx->explicit_qp = priv->qp;
686 
687  return ff_d3d12va_encode_init(avctx);
688 }
689 
691 {
692  D3D12VAEncodeHEVCContext *priv = avctx->priv_data;
693 
694  ff_cbs_fragment_free(&priv->current_access_unit);
695  ff_cbs_close(&priv->cbc);
696 
697  av_freep(&priv->common.codec_conf.pHEVCConfig);
698  av_freep(&priv->common.gop.pHEVCGroupOfPictures);
699  av_freep(&priv->common.level.pHEVCLevelSetting);
700 
701  return ff_d3d12va_encode_close(avctx);
702 }
703 
704 #define OFFSET(x) offsetof(D3D12VAEncodeHEVCContext, x)
705 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
709 
710  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
711  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
712 
713  { "profile", "Set profile (general_profile_idc)",
715  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
716 
717 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
718  { .i64 = value }, 0, 0, FLAGS, "profile"
719  { PROFILE("main", AV_PROFILE_HEVC_MAIN) },
720  { PROFILE("main10", AV_PROFILE_HEVC_MAIN_10) },
721 #undef PROFILE
722 
723  { "tier", "Set tier (general_tier_flag)",
724  OFFSET(unit_opts.tier), AV_OPT_TYPE_INT,
725  { .i64 = 0 }, 0, 1, FLAGS, "tier" },
726  { "main", NULL, 0, AV_OPT_TYPE_CONST,
727  { .i64 = 0 }, 0, 0, FLAGS, "tier" },
728  { "high", NULL, 0, AV_OPT_TYPE_CONST,
729  { .i64 = 1 }, 0, 0, FLAGS, "tier" },
730 
731  { "level", "Set level (general_level_idc)",
733  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
734 
735 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
736  { .i64 = value }, 0, 0, FLAGS, "level"
737  { LEVEL("1", 30) },
738  { LEVEL("2", 60) },
739  { LEVEL("2.1", 63) },
740  { LEVEL("3", 90) },
741  { LEVEL("3.1", 93) },
742  { LEVEL("4", 120) },
743  { LEVEL("4.1", 123) },
744  { LEVEL("5", 150) },
745  { LEVEL("5.1", 153) },
746  { LEVEL("5.2", 156) },
747  { LEVEL("6", 180) },
748  { LEVEL("6.1", 183) },
749  { LEVEL("6.2", 186) },
750 #undef LEVEL
751 
752  { NULL },
753 };
754 
756  { "b", "0" },
757  { "bf", "2" },
758  { "g", "120" },
759  { "i_qfactor", "1" },
760  { "i_qoffset", "0" },
761  { "b_qfactor", "1" },
762  { "b_qoffset", "0" },
763  { "qmin", "-1" },
764  { "qmax", "-1" },
765  { NULL },
766 };
767 
769  .class_name = "hevc_d3d12va",
770  .item_name = av_default_item_name,
771  .option = d3d12va_encode_hevc_options,
772  .version = LIBAVUTIL_VERSION_INT,
773 };
774 
776  .p.name = "hevc_d3d12va",
777  CODEC_LONG_NAME("D3D12VA hevc encoder"),
778  .p.type = AVMEDIA_TYPE_VIDEO,
779  .p.id = AV_CODEC_ID_HEVC,
780  .priv_data_size = sizeof(D3D12VAEncodeHEVCContext),
783  .close = &d3d12va_encode_hevc_close,
784  .p.priv_class = &d3d12va_encode_hevc_class,
785  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
787  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
789  .defaults = d3d12va_encode_hevc_defaults,
791  .hw_configs = ff_d3d12va_encode_hw_configs,
792  .p.wrapper_name = "d3d12va",
793 };
FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
Definition: hw_base_encode.h:55
cbs.h
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:386
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_IDR
@ FF_HW_PICTURE_TYPE_IDR
Definition: hw_base_encode.h:39
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:3441
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:768
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:785
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
cbs_h265.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
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:36
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:794
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:199
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:323
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:528
d3d12va_encode_hevc_close
static int d3d12va_encode_hevc_close(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:690
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:360
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
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:705
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:55
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
h2645data.h
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:326
FFHWBaseEncodeContext::b_per_p
int b_per_p
Definition: hw_base_encode.h:189
hw_base_encode_h265.h
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
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
FFHWBaseEncodeH265Opts
Definition: hw_base_encode_h265.h:33
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:206
d3d12va_encode_hevc_set_level
static int d3d12va_encode_hevc_set_level(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:498
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:361
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:240
AVD3D12VAFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_d3d12va.h:126
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:1628
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:160
H265RawNALUnitHeader
Definition: cbs_h265.h:30
FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_B
Definition: hw_base_encode.h:42
D3D12VAEncodeContext::codec_conf
D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION codec_conf
Definition: d3d12va_encode.h:243
D3D12VAEncodeHEVCLevel
Definition: d3d12va_encode_hevc.c:58
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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:1393
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:60
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:666
h265_profile_level.h
d3d12va_encode_hevc_options
static const AVOption d3d12va_encode_hevc_options[]
Definition: d3d12va_encode_hevc.c:706
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:775
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:755
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:778
D3D12VAEncodeContext::level
D3D12_VIDEO_ENCODER_LEVEL_SETTING level
Definition: d3d12va_encode.h:249
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:539
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
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
profile
int profile
Definition: mxfenc.c:2276
AVCodecContext::height
int height
Definition: avcodec.h:592
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:131
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:144
FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_P
Definition: hw_base_encode.h:41
d3d12va_encode_type_hevc
static const D3D12VAEncodeType d3d12va_encode_type_hevc
Definition: d3d12va_encode_hevc.c:638
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:704
FFHWBaseEncodeContext::surface_height
int surface_height
Definition: hw_base_encode.h:141
AVCodecContext
main external API structure.
Definition: avcodec.h:431
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:1618
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:801
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
FF_HW_FLAG_B_PICTURES
@ FF_HW_FLAG_B_PICTURES
Definition: hw_base_encode.h:53
D3D12VAEncodeContext::gop
D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE gop
Definition: d3d12va_encode.h:247
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
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:1512
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:1388
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
D3D12VAEncodeType::profiles
const D3D12VAEncodeProfile * profiles
List of supported profiles.
Definition: d3d12va_encode.h:256
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
d3d12va_encode_hevc_configure
static int d3d12va_encode_hevc_configure(AVCodecContext *avctx)
Definition: d3d12va_encode_hevc.c:436
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
Definition: hw_base_encode.h:58
HW_BASE_ENCODE_COMMON_OPTIONS
#define HW_BASE_ENCODE_COMMON_OPTIONS
Definition: hw_base_encode.h:243
D3D12VAEncodeType
Definition: d3d12va_encode.h:252
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
FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_I
Definition: hw_base_encode.h:40
MAX_PICTURE_REFERENCES
#define MAX_PICTURE_REFERENCES
Definition: hw_base_encode.h:27