FFmpeg
d3d12va_encode_h264.c
Go to the documentation of this file.
1 /*
2  * Direct3D 12 HW acceleration video encoder
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 #include "libavutil/opt.h"
21 #include "libavutil/common.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/pixdesc.h"
25 
26 #include "avcodec.h"
27 #include "cbs.h"
28 #include "cbs_h264.h"
29 #include "hw_base_encode_h264.h"
30 #include "h2645data.h"
31 #include "h264_levels.h"
32 #include "codec_internal.h"
33 #include "d3d12va_encode.h"
34 
35 typedef struct D3D12VAEncodeH264Picture {
39 
40 typedef struct D3D12VAEncodeH264Context {
42 
43  // User options.
44  int qp;
45  int profile;
46  int level;
47  int deblock;
49 
50  // Writer structures.
53 
57 
58 typedef struct D3D12VAEncodeH264Level {
59  int level;
60  D3D12_VIDEO_ENCODER_LEVELS_H264 d3d12_level;
62 
64  { 10, D3D12_VIDEO_ENCODER_LEVELS_H264_1 },
65  { 11, D3D12_VIDEO_ENCODER_LEVELS_H264_11 },
66  { 12, D3D12_VIDEO_ENCODER_LEVELS_H264_12 },
67  { 13, D3D12_VIDEO_ENCODER_LEVELS_H264_13 },
68  { 20, D3D12_VIDEO_ENCODER_LEVELS_H264_2 },
69  { 21, D3D12_VIDEO_ENCODER_LEVELS_H264_21 },
70  { 22, D3D12_VIDEO_ENCODER_LEVELS_H264_22 },
71  { 30, D3D12_VIDEO_ENCODER_LEVELS_H264_3 },
72  { 31, D3D12_VIDEO_ENCODER_LEVELS_H264_31 },
73  { 32, D3D12_VIDEO_ENCODER_LEVELS_H264_32 },
74  { 40, D3D12_VIDEO_ENCODER_LEVELS_H264_4 },
75  { 41, D3D12_VIDEO_ENCODER_LEVELS_H264_41 },
76  { 42, D3D12_VIDEO_ENCODER_LEVELS_H264_42 },
77  { 50, D3D12_VIDEO_ENCODER_LEVELS_H264_5 },
78  { 51, D3D12_VIDEO_ENCODER_LEVELS_H264_51 },
79  { 52, D3D12_VIDEO_ENCODER_LEVELS_H264_52 },
80  { 60, D3D12_VIDEO_ENCODER_LEVELS_H264_6 },
81  { 61, D3D12_VIDEO_ENCODER_LEVELS_H264_61 },
82  { 62, D3D12_VIDEO_ENCODER_LEVELS_H264_62 },
83 };
84 
85 static const D3D12_VIDEO_ENCODER_PROFILE_H264 profile_main = D3D12_VIDEO_ENCODER_PROFILE_H264_MAIN;
86 static const D3D12_VIDEO_ENCODER_PROFILE_H264 profile_high = D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH;
87 static const D3D12_VIDEO_ENCODER_PROFILE_H264 profile_high_10 = D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH_10;
88 
89 #define D3D_PROFILE_DESC(name) \
90  { sizeof(D3D12_VIDEO_ENCODER_PROFILE_H264), { .pH264Profile = (D3D12_VIDEO_ENCODER_PROFILE_H264 *)&profile_ ## name } }
92  { AV_PROFILE_H264_MAIN, 8, 3, 1, 1, D3D_PROFILE_DESC(main) },
93  { AV_PROFILE_H264_HIGH, 8, 3, 1, 1, D3D_PROFILE_DESC(high) },
94  { AV_PROFILE_H264_HIGH_10, 10, 3, 1, 1, D3D_PROFILE_DESC(high_10) },
96 };
97 
99  char *data, size_t *data_len,
101 {
102  D3D12VAEncodeH264Context *priv = avctx->priv_data;
103  int err;
104 
105  err = ff_cbs_write_fragment_data(priv->cbc, au);
106  if (err < 0) {
107  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
108  return err;
109  }
110 
111  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
112  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
113  "%zu < %zu.\n", *data_len,
114  8 * au->data_size - au->data_bit_padding);
115  return AVERROR(ENOSPC);
116  }
117 
118  memcpy(data, au->data, au->data_size);
119  *data_len = 8 * au->data_size - au->data_bit_padding;
120 
121  return 0;
122 }
123 
126  void *nal_unit)
127 {
128  H264RawNALUnitHeader *header = nal_unit;
129  int err;
130 
131  err = ff_cbs_insert_unit_content(au, -1,
132  header->nal_unit_type, nal_unit, NULL);
133  if (err < 0) {
134  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
135  "type = %d.\n", header->nal_unit_type);
136  return err;
137  }
138 
139  return 0;
140 }
141 
143  char *data, size_t *data_len)
144 {
145  D3D12VAEncodeH264Context *priv = avctx->priv_data;
147  int err;
148 
149  err = d3d12va_encode_h264_add_nal(avctx, au, &priv->units.raw_sps);
150  if (err < 0)
151  goto fail;
152 
153  err = d3d12va_encode_h264_add_nal(avctx, au, &priv->units.raw_pps);
154  if (err < 0)
155  goto fail;
156 
157  err = d3d12va_encode_h264_write_access_unit(avctx, data, data_len, au);
158 fail:
159  ff_cbs_fragment_reset(au);
160  return err;
161 }
162 
164 {
165  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
167  D3D12VAEncodeH264Context *priv = avctx->priv_data;
168  AVD3D12VAFramesContext *hwctx = base_ctx->input_frames->hwctx;
169  H264RawSPS *sps = &priv->units.raw_sps;
170  H264RawPPS *pps = &priv->units.raw_pps;
171  D3D12_VIDEO_ENCODER_PROFILE_H264 profile = D3D12_VIDEO_ENCODER_PROFILE_H264_MAIN;
172  D3D12_VIDEO_ENCODER_LEVELS_H264 level = { 0 };
173  const AVPixFmtDescriptor *desc;
174  HRESULT hr;
175  int err;
176 
177  D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT support = {
178  .NodeIndex = 0,
179  .Codec = D3D12_VIDEO_ENCODER_CODEC_H264,
180  .InputFormat = hwctx->format,
181  .RateControl = ctx->rc,
182  .IntraRefresh = ctx->intra_refresh.Mode,
183  .SubregionFrameEncoding = D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE_FULL_FRAME,
184  .ResolutionsListCount = 1,
185  .pResolutionList = &ctx->resolution,
186  .CodecGopSequence = ctx->gop,
187  .MaxReferenceFramesInDPB = MAX_DPB_SIZE - 1,
188  .CodecConfiguration = ctx->codec_conf,
189  .SuggestedProfile.DataSize = sizeof(D3D12_VIDEO_ENCODER_PROFILE_H264),
190  .SuggestedProfile.pH264Profile = &profile,
191  .SuggestedLevel.DataSize = sizeof(D3D12_VIDEO_ENCODER_LEVELS_H264),
192  .SuggestedLevel.pH264LevelSetting = &level,
193  .pResolutionDependentSupport = &ctx->res_limits,
194  };
195 
196  hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_SUPPORT,
197  &support, sizeof(support));
198 
199  if (FAILED(hr)) {
200  av_log(avctx, AV_LOG_ERROR, "Failed to check encoder support(%lx).\n", (long)hr);
201  return AVERROR(EINVAL);
202  }
203 
204  if (!(support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK)) {
205  av_log(avctx, AV_LOG_ERROR, "Driver does not support requested features. ValidationFlags: %#x\n",
206  support.ValidationFlags);
207  ff_d3d12va_encode_check_encoder_feature_flags(avctx, support.ValidationFlags);
208  return AVERROR(EINVAL);
209  }
210 
211  if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RECONSTRUCTED_FRAMES_REQUIRE_TEXTURE_ARRAYS) {
212  ctx->is_texture_array = 1;
213  av_log(avctx, AV_LOG_DEBUG, "D3D12 video encode on this device uses texture array mode.\n");
214  }
215 
216  // Check if the configuration with DELTA_QP is supported
217  if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_DELTA_QP_AVAILABLE) {
218  base_ctx->roi_allowed = 1;
219  // Store the QP map region size from resolution limits
220  ctx->qp_map_region_size = ctx->res_limits.QPMapRegionPixelsSize;
221  av_log(avctx, AV_LOG_DEBUG, "ROI encoding is supported via delta QP "
222  "(QP map region size: %d pixels).\n", ctx->qp_map_region_size);
223  } else {
224  base_ctx->roi_allowed = 0;
225  av_log(avctx, AV_LOG_DEBUG, "ROI encoding not supported by hardware for current rate control mode \n");
226  }
227 
228  // Check motion estimation precision mode support
229  if (ctx->me_precision != D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM) {
230  if (!(support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_MOTION_ESTIMATION_PRECISION_MODE_LIMIT_AVAILABLE)) {
231  av_log(avctx, AV_LOG_ERROR, "Hardware does not support motion estimation "
232  "precision mode limits.\n");
233  return AVERROR(ENOTSUP);
234  }
235  av_log(avctx, AV_LOG_VERBOSE, "Hardware supports motion estimation "
236  "precision mode limits.\n");
237  }
238 
240  av_assert0(desc);
241 
242  sps->pic_width_in_mbs_minus1 = ((base_ctx->surface_width + 0x0F) >> 4) - 1;
243  sps->pic_height_in_map_units_minus1 = ((base_ctx->surface_height + 0x0F) >> 4) - 1;
244 
245  priv->unit_opts.mb_width = sps->pic_width_in_mbs_minus1 + 1;
246  priv->unit_opts.mb_height = sps->pic_height_in_map_units_minus1 +1;
247 
248  err = ff_hw_base_encode_init_params_h264(base_ctx, avctx,
249  &priv->units, &priv->unit_opts);
250  if (err < 0)
251  return err;
252 
253  avctx->level = priv->units.raw_sps.level_idc;
254 
255  ctx->gop.pH264GroupOfPictures->pic_order_cnt_type = sps->pic_order_cnt_type;
256 
257  // override the default value according to the gop size
258  sps->log2_max_frame_num_minus4 = FFMAX(av_ceil_log2(base_ctx->gop_size) - 4, 0);
259  ctx->gop.pH264GroupOfPictures->log2_max_frame_num_minus4 = sps->log2_max_frame_num_minus4;
260  pps->deblocking_filter_control_present_flag = 1;
261 
262  return 0;
263 }
264 
266 {
267  HRESULT hr;
268  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
270  D3D12VAEncodeH264Context *priv = avctx->priv_data;
271 
272  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 *config;
273  D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264 h264_caps;
274 
275  D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT codec_caps = {
276  .NodeIndex = 0,
277  .Codec = D3D12_VIDEO_ENCODER_CODEC_H264,
278  .Profile = ctx->profile->d3d12_profile,
279  .CodecSupportLimits.DataSize = sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264),
280  };
281 
282  codec_caps.CodecSupportLimits.pH264Support = &h264_caps;
283  hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT,
284  &codec_caps, sizeof(codec_caps));
285  if (!(SUCCEEDED(hr) && codec_caps.IsSupported))
286  return AVERROR(EINVAL);
287 
288  ctx->codec_conf.DataSize = sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264);
289  ctx->codec_conf.pH264Config = av_mallocz(ctx->codec_conf.DataSize);
290  if (!ctx->codec_conf.pH264Config)
291  return AVERROR(ENOMEM);
292 
293  config = ctx->codec_conf.pH264Config;
294 
295  config->ConfigurationFlags = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_FLAG_NONE;
296 
297  // Deblocking filter configuration
298  if (priv->deblock) {
299  if (h264_caps.DisableDeblockingFilterSupportedModes & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_SLICES_DEBLOCKING_MODE_FLAG_0_ALL_LUMA_CHROMA_SLICE_BLOCK_EDGES_ALWAYS_FILTERED) {
300  config->DisableDeblockingFilterConfig = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_SLICES_DEBLOCKING_MODE_0_ALL_LUMA_CHROMA_SLICE_BLOCK_EDGES_ALWAYS_FILTERED;
301  } else {
302  av_log(avctx, AV_LOG_ERROR, "Requested deblocking filter enable mode not supported by driver.\n");
303  return AVERROR(ENOTSUP);
304  }
305  } else {
306  if (h264_caps.DisableDeblockingFilterSupportedModes & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_SLICES_DEBLOCKING_MODE_FLAG_1_DISABLE_ALL_SLICE_BLOCK_EDGES) {
307  config->DisableDeblockingFilterConfig = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_SLICES_DEBLOCKING_MODE_1_DISABLE_ALL_SLICE_BLOCK_EDGES;
308  } else {
309  av_log(avctx, AV_LOG_ERROR, "Requested deblocking filter disable mode not supported by driver.\n");
310  return AVERROR(ENOTSUP);
311  }
312  }
313 
314  // Entropy coder configuration
315  if (priv->unit_opts.cabac) {
316  if (h264_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264_FLAG_CABAC_ENCODING_SUPPORT) {
317  config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_FLAG_ENABLE_CABAC_ENCODING;
318  } else {
319  av_log(avctx, AV_LOG_WARNING, "CABAC entropy coding is not supported by the driver, falling back to CAVLC.\n");
320  priv->unit_opts.cabac = 0;
321  }
322  }
323 
324  base_ctx->surface_width = FFALIGN(avctx->width, 16);
325  base_ctx->surface_height = FFALIGN(avctx->height, 16);
326 
327  return 0;
328 }
329 
331 {
332  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
334  D3D12VAEncodeH264Context *priv = avctx->priv_data;
335  int fixed_qp_idr, fixed_qp_p, fixed_qp_b;
336  int err;
337 
338  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
339  if (err < 0)
340  return err;
341 
342  // Rate control
343  if (ctx->rc.Mode == D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP) {
344  D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP *cqp_ctl;
345  fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
346  if (avctx->i_quant_factor > 0.0)
347  fixed_qp_idr = av_clip((avctx->i_quant_factor * fixed_qp_p +
348  avctx->i_quant_offset) + 0.5, 1, 51);
349  else
350  fixed_qp_idr = fixed_qp_p;
351  if (avctx->b_quant_factor > 0.0)
352  fixed_qp_b = av_clip((avctx->b_quant_factor * fixed_qp_p +
353  avctx->b_quant_offset) + 0.5, 1, 51);
354  else
355  fixed_qp_b = fixed_qp_p;
356 
357  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
358  "%d / %d / %d for IDR- / P- / B-frames.\n",
359  fixed_qp_idr, fixed_qp_p, fixed_qp_b);
360 
361  ctx->rc.ConfigParams.DataSize = sizeof(D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP);
362  cqp_ctl = av_mallocz(ctx->rc.ConfigParams.DataSize);
363  if (!cqp_ctl)
364  return AVERROR(ENOMEM);
365 
366  cqp_ctl->ConstantQP_FullIntracodedFrame = fixed_qp_idr;
367  cqp_ctl->ConstantQP_InterPredictedFrame_PrevRefOnly = fixed_qp_p;
368  cqp_ctl->ConstantQP_InterPredictedFrame_BiDirectionalRef = fixed_qp_b;
369 
370  ctx->rc.ConfigParams.pConfiguration_CQP = cqp_ctl;
371  }
372  priv->unit_opts.fixed_qp_idr = 26;
373 
374  // GOP
375  ctx->gop.DataSize = sizeof(D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_H264);
376  ctx->gop.pH264GroupOfPictures = av_mallocz(ctx->gop.DataSize);
377  if (!ctx->gop.pH264GroupOfPictures)
378  return AVERROR(ENOMEM);
379 
380  ctx->gop.pH264GroupOfPictures->GOPLength = base_ctx->gop_size;
381  ctx->gop.pH264GroupOfPictures->PPicturePeriod = base_ctx->b_per_p + 1;
382  ctx->gop.pH264GroupOfPictures->log2_max_frame_num_minus4 = FFMAX(av_ceil_log2(base_ctx->gop_size) - 4, 0);
383 
384  return 0;
385 }
386 
388 {
390  int i;
391 
392  ctx->level.DataSize = sizeof(D3D12_VIDEO_ENCODER_LEVELS_H264);
393  ctx->level.pH264LevelSetting = av_mallocz(ctx->level.DataSize);
394  if (!ctx->level.pH264LevelSetting)
395  return AVERROR(ENOMEM);
396 
397  for (i = 0; i < FF_ARRAY_ELEMS(h264_levels); i++) {
398  if (avctx->level == h264_levels[i].level) {
399  *ctx->level.pH264LevelSetting = h264_levels[i].d3d12_level;
400  break;
401  }
402  }
403 
404  if (i == FF_ARRAY_ELEMS(h264_levels)) {
405  av_log(avctx, AV_LOG_ERROR, "Invalid level %d.\n", avctx->level);
406  return AVERROR(EINVAL);
407  }
408 
409  return 0;
410 }
411 
413 {
414  if (!pic->pic_ctl.pH264PicData)
415  return;
416 
417  av_freep(&pic->pic_ctl.pH264PicData->pList0ReferenceFrames);
418  av_freep(&pic->pic_ctl.pH264PicData->pList1ReferenceFrames);
419  av_freep(&pic->pic_ctl.pH264PicData->pReferenceFramesReconPictureDescriptors);
420  av_freep(&pic->pic_ctl.pH264PicData);
421 }
422 
424  FFHWBaseEncodePicture *base_pic)
425 {
426  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
428  D3D12VAEncodePicture *pic = base_pic->priv;
429  D3D12VAEncodeH264Picture *hpic = base_pic->codec_priv;
430  FFHWBaseEncodePicture *prev = base_pic->prev;
431  D3D12VAEncodeH264Picture *hprev = prev ? prev->codec_priv : NULL;
432  D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_H264 *pd = NULL;
433  UINT *ref_list0 = NULL, *ref_list1 = NULL;
434  int i, idx = 0;
435 
436  pic->pic_ctl.DataSize = sizeof(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264);
437  pic->pic_ctl.pH264PicData = av_mallocz(pic->pic_ctl.DataSize);
438  if (!pic->pic_ctl.pH264PicData)
439  return AVERROR(ENOMEM);
440 
441  if (base_pic->type == FF_HW_PICTURE_TYPE_IDR) {
442  av_assert0(base_pic->display_order == base_pic->encode_order);
443  hpic->last_idr_frame = base_pic->display_order;
444  ctx->idr_pic_id++;
445  } else {
446  av_assert0(prev);
447  hpic->last_idr_frame = hprev->last_idr_frame;
448  }
449  hpic->pic_order_cnt = base_pic->display_order - hpic->last_idr_frame;
450 
451  switch(base_pic->type) {
453  pic->pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_IDR_FRAME;
454  pic->pic_ctl.pH264PicData->idr_pic_id = ctx->idr_pic_id;
455  break;
457  pic->pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_I_FRAME;
458  break;
460  pic->pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_P_FRAME;
461  break;
463  pic->pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_B_FRAME;
464  break;
465  default:
466  av_assert0(0 && "invalid picture type");
467  }
468 
469  pic->pic_ctl.pH264PicData->PictureOrderCountNumber = hpic->pic_order_cnt;
470  pic->pic_ctl.pH264PicData->FrameDecodingOrderNumber = hpic->pic_order_cnt;
471 
472  if (base_pic->type == FF_HW_PICTURE_TYPE_P || base_pic->type == FF_HW_PICTURE_TYPE_B) {
473  pd = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*pd));
474  if (!pd)
475  return AVERROR(ENOMEM);
476 
477  ref_list0 = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*ref_list0));
478  if (!ref_list0)
479  return AVERROR(ENOMEM);
480 
481  pic->pic_ctl.pH264PicData->List0ReferenceFramesCount = base_pic->nb_refs[0];
482  for (i = 0; i < base_pic->nb_refs[0]; i++) {
483  FFHWBaseEncodePicture *ref = base_pic->refs[0][i];
485 
486  av_assert0(ref && ref->encode_order < base_pic->encode_order);
487  href = ref->codec_priv;
488 
489  ref_list0[i] = idx;
490  pd[idx].ReconstructedPictureResourceIndex = idx;
491  pd[idx].PictureOrderCountNumber = href->pic_order_cnt;
492  idx++;
493  }
494  }
495 
496  if (base_pic->type == FF_HW_PICTURE_TYPE_B) {
497  ref_list1 = av_calloc(MAX_PICTURE_REFERENCES, sizeof(*ref_list1));
498  if (!ref_list1)
499  return AVERROR(ENOMEM);
500 
501  pic->pic_ctl.pH264PicData->List1ReferenceFramesCount = base_pic->nb_refs[1];
502  for (i = 0; i < base_pic->nb_refs[1]; i++) {
503  FFHWBaseEncodePicture *ref = base_pic->refs[1][i];
505 
506  av_assert0(ref && ref->encode_order < base_pic->encode_order);
507  href = ref->codec_priv;
508 
509  ref_list1[i] = idx;
510  pd[idx].ReconstructedPictureResourceIndex = idx;
511  pd[idx].PictureOrderCountNumber = href->pic_order_cnt;
512  idx++;
513  }
514  }
515 
516  pic->pic_ctl.pH264PicData->pList0ReferenceFrames = ref_list0;
517  pic->pic_ctl.pH264PicData->pList1ReferenceFrames = ref_list1;
518  pic->pic_ctl.pH264PicData->ReferenceFramesReconPictureDescriptorsCount = idx;
519  pic->pic_ctl.pH264PicData->pReferenceFramesReconPictureDescriptors = pd;
520 
521  // Process ROI side data if present and supported
522  if (base_ctx->roi_allowed && pic->qp_map && pic->qp_map_size > 0) {
523  pic->pic_ctl.pH264PicData->QPMapValuesCount = pic->qp_map_size;
524  pic->pic_ctl.pH264PicData->pRateControlQPMap = (INT8 *)pic->qp_map;
525  }
526 
527  return 0;
528 }
529 
532 
533  .d3d12_codec = D3D12_VIDEO_ENCODER_CODEC_H264,
534 
535  .flags = FF_HW_FLAG_B_PICTURES |
538 
539  .default_quality = 25,
540 
541  .get_encoder_caps = &d3d12va_encode_h264_get_encoder_caps,
542 
543  .configure = &d3d12va_encode_h264_configure,
544 
545  .set_level = &d3d12va_encode_h264_set_level,
546 
547  .picture_priv_data_size = sizeof(D3D12VAEncodeH264Picture),
548 
549  .init_sequence_params = &d3d12va_encode_h264_init_sequence_params,
550 
551  .init_picture_params = &d3d12va_encode_h264_init_picture_params,
552 
553  .free_picture_params = &d3d12va_encode_h264_free_picture_params,
554 
556 };
557 
559 {
561  D3D12VAEncodeH264Context *priv = avctx->priv_data;
562 
563  ctx->codec = &d3d12va_encode_type_h264;
564 
565  if (avctx->profile == AV_PROFILE_UNKNOWN)
566  avctx->profile = priv->profile;
567  if (avctx->level == AV_LEVEL_UNKNOWN)
568  avctx->level = priv->level;
569 
570  if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
571  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
572  "in 8-bit unsigned integer.\n", avctx->level);
573  return AVERROR(EINVAL);
574  }
575 
576  if (priv->qp > 0)
577  ctx->explicit_qp = priv->qp;
578 
579  return ff_d3d12va_encode_init(avctx);
580 }
581 
583 {
584  D3D12VAEncodeH264Context *priv = avctx->priv_data;
585 
586  ff_cbs_fragment_free(&priv->current_access_unit);
587  ff_cbs_close(&priv->cbc);
588 
589  av_freep(&priv->common.codec_conf.pH264Config);
590  av_freep(&priv->common.gop.pH264GroupOfPictures);
591  av_freep(&priv->common.level.pH264LevelSetting);
592 
593  if (priv->common.rc.ConfigParams.pConfiguration_CQP != NULL) {
594  av_freep(&priv->common.rc.ConfigParams.pConfiguration_CQP);
595  }
596 
597  return ff_d3d12va_encode_close(avctx);
598 }
599 
600 #define OFFSET(x) offsetof(D3D12VAEncodeH264Context, x)
601 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
606 
607  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
608  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
609 
610  { "profile", "Set profile (general_profile_idc)",
612  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
613 
614 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
615  { .i64 = value }, 0, 0, FLAGS, "profile"
616  { PROFILE("main", AV_PROFILE_H264_MAIN) },
617  { PROFILE("high", AV_PROFILE_H264_HIGH) },
618  { PROFILE("high10", AV_PROFILE_H264_HIGH_10) },
619 #undef PROFILE
620 
621  { "level", "Set level (general_level_idc)",
623  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
624 
625 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
626  { .i64 = value }, 0, 0, FLAGS, "level"
627  { LEVEL("1", 10) },
628  { LEVEL("1.1", 11) },
629  { LEVEL("1.2", 12) },
630  { LEVEL("1.3", 13) },
631  { LEVEL("2", 20) },
632  { LEVEL("2.1", 21) },
633  { LEVEL("2.2", 22) },
634  { LEVEL("3", 30) },
635  { LEVEL("3.1", 31) },
636  { LEVEL("3.2", 32) },
637  { LEVEL("4", 40) },
638  { LEVEL("4.1", 41) },
639  { LEVEL("4.2", 42) },
640  { LEVEL("5", 50) },
641  { LEVEL("5.1", 51) },
642  { LEVEL("5.2", 52) },
643  { LEVEL("6", 60) },
644  { LEVEL("6.1", 61) },
645  { LEVEL("6.2", 62) },
646 #undef LEVEL
647 
648  { "deblock", "Deblocking filter mode",
649  OFFSET(deblock), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
650 
651  { "coder", "Entropy coder type",
652  OFFSET(unit_opts.cabac), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" },
653  { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },
654  { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" },
655 
656  { NULL },
657 };
658 
660  { "b", "0" },
661  { "bf", "2" },
662  { "g", "120" },
663  { "qmin", "-1" },
664  { "qmax", "-1" },
665  { NULL },
666 };
667 
669  .class_name = "h264_d3d12va",
670  .item_name = av_default_item_name,
671  .option = d3d12va_encode_h264_options,
672  .version = LIBAVUTIL_VERSION_INT,
673 };
674 
676  .p.name = "h264_d3d12va",
677  CODEC_LONG_NAME("D3D12VA h264 encoder"),
678  .p.type = AVMEDIA_TYPE_VIDEO,
679  .p.id = AV_CODEC_ID_H264,
680  .priv_data_size = sizeof(D3D12VAEncodeH264Context),
683  .close = &d3d12va_encode_h264_close,
684  .p.priv_class = &d3d12va_encode_h264_class,
685  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
687  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
689  .defaults = d3d12va_encode_h264_defaults,
691  .hw_configs = ff_d3d12va_encode_hw_configs,
692  .p.wrapper_name = "d3d12va",
693 };
cbs.h
D3D12VAEncodeH264Context::units
FFHWBaseEncodeH264 units
Definition: d3d12va_encode_h264.c:51
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:392
FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_I
Definition: hw_base_encode.h:40
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
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
FFHWBaseEncodeH264Opts
Definition: hw_base_encode_h264.h:34
d3d12va_encode_h264_free_picture_params
static void d3d12va_encode_h264_free_picture_params(D3D12VAEncodePicture *pic)
Definition: d3d12va_encode_h264.c:412
FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
Definition: hw_base_encode.h:58
OFFSET
#define OFFSET(x)
Definition: d3d12va_encode_h264.c:600
FFHWBaseEncodePicture::priv
void * priv
Definition: hw_base_encode.h:63
profile_high
static const D3D12_VIDEO_ENCODER_PROFILE_H264 profile_high
Definition: d3d12va_encode_h264.c:86
deblock
static void deblock(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int size, int dpos)
Definition: rv60dec.c:2154
FFHWBaseEncodePicture::codec_priv
void * codec_priv
Definition: hw_base_encode.h:65
h264_levels.h
D3D12VAEncodeH264Context::idr_pic_id
int idr_pic_id
Definition: d3d12va_encode_h264.c:48
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
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:112
cbs_h264.h
int64_t
long long int64_t
Definition: coverity.c:34
pixdesc.h
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
AVOption
AVOption.
Definition: opt.h:429
d3d12va_encode.h
d3d12va_encode_h264_write_access_unit
static int d3d12va_encode_h264_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
Definition: d3d12va_encode_h264.c:98
data
const char data[16]
Definition: mxf.c:149
high
int high
Definition: dovi_rpuenc.c:39
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
ff_hw_base_encode_init_params_h264
int ff_hw_base_encode_init_params_h264(FFHWBaseEncodeContext *base_ctx, AVCodecContext *avctx, FFHWBaseEncodeH264 *common, FFHWBaseEncodeH264Opts *opts)
Definition: hw_base_encode_h264.c:26
D3D12VAEncodePicture::qp_map_size
int qp_map_size
Definition: d3d12va_encode.h:63
D3D12VAEncodeH264Context
Definition: d3d12va_encode_h264.c:40
D3D12VAEncodeH264Context::level
int level
Definition: d3d12va_encode_h264.c:46
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
tf_sess_config.config
config
Definition: tf_sess_config.py:33
d3d12va_encode_h264_profiles
static const D3D12VAEncodeProfile d3d12va_encode_h264_profiles[]
Definition: d3d12va_encode_h264.c:91
FFHWBaseEncodeContext
Definition: hw_base_encode.h:122
ff_d3d12va_encode_check_encoder_feature_flags
void ff_d3d12va_encode_check_encoder_feature_flags(void *log_ctx, D3D12_VIDEO_ENCODER_VALIDATION_FLAGS flags)
Definition: d3d12va_encode.c:42
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
av_ceil_log2
#define av_ceil_log2
Definition: common.h:97
fail
#define fail()
Definition: checkasm.h:219
FFHWBaseEncodeH264
Definition: hw_base_encode_h264.h:25
D3D12VAEncodeH264Context::cbc
CodedBitstreamContext * cbc
Definition: d3d12va_encode_h264.c:54
D3D12VA_ENCODE_RC_OPTIONS
#define D3D12VA_ENCODE_RC_OPTIONS
Definition: d3d12va_encode.h:433
FFHWBaseEncodePicture::prev
struct FFHWBaseEncodePicture * prev
Definition: hw_base_encode.h:101
D3D12VAEncodeH264Picture
Definition: d3d12va_encode_h264.c:35
FFHWBaseEncodeH264Opts::cabac
int cabac
Definition: hw_base_encode_h264.h:41
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:399
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
d3d12va_encode_h264_add_nal
static int d3d12va_encode_h264_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: d3d12va_encode_h264.c:124
FFHWBaseEncodeH264Opts::fixed_qp_idr
int fixed_qp_idr
Definition: hw_base_encode_h264.h:42
D3D12VAEncodeH264Level::level
int level
Definition: d3d12va_encode_h264.c:59
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:142
D3D12VAEncodeH264Picture::last_idr_frame
int64_t last_idr_frame
Definition: d3d12va_encode_h264.c:37
AV_PROFILE_H264_HIGH_10
#define AV_PROFILE_H264_HIGH_10
Definition: defs.h:115
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
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
LEVEL
#define LEVEL(name, value)
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
D3D12VAEncodeH264Context::common
D3D12VAEncodeContext common
Definition: d3d12va_encode_h264.c:41
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
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
FFHWBaseEncodeH264::raw_sps
H264RawSPS raw_sps
Definition: hw_base_encode_h264.h:26
FFHWBaseEncodeContext::b_per_p
int b_per_p
Definition: hw_base_encode.h:189
FLAGS
#define FLAGS
Definition: d3d12va_encode_h264.c:601
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
hw_base_encode_h264.h
d3d12va_encode_h264_init_picture_params
static int d3d12va_encode_h264_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic)
Definition: d3d12va_encode_h264.c:423
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:209
d3d12va_encode_h264_get_encoder_caps
static int d3d12va_encode_h264_get_encoder_caps(AVCodecContext *avctx)
Definition: d3d12va_encode_h264.c:265
d3d12va_encode_h264_defaults
static const FFCodecDefault d3d12va_encode_h264_defaults[]
Definition: d3d12va_encode_h264.c:659
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:367
D3D12VAEncodeH264Context::deblock
int deblock
Definition: d3d12va_encode_h264.c:47
H264RawNALUnitHeader
Definition: cbs_h264.h:31
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
PROFILE
#define PROFILE(name, value)
D3D12VAEncodeH264Picture::pic_order_cnt
int pic_order_cnt
Definition: d3d12va_encode_h264.c:36
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
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1636
D3D12VAEncodeH264Context::qp
int qp
Definition: d3d12va_encode_h264.c:44
D3D12VAEncodeContext::rc
D3D12_VIDEO_ENCODER_RATE_CONTROL rc
Definition: d3d12va_encode.h:266
D3D12VAEncodeContext::codec_conf
D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION codec_conf
Definition: d3d12va_encode.h:264
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:1726
FFHWBaseEncodePicture::nb_refs
int nb_refs[MAX_REFERENCE_LIST_NUM]
Definition: hw_base_encode.h:97
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
profile_main
static const D3D12_VIDEO_ENCODER_PROFILE_H264 profile_main
Definition: d3d12va_encode_h264.c:85
MAX_DPB_SIZE
#define MAX_DPB_SIZE
Definition: hw_base_encode.h:26
D3D12VAEncodeProfile
Definition: d3d12va_encode.h:66
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:135
d3d12va_encode_h264_write_sequence_header
static int d3d12va_encode_h264_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: d3d12va_encode_h264.c:142
ff_h264_d3d12va_encoder
const FFCodec ff_h264_d3d12va_encoder
Definition: d3d12va_encode_h264.c:675
FFHWBaseEncodeH264::raw_pps
H264RawPPS raw_pps
Definition: hw_base_encode_h264.h:27
d3d12va_encode_type_h264
static const D3D12VAEncodeType d3d12va_encode_type_h264
Definition: d3d12va_encode_h264.c:530
header
static const uint8_t header[24]
Definition: sdr2.c:68
FFHWBaseEncodePicture::encode_order
int64_t encode_order
Definition: hw_base_encode.h:70
d3d12va_encode_h264_close
static int d3d12va_encode_h264_close(AVCodecContext *avctx)
Definition: d3d12va_encode_h264.c:582
FFHWBaseEncodeContext::roi_allowed
int roi_allowed
Definition: hw_base_encode.h:201
d3d12va_encode_h264_init_sequence_params
static int d3d12va_encode_h264_init_sequence_params(AVCodecContext *avctx)
Definition: d3d12va_encode_h264.c:163
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
FFHWBaseEncodeH264Opts::mb_height
int mb_height
Definition: hw_base_encode_h264.h:39
FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_B
Definition: hw_base_encode.h:42
D3D12VAEncodeContext::level
D3D12_VIDEO_ENCODER_LEVEL_SETTING level
Definition: d3d12va_encode.h:270
D3D_PROFILE_DESC
#define D3D_PROFILE_DESC(name)
Definition: d3d12va_encode_h264.c:89
D3D12VAEncodePicture::qp_map
void * qp_map
Definition: d3d12va_encode.h:62
d3d12va_encode_h264_init
static int d3d12va_encode_h264_init(AVCodecContext *avctx)
Definition: d3d12va_encode_h264.c:558
common.h
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
D3D12VAEncodeH264Context::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: d3d12va_encode_h264.c:55
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_h264_options
static const AVOption d3d12va_encode_h264_options[]
Definition: d3d12va_encode_h264.c:602
FFHWBaseEncodeContext::surface_height
int surface_height
Definition: hw_base_encode.h:141
AVCodecContext
main external API structure.
Definition: avcodec.h:439
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:114
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
H264RawSPS::level_idc
uint8_t level_idc
Definition: cbs_h264.h:113
d3d12va_encode_h264_class
static const AVClass d3d12va_encode_h264_class
Definition: d3d12va_encode_h264.c:668
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
h264_levels
static const D3D12VAEncodeH264Level h264_levels[]
Definition: d3d12va_encode_h264.c:63
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
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
FFHWBaseEncodeH264Opts::mb_width
int mb_width
Definition: hw_base_encode_h264.h:38
D3D12VAEncodeH264Level::d3d12_level
D3D12_VIDEO_ENCODER_LEVELS_H264 d3d12_level
Definition: d3d12va_encode_h264.c:60
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:82
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
mem.h
D3D12VAEncodeH264Context::unit_opts
FFHWBaseEncodeH264Opts unit_opts
Definition: d3d12va_encode_h264.c:52
FF_HW_FLAG_B_PICTURES
@ FF_HW_FLAG_B_PICTURES
Definition: hw_base_encode.h:53
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_d3d12va_encode_close
int ff_d3d12va_encode_close(AVCodecContext *avctx)
Definition: d3d12va_encode.c:1865
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:1721
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
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
FF_HW_PICTURE_TYPE_IDR
@ FF_HW_PICTURE_TYPE_IDR
Definition: hw_base_encode.h:39
d3d12va_encode_h264_set_level
static int d3d12va_encode_h264_set_level(AVCodecContext *avctx)
Definition: d3d12va_encode_h264.c:387
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
D3D12VAEncodeH264Level
Definition: d3d12va_encode_h264.c:58
profile_high_10
static const D3D12_VIDEO_ENCODER_PROFILE_H264 profile_high_10
Definition: d3d12va_encode_h264.c:87
HW_BASE_ENCODE_COMMON_OPTIONS
#define HW_BASE_ENCODE_COMMON_OPTIONS
Definition: hw_base_encode.h:243
d3d12va_encode_h264_configure
static int d3d12va_encode_h264_configure(AVCodecContext *avctx)
Definition: d3d12va_encode_h264.c:330
D3D12VAEncodeType
Definition: d3d12va_encode.h:295
hwcontext_d3d12va_internal.h
FFHWBaseEncodePicture::display_order
int64_t display_order
Definition: hw_base_encode.h:69
FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
Definition: hw_base_encode.h:55
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
D3D12VAEncodeH264Context::profile
int profile
Definition: d3d12va_encode_h264.c:45
FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_P
Definition: hw_base_encode.h:41
MAX_PICTURE_REFERENCES
#define MAX_PICTURE_REFERENCES
Definition: hw_base_encode.h:27
H264RawSPS
Definition: cbs_h264.h:102
H264RawPPS
Definition: cbs_h264.h:171