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