FFmpeg
vulkan_encode_h265.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/internal.h"
20 #include "libavutil/opt.h"
21 #include "libavutil/mem.h"
22 
23 #include "cbs.h"
24 #include "cbs_h265.h"
25 #include "atsc_a53.h"
27 
28 #include "codec_internal.h"
29 #include "version.h"
30 #include "hw_base_encode_h265.h"
31 
32 #include "vulkan_encode.h"
33 
34 enum UnitElems {
35  UNIT_AUD = 1 << 0,
38  UNIT_SEI_A53_CC = 1 << 3,
39 };
40 
43  .encode_extension = FF_VK_EXT_VIDEO_ENCODE_H265,
44  .encode_op = VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR,
45  .ext_props = {
46  .extensionName = VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_EXTENSION_NAME,
47  .specVersion = VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_SPEC_VERSION,
48  },
49 };
50 
51 typedef struct VulkanEncodeH265Picture {
52  int frame_num;
54  uint16_t idr_pic_id;
58  int pic_type;
59 
61 
62  VkVideoEncodeH265RateControlInfoKHR vkrc_info;
63  VkVideoEncodeH265RateControlLayerInfoKHR vkrc_layer_info;
64 
65  StdVideoEncodeH265PictureInfo h265pic_info;
66  VkVideoEncodeH265PictureInfoKHR vkh265pic_info;
67 
68  StdVideoEncodeH265WeightTable slice_wt;
69  StdVideoEncodeH265SliceSegmentHeader slice_hdr;
70  VkVideoEncodeH265NaluSliceSegmentInfoKHR vkslice;
71 
72  StdVideoEncodeH265ReferenceInfo h265dpb_info;
73  VkVideoEncodeH265DpbSlotInfoKHR vkh265dpb_info;
74 
75  StdVideoEncodeH265ReferenceListsInfo ref_list_info;
76  StdVideoEncodeH265LongTermRefPics l_rps;
77  StdVideoH265ShortTermRefPicSet s_rps;
79 
80 typedef struct VulkanEncodeH265Context {
82 
85 
87 
88  uint8_t fixed_qp_idr;
89  uint8_t fixed_qp_p;
90  uint8_t fixed_qp_b;
91 
92  uint64_t hrd_buffer_size;
94 
95  VkVideoEncodeH265ProfileInfoKHR profile;
96 
97  VkVideoEncodeH265CapabilitiesKHR caps;
98  VkVideoEncodeH265QualityLevelPropertiesKHR quality_props;
99 
102 
104 
110 
112  VkVideoEncodeRateControlInfoKHR *rc_info,
113  VkVideoEncodeRateControlLayerInfoKHR *rc_layer)
114 {
115  VulkanEncodeH265Context *enc = avctx->priv_data;
118 
119  hp->vkrc_info = (VkVideoEncodeH265RateControlInfoKHR) {
120  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_RATE_CONTROL_INFO_KHR,
121  .flags = VK_VIDEO_ENCODE_H265_RATE_CONTROL_REFERENCE_PATTERN_FLAT_BIT_KHR |
122  VK_VIDEO_ENCODE_H265_RATE_CONTROL_REGULAR_GOP_BIT_KHR,
123  .idrPeriod = ctx->base.gop_size,
124  .gopFrameCount = ctx->base.gop_size,
125  .consecutiveBFrameCount = FFMAX(ctx->base.b_per_p - 1, 0),
126  .subLayerCount = 0,
127  };
128  rc_info->pNext = &hp->vkrc_info;
129 
130  if (rc_info->rateControlMode > VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR) {
131  rc_info->virtualBufferSizeInMs = (enc->hrd_buffer_size * 1000LL) / avctx->bit_rate;
132  rc_info->initialVirtualBufferSizeInMs = (enc->initial_buffer_fullness * 1000LL) / avctx->bit_rate;
133 
134  hp->vkrc_layer_info = (VkVideoEncodeH265RateControlLayerInfoKHR) {
135  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_RATE_CONTROL_LAYER_INFO_KHR,
136 
137  .useMinQp = avctx->qmin > 0,
138  .minQp.qpI = avctx->qmin > 0 ? avctx->qmin : 0,
139  .minQp.qpP = avctx->qmin > 0 ? avctx->qmin : 0,
140  .minQp.qpB = avctx->qmin > 0 ? avctx->qmin : 0,
141 
142  .useMaxQp = avctx->qmax > 0,
143  .maxQp.qpI = avctx->qmax > 0 ? avctx->qmax : 0,
144  .maxQp.qpP = avctx->qmax > 0 ? avctx->qmax : 0,
145  .maxQp.qpB = avctx->qmax > 0 ? avctx->qmax : 0,
146 
147  .useMaxFrameSize = 0,
148  };
149  rc_layer->pNext = &hp->vkrc_layer_info;
150  hp->vkrc_info.subLayerCount = 1;
151  }
152 
153  return 0;
154 }
155 
158 {
159  VulkanEncodeH265Context *enc = avctx->priv_data;
161  FFHWBaseEncodePicture *prev = pic->prev;
162  VulkanEncodeH265Picture *hprev = prev ? prev->codec_priv : NULL;
163 
164  if (pic->type == FF_HW_PICTURE_TYPE_IDR) {
165  av_assert0(pic->display_order == pic->encode_order);
166 
167  hp->last_idr_frame = pic->display_order;
168 
169  hp->slice_type = STD_VIDEO_H265_SLICE_TYPE_I;
170  hp->pic_type = STD_VIDEO_H265_PICTURE_TYPE_IDR;
171  } else {
172  av_assert0(prev);
173  hp->last_idr_frame = hprev->last_idr_frame;
174 
175  if (pic->type == FF_HW_PICTURE_TYPE_I) {
176  hp->slice_type = STD_VIDEO_H265_SLICE_TYPE_I;
177  hp->pic_type = STD_VIDEO_H265_PICTURE_TYPE_I;
178  } else if (pic->type == FF_HW_PICTURE_TYPE_P) {
179  av_assert0(pic->refs[0]);
180  hp->slice_type = STD_VIDEO_H265_SLICE_TYPE_P;
181  hp->pic_type = STD_VIDEO_H265_PICTURE_TYPE_P;
182  } else {
183  FFHWBaseEncodePicture *irap_ref;
184  av_assert0(pic->refs[0][0] && pic->refs[1][0]);
185  for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1][0]) {
186  if (irap_ref->type == FF_HW_PICTURE_TYPE_I)
187  break;
188  }
189  hp->slice_type = STD_VIDEO_H265_SLICE_TYPE_B;
190  hp->pic_type = STD_VIDEO_H265_PICTURE_TYPE_B;
191  }
192  }
193  hp->pic_order_cnt = pic->display_order - hp->last_idr_frame;
194 
195  hp->units_needed = 0;
196 
197  if (enc->unit_elems & UNIT_AUD) {
198  hp->units_needed |= UNIT_AUD;
199  enc->raw_aud = (H265RawAUD) {
200  .nal_unit_header = {
202  .nuh_layer_id = 0,
203  .nuh_temporal_id_plus1 = 1,
204  },
205  .pic_type = hp->pic_type,
206  };
207  }
208 
209  // Only look for the metadata on I/IDR frame on the output. We
210  // may force an IDR frame on the output where the medadata gets
211  // changed on the input frame.
212  if ((enc->unit_elems & UNIT_SEI_MASTERING_DISPLAY) &&
213  (pic->type == FF_HW_PICTURE_TYPE_I || pic->type == FF_HW_PICTURE_TYPE_IDR)) {
214  AVFrameSideData *sd =
217 
218  if (sd) {
220 
221  // SEI is needed when both the primaries and luminance are set
222  if (mdm->has_primaries && mdm->has_luminance) {
224  &enc->sei_mastering_display;
225  const int mapping[3] = {1, 2, 0};
226  const int chroma_den = 50000;
227  const int luma_den = 10000;
228 
229  for (int i = 0; i < 3; i++) {
230  const int j = mapping[i];
231  mdcv->display_primaries_x[i] =
232  FFMIN(lrint(chroma_den *
233  av_q2d(mdm->display_primaries[j][0])),
234  chroma_den);
235  mdcv->display_primaries_y[i] =
236  FFMIN(lrint(chroma_den *
237  av_q2d(mdm->display_primaries[j][1])),
238  chroma_den);
239  }
240 
241  mdcv->white_point_x =
242  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
243  chroma_den);
244  mdcv->white_point_y =
245  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
246  chroma_den);
247 
249  lrint(luma_den * av_q2d(mdm->max_luminance));
251  FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
253 
255  }
256  }
257  }
258 
260  (pic->type == FF_HW_PICTURE_TYPE_I || pic->type == FF_HW_PICTURE_TYPE_IDR)) {
263 
264  if (sd) {
267 
268  clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
269  clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
270 
272  }
273  }
274 
275  if (enc->unit_elems & UNIT_SEI_A53_CC) {
276  int err;
277  size_t sei_a53cc_len;
278  av_freep(&enc->sei_a53cc_data);
279  err = ff_alloc_a53_sei(pic->input_image, 0, &enc->sei_a53cc_data, &sei_a53cc_len);
280  if (err < 0)
281  return err;
282  if (enc->sei_a53cc_data != NULL) {
284  enc->sei_a53cc.data = (uint8_t *)enc->sei_a53cc_data + 1;
285  enc->sei_a53cc.data_length = sei_a53cc_len - 1;
286 
288  }
289  }
290 
291  return 0;
292 }
293 
294 static void setup_slices(AVCodecContext *avctx,
296 {
297  VulkanEncodeH265Context *enc = avctx->priv_data;
299 
300  hp->slice_wt = (StdVideoEncodeH265WeightTable) {
301  .flags = (StdVideoEncodeH265WeightTableFlags) {
302  .luma_weight_l0_flag = 0,
303  .chroma_weight_l0_flag = 0,
304  .luma_weight_l1_flag = 0,
305  .chroma_weight_l1_flag = 0,
306  },
307  .luma_log2_weight_denom = 0,
308  .delta_chroma_log2_weight_denom = 0,
309  .delta_luma_weight_l0 = { 0 },
310  .luma_offset_l0 = { 0 },
311  .delta_chroma_weight_l0 = { { 0 } },
312  .delta_chroma_offset_l0 = { { 0 } },
313  .delta_luma_weight_l1 = { 0 },
314  .luma_offset_l1 = { 0 },
315  .delta_chroma_weight_l1 = { { 0 } },
316  .delta_chroma_offset_l1 = { { 0 } },
317  };
318 
319  hp->slice_hdr = (StdVideoEncodeH265SliceSegmentHeader) {
320  .flags = (StdVideoEncodeH265SliceSegmentHeaderFlags) {
321  .first_slice_segment_in_pic_flag = 1,
322  .dependent_slice_segment_flag = 0,
323  .slice_sao_luma_flag = enc->units.raw_sps.sample_adaptive_offset_enabled_flag,
324  .slice_sao_chroma_flag = enc->units.raw_sps.sample_adaptive_offset_enabled_flag,
325  .num_ref_idx_active_override_flag = 0,
326  .mvd_l1_zero_flag = 0,
327  .cabac_init_flag = 0,
328  .cu_chroma_qp_offset_enabled_flag = 0,
329  .deblocking_filter_override_flag = 0,
330  .slice_deblocking_filter_disabled_flag = 0,
331  .collocated_from_l0_flag = 1,
332  .slice_loop_filter_across_slices_enabled_flag = 0,
333  /* Reserved */
334  },
335  .slice_type = hp->slice_type,
336  .slice_segment_address = 0,
337  .collocated_ref_idx = 0,
338  .MaxNumMergeCand = 5,
339  .slice_cb_qp_offset = 0,
340  .slice_cr_qp_offset = 0,
341  .slice_beta_offset_div2 = 0,
342  .slice_tc_offset_div2 = 0,
343  .slice_act_y_qp_offset = 0,
344  .slice_act_cb_qp_offset = 0,
345  .slice_act_cr_qp_offset = 0,
346  .slice_qp_delta = 0, /* Filled in below */
347  /* Reserved */
348  .pWeightTable = NULL, // &hp->slice_wt,
349  };
350 
351  hp->vkslice = (VkVideoEncodeH265NaluSliceSegmentInfoKHR) {
352  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_NALU_SLICE_SEGMENT_INFO_KHR,
353  .pNext = NULL,
354  .constantQp = pic->type == FF_HW_PICTURE_TYPE_B ? enc->fixed_qp_b :
355  pic->type == FF_HW_PICTURE_TYPE_P ? enc->fixed_qp_p :
356  enc->fixed_qp_idr,
357  .pStdSliceSegmentHeader = &hp->slice_hdr,
358  };
359 
360  if (enc->common.opts.rc_mode != VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR)
361  hp->vkslice.constantQp = 0;
362 
363  hp->slice_hdr.slice_qp_delta = hp->vkslice.constantQp -
364  (enc->units.raw_pps.init_qp_minus26 + 26);
365 
366  hp->vkh265pic_info.pNaluSliceSegmentEntries = &hp->vkslice;
367  hp->vkh265pic_info.naluSliceSegmentEntryCount = 1;
368 }
369 
370 static void setup_refs(AVCodecContext *avctx,
372  VkVideoEncodeInfoKHR *encode_info)
373 {
374  int i, j;
375  VulkanEncodeH265Context *enc = avctx->priv_data;
377 
378  hp->ref_list_info = (StdVideoEncodeH265ReferenceListsInfo) {
379  .flags = (StdVideoEncodeH265ReferenceListsInfoFlags) {
380  .ref_pic_list_modification_flag_l0 = 0,
381  .ref_pic_list_modification_flag_l1 = 0,
382  /* Reserved */
383  },
384  /* May be overridden during setup_slices() */
385  .num_ref_idx_l0_active_minus1 = pic->nb_refs[0] - 1,
386  .num_ref_idx_l1_active_minus1 = pic->nb_refs[1] - 1,
387  /* Reserved */
388  .list_entry_l0 = { 0 },
389  .list_entry_l1 = { 0 },
390  };
391 
392  for (i = 0; i < STD_VIDEO_H265_MAX_NUM_LIST_REF; i++)
393  hp->ref_list_info.RefPicList0[i] = hp->ref_list_info.RefPicList1[i] = -1;
394 
395  /* Note: really not sure */
396  for (i = 0; i < pic->nb_refs[0]; i++) {
397  VkVideoReferenceSlotInfoKHR *slot_info;
398  slot_info = (VkVideoReferenceSlotInfoKHR *)&encode_info->pReferenceSlots[i];
399  hp->ref_list_info.RefPicList0[i] = slot_info->slotIndex;
400  }
401 
402  /* Note: really not sure */
403  for (i = 0; i < pic->nb_refs[1]; i++) {
404  VkVideoReferenceSlotInfoKHR *slot_info;
405  slot_info = (VkVideoReferenceSlotInfoKHR *)&encode_info->pReferenceSlots[pic->nb_refs[0] + i];
406  hp->ref_list_info.RefPicList1[i] = slot_info->slotIndex;
407  }
408 
409  hp->h265pic_info.pRefLists = &hp->ref_list_info;
410 
411  if (pic->type != FF_HW_PICTURE_TYPE_IDR) {
412  StdVideoH265ShortTermRefPicSet *rps;
414  int rps_poc[MAX_DPB_SIZE];
415  int rps_used[MAX_DPB_SIZE];
416  int poc, rps_pics;
417 
418  hp->h265pic_info.flags.short_term_ref_pic_set_sps_flag = 0;
419 
420  rps = &hp->s_rps;
421  memset(rps, 0, sizeof(*rps));
422 
423  rps_pics = 0;
424  for (i = 0; i < MAX_REFERENCE_LIST_NUM; i++) {
425  for (j = 0; j < pic->nb_refs[i]; j++) {
426  strp = pic->refs[i][j]->codec_priv;
427  rps_poc[rps_pics] = strp->pic_order_cnt;
428  rps_used[rps_pics] = 1;
429  ++rps_pics;
430  }
431  }
432 
433  for (i = 0; i < pic->nb_dpb_pics; i++) {
434  if (pic->dpb[i] == pic)
435  continue;
436 
437  for (j = 0; j < pic->nb_refs[0]; j++) {
438  if (pic->dpb[i] == pic->refs[0][j])
439  break;
440  }
441  if (j < pic->nb_refs[0])
442  continue;
443 
444  for (j = 0; j < pic->nb_refs[1]; j++) {
445  if (pic->dpb[i] == pic->refs[1][j])
446  break;
447  }
448  if (j < pic->nb_refs[1])
449  continue;
450 
451  strp = pic->dpb[i]->codec_priv;
452  rps_poc[rps_pics] = strp->pic_order_cnt;
453  rps_used[rps_pics] = 0;
454  ++rps_pics;
455  }
456 
457  for (i = 1; i < rps_pics; i++) {
458  for (j = i; j > 0; j--) {
459  if (rps_poc[j] > rps_poc[j - 1])
460  break;
461  av_assert0(rps_poc[j] != rps_poc[j - 1]);
462  FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
463  FFSWAP(int, rps_used[j], rps_used[j - 1]);
464  }
465  }
466 
467  av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:", hp->pic_order_cnt);
468  for (i = 0; i < rps_pics; i++)
469  av_log(avctx, AV_LOG_DEBUG, " (%d,%d)", rps_poc[i], rps_used[i]);
470 
471  av_log(avctx, AV_LOG_DEBUG, "\n");
472 
473  for (i = 0; i < rps_pics; i++) {
474  av_assert0(rps_poc[i] != hp->pic_order_cnt);
475  if (rps_poc[i] > hp->pic_order_cnt)
476  break;
477  }
478 
479  rps->num_negative_pics = i;
480  rps->used_by_curr_pic_s0_flag = 0x0;
481  poc = hp->pic_order_cnt;
482  for (j = i - 1; j >= 0; j--) {
483  rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
484  rps->used_by_curr_pic_s0_flag |= rps_used[j] << (i - 1 - j);
485  poc = rps_poc[j];
486  }
487 
488  rps->num_positive_pics = rps_pics - i;
489  rps->used_by_curr_pic_s1_flag = 0x0;
490  poc = hp->pic_order_cnt;
491  for (j = i; j < rps_pics; j++) {
492  rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
493  rps->used_by_curr_pic_s1_flag |= rps_used[j] << (j - i);
494  poc = rps_poc[j];
495  }
496 
497  hp->l_rps.num_long_term_sps = 0;
498  hp->l_rps.num_long_term_pics = 0;
499 
500  // when this flag is not present, it is inerred to 1.
501  hp->slice_hdr.flags.collocated_from_l0_flag = 1;
502  hp->h265pic_info.flags.slice_temporal_mvp_enabled_flag =
504  if (hp->h265pic_info.flags.slice_temporal_mvp_enabled_flag) {
505  if (hp->slice_hdr.slice_type == STD_VIDEO_H265_SLICE_TYPE_B)
506  hp->slice_hdr.flags.collocated_from_l0_flag = 1;
507  hp->slice_hdr.collocated_ref_idx = 0;
508  }
509 
510  hp->slice_hdr.flags.num_ref_idx_active_override_flag = 0;
511  hp->ref_list_info.num_ref_idx_l0_active_minus1 = enc->units.raw_pps.num_ref_idx_l0_default_active_minus1;
512  hp->ref_list_info.num_ref_idx_l1_active_minus1 = enc->units.raw_pps.num_ref_idx_l1_default_active_minus1;
513  }
514 
515  hp->h265pic_info.pShortTermRefPicSet = &hp->s_rps;
516  hp->h265pic_info.pLongTermRefPics = &hp->l_rps;
517 }
518 
520  VkVideoEncodeInfoKHR *encode_info)
521 {
522  int err;
523  VulkanEncodeH265Context *enc = avctx->priv_data;
524  FFVulkanEncodePicture *vp = pic->priv;
526  VkVideoReferenceSlotInfoKHR *ref_slot;
527 
528  err = vk_enc_h265_update_pic_info(avctx, pic);
529  if (err < 0)
530  return err;
531 
532  hp->vkh265pic_info = (VkVideoEncodeH265PictureInfoKHR) {
533  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_PICTURE_INFO_KHR,
534  .pNext = NULL,
535  .pNaluSliceSegmentEntries = NULL, // Filled in during setup_slices()
536  .naluSliceSegmentEntryCount = 0, // Filled in during setup_slices()
537  .pStdPictureInfo = &hp->h265pic_info,
538  };
539 
540  hp->h265pic_info = (StdVideoEncodeH265PictureInfo) {
541  .flags = (StdVideoEncodeH265PictureInfoFlags) {
542  .is_reference = pic->is_reference,
543  .IrapPicFlag = pic->type == FF_HW_PICTURE_TYPE_IDR,
544  .used_for_long_term_reference = 0,
545  .discardable_flag = 0,
546  .cross_layer_bla_flag = 0,
547  .pic_output_flag = 1,
548  .no_output_of_prior_pics_flag = 0,
549  .short_term_ref_pic_set_sps_flag = 0,
550  .slice_temporal_mvp_enabled_flag = enc->units.raw_sps.sps_temporal_mvp_enabled_flag,
551  /* Reserved */
552  },
553  .pic_type = hp->pic_type,
554  .sps_video_parameter_set_id = 0,
555  .pps_seq_parameter_set_id = 0,
556  .pps_pic_parameter_set_id = 0,
557  .short_term_ref_pic_set_idx = 0,
558  .PicOrderCntVal = hp->pic_order_cnt,
559  .TemporalId = 0,
560  /* Reserved */
561  .pRefLists = NULL, // Filled in during setup_refs
562  .pShortTermRefPicSet = NULL,
563  .pLongTermRefPics = NULL,
564  };
565  encode_info->pNext = &hp->vkh265pic_info;
566 
567  hp->h265dpb_info = (StdVideoEncodeH265ReferenceInfo) {
568  .flags = (StdVideoEncodeH265ReferenceInfoFlags) {
569  .used_for_long_term_reference = 0,
570  .unused_for_reference = 0,
571  /* Reserved */
572  },
573  .pic_type = hp->h265pic_info.pic_type,
574  .PicOrderCntVal = hp->h265pic_info.PicOrderCntVal,
575  .TemporalId = hp->h265pic_info.TemporalId,
576  };
577  hp->vkh265dpb_info = (VkVideoEncodeH265DpbSlotInfoKHR) {
578  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_DPB_SLOT_INFO_KHR,
579  .pStdReferenceInfo = &hp->h265dpb_info,
580  };
581 
582  vp->dpb_slot.pNext = &hp->vkh265dpb_info;
583 
584  ref_slot = (VkVideoReferenceSlotInfoKHR *)encode_info->pSetupReferenceSlot;
585  ref_slot->pNext = &hp->vkh265dpb_info;
586 
587  setup_refs(avctx, pic, encode_info);
588 
589  setup_slices(avctx, pic);
590 
591  return 0;
592 }
593 
594 static int init_profile(AVCodecContext *avctx,
595  VkVideoProfileInfoKHR *profile, void *pnext)
596 {
597  VkResult ret;
598  VulkanEncodeH265Context *enc = avctx->priv_data;
600  FFVulkanContext *s = &ctx->s;
601  FFVulkanFunctions *vk = &ctx->s.vkfn;
602  VkVideoEncodeH265CapabilitiesKHR h265_caps = {
603  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_CAPABILITIES_KHR,
604  };
605  VkVideoEncodeCapabilitiesKHR enc_caps = {
606  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_CAPABILITIES_KHR,
607  .pNext = &h265_caps,
608  };
609  VkVideoCapabilitiesKHR caps = {
610  .sType = VK_STRUCTURE_TYPE_VIDEO_CAPABILITIES_KHR,
611  .pNext = &enc_caps,
612  };
613 
614  /* In order of preference */
615  int last_supported = AV_PROFILE_UNKNOWN;
616  static const int known_profiles[] = {
620  };
621  int nb_profiles = FF_ARRAY_ELEMS(known_profiles);
622 
623  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->frames->sw_format);
624  if (!desc)
625  return AVERROR(EINVAL);
626 
627  if (s->frames->sw_format == AV_PIX_FMT_NV12)
628  nb_profiles = 1;
629  else if (s->frames->sw_format == AV_PIX_FMT_P010)
630  nb_profiles = 2;
631 
632  enc->profile = (VkVideoEncodeH265ProfileInfoKHR) {
633  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_PROFILE_INFO_KHR,
634  .pNext = pnext,
635  .stdProfileIdc = ff_vk_h265_profile_to_vk(avctx->profile),
636  };
637  profile->pNext = &enc->profile;
638 
639  /* Set level */
640  if (avctx->level == AV_LEVEL_UNKNOWN)
641  avctx->level = enc->common.opts.level;
642 
643  /* User has explicitly specified a profile. */
644  if (avctx->profile != AV_PROFILE_UNKNOWN)
645  return 0;
646 
647  av_log(avctx, AV_LOG_DEBUG, "Supported profiles:\n");
648  for (int i = 0; i < nb_profiles; i++) {
649  enc->profile.stdProfileIdc = ff_vk_h265_profile_to_vk(known_profiles[i]);
650  ret = vk->GetPhysicalDeviceVideoCapabilitiesKHR(s->hwctx->phys_dev,
651  profile,
652  &caps);
653  if (ret == VK_SUCCESS) {
654  av_log(avctx, AV_LOG_DEBUG, " %s\n",
655  avcodec_profile_name(avctx->codec_id, known_profiles[i]));
656  last_supported = known_profiles[i];
657  }
658  }
659 
660  if (last_supported == AV_PROFILE_UNKNOWN) {
661  av_log(avctx, AV_LOG_ERROR, "No supported profiles for given format\n");
662  return AVERROR(ENOTSUP);
663  }
664 
665  enc->profile.stdProfileIdc = ff_vk_h265_profile_to_vk(last_supported);
666  av_log(avctx, AV_LOG_VERBOSE, "Using profile %s\n",
667  avcodec_profile_name(avctx->codec_id, last_supported));
668  avctx->profile = last_supported;
669 
670  return 0;
671 }
672 
674 {
675  VulkanEncodeH265Context *enc = avctx->priv_data;
676 
677  if (avctx->rc_buffer_size)
678  enc->hrd_buffer_size = avctx->rc_buffer_size;
679  else if (avctx->rc_max_rate > 0)
680  enc->hrd_buffer_size = avctx->rc_max_rate;
681  else
682  enc->hrd_buffer_size = avctx->bit_rate;
683 
684  if (avctx->rc_initial_buffer_occupancy) {
685  if (avctx->rc_initial_buffer_occupancy > enc->hrd_buffer_size) {
686  av_log(avctx, AV_LOG_ERROR, "Invalid RC buffer settings: "
687  "must have initial buffer size (%d) <= "
688  "buffer size (%"PRId64").\n",
690  return AVERROR(EINVAL);
691  }
693  } else {
694  enc->initial_buffer_fullness = enc->hrd_buffer_size * 3 / 4;
695  }
696 
697  if (enc->common.opts.rc_mode == VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR) {
698  enc->fixed_qp_p = av_clip(enc->common.opts.qp,
699  enc->caps.minQp, enc->caps.maxQp);
700 
701  if (avctx->i_quant_factor > 0.0)
702  enc->fixed_qp_idr = av_clip((avctx->i_quant_factor * enc->fixed_qp_p +
703  avctx->i_quant_offset) + 0.5,
704  enc->caps.minQp, enc->caps.maxQp);
705  else
706  enc->fixed_qp_idr = enc->fixed_qp_p;
707 
708  if (avctx->b_quant_factor > 0.0)
709  enc->fixed_qp_b = av_clip((avctx->b_quant_factor * enc->fixed_qp_p +
710  avctx->b_quant_offset) + 0.5,
711  enc->caps.minQp, enc->caps.maxQp);
712  else
713  enc->fixed_qp_b = enc->fixed_qp_p;
714 
715  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
716  "%d / %d / %d for IDR- / P- / B-frames.\n",
717  enc->fixed_qp_idr, enc->fixed_qp_p, enc->fixed_qp_b);
718  } else {
719  enc->fixed_qp_idr = 26;
720  enc->fixed_qp_p = 26;
721  enc->fixed_qp_b = 26;
722  }
723 
724  return 0;
725 }
726 
728 {
729  int err;
730  VulkanEncodeH265Context *enc = avctx->priv_data;
732  FFHWBaseEncodeContext *base_ctx = &ctx->base;
733 
734  FFHWBaseEncodeH265 *units = &enc->units;
735  FFHWBaseEncodeH265Opts *unit_opts = &enc->unit_opts;
736 
737  int max_ctb_size;
738  unsigned min_tb_size;
739  unsigned max_tb_size;
740  unsigned max_transform_hierarchy;
741 
742  unit_opts->tier = enc->common.opts.tier;
743  unit_opts->fixed_qp_idr = enc->fixed_qp_idr;
744  unit_opts->cu_qp_delta_enabled_flag = enc->common.opts.rc_mode != VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR;
745 
746  unit_opts->nb_slices = 1;
747 
748  unit_opts->slice_block_rows = (avctx->height + base_ctx->slice_block_height - 1) /
749  base_ctx->slice_block_height;
750  unit_opts->slice_block_cols = (avctx->width + base_ctx->slice_block_width - 1) /
751  base_ctx->slice_block_width;
752 
753  /* cabac already set via an option */
754  /* fixed_qp_idr initialized in init_enc_options() */
755  /* hrd_buffer_size initialized in init_enc_options() */
756  /* initial_buffer_fullness initialized in init_enc_options() */
757 
759  units, unit_opts);
760  if (err < 0)
761  return err;
762 
764  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SAMPLE_ADAPTIVE_OFFSET_ENABLED_FLAG_SET_BIT_KHR);
766  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_TRANSFORM_SKIP_ENABLED_FLAG_SET_BIT_KHR);
767 
768  max_ctb_size = 16;
769 
770  /* coding blocks from 8x8 to max CTB size. */
771  if (enc->caps.ctbSizes & VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR)
772  max_ctb_size = 64;
773  else if (enc->caps.ctbSizes & VK_VIDEO_ENCODE_H265_CTB_SIZE_32_BIT_KHR)
774  max_ctb_size = 32;
775 
776  min_tb_size = 0;
777  max_tb_size = 0;
778  if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_4_BIT_KHR)
779  min_tb_size = 4;
780  else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_8_BIT_KHR)
781  min_tb_size = 8;
782  else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_16_BIT_KHR)
783  min_tb_size = 16;
784  else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_32_BIT_KHR)
785  min_tb_size = 32;
786 
787  if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_32_BIT_KHR)
788  max_tb_size = 32;
789  else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_16_BIT_KHR)
790  max_tb_size = 16;
791  else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_8_BIT_KHR)
792  max_tb_size = 8;
793  else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_4_BIT_KHR)
794  max_tb_size = 4;
795 
797  units->raw_sps.log2_diff_max_min_luma_coding_block_size = av_log2(max_ctb_size) - 3;
799  units->raw_sps.log2_diff_max_min_luma_transform_block_size = av_log2(max_tb_size) - av_log2(min_tb_size);
800 
801  max_transform_hierarchy = av_log2(max_ctb_size) - av_log2(min_tb_size);
802  units->raw_sps.max_transform_hierarchy_depth_intra = max_transform_hierarchy;
803  units->raw_sps.max_transform_hierarchy_depth_intra = max_transform_hierarchy;
804 
808 
810 
811  if (base_ctx->gop_size & base_ctx->gop_size - 1 == 0)
812  units->raw_sps.log2_max_pic_order_cnt_lsb_minus4 = FFMAX(av_log2(base_ctx->gop_size) - 4, 0);
813  else
814  units->raw_sps.log2_max_pic_order_cnt_lsb_minus4 = FFMAX(av_log2(base_ctx->gop_size) - 3, 0);
815 
816  return 0;
817 }
818 
819 typedef struct VulkanH265Units {
820  StdVideoH265SequenceParameterSet sps;
821  StdVideoH265ShortTermRefPicSet str[STD_VIDEO_H265_SUBLAYERS_LIST_SIZE];
822  StdVideoH265LongTermRefPicsSps ltr;
823  StdVideoH265ProfileTierLevel ptl_sps;
824  StdVideoH265DecPicBufMgr dpbm_sps;
825 
826  StdVideoH265HrdParameters vui_header_sps;
827  StdVideoH265SequenceParameterSetVui vui_sps;
828 
829  StdVideoH265SubLayerHrdParameters slhdrnal[HEVC_MAX_SUB_LAYERS];
830  StdVideoH265SubLayerHrdParameters slhdrvcl[HEVC_MAX_SUB_LAYERS];
831 
832  StdVideoH265PictureParameterSet pps;
833  StdVideoH265ScalingLists pps_scaling;
834 
835  StdVideoH265VideoParameterSet vps;
836  StdVideoH265ProfileTierLevel ptl_vps;
837  StdVideoH265DecPicBufMgr dpbm_vps;
838  StdVideoH265HrdParameters vui_header_vps;
840 
842  VulkanH265Units *vk_units)
843 {
844  VulkanEncodeH265Context *enc = avctx->priv_data;
845 
846  H265RawSPS *sps = &enc->units.raw_sps;
847  StdVideoH265SequenceParameterSet *vksps = &vk_units->sps;
848  StdVideoH265ShortTermRefPicSet *str = vk_units->str;
849  StdVideoH265LongTermRefPicsSps *ltr = &vk_units->ltr;
850  StdVideoH265ProfileTierLevel *ptl_sps = &vk_units->ptl_sps;
851  StdVideoH265DecPicBufMgr *dpbm_sps = &vk_units->dpbm_sps;
852 
853  StdVideoH265HrdParameters *vui_header_sps = &vk_units->vui_header_sps;
854  StdVideoH265SequenceParameterSetVui *vui_sps = &vk_units->vui_sps;
855 
856  StdVideoH265SubLayerHrdParameters *slhdrnal = vk_units->slhdrnal;
857  StdVideoH265SubLayerHrdParameters *slhdrvcl = vk_units->slhdrvcl;
858 
859  H265RawPPS *pps = &enc->units.raw_pps;
860  StdVideoH265PictureParameterSet *vkpps = &vk_units->pps;
861 
862  H265RawVPS *vps = &enc->units.raw_vps;
863  StdVideoH265VideoParameterSet *vkvps = &vk_units->vps;
864  StdVideoH265ProfileTierLevel *ptl_vps = &vk_units->ptl_vps;
865  StdVideoH265DecPicBufMgr *dpbm_vps = &vk_units->dpbm_vps;
866  StdVideoH265HrdParameters *vui_header_vps = &vk_units->vui_header_vps;
867 
868  /* SPS */
869  for (int i = 0; i < HEVC_MAX_SUB_LAYERS; i++) {
870  memcpy(&slhdrnal[i], &sps->vui.hrd_parameters.nal_sub_layer_hrd_parameters[i], sizeof(*slhdrnal));
871  memcpy(&slhdrvcl[i], &sps->vui.hrd_parameters.vcl_sub_layer_hrd_parameters[i], sizeof(*slhdrvcl));
872  slhdrnal[i].cbr_flag = 0x0;
873  slhdrvcl[i].cbr_flag = 0x0;
874  for (int j = 0; j < HEVC_MAX_CPB_CNT; j++) {
875  slhdrnal[i].cbr_flag |= sps->vui.hrd_parameters.nal_sub_layer_hrd_parameters[i].cbr_flag[j] << i;
876  slhdrvcl[i].cbr_flag |= sps->vui.hrd_parameters.vcl_sub_layer_hrd_parameters[i].cbr_flag[j] << i;
877  }
878  }
879 
880  *vui_header_sps = (StdVideoH265HrdParameters) {
881  .flags = (StdVideoH265HrdFlags) {
882  .nal_hrd_parameters_present_flag = sps->vui.hrd_parameters.nal_hrd_parameters_present_flag,
883  .vcl_hrd_parameters_present_flag = sps->vui.hrd_parameters.vcl_hrd_parameters_present_flag,
884  .sub_pic_hrd_params_present_flag = sps->vui.hrd_parameters.sub_pic_hrd_params_present_flag,
885  .sub_pic_cpb_params_in_pic_timing_sei_flag = sps->vui.hrd_parameters.sub_pic_cpb_params_in_pic_timing_sei_flag,
886  .fixed_pic_rate_general_flag = 0x0,
887  .fixed_pic_rate_within_cvs_flag = 0x0,
888  .low_delay_hrd_flag = 0x0,
889  },
890  .tick_divisor_minus2 = sps->vui.hrd_parameters.tick_divisor_minus2,
891  .du_cpb_removal_delay_increment_length_minus1 = sps->vui.hrd_parameters.du_cpb_removal_delay_increment_length_minus1,
892  .dpb_output_delay_du_length_minus1 = sps->vui.hrd_parameters.dpb_output_delay_du_length_minus1,
893  .bit_rate_scale = sps->vui.hrd_parameters.bit_rate_scale,
894  .cpb_size_scale = sps->vui.hrd_parameters.cpb_size_scale,
895  .cpb_size_du_scale = sps->vui.hrd_parameters.cpb_size_du_scale,
896  .initial_cpb_removal_delay_length_minus1 = sps->vui.hrd_parameters.initial_cpb_removal_delay_length_minus1,
897  .au_cpb_removal_delay_length_minus1 = sps->vui.hrd_parameters.au_cpb_removal_delay_length_minus1,
898  .dpb_output_delay_length_minus1 = sps->vui.hrd_parameters.dpb_output_delay_length_minus1,
899  /* Reserved - 3*16 bits */
900  .pSubLayerHrdParametersNal = slhdrnal,
901  .pSubLayerHrdParametersVcl = slhdrvcl,
902  };
903 
904  for (int i = 0; i < HEVC_MAX_SUB_LAYERS; i++) {
905  vui_header_sps->flags.fixed_pic_rate_general_flag |= sps->vui.hrd_parameters.fixed_pic_rate_general_flag[i] << i;
906  vui_header_sps->flags.fixed_pic_rate_within_cvs_flag |= sps->vui.hrd_parameters.fixed_pic_rate_within_cvs_flag[i] << i;
907  vui_header_sps->flags.low_delay_hrd_flag |= sps->vui.hrd_parameters.low_delay_hrd_flag[i] << i;
908  }
909 
910  for (int i = 0; i < STD_VIDEO_H265_SUBLAYERS_LIST_SIZE; i++) {
911  dpbm_sps->max_latency_increase_plus1[i] = sps->sps_max_latency_increase_plus1[i];
912  dpbm_sps->max_dec_pic_buffering_minus1[i] = sps->sps_max_dec_pic_buffering_minus1[i];
913  dpbm_sps->max_num_reorder_pics[i] = sps->sps_max_num_reorder_pics[i];
914  }
915 
916  *ptl_sps = (StdVideoH265ProfileTierLevel) {
917  .flags = (StdVideoH265ProfileTierLevelFlags) {
918  .general_tier_flag = sps->profile_tier_level.general_tier_flag,
919  .general_progressive_source_flag = sps->profile_tier_level.general_progressive_source_flag,
920  .general_interlaced_source_flag = sps->profile_tier_level.general_interlaced_source_flag,
921  .general_non_packed_constraint_flag = sps->profile_tier_level.general_non_packed_constraint_flag,
922  .general_frame_only_constraint_flag = sps->profile_tier_level.general_frame_only_constraint_flag,
923  },
924  .general_profile_idc = ff_vk_h265_profile_to_vk(sps->profile_tier_level.general_profile_idc),
925  .general_level_idc = ff_vk_h265_level_to_vk(sps->profile_tier_level.general_level_idc),
926  };
927 
928  for (int i = 0; i < STD_VIDEO_H265_MAX_SHORT_TERM_REF_PIC_SETS; i++) {
929  const H265RawSTRefPicSet *st_rps = &sps->st_ref_pic_set[i];
930 
931  str[i] = (StdVideoH265ShortTermRefPicSet) {
932  .flags = (StdVideoH265ShortTermRefPicSetFlags) {
933  .inter_ref_pic_set_prediction_flag = st_rps->inter_ref_pic_set_prediction_flag,
934  .delta_rps_sign = st_rps->delta_rps_sign,
935  },
936  .delta_idx_minus1 = st_rps->delta_idx_minus1,
937  .use_delta_flag = 0x0,
938  .abs_delta_rps_minus1 = st_rps->abs_delta_rps_minus1,
939  .used_by_curr_pic_flag = 0x0,
940  .used_by_curr_pic_s0_flag = 0x0,
941  .used_by_curr_pic_s1_flag = 0x0,
942  /* Reserved */
943  /* Reserved */
944  /* Reserved */
945  .num_negative_pics = st_rps->num_negative_pics,
946  .num_positive_pics = st_rps->num_positive_pics,
947  };
948 
949  for (int j = 0; j < HEVC_MAX_REFS; j++) {
950  str[i].use_delta_flag |= st_rps->use_delta_flag[j] << i;
951  str[i].used_by_curr_pic_flag |= st_rps->used_by_curr_pic_flag[j] << i;
952  str[i].used_by_curr_pic_s0_flag |= st_rps->used_by_curr_pic_s0_flag[j] << i;
953  str[i].used_by_curr_pic_s1_flag |= st_rps->used_by_curr_pic_s1_flag[j] << i;
954  str[i].delta_poc_s0_minus1[j] = st_rps->delta_poc_s0_minus1[j];
955  str[i].delta_poc_s1_minus1[j] = st_rps->delta_poc_s1_minus1[j];
956  }
957  }
958 
959  ltr->used_by_curr_pic_lt_sps_flag = 0;
960  for (int i = 0; i < STD_VIDEO_H265_MAX_LONG_TERM_REF_PICS_SPS; i++) {
961  ltr->used_by_curr_pic_lt_sps_flag |= sps->lt_ref_pic_poc_lsb_sps[i] << i;
962  ltr->lt_ref_pic_poc_lsb_sps[i] = sps->lt_ref_pic_poc_lsb_sps[i];
963  }
964 
965  *vksps = (StdVideoH265SequenceParameterSet) {
966  .flags = (StdVideoH265SpsFlags) {
967  .sps_temporal_id_nesting_flag = sps->sps_temporal_id_nesting_flag,
968  .separate_colour_plane_flag = sps->separate_colour_plane_flag,
969  .conformance_window_flag = sps->conformance_window_flag,
970  .sps_sub_layer_ordering_info_present_flag = sps->sps_sub_layer_ordering_info_present_flag,
971  .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
972  .sps_scaling_list_data_present_flag = sps->sps_scaling_list_data_present_flag,
973  .amp_enabled_flag = sps->amp_enabled_flag,
974  .sample_adaptive_offset_enabled_flag = sps->sample_adaptive_offset_enabled_flag,
975  .pcm_enabled_flag = sps->pcm_enabled_flag,
976  .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
977  .long_term_ref_pics_present_flag = sps->long_term_ref_pics_present_flag,
978  .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
979  .strong_intra_smoothing_enabled_flag = sps->strong_intra_smoothing_enabled_flag,
980  .vui_parameters_present_flag = sps->vui_parameters_present_flag,
981  .sps_extension_present_flag = sps->sps_extension_present_flag,
982  .sps_range_extension_flag = sps->sps_range_extension_flag,
983  .transform_skip_rotation_enabled_flag = sps->transform_skip_rotation_enabled_flag,
984  .transform_skip_context_enabled_flag = sps->transform_skip_context_enabled_flag,
985  .implicit_rdpcm_enabled_flag = sps->implicit_rdpcm_enabled_flag,
986  .explicit_rdpcm_enabled_flag = sps->explicit_rdpcm_enabled_flag,
987  .extended_precision_processing_flag = sps->extended_precision_processing_flag,
988  .intra_smoothing_disabled_flag = sps->intra_smoothing_disabled_flag,
989  .high_precision_offsets_enabled_flag = sps->high_precision_offsets_enabled_flag,
990  .persistent_rice_adaptation_enabled_flag = sps->persistent_rice_adaptation_enabled_flag,
991  .cabac_bypass_alignment_enabled_flag = sps->cabac_bypass_alignment_enabled_flag,
992  .sps_scc_extension_flag = sps->sps_scc_extension_flag,
993  .sps_curr_pic_ref_enabled_flag = sps->sps_curr_pic_ref_enabled_flag,
994  .palette_mode_enabled_flag = sps->palette_mode_enabled_flag,
995  .sps_palette_predictor_initializers_present_flag = sps->sps_palette_predictor_initializer_present_flag,
996  .intra_boundary_filtering_disabled_flag = sps->intra_boundary_filtering_disable_flag,
997  },
998  .chroma_format_idc = sps->chroma_format_idc,
999  .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
1000  .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
1001  .sps_video_parameter_set_id = sps->sps_video_parameter_set_id,
1002  .sps_max_sub_layers_minus1 = sps->sps_max_sub_layers_minus1,
1003  .sps_seq_parameter_set_id = sps->sps_seq_parameter_set_id,
1004  .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
1005  .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
1006  .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_pic_order_cnt_lsb_minus4,
1007  .log2_min_luma_coding_block_size_minus3 = sps->log2_min_luma_coding_block_size_minus3,
1008  .log2_diff_max_min_luma_coding_block_size = sps->log2_diff_max_min_luma_coding_block_size,
1009  .log2_min_luma_transform_block_size_minus2 = sps->log2_min_luma_transform_block_size_minus2,
1010  .log2_diff_max_min_luma_transform_block_size = sps->log2_diff_max_min_luma_transform_block_size,
1011  .max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter,
1012  .max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra,
1013  .num_short_term_ref_pic_sets = sps->num_short_term_ref_pic_sets,
1014  .num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps,
1015  .pcm_sample_bit_depth_luma_minus1 = sps->pcm_sample_bit_depth_luma_minus1,
1016  .pcm_sample_bit_depth_chroma_minus1 = sps->pcm_sample_bit_depth_chroma_minus1,
1017  .log2_min_pcm_luma_coding_block_size_minus3 = sps->log2_min_pcm_luma_coding_block_size_minus3,
1018  .log2_diff_max_min_pcm_luma_coding_block_size = sps->log2_diff_max_min_pcm_luma_coding_block_size,
1019  /* Reserved */
1020  /* Reserved */
1021  .palette_max_size = sps->palette_max_size,
1022  .delta_palette_max_predictor_size = sps->delta_palette_max_predictor_size,
1023  .motion_vector_resolution_control_idc = sps->motion_vector_resolution_control_idc,
1024  .sps_num_palette_predictor_initializers_minus1 = sps->sps_num_palette_predictor_initializer_minus1,
1025  .conf_win_left_offset = sps->conf_win_left_offset,
1026  .conf_win_right_offset = sps->conf_win_right_offset,
1027  .conf_win_top_offset = sps->conf_win_top_offset,
1028  .conf_win_bottom_offset = sps->conf_win_bottom_offset,
1029  .pProfileTierLevel = ptl_sps,
1030  .pDecPicBufMgr = dpbm_sps,
1031  .pScalingLists = NULL,
1032  .pShortTermRefPicSet = str,
1033  .pLongTermRefPicsSps = ltr,
1034  .pSequenceParameterSetVui = vui_sps,
1035  .pPredictorPaletteEntries = NULL,
1036  };
1037 
1038  /* PPS */
1039  *vkpps = (StdVideoH265PictureParameterSet) {
1040  .flags = (StdVideoH265PpsFlags) {
1041  .dependent_slice_segments_enabled_flag = pps->dependent_slice_segments_enabled_flag,
1042  .output_flag_present_flag = pps->output_flag_present_flag,
1043  .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
1044  .cabac_init_present_flag = pps->cabac_init_present_flag,
1045  .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
1046  .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
1047  .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
1048  .pps_slice_chroma_qp_offsets_present_flag = pps->pps_slice_chroma_qp_offsets_present_flag,
1049  .weighted_pred_flag = pps->weighted_pred_flag,
1050  .weighted_bipred_flag = pps->weighted_bipred_flag,
1051  .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
1052  .tiles_enabled_flag = pps->tiles_enabled_flag,
1053  .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
1054  .uniform_spacing_flag = pps->uniform_spacing_flag,
1055  .loop_filter_across_tiles_enabled_flag = pps->loop_filter_across_tiles_enabled_flag,
1056  .pps_loop_filter_across_slices_enabled_flag = pps->pps_loop_filter_across_slices_enabled_flag,
1057  .deblocking_filter_control_present_flag = pps->deblocking_filter_control_present_flag,
1058  .deblocking_filter_override_enabled_flag = pps->deblocking_filter_override_enabled_flag,
1059  .pps_deblocking_filter_disabled_flag = pps->pps_deblocking_filter_disabled_flag,
1060  .pps_scaling_list_data_present_flag = pps->pps_scaling_list_data_present_flag,
1061  .lists_modification_present_flag = pps->lists_modification_present_flag,
1062  .slice_segment_header_extension_present_flag = pps->slice_segment_header_extension_present_flag,
1063  .pps_extension_present_flag = pps->pps_extension_present_flag,
1064  .cross_component_prediction_enabled_flag = pps->cross_component_prediction_enabled_flag,
1065  .chroma_qp_offset_list_enabled_flag = pps->chroma_qp_offset_list_enabled_flag,
1066  .pps_curr_pic_ref_enabled_flag = pps->pps_curr_pic_ref_enabled_flag,
1067  .residual_adaptive_colour_transform_enabled_flag = pps->residual_adaptive_colour_transform_enabled_flag,
1068  .pps_slice_act_qp_offsets_present_flag = pps->pps_slice_act_qp_offsets_present_flag,
1069  .pps_palette_predictor_initializers_present_flag = pps->pps_palette_predictor_initializer_present_flag,
1070  .monochrome_palette_flag = pps->monochrome_palette_flag,
1071  .pps_range_extension_flag = pps->pps_range_extension_flag,
1072  },
1073  .pps_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
1074  .pps_seq_parameter_set_id = pps->pps_seq_parameter_set_id,
1075  .sps_video_parameter_set_id = sps->sps_video_parameter_set_id,
1076  .num_extra_slice_header_bits = pps->num_extra_slice_header_bits,
1077  .num_ref_idx_l0_default_active_minus1 = pps->num_ref_idx_l0_default_active_minus1,
1078  .num_ref_idx_l1_default_active_minus1 = pps->num_ref_idx_l1_default_active_minus1,
1079  .init_qp_minus26 = pps->init_qp_minus26,
1080  .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
1081  .pps_cb_qp_offset = pps->pps_cb_qp_offset,
1082  .pps_cr_qp_offset = pps->pps_cr_qp_offset,
1083  .pps_beta_offset_div2 = pps->pps_beta_offset_div2,
1084  .pps_tc_offset_div2 = pps->pps_tc_offset_div2,
1085  .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
1086  .log2_max_transform_skip_block_size_minus2 = pps->log2_max_transform_skip_block_size_minus2,
1087  .diff_cu_chroma_qp_offset_depth = pps->diff_cu_chroma_qp_offset_depth,
1088  .chroma_qp_offset_list_len_minus1 = pps->chroma_qp_offset_list_len_minus1,
1089  .log2_sao_offset_scale_luma = pps->log2_sao_offset_scale_luma,
1090  .log2_sao_offset_scale_chroma = pps->log2_sao_offset_scale_chroma,
1091  .pps_act_y_qp_offset_plus5 = pps->pps_act_y_qp_offset_plus5,
1092  .pps_act_cb_qp_offset_plus5 = pps->pps_act_cb_qp_offset_plus5,
1093  .pps_act_cr_qp_offset_plus3 = pps->pps_act_cr_qp_offset_plus3,
1094  .pps_num_palette_predictor_initializers = pps->pps_num_palette_predictor_initializer,
1095  .luma_bit_depth_entry_minus8 = pps->luma_bit_depth_entry_minus8,
1096  .chroma_bit_depth_entry_minus8 = pps->chroma_bit_depth_entry_minus8,
1097  .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
1098  .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
1099  .pScalingLists = NULL,
1100  .pPredictorPaletteEntries = NULL,
1101  };
1102 
1103  for (int i = 0; i < pps->num_tile_columns_minus1; i++)
1104  vkpps->column_width_minus1[i] = pps->column_width_minus1[i];
1105 
1106  for (int i = 0; i < pps->num_tile_rows_minus1; i++)
1107  vkpps->row_height_minus1[i] = pps->row_height_minus1[i];
1108 
1109  for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
1110  vkpps->cb_qp_offset_list[i] = pps->cb_qp_offset_list[i];
1111  vkpps->cr_qp_offset_list[i] = pps->cr_qp_offset_list[i];
1112  }
1113 
1114  /* VPS */
1115  for (int i = 0; i < STD_VIDEO_H265_SUBLAYERS_LIST_SIZE; i++) {
1116  dpbm_vps->max_latency_increase_plus1[i] = vps->vps_max_latency_increase_plus1[i];
1117  dpbm_vps->max_dec_pic_buffering_minus1[i] = vps->vps_max_dec_pic_buffering_minus1[i];
1118  dpbm_vps->max_num_reorder_pics[i] = vps->vps_max_num_reorder_pics[i];
1119  }
1120 
1121  *ptl_vps = (StdVideoH265ProfileTierLevel) {
1122  .flags = (StdVideoH265ProfileTierLevelFlags) {
1123  .general_tier_flag = vps->profile_tier_level.general_tier_flag,
1124  .general_progressive_source_flag = vps->profile_tier_level.general_progressive_source_flag,
1125  .general_interlaced_source_flag = vps->profile_tier_level.general_interlaced_source_flag,
1126  .general_non_packed_constraint_flag = vps->profile_tier_level.general_non_packed_constraint_flag,
1127  .general_frame_only_constraint_flag = vps->profile_tier_level.general_frame_only_constraint_flag,
1128  },
1129  .general_profile_idc = ff_vk_h265_profile_to_vk(vps->profile_tier_level.general_profile_idc),
1130  .general_level_idc = ff_vk_h265_level_to_vk(vps->profile_tier_level.general_level_idc),
1131  };
1132 
1133  *vkvps = (StdVideoH265VideoParameterSet) {
1134  .flags = (StdVideoH265VpsFlags) {
1135  .vps_temporal_id_nesting_flag = vps->vps_temporal_id_nesting_flag,
1136  .vps_sub_layer_ordering_info_present_flag = vps->vps_sub_layer_ordering_info_present_flag,
1137  .vps_timing_info_present_flag = vps->vps_timing_info_present_flag,
1138  .vps_poc_proportional_to_timing_flag = vps->vps_poc_proportional_to_timing_flag,
1139  },
1140  .vps_video_parameter_set_id = vps->vps_video_parameter_set_id,
1141  .vps_max_sub_layers_minus1 = vps->vps_max_sub_layers_minus1,
1142  /* Reserved */
1143  /* Reserved */
1144  .vps_num_units_in_tick = vps->vps_num_units_in_tick,
1145  .vps_time_scale = vps->vps_time_scale,
1146  .vps_num_ticks_poc_diff_one_minus1 = vps->vps_num_ticks_poc_diff_one_minus1,
1147  /* Reserved */
1148  .pDecPicBufMgr = dpbm_vps,
1149  .pHrdParameters = vui_header_vps,
1150  .pProfileTierLevel = ptl_vps,
1151  };
1152 
1153  return 0;
1154 }
1155 
1157 {
1158  int err;
1159  VulkanEncodeH265Context *enc = avctx->priv_data;
1160  FFVulkanEncodeContext *ctx = &enc->common;
1161  FFVulkanContext *s = &ctx->s;
1162  FFVulkanFunctions *vk = &ctx->s.vkfn;
1163 
1164  VulkanH265Units vk_units = { 0 };
1165 
1166  VkVideoEncodeH265SessionParametersAddInfoKHR h265_params_info;
1167  VkVideoEncodeH265SessionParametersCreateInfoKHR h265_params;
1168 
1169  /* Convert it to Vulkan */
1170  err = base_unit_to_vk(avctx, &vk_units);
1171  if (err < 0) {
1172  av_log(avctx, AV_LOG_ERROR, "Unable to convert SPS/PPS units to Vulkan: %s\n",
1173  av_err2str(err));
1174  return err;
1175  }
1176 
1177  /* Destroy the session params */
1178  if (ctx->session_params)
1179  vk->DestroyVideoSessionParametersKHR(s->hwctx->act_dev,
1180  ctx->session_params,
1181  s->hwctx->alloc);
1182 
1183  h265_params_info = (VkVideoEncodeH265SessionParametersAddInfoKHR) {
1184  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_SESSION_PARAMETERS_ADD_INFO_KHR,
1185  .pStdSPSs = &vk_units.sps,
1186  .stdSPSCount = 1,
1187  .pStdPPSs = &vk_units.pps,
1188  .stdPPSCount = 1,
1189  .pStdVPSs = &vk_units.vps,
1190  .stdVPSCount = 1,
1191  };
1192  h265_params = (VkVideoEncodeH265SessionParametersCreateInfoKHR) {
1193  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_SESSION_PARAMETERS_CREATE_INFO_KHR,
1194  .maxStdSPSCount = 1,
1195  .maxStdPPSCount = 1,
1196  .maxStdVPSCount = 1,
1197  .pParametersAddInfo = &h265_params_info,
1198  };
1199 
1200  return ff_vulkan_encode_create_session_params(avctx, ctx, &h265_params);
1201 }
1202 
1204  const uint8_t *data, size_t size,
1205  int sps_override, int pps_override)
1206 {
1207  int err;
1208  VulkanEncodeH265Context *enc = avctx->priv_data;
1209 
1210  CodedBitstreamContext *cbs;
1211  CodedBitstreamFragment au = { 0 };
1212 
1213  err = ff_cbs_init(&cbs, AV_CODEC_ID_HEVC, avctx);
1214  if (err < 0)
1215  return err;
1216 
1217  err = ff_cbs_read(cbs, &au, data, size);
1218  if (err < 0) {
1219  av_log(avctx, AV_LOG_ERROR, "Unable to parse feedback units, bad drivers: %s\n",
1220  av_err2str(err));
1221  return err;
1222  }
1223 
1224  if (sps_override) {
1225  for (int i = 0; i < au.nb_units; i++) {
1226  if (au.units[i].type == HEVC_NAL_SPS) {
1227  H265RawSPS *sps = au.units[i].content;
1228  enc->units.raw_sps.pic_width_in_luma_samples = sps->pic_width_in_luma_samples;
1229  enc->units.raw_sps.pic_height_in_luma_samples = sps->pic_height_in_luma_samples;
1230  enc->units.raw_sps.log2_diff_max_min_luma_coding_block_size = sps->log2_diff_max_min_luma_coding_block_size;
1231  enc->units.raw_sps.max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter;
1232  enc->units.raw_sps.max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra;
1233  }
1234  }
1235  }
1236 
1237  /* If PPS has an override, just copy it entirely. */
1238  if (pps_override) {
1239  for (int i = 0; i < au.nb_units; i++) {
1240  if (au.units[i].type == HEVC_NAL_PPS) {
1241  H265RawPPS *pps = au.units[i].content;
1242  memcpy(&enc->units.raw_pps, pps, sizeof(*pps));
1243  enc->fixed_qp_idr = pps->init_qp_minus26 + 26;
1244  break;
1245  }
1246  }
1247  }
1248 
1249  ff_cbs_fragment_free(&au);
1250  ff_cbs_close(&cbs);
1251 
1252  return 0;
1253 }
1254 
1256 {
1257  int err;
1258  VkResult ret;
1259  VulkanEncodeH265Context *enc = avctx->priv_data;
1260  FFVulkanEncodeContext *ctx = &enc->common;
1261  FFVulkanContext *s = &ctx->s;
1262  FFVulkanFunctions *vk = &ctx->s.vkfn;
1263 
1264  VkVideoEncodeH265SessionParametersGetInfoKHR h265_params_info;
1265  VkVideoEncodeSessionParametersGetInfoKHR params_info;
1266  VkVideoEncodeH265SessionParametersFeedbackInfoKHR h265_params_feedback;
1267  VkVideoEncodeSessionParametersFeedbackInfoKHR params_feedback;
1268 
1269  void *data = NULL;
1270  size_t data_size = 0;
1271 
1272  /* Generate SPS/PPS unit info */
1273  err = init_sequence_headers(avctx);
1274  if (err < 0) {
1275  av_log(avctx, AV_LOG_ERROR, "Unable to initialize SPS/PPS units: %s\n",
1276  av_err2str(err));
1277  return err;
1278  }
1279 
1280  /* Create session parameters from them */
1281  err = create_session_params(avctx);
1282  if (err < 0)
1283  return err;
1284 
1285  h265_params_info = (VkVideoEncodeH265SessionParametersGetInfoKHR) {
1286  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_SESSION_PARAMETERS_GET_INFO_KHR,
1287  .writeStdSPS = 1,
1288  .writeStdPPS = 1,
1289  .writeStdVPS = 1,
1290  .stdSPSId = enc->units.raw_sps.sps_seq_parameter_set_id,
1291  .stdPPSId = enc->units.raw_pps.pps_pic_parameter_set_id,
1292  .stdVPSId = enc->units.raw_vps.vps_video_parameter_set_id,
1293  };
1294  params_info = (VkVideoEncodeSessionParametersGetInfoKHR) {
1295  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_SESSION_PARAMETERS_GET_INFO_KHR,
1296  .pNext = &h265_params_info,
1297  .videoSessionParameters = ctx->session_params,
1298  };
1299 
1300  h265_params_feedback = (VkVideoEncodeH265SessionParametersFeedbackInfoKHR) {
1301  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_SESSION_PARAMETERS_FEEDBACK_INFO_KHR,
1302  };
1303  params_feedback = (VkVideoEncodeSessionParametersFeedbackInfoKHR) {
1304  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_SESSION_PARAMETERS_FEEDBACK_INFO_KHR,
1305  .pNext = &h265_params_feedback,
1306  };
1307 
1308  ret = vk->GetEncodedVideoSessionParametersKHR(s->hwctx->act_dev, &params_info,
1309  &params_feedback,
1310  &data_size, data);
1311  if (ret == VK_INCOMPLETE ||
1312  (ret == VK_SUCCESS) && (data_size > 0)) {
1313  data = av_mallocz(data_size);
1314  if (!data)
1315  return AVERROR(ENOMEM);
1316  } else {
1317  av_log(avctx, AV_LOG_ERROR, "Unable to get feedback for H.265 units = %"SIZE_SPECIFIER"\n", data_size);
1318  return err;
1319  }
1320 
1321  ret = vk->GetEncodedVideoSessionParametersKHR(s->hwctx->act_dev, &params_info,
1322  &params_feedback,
1323  &data_size, data);
1324  if (ret != VK_SUCCESS) {
1325  av_log(avctx, AV_LOG_ERROR, "Error writing feedback units\n");
1326  return err;
1327  }
1328 
1329  av_log(avctx, AV_LOG_VERBOSE, "Feedback units written, overrides: %i (SPS: %i PPS: %i VPS: %i)\n",
1330  params_feedback.hasOverrides,
1331  h265_params_feedback.hasStdSPSOverrides,
1332  h265_params_feedback.hasStdPPSOverrides,
1333  h265_params_feedback.hasStdVPSOverrides);
1334 
1335  params_feedback.hasOverrides = 1;
1336  h265_params_feedback.hasStdSPSOverrides = 1;
1337  h265_params_feedback.hasStdPPSOverrides = 1;
1338 
1339  /* No need to sync any overrides */
1340  if (!params_feedback.hasOverrides)
1341  return 0;
1342 
1343  /* Parse back tne units and override */
1344  err = parse_feedback_units(avctx, data, data_size,
1345  h265_params_feedback.hasStdSPSOverrides,
1346  h265_params_feedback.hasStdPPSOverrides);
1347  if (err < 0)
1348  return err;
1349 
1350  /* Create final session parameters */
1351  err = create_session_params(avctx);
1352  if (err < 0)
1353  return err;
1354 
1355  return 0;
1356 }
1357 
1360  void *nal_unit)
1361 {
1362  H265RawNALUnitHeader *header = nal_unit;
1363 
1364  int err = ff_cbs_insert_unit_content(au, -1,
1365  header->nal_unit_type, nal_unit, NULL);
1366  if (err < 0)
1367  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
1368  "type = %d.\n", header->nal_unit_type);
1369 
1370  return err;
1371 }
1372 
1374  uint8_t *data, size_t *data_len,
1376 {
1377  VulkanEncodeH265Context *enc = avctx->priv_data;
1378 
1379  int err = ff_cbs_write_fragment_data(enc->cbs, au);
1380  if (err < 0) {
1381  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
1382  return err;
1383  }
1384 
1385  if (*data_len < au->data_size) {
1386  av_log(avctx, AV_LOG_ERROR, "Access unit too large: %zu < %zu.\n",
1387  *data_len, au->data_size);
1388  return AVERROR(ENOSPC);
1389  }
1390 
1391  memcpy(data, au->data, au->data_size);
1392  *data_len = au->data_size;
1393 
1394  return 0;
1395 }
1396 
1398  FFHWBaseEncodePicture *base_pic,
1399  uint8_t *data, size_t *data_len)
1400 {
1401  int err;
1402  VulkanEncodeH265Context *enc = avctx->priv_data;
1403  VulkanEncodeH265Picture *hp = base_pic ? base_pic->codec_priv : NULL;
1405 
1406  if (hp && hp->units_needed & UNIT_AUD) {
1407  err = vulkan_encode_h265_add_nal(avctx, au, &enc->raw_aud);
1408  if (err < 0)
1409  goto fail;
1410  hp->units_needed &= ~UNIT_AUD;
1411  }
1412 
1413  err = vulkan_encode_h265_add_nal(avctx, au, &enc->units.raw_vps);
1414  if (err < 0)
1415  goto fail;
1416 
1417  err = vulkan_encode_h265_add_nal(avctx, au, &enc->units.raw_sps);
1418  if (err < 0)
1419  goto fail;
1420 
1421  err = vulkan_encode_h265_add_nal(avctx, au, &enc->units.raw_pps);
1422  if (err < 0)
1423  goto fail;
1424 
1425  err = write_access_unit(avctx, data, data_len, au);
1426 fail:
1428  return err;
1429 }
1430 
1432  FFHWBaseEncodePicture *base_pic,
1433  uint8_t *data, size_t *data_len)
1434 {
1435  int err;
1436  VulkanEncodeH265Context *enc = avctx->priv_data;
1437  VulkanEncodeH265Picture *hp = base_pic->codec_priv;
1439 
1440  if (hp->units_needed & UNIT_AUD) {
1441  err = vulkan_encode_h265_add_nal(avctx, au, &enc->raw_aud);
1442  if (err < 0)
1443  goto fail;
1444  }
1445 
1447  err = ff_cbs_sei_add_message(enc->cbs, au, 1,
1449  &enc->sei_mastering_display, NULL);
1450  if (err < 0)
1451  goto fail;
1452  }
1453 
1455  err = ff_cbs_sei_add_message(enc->cbs, au, 1,
1457  &enc->sei_content_light_level, NULL);
1458  if (err < 0)
1459  goto fail;
1460  }
1461  if (hp->units_needed & UNIT_SEI_A53_CC) {
1462  err = ff_cbs_sei_add_message(enc->cbs, au, 1,
1464  &enc->sei_a53cc, NULL);
1465  if (err < 0)
1466  goto fail;
1467  }
1468 
1469  if (hp->units_needed) {
1470  err = write_access_unit(avctx, data, data_len, au);
1471  if (err < 0)
1472  goto fail;
1473  } else {
1474  *data_len = 0;
1475  }
1476 
1477 fail:
1479  return err;
1480 }
1481 
1482 static int write_filler(AVCodecContext *avctx, uint32_t filler,
1483  uint8_t *data, size_t *data_len)
1484 {
1485  int err;
1486  VulkanEncodeH265Context *enc = avctx->priv_data;
1488 
1489  H265RawFiller raw_filler = {
1490  .nal_unit_header =
1491  {
1493  .nuh_temporal_id_plus1 = 1,
1494  },
1495  .filler_size = filler,
1496  };
1497 
1498  err = vulkan_encode_h265_add_nal(avctx, au, &raw_filler);
1499  if (err < 0)
1500  goto fail;
1501 
1502  err = write_access_unit(avctx, data, data_len, au);
1503 fail:
1505  return err;
1506 }
1507 
1508 static const FFVulkanCodec enc_cb = {
1512  .picture_priv_data_size = sizeof(VulkanEncodeH265Picture),
1513  .filler_header_size = 7,
1520 };
1521 
1523 {
1524  int err, ref_l0, ref_l1;
1525  VulkanEncodeH265Context *enc = avctx->priv_data;
1526  FFVulkanEncodeContext *ctx = &enc->common;
1527  FFHWBaseEncodeContext *base_ctx = &ctx->base;
1528  int flags;
1529 
1530  if (avctx->profile == AV_PROFILE_UNKNOWN)
1531  avctx->profile = enc->common.opts.profile;
1532 
1533  enc->caps = (VkVideoEncodeH265CapabilitiesKHR) {
1534  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_CAPABILITIES_KHR,
1535  };
1536 
1537  enc->quality_props = (VkVideoEncodeH265QualityLevelPropertiesKHR) {
1538  .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_QUALITY_LEVEL_PROPERTIES_KHR,
1539  };
1540 
1541  err = ff_vulkan_encode_init(avctx, &enc->common,
1543  &enc->caps, &enc->quality_props);
1544  if (err < 0)
1545  return err;
1546 
1547  av_log(avctx, AV_LOG_VERBOSE, "H265 encoder capabilities:\n");
1548  av_log(avctx, AV_LOG_VERBOSE, " Standard capability flags:\n");
1549  av_log(avctx, AV_LOG_VERBOSE, " separate_color_plane: %i\n",
1550  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SEPARATE_COLOR_PLANE_FLAG_SET_BIT_KHR));
1551  av_log(avctx, AV_LOG_VERBOSE, " sample_adaptive_offset: %i\n",
1552  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SAMPLE_ADAPTIVE_OFFSET_ENABLED_FLAG_SET_BIT_KHR));
1553  av_log(avctx, AV_LOG_VERBOSE, " scaling_lists: %i\n",
1554  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SCALING_LIST_DATA_PRESENT_FLAG_SET_BIT_KHR));
1555  av_log(avctx, AV_LOG_VERBOSE, " pcm: %i\n",
1556  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_PCM_ENABLED_FLAG_SET_BIT_KHR));
1557  av_log(avctx, AV_LOG_VERBOSE, " temporal_mvp: %i\n",
1558  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SPS_TEMPORAL_MVP_ENABLED_FLAG_SET_BIT_KHR));
1559  av_log(avctx, AV_LOG_VERBOSE, " init_qp: %i\n",
1560  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_INIT_QP_MINUS26_BIT_KHR));
1561  av_log(avctx, AV_LOG_VERBOSE, " weighted:%s%s\n",
1562  enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_WEIGHTED_PRED_FLAG_SET_BIT_KHR ?
1563  " pred" : "",
1564  enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_WEIGHTED_BIPRED_FLAG_SET_BIT_KHR ?
1565  " bipred" : "");
1566  av_log(avctx, AV_LOG_VERBOSE, " parallel_merge_level: %i\n",
1567  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_LOG2_PARALLEL_MERGE_LEVEL_MINUS2_BIT_KHR));
1568  av_log(avctx, AV_LOG_VERBOSE, " sign_data_hiding: %i\n",
1569  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SIGN_DATA_HIDING_ENABLED_FLAG_SET_BIT_KHR));
1570  av_log(avctx, AV_LOG_VERBOSE, " transform_skip:%s%s\n",
1571  enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_TRANSFORM_SKIP_ENABLED_FLAG_SET_BIT_KHR ?
1572  " set" : "",
1573  enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_TRANSFORM_SKIP_ENABLED_FLAG_UNSET_BIT_KHR ?
1574  " unset" : "");
1575  av_log(avctx, AV_LOG_VERBOSE, " slice_chroma_qp_offsets: %i\n",
1576  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT_FLAG_SET_BIT_KHR));
1577  av_log(avctx, AV_LOG_VERBOSE, " transquant_bypass: %i\n",
1578  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_TRANSQUANT_BYPASS_ENABLED_FLAG_SET_BIT_KHR));
1579  av_log(avctx, AV_LOG_VERBOSE, " constrained_intra_pred: %i\n",
1580  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_CONSTRAINED_INTRA_PRED_FLAG_SET_BIT_KHR));
1581  av_log(avctx, AV_LOG_VERBOSE, " entrypy_coding_sync: %i\n",
1582  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_ENTROPY_CODING_SYNC_ENABLED_FLAG_SET_BIT_KHR));
1583  av_log(avctx, AV_LOG_VERBOSE, " dependent_slice_segment:%s%s\n",
1584  enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_DEPENDENT_SLICE_SEGMENTS_ENABLED_FLAG_SET_BIT_KHR ?
1585  " enabled" : "",
1586  enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_DEPENDENT_SLICE_SEGMENT_FLAG_SET_BIT_KHR ?
1587  " set" : "");
1588  av_log(avctx, AV_LOG_VERBOSE, " slice_qp_delta: %i\n",
1589  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_SLICE_QP_DELTA_BIT_KHR));
1590  av_log(avctx, AV_LOG_VERBOSE, " different_slice_qp_delta: %i\n",
1591  !!(enc->caps.stdSyntaxFlags & VK_VIDEO_ENCODE_H265_STD_DIFFERENT_SLICE_QP_DELTA_BIT_KHR));
1592 
1593  av_log(avctx, AV_LOG_VERBOSE, " Capability flags:\n");
1594  av_log(avctx, AV_LOG_VERBOSE, " hdr_compliance: %i\n",
1595  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_HRD_COMPLIANCE_BIT_KHR));
1596  av_log(avctx, AV_LOG_VERBOSE, " pred_weight_table_generated: %i\n",
1597  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_PREDICTION_WEIGHT_TABLE_GENERATED_BIT_KHR));
1598  av_log(avctx, AV_LOG_VERBOSE, " row_unaligned_slice: %i\n",
1599  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_ROW_UNALIGNED_SLICE_BIT_KHR));
1600  av_log(avctx, AV_LOG_VERBOSE, " different_slice_type: %i\n",
1601  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_DIFFERENT_SLICE_TYPE_BIT_KHR));
1602  av_log(avctx, AV_LOG_VERBOSE, " b_frame_in_l0_list: %i\n",
1603  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_B_FRAME_IN_L0_LIST_BIT_KHR));
1604  av_log(avctx, AV_LOG_VERBOSE, " b_frame_in_l1_list: %i\n",
1605  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_B_FRAME_IN_L1_LIST_BIT_KHR));
1606  av_log(avctx, AV_LOG_VERBOSE, " per_pict_type_min_max_qp: %i\n",
1607  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_PER_PICTURE_TYPE_MIN_MAX_QP_BIT_KHR));
1608  av_log(avctx, AV_LOG_VERBOSE, " per_slice_constant_qp: %i\n",
1609  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_PER_SLICE_CONSTANT_QP_BIT_KHR));
1610  av_log(avctx, AV_LOG_VERBOSE, " generate_prefix_nalu: %i\n",
1611  !!(enc->caps.flags & VK_VIDEO_ENCODE_H264_CAPABILITY_GENERATE_PREFIX_NALU_BIT_KHR));
1612 
1613  av_log(avctx, AV_LOG_VERBOSE, " Capabilities:\n");
1614  av_log(avctx, AV_LOG_VERBOSE, " maxLevelIdc: %i\n",
1615  enc->caps.maxLevelIdc);
1616  av_log(avctx, AV_LOG_VERBOSE, " maxSliceCount: %i\n",
1617  enc->caps.maxSliceSegmentCount);
1618  av_log(avctx, AV_LOG_VERBOSE, " maxTiles: %ix%i\n",
1619  enc->caps.maxTiles.width, enc->caps.maxTiles.height);
1620  av_log(avctx, AV_LOG_VERBOSE, " cbtSizes: 0x%x\n",
1621  enc->caps.ctbSizes);
1622  av_log(avctx, AV_LOG_VERBOSE, " transformBlockSizes: 0x%x\n",
1623  enc->caps.transformBlockSizes);
1624  av_log(avctx, AV_LOG_VERBOSE, " max(P/B)PictureL0ReferenceCount: %i P's; %i B's\n",
1625  enc->caps.maxPPictureL0ReferenceCount,
1626  enc->caps.maxBPictureL0ReferenceCount);
1627  av_log(avctx, AV_LOG_VERBOSE, " maxL1ReferenceCount: %i\n",
1628  enc->caps.maxL1ReferenceCount);
1629  av_log(avctx, AV_LOG_VERBOSE, " maxSubLayerCount: %i\n",
1630  enc->caps.maxSubLayerCount);
1631  av_log(avctx, AV_LOG_VERBOSE, " expectDyadicTemporalLayerPattern: %i\n",
1632  enc->caps.expectDyadicTemporalSubLayerPattern);
1633  av_log(avctx, AV_LOG_VERBOSE, " min/max Qp: [%i, %i]\n",
1634  enc->caps.minQp, enc->caps.maxQp);
1635  av_log(avctx, AV_LOG_VERBOSE, " prefersGopRemainingFrames: %i\n",
1636  enc->caps.prefersGopRemainingFrames);
1637  av_log(avctx, AV_LOG_VERBOSE, " requiresGopRemainingFrames: %i\n",
1638  enc->caps.requiresGopRemainingFrames);
1639 
1640  err = init_enc_options(avctx);
1641  if (err < 0)
1642  return err;
1643 
1644  flags = ctx->codec->flags;
1645  if (!enc->caps.maxPPictureL0ReferenceCount &&
1646  !enc->caps.maxBPictureL0ReferenceCount &&
1647  !enc->caps.maxL1ReferenceCount) {
1648  /* Intra-only */
1650  ref_l0 = ref_l1 = 0;
1651  } else if (!enc->caps.maxPPictureL0ReferenceCount) {
1652  /* No P-frames? How. */
1653  base_ctx->p_to_gpb = 1;
1654  ref_l0 = enc->caps.maxBPictureL0ReferenceCount;
1655  ref_l1 = enc->caps.maxL1ReferenceCount;
1656  } else if (!enc->caps.maxBPictureL0ReferenceCount &&
1657  !enc->caps.maxL1ReferenceCount) {
1658  /* No B-frames */
1660  ref_l0 = enc->caps.maxPPictureL0ReferenceCount;
1661  ref_l1 = 0;
1662  } else {
1663  /* P and B frames */
1664  ref_l0 = FFMIN(enc->caps.maxPPictureL0ReferenceCount,
1665  enc->caps.maxBPictureL0ReferenceCount);
1666  ref_l1 = enc->caps.maxL1ReferenceCount;
1667  }
1668 
1669  err = ff_hw_base_init_gop_structure(base_ctx, avctx, ref_l0, ref_l1,
1670  flags, 0);
1671  if (err < 0)
1672  return err;
1673 
1674  base_ctx->output_delay = base_ctx->b_per_p;
1675  base_ctx->decode_delay = base_ctx->max_b_depth;
1676 
1677  /* Init CBS */
1678  err = ff_cbs_init(&enc->cbs, AV_CODEC_ID_HEVC, avctx);
1679  if (err < 0)
1680  return err;
1681 
1682  /* Create units and session parameters */
1683  err = init_base_units(avctx);
1684  if (err < 0)
1685  return err;
1686 
1687  /* Write out extradata */
1688  err = ff_vulkan_write_global_header(avctx, &enc->common);
1689  if (err < 0)
1690  return err;
1691 
1692  return 0;
1693 }
1694 
1696 {
1697  VulkanEncodeH265Context *enc = avctx->priv_data;
1699  return 0;
1700 }
1701 
1702 #define OFFSET(x) offsetof(VulkanEncodeH265Context, x)
1703 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1707 
1708  { "profile", "Set profile (profile_idc and constraint_set*_flag)",
1709  OFFSET(common.opts.profile), AV_OPT_TYPE_INT,
1710  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xffff, FLAGS, .unit = "profile" },
1711 
1712 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1713  { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
1714  { PROFILE("main", AV_PROFILE_HEVC_MAIN) },
1715  { PROFILE("main10", AV_PROFILE_HEVC_MAIN_10) },
1716  { PROFILE("rext", AV_PROFILE_HEVC_REXT) },
1717 #undef PROFILE
1718 
1719  { "tier", "Set tier (general_tier_flag)", OFFSET(common.opts.tier), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS, .unit = "tier" },
1720  { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, .unit = "tier" },
1721  { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, .unit = "tier" },
1722 
1723  { "level", "Set level (general_level_idc)",
1724  OFFSET(common.opts.level), AV_OPT_TYPE_INT,
1725  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, .unit = "level" },
1726 
1727 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1728  { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1729  { LEVEL("1", 30) },
1730  { LEVEL("2", 60) },
1731  { LEVEL("2.1", 63) },
1732  { LEVEL("3", 90) },
1733  { LEVEL("3.1", 93) },
1734  { LEVEL("4", 120) },
1735  { LEVEL("4.1", 123) },
1736  { LEVEL("5", 150) },
1737  { LEVEL("5.1", 153) },
1738  { LEVEL("5.2", 156) },
1739  { LEVEL("6", 180) },
1740  { LEVEL("6.1", 183) },
1741  { LEVEL("6.2", 186) },
1742 #undef LEVEL
1743 
1744  { "units", "Set units to include", OFFSET(unit_elems), AV_OPT_TYPE_FLAGS, { .i64 = UNIT_SEI_MASTERING_DISPLAY | UNIT_SEI_CONTENT_LIGHT_LEVEL | UNIT_SEI_A53_CC }, 0, INT_MAX, FLAGS, "units" },
1745  { "hdr", "Include HDR metadata for mastering display colour volume and content light level information", 0, AV_OPT_TYPE_CONST, { .i64 = UNIT_SEI_MASTERING_DISPLAY | UNIT_SEI_CONTENT_LIGHT_LEVEL }, INT_MIN, INT_MAX, FLAGS, "units" },
1746  { "a53_cc", "Include A/53 caption data", 0, AV_OPT_TYPE_CONST, { .i64 = UNIT_SEI_A53_CC }, INT_MIN, INT_MAX, FLAGS, "units" },
1747 
1748  { NULL },
1749 };
1750 
1752  { "b", "0" },
1753  { "bf", "2" },
1754  { "g", "300" },
1755  { "i_qfactor", "1" },
1756  { "i_qoffset", "0" },
1757  { "b_qfactor", "6/5" },
1758  { "b_qoffset", "0" },
1759  { "qmin", "-1" },
1760  { "qmax", "-1" },
1761  { NULL },
1762 };
1763 
1765  .class_name = "hevc_vulkan",
1766  .item_name = av_default_item_name,
1767  .option = vulkan_encode_h265_options,
1768  .version = LIBAVUTIL_VERSION_INT,
1769 };
1770 
1772  .p.name = "hevc_vulkan",
1773  CODEC_LONG_NAME("H.265/HEVC (Vulkan)"),
1774  .p.type = AVMEDIA_TYPE_VIDEO,
1775  .p.id = AV_CODEC_ID_HEVC,
1776  .priv_data_size = sizeof(VulkanEncodeH265Context),
1779  .close = &vulkan_encode_h265_close,
1780  .p.priv_class = &vulkan_encode_h265_class,
1781  .p.capabilities = AV_CODEC_CAP_DELAY |
1786  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1787  .defaults = vulkan_encode_h265_defaults,
1788  .p.pix_fmts = (const enum AVPixelFormat[]) {
1791  },
1792  .hw_configs = ff_vulkan_encode_hw_configs,
1793  .p.wrapper_name = "vulkan",
1794 };
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
FFHWBaseEncodeContext::output_delay
int64_t output_delay
Definition: hw_base_encode.h:169
SEIRawMasteringDisplayColourVolume::display_primaries_x
uint16_t display_primaries_x[3]
Definition: cbs_sei.h:77
H265RawSPS::log2_diff_max_min_luma_transform_block_size
uint8_t log2_diff_max_min_luma_transform_block_size
Definition: cbs_h265.h:286
ff_alloc_a53_sei
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
Definition: atsc_a53.c:26
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
VulkanEncodeH265Picture::slice_wt
StdVideoEncodeH265WeightTable slice_wt
Definition: vulkan_encode_h265.c:68
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
VulkanH265Units::dpbm_sps
StdVideoH265DecPicBufMgr dpbm_sps
Definition: vulkan_encode_h265.c:824
av_clip
#define av_clip
Definition: common.h:100
FF_HW_PICTURE_TYPE_IDR
@ FF_HW_PICTURE_TYPE_IDR
Definition: hw_base_encode.h:39
VulkanEncodeH265Picture
Definition: vulkan_encode_h265.c:51
H265RawVUI::bitstream_restriction_flag
uint8_t bitstream_restriction_flag
Definition: cbs_h265.h:167
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:43
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
vulkan_encode_h265_add_nal
static int vulkan_encode_h265_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: vulkan_encode_h265.c:1358
opt.h
init_sequence_headers
static av_cold int init_sequence_headers(AVCodecContext *avctx)
Definition: vulkan_encode_h265.c:727
SEIRawUserDataRegistered
Definition: cbs_sei.h:33
FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
Definition: hw_base_encode.h:55
VulkanEncodeH265Picture::h265dpb_info
StdVideoEncodeH265ReferenceInfo h265dpb_info
Definition: vulkan_encode_h265.c:72
ff_vulkan_encode_hw_configs
const AVCodecHWConfigInternal *const ff_vulkan_encode_hw_configs[]
Paperwork.
Definition: vulkan_encode.c:26
VulkanEncodeH265Context::unit_elems
enum UnitElems unit_elems
Definition: vulkan_encode_h265.c:86
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:951
FFHWBaseEncodePicture::priv
void * priv
Definition: hw_base_encode.h:63
FFHWBaseEncodePicture::codec_priv
void * codec_priv
Definition: hw_base_encode.h:65
ff_cbs_fragment_free
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:186
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:145
H265RawSTRefPicSet::abs_delta_rps_minus1
uint16_t abs_delta_rps_minus1
Definition: cbs_h265.h:225
ff_cbs_sei_add_message
int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, int prefix, uint32_t payload_type, void *payload_data, void *payload_ref)
Add an SEI message to an access unit.
Definition: cbs_sei.c:267
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
H265RawSTRefPicSet::use_delta_flag
uint8_t use_delta_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:228
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
VulkanEncodeH265Context::quality_props
VkVideoEncodeH265QualityLevelPropertiesKHR quality_props
Definition: vulkan_encode_h265.c:98
VulkanEncodeH265Picture::vkh265dpb_info
VkVideoEncodeH265DpbSlotInfoKHR vkh265dpb_info
Definition: vulkan_encode_h265.c:73
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
FF_HW_FLAG_B_PICTURES
@ FF_HW_FLAG_B_PICTURES
Definition: hw_base_encode.h:53
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:783
int64_t
long long int64_t
Definition: coverity.c:34
VulkanEncodeH265Picture::h265pic_info
StdVideoEncodeH265PictureInfo h265pic_info
Definition: vulkan_encode_h265.c:65
H265RawSTRefPicSet::used_by_curr_pic_flag
uint8_t used_by_curr_pic_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:227
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
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
setup_slices
static void setup_slices(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
Definition: vulkan_encode_h265.c:294
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:172
H265RawSTRefPicSet::delta_poc_s1_minus1
uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:234
VulkanEncodeH265Context
Definition: vulkan_encode_h265.c:80
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
AVOption
AVOption.
Definition: opt.h:429
ff_vulkan_write_global_header
av_cold int ff_vulkan_write_global_header(AVCodecContext *avctx, FFVulkanEncodeContext *ctx)
Write out the extradata in case its needed.
Definition: vulkan_encode.c:671
H265RawSTRefPicSet::used_by_curr_pic_s1_flag
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:235
VulkanH265Units::slhdrvcl
StdVideoH265SubLayerHrdParameters slhdrvcl[HEVC_MAX_SUB_LAYERS]
Definition: vulkan_encode_h265.c:830
data
const char data[16]
Definition: mxf.c:149
VulkanH265Units::vps
StdVideoH265VideoParameterSet vps
Definition: vulkan_encode_h265.c:835
UNIT_AUD
@ UNIT_AUD
Definition: vulkan_encode_h265.c:35
AVCodecContext::b_quant_offset
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:817
FFCodec
Definition: codec_internal.h:127
version.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
FLAGS
#define FLAGS
Definition: vulkan_encode_h265.c:1703
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:74
cbs.h
FFHWBaseEncodeContext::slice_block_width
int slice_block_width
Definition: hw_base_encode.h:144
cbs_h265.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
write_sequence_headers
static int write_sequence_headers(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, uint8_t *data, size_t *data_len)
Definition: vulkan_encode_h265.c:1397
avcodec_profile_name
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:442
FFVulkanEncodeDescriptor
Definition: vulkan_encode.h:31
AVCodecContext::qmax
int qmax
maximum quantizer
Definition: avcodec.h:1273
VulkanEncodeH265Picture::vkh265pic_info
VkVideoEncodeH265PictureInfoKHR vkh265pic_info
Definition: vulkan_encode_h265.c:66
H265RawSPS::pic_height_in_luma_samples
uint16_t pic_height_in_luma_samples
Definition: cbs_h265.h:265
H265RawSPS::sample_adaptive_offset_enabled_flag
uint8_t sample_adaptive_offset_enabled_flag
Definition: cbs_h265.h:297
H265RawSPS::vui
H265RawVUI vui
Definition: cbs_h265.h:318
FFHWBaseEncodeContext::slice_block_height
int slice_block_height
Definition: hw_base_encode.h:145
init_pic_rc
static int init_pic_rc(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VkVideoEncodeRateControlInfoKHR *rc_info, VkVideoEncodeRateControlLayerInfoKHR *rc_layer)
Definition: vulkan_encode_h265.c:111
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:142
H265RawSPS
Definition: cbs_h265.h:245
H265RawPPS::num_ref_idx_l0_default_active_minus1
uint8_t num_ref_idx_l0_default_active_minus1
Definition: cbs_h265.h:368
H265RawVPS
Definition: cbs_h265.h:184
VulkanEncodeH265Context::raw_aud
H265RawAUD raw_aud
Definition: vulkan_encode_h265.c:103
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
H265RawPPS
Definition: cbs_h265.h:356
FFHWBaseEncodeContext
Definition: hw_base_encode.h:122
SEIRawContentLightLevelInfo
Definition: cbs_sei.h:85
FFHWBaseEncodeH265Opts::slice_block_rows
int slice_block_rows
Definition: hw_base_encode_h265.h:42
vk_enc_h265_update_pic_info
static int vk_enc_h265_update_pic_info(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
Definition: vulkan_encode_h265.c:156
H265RawVUI::max_bits_per_min_cu_denom
uint8_t max_bits_per_min_cu_denom
Definition: cbs_h265.h:173
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:826
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
H265RawSTRefPicSet::used_by_curr_pic_s0_flag
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:233
FFHWBaseEncodePicture::type
int type
Definition: hw_base_encode.h:78
VULKAN_ENCODE_COMMON_OPTIONS
#define VULKAN_ENCODE_COMMON_OPTIONS
Definition: vulkan_encode.h:197
VulkanEncodeH265Picture::pic_order_cnt
int pic_order_cnt
Definition: vulkan_encode_h265.c:57
FFHWBaseEncodePicture::is_reference
int is_reference
Definition: hw_base_encode.h:87
fail
#define fail()
Definition: checkasm.h:189
H265RawSTRefPicSet::delta_poc_s0_minus1
uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:232
VulkanEncodeH265Picture::units_needed
enum UnitElems units_needed
Definition: vulkan_encode_h265.c:60
VulkanH265Units::ptl_sps
StdVideoH265ProfileTierLevel ptl_sps
Definition: vulkan_encode_h265.c:823
FFHWBaseEncodeH265Opts::slice_block_cols
int slice_block_cols
Definition: hw_base_encode_h265.h:43
ff_cbs_read
int ff_cbs_read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Read a bitstream from a memory region into a fragment, then split into units and decompose.
Definition: cbs.c:325
FFHWBaseEncodeH265::raw_pps
H265RawPPS raw_pps
Definition: hw_base_encode_h265.h:28
SEIRawMasteringDisplayColourVolume::max_display_mastering_luminance
uint32_t max_display_mastering_luminance
Definition: cbs_sei.h:81
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
enc_cb
static const FFVulkanCodec enc_cb
Definition: vulkan_encode_h265.c:1508
FFHWBaseEncodePicture::input_image
AVFrame * input_image
Definition: hw_base_encode.h:83
FF_VK_EXT_VIDEO_ENCODE_H265
#define FF_VK_EXT_VIDEO_ENCODE_H265
Definition: vulkan_functions.h:63
HEVC_MAX_REFS
@ HEVC_MAX_REFS
Definition: hevc.h:122
vulkan_encode_h265_class
static const AVClass vulkan_encode_h265_class
Definition: vulkan_encode_h265.c:1764
AV_CODEC_CAP_ENCODER_FLUSH
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition: codec.h:166
H265RawSPS::log2_min_luma_transform_block_size_minus2
uint8_t log2_min_luma_transform_block_size_minus2
Definition: cbs_h265.h:285
ff_hw_base_init_gop_structure
int ff_hw_base_init_gop_structure(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, uint32_t ref_l0, uint32_t ref_l1, int flags, int prediction_pre_only)
Definition: hw_base_encode.c:661
VulkanEncodeH265Context::caps
VkVideoEncodeH265CapabilitiesKHR caps
Definition: vulkan_encode_h265.c:97
init_profile
static int init_profile(AVCodecContext *avctx, VkVideoProfileInfoKHR *profile, void *pnext)
Definition: vulkan_encode_h265.c:594
FFHWBaseEncodePicture::prev
struct FFHWBaseEncodePicture * prev
Definition: hw_base_encode.h:101
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:168
VulkanEncodeH265Context::fixed_qp_b
uint8_t fixed_qp_b
Definition: vulkan_encode_h265.c:90
FFVkEncodeCommonOptions::tier
int tier
Definition: vulkan_encode.h:155
VulkanH265Units::sps
StdVideoH265SequenceParameterSet sps
Definition: vulkan_encode_h265.c:820
H265RawVPS::vps_video_parameter_set_id
uint8_t vps_video_parameter_set_id
Definition: cbs_h265.h:187
lrint
#define lrint
Definition: tablegen.h:53
SEIRawUserDataRegistered::itu_t_t35_country_code
uint8_t itu_t_t35_country_code
Definition: cbs_sei.h:34
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
AVCodecContext::rc_initial_buffer_occupancy
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:1330
PROFILE
#define PROFILE(name, value)
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
VulkanEncodeH265Context::initial_buffer_fullness
uint64_t initial_buffer_fullness
Definition: vulkan_encode_h265.c:93
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
VulkanEncodeH265Context::common
FFVulkanEncodeContext common
Definition: vulkan_encode_h265.c:81
s
#define s(width, name)
Definition: cbs_vp9.c:198
OFFSET
#define OFFSET(x)
Definition: vulkan_encode_h265.c:1702
SEIRawMasteringDisplayColourVolume::white_point_y
uint16_t white_point_y
Definition: cbs_sei.h:80
FFHWBaseEncodeH265Opts::tier
int tier
Definition: hw_base_encode_h265.h:34
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1451
H265RawSPS::log2_max_pic_order_cnt_lsb_minus4
uint8_t log2_max_pic_order_cnt_lsb_minus4
Definition: cbs_h265.h:276
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
FFHWBaseEncodeContext::max_b_depth
int max_b_depth
Definition: hw_base_encode.h:188
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:159
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
H265RawSTRefPicSet::num_positive_pics
uint8_t num_positive_pics
Definition: cbs_h265.h:231
VulkanEncodeH265Picture::l_rps
StdVideoEncodeH265LongTermRefPics l_rps
Definition: vulkan_encode_h265.c:76
FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_B
Definition: hw_base_encode.h:42
ctx
AVFormatContext * ctx
Definition: movenc.c:49
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
VulkanEncodeH265Context::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: vulkan_encode_h265.c:101
VulkanH265Units::pps
StdVideoH265PictureParameterSet pps
Definition: vulkan_encode_h265.c:832
H265RawSTRefPicSet::inter_ref_pic_set_prediction_flag
uint8_t inter_ref_pic_set_prediction_flag
Definition: cbs_h265.h:221
H265RawPPS::transform_skip_enabled_flag
uint8_t transform_skip_enabled_flag
Definition: cbs_h265.h:374
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1302
init_pic_params
static int init_pic_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VkVideoEncodeInfoKHR *encode_info)
Definition: vulkan_encode_h265.c:519
VulkanEncodeH265Picture::vkrc_layer_info
VkVideoEncodeH265RateControlLayerInfoKHR vkrc_layer_info
Definition: vulkan_encode_h265.c:63
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
H265RawSPS::log2_min_luma_coding_block_size_minus3
uint8_t log2_min_luma_coding_block_size_minus3
Definition: cbs_h265.h:283
FFVkEncodeCommonOptions::qp
int qp
Definition: vulkan_encode.h:151
H265RawSPS::pic_width_in_luma_samples
uint16_t pic_width_in_luma_samples
Definition: cbs_h265.h:264
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
FFHWBaseEncodeContext::b_per_p
int b_per_p
Definition: hw_base_encode.h:189
VulkanEncodeH265Picture::last_idr_frame
int64_t last_idr_frame
Definition: vulkan_encode_h265.c:53
if
if(ret)
Definition: filter_design.txt:179
hw_base_encode_h265.h
AVCodecContext::rc_buffer_size
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1287
FFHWBaseEncodePicture::dpb
struct FFHWBaseEncodePicture * dpb[MAX_DPB_SIZE]
Definition: hw_base_encode.h:93
VulkanEncodeH265Picture::slice_type
int slice_type
Definition: vulkan_encode_h265.c:56
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
SEIRawMasteringDisplayColourVolume::min_display_mastering_luminance
uint32_t min_display_mastering_luminance
Definition: cbs_sei.h:82
NULL
#define NULL
Definition: coverity.c:32
H265RawAUD
Definition: cbs_h265.h:487
FFHWBaseEncodeH265Opts
Definition: hw_base_encode_h265.h:33
FF_HW_FLAG_INTRA_ONLY
@ FF_HW_FLAG_INTRA_ONLY
Definition: hw_base_encode.h:51
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:198
SEIRawMasteringDisplayColourVolume
Definition: cbs_sei.h:76
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:326
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:501
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FFVkEncodeCommonOptions::level
int level
Definition: vulkan_encode.h:154
H265RawSPS::sps_seq_parameter_set_id
uint8_t sps_seq_parameter_set_id
Definition: cbs_h265.h:256
write_filler
static int write_filler(AVCodecContext *avctx, uint32_t filler, uint8_t *data, size_t *data_len)
Definition: vulkan_encode_h265.c:1482
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:120
VulkanEncodeH265Picture::s_rps
StdVideoH265ShortTermRefPicSet s_rps
Definition: vulkan_encode_h265.c:77
VulkanEncodeH265Context::fixed_qp_p
uint8_t fixed_qp_p
Definition: vulkan_encode_h265.c:89
H265RawFiller::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:745
H265RawSPS::sps_temporal_mvp_enabled_flag
uint8_t sps_temporal_mvp_enabled_flag
Definition: cbs_h265.h:314
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
FFVulkanContext
Definition: vulkan.h:268
FFVulkanEncodeContext::base
FFHWBaseEncodeContext base
Definition: vulkan_encode.h:168
VulkanH265Units::slhdrnal
StdVideoH265SubLayerHrdParameters slhdrnal[HEVC_MAX_SUB_LAYERS]
Definition: vulkan_encode_h265.c:829
H265RawNALUnitHeader::nal_unit_type
uint8_t nal_unit_type
Definition: cbs_h265.h:31
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1794
VulkanH265Units::dpbm_vps
StdVideoH265DecPicBufMgr dpbm_vps
Definition: vulkan_encode_h265.c:837
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:160
base_unit_to_vk
static av_cold int base_unit_to_vk(AVCodecContext *avctx, VulkanH265Units *vk_units)
Definition: vulkan_encode_h265.c:841
H265RawNALUnitHeader
Definition: cbs_h265.h:30
AV_PROFILE_HEVC_REXT
#define AV_PROFILE_HEVC_REXT
Definition: defs.h:162
FFVulkanEncodeContext::opts
FFVkEncodeCommonOptions opts
Definition: vulkan_encode.h:182
VulkanEncodeH265Context::hrd_buffer_size
uint64_t hrd_buffer_size
Definition: vulkan_encode_h265.c:92
FFVulkanEncodeContext
Definition: vulkan_encode.h:165
ff_hevc_vulkan_encoder
const FFCodec ff_hevc_vulkan_encoder
Definition: vulkan_encode_h265.c:1771
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
VulkanH265Units::pps_scaling
StdVideoH265ScalingLists pps_scaling
Definition: vulkan_encode_h265.c:833
VulkanEncodeH265Context::fixed_qp_idr
uint8_t fixed_qp_idr
Definition: vulkan_encode_h265.c:88
vulkan_encode_h265_defaults
static const FFCodecDefault vulkan_encode_h265_defaults[]
Definition: vulkan_encode_h265.c:1751
FFVkEncodeCommonOptions::rc_mode
VkVideoEncodeRateControlModeFlagBitsKHR rc_mode
Definition: vulkan_encode.h:161
codec_internal.h
FFHWBaseEncodePicture::nb_refs
int nb_refs[MAX_REFERENCE_LIST_NUM]
Definition: hw_base_encode.h:97
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
MAX_DPB_SIZE
#define MAX_DPB_SIZE
Definition: hw_base_encode.h:26
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
FFHWBaseEncodeContext::decode_delay
int64_t decode_delay
Definition: hw_base_encode.h:173
SEIRawUserDataRegistered::data
uint8_t * data
RefStruct reference.
Definition: cbs_sei.h:36
size
int size
Definition: twinvq_data.h:10344
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:128
VulkanEncodeH265Context::cbs
CodedBitstreamContext * cbs
Definition: vulkan_encode_h265.c:100
FFHWBaseEncodeH265
Definition: hw_base_encode_h265.h:25
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
VulkanH265Units::ltr
StdVideoH265LongTermRefPicsSps ltr
Definition: vulkan_encode_h265.c:822
ff_vk_h265_level_to_vk
StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc)
Definition: vulkan_video.c:210
FFHWBaseEncodeContext::p_to_gpb
int p_to_gpb
Definition: hw_base_encode.h:194
H265RawSPS::max_transform_hierarchy_depth_intra
uint8_t max_transform_hierarchy_depth_intra
Definition: cbs_h265.h:288
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
header
static const uint8_t header[24]
Definition: sdr2.c:68
VulkanEncodeH265Picture::ref_list_info
StdVideoEncodeH265ReferenceListsInfo ref_list_info
Definition: vulkan_encode_h265.c:75
H265RawAUD::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:488
FFHWBaseEncodePicture::encode_order
int64_t encode_order
Definition: hw_base_encode.h:70
SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition: sei.h:96
FFHWBaseEncodeH265Opts::cu_qp_delta_enabled_flag
int cu_qp_delta_enabled_flag
Definition: hw_base_encode_h265.h:36
VulkanEncodeH265Picture::pic_type
int pic_type
Definition: vulkan_encode_h265.c:58
UNIT_SEI_MASTERING_DISPLAY
@ UNIT_SEI_MASTERING_DISPLAY
Definition: vulkan_encode_h265.c:36
SEIRawUserDataRegistered::data_length
size_t data_length
Definition: cbs_sei.h:37
parse_feedback_units
static int parse_feedback_units(AVCodecContext *avctx, const uint8_t *data, size_t size, int sps_override, int pps_override)
Definition: vulkan_encode_h265.c:1203
HEVC_MAX_CPB_CNT
@ HEVC_MAX_CPB_CNT
Definition: hevc.h:134
UNIT_SEI_A53_CC
@ UNIT_SEI_A53_CC
Definition: vulkan_encode_h265.c:38
VulkanEncodeH265Context::sei_content_light_level
SEIRawContentLightLevelInfo sei_content_light_level
Definition: vulkan_encode_h265.c:106
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:810
H265RawVUI::max_bytes_per_pic_denom
uint8_t max_bytes_per_pic_denom
Definition: cbs_h265.h:172
create_session_params
static int create_session_params(AVCodecContext *avctx)
Definition: vulkan_encode_h265.c:1156
FFVkEncodeCommonOptions::profile
int profile
Definition: vulkan_encode.h:153
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
VulkanEncodeH265Context::units
FFHWBaseEncodeH265 units
Definition: vulkan_encode_h265.c:83
FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_P
Definition: hw_base_encode.h:41
SEIRawMasteringDisplayColourVolume::white_point_x
uint16_t white_point_x
Definition: cbs_sei.h:79
ff_vulkan_encode_receive_packet
int ff_vulkan_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Encode.
Definition: vulkan_encode.c:541
H265RawSPS::log2_diff_max_min_luma_coding_block_size
uint8_t log2_diff_max_min_luma_coding_block_size
Definition: cbs_h265.h:284
internal.h
FFHWBaseEncodeH265Opts::nb_slices
int nb_slices
Definition: hw_base_encode_h265.h:41
VulkanEncodeH265Context::sei_mastering_display
SEIRawMasteringDisplayColourVolume sei_mastering_display
Definition: vulkan_encode_h265.c:105
MAX_REFERENCE_LIST_NUM
#define MAX_REFERENCE_LIST_NUM
Definition: hw_base_encode.h:30
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
FFHWBaseEncodePicture::refs
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
Definition: hw_base_encode.h:98
vulkan_encode.h
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
H265RawSTRefPicSet
Definition: cbs_h265.h:220
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
profile
int profile
Definition: mxfenc.c:2233
AVCodecContext::height
int height
Definition: avcodec.h:624
FFVulkanEncodeDescriptor::codec_id
enum AVCodecID codec_id
Definition: vulkan_encode.h:32
SEIRawMasteringDisplayColourVolume::display_primaries_y
uint16_t display_primaries_y[3]
Definition: cbs_sei.h:78
ff_cbs_write_fragment_data
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:409
ret
ret
Definition: filter_design.txt:187
FFHWBaseEncodeContext::gop_size
int gop_size
Definition: hw_base_encode.h:184
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
FFHWBaseEncodePicture
Definition: hw_base_encode.h:61
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
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:80
atsc_a53.h
VulkanH265Units::ptl_vps
StdVideoH265ProfileTierLevel ptl_vps
Definition: vulkan_encode_h265.c:836
SEIRawContentLightLevelInfo::max_content_light_level
uint16_t max_content_light_level
Definition: cbs_sei.h:86
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
VulkanEncodeH265Context::sei_a53cc
SEIRawUserDataRegistered sei_a53cc
Definition: vulkan_encode_h265.c:107
VulkanEncodeH265Picture::frame_num
int frame_num
Definition: vulkan_encode_h265.c:52
H265RawPPS::init_qp_minus26
int8_t init_qp_minus26
Definition: cbs_h265.h:371
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:129
write_extra_headers
static int write_extra_headers(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, uint8_t *data, size_t *data_len)
Definition: vulkan_encode_h265.c:1431
AVCodecContext
main external API structure.
Definition: avcodec.h:451
H265RawSTRefPicSet::num_negative_pics
uint8_t num_negative_pics
Definition: cbs_h265.h:230
VulkanEncodeH265Picture::idr_pic_id
uint16_t idr_pic_id
Definition: vulkan_encode_h265.c:54
FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
Definition: hw_base_encode.h:58
VulkanEncodeH265Context::sei_a53cc_data
void * sei_a53cc_data
Definition: vulkan_encode_h265.c:108
FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_I
Definition: hw_base_encode.h:40
FFHWBaseEncodeH265Opts::fixed_qp_idr
int fixed_qp_idr
Definition: hw_base_encode_h265.h:35
VulkanH265Units::str
StdVideoH265ShortTermRefPicSet str[STD_VIDEO_H265_SUBLAYERS_LIST_SIZE]
Definition: vulkan_encode_h265.c:821
AVCodecContext::qmin
int qmin
minimum quantizer
Definition: avcodec.h:1266
FFHWBaseEncodeH265::raw_sps
H265RawSPS raw_sps
Definition: hw_base_encode_h265.h:27
VulkanEncodeH265Picture::vkslice
VkVideoEncodeH265NaluSliceSegmentInfoKHR vkslice
Definition: vulkan_encode_h265.c:70
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
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:1650
ff_vulkan_encode_init
av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, FFVulkanEncodeContext *ctx, const FFVulkanEncodeDescriptor *vk_desc, const FFVulkanCodec *codec, void *codec_caps, void *quality_pnext)
Initialize encoder.
Definition: vulkan_encode.c:701
filler
int(* filler)(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:421
H265RawPPS::num_ref_idx_l1_default_active_minus1
uint8_t num_ref_idx_l1_default_active_minus1
Definition: cbs_h265.h:369
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:833
AV_CODEC_ID_H265
#define AV_CODEC_ID_H265
Definition: codec_id.h:229
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
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
UNIT_SEI_CONTENT_LIGHT_LEVEL
@ UNIT_SEI_CONTENT_LIGHT_LEVEL
Definition: vulkan_encode_h265.c:37
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
VulkanEncodeH265Picture::vkrc_info
VkVideoEncodeH265RateControlInfoKHR vkrc_info
Definition: vulkan_encode_h265.c:62
UnitElems
UnitElems
Definition: vulkan_encode_h264.c:35
vulkan_encode_h265_close
static av_cold int vulkan_encode_h265_close(AVCodecContext *avctx)
Definition: vulkan_encode_h265.c:1695
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:552
init_enc_options
static int init_enc_options(AVCodecContext *avctx)
Definition: vulkan_encode_h265.c:673
VulkanH265Units::vui_sps
StdVideoH265SequenceParameterSetVui vui_sps
Definition: vulkan_encode_h265.c:827
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
H265RawPPS::pps_pic_parameter_set_id
uint8_t pps_pic_parameter_set_id
Definition: cbs_h265.h:359
mem.h
ff_vulkan_encode_uninit
av_cold void ff_vulkan_encode_uninit(FFVulkanEncodeContext *ctx)
Uninitialize encoder.
Definition: vulkan_encode.c:31
mastering_display_metadata.h
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
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_cbs_init
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:90
FFVulkanCodec::flags
int flags
Codec feature flags.
Definition: vulkan_encode.h:94
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
VulkanEncodeH265Picture::primary_pic_type
int primary_pic_type
Definition: vulkan_encode_h265.c:55
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
FFVulkanCodec
Definition: vulkan_encode.h:90
VulkanH265Units
Definition: vulkan_encode_h265.c:819
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:624
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
H265RawSTRefPicSet::delta_idx_minus1
uint8_t delta_idx_minus1
Definition: cbs_h265.h:223
VulkanH265Units::vui_header_vps
StdVideoH265HrdParameters vui_header_vps
Definition: vulkan_encode_h265.c:838
SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: sei.h:103
HW_BASE_ENCODE_COMMON_OPTIONS
#define HW_BASE_ENCODE_COMMON_OPTIONS
Definition: hw_base_encode.h:239
init_base_units
static int init_base_units(AVCodecContext *avctx)
Definition: vulkan_encode_h265.c:1255
LEVEL
#define LEVEL(name, value)
VulkanEncodeH265Context::unit_opts
FFHWBaseEncodeH265Opts unit_opts
Definition: vulkan_encode_h265.c:84
H265RawSPS::max_transform_hierarchy_depth_inter
uint8_t max_transform_hierarchy_depth_inter
Definition: cbs_h265.h:287
H265RawSTRefPicSet::delta_rps_sign
uint8_t delta_rps_sign
Definition: cbs_h265.h:224
FFHWBaseEncodePicture::display_order
int64_t display_order
Definition: hw_base_encode.h:69
ff_vk_h265_profile_to_vk
StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile)
Definition: vulkan_video.c:240
FFVulkanEncodePicture::dpb_slot
VkVideoReferenceSlotInfoKHR dpb_slot
Definition: vulkan_encode.h:42
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
VulkanH265Units::vui_header_sps
StdVideoH265HrdParameters vui_header_sps
Definition: vulkan_encode_h265.c:826
FFVulkanFunctions
Definition: vulkan_functions.h:263
ff_vulkan_encode_create_session_params
int ff_vulkan_encode_create_session_params(AVCodecContext *avctx, FFVulkanEncodeContext *ctx, void *codec_params_pnext)
Create session parameters.
Definition: vulkan_encode.c:1026
FFVulkanEncodePicture
Definition: vulkan_encode.h:39
VulkanEncodeH265Picture::slice_hdr
StdVideoEncodeH265SliceSegmentHeader slice_hdr
Definition: vulkan_encode_h265.c:69
write_access_unit
static int write_access_unit(AVCodecContext *avctx, uint8_t *data, size_t *data_len, CodedBitstreamFragment *au)
Definition: vulkan_encode_h265.c:1373
VulkanEncodeH265Context::profile
VkVideoEncodeH265ProfileInfoKHR profile
Definition: vulkan_encode_h265.c:95
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:153
FFHWBaseEncodePicture::nb_dpb_pics
int nb_dpb_pics
Definition: hw_base_encode.h:92
vulkan_encode_h265_init
static av_cold int vulkan_encode_h265_init(AVCodecContext *avctx)
Definition: vulkan_encode_h265.c:1522
HEVC_NAL_FD_NUT
@ HEVC_NAL_FD_NUT
Definition: hevc.h:67
setup_refs
static void setup_refs(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VkVideoEncodeInfoKHR *encode_info)
Definition: vulkan_encode_h265.c:370
vulkan_encode_h265_options
static const AVOption vulkan_encode_h265_options[]
Definition: vulkan_encode_h265.c:1704
HEVC_MAX_SUB_LAYERS
@ HEVC_MAX_SUB_LAYERS
Definition: hevc.h:105
ff_vk_enc_h265_desc
const FFVulkanEncodeDescriptor ff_vk_enc_h265_desc
Definition: vulkan_encode_h265.c:41
H265RawFiller
Definition: cbs_h265.h:744