29 #define MAX_SLICES 256
32 DXVA_PicParams_HEVC
pp;
51 if ((pp->RefPicList[
i].bPicEntry & 0x7f) == surface_index)
58 DXVA_PicParams_HEVC *pp)
65 memset(pp, 0,
sizeof(*pp));
67 pp->PicWidthInMinCbsY =
sps->min_cb_width;
68 pp->PicHeightInMinCbsY =
sps->min_cb_height;
70 pp->wFormatAndSequenceInfoFlags = (
sps->chroma_format_idc << 0) |
71 (
sps->separate_colour_plane_flag << 2) |
72 ((
sps->bit_depth - 8) << 3) |
73 ((
sps->bit_depth - 8) << 6) |
74 ((
sps->log2_max_poc_lsb - 4) << 9) |
81 pp->sps_max_dec_pic_buffering_minus1 =
sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
82 pp->log2_min_luma_coding_block_size_minus3 =
sps->log2_min_cb_size - 3;
83 pp->log2_diff_max_min_luma_coding_block_size =
sps->log2_diff_max_min_coding_block_size;
84 pp->log2_min_transform_block_size_minus2 =
sps->log2_min_tb_size - 2;
85 pp->log2_diff_max_min_transform_block_size =
sps->log2_max_trafo_size -
sps->log2_min_tb_size;
86 pp->max_transform_hierarchy_depth_inter =
sps->max_transform_hierarchy_depth_inter;
87 pp->max_transform_hierarchy_depth_intra =
sps->max_transform_hierarchy_depth_intra;
88 pp->num_short_term_ref_pic_sets =
sps->nb_st_rps;
89 pp->num_long_term_ref_pics_sps =
sps->num_long_term_ref_pics_sps;
91 pp->num_ref_idx_l0_default_active_minus1 =
pps->num_ref_idx_l0_default_active - 1;
92 pp->num_ref_idx_l1_default_active_minus1 =
pps->num_ref_idx_l1_default_active - 1;
93 pp->init_qp_minus26 =
pps->pic_init_qp_minus26;
95 if (
h->sh.short_term_ref_pic_set_sps_flag == 0 &&
h->sh.short_term_rps) {
96 pp->ucNumDeltaPocsOfRefRpsIdx =
h->sh.short_term_rps->rps_idx_num_delta_pocs;
97 pp->wNumBitsForShortTermRPSInSlice =
h->sh.short_term_ref_pic_set_size;
100 pp->dwCodingParamToolFlags = (
sps->scaling_list_enable_flag << 0) |
101 (
sps->amp_enabled_flag << 1) |
102 (
sps->sao_enabled << 2) |
103 (
sps->pcm_enabled_flag << 3) |
104 ((
sps->pcm_enabled_flag ? (
sps->pcm.bit_depth - 1) : 0) << 4) |
105 ((
sps->pcm_enabled_flag ? (
sps->pcm.bit_depth_chroma - 1) : 0) << 8) |
106 ((
sps->pcm_enabled_flag ? (
sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
107 ((
sps->pcm_enabled_flag ? (
sps->pcm.log2_max_pcm_cb_size -
sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
108 (
sps->pcm.loop_filter_disable_flag << 16) |
109 (
sps->long_term_ref_pics_present_flag << 17) |
110 (
sps->sps_temporal_mvp_enabled_flag << 18) |
111 (
sps->sps_strong_intra_smoothing_enable_flag << 19) |
112 (
pps->dependent_slice_segments_enabled_flag << 20) |
113 (
pps->output_flag_present_flag << 21) |
114 (
pps->num_extra_slice_header_bits << 22) |
115 (
pps->sign_data_hiding_flag << 25) |
116 (
pps->cabac_init_present_flag << 26) |
119 pp->dwCodingSettingPicturePropertyFlags = (
pps->constrained_intra_pred_flag << 0) |
120 (
pps->transform_skip_enabled_flag << 1) |
121 (
pps->cu_qp_delta_enabled_flag << 2) |
122 (
pps->pic_slice_level_chroma_qp_offsets_present_flag << 3) |
123 (
pps->weighted_pred_flag << 4) |
124 (
pps->weighted_bipred_flag << 5) |
125 (
pps->transquant_bypass_enable_flag << 6) |
126 (
pps->tiles_enabled_flag << 7) |
127 (
pps->entropy_coding_sync_enabled_flag << 8) |
128 (
pps->uniform_spacing_flag << 9) |
129 ((
pps->tiles_enabled_flag ?
pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |
130 (
pps->seq_loop_filter_across_slices_enabled_flag << 11) |
131 (
pps->deblocking_filter_override_enabled_flag << 12) |
132 (
pps->disable_dbf << 13) |
133 (
pps->lists_modification_present_flag << 14) |
134 (
pps->slice_header_extension_present_flag << 15) |
140 pp->pps_cb_qp_offset =
pps->cb_qp_offset;
141 pp->pps_cr_qp_offset =
pps->cr_qp_offset;
142 if (
pps->tiles_enabled_flag) {
143 pp->num_tile_columns_minus1 =
pps->num_tile_columns - 1;
144 pp->num_tile_rows_minus1 =
pps->num_tile_rows - 1;
146 if (!
pps->uniform_spacing_flag) {
147 for (
i = 0;
i <
pps->num_tile_columns;
i++)
148 pp->column_width_minus1[
i] =
pps->column_width[
i] - 1;
151 pp->row_height_minus1[
i] =
pps->row_height[
i] - 1;
155 pp->diff_cu_qp_delta_depth =
pps->diff_cu_qp_delta_depth;
156 pp->pps_beta_offset_div2 =
pps->beta_offset / 2;
157 pp->pps_tc_offset_div2 =
pps->tc_offset / 2;
158 pp->log2_parallel_merge_level_minus2 =
pps->log2_parallel_merge_level - 2;
159 pp->CurrPicOrderCntVal =
h->poc;
172 pp->PicOrderCntValList[
i] =
frame->poc;
174 pp->RefPicList[
i].bPicEntry = 0xff;
175 pp->PicOrderCntValList[
i] = 0;
179 #define DO_REF_LIST(ref_idx, ref_list) { \
180 const RefPicList *rpl = &h->rps[ref_idx]; \
181 for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ref_list); i++) { \
182 const HEVCFrame *frame = NULL; \
183 while (!frame && j < rpl->nb_refs) \
184 frame = rpl->ref[j++]; \
186 pp->ref_list[i] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, frame->frame)); \
188 pp->ref_list[i] = 0xff; \
197 pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx,
ctx)++;
203 const ScalingList *sl =
h->ps.pps->scaling_list_data_present_flag ?
204 &
h->ps.pps->scaling_list : &
h->ps.sps->scaling_list;
206 memset(qm, 0,
sizeof(*qm));
207 for (
i = 0;
i < 6;
i++) {
208 for (j = 0; j < 16; j++) {
210 qm->ucScalingLists0[
i][j] = sl->
sl[0][
i][pos];
213 for (j = 0; j < 64; j++) {
215 qm->ucScalingLists1[
i][j] = sl->
sl[1][
i][pos];
216 qm->ucScalingLists2[
i][j] = sl->
sl[2][
i][pos];
219 qm->ucScalingLists3[
i][j] = sl->
sl[3][
i * 3][pos];
222 qm->ucScalingListDCCoefSizeID2[
i] = sl->
sl_dc[0][
i];
224 qm->ucScalingListDCCoefSizeID3[
i] = sl->
sl_dc[1][
i * 3];
229 unsigned position,
unsigned size)
231 memset(slice, 0,
sizeof(*slice));
232 slice->BSNALunitDataLocation = position;
233 slice->SliceBytesInBuffer =
size;
234 slice->wBadSliceChopping = 0;
245 DXVA_Slice_HEVC_Short *slice =
NULL;
258 type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
262 &dxva_size, &dxva_data_ptr)))
268 type = DXVA2_BitStreamDateBufferType;
271 &dxva_data_ptr, &dxva_size)))
276 dxva_data = dxva_data_ptr;
278 end = dxva_data + dxva_size;
282 static const unsigned start_code_size =
sizeof(
start_code);
283 unsigned position,
size;
287 position = slice->BSNALunitDataLocation;
288 size = slice->SliceBytesInBuffer;
289 if (start_code_size +
size >
end - current) {
294 slice->BSNALunitDataLocation = current - dxva_data;
295 slice->SliceBytesInBuffer = start_code_size +
size;
298 current += start_code_size;
303 padding =
FFMIN(128 - ((current - dxva_data) & 127),
end - current);
304 if (slice && padding > 0) {
305 memset(current, 0, padding);
308 slice->SliceBytesInBuffer += padding;
325 D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
326 memset(dsc11, 0,
sizeof(*dsc11));
327 dsc11->BufferType =
type;
328 dsc11->DataSize = current - dxva_data;
329 dsc11->NumMBsInBuffer = 0;
331 type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
336 DXVA2_DecodeBufferDesc *dsc2 = bs;
337 memset(dsc2, 0,
sizeof(*dsc2));
338 dsc2->CompressedBufferType =
type;
339 dsc2->DataSize = current - dxva_data;
340 dsc2->NumMBsInBuffer = 0;
342 type = DXVA2_SliceControlBufferType;
349 av_assert0(((current - dxva_data) & 127) == 0);
352 slice_data, slice_size, 0);
364 if (!DXVA_CONTEXT_VALID(avctx,
ctx))
407 int scale = ctx_pic->
pp.dwCodingParamToolFlags & 1;
414 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
415 scale ? &ctx_pic->
qm :
NULL, scale ?
sizeof(ctx_pic->
qm) : 0,
420 #if CONFIG_HEVC_DXVA2_HWACCEL
422 .
name =
"hevc_dxva2",
437 #if CONFIG_HEVC_D3D11VA_HWACCEL
439 .
name =
"hevc_d3d11va",
454 #if CONFIG_HEVC_D3D11VA2_HWACCEL
456 .
name =
"hevc_d3d11va2",