23 #include "config_components.h"
32 #define MAX_SLICES 256
35 DXVA_PicParams_HEVC
pp;
54 if ((pp->RefPicList[
i].bPicEntry & 0x7f) == surface_index)
61 DXVA_PicParams_HEVC *pp)
65 const HEVCFrame *current_picture =
h->cur_frame;
70 memset(pp, 0,
sizeof(*pp));
72 pp->PicWidthInMinCbsY =
sps->min_cb_width;
73 pp->PicHeightInMinCbsY =
sps->min_cb_height;
75 pp->wFormatAndSequenceInfoFlags = (
sps->chroma_format_idc << 0) |
76 (
sps->separate_colour_plane << 2) |
77 ((
sps->bit_depth - 8) << 3) |
78 ((
sps->bit_depth - 8) << 6) |
79 ((
sps->log2_max_poc_lsb - 4) << 9) |
84 pp->sps_max_dec_pic_buffering_minus1 =
sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
85 pp->log2_min_luma_coding_block_size_minus3 =
sps->log2_min_cb_size - 3;
86 pp->log2_diff_max_min_luma_coding_block_size =
sps->log2_diff_max_min_coding_block_size;
87 pp->log2_min_transform_block_size_minus2 =
sps->log2_min_tb_size - 2;
88 pp->log2_diff_max_min_transform_block_size =
sps->log2_max_trafo_size -
sps->log2_min_tb_size;
89 pp->max_transform_hierarchy_depth_inter =
sps->max_transform_hierarchy_depth_inter;
90 pp->max_transform_hierarchy_depth_intra =
sps->max_transform_hierarchy_depth_intra;
91 pp->num_short_term_ref_pic_sets =
sps->nb_st_rps;
92 pp->num_long_term_ref_pics_sps =
sps->num_long_term_ref_pics_sps;
94 pp->num_ref_idx_l0_default_active_minus1 =
pps->num_ref_idx_l0_default_active - 1;
95 pp->num_ref_idx_l1_default_active_minus1 =
pps->num_ref_idx_l1_default_active - 1;
96 pp->init_qp_minus26 =
pps->pic_init_qp_minus26;
98 if (
h->sh.short_term_ref_pic_set_sps_flag == 0 &&
h->sh.short_term_rps) {
99 pp->ucNumDeltaPocsOfRefRpsIdx =
h->sh.short_term_rps->rps_idx_num_delta_pocs;
100 pp->wNumBitsForShortTermRPSInSlice =
h->sh.short_term_ref_pic_set_size;
103 pp->dwCodingParamToolFlags = (
sps->scaling_list_enabled << 0) |
104 (
sps->amp_enabled << 1) |
105 (
sps->sao_enabled << 2) |
106 (
sps->pcm_enabled << 3) |
107 ((
sps->pcm_enabled ? (
sps->pcm.bit_depth - 1) : 0) << 4) |
108 ((
sps->pcm_enabled ? (
sps->pcm.bit_depth_chroma - 1) : 0) << 8) |
109 ((
sps->pcm_enabled ? (
sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
110 ((
sps->pcm_enabled ? (
sps->pcm.log2_max_pcm_cb_size -
sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
111 (
sps->pcm_loop_filter_disabled << 16) |
112 (
sps->long_term_ref_pics_present << 17) |
113 (
sps->temporal_mvp_enabled << 18) |
114 (
sps->strong_intra_smoothing_enabled << 19) |
115 (
pps->dependent_slice_segments_enabled_flag << 20) |
116 (
pps->output_flag_present_flag << 21) |
117 (
pps->num_extra_slice_header_bits << 22) |
118 (
pps->sign_data_hiding_flag << 25) |
119 (
pps->cabac_init_present_flag << 26) |
122 pp->dwCodingSettingPicturePropertyFlags = (
pps->constrained_intra_pred_flag << 0) |
123 (
pps->transform_skip_enabled_flag << 1) |
124 (
pps->cu_qp_delta_enabled_flag << 2) |
125 (
pps->pic_slice_level_chroma_qp_offsets_present_flag << 3) |
126 (
pps->weighted_pred_flag << 4) |
127 (
pps->weighted_bipred_flag << 5) |
128 (
pps->transquant_bypass_enable_flag << 6) |
129 (
pps->tiles_enabled_flag << 7) |
130 (
pps->entropy_coding_sync_enabled_flag << 8) |
131 (
pps->uniform_spacing_flag << 9) |
132 ((
pps->tiles_enabled_flag ?
pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |
133 (
pps->seq_loop_filter_across_slices_enabled_flag << 11) |
134 (
pps->deblocking_filter_override_enabled_flag << 12) |
135 (
pps->disable_dbf << 13) |
136 (
pps->lists_modification_present_flag << 14) |
137 (
pps->slice_header_extension_present_flag << 15) |
143 pp->pps_cb_qp_offset =
pps->cb_qp_offset;
144 pp->pps_cr_qp_offset =
pps->cr_qp_offset;
145 if (
pps->tiles_enabled_flag) {
146 pp->num_tile_columns_minus1 =
pps->num_tile_columns - 1;
147 pp->num_tile_rows_minus1 =
pps->num_tile_rows - 1;
149 if (!
pps->uniform_spacing_flag) {
150 for (
i = 0;
i <
pps->num_tile_columns;
i++)
151 pp->column_width_minus1[
i] =
pps->column_width[
i] - 1;
154 pp->row_height_minus1[
i] =
pps->row_height[
i] - 1;
158 pp->diff_cu_qp_delta_depth =
pps->diff_cu_qp_delta_depth;
159 pp->pps_beta_offset_div2 =
pps->beta_offset / 2;
160 pp->pps_tc_offset_div2 =
pps->tc_offset / 2;
161 pp->log2_parallel_merge_level_minus2 =
pps->log2_parallel_merge_level - 2;
162 pp->CurrPicOrderCntVal =
h->poc;
175 pp->PicOrderCntValList[
i] =
frame->poc;
177 pp->RefPicList[
i].bPicEntry = 0xff;
178 pp->PicOrderCntValList[
i] = 0;
184 #define DO_REF_LIST(ref_idx, ref_list) { \
185 const RefPicList *rpl = &h->rps[ref_idx]; \
186 for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ref_list); i++) { \
187 const HEVCFrame *frame = NULL; \
188 while (!frame && j < rpl->nb_refs) \
189 frame = rpl->ref[j++]; \
190 if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)) \
191 pp->ref_list[i] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, frame->f, 0)); \
193 pp->ref_list[i] = 0xff; \
209 const ScalingList *sl =
h->pps->scaling_list_data_present_flag ?
210 &
h->pps->scaling_list : &
h->pps->sps->scaling_list;
212 memset(qm, 0,
sizeof(*qm));
213 for (
i = 0;
i < 6;
i++) {
214 for (j = 0; j < 16; j++) {
216 qm->ucScalingLists0[
i][j] = sl->
sl[0][
i][
pos];
219 for (j = 0; j < 64; j++) {
221 qm->ucScalingLists1[
i][j] = sl->
sl[1][
i][
pos];
222 qm->ucScalingLists2[
i][j] = sl->
sl[2][
i][
pos];
225 qm->ucScalingLists3[
i][j] = sl->
sl[3][
i * 3][
pos];
228 qm->ucScalingListDCCoefSizeID2[
i] = sl->
sl_dc[0][
i];
230 qm->ucScalingListDCCoefSizeID3[
i] = sl->
sl_dc[1][
i * 3];
235 unsigned position,
unsigned size)
237 memset(slice, 0,
sizeof(*slice));
238 slice->BSNALunitDataLocation = position;
239 slice->SliceBytesInBuffer =
size;
240 slice->wBadSliceChopping = 0;
249 const HEVCFrame *current_picture =
h->cur_frame;
251 DXVA_Slice_HEVC_Short *slice =
NULL;
252 void *dxva_data_ptr =
NULL;
253 uint8_t *dxva_data, *current, *end;
264 type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
268 &dxva_size, &dxva_data_ptr)))
274 type = DXVA2_BitStreamDateBufferType;
277 &dxva_data_ptr, &dxva_size)))
285 dxva_data = dxva_data_ptr;
287 end = dxva_data + dxva_size;
290 static const uint8_t
start_code[] = { 0, 0, 1 };
291 static const unsigned start_code_size =
sizeof(
start_code);
292 unsigned position,
size;
296 position = slice->BSNALunitDataLocation;
297 size = slice->SliceBytesInBuffer;
298 if (start_code_size +
size > end - current) {
303 slice->BSNALunitDataLocation = current - dxva_data;
304 slice->SliceBytesInBuffer = start_code_size +
size;
307 current += start_code_size;
312 padding =
FFMIN(128 - ((current - dxva_data) & 127), end - current);
313 if (slice && padding > 0) {
314 memset(current, 0, padding);
317 slice->SliceBytesInBuffer += padding;
334 D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
335 memset(dsc11, 0,
sizeof(*dsc11));
336 dsc11->BufferType =
type;
337 dsc11->DataSize = current - dxva_data;
338 dsc11->NumMBsInBuffer = 0;
340 type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
345 DXVA2_DecodeBufferDesc *dsc2 = bs;
346 memset(dsc2, 0,
sizeof(*dsc2));
347 dsc2->CompressedBufferType =
type;
348 dsc2->DataSize = current - dxva_data;
349 dsc2->NumMBsInBuffer = 0;
351 type = DXVA2_SliceControlBufferType;
358 av_assert0(((current - dxva_data) & 127) == 0);
361 slice_data, slice_size, 0);
394 const HEVCFrame *current_picture =
h->cur_frame;
416 int scale = ctx_pic->
pp.dwCodingParamToolFlags & 1;
423 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
429 #if CONFIG_HEVC_DXVA2_HWACCEL
431 .
p.
name =
"hevc_dxva2",
446 #if CONFIG_HEVC_D3D11VA_HWACCEL
448 .
p.
name =
"hevc_d3d11va",
463 #if CONFIG_HEVC_D3D11VA2_HWACCEL
465 .
p.
name =
"hevc_d3d11va2",