FFmpeg  4.4.9
vdpau_hevc.c
Go to the documentation of this file.
1 /*
2  * MPEG-H Part 2 / HEVC / H.265 HW decode acceleration through VDPAU
3  *
4  * Copyright (c) 2013 Philip Langdale
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <vdpau/vdpau.h>
24 
25 #include "avcodec.h"
26 #include "internal.h"
27 #include "hevc_data.h"
28 #include "hevcdec.h"
29 #include "hwconfig.h"
30 #include "vdpau.h"
31 #include "vdpau_internal.h"
32 #include "h265_profile_level.h"
33 
34 
36  const uint8_t *buffer, uint32_t size)
37 {
38  HEVCContext *h = avctx->priv_data;
39  HEVCFrame *pic = h->ref;
40  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
41 
42  VdpPictureInfoHEVC *info = &pic_ctx->info.hevc;
43 #ifdef VDP_YCBCR_FORMAT_Y_U_V_444
44  VdpPictureInfoHEVC444 *info2 = &pic_ctx->info.hevc_444;
45 #endif
46 
47  const HEVCSPS *sps = h->ps.sps;
48  const HEVCPPS *pps = h->ps.pps;
49  const SliceHeader *sh = &h->sh;
50  const ScalingList *sl = pps->scaling_list_data_present_flag ?
51  &pps->scaling_list : &sps->scaling_list;
52 
53  /* init VdpPictureInfoHEVC */
54 
55  /* SPS */
56  info->chroma_format_idc = sps->chroma_format_idc;
57  info->separate_colour_plane_flag = sps->separate_colour_plane_flag;
58  info->pic_width_in_luma_samples = sps->width;
59  info->pic_height_in_luma_samples = sps->height;
60  info->bit_depth_luma_minus8 = sps->bit_depth - 8;
61  info->bit_depth_chroma_minus8 = sps->bit_depth - 8;
62  info->log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_poc_lsb - 4;
63  /* Provide the value corresponding to the nuh_temporal_id of the frame
64  to be decoded. */
65  info->sps_max_dec_pic_buffering_minus1 = sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
66  info->log2_min_luma_coding_block_size_minus3 = sps->log2_min_cb_size - 3;
67  info->log2_diff_max_min_luma_coding_block_size = sps->log2_diff_max_min_coding_block_size;
68  info->log2_min_transform_block_size_minus2 = sps->log2_min_tb_size - 2;
69  info->log2_diff_max_min_transform_block_size = sps->log2_max_trafo_size - sps->log2_min_tb_size;
70  info->max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter;
71  info->max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra;
72  info->scaling_list_enabled_flag = sps->scaling_list_enable_flag;
73  /* Scaling lists, in diagonal order, to be used for this frame. */
74  for (size_t i = 0; i < 6; i++) {
75  for (size_t j = 0; j < 16; j++) {
76  /* Scaling List for 4x4 quantization matrix,
77  indexed as ScalingList4x4[matrixId][i]. */
79  info->ScalingList4x4[i][j] = sl->sl[0][i][pos];
80  }
81  for (size_t j = 0; j < 64; j++) {
83  /* Scaling List for 8x8 quantization matrix,
84  indexed as ScalingList8x8[matrixId][i]. */
85  info->ScalingList8x8[i][j] = sl->sl[1][i][pos];
86  /* Scaling List for 16x16 quantization matrix,
87  indexed as ScalingList16x16[matrixId][i]. */
88  info->ScalingList16x16[i][j] = sl->sl[2][i][pos];
89  if (i < 2) {
90  /* Scaling List for 32x32 quantization matrix,
91  indexed as ScalingList32x32[matrixId][i]. */
92  info->ScalingList32x32[i][j] = sl->sl[3][i * 3][pos];
93  }
94  }
95  /* Scaling List DC Coefficients for 16x16,
96  indexed as ScalingListDCCoeff16x16[matrixId]. */
97  info->ScalingListDCCoeff16x16[i] = sl->sl_dc[0][i];
98  if (i < 2) {
99  /* Scaling List DC Coefficients for 32x32,
100  indexed as ScalingListDCCoeff32x32[matrixId]. */
101  info->ScalingListDCCoeff32x32[i] = sl->sl_dc[1][i * 3];
102  }
103  }
104  info->amp_enabled_flag = sps->amp_enabled_flag;
105  info->sample_adaptive_offset_enabled_flag = sps->sao_enabled;
106  info->pcm_enabled_flag = sps->pcm_enabled_flag;
107  if (info->pcm_enabled_flag) {
108  /* Only needs to be set if pcm_enabled_flag is set. Ignored otherwise. */
109  info->pcm_sample_bit_depth_luma_minus1 = sps->pcm.bit_depth - 1;
110  /* Only needs to be set if pcm_enabled_flag is set. Ignored otherwise. */
111  info->pcm_sample_bit_depth_chroma_minus1 = sps->pcm.bit_depth_chroma - 1;
112  /* Only needs to be set if pcm_enabled_flag is set. Ignored otherwise. */
113  info->log2_min_pcm_luma_coding_block_size_minus3 = sps->pcm.log2_min_pcm_cb_size - 3;
114  /* Only needs to be set if pcm_enabled_flag is set. Ignored otherwise. */
115  info->log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size;
116  /* Only needs to be set if pcm_enabled_flag is set. Ignored otherwise. */
117  info->pcm_loop_filter_disabled_flag = sps->pcm.loop_filter_disable_flag;
118  }
119  /* Per spec, when zero, assume short_term_ref_pic_set_sps_flag
120  is also zero. */
121  info->num_short_term_ref_pic_sets = sps->nb_st_rps;
122  info->long_term_ref_pics_present_flag = sps->long_term_ref_pics_present_flag;
123  /* Only needed if long_term_ref_pics_present_flag is set. Ignored
124  otherwise. */
125  info->num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps;
126  info->sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag;
127  info->strong_intra_smoothing_enabled_flag = sps->sps_strong_intra_smoothing_enable_flag;
128 
129  /* Copy the HEVC Picture Parameter Set bitstream fields. */
130  info->dependent_slice_segments_enabled_flag = pps->dependent_slice_segments_enabled_flag;
131  info->output_flag_present_flag = pps->output_flag_present_flag;
132  info->num_extra_slice_header_bits = pps->num_extra_slice_header_bits;
133  info->sign_data_hiding_enabled_flag = pps->sign_data_hiding_flag;
134  info->cabac_init_present_flag = pps->cabac_init_present_flag;
135  info->num_ref_idx_l0_default_active_minus1 = pps->num_ref_idx_l0_default_active - 1;
136  info->num_ref_idx_l1_default_active_minus1 = pps->num_ref_idx_l1_default_active - 1;
137  info->init_qp_minus26 = pps->pic_init_qp_minus26;
138  info->constrained_intra_pred_flag = pps->constrained_intra_pred_flag;
139  info->transform_skip_enabled_flag = pps->transform_skip_enabled_flag;
140  info->cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag;
141  /* Only needed if cu_qp_delta_enabled_flag is set. Ignored otherwise. */
142  info->diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth;
143  info->pps_cb_qp_offset = pps->cb_qp_offset;
144  info->pps_cr_qp_offset = pps->cr_qp_offset;
145  info->pps_slice_chroma_qp_offsets_present_flag = pps->pic_slice_level_chroma_qp_offsets_present_flag;
146  info->weighted_pred_flag = pps->weighted_pred_flag;
147  info->weighted_bipred_flag = pps->weighted_bipred_flag;
148  info->transquant_bypass_enabled_flag = pps->transquant_bypass_enable_flag;
149  info->tiles_enabled_flag = pps->tiles_enabled_flag;
150  info->entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag;
151  if (info->tiles_enabled_flag) {
152  if (pps->num_tile_columns > FF_ARRAY_ELEMS(info->column_width_minus1) ||
153  pps->num_tile_rows > FF_ARRAY_ELEMS(info->row_height_minus1)) {
154  av_log(avctx, AV_LOG_ERROR, "Too many tiles\n");
155  return AVERROR(ENOSYS);
156  }
157  /* Only valid if tiles_enabled_flag is set. Ignored otherwise. */
158  info->num_tile_columns_minus1 = pps->num_tile_columns - 1;
159  /* Only valid if tiles_enabled_flag is set. Ignored otherwise. */
160  info->num_tile_rows_minus1 = pps->num_tile_rows - 1;
161  /* Only valid if tiles_enabled_flag is set. Ignored otherwise. */
162  info->uniform_spacing_flag = pps->uniform_spacing_flag;
163  /* Only need to set 0..num_tile_columns_minus1. The struct
164  definition reserves up to the maximum of 20. Invalid values are
165  ignored. */
166  for (ssize_t i = 0; i < pps->num_tile_columns; i++) {
167  info->column_width_minus1[i] = pps->column_width[i] - 1;
168  }
169  /* Only need to set 0..num_tile_rows_minus1. The struct
170  definition reserves up to the maximum of 22. Invalid values are
171  ignored.*/
172  for (ssize_t i = 0; i < pps->num_tile_rows; i++) {
173  info->row_height_minus1[i] = pps->row_height[i] - 1;
174  }
175  /* Only needed if tiles_enabled_flag is set. Invalid values are
176  ignored. */
177  info->loop_filter_across_tiles_enabled_flag = pps->loop_filter_across_tiles_enabled_flag;
178  }
179  info->pps_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
180  info->deblocking_filter_control_present_flag = pps->deblocking_filter_control_present_flag;
181  /* Only valid if deblocking_filter_control_present_flag is set. Ignored
182  otherwise. */
183  info->deblocking_filter_override_enabled_flag = pps->deblocking_filter_override_enabled_flag;
184  /* Only valid if deblocking_filter_control_present_flag is set. Ignored
185  otherwise. */
186  info->pps_deblocking_filter_disabled_flag = pps->disable_dbf;
187  /* Only valid if deblocking_filter_control_present_flag is set and
188  pps_deblocking_filter_disabled_flag is not set. Ignored otherwise.*/
189  info->pps_beta_offset_div2 = pps->beta_offset / 2;
190  /* Only valid if deblocking_filter_control_present_flag is set and
191  pps_deblocking_filter_disabled_flag is not set. Ignored otherwise. */
192  info->pps_tc_offset_div2 = pps->tc_offset / 2;
193  info->lists_modification_present_flag = pps->lists_modification_present_flag;
194  info->log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level - 2;
195  info->slice_segment_header_extension_present_flag = pps->slice_header_extension_present_flag;
196 
197  /* Set to 1 if nal_unit_type is equal to IDR_W_RADL or IDR_N_LP.
198  Set to zero otherwise. */
199  info->IDRPicFlag = IS_IDR(h);
200  /* Set to 1 if nal_unit_type in the range of BLA_W_LP to
201  RSV_IRAP_VCL23, inclusive. Set to zero otherwise.*/
202  info->RAPPicFlag = IS_IRAP(h);
203  /* See section 7.4.7.1 of the specification. */
204  info->CurrRpsIdx = sps->nb_st_rps;
205  if (sh->short_term_ref_pic_set_sps_flag == 1) {
206  for (size_t i = 0; i < sps->nb_st_rps; i++) {
207  if (sh->short_term_rps == &sps->st_rps[i]) {
208  info->CurrRpsIdx = i;
209  break;
210  }
211  }
212  }
213  /* See section 7.4.7.2 of the specification. */
214  info->NumPocTotalCurr = ff_hevc_frame_nb_refs(h);
215  if (sh->short_term_ref_pic_set_sps_flag == 0 && sh->short_term_rps) {
216  /* Corresponds to specification field, NumDeltaPocs[RefRpsIdx].
217  Only applicable when short_term_ref_pic_set_sps_flag == 0.
218  Implementations will ignore this value in other cases. See 7.4.8. */
219  info->NumDeltaPocsOfRefRpsIdx = sh->short_term_rps->rps_idx_num_delta_pocs;
220  }
221  /* Section 7.6.3.1 of the H.265/HEVC Specification defines the syntax of
222  the slice_segment_header. This header contains information that
223  some VDPAU implementations may choose to skip. The VDPAU API
224  requires client applications to track the number of bits used in the
225  slice header for structures associated with short term and long term
226  reference pictures. First, VDPAU requires the number of bits used by
227  the short_term_ref_pic_set array in the slice_segment_header. */
228  info->NumShortTermPictureSliceHeaderBits = sh->short_term_ref_pic_set_size;
229  /* Second, VDPAU requires the number of bits used for long term reference
230  pictures in the slice_segment_header. This is equal to the number
231  of bits used for the contents of the block beginning with
232  "if(long_term_ref_pics_present_flag)". */
233  info->NumLongTermPictureSliceHeaderBits = sh->long_term_ref_pic_set_size;
234 
235  /* The value of PicOrderCntVal of the picture in the access unit
236  containing the SEI message. The picture being decoded. */
237  info->CurrPicOrderCntVal = h->poc;
238 
239  /* Slice Decoding Process - Reference Picture Sets */
240  for (size_t i = 0; i < 16; i++) {
241  info->RefPics[i] = VDP_INVALID_HANDLE;
242  info->PicOrderCntVal[i] = 0;
243  info->IsLongTerm[i] = 0;
244  }
245  for (size_t i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
246  const HEVCFrame *frame = &h->DPB[i];
247  if (frame != h->ref && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF |
249  if (j > 15) {
250  av_log(avctx, AV_LOG_WARNING,
251  "VDPAU only supports up to 16 references in the DPB. "
252  "This frame may not be decoded correctly.\n");
253  break;
254  }
255  /* Array of video reference surfaces.
256  Set any unused positions to VDP_INVALID_HANDLE. */
257  info->RefPics[j] = ff_vdpau_get_surface_id(frame->frame);
258  /* Array of picture order counts. These correspond to positions
259  in the RefPics array. */
260  info->PicOrderCntVal[j] = frame->poc;
261  /* Array used to specify whether a particular RefPic is
262  a long term reference. A value of "1" indicates a long-term
263  reference. */
264  // XXX: Setting this caused glitches in the nvidia implementation
265  // Always setting it to zero, produces correct results
266  //info->IsLongTerm[j] = frame->flags & HEVC_FRAME_FLAG_LONG_REF;
267  info->IsLongTerm[j] = 0;
268  j++;
269  }
270  }
271  /* Copy of specification field, see Section 8.3.2 of the
272  H.265/HEVC Specification. */
273  info->NumPocStCurrBefore = h->rps[ST_CURR_BEF].nb_refs;
274  if (info->NumPocStCurrBefore > 8) {
275  av_log(avctx, AV_LOG_WARNING,
276  "VDPAU only supports up to 8 references in StCurrBefore. "
277  "This frame may not be decoded correctly.\n");
278  info->NumPocStCurrBefore = 8;
279  }
280  /* Copy of specification field, see Section 8.3.2 of the
281  H.265/HEVC Specification. */
282  info->NumPocStCurrAfter = h->rps[ST_CURR_AFT].nb_refs;
283  if (info->NumPocStCurrAfter > 8) {
284  av_log(avctx, AV_LOG_WARNING,
285  "VDPAU only supports up to 8 references in StCurrAfter. "
286  "This frame may not be decoded correctly.\n");
287  info->NumPocStCurrAfter = 8;
288  }
289  /* Copy of specification field, see Section 8.3.2 of the
290  H.265/HEVC Specification. */
291  info->NumPocLtCurr = h->rps[LT_CURR].nb_refs;
292  if (info->NumPocLtCurr > 8) {
293  av_log(avctx, AV_LOG_WARNING,
294  "VDPAU only supports up to 8 references in LtCurr. "
295  "This frame may not be decoded correctly.\n");
296  info->NumPocLtCurr = 8;
297  }
298  /* Reference Picture Set list, one of the short-term RPS. These
299  correspond to positions in the RefPics array. */
300  for (ssize_t i = 0, j = 0; i < h->rps[ST_CURR_BEF].nb_refs; i++) {
301  HEVCFrame *frame = h->rps[ST_CURR_BEF].ref[i];
302  if (frame) {
303  uint8_t found = 0;
304  uintptr_t id = ff_vdpau_get_surface_id(frame->frame);
305  for (size_t k = 0; k < 16; k++) {
306  if (id == info->RefPics[k]) {
307  info->RefPicSetStCurrBefore[j] = k;
308  j++;
309  found = 1;
310  break;
311  }
312  }
313  if (!found) {
314  av_log(avctx, AV_LOG_WARNING, "missing surface: %p\n",
315  (void *)id);
316  }
317  } else {
318  av_log(avctx, AV_LOG_WARNING, "missing STR Before frame: %zd\n", i);
319  }
320  }
321  /* Reference Picture Set list, one of the short-term RPS. These
322  correspond to positions in the RefPics array. */
323  for (ssize_t i = 0, j = 0; i < h->rps[ST_CURR_AFT].nb_refs; i++) {
324  HEVCFrame *frame = h->rps[ST_CURR_AFT].ref[i];
325  if (frame) {
326  uint8_t found = 0;
327  uintptr_t id = ff_vdpau_get_surface_id(frame->frame);
328  for (size_t k = 0; k < 16; k++) {
329  if (id == info->RefPics[k]) {
330  info->RefPicSetStCurrAfter[j] = k;
331  j++;
332  found = 1;
333  break;
334  }
335  }
336  if (!found) {
337  av_log(avctx, AV_LOG_WARNING, "missing surface: %p\n",
338  (void *)id);
339  }
340  } else {
341  av_log(avctx, AV_LOG_WARNING, "missing STR After frame: %zd\n", i);
342  }
343  }
344  /* Reference Picture Set list, one of the long-term RPS. These
345  correspond to positions in the RefPics array. */
346  for (ssize_t i = 0, j = 0; i < h->rps[LT_CURR].nb_refs; i++) {
347  HEVCFrame *frame = h->rps[LT_CURR].ref[i];
348  if (frame) {
349  uint8_t found = 0;
350  uintptr_t id = ff_vdpau_get_surface_id(frame->frame);
351  for (size_t k = 0; k < 16; k++) {
352  if (id == info->RefPics[k]) {
353  info->RefPicSetLtCurr[j] = k;
354  j++;
355  found = 1;
356  break;
357  }
358  }
359  if (!found) {
360  av_log(avctx, AV_LOG_WARNING, "missing surface: %p\n",
361  (void *)id);
362  }
363  } else {
364  av_log(avctx, AV_LOG_WARNING, "missing LTR frame: %zd\n", i);
365  }
366  }
367 
368 #ifdef VDP_YCBCR_FORMAT_Y_U_V_444
369  if (sps->sps_range_extension_flag) {
370  info2->sps_range_extension_flag = 1;
371  info2->transformSkipRotationEnableFlag = sps->transform_skip_rotation_enabled_flag;
372  info2->transformSkipContextEnableFlag = sps->transform_skip_context_enabled_flag;
373  info2->implicitRdpcmEnableFlag = sps->implicit_rdpcm_enabled_flag;
374  info2->explicitRdpcmEnableFlag = sps->explicit_rdpcm_enabled_flag;
375  info2->extendedPrecisionProcessingFlag = sps->extended_precision_processing_flag;
376  info2->intraSmoothingDisabledFlag = sps->intra_smoothing_disabled_flag;
377  info2->highPrecisionOffsetsEnableFlag = sps->high_precision_offsets_enabled_flag;
378  info2->persistentRiceAdaptationEnableFlag = sps->persistent_rice_adaptation_enabled_flag;
379  info2->cabacBypassAlignmentEnableFlag = sps->cabac_bypass_alignment_enabled_flag;
380  } else {
381  info2->sps_range_extension_flag = 0;
382  }
383  if (pps->pps_range_extensions_flag) {
384  info2->pps_range_extension_flag = 1;
385  info2->log2MaxTransformSkipSize = pps->log2_max_transform_skip_block_size;
386  info2->crossComponentPredictionEnableFlag = pps->cross_component_prediction_enabled_flag;
387  info2->chromaQpAdjustmentEnableFlag = pps->chroma_qp_offset_list_enabled_flag;
388  info2->diffCuChromaQpAdjustmentDepth = pps->diff_cu_chroma_qp_offset_depth;
389  info2->chromaQpAdjustmentTableSize = pps->chroma_qp_offset_list_len_minus1 + 1;
390  info2->log2SaoOffsetScaleLuma = pps->log2_sao_offset_scale_luma;
391  info2->log2SaoOffsetScaleChroma = pps->log2_sao_offset_scale_chroma;
392  for (ssize_t i = 0; i < info2->chromaQpAdjustmentTableSize; i++)
393  {
394  info2->cb_qp_adjustment[i] = pps->cb_qp_offset_list[i];
395  info2->cr_qp_adjustment[i] = pps->cr_qp_offset_list[i];
396  }
397 
398  } else {
399  info2->pps_range_extension_flag = 0;
400  }
401 #endif
402 
403  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
404 }
405 
406 static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
407 
409  const uint8_t *buffer, uint32_t size)
410 {
411  HEVCContext *h = avctx->priv_data;
412  struct vdpau_picture_context *pic_ctx = h->ref->hwaccel_picture_private;
413  int val;
414 
416  if (val)
417  return val;
418 
419  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
420  if (val)
421  return val;
422 
423  return 0;
424 }
425 
427 {
428  HEVCContext *h = avctx->priv_data;
429  struct vdpau_picture_context *pic_ctx = h->ref->hwaccel_picture_private;
430  int val;
431 
432  val = ff_vdpau_common_end_frame(avctx, h->ref->frame, pic_ctx);
433  if (val < 0)
434  return val;
435 
436  return 0;
437 }
438 
439 
440 
441 static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h265_raw_ptl)
442 {
443  h265_raw_ptl->general_profile_space = general_ptl->profile_space;
444  h265_raw_ptl->general_tier_flag = general_ptl->tier_flag;
445  h265_raw_ptl->general_profile_idc = general_ptl->profile_idc;
446 
447  memcpy(h265_raw_ptl->general_profile_compatibility_flag,
448  general_ptl->profile_compatibility_flag, 32 * sizeof(uint8_t));
449 
450 #define copy_field(name) h265_raw_ptl->general_ ## name = general_ptl->name
451  copy_field(progressive_source_flag);
452  copy_field(interlaced_source_flag);
453  copy_field(non_packed_constraint_flag);
454  copy_field(frame_only_constraint_flag);
455  copy_field(max_12bit_constraint_flag);
456  copy_field(max_10bit_constraint_flag);
457  copy_field(max_8bit_constraint_flag);
458  copy_field(max_422chroma_constraint_flag);
459  copy_field(max_420chroma_constraint_flag);
460  copy_field(max_monochrome_constraint_flag);
461  copy_field(intra_constraint_flag);
462  copy_field(one_picture_only_constraint_flag);
463  copy_field(lower_bit_rate_constraint_flag);
464  copy_field(max_14bit_constraint_flag);
465  copy_field(inbld_flag);
467 #undef copy_field
468 
469  return 0;
470 }
471 
472 /*
473  * Find exact vdpau_profile for HEVC Range Extension
474  */
475 static int vdpau_hevc_parse_rext_profile(AVCodecContext *avctx, VdpDecoderProfile *vdp_profile)
476 {
477  const HEVCContext *h = avctx->priv_data;
478  const HEVCSPS *sps = h->ps.sps;
479  const PTL *ptl = &sps->ptl;
480  const PTLCommon *general_ptl = &ptl->general_ptl;
482  H265RawProfileTierLevel h265_raw_ptl = {0};
483 
484  /* convert PTLCommon to H265RawProfileTierLevel */
485  ptl_convert(general_ptl, &h265_raw_ptl);
486 
487  profile = ff_h265_get_profile(&h265_raw_ptl);
488  if (!profile) {
489  av_log(avctx, AV_LOG_WARNING, "HEVC profile is not found.\n");
491  // Default to selecting Main profile if profile mismatch is allowed
492  *vdp_profile = VDP_DECODER_PROFILE_HEVC_MAIN;
493  return 0;
494  } else
495  return AVERROR(ENOTSUP);
496  }
497 
498  if (!strcmp(profile->name, "Main 12") ||
499  !strcmp(profile->name, "Main 12 Intra"))
500  *vdp_profile = VDP_DECODER_PROFILE_HEVC_MAIN_12;
501 #ifdef VDP_DECODER_PROFILE_HEVC_MAIN_444
502  else if (!strcmp(profile->name, "Main 4:4:4") ||
503  !strcmp(profile->name, "Main 4:4:4 Intra"))
504  *vdp_profile = VDP_DECODER_PROFILE_HEVC_MAIN_444;
505 #endif
506 #ifdef VDP_DECODER_PROFILE_HEVC_MAIN_444_10
507  else if (!strcmp(profile->name, "Main 4:4:4 10") ||
508  !strcmp(profile->name, "Main 4:4:4 10 Intra"))
509  *vdp_profile = VDP_DECODER_PROFILE_HEVC_MAIN_444_10;
510  else if (!strcmp(profile->name, "Main 4:4:4 12") ||
511  !strcmp(profile->name, "Main 4:4:4 12 Intra"))
512  *vdp_profile = VDP_DECODER_PROFILE_HEVC_MAIN_444_12;
513 #endif
514  else
515  return AVERROR(ENOTSUP);
516 
517  return 0;
518 }
519 
520 
521 static int vdpau_hevc_init(AVCodecContext *avctx)
522 {
523  VdpDecoderProfile profile;
524  uint32_t level = avctx->level;
525  int ret;
526 
527  switch (avctx->profile) {
529  profile = VDP_DECODER_PROFILE_HEVC_MAIN;
530  break;
532  profile = VDP_DECODER_PROFILE_HEVC_MAIN_10;
533  break;
535  profile = VDP_DECODER_PROFILE_HEVC_MAIN_STILL;
536  break;
538  ret = vdpau_hevc_parse_rext_profile(avctx, &profile);
539  if (ret)
540  return AVERROR(ENOTSUP);
541  break;
542  default:
543  return AVERROR(ENOTSUP);
544  }
545 
546  return ff_vdpau_common_init(avctx, profile, level);
547 }
548 
550  .name = "hevc_vdpau",
551  .type = AVMEDIA_TYPE_VIDEO,
552  .id = AV_CODEC_ID_HEVC,
553  .pix_fmt = AV_PIX_FMT_VDPAU,
554  .start_frame = vdpau_hevc_start_frame,
555  .end_frame = vdpau_hevc_end_frame,
556  .decode_slice = vdpau_hevc_decode_slice,
557  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
559  .uninit = ff_vdpau_common_uninit,
560  .frame_params = ff_vdpau_common_frame_params,
561  .priv_data_size = sizeof(VDPAUContext),
562  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
563 };
static double val(void *priv, double ch)
Definition: aeval.c:76
uint8_t
Libavcodec external API header.
#define FF_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: avcodec.h:1952
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:1951
#define FF_PROFILE_HEVC_REXT
Definition: avcodec.h:1953
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:1950
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static AVFrame * frame
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:137
int ff_vdpau_common_start_frame(struct vdpau_picture_context *pic_ctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vdpau.c:326
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:288
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:381
int ff_vdpau_common_end_frame(AVCodecContext *avctx, AVFrame *frame, struct vdpau_picture_context *pic_ctx)
Definition: vdpau.c:336
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:118
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:223
#define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH
Hardware acceleration should still be attempted for decoding when the codec profile does not match th...
Definition: avcodec.h:2638
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
const H265ProfileDescriptor * ff_h265_get_profile(const H265RawProfileTierLevel *ptl)
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: hevc_data.c:39
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: hevc_data.c:25
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: hevc_data.c:58
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: hevc_data.c:32
int ff_hevc_frame_nb_refs(const HEVCContext *s)
Get the number of candidate references for the current frame.
Definition: hevc_refs.c:504
#define HEVC_FRAME_FLAG_SHORT_REF
Definition: hevcdec.h:392
#define IS_IDR(s)
Definition: hevcdec.h:78
#define HEVC_FRAME_FLAG_LONG_REF
Definition: hevcdec.h:393
#define IS_IRAP(s)
Definition: hevcdec.h:81
@ ST_CURR_AFT
Definition: hevcdec.h:85
@ ST_CURR_BEF
Definition: hevcdec.h:84
@ LT_CURR
Definition: hevcdec.h:87
#define HWACCEL_CAP_ASYNC_SAFE
Definition: hwconfig.h:26
int i
Definition: input.c:407
common internal API header
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:197
mfxU16 profile
Definition: qsvenc.c:45
static char buffer[20]
Definition: seek.c:32
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition: spdifenc.c:412
main external API structure.
Definition: avcodec.h:536
int hwaccel_flags
Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active).
Definition: avcodec.h:2283
int level
level
Definition: avcodec.h:1988
int profile
profile
Definition: avcodec.h:1862
void * priv_data
Definition: avcodec.h:563
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:555
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2448
uint8_t general_profile_compatibility_flag[32]
Definition: cbs_h265.h:40
uint8_t general_tier_flag
Definition: cbs_h265.h:37
uint8_t general_profile_space
Definition: cbs_h265.h:36
uint8_t general_profile_idc
Definition: cbs_h265.h:38
void * hwaccel_picture_private
Definition: hevcdec.h:411
uint8_t profile_idc
Definition: hevc_ps.h:95
uint8_t profile_space
Definition: hevc_ps.h:93
uint8_t tier_flag
Definition: hevc_ps.h:94
uint8_t profile_compatibility_flag[32]
Definition: hevc_ps.h:96
Definition: hevc_ps.h:115
uint8_t sl_dc[2][6]
Definition: hevc_ps.h:150
uint8_t sl[4][6][64]
Definition: hevc_ps.h:149
int rps_idx_num_delta_pocs
Definition: hevc_ps.h:37
const ShortTermRPS * short_term_rps
Definition: hevcdec.h:271
int short_term_ref_pic_set_sps_flag
Definition: hevcdec.h:268
int short_term_ref_pic_set_size
Definition: hevcdec.h:269
int long_term_ref_pic_set_size
Definition: hevcdec.h:272
union VDPAUPictureInfo info
VDPAU picture information.
uint8_t level
Definition: svq3.c:206
#define av_log(a,...)
int level_idc
Definition: h264_levels.c:25
int size
Public libavcodec VDPAU header.
static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h265_raw_ptl)
Definition: vdpau_hevc.c:441
const AVHWAccel ff_hevc_vdpau_hwaccel
Definition: vdpau_hevc.c:549
static int vdpau_hevc_end_frame(AVCodecContext *avctx)
Definition: vdpau_hevc.c:426
static const uint8_t start_code_prefix[3]
Definition: vdpau_hevc.c:406
#define copy_field(name)
static int vdpau_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_hevc.c:408
static int vdpau_hevc_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_hevc.c:35
static int vdpau_hevc_init(AVCodecContext *avctx)
Definition: vdpau_hevc.c:521
static int vdpau_hevc_parse_rext_profile(AVCodecContext *avctx, VdpDecoderProfile *vdp_profile)
Definition: vdpau_hevc.c:475
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.