24 #include <va/va_dec_hevc.h>
34 #if VA_CHECK_VERSION(1, 2, 0)
35 VAPictureParameterBufferHEVCExtension
pic_param;
49 va_pic->picture_id = VA_INVALID_ID;
50 va_pic->flags = VA_PICTURE_HEVC_INVALID;
51 va_pic->pic_order_cnt = 0;
57 va_pic->pic_order_cnt = pic->
poc;
58 va_pic->flags = rps_type;
61 va_pic->flags |= VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
64 va_pic->flags |= VA_PICTURE_HEVC_FIELD_PIC;
67 va_pic->flags |= VA_PICTURE_HEVC_BOTTOM_FIELD;
79 return VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE;
84 return VA_PICTURE_HEVC_RPS_ST_CURR_AFTER;
89 return VA_PICTURE_HEVC_RPS_LT_CURR;
92 if (
h->ps.pps->pps_curr_pic_ref_enabled_flag && current_picture->
poc == pic->
poc)
93 return VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
107 if ((&
h->DPB[j] != current_picture ||
h->ps.pps->pps_curr_pic_ref_enabled_flag) &&
132 int pic_param_size, err,
i;
134 #if VA_CHECK_VERSION(1, 2, 0)
135 int num_comps, pre_palette_size;
138 VAPictureParameterBufferHEVC *pic_param = (VAPictureParameterBufferHEVC *)&pic->
pic_param;
142 *pic_param = (VAPictureParameterBufferHEVC) {
143 .pic_width_in_luma_samples =
sps->width,
144 .pic_height_in_luma_samples =
sps->height,
145 .log2_min_luma_coding_block_size_minus3 =
sps->log2_min_cb_size - 3,
146 .sps_max_dec_pic_buffering_minus1 =
sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering - 1,
147 .log2_diff_max_min_luma_coding_block_size =
sps->log2_diff_max_min_coding_block_size,
148 .log2_min_transform_block_size_minus2 =
sps->log2_min_tb_size - 2,
149 .log2_diff_max_min_transform_block_size =
sps->log2_max_trafo_size -
sps->log2_min_tb_size,
150 .max_transform_hierarchy_depth_inter =
sps->max_transform_hierarchy_depth_inter,
151 .max_transform_hierarchy_depth_intra =
sps->max_transform_hierarchy_depth_intra,
152 .num_short_term_ref_pic_sets =
sps->nb_st_rps,
153 .num_long_term_ref_pic_sps =
sps->num_long_term_ref_pics_sps,
154 .num_ref_idx_l0_default_active_minus1 =
pps->num_ref_idx_l0_default_active - 1,
155 .num_ref_idx_l1_default_active_minus1 =
pps->num_ref_idx_l1_default_active - 1,
156 .init_qp_minus26 =
pps->pic_init_qp_minus26,
157 .pps_cb_qp_offset =
pps->cb_qp_offset,
158 .pps_cr_qp_offset =
pps->cr_qp_offset,
159 .pcm_sample_bit_depth_luma_minus1 =
sps->pcm.bit_depth - 1,
160 .pcm_sample_bit_depth_chroma_minus1 =
sps->pcm.bit_depth_chroma - 1,
161 .log2_min_pcm_luma_coding_block_size_minus3 =
sps->pcm.log2_min_pcm_cb_size - 3,
162 .log2_diff_max_min_pcm_luma_coding_block_size =
sps->pcm.log2_max_pcm_cb_size -
sps->pcm.log2_min_pcm_cb_size,
163 .diff_cu_qp_delta_depth =
pps->diff_cu_qp_delta_depth,
164 .pps_beta_offset_div2 =
pps->beta_offset / 2,
165 .pps_tc_offset_div2 =
pps->tc_offset / 2,
166 .log2_parallel_merge_level_minus2 =
pps->log2_parallel_merge_level - 2,
167 .bit_depth_luma_minus8 =
sps->bit_depth - 8,
168 .bit_depth_chroma_minus8 =
sps->bit_depth - 8,
169 .log2_max_pic_order_cnt_lsb_minus4 =
sps->log2_max_poc_lsb - 4,
170 .num_extra_slice_header_bits =
pps->num_extra_slice_header_bits,
172 .chroma_format_idc =
sps->chroma_format_idc,
173 .tiles_enabled_flag =
pps->tiles_enabled_flag,
174 .separate_colour_plane_flag =
sps->separate_colour_plane_flag,
175 .pcm_enabled_flag =
sps->pcm_enabled_flag,
176 .scaling_list_enabled_flag =
sps->scaling_list_enable_flag,
177 .transform_skip_enabled_flag =
pps->transform_skip_enabled_flag,
178 .amp_enabled_flag =
sps->amp_enabled_flag,
179 .strong_intra_smoothing_enabled_flag =
sps->sps_strong_intra_smoothing_enable_flag,
180 .sign_data_hiding_enabled_flag =
pps->sign_data_hiding_flag,
181 .constrained_intra_pred_flag =
pps->constrained_intra_pred_flag,
182 .cu_qp_delta_enabled_flag =
pps->cu_qp_delta_enabled_flag,
183 .weighted_pred_flag =
pps->weighted_pred_flag,
184 .weighted_bipred_flag =
pps->weighted_bipred_flag,
185 .transquant_bypass_enabled_flag =
pps->transquant_bypass_enable_flag,
186 .entropy_coding_sync_enabled_flag =
pps->entropy_coding_sync_enabled_flag,
187 .pps_loop_filter_across_slices_enabled_flag =
pps->seq_loop_filter_across_slices_enabled_flag,
188 .loop_filter_across_tiles_enabled_flag =
pps->loop_filter_across_tiles_enabled_flag,
189 .pcm_loop_filter_disabled_flag =
sps->pcm.loop_filter_disable_flag,
191 .slice_parsing_fields.bits = {
192 .lists_modification_present_flag =
pps->lists_modification_present_flag,
193 .long_term_ref_pics_present_flag =
sps->long_term_ref_pics_present_flag,
194 .sps_temporal_mvp_enabled_flag =
sps->sps_temporal_mvp_enabled_flag,
195 .cabac_init_present_flag =
pps->cabac_init_present_flag,
196 .output_flag_present_flag =
pps->output_flag_present_flag,
197 .dependent_slice_segments_enabled_flag =
pps->dependent_slice_segments_enabled_flag,
198 .pps_slice_chroma_qp_offsets_present_flag =
pps->pic_slice_level_chroma_qp_offsets_present_flag,
199 .sample_adaptive_offset_enabled_flag =
sps->sao_enabled,
200 .deblocking_filter_override_enabled_flag =
pps->deblocking_filter_override_enabled_flag,
201 .pps_disable_deblocking_filter_flag =
pps->disable_dbf,
202 .slice_segment_header_extension_present_flag =
pps->slice_header_extension_present_flag,
212 if (
pps->tiles_enabled_flag) {
213 pic_param->num_tile_columns_minus1 =
pps->num_tile_columns - 1;
214 pic_param->num_tile_rows_minus1 =
pps->num_tile_rows - 1;
216 for (
i = 0;
i <
pps->num_tile_columns;
i++)
217 pic_param->column_width_minus1[
i] =
pps->column_width[
i] - 1;
220 pic_param->row_height_minus1[
i] =
pps->row_height[
i] - 1;
223 if (
h->sh.short_term_ref_pic_set_sps_flag == 0 &&
h->sh.short_term_rps) {
224 pic_param->st_rps_bits =
h->sh.short_term_ref_pic_set_size;
226 pic_param->st_rps_bits = 0;
229 #if VA_CHECK_VERSION(1, 2, 0)
232 pic->
pic_param.rext = (VAPictureParameterBufferHEVCRext) {
233 .range_extension_pic_fields.bits = {
234 .transform_skip_rotation_enabled_flag =
sps->transform_skip_rotation_enabled_flag,
235 .transform_skip_context_enabled_flag =
sps->transform_skip_context_enabled_flag,
236 .implicit_rdpcm_enabled_flag =
sps->implicit_rdpcm_enabled_flag,
237 .explicit_rdpcm_enabled_flag =
sps->explicit_rdpcm_enabled_flag,
238 .extended_precision_processing_flag =
sps->extended_precision_processing_flag,
239 .intra_smoothing_disabled_flag =
sps->intra_smoothing_disabled_flag,
240 .high_precision_offsets_enabled_flag =
sps->high_precision_offsets_enabled_flag,
241 .persistent_rice_adaptation_enabled_flag =
sps->persistent_rice_adaptation_enabled_flag,
242 .cabac_bypass_alignment_enabled_flag =
sps->cabac_bypass_alignment_enabled_flag,
243 .cross_component_prediction_enabled_flag =
pps->cross_component_prediction_enabled_flag,
244 .chroma_qp_offset_list_enabled_flag =
pps->chroma_qp_offset_list_enabled_flag,
246 .diff_cu_chroma_qp_offset_depth =
pps->diff_cu_chroma_qp_offset_depth,
247 .chroma_qp_offset_list_len_minus1 =
pps->chroma_qp_offset_list_len_minus1,
248 .log2_sao_offset_scale_luma =
pps->log2_sao_offset_scale_luma,
249 .log2_sao_offset_scale_chroma =
pps->log2_sao_offset_scale_chroma,
250 .log2_max_transform_skip_block_size_minus2 =
pps->log2_max_transform_skip_block_size - 2,
253 for (
i = 0;
i < 6;
i++)
254 pic->
pic_param.rext.cb_qp_offset_list[
i] =
pps->cb_qp_offset_list[
i];
256 pic->
pic_param.rext.cr_qp_offset_list[
i] =
pps->cr_qp_offset_list[
i];
259 pre_palette_size =
pps->pps_palette_predictor_initializers_present_flag ?
260 pps->pps_num_palette_predictor_initializers :
261 (
sps->sps_palette_predictor_initializers_present_flag ?
262 sps->sps_num_palette_predictor_initializers :
266 pic->
pic_param.scc = (VAPictureParameterBufferHEVCScc) {
267 .screen_content_pic_fields.bits = {
268 .pps_curr_pic_ref_enabled_flag =
pps->pps_curr_pic_ref_enabled_flag,
269 .palette_mode_enabled_flag =
sps->palette_mode_enabled_flag,
270 .motion_vector_resolution_control_idc =
sps->motion_vector_resolution_control_idc,
271 .intra_boundary_filtering_disabled_flag =
sps->intra_boundary_filtering_disabled_flag,
272 .residual_adaptive_colour_transform_enabled_flag
273 =
pps->residual_adaptive_colour_transform_enabled_flag,
274 .pps_slice_act_qp_offsets_present_flag =
pps->pps_slice_act_qp_offsets_present_flag,
276 .palette_max_size =
sps->palette_max_size,
277 .delta_palette_max_predictor_size =
sps->delta_palette_max_predictor_size,
278 .predictor_palette_size = pre_palette_size,
279 .pps_act_y_qp_offset_plus5 =
pps->residual_adaptive_colour_transform_enabled_flag ?
280 pps->pps_act_y_qp_offset + 5 : 0,
281 .pps_act_cb_qp_offset_plus5 =
pps->residual_adaptive_colour_transform_enabled_flag ?
282 pps->pps_act_cb_qp_offset + 5 : 0,
283 .pps_act_cr_qp_offset_plus3 =
pps->residual_adaptive_colour_transform_enabled_flag ?
284 pps->pps_act_cr_qp_offset + 3 : 0,
287 num_comps =
pps->monochrome_palette_flag ? 1 : 3;
289 for (
int j = 0; j < pre_palette_size; j++)
291 pps->pps_palette_predictor_initializers_present_flag ?
292 pps->pps_palette_predictor_initializer[
comp][j]:
293 sps->sps_palette_predictor_initializer[
comp][j];
298 sizeof(pic->
pic_param) :
sizeof(VAPictureParameterBufferHEVC);
301 VAPictureParameterBufferType,
306 if (
pps->scaling_list_data_present_flag)
308 else if (
sps->scaling_list_enable_flag)
312 VAIQMatrixBufferHEVC iq_matrix;
315 for (
i = 0;
i < 6;
i++) {
316 for (j = 0; j < 16; j++)
318 for (j = 0; j < 64; j++) {
330 VAIQMatrixBufferType,
331 &iq_matrix,
sizeof(iq_matrix));
347 VASliceParameterBufferHEVC *last_slice_param = (VASliceParameterBufferHEVC *)&pic->
last_slice_param;
354 last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
376 VASliceParameterBufferHEVC *slice_param)
379 #if VA_CHECK_VERSION(1, 2, 0)
385 "or above, which can support REXT related setting correctly.\n");
388 memset(slice_param->delta_luma_weight_l0, 0,
sizeof(slice_param->delta_luma_weight_l0));
389 memset(slice_param->delta_luma_weight_l1, 0,
sizeof(slice_param->delta_luma_weight_l1));
390 memset(slice_param->luma_offset_l0, 0,
sizeof(slice_param->luma_offset_l0));
391 memset(slice_param->luma_offset_l1, 0,
sizeof(slice_param->luma_offset_l1));
392 memset(slice_param->delta_chroma_weight_l0, 0,
sizeof(slice_param->delta_chroma_weight_l0));
393 memset(slice_param->delta_chroma_weight_l1, 0,
sizeof(slice_param->delta_chroma_weight_l1));
394 memset(slice_param->ChromaOffsetL0, 0,
sizeof(slice_param->ChromaOffsetL0));
395 memset(slice_param->ChromaOffsetL1, 0,
sizeof(slice_param->ChromaOffsetL1));
397 slice_param->delta_chroma_log2_weight_denom = 0;
398 slice_param->luma_log2_weight_denom = 0;
407 if (
h->ps.sps->chroma_format_idc) {
439 VAPictureParameterBufferHEVC *pp = (VAPictureParameterBufferHEVC *)&pic->
pic_param;
446 VASurfaceID pid = pp->ReferenceFrames[
i].picture_id;
447 int poc = pp->ReferenceFrames[
i].pic_order_cnt;
462 VASliceParameterBufferHEVC *last_slice_param = (VASliceParameterBufferHEVC *)&pic->
last_slice_param;
470 int err,
i, list_idx;
484 *last_slice_param = (VASliceParameterBufferHEVC) {
485 .slice_data_size =
size,
486 .slice_data_offset = 0,
487 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
490 .slice_data_byte_offset = (
get_bits_count(&
h->HEVClc->gb) + 1 + 7) / 8,
496 .slice_tc_offset_div2 = sh->
tc_offset / 2,
502 .LongSliceFlags.fields = {
517 memset(last_slice_param->RefPicList, 0xFF,
sizeof(last_slice_param->RefPicList));
519 for (list_idx = 0; list_idx < nb_list; list_idx++) {
528 #if VA_CHECK_VERSION(1, 2, 0)
530 pic->last_slice_param.rext = (VASliceParameterBufferHEVCRext) {
531 .slice_ext_flags.bits = {
532 .cu_chroma_qp_offset_enabled_flag = sh->cu_chroma_qp_offset_enabled_flag,
533 .use_integer_mv_flag = sh->use_integer_mv_flag,
535 .slice_act_y_qp_offset = sh->slice_act_y_qp_offset,
536 .slice_act_cb_qp_offset = sh->slice_act_cb_qp_offset,
537 .slice_act_cr_qp_offset = sh->slice_act_cr_qp_offset,
539 for (
i = 0;
i < 15 &&
i < sh->nb_refs[
L0];
i++) {
540 pic->last_slice_param.rext.luma_offset_l0[
i] = sh->luma_offset_l0[
i];
541 pic->last_slice_param.rext.ChromaOffsetL0[
i][0] = sh->chroma_offset_l0[
i][0];
542 pic->last_slice_param.rext.ChromaOffsetL0[
i][1] = sh->chroma_offset_l0[
i][1];
546 for (
i = 0;
i < 15 &&
i < sh->nb_refs[
L1];
i++) {
547 pic->last_slice_param.rext.luma_offset_l1[
i] = sh->luma_offset_l1[
i];
548 pic->last_slice_param.rext.ChromaOffsetL1[
i][0] = sh->chroma_offset_l1[
i][0];
549 pic->last_slice_param.rext.ChromaOffsetL1[
i][1] = sh->chroma_offset_l1[
i][1];
555 pic->last_buffer =
buffer;
556 pic->last_size =
size;
570 #define copy_field(name) h265_raw_ptl->general_ ## name = general_ptl->name
615 #if VA_CHECK_VERSION(1, 2, 0)
616 if (!strcmp(
profile->name,
"Main 12") ||
617 !strcmp(
profile->name,
"Main 12 Intra"))
618 return VAProfileHEVCMain12;
619 else if (!strcmp(
profile->name,
"Main 4:2:2 10") ||
620 !strcmp(
profile->name,
"Main 4:2:2 10 Intra"))
621 return VAProfileHEVCMain422_10;
622 else if (!strcmp(
profile->name,
"Main 4:2:2 12") ||
623 !strcmp(
profile->name,
"Main 4:2:2 12 Intra"))
624 return VAProfileHEVCMain422_12;
625 else if (!strcmp(
profile->name,
"Main 4:4:4") ||
626 !strcmp(
profile->name,
"Main 4:4:4 Intra"))
627 return VAProfileHEVCMain444;
628 else if (!strcmp(
profile->name,
"Main 4:4:4 10") ||
629 !strcmp(
profile->name,
"Main 4:4:4 10 Intra"))
630 return VAProfileHEVCMain444_10;
631 else if (!strcmp(
profile->name,
"Main 4:4:4 12") ||
632 !strcmp(
profile->name,
"Main 4:4:4 12 Intra"))
633 return VAProfileHEVCMain444_12;
634 else if (!strcmp(
profile->name,
"Screen-Extended Main"))
635 return VAProfileHEVCSccMain;
636 else if (!strcmp(
profile->name,
"Screen-Extended Main 10"))
637 return VAProfileHEVCSccMain10;
638 else if (!strcmp(
profile->name,
"Screen-Extended Main 4:4:4"))
639 return VAProfileHEVCSccMain444;
640 #if VA_CHECK_VERSION(1, 8, 0)
641 else if (!strcmp(
profile->name,
"Screen-Extended Main 4:4:4 10"))
642 return VAProfileHEVCSccMain444_10;
646 "not supported with this VA version.\n",
profile->name);
652 return VAProfileHEVCMain;
654 return VAProfileNone;
658 .
p.
name =
"hevc_vaapi",