FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vaapi_hevc.c
Go to the documentation of this file.
1 /*
2  * HEVC HW decode acceleration through VA API
3  *
4  * Copyright (C) 2015 Timo Rothenpieler <timo@rothenpieler.org>
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
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "vaapi_internal.h"
24 #include "hevc.h"
25 #include "mpegutils.h"
26 
27 /**
28  * @file
29  * This file implements the glue code between FFmpeg's and VA API's
30  * structures for HEVC decoding.
31  */
32 
33 typedef struct vaapi_hevc_frame_data {
34  VAPictureParameterBufferHEVC *pic_param;
35  VASliceParameterBufferHEVC *last_slice_param;
37 
38 /**
39  * Initialize an empty VA API picture.
40  *
41  * VA API requires a fixed-size reference picture array.
42  */
43 static void init_vaapi_pic(VAPictureHEVC *va_pic)
44 {
45  va_pic->picture_id = VA_INVALID_ID;
46  va_pic->flags = VA_PICTURE_HEVC_INVALID;
47  va_pic->pic_order_cnt = 0;
48 }
49 
50 static void fill_vaapi_pic(VAPictureHEVC *va_pic, const HEVCFrame *pic, int rps_type)
51 {
52  va_pic->picture_id = ff_vaapi_get_surface_id(pic->frame);
53  va_pic->pic_order_cnt = pic->poc;
54  va_pic->flags = rps_type;
55 
57  va_pic->flags |= VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
58 
59  if (pic->frame->interlaced_frame) {
60  va_pic->flags |= VA_PICTURE_HEVC_FIELD_PIC;
61 
62  if (!pic->frame->top_field_first) {
63  va_pic->flags |= VA_PICTURE_HEVC_BOTTOM_FIELD;
64  }
65  }
66 }
67 
68 static int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
69 {
70  VASurfaceID pic_surf = ff_vaapi_get_surface_id(pic->frame);
71  int i;
72 
73  for (i = 0; i < h->rps[ST_CURR_BEF].nb_refs; ++i) {
74  if (pic_surf == ff_vaapi_get_surface_id(h->rps[ST_CURR_BEF].ref[i]->frame))
75  return VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE;
76  }
77 
78  for (i = 0; i < h->rps[ST_CURR_AFT].nb_refs; ++i) {
79  if (pic_surf == ff_vaapi_get_surface_id(h->rps[ST_CURR_AFT].ref[i]->frame))
80  return VA_PICTURE_HEVC_RPS_ST_CURR_AFTER;
81  }
82 
83  for (i = 0; i < h->rps[LT_CURR].nb_refs; ++i) {
84  if (pic_surf == ff_vaapi_get_surface_id(h->rps[LT_CURR].ref[i]->frame))
85  return VA_PICTURE_HEVC_RPS_LT_CURR;
86  }
87 
88  return 0;
89 }
90 
91 static void fill_vaapi_ReferenceFrames(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
92 {
93  const HEVCFrame *current_picture = h->ref;
94  int i, j, rps_type;
95 
96  for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ReferenceFrames); i++) {
97  const HEVCFrame *frame = NULL;
98 
99  while (!frame && j < FF_ARRAY_ELEMS(h->DPB)) {
100  if (&h->DPB[j] != current_picture && (h->DPB[j].flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)))
101  frame = &h->DPB[j];
102  j++;
103  }
104 
105  init_vaapi_pic(&pp->ReferenceFrames[i]);
106 
107  if (frame) {
108  rps_type = find_frame_rps_type(h, frame);
109  fill_vaapi_pic(&pp->ReferenceFrames[i], frame, rps_type);
110  }
111  }
112 }
113 
115 {
117  VAPictureParameterBufferHEVC *pp = frame_data->pic_param;
118  uint8_t i;
119 
120  if (!frame)
121  return 0xff;
122 
123  for (i = 0; i < FF_ARRAY_ELEMS(pp->ReferenceFrames); ++i) {
124  VASurfaceID pid = pp->ReferenceFrames[i].picture_id;
125  int poc = pp->ReferenceFrames[i].pic_order_cnt;
126  if (pid != VA_INVALID_ID && pid == ff_vaapi_get_surface_id(frame->frame) && poc == frame->poc)
127  return i;
128  }
129 
130  return 0xff;
131 }
132 
133 static void fill_picture_parameters(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
134 {
135  int i;
136 
137  pp->pic_fields.value = 0;
138  pp->slice_parsing_fields.value = 0;
139 
140  fill_vaapi_pic(&pp->CurrPic, h->ref, 0);
142 
143  pp->pic_width_in_luma_samples = h->ps.sps->width;
144  pp->pic_height_in_luma_samples = h->ps.sps->height;
145 
146  pp->log2_min_luma_coding_block_size_minus3 = h->ps.sps->log2_min_cb_size - 3;
147 
148  pp->pic_fields.bits.chroma_format_idc = h->ps.sps->chroma_format_idc;
149 
150  pp->sps_max_dec_pic_buffering_minus1 = h->ps.sps->temporal_layer[h->ps.sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
151  pp->log2_diff_max_min_luma_coding_block_size = h->ps.sps->log2_diff_max_min_coding_block_size;
152  pp->log2_min_transform_block_size_minus2 = h->ps.sps->log2_min_tb_size - 2;
153  pp->log2_diff_max_min_transform_block_size = h->ps.sps->log2_max_trafo_size - h->ps.sps->log2_min_tb_size;
154  pp->max_transform_hierarchy_depth_inter = h->ps.sps->max_transform_hierarchy_depth_inter;
155  pp->max_transform_hierarchy_depth_intra = h->ps.sps->max_transform_hierarchy_depth_intra;
156  pp->num_short_term_ref_pic_sets = h->ps.sps->nb_st_rps;
157  pp->num_long_term_ref_pic_sps = h->ps.sps->num_long_term_ref_pics_sps;
158 
159  pp->num_ref_idx_l0_default_active_minus1 = h->ps.pps->num_ref_idx_l0_default_active - 1;
160  pp->num_ref_idx_l1_default_active_minus1 = h->ps.pps->num_ref_idx_l1_default_active - 1;
161  pp->init_qp_minus26 = h->ps.pps->pic_init_qp_minus26;
162 
163  pp->pps_cb_qp_offset = h->ps.pps->cb_qp_offset;
164  pp->pps_cr_qp_offset = h->ps.pps->cr_qp_offset;
165 
166  pp->pic_fields.bits.tiles_enabled_flag = h->ps.pps->tiles_enabled_flag;
167  pp->pic_fields.bits.separate_colour_plane_flag = h->ps.sps->separate_colour_plane_flag;
168  pp->pic_fields.bits.pcm_enabled_flag = h->ps.sps->pcm_enabled_flag;
169  pp->pic_fields.bits.scaling_list_enabled_flag = h->ps.sps->scaling_list_enable_flag;
170  pp->pic_fields.bits.transform_skip_enabled_flag = h->ps.pps->transform_skip_enabled_flag;
171  pp->pic_fields.bits.amp_enabled_flag = h->ps.sps->amp_enabled_flag;
172  pp->pic_fields.bits.strong_intra_smoothing_enabled_flag = h->ps.sps->sps_strong_intra_smoothing_enable_flag;
173  pp->pic_fields.bits.sign_data_hiding_enabled_flag = h->ps.pps->sign_data_hiding_flag;
174  pp->pic_fields.bits.constrained_intra_pred_flag = h->ps.pps->constrained_intra_pred_flag;
175  pp->pic_fields.bits.cu_qp_delta_enabled_flag = h->ps.pps->cu_qp_delta_enabled_flag;
176  pp->pic_fields.bits.weighted_pred_flag = h->ps.pps->weighted_pred_flag;
177  pp->pic_fields.bits.weighted_bipred_flag = h->ps.pps->weighted_bipred_flag;
178  pp->pic_fields.bits.transquant_bypass_enabled_flag = h->ps.pps->transquant_bypass_enable_flag;
179  pp->pic_fields.bits.entropy_coding_sync_enabled_flag = h->ps.pps->entropy_coding_sync_enabled_flag;
180  pp->pic_fields.bits.pps_loop_filter_across_slices_enabled_flag = h->ps.pps->seq_loop_filter_across_slices_enabled_flag;
181  pp->pic_fields.bits.loop_filter_across_tiles_enabled_flag = h->ps.pps->loop_filter_across_tiles_enabled_flag;
182 
183  pp->pic_fields.bits.pcm_loop_filter_disabled_flag = h->ps.sps->pcm.loop_filter_disable_flag;
184  pp->pcm_sample_bit_depth_luma_minus1 = h->ps.sps->pcm.bit_depth - 1;
185  pp->pcm_sample_bit_depth_chroma_minus1 = h->ps.sps->pcm.bit_depth_chroma - 1;
186  pp->log2_min_pcm_luma_coding_block_size_minus3 = h->ps.sps->pcm.log2_min_pcm_cb_size - 3;
187  pp->log2_diff_max_min_pcm_luma_coding_block_size = h->ps.sps->pcm.log2_max_pcm_cb_size - h->ps.sps->pcm.log2_min_pcm_cb_size;
188 
189  memset(pp->column_width_minus1, 0, sizeof(pp->column_width_minus1));
190  memset(pp->row_height_minus1, 0, sizeof(pp->row_height_minus1));
191 
192  if (h->ps.pps->tiles_enabled_flag) {
193  pp->num_tile_columns_minus1 = h->ps.pps->num_tile_columns - 1;
194  pp->num_tile_rows_minus1 = h->ps.pps->num_tile_rows - 1;
195 
196  for (i = 0; i < h->ps.pps->num_tile_columns; i++)
197  pp->column_width_minus1[i] = h->ps.pps->column_width[i] - 1;
198 
199  for (i = 0; i < h->ps.pps->num_tile_rows; i++)
200  pp->row_height_minus1[i] = h->ps.pps->row_height[i] - 1;
201  }
202 
203  pp->diff_cu_qp_delta_depth = h->ps.pps->diff_cu_qp_delta_depth;
204  pp->pps_beta_offset_div2 = h->ps.pps->beta_offset / 2;
205  pp->pps_tc_offset_div2 = h->ps.pps->tc_offset / 2;
206  pp->log2_parallel_merge_level_minus2 = h->ps.pps->log2_parallel_merge_level - 2;
207 
208  /* Different chroma/luma bit depths are currently not supported by ffmpeg. */
209  pp->bit_depth_luma_minus8 = h->ps.sps->bit_depth - 8;
210  pp->bit_depth_chroma_minus8 = h->ps.sps->bit_depth - 8;
211 
212  pp->slice_parsing_fields.bits.lists_modification_present_flag = h->ps.pps->lists_modification_present_flag;
213  pp->slice_parsing_fields.bits.long_term_ref_pics_present_flag = h->ps.sps->long_term_ref_pics_present_flag;
214  pp->slice_parsing_fields.bits.sps_temporal_mvp_enabled_flag = h->ps.sps->sps_temporal_mvp_enabled_flag;
215  pp->slice_parsing_fields.bits.cabac_init_present_flag = h->ps.pps->cabac_init_present_flag;
216  pp->slice_parsing_fields.bits.output_flag_present_flag = h->ps.pps->output_flag_present_flag;
217  pp->slice_parsing_fields.bits.dependent_slice_segments_enabled_flag = h->ps.pps->dependent_slice_segments_enabled_flag;
218  pp->slice_parsing_fields.bits.pps_slice_chroma_qp_offsets_present_flag = h->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag;
219  pp->slice_parsing_fields.bits.sample_adaptive_offset_enabled_flag = h->ps.sps->sao_enabled;
220  pp->slice_parsing_fields.bits.deblocking_filter_override_enabled_flag = h->ps.pps->deblocking_filter_override_enabled_flag;
221  pp->slice_parsing_fields.bits.pps_disable_deblocking_filter_flag = h->ps.pps->disable_dbf;
222  pp->slice_parsing_fields.bits.slice_segment_header_extension_present_flag = h->ps.pps->slice_header_extension_present_flag;
223 
224  pp->log2_max_pic_order_cnt_lsb_minus4 = h->ps.sps->log2_max_poc_lsb - 4;
225  pp->num_extra_slice_header_bits = h->ps.pps->num_extra_slice_header_bits;
226 
228  pp->slice_parsing_fields.bits.RapPicFlag = 1;
229  } else {
230  pp->slice_parsing_fields.bits.RapPicFlag = 0;
231  }
232 
233  if (IS_IDR(h)) {
234  pp->slice_parsing_fields.bits.IdrPicFlag = 1;
235  } else {
236  pp->slice_parsing_fields.bits.IdrPicFlag = 0;
237  }
238 
239  if (IS_IRAP(h)) {
240  pp->slice_parsing_fields.bits.IntraPicFlag = 1;
241  } else {
242  pp->slice_parsing_fields.bits.IntraPicFlag = 0;
243  }
244 
246  pp->st_rps_bits = h->sh.short_term_ref_pic_set_size;
247  } else {
248  pp->st_rps_bits = 0;
249  }
250 
251  /* TODO */
252  pp->pic_fields.bits.NoPicReorderingFlag = 0;
253  pp->pic_fields.bits.NoBiPredFlag = 0;
254 }
255 
256 
257 /** Initialize and start decoding a frame with VA API. */
259  av_unused const uint8_t *buffer,
260  av_unused uint32_t size)
261 {
262  HEVCContext * const h = avctx->priv_data;
263  FFVAContext * const vactx = ff_vaapi_get_context(avctx);
265  VAPictureParameterBufferHEVC *pic_param;
266  VAIQMatrixBufferHEVC *iq_matrix;
267  ScalingList const * scaling_list;
268  int i, j, pos;
269 
270  ff_dlog(avctx, "vaapi_hevc_start_frame()\n");
271 
272  vactx->slice_param_size = sizeof(VASliceParameterBufferHEVC);
273 
274  /* Fill in VAPictureParameterBufferHEVC. */
275  pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferHEVC));
276  if (!pic_param)
277  return -1;
278  fill_picture_parameters(h, pic_param);
279  frame_data->pic_param = pic_param;
280 
281  /* Fill in VAIQMatrixBufferHEVC. */
283  scaling_list = &h->ps.pps->scaling_list;
284  } else if (h->ps.sps->scaling_list_enable_flag) {
285  scaling_list = &h->ps.sps->scaling_list;
286  } else {
287  return 0;
288  }
289 
290  iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferHEVC));
291  if (!iq_matrix)
292  return -1;
293 
294  for (i = 0; i < 6; ++i) {
295  for (j = 0; j < 16; ++j) {
297  iq_matrix->ScalingList4x4[i][j] = scaling_list->sl[0][i][pos];
298  }
299  for (j = 0; j < 64; ++j) {
301  iq_matrix->ScalingList8x8[i][j] = scaling_list->sl[1][i][pos];
302  iq_matrix->ScalingList16x16[i][j] = scaling_list->sl[2][i][pos];
303  if (i < 2) {
304  iq_matrix->ScalingList32x32[i][j] = scaling_list->sl[3][i * 3][pos];
305  }
306  }
307  iq_matrix->ScalingListDC16x16[i] = scaling_list->sl_dc[0][i];
308  if (i < 2) {
309  iq_matrix->ScalingListDC32x32[i] = scaling_list->sl_dc[1][i * 3];
310  }
311  }
312 
313  return 0;
314 }
315 
316 /** End a hardware decoding based frame. */
318 {
319  FFVAContext * const vactx = ff_vaapi_get_context(avctx);
320  HEVCContext * const h = avctx->priv_data;
322  int ret;
323 
324  ff_dlog(avctx, "vaapi_hevc_end_frame()\n");
325 
326  frame_data->last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
327 
328  ret = ff_vaapi_commit_slices(vactx);
329  if (ret < 0)
330  goto finish;
331 
333  if (ret < 0)
334  goto finish;
335 
336 finish:
338  return ret;
339 }
340 
342  VASliceParameterBufferHEVC *slice_param,
343  SliceHeader * const sh)
344 {
345  int i;
346 
347  memset(slice_param->delta_luma_weight_l0, 0, sizeof(slice_param->delta_luma_weight_l0));
348  memset(slice_param->delta_luma_weight_l1, 0, sizeof(slice_param->delta_luma_weight_l1));
349  memset(slice_param->luma_offset_l0, 0, sizeof(slice_param->luma_offset_l0));
350  memset(slice_param->luma_offset_l1, 0, sizeof(slice_param->luma_offset_l1));
351  memset(slice_param->delta_chroma_weight_l0, 0, sizeof(slice_param->delta_chroma_weight_l0));
352  memset(slice_param->delta_chroma_weight_l1, 0, sizeof(slice_param->delta_chroma_weight_l1));
353  memset(slice_param->ChromaOffsetL0, 0, sizeof(slice_param->ChromaOffsetL0));
354  memset(slice_param->ChromaOffsetL1, 0, sizeof(slice_param->ChromaOffsetL1));
355 
356  slice_param->delta_chroma_log2_weight_denom = 0;
357  slice_param->luma_log2_weight_denom = 0;
358 
359  if ( sh->slice_type == I_SLICE
360  || (sh->slice_type == P_SLICE && !h->ps.pps->weighted_pred_flag)
361  || (sh->slice_type == B_SLICE && !h->ps.pps->weighted_bipred_flag)) {
362  return 0;
363  }
364 
365  slice_param->luma_log2_weight_denom = sh->luma_log2_weight_denom;
366 
367  if (h->ps.sps->chroma_format_idc) {
368  slice_param->delta_chroma_log2_weight_denom = sh->chroma_log2_weight_denom - sh->luma_log2_weight_denom;
369  }
370 
371  for (i = 0; i < 15 && i < sh->nb_refs[L0]; ++i) {
372  slice_param->delta_luma_weight_l0[i] = sh->luma_weight_l0[i] - (1 << sh->luma_log2_weight_denom);
373  slice_param->luma_offset_l0[i] = sh->luma_offset_l0[i];
374  slice_param->delta_chroma_weight_l0[i][0] = sh->chroma_weight_l0[i][0] - (1 << sh->chroma_log2_weight_denom);
375  slice_param->delta_chroma_weight_l0[i][1] = sh->chroma_weight_l0[i][1] - (1 << sh->chroma_log2_weight_denom);
376  slice_param->ChromaOffsetL0[i][0] = sh->chroma_offset_l0[i][0];
377  slice_param->ChromaOffsetL0[i][1] = sh->chroma_offset_l0[i][1];
378  }
379 
380  if (sh->slice_type == B_SLICE) {
381  for (i = 0; i < 15 && i < sh->nb_refs[L1]; ++i) {
382  slice_param->delta_luma_weight_l1[i] = sh->luma_weight_l1[i] - (1 << sh->luma_log2_weight_denom);
383  slice_param->luma_offset_l1[i] = sh->luma_offset_l1[i];
384  slice_param->delta_chroma_weight_l1[i][0] = sh->chroma_weight_l1[i][0] - (1 << sh->chroma_log2_weight_denom);
385  slice_param->delta_chroma_weight_l1[i][1] = sh->chroma_weight_l1[i][1] - (1 << sh->chroma_log2_weight_denom);
386  slice_param->ChromaOffsetL1[i][0] = sh->chroma_offset_l1[i][0];
387  slice_param->ChromaOffsetL1[i][1] = sh->chroma_offset_l1[i][1];
388  }
389  }
390 
391  return 0;
392 }
393 
394 /** Decode the given hevc slice with VA API. */
396  const uint8_t *buffer,
397  uint32_t size)
398 {
399  FFVAContext * const vactx = ff_vaapi_get_context(avctx);
400  HEVCContext * const h = avctx->priv_data;
402  SliceHeader * const sh = &h->sh;
403  VASliceParameterBufferHEVC *slice_param;
404  int i, list_idx;
405  uint8_t nb_list = sh->slice_type == B_SLICE ? 2 : 1;
406 
407  if (sh->slice_type == I_SLICE)
408  nb_list = 0;
409 
410  ff_dlog(avctx, "vaapi_hevc_decode_slice(): buffer %p, size %d\n", buffer, size);
411 
412  /* Fill in VASliceParameterBufferH264. */
413  slice_param = (VASliceParameterBufferHEVC *)ff_vaapi_alloc_slice(vactx, buffer, size);
414  if (!slice_param)
415  return -1;
416 
417  frame_data->last_slice_param = slice_param;
418 
419  /* The base structure changed, so this has to be re-set in order to be valid on every byte order. */
420  slice_param->slice_data_flag = VA_SLICE_DATA_FLAG_ALL;
421 
422  /* Add 1 to the bits count here to account for the byte_alignment bit, which allways is at least one bit and not accounted for otherwise. */
423  slice_param->slice_data_byte_offset = (get_bits_count(&h->HEVClc->gb) + 1 + 7) / 8;
424 
425  slice_param->slice_segment_address = sh->slice_segment_addr;
426 
427  slice_param->LongSliceFlags.value = 0;
428  slice_param->LongSliceFlags.fields.dependent_slice_segment_flag = sh->dependent_slice_segment_flag;
429  slice_param->LongSliceFlags.fields.slice_type = sh->slice_type;
430  slice_param->LongSliceFlags.fields.color_plane_id = sh->colour_plane_id;
431  slice_param->LongSliceFlags.fields.mvd_l1_zero_flag = sh->mvd_l1_zero_flag;
432  slice_param->LongSliceFlags.fields.cabac_init_flag = sh->cabac_init_flag;
433  slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag = sh->slice_temporal_mvp_enabled_flag;
434  slice_param->LongSliceFlags.fields.slice_deblocking_filter_disabled_flag = sh->disable_deblocking_filter_flag;
435  slice_param->LongSliceFlags.fields.collocated_from_l0_flag = sh->collocated_list == L0 ? 1 : 0;
436  slice_param->LongSliceFlags.fields.slice_loop_filter_across_slices_enabled_flag = sh->slice_loop_filter_across_slices_enabled_flag;
437 
438  slice_param->LongSliceFlags.fields.slice_sao_luma_flag = sh->slice_sample_adaptive_offset_flag[0];
439  if (h->ps.sps->chroma_format_idc) {
440  slice_param->LongSliceFlags.fields.slice_sao_chroma_flag = sh->slice_sample_adaptive_offset_flag[1];
441  }
442 
444  slice_param->collocated_ref_idx = sh->collocated_ref_idx;
445  } else {
446  slice_param->collocated_ref_idx = 0xFF;
447  }
448 
449  slice_param->slice_qp_delta = sh->slice_qp_delta;
450  slice_param->slice_cb_qp_offset = sh->slice_cb_qp_offset;
451  slice_param->slice_cr_qp_offset = sh->slice_cr_qp_offset;
452  slice_param->slice_beta_offset_div2 = sh->beta_offset / 2;
453  slice_param->slice_tc_offset_div2 = sh->tc_offset / 2;
454 
455  if (sh->slice_type == I_SLICE) {
456  slice_param->five_minus_max_num_merge_cand = 0;
457  } else {
458  slice_param->five_minus_max_num_merge_cand = 5 - sh->max_num_merge_cand;
459  }
460 
461  slice_param->num_ref_idx_l0_active_minus1 = sh->nb_refs[L0] ? sh->nb_refs[L0] - 1 : 0;
462  slice_param->num_ref_idx_l1_active_minus1 = sh->nb_refs[L1] ? sh->nb_refs[L1] - 1 : 0;
463 
464  memset(slice_param->RefPicList, 0xFF, sizeof(slice_param->RefPicList));
465 
466  /* h->ref->refPicList is updated befor calling each slice */
467  for (list_idx = 0; list_idx < nb_list; ++list_idx) {
468  RefPicList *rpl = &h->ref->refPicList[list_idx];
469 
470  for (i = 0; i < rpl->nb_refs; ++i) {
471  slice_param->RefPicList[list_idx][i] = get_ref_pic_index(h, rpl->ref[i]);
472  }
473  }
474 
475  return fill_pred_weight_table(h, slice_param, sh);
476 }
477 
479  .name = "hevc_vaapi",
480  .type = AVMEDIA_TYPE_VIDEO,
481  .id = AV_CODEC_ID_HEVC,
482  .pix_fmt = AV_PIX_FMT_VAAPI,
483  .start_frame = vaapi_hevc_start_frame,
484  .end_frame = vaapi_hevc_end_frame,
485  .decode_slice = vaapi_hevc_decode_slice,
486  .init = ff_vaapi_context_init,
487  .uninit = ff_vaapi_context_fini,
488  .priv_data_size = sizeof(FFVAContext),
489  .frame_priv_data_size = sizeof(vaapi_hevc_frame_data),
490 };
VASliceParameterBufferBase * ff_vaapi_alloc_slice(FFVAContext *vactx, const uint8_t *buffer, uint32_t size)
Allocate a new slice descriptor for the input slice.
Definition: vaapi.c:178
const HEVCPPS * pps
Definition: hevc.h:579
AVFrame * frame
Definition: hevc.h:729
#define NULL
Definition: coverity.c:32
unsigned int log2_min_cb_size
Definition: hevc.h:454
int ff_vaapi_context_fini(AVCodecContext *avctx)
Common AVHWAccel.uninit() implementation.
Definition: vaapi.c:66
int short_term_ref_pic_set_sps_flag
Definition: hevc.h:600
HEVCFrame * ref
Definition: hevc.h:840
struct HEVCSPS::@68 pcm
static int vaapi_hevc_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Initialize and start decoding a frame with VA API.
Definition: vaapi_hevc.c:258
int ff_vaapi_render_picture(FFVAContext *vactx, VASurfaceID surface)
Definition: vaapi.c:71
int max_dec_pic_buffering
Definition: hevc.h:422
static void fill_vaapi_pic(VAPictureHEVC *va_pic, const HEVCFrame *pic, int rps_type)
Definition: vaapi_hevc.c:50
unsigned int * row_height
RowHeight.
Definition: hevc.h:555
void * hwaccel_picture_private
Definition: hevc.h:745
int pic_init_qp_minus26
Definition: hevc.h:503
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: hevc_data.c:25
uint8_t weighted_bipred_flag
Definition: hevc.h:515
uint8_t seq_loop_filter_across_slices_enabled_flag
Definition: hevc.h:528
uint8_t cabac_init_present_flag
Definition: hevc.h:499
int16_t chroma_offset_l1[16][2]
Definition: hevc.h:654
static void init_vaapi_pic(VAPictureHEVC *va_pic)
Initialize an empty VA API picture.
Definition: vaapi_hevc.c:43
HEVCParamSets ps
Definition: hevc.h:827
int num_ref_idx_l0_default_active
num_ref_idx_l0_default_active_minus1 + 1
Definition: hevc.h:501
struct HEVCFrame * ref[MAX_REFS]
Definition: hevc.h:292
uint8_t dependent_slice_segment_flag
Definition: hevc.h:595
int width
Definition: hevc.h:472
uint8_t entropy_coding_sync_enabled_flag
Definition: hevc.h:521
int log2_parallel_merge_level
log2_parallel_merge_level_minus2 + 2
Definition: hevc.h:540
int nb_refs
Definition: hevc.h:295
int chroma_format_idc
Definition: hevc.h:404
uint8_t disable_dbf
Definition: hevc.h:532
unsigned int log2_max_trafo_size
Definition: hevc.h:457
unsigned int slice_segment_addr
address (in raster order) of the first block in the current slice
Definition: hevc.h:586
uint8_t
static void fill_vaapi_ReferenceFrames(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
Definition: vaapi_hevc.c:91
unsigned int slice_param_size
Size of a slice parameter element.
int num_ref_idx_l1_default_active
num_ref_idx_l1_default_active_minus1 + 1
Definition: hevc.h:502
unsigned int log2_min_pcm_cb_size
Definition: hevc.h:447
static AVFrame * frame
uint8_t scaling_list_data_present_flag
Definition: hevc.h:536
static void finish(void)
Definition: movenc.c:344
uint8_t bit_depth_chroma
Definition: hevc.h:446
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:199
#define ff_dlog(a,...)
void * ff_vaapi_alloc_iq_matrix(FFVAContext *vactx, unsigned int size)
Allocate a new IQ matrix buffer.
Definition: vaapi.c:168
static FFVAContext * ff_vaapi_get_context(AVCodecContext *avctx)
Extract vaapi_context from an AVCodecContext.
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:322
uint8_t loop_filter_disable_flag
Definition: hevc.h:449
ptrdiff_t size
Definition: opengl_enc.c:101
uint8_t transquant_bypass_enable_flag
Definition: hevc.h:517
static int vaapi_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Decode the given hevc slice with VA API.
Definition: vaapi_hevc.c:395
#define HEVC_FRAME_FLAG_LONG_REF
Definition: hevc.h:725
uint8_t colour_plane_id
RPS coded in the slice header itself is stored here.
Definition: hevc.h:597
Definition: hevc.h:126
unsigned int log2_max_poc_lsb
Definition: hevc.h:417
static int vaapi_hevc_end_frame(AVCodecContext *avctx)
End a hardware decoding based frame.
Definition: vaapi_hevc.c:317
void ff_vaapi_common_end_frame(AVCodecContext *avctx)
Common AVHWAccel.end_frame() implementation.
Definition: vaapi.c:209
int ff_vaapi_context_init(AVCodecContext *avctx)
Common AVHWAccel.init() implementation.
Definition: vaapi.c:45
uint8_t amp_enabled_flag
Definition: hevc.h:436
RefPicList * refPicList
Definition: hevc.h:732
int16_t luma_offset_l0[16]
Definition: hevc.h:650
int tc_offset
tc_offset_div2 * 2
Definition: hevc.h:631
const ShortTermRPS * short_term_rps
Definition: hevc.h:603
static int fill_pred_weight_table(HEVCContext *const h, VASliceParameterBufferHEVC *slice_param, SliceHeader *const sh)
Definition: vaapi_hevc.c:341
uint8_t slice_temporal_mvp_enabled_flag
Definition: hevc.h:610
uint8_t tiles_enabled_flag
Definition: hevc.h:520
int16_t luma_weight_l0[16]
Definition: hevc.h:645
int slice_qp_delta
Definition: hevc.h:624
const HEVCSPS * sps
Definition: hevc.h:578
uint8_t lists_modification_present_flag
Definition: hevc.h:539
int beta_offset
beta_offset_div2 * 2
Definition: hevc.h:630
#define HEVC_FRAME_FLAG_SHORT_REF
Definition: hevc.h:724
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3726
int max_transform_hierarchy_depth_inter
Definition: hevc.h:461
#define IS_IDR(s)
Definition: hevc.h:86
int slice_cr_qp_offset
Definition: hevc.h:626
int num_tile_columns
num_tile_columns_minus1 + 1
Definition: hevc.h:523
static VASurfaceID ff_vaapi_get_surface_id(AVFrame *pic)
Extract VASurfaceID from an AVFrame.
uint8_t cu_qp_delta_enabled_flag
Definition: hevc.h:508
static void fill_picture_parameters(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
Definition: vaapi_hevc.c:133
Definition: hevc.h:134
int16_t chroma_weight_l0[16][2]
Definition: hevc.h:646
uint8_t sl_dc[2][6]
Definition: hevc.h:399
uint8_t sign_data_hiding_flag
Definition: hevc.h:497
int height
Definition: hevc.h:473
uint8_t output_flag_present_flag
Definition: hevc.h:516
int16_t luma_offset_l1[16]
Definition: hevc.h:653
int16_t chroma_offset_l0[16][2]
Definition: hevc.h:651
#define FF_ARRAY_ELEMS(a)
uint8_t constrained_intra_pred_flag
Definition: hevc.h:505
uint8_t sl[4][6][64]
Definition: hevc.h:398
uint8_t pic_slice_level_chroma_qp_offsets_present_flag
Definition: hevc.h:513
Definition: hevc.h:133
HEVCFrame DPB[32]
Definition: hevc.h:841
int slice_cb_qp_offset
Definition: hevc.h:625
uint8_t transform_skip_enabled_flag
Definition: hevc.h:506
int short_term_ref_pic_set_size
Definition: hevc.h:601
#define IS_IRAP(s)
Definition: hevc.h:89
VAPictureParameterBufferHEVC * pic_param
Definition: vaapi_hevc.c:34
int max_sub_layers
Definition: hevc.h:420
ScalingList scaling_list
Definition: hevc.h:537
main external API structure.
Definition: avcodec.h:1676
uint8_t sao_enabled
Definition: hevc.h:437
int num_extra_slice_header_bits
Definition: hevc.h:541
uint8_t loop_filter_across_tiles_enabled_flag
Definition: hevc.h:526
static uint8_t get_ref_pic_index(const HEVCContext *h, const HEVCFrame *frame)
Definition: vaapi_hevc.c:114
uint8_t num_long_term_ref_pics_sps
Definition: hevc.h:442
uint8_t sps_temporal_mvp_enabled_flag
Definition: hevc.h:451
unsigned int nb_st_rps
Definition: hevc.h:433
uint8_t cabac_init_flag
Definition: hevc.h:617
int num_tile_rows
num_tile_rows_minus1 + 1
Definition: hevc.h:524
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: hevc_data.c:58
int poc
Definition: hevc.h:735
int ff_vaapi_commit_slices(FFVAContext *vactx)
Definition: vaapi.c:111
unsigned int max_num_merge_cand
5 - 5_minus_max_num_merge_cand
Definition: hevc.h:633
GetBitContext gb
Definition: hevc.h:766
static int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
Definition: vaapi_hevc.c:68
unsigned int log2_min_tb_size
Definition: hevc.h:456
#define L0
Definition: hevc.h:68
enum NALUnitType nal_unit_type
Definition: hevc.h:838
uint8_t scaling_list_enable_flag
Definition: hevc.h:430
void * ff_vaapi_alloc_pic_param(FFVAContext *vactx, unsigned int size)
Allocate a new picture parameter buffer.
Definition: vaapi.c:163
int16_t luma_weight_l1[16]
Definition: hevc.h:648
int16_t chroma_log2_weight_denom
Definition: hevc.h:643
int tc_offset
tc_offset_div2 * 2
Definition: hevc.h:534
uint8_t flags
A combination of HEVC_FRAME_FLAG_*.
Definition: hevc.h:756
struct HEVCSPS::@67 temporal_layer[MAX_SUB_LAYERS]
HEVCLocalContext * HEVClc
Definition: hevc.h:809
int cr_qp_offset
Definition: hevc.h:512
ScalingList scaling_list
Definition: hevc.h:431
unsigned int log2_diff_max_min_coding_block_size
Definition: hevc.h:455
unsigned int log2_max_pcm_cb_size
Definition: hevc.h:448
int max_transform_hierarchy_depth_intra
Definition: hevc.h:462
uint8_t weighted_pred_flag
Definition: hevc.h:514
unsigned int nb_refs[2]
Definition: hevc.h:612
uint8_t disable_deblocking_filter_flag
slice_header_disable_deblocking_filter_flag
Definition: hevc.h:618
unsigned int * column_width
ColumnWidth.
Definition: hevc.h:554
uint8_t slice_header_extension_present_flag
Definition: hevc.h:542
uint8_t collocated_list
Definition: hevc.h:620
uint8_t slice_loop_filter_across_slices_enabled_flag
Definition: hevc.h:619
void * priv_data
Definition: avcodec.h:1718
RefPicList rps[5]
Definition: hevc.h:833
uint8_t sps_strong_intra_smoothing_enable_flag
Definition: hevc.h:452
unsigned int collocated_ref_idx
Definition: hevc.h:622
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:327
uint8_t luma_log2_weight_denom
Definition: hevc.h:642
int16_t chroma_weight_l1[16][2]
Definition: hevc.h:647
uint8_t long_term_ref_pics_present_flag
Definition: hevc.h:439
Definition: hevc.h:132
AVHWAccel ff_hevc_vaapi_hwaccel
Definition: vaapi_hevc.c:478
int diff_cu_qp_delta_depth
Definition: hevc.h:509
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: hevc_data.c:39
int cb_qp_offset
Definition: hevc.h:511
uint8_t deblocking_filter_override_enabled_flag
Definition: hevc.h:531
int bit_depth
Definition: hevc.h:413
enum SliceType slice_type
Definition: hevc.h:590
int beta_offset
beta_offset_div2 * 2
Definition: hevc.h:533
#define L1
Definition: hevc.h:69
SliceHeader sh
Definition: hevc.h:835
int pcm_enabled_flag
Definition: hevc.h:418
uint8_t mvd_l1_zero_flag
Definition: hevc.h:615
VASliceParameterBufferHEVC * last_slice_param
Definition: vaapi_hevc.c:35
for(j=16;j >0;--j)
uint8_t separate_colour_plane_flag
output (i.e. cropped) values
Definition: hevc.h:405
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: hevc_data.c:32
GLuint buffer
Definition: opengl_enc.c:102
#define av_unused
Definition: attributes.h:126
uint8_t slice_sample_adaptive_offset_flag[3]
Definition: hevc.h:614
uint8_t dependent_slice_segments_enabled_flag
Definition: hevc.h:519