FFmpeg
hevcdec.c
Go to the documentation of this file.
1 /*
2  * HEVC video Decoder
3  *
4  * Copyright (C) 2012 - 2013 Guillaume Martres
5  * Copyright (C) 2012 - 2013 Mickael Raulet
6  * Copyright (C) 2012 - 2013 Gildas Cocherel
7  * Copyright (C) 2012 - 2013 Wassim Hamidouche
8  *
9  * This file is part of FFmpeg.
10  *
11  * FFmpeg is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * FFmpeg is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with FFmpeg; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25 
26 #include "config_components.h"
27 
28 #include "libavutil/attributes.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/common.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/md5.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/stereo3d.h"
39 #include "libavutil/tdrdi.h"
40 #include "libavutil/timecode.h"
41 
42 #include "aom_film_grain.h"
43 #include "bswapdsp.h"
44 #include "cabac_functions.h"
45 #include "codec_internal.h"
46 #include "decode.h"
47 #include "golomb.h"
48 #include "h274.h"
49 #include "hevc.h"
50 #include "parse.h"
51 #include "hevcdec.h"
52 #include "hwaccel_internal.h"
53 #include "hwconfig.h"
54 #include "internal.h"
55 #include "profiles.h"
56 #include "progressframe.h"
57 #include "libavutil/refstruct.h"
58 #include "thread.h"
59 #include "threadprogress.h"
60 
61 static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 };
62 
63 /**
64  * NOTE: Each function hls_foo correspond to the function foo in the
65  * specification (HLS stands for High Level Syntax).
66  */
67 
68 /**
69  * Section 5.7
70  */
71 
72 /* free everything allocated by pic_arrays_init() */
74 {
75  av_freep(&l->sao);
76  av_freep(&l->deblock);
77 
78  av_freep(&l->skip_flag);
80 
81  av_freep(&l->tab_ipm);
82  av_freep(&l->cbf_luma);
83  av_freep(&l->is_pcm);
84 
85  av_freep(&l->qp_y_tab);
88 
90  av_freep(&l->vertical_bs);
91 
92  for (int i = 0; i < 3; i++) {
95  }
96 
99 }
100 
101 /* allocate arrays that depend on frame dimensions */
103 {
104  int log2_min_cb_size = sps->log2_min_cb_size;
105  int width = sps->width;
106  int height = sps->height;
107  int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
108  ((height >> log2_min_cb_size) + 1);
109  int ctb_count = sps->ctb_width * sps->ctb_height;
110  int min_pu_size = sps->min_pu_width * sps->min_pu_height;
111 
112  l->bs_width = (width >> 2) + 1;
113  l->bs_height = (height >> 2) + 1;
114 
115  l->sao = av_calloc(ctb_count, sizeof(*l->sao));
116  l->deblock = av_calloc(ctb_count, sizeof(*l->deblock));
117  if (!l->sao || !l->deblock)
118  goto fail;
119 
120  l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
121  l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
122  if (!l->skip_flag || !l->tab_ct_depth)
123  goto fail;
124 
125  l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
126  l->tab_ipm = av_mallocz(min_pu_size);
127  l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
128  if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm)
129  goto fail;
130 
131  l->filter_slice_edges = av_mallocz(ctb_count);
132  l->tab_slice_address = av_malloc_array(pic_size_in_ctb,
133  sizeof(*l->tab_slice_address));
134  l->qp_y_tab = av_calloc(pic_size_in_ctb,
135  sizeof(*l->qp_y_tab));
136  if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address)
137  goto fail;
138 
141  if (!l->horizontal_bs || !l->vertical_bs)
142  goto fail;
143 
144  l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
145  l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
146  if (!l->tab_mvf_pool || !l->rpl_tab_pool)
147  goto fail;
148 
149  if (sps->sao_enabled) {
150  int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
151 
152  for (int c_idx = 0; c_idx < c_count; c_idx++) {
153  int w = sps->width >> sps->hshift[c_idx];
154  int h = sps->height >> sps->vshift[c_idx];
155  l->sao_pixel_buffer_h[c_idx] =
156  av_mallocz((w * 2 * sps->ctb_height) <<
157  sps->pixel_shift);
158  l->sao_pixel_buffer_v[c_idx] =
159  av_mallocz((h * 2 * sps->ctb_width) <<
160  sps->pixel_shift);
161  if (!l->sao_pixel_buffer_h[c_idx] ||
162  !l->sao_pixel_buffer_v[c_idx])
163  goto fail;
164  }
165  }
166 
167  return 0;
168 
169 fail:
170  pic_arrays_free(l);
171  return AVERROR(ENOMEM);
172 }
173 
174 static int pred_weight_table(SliceHeader *sh, void *logctx,
175  const HEVCSPS *sps, GetBitContext *gb)
176 {
177  int i = 0;
178  int j = 0;
179  int luma_log2_weight_denom;
180  unsigned luma_weight_flags, chroma_weight_flags;
181 
182  luma_log2_weight_denom = get_ue_golomb_long(gb);
183  if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
184  av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
185  return AVERROR_INVALIDDATA;
186  }
187  sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
188  if (sps->chroma_format_idc != 0) {
189  int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
190  if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
191  av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
192  return AVERROR_INVALIDDATA;
193  }
194  sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
195  }
196 
197  luma_weight_flags = get_bits(gb, sh->nb_refs[L0]);
198  chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
199  for (i = 0; i < sh->nb_refs[L0]; i++) {
200  unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
201 
202  if (luma_weight_flags & flag_bit) {
203  int delta_luma_weight_l0 = get_se_golomb(gb);
204  if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
205  return AVERROR_INVALIDDATA;
206  sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
207  sh->luma_offset_l0[i] = get_se_golomb(gb);
208  } else {
209  sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
210  sh->luma_offset_l0[i] = 0;
211  }
212  if (chroma_weight_flags & flag_bit) {
213  for (j = 0; j < 2; j++) {
214  int delta_chroma_weight_l0 = get_se_golomb(gb);
215  int delta_chroma_offset_l0 = get_se_golomb(gb);
216 
217  if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
218  || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) {
219  return AVERROR_INVALIDDATA;
220  }
221 
222  sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
223  sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
224  >> sh->chroma_log2_weight_denom) + 128), -128, 127);
225  }
226  } else {
227  sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
228  sh->chroma_offset_l0[i][0] = 0;
229  sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
230  sh->chroma_offset_l0[i][1] = 0;
231  }
232  }
233  if (sh->slice_type == HEVC_SLICE_B) {
234  luma_weight_flags = get_bits(gb, sh->nb_refs[L1]);
235  chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0;
236  for (i = 0; i < sh->nb_refs[L1]; i++) {
237  unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
238 
239  if (luma_weight_flags & flag_bit) {
240  int delta_luma_weight_l1 = get_se_golomb(gb);
241  if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
242  return AVERROR_INVALIDDATA;
243  sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
244  sh->luma_offset_l1[i] = get_se_golomb(gb);
245  } else {
246  sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
247  sh->luma_offset_l1[i] = 0;
248  }
249  if (chroma_weight_flags & flag_bit) {
250  for (j = 0; j < 2; j++) {
251  int delta_chroma_weight_l1 = get_se_golomb(gb);
252  int delta_chroma_offset_l1 = get_se_golomb(gb);
253 
254  if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
255  || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) {
256  return AVERROR_INVALIDDATA;
257  }
258 
259  sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
260  sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
261  >> sh->chroma_log2_weight_denom) + 128), -128, 127);
262  }
263  } else {
264  sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
265  sh->chroma_offset_l1[i][0] = 0;
266  sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
267  sh->chroma_offset_l1[i][1] = 0;
268  }
269  }
270  }
271  return 0;
272 }
273 
274 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
275  GetBitContext *gb, int cur_poc, int poc_lsb)
276 {
277  int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
278  int prev_delta_msb = 0;
279  unsigned int nb_sps = 0, nb_sh;
280  int i;
281 
282  rps->nb_refs = 0;
283  if (!sps->long_term_ref_pics_present)
284  return 0;
285 
286  if (sps->num_long_term_ref_pics_sps > 0)
287  nb_sps = get_ue_golomb_long(gb);
288  nb_sh = get_ue_golomb_long(gb);
289 
290  if (nb_sps > sps->num_long_term_ref_pics_sps)
291  return AVERROR_INVALIDDATA;
292  if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc))
293  return AVERROR_INVALIDDATA;
294 
295  rps->nb_refs = nb_sh + nb_sps;
296 
297  for (i = 0; i < rps->nb_refs; i++) {
298 
299  if (i < nb_sps) {
300  uint8_t lt_idx_sps = 0;
301 
302  if (sps->num_long_term_ref_pics_sps > 1)
303  lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
304 
305  rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
306  rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps));
307  } else {
308  rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
309  rps->used[i] = get_bits1(gb);
310  }
311 
312  rps->poc_msb_present[i] = get_bits1(gb);
313  if (rps->poc_msb_present[i]) {
315  int64_t poc;
316 
317  if (i && i != nb_sps)
318  delta += prev_delta_msb;
319 
320  poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
321  if (poc != (int32_t)poc)
322  return AVERROR_INVALIDDATA;
323  rps->poc[i] = poc;
324  prev_delta_msb = delta;
325  }
326  }
327 
328  return 0;
329 }
330 
332 {
333  AVCodecContext *avctx = s->avctx;
334  const HEVCVPS *vps = sps->vps;
335  const HEVCWindow *ow = &sps->output_window;
336  unsigned int num = 0, den = 0;
337 
338  avctx->pix_fmt = sps->pix_fmt;
339  avctx->coded_width = sps->width;
340  avctx->coded_height = sps->height;
341  avctx->width = sps->width - ow->left_offset - ow->right_offset;
342  avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
343  avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
344  avctx->profile = sps->ptl.general_ptl.profile_idc;
345  avctx->level = sps->ptl.general_ptl.level_idc;
346 
347  ff_set_sar(avctx, sps->vui.common.sar);
348 
349  if (sps->vui.common.video_signal_type_present_flag)
350  avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG
352  else
353  avctx->color_range = AVCOL_RANGE_MPEG;
354 
355  if (sps->vui.common.colour_description_present_flag) {
356  avctx->color_primaries = sps->vui.common.colour_primaries;
357  avctx->color_trc = sps->vui.common.transfer_characteristics;
358  avctx->colorspace = sps->vui.common.matrix_coeffs;
359  } else {
363  }
364 
366  if (sps->chroma_format_idc == 1) {
367  if (sps->vui.common.chroma_loc_info_present_flag) {
368  if (sps->vui.common.chroma_sample_loc_type_top_field <= 5)
369  avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1;
370  } else
372  }
373 
374  if (vps->vps_timing_info_present_flag) {
375  num = vps->vps_num_units_in_tick;
376  den = vps->vps_time_scale;
377  } else if (sps->vui.vui_timing_info_present_flag) {
378  num = sps->vui.vui_num_units_in_tick;
379  den = sps->vui.vui_time_scale;
380  }
381 
382  if (num > 0 && den > 0)
383  av_reduce(&avctx->framerate.den, &avctx->framerate.num,
384  num, den, 1 << 30);
385 }
386 
388 {
389  AVCodecContext *avctx = s->avctx;
390 
391 #if FF_API_CODEC_PROPS
393  if (s->sei.common.a53_caption.buf_ref)
394  s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
396 #endif
397 
398  if (s->sei.common.alternative_transfer.present &&
399  av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
400  s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
401  avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
402  }
403 
404 #if FF_API_CODEC_PROPS
406  if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
407  s->sei.common.aom_film_grain.enable)
410 #endif
411 
412  return 0;
413 }
414 
416 {
417  const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
418 
419  av_freep(&s->view_ids_available);
420  s->nb_view_ids_available = 0;
421  av_freep(&s->view_pos_available);
422  s->nb_view_pos_available = 0;
423 
424  // don't export anything in the trivial case (1 layer, view id=0)
425  if (vps->nb_layers < 2 && !vps->view_id[0])
426  return 0;
427 
428  s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available));
429  if (!s->view_ids_available)
430  return AVERROR(ENOMEM);
431 
432  if (tdrdi->num_ref_displays) {
433  s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available));
434  if (!s->view_pos_available)
435  return AVERROR(ENOMEM);
436  }
437 
438  for (int i = 0; i < vps->nb_layers; i++) {
439  s->view_ids_available[i] = vps->view_id[i];
440 
441  if (s->view_pos_available) {
442  s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ?
444  vps->view_id[i] == tdrdi->right_view_id[0] ?
446  }
447  }
448  s->nb_view_ids_available = vps->nb_layers;
449  s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0;
450 
451  return 0;
452 }
453 
455 {
456  const HEVCVPS *vps = s->vps;
457  int ret = 0;
458 
459  if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
460  return 0;
461 
462  /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
463  * than alpha cannot reach here.
464  */
465  ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
466 
467  av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
468  ret ? "is" : "not");
469 
470  return ret;
471 }
472 
474 {
475  unsigned layers_active_output = 0, highest_layer;
476 
477  s->layers_active_output = 1;
478  s->layers_active_decode = 1;
479 
480  if (ff_hevc_is_alpha_video(s)) {
481  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
482 
483  if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
484  return 0;
485 
486  s->layers_active_decode = (1 << vps->nb_layers) - 1;
487  s->layers_active_output = 1;
488 
489  return 0;
490  }
491 
492  // nothing requested - decode base layer only
493  if (!s->nb_view_ids)
494  return 0;
495 
496  if (s->nb_view_ids == 1 && s->view_ids[0] == -1) {
497  layers_active_output = (1 << vps->nb_layers) - 1;
498  } else {
499  for (int i = 0; i < s->nb_view_ids; i++) {
500  int view_id = s->view_ids[i];
501  int layer_idx = -1;
502 
503  if (view_id < 0) {
504  av_log(s->avctx, AV_LOG_ERROR,
505  "Invalid view ID requested: %d\n", view_id);
506  return AVERROR(EINVAL);
507  }
508 
509  for (int j = 0; j < vps->nb_layers; j++) {
510  if (vps->view_id[j] == view_id) {
511  layer_idx = j;
512  break;
513  }
514  }
515  if (layer_idx < 0) {
516  av_log(s->avctx, AV_LOG_ERROR,
517  "View ID %d not present in VPS\n", view_id);
518  return AVERROR(EINVAL);
519  }
520  layers_active_output |= 1 << layer_idx;
521  }
522  }
523 
524  if (!layers_active_output) {
525  av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n");
526  return AVERROR_BUG;
527  }
528 
529  highest_layer = ff_log2(layers_active_output);
530  if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) {
531  av_log(s->avctx, AV_LOG_ERROR,
532  "Too many layers requested: %u\n", layers_active_output);
533  return AVERROR(EINVAL);
534  }
535 
536  /* Assume a higher layer depends on all the lower ones.
537  * This is enforced in VPS parsing currently, this logic will need
538  * to be changed if we want to support more complex dependency structures.
539  */
540  s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
541  s->layers_active_output = layers_active_output;
542 
543  av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n",
544  s->layers_active_decode, s->layers_active_output);
545 
546  return 0;
547 }
548 
550  enum AVPixelFormat pix_fmt)
551 {
552  switch (pix_fmt) {
553  case AV_PIX_FMT_YUV420P:
554  case AV_PIX_FMT_YUVJ420P:
555  return AV_PIX_FMT_YUVA420P;
557  return AV_PIX_FMT_YUVA420P10;
558  case AV_PIX_FMT_YUV444P:
559  return AV_PIX_FMT_YUVA444P;
560  case AV_PIX_FMT_YUV422P:
561  return AV_PIX_FMT_YUVA422P;
565  return AV_PIX_FMT_YUVA444P10;
567  return AV_PIX_FMT_YUVA444P12;
569  return AV_PIX_FMT_YUVA422P12;
570  default:
571  av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
573  return AV_PIX_FMT_NONE;
574  }
575 }
576 
578 {
579 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
580  CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
581  CONFIG_HEVC_D3D12VA_HWACCEL + \
582  CONFIG_HEVC_NVDEC_HWACCEL + \
583  CONFIG_HEVC_VAAPI_HWACCEL + \
584  CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
585  CONFIG_HEVC_VDPAU_HWACCEL + \
586  CONFIG_HEVC_VULKAN_HWACCEL)
587  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
588  enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
589  int ret;
590 
592  alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
593 
594  switch (sps->pix_fmt) {
595  case AV_PIX_FMT_YUV420P:
596  case AV_PIX_FMT_YUVJ420P:
597 #if CONFIG_HEVC_DXVA2_HWACCEL
598  *fmt++ = AV_PIX_FMT_DXVA2_VLD;
599 #endif
600 #if CONFIG_HEVC_D3D11VA_HWACCEL
601  *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
602  *fmt++ = AV_PIX_FMT_D3D11;
603 #endif
604 #if CONFIG_HEVC_D3D12VA_HWACCEL
605  *fmt++ = AV_PIX_FMT_D3D12;
606 #endif
607 #if CONFIG_HEVC_VAAPI_HWACCEL
608  *fmt++ = AV_PIX_FMT_VAAPI;
609 #endif
610 #if CONFIG_HEVC_VDPAU_HWACCEL
611  *fmt++ = AV_PIX_FMT_VDPAU;
612 #endif
613 #if CONFIG_HEVC_NVDEC_HWACCEL
614  *fmt++ = AV_PIX_FMT_CUDA;
615 #endif
616 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
617  *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
618 #endif
619 #if CONFIG_HEVC_VULKAN_HWACCEL
620  *fmt++ = AV_PIX_FMT_VULKAN;
621 #endif
622  break;
624 #if CONFIG_HEVC_DXVA2_HWACCEL
625  *fmt++ = AV_PIX_FMT_DXVA2_VLD;
626 #endif
627 #if CONFIG_HEVC_D3D11VA_HWACCEL
628  *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
629  *fmt++ = AV_PIX_FMT_D3D11;
630 #endif
631 #if CONFIG_HEVC_D3D12VA_HWACCEL
632  *fmt++ = AV_PIX_FMT_D3D12;
633 #endif
634 #if CONFIG_HEVC_VAAPI_HWACCEL
635  *fmt++ = AV_PIX_FMT_VAAPI;
636 #endif
637 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
638  *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
639 #endif
640 #if CONFIG_HEVC_VULKAN_HWACCEL
641  *fmt++ = AV_PIX_FMT_VULKAN;
642 #endif
643 #if CONFIG_HEVC_VDPAU_HWACCEL
644  *fmt++ = AV_PIX_FMT_VDPAU;
645 #endif
646 #if CONFIG_HEVC_NVDEC_HWACCEL
647  *fmt++ = AV_PIX_FMT_CUDA;
648 #endif
649  break;
650  case AV_PIX_FMT_YUV444P:
651 #if CONFIG_HEVC_VAAPI_HWACCEL
652  *fmt++ = AV_PIX_FMT_VAAPI;
653 #endif
654 #if CONFIG_HEVC_VDPAU_HWACCEL
655  *fmt++ = AV_PIX_FMT_VDPAU;
656 #endif
657 #if CONFIG_HEVC_NVDEC_HWACCEL
658  *fmt++ = AV_PIX_FMT_CUDA;
659 #endif
660 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
661  *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
662 #endif
663 #if CONFIG_HEVC_VULKAN_HWACCEL
664  *fmt++ = AV_PIX_FMT_VULKAN;
665 #endif
666  break;
667  case AV_PIX_FMT_YUV422P:
669 #if CONFIG_HEVC_VAAPI_HWACCEL
670  *fmt++ = AV_PIX_FMT_VAAPI;
671 #endif
672 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
673  *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
674 #endif
675 #if CONFIG_HEVC_VULKAN_HWACCEL
676  *fmt++ = AV_PIX_FMT_VULKAN;
677 #endif
678 #if CONFIG_HEVC_NVDEC_HWACCEL
679  *fmt++ = AV_PIX_FMT_CUDA;
680 #endif
681  break;
683 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
684  *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
685 #endif
686  /* NOTE: fallthrough */
689 #if CONFIG_HEVC_VAAPI_HWACCEL
690  *fmt++ = AV_PIX_FMT_VAAPI;
691 #endif
692 #if CONFIG_HEVC_VDPAU_HWACCEL
693  *fmt++ = AV_PIX_FMT_VDPAU;
694 #endif
695 #if CONFIG_HEVC_VULKAN_HWACCEL
696  *fmt++ = AV_PIX_FMT_VULKAN;
697 #endif
698 #if CONFIG_HEVC_NVDEC_HWACCEL
699  *fmt++ = AV_PIX_FMT_CUDA;
700 #endif
701  break;
703 #if CONFIG_HEVC_VAAPI_HWACCEL
704  *fmt++ = AV_PIX_FMT_VAAPI;
705 #endif
706 #if CONFIG_HEVC_VULKAN_HWACCEL
707  *fmt++ = AV_PIX_FMT_VULKAN;
708 #endif
709 #if CONFIG_HEVC_NVDEC_HWACCEL
710  *fmt++ = AV_PIX_FMT_CUDA;
711 #endif
712  break;
713  }
714 
715  if (alpha_fmt != AV_PIX_FMT_NONE)
716  *fmt++ = alpha_fmt;
717  *fmt++ = sps->pix_fmt;
718  *fmt = AV_PIX_FMT_NONE;
719 
720  // export multilayer information from active VPS to the caller,
721  // so it is available in get_format()
722  ret = export_multilayer(s, sps->vps);
723  if (ret < 0)
724  return ret;
725 
726  ret = ff_get_format(s->avctx, pix_fmts);
727  if (ret < 0)
728  return ret;
729  s->avctx->pix_fmt = ret;
730 
731  // set up multilayer decoding, if requested by caller
732  ret = setup_multilayer(s, sps->vps);
733  if (ret < 0)
734  return ret;
735 
736  return 0;
737 }
738 
740 {
741  int ret;
742 
743  pic_arrays_free(l);
744  av_refstruct_unref(&l->sps);
745  av_refstruct_unref(&s->vps);
746 
747  if (!sps)
748  return 0;
749 
750  ret = pic_arrays_init(l, sps);
751  if (ret < 0)
752  goto fail;
753 
754  ff_hevc_pred_init(&s->hpc, sps->bit_depth);
755  ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
756  ff_videodsp_init (&s->vdsp, sps->bit_depth);
757 
758  l->sps = av_refstruct_ref_c(sps);
759  s->vps = av_refstruct_ref_c(sps->vps);
760 
761  return 0;
762 
763 fail:
764  pic_arrays_free(l);
765  av_refstruct_unref(&l->sps);
766  return ret;
767 }
768 
770 {
771  const HEVCPPS *pps;
772  const HEVCSPS *sps;
773  const HEVCVPS *vps;
774  unsigned pps_id, layer_idx;
775  int i, ret;
776 
777  // Coded parameters
779 
781  if (IS_IRAP(s))
783 
784  pps_id = get_ue_golomb_long(gb);
785  if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
786  av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
787  return AVERROR_INVALIDDATA;
788  }
789  if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
790  av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
791  return AVERROR_INVALIDDATA;
792  }
793  sh->pps_id = pps_id;
794 
795  pps = s->ps.pps_list[pps_id];
796  sps = pps->sps;
797  vps = sps->vps;
798  layer_idx = vps->layer_idx[s->nuh_layer_id];
799 
800  if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
802 
804  if (!sh->first_slice_in_pic_flag) {
805  int slice_address_length;
806 
807  if (pps->dependent_slice_segments_enabled_flag)
809  if (sh->dependent_slice_segment_flag && !s->slice_initialized) {
810  av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
811  return AVERROR_INVALIDDATA;
812  }
813 
814  slice_address_length = av_ceil_log2(sps->ctb_width *
815  sps->ctb_height);
816  sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
817  if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
818  av_log(s->avctx, AV_LOG_ERROR,
819  "Invalid slice segment address: %u.\n",
820  sh->slice_segment_addr);
821  return AVERROR_INVALIDDATA;
822  }
823 
824  if (!sh->dependent_slice_segment_flag) {
825  sh->slice_addr = sh->slice_segment_addr;
826  }
827  } else {
828  sh->slice_segment_addr = sh->slice_addr = 0;
829  }
830 
831  if (!sh->dependent_slice_segment_flag) {
832  for (i = 0; i < pps->num_extra_slice_header_bits; i++)
833  skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
834 
835  sh->slice_type = get_ue_golomb_long(gb);
836  if (!(sh->slice_type == HEVC_SLICE_I ||
837  sh->slice_type == HEVC_SLICE_P ||
838  sh->slice_type == HEVC_SLICE_B)) {
839  av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
840  sh->slice_type);
841  return AVERROR_INVALIDDATA;
842  }
843  if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
844  !pps->pps_curr_pic_ref_enabled_flag &&
845  s->nuh_layer_id == 0) {
846  av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
847  return AVERROR_INVALIDDATA;
848  }
849 
850  // when flag is not present, picture is inferred to be output
851  sh->pic_output_flag = 1;
852  if (pps->output_flag_present_flag)
853  sh->pic_output_flag = get_bits1(gb);
854 
855  if (sps->separate_colour_plane)
856  sh->colour_plane_id = get_bits(gb, 2);
857 
858  if (!IS_IDR(s) ||
859  (s->nuh_layer_id > 0 &&
860  !(vps->poc_lsb_not_present & (1 << layer_idx)))) {
861  int poc;
862 
863  sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
864  poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
865  if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
866  av_log(s->avctx, AV_LOG_WARNING,
867  "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
868  if (s->avctx->err_recognition & AV_EF_EXPLODE)
869  return AVERROR_INVALIDDATA;
870  poc = sh->poc;
871  }
872  sh->poc = poc;
873  }
874 
875  if (!IS_IDR(s)) {
876  int pos;
877 
879  pos = get_bits_left(gb);
881  ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
882  if (ret < 0)
883  return ret;
884 
885  sh->short_term_rps = &sh->slice_rps;
886  } else {
887  int numbits, rps_idx;
888 
889  if (!sps->nb_st_rps) {
890  av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
891  return AVERROR_INVALIDDATA;
892  }
893 
894  numbits = av_ceil_log2(sps->nb_st_rps);
895  rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
896  sh->short_term_rps = &sps->st_rps[rps_idx];
897  }
899 
900  pos = get_bits_left(gb);
901  ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
902  if (ret < 0) {
903  av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
904  if (s->avctx->err_recognition & AV_EF_EXPLODE)
905  return AVERROR_INVALIDDATA;
906  }
908 
909  if (sps->temporal_mvp_enabled)
911  else
913  } else {
914  sh->poc = 0;
915  sh->pic_order_cnt_lsb = 0;
918  sh->short_term_rps = NULL;
920  sh->long_term_rps.nb_refs = 0;
922  }
923 
924  sh->inter_layer_pred = 0;
925  if (s->nuh_layer_id > 0) {
926  int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx];
927 
928  if (vps->default_ref_layers_active)
929  sh->inter_layer_pred = !!num_direct_ref_layers;
930  else if (num_direct_ref_layers) {
931  sh->inter_layer_pred = get_bits1(gb);
932 
933  if (sh->inter_layer_pred && num_direct_ref_layers > 1) {
934  av_log(s->avctx, AV_LOG_ERROR,
935  "NumDirectRefLayers>1 not supported\n");
936  return AVERROR_PATCHWELCOME;
937  }
938  }
939  }
940 
941  if (sps->sao_enabled) {
943  if (sps->chroma_format_idc) {
946  }
947  } else {
951  }
952 
953  sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
954  if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
955  int nb_refs;
956 
957  sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
958  if (sh->slice_type == HEVC_SLICE_B)
959  sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
960 
961  if (get_bits1(gb)) { // num_ref_idx_active_override_flag
962  sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
963  if (sh->slice_type == HEVC_SLICE_B)
964  sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
965  }
966  if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) {
967  av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
968  sh->nb_refs[L0], sh->nb_refs[L1]);
969  return AVERROR_INVALIDDATA;
970  }
971 
972  sh->rpl_modification_flag[0] = 0;
973  sh->rpl_modification_flag[1] = 0;
974  nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx);
975  if (!nb_refs) {
976  av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
977  return AVERROR_INVALIDDATA;
978  }
979 
980  if (pps->lists_modification_present_flag && nb_refs > 1) {
981  sh->rpl_modification_flag[0] = get_bits1(gb);
982  if (sh->rpl_modification_flag[0]) {
983  for (i = 0; i < sh->nb_refs[L0]; i++)
984  sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
985  }
986 
987  if (sh->slice_type == HEVC_SLICE_B) {
988  sh->rpl_modification_flag[1] = get_bits1(gb);
989  if (sh->rpl_modification_flag[1] == 1)
990  for (i = 0; i < sh->nb_refs[L1]; i++)
991  sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
992  }
993  }
994 
995  if (sh->slice_type == HEVC_SLICE_B)
996  sh->mvd_l1_zero_flag = get_bits1(gb);
997 
998  if (pps->cabac_init_present_flag)
999  sh->cabac_init_flag = get_bits1(gb);
1000  else
1001  sh->cabac_init_flag = 0;
1002 
1003  sh->collocated_ref_idx = 0;
1005  sh->collocated_list = L0;
1006  if (sh->slice_type == HEVC_SLICE_B)
1007  sh->collocated_list = !get_bits1(gb);
1008 
1009  if (sh->nb_refs[sh->collocated_list] > 1) {
1011  if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
1012  av_log(s->avctx, AV_LOG_ERROR,
1013  "Invalid collocated_ref_idx: %d.\n",
1014  sh->collocated_ref_idx);
1015  return AVERROR_INVALIDDATA;
1016  }
1017  }
1018  }
1019 
1020  if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
1021  (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
1022  int ret = pred_weight_table(sh, s->avctx, sps, gb);
1023  if (ret < 0)
1024  return ret;
1025  }
1026 
1027  sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
1028  if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
1029  av_log(s->avctx, AV_LOG_ERROR,
1030  "Invalid number of merging MVP candidates: %d.\n",
1031  sh->max_num_merge_cand);
1032  return AVERROR_INVALIDDATA;
1033  }
1034 
1035  // Syntax in 7.3.6.1
1036  if (sps->motion_vector_resolution_control_idc == 2)
1037  sh->use_integer_mv_flag = get_bits1(gb);
1038  else
1039  // Inferred to be equal to motion_vector_resolution_control_idc if not present
1040  sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
1041 
1042  }
1043 
1044  sh->slice_qp_delta = get_se_golomb(gb);
1045 
1046  if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
1049  if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 ||
1050  sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) {
1051  av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
1052  return AVERROR_INVALIDDATA;
1053  }
1054  } else {
1055  sh->slice_cb_qp_offset = 0;
1056  sh->slice_cr_qp_offset = 0;
1057  }
1058 
1059  if (pps->pps_slice_act_qp_offsets_present_flag) {
1063  }
1064 
1065  if (pps->chroma_qp_offset_list_enabled_flag)
1067  else
1069 
1070  if (pps->deblocking_filter_control_present_flag) {
1071  int deblocking_filter_override_flag = 0;
1072 
1073  if (pps->deblocking_filter_override_enabled_flag)
1074  deblocking_filter_override_flag = get_bits1(gb);
1075 
1076  if (deblocking_filter_override_flag) {
1078  if (!sh->disable_deblocking_filter_flag) {
1079  int beta_offset_div2 = get_se_golomb(gb);
1080  int tc_offset_div2 = get_se_golomb(gb) ;
1081  if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
1082  tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1083  av_log(s->avctx, AV_LOG_ERROR,
1084  "Invalid deblock filter offsets: %d, %d\n",
1085  beta_offset_div2, tc_offset_div2);
1086  return AVERROR_INVALIDDATA;
1087  }
1088  sh->beta_offset = beta_offset_div2 * 2;
1089  sh->tc_offset = tc_offset_div2 * 2;
1090  }
1091  } else {
1092  sh->disable_deblocking_filter_flag = pps->disable_dbf;
1093  sh->beta_offset = pps->beta_offset;
1094  sh->tc_offset = pps->tc_offset;
1095  }
1096  } else {
1098  sh->beta_offset = 0;
1099  sh->tc_offset = 0;
1100  }
1101 
1102  if (pps->seq_loop_filter_across_slices_enabled_flag &&
1107  } else {
1108  sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
1109  }
1110  }
1111 
1112  sh->num_entry_point_offsets = 0;
1113  if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1114  unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
1115  // It would be possible to bound this tighter but this here is simpler
1116  if (num_entry_point_offsets > get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) {
1117  av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1118  return AVERROR_INVALIDDATA;
1119  }
1120 
1121  sh->num_entry_point_offsets = num_entry_point_offsets;
1122  if (sh->num_entry_point_offsets > 0) {
1123  int offset_len = get_ue_golomb_long(gb) + 1;
1124 
1125  if (offset_len < 1 || offset_len > 32) {
1126  sh->num_entry_point_offsets = 0;
1127  av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
1128  return AVERROR_INVALIDDATA;
1129  }
1130 
1132  av_freep(&sh->offset);
1133  av_freep(&sh->size);
1134  sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
1135  sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1136  sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1137  if (!sh->entry_point_offset || !sh->offset || !sh->size) {
1138  sh->num_entry_point_offsets = 0;
1139  av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
1140  return AVERROR(ENOMEM);
1141  }
1142  for (i = 0; i < sh->num_entry_point_offsets; i++) {
1143  unsigned val = get_bits_long(gb, offset_len);
1144  sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
1145  }
1146  }
1147  }
1148 
1149  if (pps->slice_header_extension_present_flag) {
1150  unsigned int length = get_ue_golomb_long(gb);
1151  if (length*8LL > get_bits_left(gb)) {
1152  av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
1153  return AVERROR_INVALIDDATA;
1154  }
1155  for (i = 0; i < length; i++)
1156  skip_bits(gb, 8); // slice_header_extension_data_byte
1157  }
1158 
1159  ret = get_bits1(gb);
1160  if (!ret && get_bits_left(gb) >= 0) {
1161  av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
1162  return AVERROR_INVALIDDATA;
1163  }
1164  sh->data_offset = align_get_bits(gb) - gb->buffer;
1165 
1166  if (get_bits_left(gb) < 0) {
1167  av_log(s->avctx, AV_LOG_ERROR,
1168  "Overread slice header by %d bits\n", -get_bits_left(gb));
1169  return AVERROR_INVALIDDATA;
1170  }
1171 
1172  // Inferred parameters
1173  sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
1174  if (sh->slice_qp > 51 ||
1175  sh->slice_qp < -sps->qp_bd_offset) {
1176  av_log(s->avctx, AV_LOG_ERROR,
1177  "The slice_qp %d is outside the valid range "
1178  "[%d, 51].\n",
1179  sh->slice_qp,
1180  -sps->qp_bd_offset);
1181  return AVERROR_INVALIDDATA;
1182  }
1183 
1185 
1186  if (sh->dependent_slice_segment_flag &&
1187  (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) {
1188  av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
1189  return AVERROR_INVALIDDATA;
1190  }
1191 
1192  return 0;
1193 }
1194 
1195 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1196 
1197 #define SET_SAO(elem, value) \
1198 do { \
1199  if (!sao_merge_up_flag && !sao_merge_left_flag) \
1200  sao->elem = value; \
1201  else if (sao_merge_left_flag) \
1202  sao->elem = CTB(l->sao, rx-1, ry).elem; \
1203  else if (sao_merge_up_flag) \
1204  sao->elem = CTB(l->sao, rx, ry-1).elem; \
1205  else \
1206  sao->elem = 0; \
1207 } while (0)
1208 
1210  const HEVCPPS *pps, const HEVCSPS *sps,
1211  int rx, int ry)
1212 {
1213  const HEVCContext *const s = lc->parent;
1214  int sao_merge_left_flag = 0;
1215  int sao_merge_up_flag = 0;
1216  SAOParams *sao = &CTB(l->sao, rx, ry);
1217  int c_idx, i;
1218 
1219  if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1220  s->sh.slice_sample_adaptive_offset_flag[1]) {
1221  if (rx > 0) {
1222  if (lc->ctb_left_flag)
1223  sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1224  }
1225  if (ry > 0 && !sao_merge_left_flag) {
1226  if (lc->ctb_up_flag)
1227  sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1228  }
1229  }
1230 
1231  for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1232  int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1233  pps->log2_sao_offset_scale_chroma;
1234 
1235  if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1236  sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1237  continue;
1238  }
1239 
1240  if (c_idx == 2) {
1241  sao->type_idx[2] = sao->type_idx[1];
1242  sao->eo_class[2] = sao->eo_class[1];
1243  } else {
1244  SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1245  }
1246 
1247  if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1248  continue;
1249 
1250  for (i = 0; i < 4; i++)
1251  SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1252 
1253  if (sao->type_idx[c_idx] == SAO_BAND) {
1254  for (i = 0; i < 4; i++) {
1255  if (sao->offset_abs[c_idx][i]) {
1256  SET_SAO(offset_sign[c_idx][i],
1258  } else {
1259  sao->offset_sign[c_idx][i] = 0;
1260  }
1261  }
1262  SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1263  } else if (c_idx != 2) {
1264  SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1265  }
1266 
1267  // Inferred parameters
1268  sao->offset_val[c_idx][0] = 0;
1269  for (i = 0; i < 4; i++) {
1270  sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1271  if (sao->type_idx[c_idx] == SAO_EDGE) {
1272  if (i > 1)
1273  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1274  } else if (sao->offset_sign[c_idx][i]) {
1275  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1276  }
1277  sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1278  }
1279  }
1280 }
1281 
1282 #undef SET_SAO
1283 #undef CTB
1284 
1286 {
1287  int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx);
1288 
1289  if (log2_res_scale_abs_plus1 != 0) {
1290  int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx);
1291  lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1292  (1 - 2 * res_scale_sign_flag);
1293  } else {
1294  lc->tu.res_scale_val = 0;
1295  }
1296 
1297 
1298  return 0;
1299 }
1300 
1302  const HEVCLayerContext *l,
1303  const HEVCPPS *pps, const HEVCSPS *sps,
1304  int x0, int y0,
1305  int xBase, int yBase, int cb_xBase, int cb_yBase,
1306  int log2_cb_size, int log2_trafo_size,
1307  int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1308 {
1309  const HEVCContext *const s = lc->parent;
1310  const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1311  int i;
1312 
1313  if (lc->cu.pred_mode == MODE_INTRA) {
1314  int trafo_size = 1 << log2_trafo_size;
1315  ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1316 
1317  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1318  }
1319 
1320  if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1321  (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1322  int scan_idx = SCAN_DIAG;
1323  int scan_idx_c = SCAN_DIAG;
1324  int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1325  (sps->chroma_format_idc == 2 &&
1326  (cbf_cb[1] || cbf_cr[1]));
1327 
1328  if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1330  if (lc->tu.cu_qp_delta != 0)
1331  if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1332  lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1333  lc->tu.is_cu_qp_delta_coded = 1;
1334 
1335  if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1336  lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
1337  av_log(s->avctx, AV_LOG_ERROR,
1338  "The cu_qp_delta %d is outside the valid range "
1339  "[%d, %d].\n",
1340  lc->tu.cu_qp_delta,
1341  -(26 + sps->qp_bd_offset / 2),
1342  (25 + sps->qp_bd_offset / 2));
1343  return AVERROR_INVALIDDATA;
1344  }
1345 
1346  ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size);
1347  }
1348 
1349  if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1351  int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
1352  if (cu_chroma_qp_offset_flag) {
1353  int cu_chroma_qp_offset_idx = 0;
1354  if (pps->chroma_qp_offset_list_len_minus1 > 0) {
1355  cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
1356  av_log(s->avctx, AV_LOG_ERROR,
1357  "cu_chroma_qp_offset_idx not yet tested.\n");
1358  }
1359  lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1360  lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1361  } else {
1362  lc->tu.cu_qp_offset_cb = 0;
1363  lc->tu.cu_qp_offset_cr = 0;
1364  }
1366  }
1367 
1368  if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1369  if (lc->tu.intra_pred_mode >= 6 &&
1370  lc->tu.intra_pred_mode <= 14) {
1371  scan_idx = SCAN_VERT;
1372  } else if (lc->tu.intra_pred_mode >= 22 &&
1373  lc->tu.intra_pred_mode <= 30) {
1374  scan_idx = SCAN_HORIZ;
1375  }
1376 
1377  if (lc->tu.intra_pred_mode_c >= 6 &&
1378  lc->tu.intra_pred_mode_c <= 14) {
1379  scan_idx_c = SCAN_VERT;
1380  } else if (lc->tu.intra_pred_mode_c >= 22 &&
1381  lc->tu.intra_pred_mode_c <= 30) {
1382  scan_idx_c = SCAN_HORIZ;
1383  }
1384  }
1385 
1386  lc->tu.cross_pf = 0;
1387 
1388  if (cbf_luma)
1389  ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1390  if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1391  int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1392  int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1393  lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
1394  (lc->cu.pred_mode == MODE_INTER ||
1395  (lc->tu.chroma_mode_c == 4)));
1396 
1397  if (lc->tu.cross_pf) {
1398  hls_cross_component_pred(lc, 0);
1399  }
1400  for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1401  if (lc->cu.pred_mode == MODE_INTRA) {
1402  ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1403  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1404  s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
1405  }
1406  if (cbf_cb[i])
1407  ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1408  log2_trafo_size_c, scan_idx_c, 1);
1409  else
1410  if (lc->tu.cross_pf) {
1411  ptrdiff_t stride = s->cur_frame->f->linesize[1];
1412  int hshift = sps->hshift[1];
1413  int vshift = sps->vshift[1];
1414  const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1415  int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1416  int size = 1 << log2_trafo_size_c;
1417 
1418  uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
1419  ((x0 >> hshift) << sps->pixel_shift)];
1420  for (i = 0; i < (size * size); i++) {
1421  coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1422  }
1423  s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1424  }
1425  }
1426 
1427  if (lc->tu.cross_pf) {
1428  hls_cross_component_pred(lc, 1);
1429  }
1430  for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1431  if (lc->cu.pred_mode == MODE_INTRA) {
1432  ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1433  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1434  s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
1435  }
1436  if (cbf_cr[i])
1437  ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1438  log2_trafo_size_c, scan_idx_c, 2);
1439  else
1440  if (lc->tu.cross_pf) {
1441  ptrdiff_t stride = s->cur_frame->f->linesize[2];
1442  int hshift = sps->hshift[2];
1443  int vshift = sps->vshift[2];
1444  const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1445  int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1446  int size = 1 << log2_trafo_size_c;
1447 
1448  uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
1449  ((x0 >> hshift) << sps->pixel_shift)];
1450  for (i = 0; i < (size * size); i++) {
1451  coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1452  }
1453  s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1454  }
1455  }
1456  } else if (sps->chroma_format_idc && blk_idx == 3) {
1457  int trafo_size_h = 1 << (log2_trafo_size + 1);
1458  int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1459  for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1460  if (lc->cu.pred_mode == MODE_INTRA) {
1461  ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1462  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1463  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1464  }
1465  if (cbf_cb[i])
1466  ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1467  log2_trafo_size, scan_idx_c, 1);
1468  }
1469  for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1470  if (lc->cu.pred_mode == MODE_INTRA) {
1471  ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1472  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1473  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1474  }
1475  if (cbf_cr[i])
1476  ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1477  log2_trafo_size, scan_idx_c, 2);
1478  }
1479  }
1480  } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1481  if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1482  int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1483  int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1484  ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1485  sps->log2_ctb_size);
1486  s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1487  s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
1488  if (sps->chroma_format_idc == 2) {
1489  ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
1490  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1491  s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1492  s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1493  }
1494  } else if (blk_idx == 3) {
1495  int trafo_size_h = 1 << (log2_trafo_size + 1);
1496  int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1497  ff_hevc_set_neighbour_available(lc, xBase, yBase,
1498  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1499  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1500  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1501  if (sps->chroma_format_idc == 2) {
1502  ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
1503  trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1504  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
1505  s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
1506  }
1507  }
1508  }
1509 
1510  return 0;
1511 }
1512 
1513 static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps,
1514  int x0, int y0, int log2_cb_size)
1515 {
1516  int cb_size = 1 << log2_cb_size;
1517  int log2_min_pu_size = sps->log2_min_pu_size;
1518 
1519  int min_pu_width = sps->min_pu_width;
1520  int x_end = FFMIN(x0 + cb_size, sps->width);
1521  int y_end = FFMIN(y0 + cb_size, sps->height);
1522  int i, j;
1523 
1524  for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1525  for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1526  is_pcm[i + j * min_pu_width] = 2;
1527 }
1528 
1530  const HEVCLayerContext *l,
1531  const HEVCPPS *pps, const HEVCSPS *sps,
1532  int x0, int y0,
1533  int xBase, int yBase, int cb_xBase, int cb_yBase,
1534  int log2_cb_size, int log2_trafo_size,
1535  int trafo_depth, int blk_idx,
1536  const int *base_cbf_cb, const int *base_cbf_cr)
1537 {
1538  const HEVCContext *const s = lc->parent;
1539  uint8_t split_transform_flag;
1540  int cbf_cb[2];
1541  int cbf_cr[2];
1542  int ret;
1543 
1544  cbf_cb[0] = base_cbf_cb[0];
1545  cbf_cb[1] = base_cbf_cb[1];
1546  cbf_cr[0] = base_cbf_cr[0];
1547  cbf_cr[1] = base_cbf_cr[1];
1548 
1549  if (lc->cu.intra_split_flag) {
1550  if (trafo_depth == 1) {
1551  lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1552  if (sps->chroma_format_idc == 3) {
1553  lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1554  lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1555  } else {
1557  lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1558  }
1559  }
1560  } else {
1561  lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1563  lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1564  }
1565 
1566  if (log2_trafo_size <= sps->log2_max_trafo_size &&
1567  log2_trafo_size > sps->log2_min_tb_size &&
1568  trafo_depth < lc->cu.max_trafo_depth &&
1569  !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1570  split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
1571  } else {
1572  int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1573  lc->cu.pred_mode == MODE_INTER &&
1574  lc->cu.part_mode != PART_2Nx2N &&
1575  trafo_depth == 0;
1576 
1577  split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1578  (lc->cu.intra_split_flag && trafo_depth == 0) ||
1579  inter_split;
1580  }
1581 
1582  if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1583  if (trafo_depth == 0 || cbf_cb[0]) {
1584  cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1585  if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1586  cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1587  }
1588  }
1589 
1590  if (trafo_depth == 0 || cbf_cr[0]) {
1591  cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1592  if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1593  cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1594  }
1595  }
1596  }
1597 
1598  if (split_transform_flag) {
1599  const int trafo_size_split = 1 << (log2_trafo_size - 1);
1600  const int x1 = x0 + trafo_size_split;
1601  const int y1 = y0 + trafo_size_split;
1602 
1603 #define SUBDIVIDE(x, y, idx) \
1604 do { \
1605  ret = hls_transform_tree(lc, l, pps, sps, \
1606  x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1607  log2_trafo_size - 1, trafo_depth + 1, idx, \
1608  cbf_cb, cbf_cr); \
1609  if (ret < 0) \
1610  return ret; \
1611 } while (0)
1612 
1613  SUBDIVIDE(x0, y0, 0);
1614  SUBDIVIDE(x1, y0, 1);
1615  SUBDIVIDE(x0, y1, 2);
1616  SUBDIVIDE(x1, y1, 3);
1617 
1618 #undef SUBDIVIDE
1619  } else {
1620  int min_tu_size = 1 << sps->log2_min_tb_size;
1621  int log2_min_tu_size = sps->log2_min_tb_size;
1622  int min_tu_width = sps->min_tb_width;
1623  int cbf_luma = 1;
1624 
1625  if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1626  cbf_cb[0] || cbf_cr[0] ||
1627  (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1628  cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1629  }
1630 
1631  ret = hls_transform_unit(lc, l, pps, sps,
1632  x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1633  log2_cb_size, log2_trafo_size,
1634  blk_idx, cbf_luma, cbf_cb, cbf_cr);
1635  if (ret < 0)
1636  return ret;
1637  // TODO: store cbf_luma somewhere else
1638  if (cbf_luma) {
1639  int i, j;
1640  for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1641  for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1642  int x_tu = (x0 + j) >> log2_min_tu_size;
1643  int y_tu = (y0 + i) >> log2_min_tu_size;
1644  l->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1645  }
1646  }
1647  if (!s->sh.disable_deblocking_filter_flag) {
1648  ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size);
1649  if (pps->transquant_bypass_enable_flag &&
1651  set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size);
1652  }
1653  }
1654  return 0;
1655 }
1656 
1658  const HEVCPPS *pps, int x0, int y0, int log2_cb_size)
1659 {
1660  const HEVCContext *const s = lc->parent;
1661  const HEVCSPS *const sps = pps->sps;
1662  GetBitContext gb;
1663  int cb_size = 1 << log2_cb_size;
1664  ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
1665  ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
1666  ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
1667  uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
1668  uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
1669  uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
1670 
1671  int length = cb_size * cb_size * sps->pcm.bit_depth +
1672  (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
1673  ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
1674  sps->pcm.bit_depth_chroma;
1675  const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1676  int ret;
1677 
1678  if (!s->sh.disable_deblocking_filter_flag)
1679  ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
1680 
1681  ret = init_get_bits(&gb, pcm, length);
1682  if (ret < 0)
1683  return ret;
1684 
1685  s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
1686  if (sps->chroma_format_idc) {
1687  s->hevcdsp.put_pcm(dst1, stride1,
1688  cb_size >> sps->hshift[1],
1689  cb_size >> sps->vshift[1],
1690  &gb, sps->pcm.bit_depth_chroma);
1691  s->hevcdsp.put_pcm(dst2, stride2,
1692  cb_size >> sps->hshift[2],
1693  cb_size >> sps->vshift[2],
1694  &gb, sps->pcm.bit_depth_chroma);
1695  }
1696 
1697  return 0;
1698 }
1699 
1700 /**
1701  * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1702  *
1703  * @param s HEVC decoding context
1704  * @param dst target buffer for block data at block position
1705  * @param dststride stride of the dst buffer
1706  * @param ref reference picture buffer at origin (0, 0)
1707  * @param mv motion vector (relative to block position) to get pixel data from
1708  * @param x_off horizontal position of block from origin (0, 0)
1709  * @param y_off vertical position of block from origin (0, 0)
1710  * @param block_w width of block
1711  * @param block_h height of block
1712  * @param luma_weight weighting factor applied to the luma prediction
1713  * @param luma_offset additive offset applied to the luma prediction value
1714  */
1715 
1717  const HEVCPPS *pps, const HEVCSPS *sps,
1718  uint8_t *dst, ptrdiff_t dststride,
1719  const AVFrame *ref, const Mv *mv, int x_off, int y_off,
1720  int block_w, int block_h, int luma_weight, int luma_offset)
1721 {
1722  const HEVCContext *const s = lc->parent;
1723  const uint8_t *src = ref->data[0];
1724  ptrdiff_t srcstride = ref->linesize[0];
1725  int pic_width = sps->width;
1726  int pic_height = sps->height;
1727  int mx = mv->x & 3;
1728  int my = mv->y & 3;
1729  int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1730  (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1731  int idx = hevc_pel_weight[block_w];
1732 
1733  x_off += mv->x >> 2;
1734  y_off += mv->y >> 2;
1735  src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1736 
1737  if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1738  x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1739  y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1740  ref == s->cur_frame->f) {
1741  const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1742  int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1743  int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1744 
1745  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1746  edge_emu_stride, srcstride,
1747  block_w + QPEL_EXTRA,
1748  block_h + QPEL_EXTRA,
1749  x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1750  pic_width, pic_height);
1751  src = lc->edge_emu_buffer + buf_offset;
1752  srcstride = edge_emu_stride;
1753  }
1754 
1755  if (!weight_flag)
1756  s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1757  block_h, mx, my, block_w);
1758  else
1759  s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1760  block_h, s->sh.luma_log2_weight_denom,
1761  luma_weight, luma_offset, mx, my, block_w);
1762 }
1763 
1764 /**
1765  * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1766  *
1767  * @param s HEVC decoding context
1768  * @param dst target buffer for block data at block position
1769  * @param dststride stride of the dst buffer
1770  * @param ref0 reference picture0 buffer at origin (0, 0)
1771  * @param mv0 motion vector0 (relative to block position) to get pixel data from
1772  * @param x_off horizontal position of block from origin (0, 0)
1773  * @param y_off vertical position of block from origin (0, 0)
1774  * @param block_w width of block
1775  * @param block_h height of block
1776  * @param ref1 reference picture1 buffer at origin (0, 0)
1777  * @param mv1 motion vector1 (relative to block position) to get pixel data from
1778  * @param current_mv current motion vector structure
1779  */
1781  const HEVCPPS *pps, const HEVCSPS *sps,
1782  uint8_t *dst, ptrdiff_t dststride,
1783  const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1784  int block_w, int block_h, const AVFrame *ref1,
1785  const Mv *mv1, struct MvField *current_mv)
1786 {
1787  const HEVCContext *const s = lc->parent;
1788  ptrdiff_t src0stride = ref0->linesize[0];
1789  ptrdiff_t src1stride = ref1->linesize[0];
1790  int pic_width = sps->width;
1791  int pic_height = sps->height;
1792  int mx0 = mv0->x & 3;
1793  int my0 = mv0->y & 3;
1794  int mx1 = mv1->x & 3;
1795  int my1 = mv1->y & 3;
1796  int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1797  (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1798  int x_off0 = x_off + (mv0->x >> 2);
1799  int y_off0 = y_off + (mv0->y >> 2);
1800  int x_off1 = x_off + (mv1->x >> 2);
1801  int y_off1 = y_off + (mv1->y >> 2);
1802  int idx = hevc_pel_weight[block_w];
1803 
1804  const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1805  const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1806 
1807  if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1808  x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1809  y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1810  const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1811  int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1812  int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1813 
1814  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1815  edge_emu_stride, src0stride,
1816  block_w + QPEL_EXTRA,
1817  block_h + QPEL_EXTRA,
1818  x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1819  pic_width, pic_height);
1820  src0 = lc->edge_emu_buffer + buf_offset;
1821  src0stride = edge_emu_stride;
1822  }
1823 
1824  if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1825  x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1826  y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1827  const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1828  int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1829  int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1830 
1831  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1832  edge_emu_stride, src1stride,
1833  block_w + QPEL_EXTRA,
1834  block_h + QPEL_EXTRA,
1835  x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1836  pic_width, pic_height);
1837  src1 = lc->edge_emu_buffer2 + buf_offset;
1838  src1stride = edge_emu_stride;
1839  }
1840 
1841  s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1842  block_h, mx0, my0, block_w);
1843  if (!weight_flag)
1844  s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1845  block_h, mx1, my1, block_w);
1846  else
1847  s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1848  block_h, s->sh.luma_log2_weight_denom,
1849  s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1850  s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1851  s->sh.luma_offset_l0[current_mv->ref_idx[0]],
1852  s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1853  mx1, my1, block_w);
1854 
1855 }
1856 
1857 /**
1858  * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1859  *
1860  * @param s HEVC decoding context
1861  * @param dst1 target buffer for block data at block position (U plane)
1862  * @param dst2 target buffer for block data at block position (V plane)
1863  * @param dststride stride of the dst1 and dst2 buffers
1864  * @param ref reference picture buffer at origin (0, 0)
1865  * @param mv motion vector (relative to block position) to get pixel data from
1866  * @param x_off horizontal position of block from origin (0, 0)
1867  * @param y_off vertical position of block from origin (0, 0)
1868  * @param block_w width of block
1869  * @param block_h height of block
1870  * @param chroma_weight weighting factor applied to the chroma prediction
1871  * @param chroma_offset additive offset applied to the chroma prediction value
1872  */
1873 
1875  const HEVCPPS *pps, const HEVCSPS *sps,
1876  uint8_t *dst0,
1877  ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
1878  int x_off, int y_off, int block_w, int block_h,
1879  const struct MvField *current_mv, int chroma_weight, int chroma_offset)
1880 {
1881  const HEVCContext *const s = lc->parent;
1882  int pic_width = sps->width >> sps->hshift[1];
1883  int pic_height = sps->height >> sps->vshift[1];
1884  const Mv *mv = &current_mv->mv[reflist];
1885  int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1886  (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1887  int idx = hevc_pel_weight[block_w];
1888  int hshift = sps->hshift[1];
1889  int vshift = sps->vshift[1];
1890  intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1891  intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1892  intptr_t _mx = mx << (1 - hshift);
1893  intptr_t _my = my << (1 - vshift);
1894  int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1895 
1896  x_off += mv->x >> (2 + hshift);
1897  y_off += mv->y >> (2 + vshift);
1898  src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1899 
1900  if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1901  x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1902  y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1903  emu) {
1904  const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1905  int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1906  int buf_offset0 = EPEL_EXTRA_BEFORE *
1907  (edge_emu_stride + (1 << sps->pixel_shift));
1908  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1909  edge_emu_stride, srcstride,
1910  block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1911  x_off - EPEL_EXTRA_BEFORE,
1912  y_off - EPEL_EXTRA_BEFORE,
1913  pic_width, pic_height);
1914 
1915  src0 = lc->edge_emu_buffer + buf_offset0;
1916  srcstride = edge_emu_stride;
1917  }
1918  if (!weight_flag)
1919  s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1920  block_h, _mx, _my, block_w);
1921  else
1922  s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1923  block_h, s->sh.chroma_log2_weight_denom,
1924  chroma_weight, chroma_offset, _mx, _my, block_w);
1925 }
1926 
1927 /**
1928  * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1929  *
1930  * @param s HEVC decoding context
1931  * @param dst target buffer for block data at block position
1932  * @param dststride stride of the dst buffer
1933  * @param ref0 reference picture0 buffer at origin (0, 0)
1934  * @param mv0 motion vector0 (relative to block position) to get pixel data from
1935  * @param x_off horizontal position of block from origin (0, 0)
1936  * @param y_off vertical position of block from origin (0, 0)
1937  * @param block_w width of block
1938  * @param block_h height of block
1939  * @param ref1 reference picture1 buffer at origin (0, 0)
1940  * @param mv1 motion vector1 (relative to block position) to get pixel data from
1941  * @param current_mv current motion vector structure
1942  * @param cidx chroma component(cb, cr)
1943  */
1945  const HEVCPPS *pps, const HEVCSPS *sps,
1946  uint8_t *dst0, ptrdiff_t dststride,
1947  const AVFrame *ref0, const AVFrame *ref1,
1948  int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
1949 {
1950  const HEVCContext *const s = lc->parent;
1951  const uint8_t *src1 = ref0->data[cidx+1];
1952  const uint8_t *src2 = ref1->data[cidx+1];
1953  ptrdiff_t src1stride = ref0->linesize[cidx+1];
1954  ptrdiff_t src2stride = ref1->linesize[cidx+1];
1955  int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1956  (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1957  int pic_width = sps->width >> sps->hshift[1];
1958  int pic_height = sps->height >> sps->vshift[1];
1959  const Mv *const mv0 = &current_mv->mv[0];
1960  const Mv *const mv1 = &current_mv->mv[1];
1961  int hshift = sps->hshift[1];
1962  int vshift = sps->vshift[1];
1963 
1964  intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1965  intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1966  intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1967  intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1968  intptr_t _mx0 = mx0 << (1 - hshift);
1969  intptr_t _my0 = my0 << (1 - vshift);
1970  intptr_t _mx1 = mx1 << (1 - hshift);
1971  intptr_t _my1 = my1 << (1 - vshift);
1972 
1973  int x_off0 = x_off + (mv0->x >> (2 + hshift));
1974  int y_off0 = y_off + (mv0->y >> (2 + vshift));
1975  int x_off1 = x_off + (mv1->x >> (2 + hshift));
1976  int y_off1 = y_off + (mv1->y >> (2 + vshift));
1977  int idx = hevc_pel_weight[block_w];
1978  src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1979  src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1980 
1981  if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
1982  x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1983  y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1984  const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1985  int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
1986  int buf_offset1 = EPEL_EXTRA_BEFORE *
1987  (edge_emu_stride + (1 << sps->pixel_shift));
1988 
1989  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1990  edge_emu_stride, src1stride,
1991  block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1992  x_off0 - EPEL_EXTRA_BEFORE,
1993  y_off0 - EPEL_EXTRA_BEFORE,
1994  pic_width, pic_height);
1995 
1996  src1 = lc->edge_emu_buffer + buf_offset1;
1997  src1stride = edge_emu_stride;
1998  }
1999 
2000  if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
2001  x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
2002  y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
2003  const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
2004  int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
2005  int buf_offset1 = EPEL_EXTRA_BEFORE *
2006  (edge_emu_stride + (1 << sps->pixel_shift));
2007 
2008  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
2009  edge_emu_stride, src2stride,
2010  block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
2011  x_off1 - EPEL_EXTRA_BEFORE,
2012  y_off1 - EPEL_EXTRA_BEFORE,
2013  pic_width, pic_height);
2014 
2015  src2 = lc->edge_emu_buffer2 + buf_offset1;
2016  src2stride = edge_emu_stride;
2017  }
2018 
2019  s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
2020  block_h, _mx0, _my0, block_w);
2021  if (!weight_flag)
2022  s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2023  src2, src2stride, lc->tmp,
2024  block_h, _mx1, _my1, block_w);
2025  else
2026  s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2027  src2, src2stride, lc->tmp,
2028  block_h,
2029  s->sh.chroma_log2_weight_denom,
2030  s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
2031  s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
2032  s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx],
2033  s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
2034  _mx1, _my1, block_w);
2035 }
2036 
2037 static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
2038  const Mv *mv, int y0, int height)
2039 {
2040  if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
2041  int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
2042 
2043  ff_progress_frame_await(&ref->tf, y);
2044  }
2045 }
2046 
2048  const HEVCPPS *pps, const HEVCSPS *sps,
2049  int x0, int y0, int nPbW,
2050  int nPbH, int log2_cb_size, int part_idx,
2051  int merge_idx, MvField *mv)
2052 {
2053  const HEVCContext *const s = lc->parent;
2054  enum InterPredIdc inter_pred_idc = PRED_L0;
2055  int mvp_flag;
2056 
2057  ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
2058  mv->pred_flag = 0;
2059  if (s->sh.slice_type == HEVC_SLICE_B)
2060  inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
2061 
2062  if (inter_pred_idc != PRED_L1) {
2063  if (s->sh.nb_refs[L0])
2064  mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]);
2065 
2066  mv->pred_flag = PF_L0;
2067  ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
2068  mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2069  ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2070  part_idx, merge_idx, mv, mvp_flag, 0);
2071  mv->mv[0].x += lc->pu.mvd.x;
2072  mv->mv[0].y += lc->pu.mvd.y;
2073  }
2074 
2075  if (inter_pred_idc != PRED_L0) {
2076  if (s->sh.nb_refs[L1])
2077  mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]);
2078 
2079  if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
2080  AV_ZERO32(&lc->pu.mvd);
2081  } else {
2082  ff_hevc_hls_mvd_coding(lc, x0, y0, 1);
2083  }
2084 
2085  mv->pred_flag += PF_L1;
2086  mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2087  ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2088  part_idx, merge_idx, mv, mvp_flag, 1);
2089  mv->mv[1].x += lc->pu.mvd.x;
2090  mv->mv[1].y += lc->pu.mvd.y;
2091  }
2092 }
2093 
2095  const HEVCLayerContext *l,
2096  const HEVCPPS *pps, const HEVCSPS *sps,
2097  int x0, int y0, int nPbW, int nPbH,
2098  int log2_cb_size, int partIdx, int idx)
2099 {
2100 #define POS(c_idx, x, y) \
2101  s->cur_frame->f->data[c_idx] ? \
2102  &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2103  (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL
2104  const HEVCContext *const s = lc->parent;
2105  int merge_idx = 0;
2106  struct MvField current_mv = {{{ 0 }}};
2107 
2108  int min_pu_width = sps->min_pu_width;
2109 
2110  MvField *tab_mvf = s->cur_frame->tab_mvf;
2111  const RefPicList *refPicList = s->cur_frame->refPicList;
2112  const HEVCFrame *ref0 = NULL, *ref1 = NULL;
2113  const int *linesize = s->cur_frame->f->linesize;
2114  uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift);
2115  uint8_t *dst1 = POS(1, x0, y0);
2116  uint8_t *dst2 = POS(2, x0, y0);
2117  int log2_min_cb_size = sps->log2_min_cb_size;
2118  int min_cb_width = sps->min_cb_width;
2119  int x_cb = x0 >> log2_min_cb_size;
2120  int y_cb = y0 >> log2_min_cb_size;
2121  int x_pu, y_pu;
2122  int i, j;
2123 
2124  int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb);
2125 
2126  if (!skip_flag)
2128 
2129  if (skip_flag || lc->pu.merge_flag) {
2130  if (s->sh.max_num_merge_cand > 1)
2131  merge_idx = ff_hevc_merge_idx_decode(lc);
2132  else
2133  merge_idx = 0;
2134 
2135  ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2136  partIdx, merge_idx, &current_mv);
2137  } else {
2138  hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
2139  partIdx, merge_idx, &current_mv);
2140  }
2141 
2142  x_pu = x0 >> sps->log2_min_pu_size;
2143  y_pu = y0 >> sps->log2_min_pu_size;
2144 
2145  for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++)
2146  for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++)
2147  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
2148 
2149  if (current_mv.pred_flag & PF_L0) {
2150  ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
2151  if (!ref0 || !ref0->f)
2152  return;
2153  hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
2154  }
2155  if (current_mv.pred_flag & PF_L1) {
2156  ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
2157  if (!ref1 || !ref1->f)
2158  return;
2159  hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
2160  }
2161 
2162  if (current_mv.pred_flag == PF_L0) {
2163  int x0_c = x0 >> sps->hshift[1];
2164  int y0_c = y0 >> sps->vshift[1];
2165  int nPbW_c = nPbW >> sps->hshift[1];
2166  int nPbH_c = nPbH >> sps->vshift[1];
2167 
2168  luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f,
2169  &current_mv.mv[0], x0, y0, nPbW, nPbH,
2170  s->sh.luma_weight_l0[current_mv.ref_idx[0]],
2171  s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
2172 
2173  if (sps->chroma_format_idc) {
2174  chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1],
2175  0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2176  s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
2177  chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2],
2178  0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2179  s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
2180  }
2181  } else if (current_mv.pred_flag == PF_L1) {
2182  int x0_c = x0 >> sps->hshift[1];
2183  int y0_c = y0 >> sps->vshift[1];
2184  int nPbW_c = nPbW >> sps->hshift[1];
2185  int nPbH_c = nPbH >> sps->vshift[1];
2186 
2187  luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f,
2188  &current_mv.mv[1], x0, y0, nPbW, nPbH,
2189  s->sh.luma_weight_l1[current_mv.ref_idx[1]],
2190  s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
2191 
2192  if (sps->chroma_format_idc) {
2193  chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1],
2194  1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2195  s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
2196 
2197  chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2],
2198  1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2199  s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
2200  }
2201  } else if (current_mv.pred_flag == PF_BI) {
2202  int x0_c = x0 >> sps->hshift[1];
2203  int y0_c = y0 >> sps->vshift[1];
2204  int nPbW_c = nPbW >> sps->hshift[1];
2205  int nPbH_c = nPbH >> sps->vshift[1];
2206 
2207  luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f,
2208  &current_mv.mv[0], x0, y0, nPbW, nPbH,
2209  ref1->f, &current_mv.mv[1], &current_mv);
2210 
2211  if (sps->chroma_format_idc) {
2212  chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f,
2213  x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 0);
2214 
2215  chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f,
2216  x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 1);
2217  }
2218  }
2219 }
2220 
2221 /**
2222  * 8.4.1
2223  */
2225  const HEVCSPS *sps,
2226  int x0, int y0, int pu_size,
2227  int prev_intra_luma_pred_flag)
2228 {
2229  const HEVCContext *const s = lc->parent;
2230  int x_pu = x0 >> sps->log2_min_pu_size;
2231  int y_pu = y0 >> sps->log2_min_pu_size;
2232  int min_pu_width = sps->min_pu_width;
2233  int size_in_pus = pu_size >> sps->log2_min_pu_size;
2234  int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2235  int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2236 
2237  int cand_up = (lc->ctb_up_flag || y0b) ?
2238  l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
2239  int cand_left = (lc->ctb_left_flag || x0b) ?
2240  l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
2241 
2242  int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size);
2243 
2244  MvField *tab_mvf = s->cur_frame->tab_mvf;
2245  int intra_pred_mode;
2246  int candidate[3];
2247  int i, j;
2248 
2249  // intra_pred_mode prediction does not cross vertical CTB boundaries
2250  if ((y0 - 1) < y_ctb)
2251  cand_up = INTRA_DC;
2252 
2253  if (cand_left == cand_up) {
2254  if (cand_left < 2) {
2255  candidate[0] = INTRA_PLANAR;
2256  candidate[1] = INTRA_DC;
2257  candidate[2] = INTRA_ANGULAR_26;
2258  } else {
2259  candidate[0] = cand_left;
2260  candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2261  candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2262  }
2263  } else {
2264  candidate[0] = cand_left;
2265  candidate[1] = cand_up;
2266  if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2267  candidate[2] = INTRA_PLANAR;
2268  } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2269  candidate[2] = INTRA_DC;
2270  } else {
2271  candidate[2] = INTRA_ANGULAR_26;
2272  }
2273  }
2274 
2275  if (prev_intra_luma_pred_flag) {
2276  intra_pred_mode = candidate[lc->pu.mpm_idx];
2277  } else {
2278  if (candidate[0] > candidate[1])
2279  FFSWAP(uint8_t, candidate[0], candidate[1]);
2280  if (candidate[0] > candidate[2])
2281  FFSWAP(uint8_t, candidate[0], candidate[2]);
2282  if (candidate[1] > candidate[2])
2283  FFSWAP(uint8_t, candidate[1], candidate[2]);
2284 
2285  intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2286  for (i = 0; i < 3; i++)
2287  if (intra_pred_mode >= candidate[i])
2288  intra_pred_mode++;
2289  }
2290 
2291  /* write the intra prediction units into the mv array */
2292  if (!size_in_pus)
2293  size_in_pus = 1;
2294  for (i = 0; i < size_in_pus; i++) {
2295  memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
2296  intra_pred_mode, size_in_pus);
2297 
2298  for (j = 0; j < size_in_pus; j++) {
2299  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2300  }
2301  }
2302 
2303  return intra_pred_mode;
2304 }
2305 
2306 static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth,
2307  int x0, int y0,
2308  int log2_cb_size, int ct_depth)
2309 {
2310  int length = (1 << log2_cb_size) >> sps->log2_min_cb_size;
2311  int x_cb = x0 >> sps->log2_min_cb_size;
2312  int y_cb = y0 >> sps->log2_min_cb_size;
2313  int y;
2314 
2315  for (y = 0; y < length; y++)
2316  memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb],
2317  ct_depth, length);
2318 }
2319 
2320 static const uint8_t tab_mode_idx[] = {
2321  0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2322  21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2323 
2325  const HEVCLayerContext *l, const HEVCSPS *sps,
2326  int x0, int y0,
2327  int log2_cb_size)
2328 {
2329  static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2330  uint8_t prev_intra_luma_pred_flag[4];
2331  int split = lc->cu.part_mode == PART_NxN;
2332  int pb_size = (1 << log2_cb_size) >> split;
2333  int side = split + 1;
2334  int chroma_mode;
2335  int i, j;
2336 
2337  for (i = 0; i < side; i++)
2338  for (j = 0; j < side; j++)
2339  prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc);
2340 
2341  for (i = 0; i < side; i++) {
2342  for (j = 0; j < side; j++) {
2343  if (prev_intra_luma_pred_flag[2 * i + j])
2344  lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc);
2345  else
2347 
2348  lc->pu.intra_pred_mode[2 * i + j] =
2349  luma_intra_pred_mode(lc, l, sps,
2350  x0 + pb_size * j, y0 + pb_size * i, pb_size,
2351  prev_intra_luma_pred_flag[2 * i + j]);
2352  }
2353  }
2354 
2355  if (sps->chroma_format_idc == 3) {
2356  for (i = 0; i < side; i++) {
2357  for (j = 0; j < side; j++) {
2358  lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2359  if (chroma_mode != 4) {
2360  if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode])
2361  lc->pu.intra_pred_mode_c[2 * i + j] = 34;
2362  else
2363  lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode];
2364  } else {
2365  lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j];
2366  }
2367  }
2368  }
2369  } else if (sps->chroma_format_idc == 2) {
2370  int mode_idx;
2371  lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2372  if (chroma_mode != 4) {
2373  if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2374  mode_idx = 34;
2375  else
2376  mode_idx = intra_chroma_table[chroma_mode];
2377  } else {
2378  mode_idx = lc->pu.intra_pred_mode[0];
2379  }
2380  lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
2381  } else if (sps->chroma_format_idc != 0) {
2382  chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2383  if (chroma_mode != 4) {
2384  if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2385  lc->pu.intra_pred_mode_c[0] = 34;
2386  else
2387  lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2388  } else {
2389  lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2390  }
2391  }
2392 }
2393 
2395  const HEVCLayerContext *l,
2396  const HEVCSPS *sps,
2397  int x0, int y0,
2398  int log2_cb_size)
2399 {
2400  const HEVCContext *const s = lc->parent;
2401  int pb_size = 1 << log2_cb_size;
2402  int size_in_pus = pb_size >> sps->log2_min_pu_size;
2403  int min_pu_width = sps->min_pu_width;
2404  MvField *tab_mvf = s->cur_frame->tab_mvf;
2405  int x_pu = x0 >> sps->log2_min_pu_size;
2406  int y_pu = y0 >> sps->log2_min_pu_size;
2407  int j, k;
2408 
2409  if (size_in_pus == 0)
2410  size_in_pus = 1;
2411  for (j = 0; j < size_in_pus; j++)
2412  memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2413  if (lc->cu.pred_mode == MODE_INTRA)
2414  for (j = 0; j < size_in_pus; j++)
2415  for (k = 0; k < size_in_pus; k++)
2416  tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
2417 }
2418 
2420  const HEVCLayerContext *l,
2421  const HEVCPPS *pps, const HEVCSPS *sps,
2422  int x0, int y0, int log2_cb_size)
2423 {
2424  int cb_size = 1 << log2_cb_size;
2425  int log2_min_cb_size = sps->log2_min_cb_size;
2426  int length = cb_size >> log2_min_cb_size;
2427  int min_cb_width = sps->min_cb_width;
2428  int x_cb = x0 >> log2_min_cb_size;
2429  int y_cb = y0 >> log2_min_cb_size;
2430  int idx = log2_cb_size - 2;
2431  int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2432  int x, y, ret;
2433 
2434  lc->cu.x = x0;
2435  lc->cu.y = y0;
2436  lc->cu.pred_mode = MODE_INTRA;
2437  lc->cu.part_mode = PART_2Nx2N;
2438  lc->cu.intra_split_flag = 0;
2439 
2440  SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0;
2441  for (x = 0; x < 4; x++)
2442  lc->pu.intra_pred_mode[x] = 1;
2443  if (pps->transquant_bypass_enable_flag) {
2445  if (lc->cu.cu_transquant_bypass_flag)
2446  set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2447  } else
2448  lc->cu.cu_transquant_bypass_flag = 0;
2449 
2450  if (s->sh.slice_type != HEVC_SLICE_I) {
2451  const int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2452  const int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2453  uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag,
2454  x0b, y0b, x_cb, y_cb,
2455  min_cb_width);
2456 
2457  x = y_cb * min_cb_width + x_cb;
2458  for (y = 0; y < length; y++) {
2459  memset(&l->skip_flag[x], skip_flag, length);
2460  x += min_cb_width;
2461  }
2462  lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2463  } else {
2464  x = y_cb * min_cb_width + x_cb;
2465  for (y = 0; y < length; y++) {
2466  memset(&l->skip_flag[x], 0, length);
2467  x += min_cb_width;
2468  }
2469  }
2470 
2471  if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) {
2472  hls_prediction_unit(lc, l, pps, sps,
2473  x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2474  intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2475 
2476  if (!s->sh.disable_deblocking_filter_flag)
2477  ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2478  } else {
2479  int pcm_flag = 0;
2480 
2481  if (s->sh.slice_type != HEVC_SLICE_I)
2483  if (lc->cu.pred_mode != MODE_INTRA ||
2484  log2_cb_size == sps->log2_min_cb_size) {
2485  lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size);
2486  lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2487  lc->cu.pred_mode == MODE_INTRA;
2488  }
2489 
2490  if (lc->cu.pred_mode == MODE_INTRA) {
2491  if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled &&
2492  log2_cb_size >= sps->pcm.log2_min_pcm_cb_size &&
2493  log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2494  pcm_flag = ff_hevc_pcm_flag_decode(lc);
2495  }
2496  if (pcm_flag) {
2497  intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2498  ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size);
2499  if (sps->pcm_loop_filter_disabled)
2500  set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2501 
2502  if (ret < 0)
2503  return ret;
2504  } else {
2505  intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size);
2506  }
2507  } else {
2508  intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2509  switch (lc->cu.part_mode) {
2510  case PART_2Nx2N:
2511  hls_prediction_unit(lc, l, pps, sps,
2512  x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2513  break;
2514  case PART_2NxN:
2515  hls_prediction_unit(lc, l, pps, sps,
2516  x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2517  hls_prediction_unit(lc, l, pps, sps,
2518  x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2519  break;
2520  case PART_Nx2N:
2521  hls_prediction_unit(lc, l, pps, sps,
2522  x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2523  hls_prediction_unit(lc, l, pps, sps,
2524  x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2525  break;
2526  case PART_2NxnU:
2527  hls_prediction_unit(lc, l, pps, sps,
2528  x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2529  hls_prediction_unit(lc, l, pps, sps,
2530  x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2531  break;
2532  case PART_2NxnD:
2533  hls_prediction_unit(lc, l, pps, sps,
2534  x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2535  hls_prediction_unit(lc, l, pps, sps,
2536  x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2537  break;
2538  case PART_nLx2N:
2539  hls_prediction_unit(lc, l, pps, sps,
2540  x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2541  hls_prediction_unit(lc, l, pps, sps,
2542  x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2543  break;
2544  case PART_nRx2N:
2545  hls_prediction_unit(lc, l, pps, sps,
2546  x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2547  hls_prediction_unit(lc, l, pps, sps,
2548  x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2549  break;
2550  case PART_NxN:
2551  hls_prediction_unit(lc, l, pps, sps,
2552  x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2553  hls_prediction_unit(lc, l, pps, sps,
2554  x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2555  hls_prediction_unit(lc, l, pps, sps,
2556  x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2557  hls_prediction_unit(lc, l, pps, sps,
2558  x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2559  break;
2560  }
2561  }
2562 
2563  if (!pcm_flag) {
2564  int rqt_root_cbf = 1;
2565 
2566  if (lc->cu.pred_mode != MODE_INTRA &&
2567  !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2568  rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc);
2569  }
2570  if (rqt_root_cbf) {
2571  const static int cbf[2] = { 0 };
2572  lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2573  sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2574  sps->max_transform_hierarchy_depth_inter;
2575  ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0,
2576  log2_cb_size,
2577  log2_cb_size, 0, 0, cbf, cbf);
2578  if (ret < 0)
2579  return ret;
2580  } else {
2581  if (!s->sh.disable_deblocking_filter_flag)
2582  ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2583  }
2584  }
2585  }
2586 
2587  if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2588  ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size);
2589 
2590  x = y_cb * min_cb_width + x_cb;
2591  for (y = 0; y < length; y++) {
2592  memset(&l->qp_y_tab[x], lc->qp_y, length);
2593  x += min_cb_width;
2594  }
2595 
2596  if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2597  ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2598  lc->qPy_pred = lc->qp_y;
2599  }
2600 
2601  set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth);
2602 
2603  return 0;
2604 }
2605 
2607  const HEVCLayerContext *l,
2608  const HEVCPPS *pps, const HEVCSPS *sps,
2609  int x0, int y0,
2610  int log2_cb_size, int cb_depth)
2611 {
2612  const HEVCContext *const s = lc->parent;
2613  const int cb_size = 1 << log2_cb_size;
2614  int ret;
2615  int split_cu;
2616 
2617  lc->ct_depth = cb_depth;
2618  if (x0 + cb_size <= sps->width &&
2619  y0 + cb_size <= sps->height &&
2620  log2_cb_size > sps->log2_min_cb_size) {
2622  sps, cb_depth, x0, y0);
2623  } else {
2624  split_cu = (log2_cb_size > sps->log2_min_cb_size);
2625  }
2626  if (pps->cu_qp_delta_enabled_flag &&
2627  log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) {
2628  lc->tu.is_cu_qp_delta_coded = 0;
2629  lc->tu.cu_qp_delta = 0;
2630  }
2631 
2632  if (s->sh.cu_chroma_qp_offset_enabled_flag &&
2633  log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) {
2635  }
2636 
2637  if (split_cu) {
2638  int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2639  const int cb_size_split = cb_size >> 1;
2640  const int x1 = x0 + cb_size_split;
2641  const int y1 = y0 + cb_size_split;
2642 
2643  int more_data = 0;
2644 
2645  more_data = hls_coding_quadtree(lc, l, pps, sps,
2646  x0, y0, log2_cb_size - 1, cb_depth + 1);
2647  if (more_data < 0)
2648  return more_data;
2649 
2650  if (more_data && x1 < sps->width) {
2651  more_data = hls_coding_quadtree(lc, l, pps, sps,
2652  x1, y0, log2_cb_size - 1, cb_depth + 1);
2653  if (more_data < 0)
2654  return more_data;
2655  }
2656  if (more_data && y1 < sps->height) {
2657  more_data = hls_coding_quadtree(lc, l, pps, sps,
2658  x0, y1, log2_cb_size - 1, cb_depth + 1);
2659  if (more_data < 0)
2660  return more_data;
2661  }
2662  if (more_data && x1 < sps->width &&
2663  y1 < sps->height) {
2664  more_data = hls_coding_quadtree(lc, l, pps, sps,
2665  x1, y1, log2_cb_size - 1, cb_depth + 1);
2666  if (more_data < 0)
2667  return more_data;
2668  }
2669 
2670  if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2671  ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2672  lc->qPy_pred = lc->qp_y;
2673 
2674  if (more_data)
2675  return ((x1 + cb_size_split) < sps->width ||
2676  (y1 + cb_size_split) < sps->height);
2677  else
2678  return 0;
2679  } else {
2680  ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size);
2681  if (ret < 0)
2682  return ret;
2683  if ((!((x0 + cb_size) %
2684  (1 << (sps->log2_ctb_size))) ||
2685  (x0 + cb_size >= sps->width)) &&
2686  (!((y0 + cb_size) %
2687  (1 << (sps->log2_ctb_size))) ||
2688  (y0 + cb_size >= sps->height))) {
2689  int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc);
2690  return !end_of_slice_flag;
2691  } else {
2692  return 1;
2693  }
2694  }
2695 
2696  return 0;
2697 }
2698 
2700  const HEVCLayerContext *l,
2701  const HEVCPPS *pps, const HEVCSPS *sps,
2702  int x_ctb, int y_ctb, int ctb_addr_ts)
2703 {
2704  const HEVCContext *const s = lc->parent;
2705  int ctb_size = 1 << sps->log2_ctb_size;
2706  int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2707  int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2708 
2709  l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2710 
2711  if (pps->entropy_coding_sync_enabled_flag) {
2712  if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2713  lc->first_qp_group = 1;
2714  lc->end_of_tiles_x = sps->width;
2715  } else if (pps->tiles_enabled_flag) {
2716  if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
2717  int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size];
2718  lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size);
2719  lc->first_qp_group = 1;
2720  }
2721  } else {
2722  lc->end_of_tiles_x = sps->width;
2723  }
2724 
2725  lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height);
2726 
2727  lc->boundary_flags = 0;
2728  if (pps->tiles_enabled_flag) {
2729  if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2731  if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1])
2733  if (y_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - sps->ctb_width]])
2735  if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width])
2737  } else {
2738  if (ctb_addr_in_slice <= 0)
2740  if (ctb_addr_in_slice < sps->ctb_width)
2742  }
2743 
2744  lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2745  lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2746  lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - sps->ctb_width]]));
2747  lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - sps->ctb_width]]));
2748 }
2749 
2751 {
2752  HEVCLocalContext *const lc = &s->local_ctx[0];
2753  const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2754  const HEVCPPS *const pps = s->pps;
2755  const HEVCSPS *const sps = pps->sps;
2756  const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
2757  const size_t slice_size = get_bits_bytesize(gb, 1) - s->sh.data_offset;
2758  int ctb_size = 1 << sps->log2_ctb_size;
2759  int more_data = 1;
2760  int x_ctb = 0;
2761  int y_ctb = 0;
2762  int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2763  int ret;
2764 
2765  while (more_data && ctb_addr_ts < sps->ctb_size) {
2766  int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2767 
2768  x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2769  y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2770  hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2771 
2772  ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0);
2773  if (ret < 0) {
2774  l->tab_slice_address[ctb_addr_rs] = -1;
2775  return ret;
2776  }
2777 
2778  hls_sao_param(lc, l, pps, sps,
2779  x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2780 
2781  l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2782  l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2783  l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2784 
2785  more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2786  if (more_data < 0) {
2787  l->tab_slice_address[ctb_addr_rs] = -1;
2788  return more_data;
2789  }
2790 
2791 
2792  ctb_addr_ts++;
2793  ff_hevc_save_states(lc, pps, ctb_addr_ts);
2794  ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2795  }
2796 
2797  if (x_ctb + ctb_size >= sps->width &&
2798  y_ctb + ctb_size >= sps->height)
2799  ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2800 
2801  return ctb_addr_ts;
2802 }
2803 
2804 static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist,
2805  int job, int thread)
2806 {
2807  HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread];
2808  const HEVCContext *const s = lc->parent;
2809  const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2810  const HEVCPPS *const pps = s->pps;
2811  const HEVCSPS *const sps = pps->sps;
2812  int ctb_size = 1 << sps->log2_ctb_size;
2813  int more_data = 1;
2814  int ctb_row = job;
2815  int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size);
2816  int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2817 
2818  const uint8_t *data = s->data + s->sh.offset[ctb_row];
2819  const size_t data_size = s->sh.size[ctb_row];
2820 
2821  int progress = 0;
2822 
2823  int ret;
2824 
2825  if (ctb_row)
2826  ff_init_cabac_decoder(&lc->cc, data, data_size);
2827 
2828  while(more_data && ctb_addr_ts < sps->ctb_size) {
2829  int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
2830  int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
2831 
2832  hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2833 
2834  if (ctb_row)
2835  ff_thread_progress_await(&s->wpp_progress[ctb_row - 1],
2836  progress + SHIFT_CTB_WPP + 1);
2837 
2838  /* atomic_load's prototype requires a pointer to non-const atomic variable
2839  * (due to implementations via mutexes, where reads involve writes).
2840  * Of course, casting const away here is nevertheless safe. */
2841  if (atomic_load((atomic_int*)&s->wpp_err)) {
2842  ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2843  return 0;
2844  }
2845 
2846  ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
2847  if (ret < 0)
2848  goto error;
2849  hls_sao_param(lc, l, pps, sps,
2850  x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2851 
2852  l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2853  l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2854  l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2855 
2856  more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2857 
2858  if (more_data < 0) {
2859  ret = more_data;
2860  goto error;
2861  }
2862 
2863  ctb_addr_ts++;
2864 
2865  ff_hevc_save_states(lc, pps, ctb_addr_ts);
2866  ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress);
2867  ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2868 
2869  if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) {
2870  /* Casting const away here is safe, because it is an atomic operation. */
2871  atomic_store((atomic_int*)&s->wpp_err, 1);
2872  ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2873  return 0;
2874  }
2875 
2876  if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) {
2877  ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2878  ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2879  return ctb_addr_ts;
2880  }
2881  ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2882  x_ctb+=ctb_size;
2883 
2884  if(x_ctb >= sps->width) {
2885  break;
2886  }
2887  }
2888  ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2889 
2890  return 0;
2891 error:
2892  l->tab_slice_address[ctb_addr_rs] = -1;
2893  /* Casting const away here is safe, because it is an atomic operation. */
2894  atomic_store((atomic_int*)&s->wpp_err, 1);
2895  ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2896  return ret;
2897 }
2898 
2899 static int wpp_progress_init(HEVCContext *s, unsigned count)
2900 {
2901  if (s->nb_wpp_progress < count) {
2902  void *tmp = av_realloc_array(s->wpp_progress, count,
2903  sizeof(*s->wpp_progress));
2904  if (!tmp)
2905  return AVERROR(ENOMEM);
2906 
2907  s->wpp_progress = tmp;
2908  memset(s->wpp_progress + s->nb_wpp_progress, 0,
2909  (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress));
2910 
2911  for (int i = s->nb_wpp_progress; i < count; i++) {
2912  int ret = ff_thread_progress_init(&s->wpp_progress[i], 1);
2913  if (ret < 0)
2914  return ret;
2915  s->nb_wpp_progress = i + 1;
2916  }
2917  }
2918 
2919  for (int i = 0; i < count; i++)
2920  ff_thread_progress_reset(&s->wpp_progress[i]);
2921 
2922  return 0;
2923 }
2924 
2925 static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
2926 {
2927  const HEVCPPS *const pps = s->pps;
2928  const HEVCSPS *const sps = pps->sps;
2929  const uint8_t *data = nal->data;
2930  int length = nal->size;
2931  int *ret;
2932  int64_t offset;
2933  int64_t startheader, cmpt = 0;
2934  int i, j, res = 0;
2935 
2936  if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * sps->ctb_width >= sps->ctb_width * sps->ctb_height) {
2937  av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
2938  s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
2939  sps->ctb_width, sps->ctb_height
2940  );
2941  return AVERROR_INVALIDDATA;
2942  }
2943 
2944  if (s->avctx->thread_count > s->nb_local_ctx) {
2945  HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx));
2946 
2947  if (!tmp)
2948  return AVERROR(ENOMEM);
2949 
2950  memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx);
2951  av_free(s->local_ctx);
2952  s->local_ctx = tmp;
2953 
2954  for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) {
2955  tmp = &s->local_ctx[i];
2956 
2957  memset(tmp, 0, sizeof(*tmp));
2958 
2959  tmp->logctx = s->avctx;
2960  tmp->parent = s;
2961  tmp->common_cabac_state = &s->cabac;
2962  }
2963 
2964  s->nb_local_ctx = s->avctx->thread_count;
2965  }
2966 
2967  offset = s->sh.data_offset;
2968 
2969  for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2970  if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2971  startheader--;
2972  cmpt++;
2973  }
2974  }
2975 
2976  for (i = 1; i < s->sh.num_entry_point_offsets; i++) {
2977  offset += (s->sh.entry_point_offset[i - 1] - cmpt);
2978  for (j = 0, cmpt = 0, startheader = offset
2979  + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
2980  if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2981  startheader--;
2982  cmpt++;
2983  }
2984  }
2985  s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt;
2986  s->sh.offset[i] = offset;
2987 
2988  }
2989 
2990  offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
2991  if (length < offset) {
2992  av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
2993  return AVERROR_INVALIDDATA;
2994  }
2995  s->sh.size [s->sh.num_entry_point_offsets] = length - offset;
2996  s->sh.offset[s->sh.num_entry_point_offsets] = offset;
2997 
2998  s->sh.offset[0] = s->sh.data_offset;
2999  s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0];
3000 
3001  s->data = data;
3002 
3003  for (i = 1; i < s->nb_local_ctx; i++) {
3004  s->local_ctx[i].first_qp_group = 1;
3005  s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
3006  }
3007 
3008  atomic_store(&s->wpp_err, 0);
3009  res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1);
3010  if (res < 0)
3011  return res;
3012 
3013  ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret));
3014  if (!ret)
3015  return AVERROR(ENOMEM);
3016 
3017  if (pps->entropy_coding_sync_enabled_flag)
3018  s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1);
3019 
3020  for (i = 0; i <= s->sh.num_entry_point_offsets; i++)
3021  res += ret[i];
3022 
3023  av_free(ret);
3024  return res;
3025 }
3026 
3028  const H2645NAL *nal, GetBitContext *gb)
3029 {
3030  const HEVCPPS *pps = s->pps;
3031  int ret;
3032 
3033  if (!s->sh.first_slice_in_pic_flag)
3034  s->slice_idx += !s->sh.dependent_slice_segment_flag;
3035 
3036  if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) {
3037  ret = ff_hevc_slice_rpl(s);
3038  if (ret < 0) {
3039  av_log(s->avctx, AV_LOG_WARNING,
3040  "Error constructing the reference lists for the current slice.\n");
3041  return ret;
3042  }
3043  }
3044 
3045  s->slice_initialized = 1;
3046 
3047  if (s->avctx->hwaccel)
3048  return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
3049 
3050  if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
3051  av_log(s->avctx, AV_LOG_ERROR,
3052  "SCC profile is not yet implemented in hevc native decoder.\n");
3053  return AVERROR_PATCHWELCOME;
3054  }
3055 
3056  if (s->sh.dependent_slice_segment_flag) {
3057  int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
3058  int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
3059  if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) {
3060  av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
3061  return AVERROR_INVALIDDATA;
3062  }
3063  }
3064 
3065  s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
3066 
3067  if (!pps->cu_qp_delta_enabled_flag)
3068  s->local_ctx[0].qp_y = s->sh.slice_qp;
3069 
3070  s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3071  s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3072 
3073  if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
3074  s->sh.num_entry_point_offsets > 0 &&
3075  pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
3076  return hls_slice_data_wpp(s, nal);
3077 
3078  return hls_decode_entry(s, gb);
3079 }
3080 
3082 {
3083  const HEVCSPS *sps = s->cur_frame->pps->sps;
3084  AVFrame *out = s->cur_frame->f;
3085  int ret;
3086 
3087  // Decrement the mastering display and content light level flag when IRAP
3088  // frame has no_rasl_output_flag=1 so the side data persists for the entire
3089  // coded video sequence.
3090  if (IS_IRAP(s) && s->no_rasl_output_flag) {
3091  if (s->sei.common.mastering_display.present > 0)
3092  s->sei.common.mastering_display.present--;
3093 
3094  if (s->sei.common.content_light.present > 0)
3095  s->sei.common.content_light.present--;
3096  }
3097 
3098  ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
3099  &sps->vui.common,
3100  sps->bit_depth, sps->bit_depth_chroma,
3101  s->cur_frame->poc /* no poc_offset in HEVC */);
3102  if (ret < 0)
3103  return ret;
3104 
3105  if (s->sei.timecode.present) {
3106  uint32_t *tc_sd;
3107  char tcbuf[AV_TIMECODE_STR_SIZE];
3108  AVFrameSideData *tcside;
3110  sizeof(uint32_t) * 4, &tcside);
3111  if (ret < 0)
3112  return ret;
3113 
3114  if (tcside) {
3115  tc_sd = (uint32_t*)tcside->data;
3116  tc_sd[0] = s->sei.timecode.num_clock_ts;
3117 
3118  for (int i = 0; i < tc_sd[0]; i++) {
3119  int drop = s->sei.timecode.cnt_dropped_flag[i];
3120  int hh = s->sei.timecode.hours_value[i];
3121  int mm = s->sei.timecode.minutes_value[i];
3122  int ss = s->sei.timecode.seconds_value[i];
3123  int ff = s->sei.timecode.n_frames[i];
3124 
3125  tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
3126  av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
3127  av_dict_set(&out->metadata, "timecode", tcbuf, 0);
3128  }
3129  }
3130 
3131  s->sei.timecode.num_clock_ts = 0;
3132  }
3133 
3134  if (s->sei.common.dynamic_hdr_plus.info) {
3135  AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_plus.info);
3136  if (!info_ref)
3137  return AVERROR(ENOMEM);
3138 
3140  if (ret < 0)
3141  return ret;
3142  }
3143 
3144  if (s->rpu_buf) {
3146  if (!rpu)
3147  return AVERROR(ENOMEM);
3148 
3149  s->rpu_buf = NULL;
3150  }
3151 
3152  if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0)
3153  return ret;
3154 
3155  if (s->sei.common.dynamic_hdr_vivid.info) {
3156  if (!av_frame_side_data_add(&out->side_data, &out->nb_side_data,
3158  &s->sei.common.dynamic_hdr_vivid.info,
3160  return AVERROR(ENOMEM);
3161  }
3162 
3163  return 0;
3164 }
3165 
3167 {
3168  int nal_idx = 0;
3169 
3170  for (int i = nal_idx; i < s->pkt.nb_nals; i++) {
3171  const H2645NAL *nal = &s->pkt.nals[i];
3172  const int layer_id = nal->nuh_layer_id;
3173  GetBitContext gb = nal->gb;
3174 
3175  if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 ||
3176  !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id])))
3177  continue;
3178 
3179  switch (nal->type) {
3180  case HEVC_NAL_TRAIL_R:
3181  case HEVC_NAL_TRAIL_N:
3182  case HEVC_NAL_TSA_N:
3183  case HEVC_NAL_TSA_R:
3184  case HEVC_NAL_STSA_N:
3185  case HEVC_NAL_STSA_R:
3186  case HEVC_NAL_BLA_W_LP:
3187  case HEVC_NAL_BLA_W_RADL:
3188  case HEVC_NAL_BLA_N_LP:
3189  case HEVC_NAL_IDR_W_RADL:
3190  case HEVC_NAL_IDR_N_LP:
3191  case HEVC_NAL_CRA_NUT:
3192  case HEVC_NAL_RADL_N:
3193  case HEVC_NAL_RADL_R:
3194  case HEVC_NAL_RASL_N:
3195  case HEVC_NAL_RASL_R:
3196  if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag
3197  continue;
3198  case HEVC_NAL_VPS:
3199  case HEVC_NAL_SPS:
3200  case HEVC_NAL_PPS:
3201  nal_idx = i;
3202  break;
3203  }
3204  }
3205 
3206  return nal_idx;
3207 }
3208 
3210  unsigned nal_idx)
3211 {
3212  const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
3213  const HEVCSPS *const sps = pps->sps;
3214  int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
3215  ((sps->height >> sps->log2_min_cb_size) + 1);
3216  int new_sequence = (l == &s->layers[0]) &&
3217  (IS_IDR(s) || IS_BLA(s) || s->last_eos);
3218  int prev_layers_active_decode = s->layers_active_decode;
3219  int prev_layers_active_output = s->layers_active_output;
3220  int ret;
3221 
3222  if (sps->vps != s->vps && l != &s->layers[0]) {
3223  av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n");
3224  set_sps(s, l, NULL);
3225  return AVERROR_INVALIDDATA;
3226  }
3227 
3228  av_refstruct_replace(&s->pps, pps);
3229  if (l->sps != sps) {
3230  const HEVCSPS *sps_base = s->layers[0].sps;
3231  enum AVPixelFormat pix_fmt = sps->pix_fmt;
3232 
3233  if (l != &s->layers[0]) {
3234  if (!sps_base) {
3235  av_log(s->avctx, AV_LOG_ERROR,
3236  "Access unit starts with a non-base layer frame\n");
3237  return AVERROR_INVALIDDATA;
3238  }
3239 
3240  // Files produced by Vision Pro lack VPS extension VUI,
3241  // so the secondary layer has no range information.
3242  // This check avoids failing in such a case.
3243  if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P &&
3244  sps->pix_fmt == AV_PIX_FMT_YUV420P &&
3245  !sps->vui.common.video_signal_type_present_flag)
3246  pix_fmt = sps_base->pix_fmt;
3247 
3248  // Ignore range mismatch between base layer and alpha layer
3249  if (ff_hevc_is_alpha_video(s) &&
3250  sps_base->pix_fmt == AV_PIX_FMT_YUV420P &&
3252  pix_fmt = sps_base->pix_fmt;
3253 
3254  if (pix_fmt != sps_base->pix_fmt ||
3255  sps->width != sps_base->width ||
3256  sps->height != sps_base->height) {
3257  av_log(s->avctx, AV_LOG_ERROR,
3258  "Base/non-base layer SPS have unsupported parameter combination\n");
3259  return AVERROR(ENOSYS);
3260  }
3261  }
3262 
3263  ff_hevc_clear_refs(l);
3264 
3265  ret = set_sps(s, l, sps);
3266  if (ret < 0)
3267  return ret;
3268 
3269  if (l == &s->layers[0]) {
3271 
3272  ret = get_format(s, sps);
3273  if (ret < 0) {
3274  set_sps(s, l, NULL);
3275  return ret;
3276  }
3277 
3278  new_sequence = 1;
3279  }
3280  }
3281 
3282  memset(l->horizontal_bs, 0, l->bs_width * l->bs_height);
3283  memset(l->vertical_bs, 0, l->bs_width * l->bs_height);
3284  memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
3285  memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
3286  memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address));
3287 
3288  if (IS_IDR(s))
3289  ff_hevc_clear_refs(l);
3290 
3291  s->slice_idx = 0;
3292  s->first_nal_type = s->nal_unit_type;
3293  s->poc = s->sh.poc;
3294 
3295  if (IS_IRAP(s)) {
3296  s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
3297  (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
3298  s->recovery_poc = HEVC_RECOVERY_END;
3299  }
3300 
3301  if (s->recovery_poc != HEVC_RECOVERY_END &&
3302  s->sei.recovery_point.has_recovery_poc) {
3303  if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED)
3304  s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt;
3305  else if (s->poc >= s->recovery_poc)
3306  s->recovery_poc = HEVC_RECOVERY_END;
3307  }
3308 
3309  /* 8.3.1 */
3310  if (s->temporal_id == 0 &&
3311  s->nal_unit_type != HEVC_NAL_TRAIL_N &&
3312  s->nal_unit_type != HEVC_NAL_TSA_N &&
3313  s->nal_unit_type != HEVC_NAL_STSA_N &&
3314  s->nal_unit_type != HEVC_NAL_RADL_N &&
3315  s->nal_unit_type != HEVC_NAL_RADL_R &&
3316  s->nal_unit_type != HEVC_NAL_RASL_N &&
3317  s->nal_unit_type != HEVC_NAL_RASL_R)
3318  s->poc_tid0 = s->poc;
3319 
3320  if (pps->tiles_enabled_flag)
3321  s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
3322 
3323  if (new_sequence) {
3324  ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output,
3325  0, 0, s->sh.no_output_of_prior_pics_flag);
3326  if (ret < 0)
3327  return ret;
3328  }
3329 
3331  if (ret < 0)
3332  return ret;
3333 
3334  ret = ff_hevc_set_new_ref(s, l, s->poc);
3335  if (ret < 0)
3336  goto fail;
3337 
3338  ret = ff_hevc_frame_rps(s, l);
3339  if (ret < 0) {
3340  av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
3341  goto fail;
3342  }
3343 
3344  if (IS_IRAP(s))
3345  s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY;
3346  else
3347  s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY;
3348 
3349  s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics &&
3350  s->sei.common.film_grain_characteristics->present) ||
3351  s->sei.common.aom_film_grain.enable) &&
3352  !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
3353  !s->avctx->hwaccel;
3354 
3355  ret = set_side_data(s);
3356  if (ret < 0)
3357  goto fail;
3358 
3359  if (s->cur_frame->needs_fg &&
3360  (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present &&
3361  !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id,
3362  s->cur_frame->f->format) ||
3363  !av_film_grain_params_select(s->cur_frame->f))) {
3364  av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
3365  "Unsupported film grain parameters. Ignoring film grain.\n");
3366  s->cur_frame->needs_fg = 0;
3367  }
3368 
3369  if (s->cur_frame->needs_fg) {
3370  s->cur_frame->frame_grain->format = s->cur_frame->f->format;
3371  s->cur_frame->frame_grain->width = s->cur_frame->f->width;
3372  s->cur_frame->frame_grain->height = s->cur_frame->f->height;
3373  if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
3374  goto fail;
3375 
3376  ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
3377  if (ret < 0)
3378  goto fail;
3379  }
3380 
3381  s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
3382 
3383  ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output,
3384  sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics,
3385  sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3386  if (ret < 0)
3387  goto fail;
3388 
3389  if (s->avctx->hwaccel) {
3390  AVCodecInternal *avci = s->avctx->internal;
3391  AVPacket *avpkt = avci->in_pkt;
3392  ret = FF_HW_CALL(s->avctx, start_frame,
3393  avpkt->buf, NULL, 0);
3394  if (ret < 0)
3395  goto fail;
3396  }
3397 
3398  // after starting the base-layer frame we know which layers will be decoded,
3399  // so we can now figure out which NALUs to wait for before we can call
3400  // ff_thread_finish_setup()
3401  if (l == &s->layers[0])
3402  s->finish_setup_nal_idx = find_finish_setup_nal(s);
3403 
3404  if (nal_idx >= s->finish_setup_nal_idx)
3405  ff_thread_finish_setup(s->avctx);
3406 
3407  return 0;
3408 
3409 fail:
3410  if (l->cur_frame)
3412  l->cur_frame = NULL;
3413  s->cur_frame = s->collocated_ref = NULL;
3414  return ret;
3415 }
3416 
3418 {
3420  char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
3421  int pixel_shift;
3422  int err = 0;
3423  int i, j;
3424 
3425  if (!desc)
3426  return AVERROR(EINVAL);
3427 
3428  pixel_shift = desc->comp[0].depth > 8;
3429 
3430  /* the checksums are LE, so we have to byteswap for >8bpp formats
3431  * on BE arches */
3432 #if HAVE_BIGENDIAN
3433  if (pixel_shift && !s->checksum_buf) {
3434  av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
3435  FFMAX3(frame->linesize[0], frame->linesize[1],
3436  frame->linesize[2]));
3437  if (!s->checksum_buf)
3438  return AVERROR(ENOMEM);
3439  }
3440 #endif
3441 
3442  msg_buf[0] = '\0';
3443  for (i = 0; frame->data[i]; i++) {
3444  int width = s->avctx->coded_width;
3445  int height = s->avctx->coded_height;
3446  int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
3447  int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
3448  uint8_t md5[16];
3449 
3450  av_md5_init(s->md5_ctx);
3451  for (j = 0; j < h; j++) {
3452  const uint8_t *src = frame->data[i] + j * frame->linesize[i];
3453 #if HAVE_BIGENDIAN
3454  if (pixel_shift) {
3455  s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
3456  (const uint16_t *) src, w);
3457  src = s->checksum_buf;
3458  }
3459 #endif
3460  av_md5_update(s->md5_ctx, src, w << pixel_shift);
3461  }
3462  av_md5_final(s->md5_ctx, md5);
3463 
3464 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3465 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3466 
3467  if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
3468  av_strlcatf(msg_buf, sizeof(msg_buf),
3469  "plane %d - correct " MD5_PRI "; ",
3470  i, MD5_PRI_ARG(md5));
3471  } else {
3472  av_strlcatf(msg_buf, sizeof(msg_buf),
3473  "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3474  i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
3475  err = AVERROR_INVALIDDATA;
3476  }
3477  }
3478 
3479  av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
3480  "Verifying checksum for frame with POC %d: %s\n",
3481  s->poc, msg_buf);
3482 
3483  return err;
3484  }
3485 
3487 {
3488  HEVCFrame *out = l->cur_frame;
3489  const AVFilmGrainParams *fgp;
3490  av_unused int ret;
3491 
3492  if (out->needs_fg) {
3493  av_assert0(out->frame_grain->buf[0]);
3494  fgp = av_film_grain_params_select(out->f);
3495  switch (fgp->type) {
3497  av_assert0(0);
3498  return AVERROR_BUG;
3500  ret = ff_h274_apply_film_grain(out->frame_grain, out->f, fgp);
3501  break;
3503  ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp);
3504  break;
3505  }
3506  av_assert1(ret >= 0);
3507  }
3508 
3509  if (s->avctx->hwaccel) {
3510  ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
3511  if (ret < 0) {
3512  av_log(s->avctx, AV_LOG_ERROR,
3513  "hardware accelerator failed to decode picture\n");
3514  return ret;
3515  }
3516  } else {
3517  if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
3518  s->sei.picture_hash.is_md5) {
3519  ret = verify_md5(s, out->f);
3520  if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
3521  return ret;
3522  }
3523  }
3524  s->sei.picture_hash.is_md5 = 0;
3525 
3526  av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n",
3527  l - s->layers, s->poc);
3528 
3529  return 0;
3530 }
3531 
3532 static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb)
3533 {
3534  const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0;
3535  HEVCLayerContext *l;
3536  int ret;
3537 
3538  // skip layers not requested to be decoded
3539  // layers_active_decode can only change while decoding a base-layer frame,
3540  // so we can check it for non-base layers
3541  if (layer_idx < 0 ||
3542  (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx))))
3543  return 0;
3544 
3545  ret = hls_slice_header(&s->sh, s, gb);
3546  // Once hls_slice_header has been called, the context is inconsistent with the slice header
3547  // until the context is reinitialized according to the contents of the new slice header
3548  // at the start of decode_slice_data.
3549  s->slice_initialized = 0;
3550  if (ret < 0) {
3551  return ret;
3552  }
3553 
3554  if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
3555  (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
3556  (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
3557  ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
3558  s->no_rasl_output_flag)) {
3559  return 0;
3560  }
3561 
3562  // switching to a new layer, mark previous layer's frame (if any) as done
3563  if (s->cur_layer != layer_idx &&
3564  s->layers[s->cur_layer].cur_frame &&
3565  s->avctx->active_thread_type == FF_THREAD_FRAME)
3566  ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX);
3567 
3568  s->cur_layer = layer_idx;
3569  l = &s->layers[s->cur_layer];
3570 
3571  if (s->sh.first_slice_in_pic_flag) {
3572  if (l->cur_frame) {
3573  av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
3574  return AVERROR_INVALIDDATA;
3575  }
3576 
3577  ret = hevc_frame_start(s, l, nal_idx);
3578  if (ret < 0)
3579  return ret;
3580  } else if (!l->cur_frame) {
3581  av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
3582  return AVERROR_INVALIDDATA;
3583  }
3584 
3585  if (s->nal_unit_type != s->first_nal_type) {
3586  av_log(s->avctx, AV_LOG_ERROR,
3587  "Non-matching NAL types of the VCL NALUs: %d %d\n",
3588  s->first_nal_type, s->nal_unit_type);
3589  return AVERROR_INVALIDDATA;
3590  }
3591 
3592  ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb);
3593  if (ret < 0)
3594  return ret;
3595 
3596  return 0;
3597 }
3598 
3599 static int decode_nal_unit(HEVCContext *s, unsigned nal_idx)
3600 {
3601  H2645NAL *nal = &s->pkt.nals[nal_idx];
3602  GetBitContext gb = nal->gb;
3603  int ret;
3604 
3605  s->nal_unit_type = nal->type;
3606  s->nuh_layer_id = nal->nuh_layer_id;
3607  s->temporal_id = nal->temporal_id;
3608 
3609  if (FF_HW_HAS_CB(s->avctx, decode_params) &&
3610  (s->nal_unit_type == HEVC_NAL_VPS ||
3611  s->nal_unit_type == HEVC_NAL_SPS ||
3612  s->nal_unit_type == HEVC_NAL_PPS ||
3613  s->nal_unit_type == HEVC_NAL_SEI_PREFIX ||
3614  s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) {
3615  ret = FF_HW_CALL(s->avctx, decode_params,
3616  nal->type, nal->raw_data, nal->raw_size);
3617  if (ret < 0)
3618  goto fail;
3619  }
3620 
3621  switch (s->nal_unit_type) {
3622  case HEVC_NAL_VPS:
3623  ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps);
3624  if (ret < 0)
3625  goto fail;
3626  break;
3627  case HEVC_NAL_SPS:
3628  ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps,
3629  nal->nuh_layer_id, s->apply_defdispwin);
3630  if (ret < 0)
3631  goto fail;
3632  break;
3633  case HEVC_NAL_PPS:
3634  ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps);
3635  if (ret < 0)
3636  goto fail;
3637  break;
3638  case HEVC_NAL_SEI_PREFIX:
3639  case HEVC_NAL_SEI_SUFFIX:
3640  ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
3641  if (ret < 0)
3642  goto fail;
3643  break;
3644  case HEVC_NAL_TRAIL_R:
3645  case HEVC_NAL_TRAIL_N:
3646  case HEVC_NAL_TSA_N:
3647  case HEVC_NAL_TSA_R:
3648  case HEVC_NAL_STSA_N:
3649  case HEVC_NAL_STSA_R:
3650  case HEVC_NAL_BLA_W_LP:
3651  case HEVC_NAL_BLA_W_RADL:
3652  case HEVC_NAL_BLA_N_LP:
3653  case HEVC_NAL_IDR_W_RADL:
3654  case HEVC_NAL_IDR_N_LP:
3655  case HEVC_NAL_CRA_NUT:
3656  case HEVC_NAL_RADL_N:
3657  case HEVC_NAL_RADL_R:
3658  case HEVC_NAL_RASL_N:
3659  case HEVC_NAL_RASL_R:
3660  ret = decode_slice(s, nal_idx, &gb);
3661  if (ret < 0)
3662  goto fail;
3663  break;
3664  case HEVC_NAL_EOS_NUT:
3665  case HEVC_NAL_EOB_NUT:
3666  case HEVC_NAL_AUD:
3667  case HEVC_NAL_FD_NUT:
3668  case HEVC_NAL_UNSPEC62:
3669  break;
3670  default:
3671  av_log(s->avctx, AV_LOG_INFO,
3672  "Skipping NAL unit %d\n", s->nal_unit_type);
3673  }
3674 
3675  return 0;
3676 fail:
3677  if (ret == AVERROR_INVALIDDATA &&
3678  !(s->avctx->err_recognition & AV_EF_EXPLODE)) {
3679  av_log(s->avctx, AV_LOG_WARNING,
3680  "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
3681  return 0;
3682  }
3683  return ret;
3684 }
3685 
3687 {
3688  s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED;
3689  s->sei.recovery_point.has_recovery_poc = 0;
3690 }
3691 
3692 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
3693 {
3694  int i, ret = 0;
3695  int eos_at_start = 1;
3696  int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
3697 
3698  s->cur_frame = s->collocated_ref = NULL;
3699  s->last_eos = s->eos;
3700  s->eos = 0;
3701  s->slice_initialized = 0;
3702  if (s->last_eos)
3704 
3705  for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3706  HEVCLayerContext *l = &s->layers[i];
3707  l->cur_frame = NULL;
3708  }
3709 
3710  /* split the input packet into NAL units, so we know the upper bound on the
3711  * number of slices in the frame */
3712  ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx,
3713  s->nal_length_size, s->avctx->codec_id, flags);
3714  if (ret < 0) {
3715  av_log(s->avctx, AV_LOG_ERROR,
3716  "Error splitting the input into NAL units.\n");
3717  return ret;
3718  }
3719 
3720  for (i = 0; i < s->pkt.nb_nals; i++) {
3721  if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT ||
3722  s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) {
3723  if (eos_at_start) {
3724  s->last_eos = 1;
3726  } else {
3727  s->eos = 1;
3728  }
3729  } else {
3730  eos_at_start = 0;
3731  }
3732  }
3733 
3734  /*
3735  * Check for RPU delimiter.
3736  *
3737  * Dolby Vision RPUs masquerade as unregistered NALs of type 62.
3738  *
3739  * We have to do this check here an create the rpu buffer, since RPUs are appended
3740  * to the end of an AU; they are the last non-EOB/EOS NAL in the AU.
3741  */
3742  if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 &&
3743  s->pkt.nals[s->pkt.nb_nals - 1].size > 2 && !s->pkt.nals[s->pkt.nb_nals - 1].nuh_layer_id
3744  && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) {
3745  H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1];
3746  if (s->rpu_buf) {
3747  av_buffer_unref(&s->rpu_buf);
3748  av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3749  }
3750 
3751  s->rpu_buf = av_buffer_alloc(nal->raw_size - 2);
3752  if (!s->rpu_buf) {
3753  ret = AVERROR(ENOMEM);
3754  goto fail;
3755  }
3756  memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
3757 
3758  ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2,
3759  s->avctx->err_recognition);
3760  if (ret < 0) {
3761  av_buffer_unref(&s->rpu_buf);
3762  av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
3763  /* ignore */
3764  }
3765  }
3766 
3767  /* decode the NAL units */
3768  for (i = 0; i < s->pkt.nb_nals; i++) {
3769  H2645NAL *nal = &s->pkt.nals[i];
3770 
3771  if (s->avctx->skip_frame >= AVDISCARD_ALL ||
3772  (s->avctx->skip_frame >= AVDISCARD_NONREF && ff_hevc_nal_is_nonref(nal->type)))
3773  continue;
3774 
3775  ret = decode_nal_unit(s, i);
3776  if (ret < 0) {
3777  av_log(s->avctx, AV_LOG_WARNING,
3778  "Error parsing NAL unit #%d.\n", i);
3779  goto fail;
3780  }
3781  }
3782 
3783 fail:
3784  for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3785  HEVCLayerContext *l = &s->layers[i];
3786 
3787  if (!l->cur_frame)
3788  continue;
3789 
3790  if (ret >= 0)
3791  ret = hevc_frame_end(s, l);
3792 
3793  if (s->avctx->active_thread_type == FF_THREAD_FRAME)
3794  ff_progress_frame_report(&l->cur_frame->tf, INT_MAX);
3795  }
3796 
3797  return ret;
3798 }
3799 
3800 static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
3801 {
3802  int ret, i;
3803 
3804  ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff,
3805  &s->nal_length_size, s->avctx->err_recognition,
3806  s->apply_defdispwin, s->avctx);
3807  if (ret < 0)
3808  return ret;
3809 
3810  /* export stream parameters from the first SPS */
3811  for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
3812  if (first && s->ps.sps_list[i]) {
3813  const HEVCSPS *sps = s->ps.sps_list[i];
3815 
3816  ret = export_multilayer(s, sps->vps);
3817  if (ret < 0)
3818  return ret;
3819 
3820  break;
3821  }
3822  }
3823 
3824  /* export stream parameters from SEI */
3826  if (ret < 0)
3827  return ret;
3828 
3829  return 0;
3830 }
3831 
3833 {
3834  HEVCContext *s = avctx->priv_data;
3835  AVCodecInternal *avci = avctx->internal;
3836  AVPacket *avpkt = avci->in_pkt;
3837 
3838  int ret;
3839  uint8_t *sd;
3840  size_t sd_size;
3841 
3842  s->pkt_dts = AV_NOPTS_VALUE;
3843 
3844  if (av_container_fifo_can_read(s->output_fifo))
3845  goto do_output;
3846 
3847  av_packet_unref(avpkt);
3848  ret = ff_decode_get_packet(avctx, avpkt);
3849  if (ret == AVERROR_EOF) {
3850  ret = ff_hevc_output_frames(s, s->layers_active_decode,
3851  s->layers_active_output, 0, 0, 0);
3852  if (ret < 0)
3853  return ret;
3854  goto do_output;
3855  } else if (ret < 0)
3856  return ret;
3857 
3858  s->pkt_dts = avpkt->dts;
3859 
3860  sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
3861  if (sd && sd_size > 0) {
3862  ret = hevc_decode_extradata(s, sd, sd_size, 0);
3863  if (ret < 0)
3864  return ret;
3865  }
3866 
3867  sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
3868  if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) {
3869  int old = s->dovi_ctx.cfg.dv_profile;
3870  s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd;
3871  if (old)
3872  av_log(avctx, AV_LOG_DEBUG,
3873  "New DOVI configuration record from input packet (profile %d -> %u).\n",
3874  old, s->dovi_ctx.cfg.dv_profile);
3875  }
3876 
3877  ret = decode_nal_units(s, avpkt->data, avpkt->size);
3878  if (ret < 0)
3879  return ret;
3880 
3881 do_output:
3882  if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) {
3885 
3886  return 0;
3887  }
3888 
3889  return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
3890 }
3891 
3893 {
3894  int ret;
3895 
3896  ff_progress_frame_ref(&dst->tf, &src->tf);
3897 
3898  if (src->needs_fg) {
3899  ret = av_frame_ref(dst->frame_grain, src->frame_grain);
3900  if (ret < 0) {
3901  ff_hevc_unref_frame(dst, ~0);
3902  return ret;
3903  }
3904  dst->needs_fg = 1;
3905  }
3906 
3907  dst->pps = av_refstruct_ref_c(src->pps);
3908  dst->tab_mvf = av_refstruct_ref(src->tab_mvf);
3909  dst->rpl_tab = av_refstruct_ref(src->rpl_tab);
3910  dst->rpl = av_refstruct_ref(src->rpl);
3911  dst->nb_rpl_elems = src->nb_rpl_elems;
3912 
3913  dst->poc = src->poc;
3914  dst->ctb_count = src->ctb_count;
3915  dst->flags = src->flags;
3916 
3917  dst->base_layer_frame = src->base_layer_frame;
3918 
3919  av_refstruct_replace(&dst->hwaccel_picture_private,
3920  src->hwaccel_picture_private);
3921 
3922  return 0;
3923 }
3924 
3926 {
3927  HEVCContext *s = avctx->priv_data;
3928 
3929  for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3930  pic_arrays_free(&s->layers[i]);
3931  av_refstruct_unref(&s->layers[i].sps);
3932  }
3933 
3934  av_refstruct_unref(&s->vps);
3935  av_refstruct_unref(&s->pps);
3936 
3937  ff_dovi_ctx_unref(&s->dovi_ctx);
3938  av_buffer_unref(&s->rpu_buf);
3939 
3940  av_freep(&s->md5_ctx);
3941 
3942  av_container_fifo_free(&s->output_fifo);
3943 
3944  for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3945  HEVCLayerContext *l = &s->layers[layer];
3946  for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3947  ff_hevc_unref_frame(&l->DPB[i], ~0);
3949  }
3950  }
3951 
3952  ff_hevc_ps_uninit(&s->ps);
3953 
3954  for (int i = 0; i < s->nb_wpp_progress; i++)
3955  ff_thread_progress_destroy(&s->wpp_progress[i]);
3956  av_freep(&s->wpp_progress);
3957 
3958  av_freep(&s->sh.entry_point_offset);
3959  av_freep(&s->sh.offset);
3960  av_freep(&s->sh.size);
3961 
3962  av_freep(&s->local_ctx);
3963 
3964  ff_h2645_packet_uninit(&s->pkt);
3965 
3966  ff_hevc_reset_sei(&s->sei);
3967 
3968  return 0;
3969 }
3970 
3972 {
3973  HEVCContext *s = avctx->priv_data;
3974 
3975  s->avctx = avctx;
3976 
3977  s->local_ctx = av_mallocz(sizeof(*s->local_ctx));
3978  if (!s->local_ctx)
3979  return AVERROR(ENOMEM);
3980  s->nb_local_ctx = 1;
3981 
3982  s->local_ctx[0].parent = s;
3983  s->local_ctx[0].logctx = avctx;
3984  s->local_ctx[0].common_cabac_state = &s->cabac;
3985 
3986  s->output_fifo = av_container_fifo_alloc_avframe(0);
3987  if (!s->output_fifo)
3988  return AVERROR(ENOMEM);
3989 
3990  for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3991  HEVCLayerContext *l = &s->layers[layer];
3992  for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3993  l->DPB[i].frame_grain = av_frame_alloc();
3994  if (!l->DPB[i].frame_grain)
3995  return AVERROR(ENOMEM);
3996  }
3997  }
3998 
3999  s->md5_ctx = av_md5_alloc();
4000  if (!s->md5_ctx)
4001  return AVERROR(ENOMEM);
4002 
4003  ff_bswapdsp_init(&s->bdsp);
4004 
4005  s->dovi_ctx.logctx = avctx;
4006  s->eos = 0;
4007 
4008  ff_hevc_reset_sei(&s->sei);
4009 
4010  return 0;
4011 }
4012 
4013 #if HAVE_THREADS
4014 static int hevc_update_thread_context(AVCodecContext *dst,
4015  const AVCodecContext *src)
4016 {
4017  HEVCContext *s = dst->priv_data;
4018  HEVCContext *s0 = src->priv_data;
4019  int ret;
4020 
4021  for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4022  HEVCLayerContext *l = &s->layers[layer];
4023  const HEVCLayerContext *l0 = &s0->layers[layer];
4024  for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4025  ff_hevc_unref_frame(&l->DPB[i], ~0);
4026  if (l0->DPB[i].f) {
4027  ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]);
4028  if (ret < 0)
4029  return ret;
4030  }
4031  }
4032 
4033  if (l->sps != l0->sps) {
4034  ret = set_sps(s, l, l0->sps);
4035  if (ret < 0)
4036  return ret;
4037  }
4038  }
4039 
4040  for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++)
4041  av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
4042 
4043  for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++)
4044  av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]);
4045 
4046  for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++)
4047  av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
4048 
4049  // PPS do not persist between frames
4050  av_refstruct_unref(&s->pps);
4051 
4052  s->poc_tid0 = s0->poc_tid0;
4053  s->eos = s0->eos;
4054  s->no_rasl_output_flag = s0->no_rasl_output_flag;
4055 
4056  s->is_nalff = s0->is_nalff;
4057  s->nal_length_size = s0->nal_length_size;
4058  s->layers_active_decode = s0->layers_active_decode;
4059  s->layers_active_output = s0->layers_active_output;
4060 
4061  s->film_grain_warning_shown = s0->film_grain_warning_shown;
4062 
4063  if (s->nb_view_ids != s0->nb_view_ids ||
4064  memcmp(s->view_ids, s0->view_ids, sizeof(*s->view_ids) * s->nb_view_ids)) {
4065  av_freep(&s->view_ids);
4066  s->nb_view_ids = 0;
4067 
4068  if (s0->nb_view_ids) {
4069  s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids));
4070  if (!s->view_ids)
4071  return AVERROR(ENOMEM);
4072  s->nb_view_ids = s0->nb_view_ids;
4073  }
4074  }
4075 
4076  ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
4077  if (ret < 0)
4078  return ret;
4079 
4080  ret = av_buffer_replace(&s->sei.common.dynamic_hdr_plus.info,
4082  if (ret < 0)
4083  return ret;
4084 
4085  ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf);
4086  if (ret < 0)
4087  return ret;
4088 
4089  ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
4090 
4091  ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info,
4093  if (ret < 0)
4094  return ret;
4095 
4096  s->sei.common.frame_packing = s0->sei.common.frame_packing;
4097  s->sei.common.display_orientation = s0->sei.common.display_orientation;
4098  s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
4099  s->sei.tdrdi = s0->sei.tdrdi;
4100  s->sei.recovery_point = s0->sei.recovery_point;
4101  s->recovery_poc = s0->recovery_poc;
4102 
4103  return 0;
4104 }
4105 #endif
4106 
4108 {
4109  int ret;
4110 
4111  if (sei->tdrdi.present) {
4112  AVBufferRef *buf;
4113  size_t size;
4114  AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(sei->tdrdi.num_ref_displays, &size);
4115 
4116  if (!tdrdi)
4117  return AVERROR(ENOMEM);
4118 
4119  buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0);
4120  if (!buf) {
4121  av_free(tdrdi);
4122  return AVERROR(ENOMEM);
4123  }
4124 
4125  tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width;
4126  tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag;
4127  tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist;
4128  tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays;
4129  for (int i = 0; i < sei->tdrdi.num_ref_displays; i++) {
4130  AV3DReferenceDisplay *display = av_tdrdi_get_display(tdrdi, i);
4131 
4132  display->left_view_id = sei->tdrdi.left_view_id[i];
4133  display->right_view_id = sei->tdrdi.right_view_id[i];
4134  display->exponent_ref_display_width = sei->tdrdi.exponent_ref_display_width[i];
4135  display->mantissa_ref_display_width = sei->tdrdi.mantissa_ref_display_width[i];
4136  display->exponent_ref_viewing_distance = sei->tdrdi.exponent_ref_viewing_distance[i];
4137  display->mantissa_ref_viewing_distance = sei->tdrdi.mantissa_ref_viewing_distance[i];
4138  display->additional_shift_present_flag = sei->tdrdi.additional_shift_present_flag[i];
4139  display->num_sample_shift = sei->tdrdi.num_sample_shift[i];
4140  }
4143  if (ret < 0) {
4144  av_buffer_unref(&buf);
4145  return ret;
4146  }
4147  }
4148 
4149  ret = ff_h2645_sei_to_context(avctx, &sei->common);
4150  if (ret < 0)
4151  return ret;
4152 
4153  return 0;
4154 }
4155 
4157 {
4158  HEVCContext *s = avctx->priv_data;
4159  int ret;
4160 
4161  ret = hevc_init_context(avctx);
4162  if (ret < 0)
4163  return ret;
4164 
4165  s->sei.picture_timing.picture_struct = 0;
4166  s->eos = 1;
4167 
4168  atomic_init(&s->wpp_err, 0);
4169 
4170  if (!avctx->internal->is_copy) {
4171  const AVPacketSideData *sd;
4172 
4173  if (avctx->extradata_size > 0 && avctx->extradata) {
4174  ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1);
4175  if (ret < 0) {
4176  return ret;
4177  }
4178 
4179  ret = hevc_sei_to_context(avctx, &s->sei);
4180  if (ret < 0)
4181  return ret;
4182  }
4183 
4185  if (sd && sd->size >= sizeof(s->dovi_ctx.cfg))
4186  s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
4187  }
4188 
4189  return 0;
4190 }
4191 
4193 {
4194  HEVCContext *s = avctx->priv_data;
4196  ff_hevc_reset_sei(&s->sei);
4197  ff_dovi_ctx_flush(&s->dovi_ctx);
4198  av_buffer_unref(&s->rpu_buf);
4199  s->eos = 1;
4200 
4201  if (FF_HW_HAS_CB(avctx, flush))
4202  FF_HW_SIMPLE_CALL(avctx, flush);
4203 }
4204 
4205 #define OFFSET(x) offsetof(HEVCContext, x)
4206 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4207 
4208 static const AVOption options[] = {
4209  { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin),
4210  AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4211  { "strict-displaywin", "strictly apply default display window size", OFFSET(apply_defdispwin),
4212  AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4213  { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views",
4214  .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY,
4215  .min = -1, .max = INT_MAX, .flags = PAR },
4216  { "view_ids_available", "Array of available view IDs is exported here",
4217  .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4219  { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4220  .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4221  .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" },
4222  { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" },
4223  { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" },
4224  { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" },
4225 
4226  { NULL },
4227 };
4228 
4229 static const AVClass hevc_decoder_class = {
4230  .class_name = "HEVC decoder",
4231  .item_name = av_default_item_name,
4232  .option = options,
4233  .version = LIBAVUTIL_VERSION_INT,
4234 };
4235 
4237  .p.name = "hevc",
4238  CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"),
4239  .p.type = AVMEDIA_TYPE_VIDEO,
4240  .p.id = AV_CODEC_ID_HEVC,
4241  .priv_data_size = sizeof(HEVCContext),
4242  .p.priv_class = &hevc_decoder_class,
4243  .init = hevc_decode_init,
4244  .close = hevc_decode_free,
4246  .flush = hevc_decode_flush,
4247  UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
4248  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
4250  .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
4253  .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
4254  .hw_configs = (const AVCodecHWConfigInternal *const []) {
4255 #if CONFIG_HEVC_DXVA2_HWACCEL
4256  HWACCEL_DXVA2(hevc),
4257 #endif
4258 #if CONFIG_HEVC_D3D11VA_HWACCEL
4259  HWACCEL_D3D11VA(hevc),
4260 #endif
4261 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4262  HWACCEL_D3D11VA2(hevc),
4263 #endif
4264 #if CONFIG_HEVC_D3D12VA_HWACCEL
4265  HWACCEL_D3D12VA(hevc),
4266 #endif
4267 #if CONFIG_HEVC_NVDEC_HWACCEL
4268  HWACCEL_NVDEC(hevc),
4269 #endif
4270 #if CONFIG_HEVC_VAAPI_HWACCEL
4271  HWACCEL_VAAPI(hevc),
4272 #endif
4273 #if CONFIG_HEVC_VDPAU_HWACCEL
4274  HWACCEL_VDPAU(hevc),
4275 #endif
4276 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4277  HWACCEL_VIDEOTOOLBOX(hevc),
4278 #endif
4279 #if CONFIG_HEVC_VULKAN_HWACCEL
4280  HWACCEL_VULKAN(hevc),
4281 #endif
4282  NULL
4283  },
4284 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
HEVCLayerContext::tab_ct_depth
uint8_t * tab_ct_depth
Definition: hevcdec.h:466
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
flags
const SwsFlags flags[]
Definition: swscale.c:61
HWACCEL_D3D12VA
#define HWACCEL_D3D12VA(codec)
Definition: hwconfig.h:80
ff_get_coded_side_data
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
Definition: decode.c:1356
ff_hevc_decode_extradata
int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps, HEVCSEI *sei, int *is_nalff, int *nal_length_size, int err_recognition, int apply_defdispwin, void *logctx)
Definition: parse.c:79
hwconfig.h
ff_progress_frame_report
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition: decode.c:1921
HEVCLayerContext::horizontal_bs
uint8_t * horizontal_bs
Definition: hevcdec.h:480
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
export_multilayer
static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
Definition: hevcdec.c:415
hevc_decoder_class
static const AVClass hevc_decoder_class
Definition: hevcdec.c:4229
SliceHeader::beta_offset
int beta_offset
beta_offset_div2 * 2
Definition: hevcdec.h:259
bswapdsp.h
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
L1
F H1 F F H1 F F F F H1<-F-------F-------F v v v H2 H3 H2 ^ ^ ^ F-------F-------F-> H1<-F-------F-------F|||||||||F H1 F|||||||||F H1 Funavailable fullpel samples(outside the picture for example) shall be equalto the closest available fullpel sampleSmaller pel interpolation:--------------------------if diag_mc is set then points which lie on a line between 2 vertically, horizontally or diagonally adjacent halfpel points shall be interpolatedlinearly with rounding to nearest and halfway values rounded up.points which lie on 2 diagonals at the same time should only use the onediagonal not containing the fullpel point F--> O q O<--h1-> O q O<--F v \/v \/v O O O O O O O|/|\|q q q q q|/|\|O O O O O O O ^/\ ^/\ ^ h2--> O q O<--h3-> O q O<--h2 v \/v \/v O O O O O O O|\|/|q q q q q|\|/|O O O O O O O ^/\ ^/\ ^ F--> O q O<--h1-> O q O<--Fthe remaining points shall be bilinearly interpolated from theup to 4 surrounding halfpel and fullpel points, again rounding should be tonearest and halfway values rounded upcompliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chromainterpolation at leastOverlapped block motion compensation:-------------------------------------FIXMELL band prediction:===================Each sample in the LL0 subband is predicted by the median of the left, top andleft+top-topleft samples, samples outside the subband shall be considered tobe 0. To reverse this prediction in the decoder apply the following.for(y=0;y< height;y++){ for(x=0;x< width;x++){ sample[y][x]+=median(sample[y-1][x], sample[y][x-1], sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]);}}sample[-1][ *]=sample[ *][-1]=0;width, height here are the width and height of the LL0 subband not of the finalvideoDequantization:===============FIXMEWavelet Transform:==================Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integertransform and an integer approximation of the symmetric biorthogonal 9/7daubechies wavelet.2D IDWT(inverse discrete wavelet transform) --------------------------------------------The 2D IDWT applies a 2D filter recursively, each time combining the4 lowest frequency subbands into a single subband until only 1 subbandremains.The 2D filter is done by first applying a 1D filter in the vertical directionand then applying it in the horizontal one. --------------- --------------- --------------- ---------------|LL0|HL0|||||||||||||---+---|HL1||L0|H0|HL1||LL1|HL1|||||LH0|HH0|||||||||||||-------+-------|-> L1 H1 LH1 HH1 LH1 HH1 LH1 HH1 L1
Definition: snow.txt:554
ff_hevc_dsp_init
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: dsp.c:128
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:249
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AV_TIMECODE_STR_SIZE
#define AV_TIMECODE_STR_SIZE
Definition: timecode.h:33
ff_hevc_luma_mv_mvp_mode
void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv, int mvp_lx_flag, int LX)
Definition: mvs.c:589
HEVCLocalContext
Definition: hevcdec.h:391
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AV3DReferenceDisplay::num_sample_shift
int16_t num_sample_shift
The recommended additional horizontal shift for a stereo pair corresponding to the n-th reference bas...
Definition: tdrdi.h:141
HEVCLayerContext::bs_height
int bs_height
Definition: hevcdec.h:459
SliceHeader::slice_act_cr_qp_offset
int slice_act_cr_qp_offset
Definition: hevcdec.h:255
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
AV_STEREO3D_VIEW_LEFT
@ AV_STEREO3D_VIEW_LEFT
Frame contains only the left view.
Definition: stereo3d.h:158
ff_hevc_merge_flag_decode
int ff_hevc_merge_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:747
av_clip
#define av_clip
Definition: common.h:100
ff_thread_progress_report
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
Definition: threadprogress.c:53
atomic_store
#define atomic_store(object, desired)
Definition: stdatomic.h:85
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
SliceHeader::chroma_offset_l1
int16_t chroma_offset_l1[16][2]
Definition: hevcdec.h:284
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_dovi_ctx_unref
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition: dovi_rpu.c:30
threadprogress.h
decode_slice
static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb)
Definition: hevcdec.c:3532
MD5_PRI_ARG
#define MD5_PRI_ARG(buf)
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:659
av_container_fifo_alloc_avframe
AVContainerFifo * av_container_fifo_alloc_avframe(unsigned flags)
Allocate an AVContainerFifo instance for AVFrames.
Definition: container_fifo.c:215
ff_hevc_end_of_slice_flag_decode
int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:563
PART_NxN
@ PART_NxN
Definition: hevcdec.h:98
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:1924
ff_hevc_cu_qp_delta_sign_flag
int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc)
Definition: cabac.c:613
SliceHeader::slice_act_y_qp_offset
int slice_act_y_qp_offset
Definition: hevcdec.h:253
ff_hevc_compute_poc
static int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type)
Definition: ps.h:551
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1207
decode_reset_recovery_point
static void decode_reset_recovery_point(HEVCContext *s)
Definition: hevcdec.c:3686
out
FILE * out
Definition: movenc.c:55
HEVCContext::layers_active_output
unsigned layers_active_output
Definition: hevcdec.h:503
HEVC_RECOVERY_UNSPECIFIED
#define HEVC_RECOVERY_UNSPECIFIED
Definition: hevcdec.h:79
HEVCWindow::bottom_offset
unsigned int bottom_offset
Definition: ps.h:95
SAO_BAND
@ SAO_BAND
Definition: hevcdec.h:164
HEVCParamSets::pps_list
const HEVCPPS * pps_list[HEVC_MAX_PPS_COUNT]
RefStruct references.
Definition: ps.h:514
ff_hevc_profiles
const AVProfile ff_hevc_profiles[]
Definition: profiles.c:97
ff_hevc_set_neighbour_available
void ff_hevc_set_neighbour_available(HEVCLocalContext *lc, int x0, int y0, int nPbW, int nPbH, int log2_ctb_size)
Definition: mvs.c:43
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
chroma_mc_uni
static void chroma_mc_uni(HEVCLocalContext *lc, const HEVCPPS *pps, const HEVCSPS *sps, uint8_t *dst0, ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, int x_off, int y_off, int block_w, int block_h, const struct MvField *current_mv, int chroma_weight, int chroma_offset)
8.5.3.2.2.2 Chroma sample uniprediction interpolation process
Definition: hevcdec.c:1874
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:124
ff_h2645_sei_to_frame
int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, enum AVCodecID codec_id, AVCodecContext *avctx, const H2645VUI *vui, unsigned bit_depth_luma, unsigned bit_depth_chroma, int seed)
Definition: h2645_sei.c:702
ff_h274_apply_film_grain
int ff_h274_apply_film_grain(AVFrame *out_frame, const AVFrame *in_frame, const AVFilmGrainParams *params)
Definition: h274.c:245
src1
const pixel * src1
Definition: h264pred_template.c:420
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:424
HEVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: hevcdec.h:423
ff_dovi_rpu_parse
int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, int err_recognition)
Parse the contents of a Dolby Vision RPU and update the parsed values in the DOVIContext struct.
Definition: dovi_rpudec.c:347
hevc_await_progress
static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, const Mv *mv, int y0, int height)
Definition: hevcdec.c:2037
int64_t
long long int64_t
Definition: coverity.c:34
HEVCLayerContext::tab_ipm
uint8_t * tab_ipm
Definition: hevcdec.h:470
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
SliceHeader::num_entry_point_offsets
int num_entry_point_offsets
Definition: hevcdec.h:268
av_tdrdi_get_display
static av_always_inline AV3DReferenceDisplay * av_tdrdi_get_display(AV3DReferenceDisplaysInfo *tdrdi, unsigned int idx)
Definition: tdrdi.h:145
HEVCFrame::frame_grain
AVFrame * frame_grain
Definition: hevcdec.h:367
ff_hevc_decode_short_term_rps
int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
Definition: ps.c:89
hls_slice_header
static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
Definition: hevcdec.c:769
AV_FRAME_DATA_FILM_GRAIN_PARAMS
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
Definition: frame.h:188
PART_2NxnU
@ PART_2NxnU
Definition: hevcdec.h:99
av_unused
#define av_unused
Definition: attributes.h:151
AV_FRAME_DATA_S12M_TIMECODE
@ AV_FRAME_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1.
Definition: frame.h:152
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
ff_hevc_flush_dpb
void ff_hevc_flush_dpb(HEVCContext *s)
Drop all frames currently in DPB.
Definition: refs.c:76
container_fifo.h
AV3DReferenceDisplay
Data structure for single deference display information.
Definition: tdrdi.h:100
HEVCLayerContext::bs_width
int bs_width
Definition: hevcdec.h:458
H2645NAL::nuh_layer_id
int nuh_layer_id
Definition: h2645_parse.h:67
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:652
TransformUnit::cu_qp_delta
int cu_qp_delta
Definition: hevcdec.h:334
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:409
w
uint8_t w
Definition: llviddspenc.c:38
HWACCEL_DXVA2
#define HWACCEL_DXVA2(codec)
Definition: hwconfig.h:64
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
AVPacket::data
uint8_t * data
Definition: packet.h:588
set_deblocking_bypass
static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps, int x0, int y0, int log2_cb_size)
Definition: hevcdec.c:1513
HEVC_NAL_BLA_N_LP
@ HEVC_NAL_BLA_N_LP
Definition: hevc.h:47
SAOParams::offset_sign
int offset_sign[3][4]
sao_offset_sign
Definition: dsp.h:36
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:590
INTRA_DC
@ INTRA_DC
Definition: hevcdec.h:126
hevc_decode_flush
static av_cold void hevc_decode_flush(AVCodecContext *avctx)
Definition: hevcdec.c:4192
AVOption
AVOption.
Definition: opt.h:429
HWACCEL_D3D11VA2
#define HWACCEL_D3D11VA2(codec)
Definition: hwconfig.h:66
ff_h2645_packet_uninit
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:604
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
ff_hevc_pred_mode_decode
int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
Definition: cabac.c:634
HEVCContext::no_rasl_output_flag
int no_rasl_output_flag
Definition: hevcdec.h:532
data
const char data[16]
Definition: mxf.c:149
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:305
HEVC_NAL_TSA_N
@ HEVC_NAL_TSA_N
Definition: hevc.h:31
AV_FRAME_DATA_DOVI_RPU_BUFFER
@ AV_FRAME_DATA_DOVI_RPU_BUFFER
Dolby Vision RPU raw data, suitable for passing to x265 or other libraries.
Definition: frame.h:201
HEVC_NAL_IDR_N_LP
@ HEVC_NAL_IDR_N_LP
Definition: hevc.h:49
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:539
SAO_EDGE
@ SAO_EDGE
Definition: hevcdec.h:165
atomic_int
intptr_t atomic_int
Definition: stdatomic.h:55
ff_aom_apply_film_grain
int ff_aom_apply_film_grain(AVFrame *out, const AVFrame *in, const AVFilmGrainParams *params)
Definition: aom_film_grain.c:68
SliceHeader::slice_temporal_mvp_enabled_flag
uint8_t slice_temporal_mvp_enabled_flag
Definition: hevcdec.h:235
AV_PIX_FMT_D3D11VA_VLD
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
Definition: pixfmt.h:254
TransformUnit::is_cu_qp_delta_coded
uint8_t is_cu_qp_delta_coded
Definition: hevcdec.h:342
FFCodec
Definition: codec_internal.h:127
ff_hevc_output_frames
int ff_hevc_output_frames(HEVCContext *s, unsigned layers_active_decode, unsigned layers_active_output, unsigned max_output, unsigned max_dpb, int discard)
Find frames in the DPB that are ready for output and either write them to the output FIFO or drop the...
Definition: refs.c:265
hevc_receive_frame
static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: hevcdec.c:3832
ff_hevc_hls_filters
void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, int x_ctb, int y_ctb, int ctb_size)
Definition: filter.c:912
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:176
SliceHeader::slice_loop_filter_across_slices_enabled_flag
uint8_t slice_loop_filter_across_slices_enabled_flag
Definition: hevcdec.h:244
ff_hevc_sao_type_idx_decode
int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc)
Definition: cabac.c:521
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
HEVCLocalContext::ctb_up_left_flag
uint8_t ctb_up_left_flag
Definition: hevcdec.h:425
HEVC_NAL_IDR_W_RADL
@ HEVC_NAL_IDR_W_RADL
Definition: hevc.h:48
find_finish_setup_nal
static int find_finish_setup_nal(const HEVCContext *s)
Definition: hevcdec.c:3166
H2645NAL::temporal_id
int temporal_id
HEVC only, nuh_temporal_id_plus_1 - 1.
Definition: h2645_parse.h:62
H2645_FLAG_SMALL_PADDING
@ H2645_FLAG_SMALL_PADDING
Definition: h2645_parse.h:98
av_timecode_get_smpte
uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss, int ff)
Convert sei info to SMPTE 12M binary representation.
Definition: timecode.c:70
RefPicList
Definition: hevcdec.h:194
AV_STEREO3D_VIEW_RIGHT
@ AV_STEREO3D_VIEW_RIGHT
Frame contains only the right view.
Definition: stereo3d.h:163
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_STEREO3D_VIEW_UNSPEC
@ AV_STEREO3D_VIEW_UNSPEC
Content is unspecified.
Definition: stereo3d.h:168
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:517
ff_hevc_prev_intra_luma_pred_flag_decode
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:702
PF_INTRA
@ PF_INTRA
Definition: hevcdec.h:118
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
set_sps
static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
Definition: hevcdec.c:739
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:448
verify_md5
static int verify_md5(HEVCContext *s, AVFrame *frame)
Definition: hevcdec.c:3417
MODE_SKIP
@ MODE_SKIP
Definition: hevcdec.h:108
HEVCLayerContext::skip_flag
uint8_t * skip_flag
Definition: hevcdec.h:465
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
HEVCLocalContext::end_of_tiles_x
int end_of_tiles_x
Definition: hevcdec.h:426
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:280
CodingUnit::x
int x
Definition: hevcdec.h:291
tab_mode_idx
static const uint8_t tab_mode_idx[]
Definition: hevcdec.c:2320
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:383
AV3DReferenceDisplaysInfo
This structure describes information about the reference display width(s) and reference viewing dista...
Definition: tdrdi.h:53
BOUNDARY_LEFT_TILE
#define BOUNDARY_LEFT_TILE
Definition: hevcdec.h:440
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:551
golomb.h
exp golomb vlc stuff
AVCodecInternal::is_copy
int is_copy
When using frame-threaded decoding, this field is set for the first worker thread (e....
Definition: internal.h:54
hls_coding_unit
static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int log2_cb_size)
Definition: hevcdec.c:2419
AVPacketSideData::size
size_t size
Definition: packet.h:411
PART_2Nx2N
@ PART_2Nx2N
Definition: hevcdec.h:95
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:337
intra_prediction_unit
static void intra_prediction_unit(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCSPS *sps, int x0, int y0, int log2_cb_size)
Definition: hevcdec.c:2324
hevc_decode_free
static av_cold int hevc_decode_free(AVCodecContext *avctx)
Definition: hevcdec.c:3925
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:57
HEVCLocalContext::ctb_up_right_flag
uint8_t ctb_up_right_flag
Definition: hevcdec.h:424
HEVCLayerContext::tab_slice_address
int32_t * tab_slice_address
Definition: hevcdec.h:476
ff_hevc_decoder
const FFCodec ff_hevc_decoder
Definition: hevcdec.c:4236
HEVCLayerContext::sao_pixel_buffer_v
uint8_t * sao_pixel_buffer_v[3]
Definition: hevcdec.h:484
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
HEVCLayerContext::sao_pixel_buffer_h
uint8_t * sao_pixel_buffer_h[3]
Definition: hevcdec.h:483
PRED_BI
@ PRED_BI
Definition: hevcdec.h:114
ff_hevc_split_transform_flag_decode
int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size)
Definition: cabac.c:821
av_ceil_log2
#define av_ceil_log2
Definition: common.h:97
fail
#define fail()
Definition: checkasm.h:208
PredictionUnit::intra_pred_mode_c
uint8_t intra_pred_mode_c[4]
Definition: hevcdec.h:329
H2645SEI::dynamic_hdr_vivid
HEVCSEIDynamicHDRVivid dynamic_hdr_vivid
Definition: h2645_sei.h:132
md5
struct AVMD5 * md5
Definition: movenc.c:57
InterPredIdc
InterPredIdc
Definition: hevcdec.h:111
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:106
timecode.h
HEVCWindow::left_offset
unsigned int left_offset
Definition: ps.h:92
GetBitContext
Definition: get_bits.h:109
SliceHeader::luma_log2_weight_denom
uint8_t luma_log2_weight_denom
Definition: hevcdec.h:272
ff_hevc_hls_mvd_coding
void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
Definition: cabac.c:1493
HEVCLocalContext::pu
PredictionUnit pu
Definition: hevcdec.h:436
HEVC_NAL_SEI_SUFFIX
@ HEVC_NAL_SEI_SUFFIX
Definition: hevc.h:69
HEVC_MAX_REFS
@ HEVC_MAX_REFS
Definition: hevc.h:122
H2645_FLAG_IS_NALFF
@ H2645_FLAG_IS_NALFF
Definition: h2645_parse.h:97
av_film_grain_params_select
const AVFilmGrainParams * av_film_grain_params_select(const AVFrame *frame)
Select the most appropriate film grain parameters set for the frame, taking into account the frame's ...
Definition: film_grain_params.c:53
TransformUnit::res_scale_val
int res_scale_val
Definition: hevcdec.h:336
SliceHeader::short_term_ref_pic_set_size
int short_term_ref_pic_set_size
Definition: hevcdec.h:226
ff_hevc_cu_chroma_qp_offset_idx
int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
Definition: cabac.c:623
val
static double val(void *priv, double ch)
Definition: aeval.c:77
ff_hevc_sao_offset_abs_decode
int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth)
Definition: cabac.c:541
HWACCEL_VDPAU
#define HWACCEL_VDPAU(codec)
Definition: hwconfig.h:72
ff_videodsp_init
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:39
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:607
SliceHeader::long_term_ref_pic_set_size
int long_term_ref_pic_set_size
Definition: hevcdec.h:229
hls_cross_component_pred
static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
Definition: hevcdec.c:1285
HEVCParamSets::sps_list
const HEVCSPS * sps_list[HEVC_MAX_SPS_COUNT]
RefStruct references.
Definition: ps.h:513
ss
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:202
hls_transform_tree
static int hls_transform_tree(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase, int log2_cb_size, int log2_trafo_size, int trafo_depth, int blk_idx, const int *base_cbf_cb, const int *base_cbf_cr)
Definition: hevcdec.c:1529
HEVC_NAL_SEI_PREFIX
@ HEVC_NAL_SEI_PREFIX
Definition: hevc.h:68
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
wpp_progress_init
static int wpp_progress_init(HEVCContext *s, unsigned count)
Definition: hevcdec.c:2899
ff_hevc_luma_mv_merge_mode
void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, const HEVCPPS *pps, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv)
Definition: mvs.c:482
AVRational::num
int num
Numerator.
Definition: rational.h:59
progressframe.h
refstruct.h
ff_hevc_pred_init
void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth)
Definition: pred.c:43
ff_frame_new_side_data_from_buf
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition: decode.c:2164
SliceHeader::slice_segment_addr
unsigned int slice_segment_addr
address (in raster order) of the first block in the current slice segment
Definition: hevcdec.h:209
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
pic_arrays_free
static void pic_arrays_free(HEVCLayerContext *l)
NOTE: Each function hls_foo correspond to the function foo in the specification (HLS stands for High ...
Definition: hevcdec.c:73
first
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
Definition: rate_distortion.txt:12
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:68
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:645
hls_decode_entry_wpp
static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, int job, int thread)
Definition: hevcdec.c:2804
ff_hevc_mvp_lx_flag_decode
int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:778
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
HEVCLayerContext::vertical_bs
uint8_t * vertical_bs
Definition: hevcdec.h:481
set_side_data
static int set_side_data(HEVCContext *s)
Definition: hevcdec.c:3081
QPEL_EXTRA_AFTER
#define QPEL_EXTRA_AFTER
Definition: hevcdec.h:63
film_grain_params.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:106
luma_mc_uni
static void luma_mc_uni(HEVCLocalContext *lc, const HEVCPPS *pps, const HEVCSPS *sps, uint8_t *dst, ptrdiff_t dststride, const AVFrame *ref, const Mv *mv, int x_off, int y_off, int block_w, int block_h, int luma_weight, int luma_offset)
8.5.3.2.2.1 Luma sample unidirectional interpolation process
Definition: hevcdec.c:1716
TransformUnit::intra_pred_mode
int intra_pred_mode
Definition: hevcdec.h:339
HEVCSEIDynamicHDRPlus::info
AVBufferRef * info
Definition: h2645_sei.h:46
ff_hevc_is_alpha_video
int ff_hevc_is_alpha_video(const HEVCContext *s)
Definition: hevcdec.c:454
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:642
SliceHeader::cabac_init_flag
uint8_t cabac_init_flag
Definition: hevcdec.h:242
DBParams::beta_offset
int beta_offset
Definition: hevcdec.h:350
H2645NAL::size
int size
Definition: h2645_parse.h:36
DBParams::tc_offset
int tc_offset
Definition: hevcdec.h:351
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:515
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:697
ff_hevc_decode_nal_sei
int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s, const HEVCParamSets *ps, enum HEVCNALUnitType type)
Definition: sei.c:303
ff_progress_frame_ref
void ff_progress_frame_ref(ProgressFrame *dst, const ProgressFrame *src)
Set dst->f to src->f and make dst a co-owner of src->f.
Definition: decode.c:1896
AV_FRAME_SIDE_DATA_FLAG_NEW_REF
#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF
Create a new reference to the passed in buffer instead of taking ownership of it.
Definition: frame.h:1058
QPEL_EXTRA_BEFORE
#define QPEL_EXTRA_BEFORE
Definition: hevcdec.h:62
stereo3d.h
HEVCLayerContext::cur_frame
HEVCFrame * cur_frame
Definition: hevcdec.h:454
AV_PIX_FMT_DXVA2_VLD
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:134
HEVCLocalContext::parent
const struct HEVCContext * parent
Definition: hevcdec.h:399
s
#define s(width, name)
Definition: cbs_vp9.c:198
HEVCSPS::height
int height
Definition: ps.h:351
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
SAO_NOT_APPLIED
@ SAO_NOT_APPLIED
Definition: hevcdec.h:163
AV_PROFILE_HEVC_SCC
#define AV_PROFILE_HEVC_SCC
Definition: defs.h:164
set_ct_depth
static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth, int x0, int y0, int log2_cb_size, int ct_depth)
Definition: hevcdec.c:2306
ff_hevc_part_mode_decode
int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
Definition: cabac.c:660
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
SliceHeader::luma_offset_l1
int16_t luma_offset_l1[16]
Definition: hevcdec.h:283
AV_ZERO32
#define AV_ZERO32(d)
Definition: intreadwrite.h:662
AVCodecContext::nb_decoded_side_data
int nb_decoded_side_data
Definition: avcodec.h:1925
ff_hevc_merge_idx_decode
int ff_hevc_merge_idx_decode(HEVCLocalContext *lc)
Definition: cabac.c:736
HEVCSEI::common
H2645SEI common
Definition: sei.h:107
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
ff_hevc_nal_is_nonref
static av_always_inline int ff_hevc_nal_is_nonref(enum HEVCNALUnitType type)
Definition: hevcdec.h:653
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1038
HEVCSEI
Definition: sei.h:106
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
HEVC_NAL_UNSPEC62
@ HEVC_NAL_UNSPEC62
Definition: hevc.h:91
export_stream_params_from_sei
static int export_stream_params_from_sei(HEVCContext *s)
Definition: hevcdec.c:387
hevc_frame_start
static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, unsigned nal_idx)
Definition: hevcdec.c:3209
ff_hevc_save_states
void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps, int ctb_addr_ts)
Definition: cabac.c:402
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
ff_hevc_skip_flag_decode
int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag, int x0, int y0, int x_cb, int y_cb, int min_cb_width)
Definition: cabac.c:573
SliceHeader::slice_rps
ShortTermRPS slice_rps
Definition: hevcdec.h:227
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:594
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AVPacketSideData::data
uint8_t * data
Definition: packet.h:410
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ff_progress_frame_await
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_progress_frame_await() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_progress_frame_report() has been called on them. This includes draw_edges(). Porting codecs to frame threading
decode.h
ff_hevc_cbf_cb_cr_decode
int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth)
Definition: cabac.c:826
hevc.h
IS_IDR
#define IS_IDR(s)
Definition: hevcdec.h:74
H2645NAL::data
const uint8_t * data
Definition: h2645_parse.h:35
av_container_fifo_read
int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags)
Read the next available object from the FIFO into obj.
Definition: container_fifo.c:122
AV_FRAME_DATA_3D_REFERENCE_DISPLAYS
@ AV_FRAME_DATA_3D_REFERENCE_DISPLAYS
This side data contains information about the reference display width(s) and reference viewing distan...
Definition: frame.h:256
RefPicList::ref
struct HEVCFrame * ref[HEVC_MAX_REFS]
Definition: hevcdec.h:195
H2645NAL::skipped_bytes_pos
int * skipped_bytes_pos
Definition: h2645_parse.h:71
HEVCWindow::top_offset
unsigned int top_offset
Definition: ps.h:94
export_stream_params
static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
Definition: hevcdec.c:331
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
SliceHeader::size
int * size
Definition: hevcdec.h:267
SliceHeader::collocated_list
uint8_t collocated_list
Definition: hevcdec.h:245
atomic_load
#define atomic_load(object)
Definition: stdatomic.h:93
SliceHeader::luma_offset_l0
int16_t luma_offset_l0[16]
Definition: hevcdec.h:280
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
AV_FILM_GRAIN_PARAMS_NONE
@ AV_FILM_GRAIN_PARAMS_NONE
Definition: film_grain_params.h:25
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: defs.h:229
HEVCLayerContext::tab_mvf_pool
struct AVRefStructPool * tab_mvf_pool
Definition: hevcdec.h:486
get_se_golomb
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:239
INTRA_ANGULAR_26
@ INTRA_ANGULAR_26
Definition: hevcdec.h:151
H2645NAL::type
int type
NAL unit type.
Definition: h2645_parse.h:52
SliceHeader::chroma_weight_l1
int16_t chroma_weight_l1[16][2]
Definition: hevcdec.h:277
CodingUnit::max_trafo_depth
uint8_t max_trafo_depth
MaxTrafoDepth.
Definition: hevcdec.h:299
AV_FRAME_DATA_DYNAMIC_HDR_VIVID
@ AV_FRAME_DATA_DYNAMIC_HDR_VIVID
HDR Vivid dynamic metadata associated with a video frame.
Definition: frame.h:215
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
SliceHeader::slice_ctb_addr_rs
int slice_ctb_addr_rs
Definition: hevcdec.h:286
SliceHeader::poc
int poc
Definition: hevcdec.h:216
ff_hevc_hls_residual_coding
void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps, int x0, int y0, int log2_trafo_size, enum ScanType scan_idx, int c_idx)
Definition: cabac.c:981
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:57
ff_hevc_decode_nal_vps
int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: ps.c:761
FF_CODEC_PROPERTY_FILM_GRAIN
#define FF_CODEC_PROPERTY_FILM_GRAIN
Definition: avcodec.h:1640
AV_PIX_FMT_YUVA422P10LE
@ AV_PIX_FMT_YUVA422P10LE
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:184
hevc_ref_frame
static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
Definition: hevcdec.c:3892
if
if(ret)
Definition: filter_design.txt:179
hevc_decode_init
static av_cold int hevc_decode_init(AVCodecContext *avctx)
Definition: hevcdec.c:4156
srcstride
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t const uint8_t ptrdiff_t srcstride
Definition: dsp.h:88
SliceHeader::pic_output_flag
uint8_t pic_output_flag
Definition: hevcdec.h:220
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:95
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:110
pred_weight_table
static int pred_weight_table(SliceHeader *sh, void *logctx, const HEVCSPS *sps, GetBitContext *gb)
Definition: hevcdec.c:174
PredictionUnit::rem_intra_luma_pred_mode
int rem_intra_luma_pred_mode
Definition: hevcdec.h:325
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
HEVCContext::sei
HEVCSEI sei
Definition: hevcdec.h:511
H2645NAL::raw_size
int raw_size
Definition: h2645_parse.h:44
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
ff_thread_progress_await
void ff_thread_progress_await(const ThreadProgress *pro_c, int n)
This function is a no-op in no-op mode; otherwise it waits until other threads have reached a certain...
Definition: threadprogress.c:64
IS_BLA
#define IS_BLA(s)
Definition: hevcdec.h:75
HEVCLayerContext::deblock
DBParams * deblock
Definition: hevcdec.h:462
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
ff_bswapdsp_init
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
NULL
#define NULL
Definition: coverity.c:32
parse.h
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
SAOParams::offset_abs
int offset_abs[3][4]
sao_offset_abs
Definition: dsp.h:35
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:669
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
HEVCLocalContext::tmp
int16_t tmp[MAX_PB_SIZE *MAX_PB_SIZE]
Definition: hevcdec.h:432
CTB
#define CTB(tab, x, y)
Definition: hevcdec.c:1195
hwaccel_internal.h
LongTermRPS::poc
int poc[32]
Definition: hevcdec.h:188
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:798
CodingUnit::cu_transquant_bypass_flag
uint8_t cu_transquant_bypass_flag
Definition: hevcdec.h:300
is_pcm
static int is_pcm(enum AVCodecID codec_id)
Definition: mxfdec.c:2551
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:466
ff_hevc_decode_nal_pps
int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: ps.c:2162
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
HEVCLocalContext::first_qp_group
uint8_t first_qp_group
Definition: hevcdec.h:396
ff_h2645_sei_to_context
int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei)
Definition: h2645_sei.c:896
do_output
static void do_output(BM3DContext *s, uint8_t *dst, int dst_linesize, int plane, int nb_jobs)
Definition: vf_bm3d.c:630
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:241
HEVCLayerContext::cbf_luma
uint8_t * cbf_luma
Definition: hevcdec.h:469
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:391
HEVC_NAL_STSA_N
@ HEVC_NAL_STSA_N
Definition: hevc.h:33
profiles.h
ff_hevc_reset_sei
static void ff_hevc_reset_sei(HEVCSEI *sei)
Reset SEI values that are stored on the Context.
Definition: sei.h:128
AV3DReferenceDisplay::exponent_ref_display_width
uint8_t exponent_ref_display_width
The exponent part of the reference display width of the n-th reference display.
Definition: tdrdi.h:114
ff_hevc_res_scale_sign_flag
int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx)
Definition: cabac.c:861
ff_set_sar
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:106
L0
#define L0
Definition: hevcdec.h:56
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:552
LongTermRPS::poc_msb_present
uint8_t poc_msb_present[32]
Definition: hevcdec.h:189
HEVC_NAL_EOS_NUT
@ HEVC_NAL_EOS_NUT
Definition: hevc.h:65
options
Definition: swscale.c:43
HEVCContext::film_grain_warning_shown
int film_grain_warning_shown
Definition: hevcdec.h:577
ff_log2
#define ff_log2
Definition: intmath.h:51
av_frame_new_side_data_from_buf
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition: frame.c:638
PART_Nx2N
@ PART_Nx2N
Definition: hevcdec.h:97
ff_hevc_ref_idx_lx_decode
int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
Definition: cabac.c:762
RefPicListTab
Definition: hevcdec.h:201
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:341
BOUNDARY_UPPER_TILE
#define BOUNDARY_UPPER_TILE
Definition: hevcdec.h:442
AV_PIX_FMT_D3D12
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition: pixfmt.h:440
decode_nal_unit
static int decode_nal_unit(HEVCContext *s, unsigned nal_idx)
Definition: hevcdec.c:3599
aom_film_grain.h
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
AV_OPT_TYPE_UINT
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
Definition: opt.h:335
h274.h
HEVCContext::is_nalff
int is_nalff
this flag is != 0 if bitstream is encapsulated as a format defined in 14496-15
Definition: hevcdec.h:560
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
FF_HW_HAS_CB
#define FF_HW_HAS_CB(avctx, function)
Definition: hwaccel_internal.h:179
SliceHeader::nb_refs
unsigned int nb_refs[2]
Definition: hevcdec.h:237
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:304
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:858
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1628
PF_BI
@ PF_BI
Definition: hevcdec.h:121
ff_hevc_sao_eo_class_decode
int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc)
Definition: cabac.c:556
H2645SEI::display_orientation
H2645SEIDisplayOrientation display_orientation
Definition: h2645_sei.h:136
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:72
HEVCWindow
Definition: ps.h:91
SCAN_HORIZ
@ SCAN_HORIZ
Definition: hevcdec.h:178
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
get_bits_bytesize
static int get_bits_bytesize(const GetBitContext *s, int round_up)
Get the size of the GetBitContext's buffer in bytes.
Definition: get_bits.h:268
PAR
#define PAR
Definition: hevcdec.c:4206
HEVCLocalContext::edge_emu_buffer
uint8_t edge_emu_buffer[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevcdec.h:429
IS_IRAP
#define IS_IRAP(s)
Definition: hevcdec.h:77
SAOParams::offset_val
int16_t offset_val[3][5]
SaoOffsetVal.
Definition: dsp.h:42
HEVCSEI::recovery_point
HEVCSEIRecoveryPoint recovery_point
Definition: sei.h:113
LongTermRPS::used
uint8_t used[32]
Definition: hevcdec.h:190
HEVC_NAL_RASL_R
@ HEVC_NAL_RASL_R
Definition: hevc.h:38
SliceHeader::colour_plane_id
uint8_t colour_plane_id
Definition: hevcdec.h:221
PART_nLx2N
@ PART_nLx2N
Definition: hevcdec.h:101
ff_hevc_cabac_init
int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps, int ctb_addr_ts, const uint8_t *data, size_t size, int is_wpp)
Definition: cabac.c:454
HEVCContext::nal_length_size
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
Definition: hevcdec.h:574
luma_mc_bi
static void luma_mc_bi(HEVCLocalContext *lc, const HEVCPPS *pps, const HEVCSPS *sps, uint8_t *dst, ptrdiff_t dststride, const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, int block_w, int block_h, const AVFrame *ref1, const Mv *mv1, struct MvField *current_mv)
8.5.3.2.2.1 Luma sample bidirectional interpolation process
Definition: hevcdec.c:1780
SliceHeader::dependent_slice_segment_flag
uint8_t dependent_slice_segment_flag
Definition: hevcdec.h:219
HEVCSEITDRDI
Definition: sei.h:82
ff_hevc_set_new_ref
int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
Definition: refs.c:209
SliceHeader::slice_act_cb_qp_offset
int slice_act_cb_qp_offset
Definition: hevcdec.h:254
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:231
SliceHeader::first_slice_in_pic_flag
uint8_t first_slice_in_pic_flag
Definition: hevcdec.h:218
HEVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: hevcdec.h:422
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
H2645SEI::frame_packing
H2645SEIFramePacking frame_packing
Definition: h2645_sei.h:135
AVPacket::size
int size
Definition: packet.h:589
BOUNDARY_UPPER_SLICE
#define BOUNDARY_UPPER_SLICE
Definition: hevcdec.h:441
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
ff_dovi_attach_side_data
int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
Attach the decoded AVDOVIMetadata as side data to an AVFrame.
Definition: dovi_rpudec.c:64
hevcdec.h
ff_hevc_frame_rps
int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l)
Construct the reference picture sets for the current frame.
Definition: refs.c:534
height
#define height
Definition: dsp.h:89
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:278
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
HEVC_NAL_RASL_N
@ HEVC_NAL_RASL_N
Definition: hevc.h:37
HEVC_MAX_NUH_LAYER_ID
@ HEVC_MAX_NUH_LAYER_ID
Definition: hevc.h:110
HEVCSEITDRDI::right_view_id
uint16_t right_view_id[32]
Definition: sei.h:88
AV_OPT_TYPE_FLAG_ARRAY
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition: opt.h:346
AV_PIX_FMT_YUV422P10LE
@ AV_PIX_FMT_YUV422P10LE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:158
HEVCSEITDRDI::left_view_id
uint16_t left_view_id[32]
Definition: sei.h:87
ff_hevc_unref_frame
void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
Definition: refs.c:35
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
INTRA_PLANAR
@ INTRA_PLANAR
Definition: hevcdec.h:125
PART_2NxnD
@ PART_2NxnD
Definition: hevcdec.h:100
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:544
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
FF_CODEC_CAP_EXPORTS_CROPPING
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
Definition: codec_internal.h:60
size
int size
Definition: twinvq_data.h:10344
SCAN_VERT
@ SCAN_VERT
Definition: hevcdec.h:179
ff_hevc_pcm_flag_decode
int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:697
ff_hevc_deblocking_boundary_strengths
void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, int x0, int y0, int log2_trafo_size)
Definition: filter.c:742
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
H2645NAL::gb
GetBitContext gb
Definition: h2645_parse.h:47
SliceHeader::collocated_ref_idx
unsigned int collocated_ref_idx
Definition: hevcdec.h:247
HEVCContext::nb_view_ids
unsigned nb_view_ids
Definition: hevcdec.h:566
SliceHeader::entry_point_offset
unsigned * entry_point_offset
Definition: hevcdec.h:265
ff_frame_new_side_data
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **psd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
Definition: decode.c:2126
hls_decode_neighbour
static void hls_decode_neighbour(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x_ctb, int y_ctb, int ctb_addr_ts)
Definition: hevcdec.c:2699
ff_frame_new_side_data_from_buf_ext
int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf)
Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AV...
Definition: decode.c:2145
H2645NAL
Definition: h2645_parse.h:34
hls_slice_data_wpp
static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
Definition: hevcdec.c:2925
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
AVFrameSideData::data
uint8_t * data
Definition: frame.h:284
TransformUnit::chroma_mode_c
int chroma_mode_c
Definition: hevcdec.h:341
SUBDIVIDE
#define SUBDIVIDE(x, y, idx)
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:201
FF_THREAD_SLICE
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:1573
SliceHeader::short_term_ref_pic_set_sps_flag
int short_term_ref_pic_set_sps_flag
RPS coded in the slice header itself is stored here.
Definition: hevcdec.h:225
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:797
SliceHeader::no_output_of_prior_pics_flag
uint8_t no_output_of_prior_pics_flag
Definition: hevcdec.h:234
AVCodecHWConfigInternal
Definition: hwconfig.h:25
MvField
Definition: hevcdec.h:308
QPEL_EXTRA
#define QPEL_EXTRA
Definition: hevcdec.h:64
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
PF_L1
@ PF_L1
Definition: hevcdec.h:120
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:89
HEVC_NAL_STSA_R
@ HEVC_NAL_STSA_R
Definition: hevc.h:34
av_frame_remove_side_data
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:725
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
av_refstruct_ref
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
HEVCContext::dovi_ctx
DOVIContext dovi_ctx
Dolby Vision decoding context.
Definition: hevcdec.h:583
SliceHeader::chroma_weight_l0
int16_t chroma_weight_l0[16][2]
Definition: hevcdec.h:276
options
static const AVOption options[]
Definition: hevcdec.c:4208
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:99
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:592
HWACCEL_D3D11VA
#define HWACCEL_D3D11VA(codec)
Definition: hwconfig.h:78
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
ff_hevc_cbf_luma_decode
int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
Definition: cabac.c:831
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:336
AVCodecInternal
Definition: internal.h:49
HEVCContext::ps
HEVCParamSets ps
Definition: hevcdec.h:510
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
HWACCEL_NVDEC
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:68
av_zero_extend
#define av_zero_extend
Definition: common.h:151
ff_dovi_ctx_flush
av_cold void ff_dovi_ctx_flush(DOVIContext *s)
Partially reset the internal state.
Definition: dovi_rpu.c:43
TransformUnit::cu_qp_offset_cb
int8_t cu_qp_offset_cb
Definition: hevcdec.h:344
SliceHeader::chroma_log2_weight_denom
int16_t chroma_log2_weight_denom
Definition: hevcdec.h:273
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
MvField::pred_flag
int8_t pred_flag
Definition: hevcdec.h:311
HEVCLocalContext::ct_depth
int ct_depth
Definition: hevcdec.h:434
SAOParams::eo_class
int eo_class[3]
sao_eo_class
Definition: dsp.h:40
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1572
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
AV_OPT_FLAG_READONLY
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:368
ff_init_cabac_decoder
int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
Definition: cabac.c:162
ff_hevc_ps_uninit
void ff_hevc_ps_uninit(HEVCParamSets *ps)
Definition: ps.c:2434
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
PART_nRx2N
@ PART_nRx2N
Definition: hevcdec.h:102
setup_multilayer
static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
Definition: hevcdec.c:473
EPEL_EXTRA_BEFORE
#define EPEL_EXTRA_BEFORE
Definition: hevcdec.h:59
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
SliceHeader::slice_cb_qp_offset
int slice_cb_qp_offset
Definition: hevcdec.h:250
SliceHeader
Definition: hevcdec.h:205
ff_hevc_frame_nb_refs
int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps, unsigned layer_idx)
Get the number of candidate references for the current frame.
Definition: refs.c:614
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
HEVCLayerContext::filter_slice_edges
uint8_t * filter_slice_edges
Definition: hevcdec.h:474
HEVCLayerContext::qp_y_tab
int8_t * qp_y_tab
Definition: hevcdec.h:478
av_md5_init
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing.
Definition: md5.c:143
ff_hevc_cu_transquant_bypass_flag_decode
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:568
HEVC_NAL_TSA_R
@ HEVC_NAL_TSA_R
Definition: hevc.h:32
AV3DReferenceDisplay::right_view_id
uint16_t right_view_id
The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
Definition: tdrdi.h:109
SliceHeader::slice_sample_adaptive_offset_flag
uint8_t slice_sample_adaptive_offset_flag[3]
Definition: hevcdec.h:239
AVDISCARD_NONINTRA
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition: defs.h:230
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
decode_nal_units
static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
Definition: hevcdec.c:3692
av_timecode_make_smpte_tc_string2
char * av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
Get the timecode string from the SMPTE timecode format.
Definition: timecode.c:131
hevc_pel_weight
static const uint8_t hevc_pel_weight[65]
Definition: hevcdec.c:61
HEVCFrame
Definition: hevcdec.h:360
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:514
HEVCFrame::tf
ProgressFrame tf
Definition: hevcdec.h:365
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:252
HEVCLayerContext
Definition: hevcdec.h:452
internal.h
EPEL_EXTRA_AFTER
#define EPEL_EXTRA_AFTER
Definition: hevcdec.h:60
src2
const pixel * src2
Definition: h264pred_template.c:421
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
ff_hevc_no_residual_syntax_flag_decode
int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:783
SliceHeader::offset
int * offset
Definition: hevcdec.h:266
HEVCSEITDRDI::num_ref_displays
uint8_t num_ref_displays
Definition: sei.h:86
common.h
HEVCContext::view_ids
int * view_ids
Definition: hevcdec.h:565
AVCodecInternal::in_pkt
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition: internal.h:83
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
SliceHeader::mvd_l1_zero_flag
uint8_t mvd_l1_zero_flag
Definition: hevcdec.h:240
ff_hevc_mpm_idx_decode
int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc)
Definition: cabac.c:707
delta
float delta
Definition: vorbis_enc_data.h:430
md5.h
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
chroma_mc_bi
static void chroma_mc_bi(HEVCLocalContext *lc, const HEVCPPS *pps, const HEVCSPS *sps, uint8_t *dst0, ptrdiff_t dststride, const AVFrame *ref0, const AVFrame *ref1, int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
8.5.3.2.2.2 Chroma sample bidirectional interpolation process
Definition: hevcdec.c:1944
av_always_inline
#define av_always_inline
Definition: attributes.h:63
ff_thread_progress_init
av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode)
Initialize a ThreadProgress.
Definition: threadprogress.c:33
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
PF_L0
@ PF_L0
Definition: hevcdec.h:119
EDGE_EMU_BUFFER_STRIDE
#define EDGE_EMU_BUFFER_STRIDE
Definition: hevcdec.h:66
cabac_functions.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AV3DReferenceDisplay::mantissa_ref_display_width
uint8_t mantissa_ref_display_width
The mantissa part of the reference display width of the n-th reference display.
Definition: tdrdi.h:119
SET_SAO
#define SET_SAO(elem, value)
Definition: hevcdec.c:1197
SliceHeader::data_offset
unsigned data_offset
Definition: hevcdec.h:287
HEVCLocalContext::qp_y
int8_t qp_y
Definition: hevcdec.h:415
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
HEVCSPS::width
int width
coded frame dimension in various units
Definition: ps.h:350
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:676
HEVCSEI::tdrdi
HEVCSEITDRDI tdrdi
Definition: sei.h:112
SliceHeader::chroma_offset_l0
int16_t chroma_offset_l0[16][2]
Definition: hevcdec.h:281
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
SliceHeader::list_entry_lx
unsigned int list_entry_lx[2][32]
Definition: hevcdec.h:231
AVCodecContext::height
int height
Definition: avcodec.h:592
HEVCSEIDynamicHDRVivid::info
AVBufferRef * info
Definition: h2645_sei.h:50
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:631
av_md5_final
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
Definition: md5.c:188
HEVCContext::recovery_poc
int recovery_poc
Definition: hevcdec.h:529
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
HEVCFrame::f
AVFrame * f
Definition: hevcdec.h:363
HWACCEL_VIDEOTOOLBOX
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition: hwconfig.h:74
ff_hevc_cu_chroma_qp_offset_flag
int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
Definition: cabac.c:618
hls_coding_quadtree
static int hls_coding_quadtree(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int log2_cb_size, int cb_depth)
Definition: hevcdec.c:2606
SAOParams
Definition: dsp.h:34
hls_decode_entry
static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
Definition: hevcdec.c:2750
SliceHeader::short_term_rps
const ShortTermRPS * short_term_rps
Definition: hevcdec.h:228
hls_prediction_unit
static void hls_prediction_unit(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int partIdx, int idx)
Definition: hevcdec.c:2094
hls_transform_unit
static int hls_transform_unit(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase, int log2_cb_size, int log2_trafo_size, int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
Definition: hevcdec.c:1301
SliceHeader::cu_chroma_qp_offset_enabled_flag
uint8_t cu_chroma_qp_offset_enabled_flag
Definition: hevcdec.h:257
decode_lt_rps
static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps, GetBitContext *gb, int cur_poc, int poc_lsb)
Definition: hevcdec.c:274
ff_hevc_sao_merge_flag_decode
int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:516
HEVCLayerContext::sps
const HEVCSPS * sps
Definition: hevcdec.h:456
ret
ret
Definition: filter_design.txt:187
H2645NAL::raw_data
const uint8_t * raw_data
Definition: h2645_parse.h:45
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
PRED_L1
@ PRED_L1
Definition: hevcdec.h:113
PredictionUnit::mvd
Mv mvd
Definition: hevcdec.h:327
SliceHeader::disable_deblocking_filter_flag
uint8_t disable_deblocking_filter_flag
slice_header_disable_deblocking_filter_flag
Definition: hevcdec.h:243
HEVCLocalContext::edge_emu_buffer2
uint8_t edge_emu_buffer2[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevcdec.h:431
HEVC_NAL_EOB_NUT
@ HEVC_NAL_EOB_NUT
Definition: hevc.h:66
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
ff_hevc_set_qPy
void ff_hevc_set_qPy(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, int xBase, int yBase, int log2_cb_size)
Definition: filter.c:122
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:560
av_container_fifo_free
void av_container_fifo_free(AVContainerFifo **pcf)
Free a AVContainerFifo and everything in it.
Definition: container_fifo.c:101
hls_sao_param
static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int rx, int ry)
Definition: hevcdec.c:1209
av_refstruct_pool_alloc
AVRefStructPool * av_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to av_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
Definition: refstruct.c:335
pos
unsigned int pos
Definition: spdifenc.c:414
AV3DReferenceDisplay::mantissa_ref_viewing_distance
uint8_t mantissa_ref_viewing_distance
The mantissa part of the reference viewing distance of the n-th reference display.
Definition: tdrdi.h:129
SliceHeader::max_num_merge_cand
uint8_t max_num_merge_cand
5 - 5_minus_max_num_merge_cand
Definition: hevcdec.h:262
ff_thread_progress_destroy
av_cold void ff_thread_progress_destroy(ThreadProgress *pro)
Destroy a ThreadProgress.
Definition: threadprogress.c:44
SliceHeader::luma_weight_l0
int16_t luma_weight_l0[16]
Definition: hevcdec.h:275
ff_thread_finish_setup
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:543
ff_hevc_sao_band_position_decode
int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
Definition: cabac.c:531
HEVCLocalContext::boundary_flags
int boundary_flags
Definition: hevcdec.h:445
U
#define U(x)
Definition: vpx_arith.h:37
HWACCEL_VULKAN
#define HWACCEL_VULKAN(codec)
Definition: hwconfig.h:76
LongTermRPS
Definition: hevcdec.h:187
SliceHeader::slice_type
enum HEVCSliceType slice_type
Definition: hevcdec.h:213
AV_FRAME_DATA_DYNAMIC_HDR_PLUS
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
Definition: frame.h:159
AVCodecContext
main external API structure.
Definition: avcodec.h:431
get_ue_golomb_31
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition: golomb.h:120
HEVCContext::layers_active_decode
unsigned layers_active_decode
Definition: hevcdec.h:502
SliceHeader::slice_qp
int8_t slice_qp
Definition: hevcdec.h:270
HEVC_NAL_CRA_NUT
@ HEVC_NAL_CRA_NUT
Definition: hevc.h:50
ff_hevc_inter_pred_idc_decode
int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH)
Definition: cabac.c:752
AV_FILM_GRAIN_PARAMS_H274
@ AV_FILM_GRAIN_PARAMS_H274
The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)
Definition: film_grain_params.h:35
FF_CODEC_RECEIVE_FRAME_CB
#define FF_CODEC_RECEIVE_FRAME_CB(func)
Definition: codec_internal.h:355
av_refstruct_ref_c
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
Definition: refstruct.c:149
ff_hevc_decode_nal_sps
int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps, unsigned nuh_layer_id, int apply_defdispwin)
Definition: ps.c:1700
ff_h274_film_grain_params_supported
static int ff_h274_film_grain_params_supported(int model_id, enum AVPixelFormat pix_fmt)
Check whether ff_h274_apply_film_grain() supports the given parameter combination.
Definition: h274.h:39
PredictionUnit::merge_flag
uint8_t merge_flag
Definition: hevcdec.h:328
av_refstruct_replace
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
av_md5_alloc
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
Definition: md5.c:50
AVRational::den
int den
Denominator.
Definition: rational.h:60
SliceHeader::slice_cr_qp_offset
int slice_cr_qp_offset
Definition: hevcdec.h:251
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
map_to_alpha_format
static enum AVPixelFormat map_to_alpha_format(HEVCContext *s, enum AVPixelFormat pix_fmt)
Definition: hevcdec.c:549
FF_HW_CALL
#define FF_HW_CALL(avctx, function,...)
Definition: hwaccel_internal.h:173
HEVCContext
Definition: hevcdec.h:490
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:593
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1618
HWACCEL_MAX
#define HWACCEL_MAX
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:294
HEVCContext::layers
HEVCLayerContext layers[HEVC_VPS_MAX_LAYERS]
Definition: hevcdec.h:498
SliceHeader::pic_order_cnt_lsb
int pic_order_cnt_lsb
Definition: hevcdec.h:215
HEVCLayerContext::DPB
HEVCFrame DPB[32]
Definition: hevcdec.h:453
AV3DReferenceDisplay::additional_shift_present_flag
uint8_t additional_shift_present_flag
An array of flags to indicates that the information about additional horizontal shift of the left and...
Definition: tdrdi.h:135
HEVCContext::rpu_buf
AVBufferRef * rpu_buf
0 or 1 Dolby Vision RPUs.
Definition: hevcdec.h:582
HEVCLocalContext::qPy_pred
int qPy_pred
Definition: hevcdec.h:418
ff_hevc_split_coding_unit_flag_decode
int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, uint8_t *tab_ct_depth, const HEVCSPS *sps, int ct_depth, int x0, int y0)
Definition: cabac.c:639
SCAN_DIAG
@ SCAN_DIAG
Definition: hevcdec.h:177
intra_prediction_unit_default_value
static void intra_prediction_unit_default_value(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCSPS *sps, int x0, int y0, int log2_cb_size)
Definition: hevcdec.c:2394
SliceHeader::rpl_modification_flag
uint8_t rpl_modification_flag[2]
Definition: hevcdec.h:233
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
pps
uint64_t pps
Definition: dovi_rpuenc.c:36
SAOParams::type_idx
uint8_t type_idx[3]
sao_type_idx
Definition: dsp.h:44
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:1774
HEVCWindow::right_offset
unsigned int right_offset
Definition: ps.h:93
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
av_tdrdi_alloc
AV3DReferenceDisplaysInfo * av_tdrdi_alloc(unsigned int nb_displays, size_t *out_size)
Allocate a AV3DReferenceDisplaysInfo structure and initialize its fields to default values.
Definition: tdrdi.c:25
MD5_PRI
#define MD5_PRI
ff_thread_progress_reset
static void ff_thread_progress_reset(ThreadProgress *pro)
Reset the ThreadProgress.progress counter; must only be called if the ThreadProgress is not in use in...
Definition: threadprogress.h:72
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
FF_CODEC_PROPERTY_CLOSED_CAPTIONS
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:1639
av_md5_update
void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
Update hash value.
Definition: md5.c:153
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
HEVCLocalContext::tu
TransformUnit tu
Definition: hevcdec.h:420
av_container_fifo_can_read
size_t av_container_fifo_can_read(const AVContainerFifo *cf)
Definition: container_fifo.c:185
CodingUnit::y
int y
Definition: hevcdec.h:292
src0
const pixel *const src0
Definition: h264pred_template.c:419
AVCodecInternal::draining
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
Definition: internal.h:139
HEVC_SCALABILITY_AUXILIARY
@ HEVC_SCALABILITY_AUXILIARY
Definition: hevc.h:169
av_log_once
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition: log.c:450
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
ff_hevc_cu_qp_delta_abs
int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc)
Definition: cabac.c:586
MvField::mv
Mv mv[2]
mvL0, vvL1
Definition: hevcdec.h:309
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:607
SliceHeader::inter_layer_pred
uint8_t inter_layer_pred
Definition: hevcdec.h:222
desc
const char * desc
Definition: libsvtav1.c:78
Mv
Definition: hevcdec.h:303
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ff_hevc_clear_refs
void ff_hevc_clear_refs(HEVCLayerContext *l)
Mark all frames in DPB as unused for reference.
Definition: refs.c:67
MvField::ref_idx
int8_t ref_idx[2]
refIdxL0, refIdxL1
Definition: hevcdec.h:310
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
PRED_L0
@ PRED_L0
Definition: hevcdec.h:112
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:353
AV3DReferenceDisplay::exponent_ref_viewing_distance
uint8_t exponent_ref_viewing_distance
The exponent part of the reference viewing distance of the n-th reference display.
Definition: tdrdi.h:124
HEVC_RECOVERY_END
#define HEVC_RECOVERY_END
Definition: hevcdec.h:80
HEVC_MAX_PPS_COUNT
@ HEVC_MAX_PPS_COUNT
Definition: hevc.h:117
HEVCVPS
Definition: ps.h:171
get_ue_golomb_long
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition: golomb.h:104
hevc_decode_extradata
static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
Definition: hevcdec.c:3800
EPEL_EXTRA
#define EPEL_EXTRA
Definition: hevcdec.h:61
ff_h2645_sei_ctx_replace
int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
Definition: h2645_sei.c:504
ff_hevc_slice_rpl
int ff_hevc_slice_rpl(HEVCContext *s)
Construct the reference picture list(s) for the current slice.
Definition: refs.c:343
HEVCContext::eos
int eos
current packet contains an EOS/EOB NAL
Definition: hevcdec.h:527
get_format
static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
Definition: hevcdec.c:577
HEVCLayerContext::sao
SAOParams * sao
Definition: hevcdec.h:461
HEVCSPS
Definition: ps.h:255
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:282
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
pic_arrays_init
static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
Definition: hevcdec.c:102
HEVCPPS
Definition: ps.h:374
HEVC_NAL_TRAIL_R
@ HEVC_NAL_TRAIL_R
Definition: hevc.h:30
CodingUnit::part_mode
enum PartMode part_mode
PartMode.
Definition: hevcdec.h:295
HEVC_NAL_RADL_R
@ HEVC_NAL_RADL_R
Definition: hevc.h:36
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_refstruct_pool_uninit
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition: refstruct.h:292
hevc_init_context
static av_cold int hevc_init_context(AVCodecContext *avctx)
Definition: hevcdec.c:3971
SliceHeader::tc_offset
int tc_offset
tc_offset_div2 * 2
Definition: hevcdec.h:260
LongTermRPS::nb_refs
uint8_t nb_refs
Definition: hevcdec.h:191
AV_OPT_FLAG_EXPORT
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition: opt.h:363
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
TransformUnit::cross_pf
uint8_t cross_pf
Definition: hevcdec.h:346
HEVCLocalContext::cu
CodingUnit cu
Definition: hevcdec.h:435
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
av_fast_malloc
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:557
H2645SEI::dynamic_hdr_plus
HEVCSEIDynamicHDRPlus dynamic_hdr_plus
Definition: h2645_sei.h:131
SliceHeader::pps_id
unsigned int pps_id
Definition: hevcdec.h:206
SliceHeader::luma_weight_l1
int16_t luma_weight_l1[16]
Definition: hevcdec.h:278
hevc_luma_mv_mvp_mode
static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv)
Definition: hevcdec.c:2047
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:70
HEVCParamSets::vps_list
const HEVCVPS * vps_list[HEVC_MAX_VPS_COUNT]
RefStruct references.
Definition: ps.h:512
FFMAX3
#define FFMAX3(a, b, c)
Definition: macros.h:48
OFFSET
#define OFFSET(x)
Definition: hevcdec.c:4205
ff_hevc_log2_res_scale_abs
int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx)
Definition: cabac.c:851
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
int32_t
int32_t
Definition: audioconvert.c:56
decode_slice_data
static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, const H2645NAL *nal, GetBitContext *gb)
Definition: hevcdec.c:3027
PredictionUnit::mpm_idx
int mpm_idx
Definition: hevcdec.h:324
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVCodecContext::properties
attribute_deprecated unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:1637
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:472
ff_hevc_sao_offset_sign_decode
int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc)
Definition: cabac.c:551
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
PredictionUnit::chroma_mode_c
uint8_t chroma_mode_c[4]
Definition: hevcdec.h:330
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
skip_bytes
static const av_unused uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
Definition: cabac_functions.h:203
PredictionUnit::intra_pred_mode
uint8_t intra_pred_mode[4]
Definition: hevcdec.h:326
TransformUnit::is_cu_chroma_qp_offset_coded
uint8_t is_cu_chroma_qp_offset_coded
Definition: hevcdec.h:343
h
h
Definition: vp9dsp_template.c:2070
hevc_frame_end
static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l)
Definition: hevcdec.c:3486
BOUNDARY_LEFT_SLICE
#define BOUNDARY_LEFT_SLICE
Definition: hevcdec.h:439
ff_h2645_packet_split
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int nal_length_size, enum AVCodecID codec_id, int flags)
Split an input packet into NAL units.
Definition: h2645_parse.c:466
SliceHeader::slice_qp_delta
int slice_qp_delta
Definition: hevcdec.h:249
stride
#define stride
Definition: h264pred_template.c:536
SliceHeader::slice_addr
unsigned int slice_addr
address (in raster order) of the first block in the current slice
Definition: hevcdec.h:211
SliceHeader::use_integer_mv_flag
uint8_t use_integer_mv_flag
Definition: hevcdec.h:263
avstring.h
atomic_init
#define atomic_init(obj, value)
Definition: stdatomic.h:33
HEVCLayerContext::rpl_tab_pool
struct AVRefStructPool * rpl_tab_pool
Definition: hevcdec.h:487
ff_hevc_hls_filter
void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, int x, int y, int ctb_size)
Definition: filter.c:872
width
#define width
Definition: dsp.h:89
TransformUnit::intra_pred_mode_c
int intra_pred_mode_c
Definition: hevcdec.h:340
AV3DReferenceDisplay::left_view_id
uint16_t left_view_id
The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
Definition: tdrdi.h:104
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:228
HEVC_NAL_RADL_N
@ HEVC_NAL_RADL_N
Definition: hevc.h:35
AV_FILM_GRAIN_PARAMS_AV1
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
Definition: film_grain_params.h:30
hevc_sei_to_context
static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei)
Definition: hevcdec.c:4107
hls_pcm_sample
static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, int x0, int y0, int log2_cb_size)
Definition: hevcdec.c:1657
HEVCLocalContext::end_of_tiles_y
int end_of_tiles_y
Definition: hevcdec.h:427
AVFilmGrainParams::type
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
Definition: film_grain_params.h:205
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
HEVCContext::poc_tid0
int poc_tid0
Definition: hevcdec.h:525
CodingUnit::intra_split_flag
uint8_t intra_split_flag
IntraSplitFlag.
Definition: hevcdec.h:298
H2645SEI::alternative_transfer
H2645SEIAlternativeTransfer alternative_transfer
Definition: h2645_sei.h:137
POS
#define POS(c_idx, x, y)
HEVCSPS::pix_fmt
enum AVPixelFormat pix_fmt
Definition: ps.h:268
SHIFT_CTB_WPP
#define SHIFT_CTB_WPP
Definition: hevcdec.h:45
av_color_transfer_name
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:3823
ff_hevc_intra_chroma_pred_mode_decode
int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc)
Definition: cabac.c:725
luma_intra_pred_mode
static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCSPS *sps, int x0, int y0, int pu_size, int prev_intra_luma_pred_flag)
8.4.1
Definition: hevcdec.c:2224
PART_2NxN
@ PART_2NxN
Definition: hevcdec.h:96
av_frame_side_data_add
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
Definition: side_data.c:223
src
#define src
Definition: vp8dsp.c:248
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:400
SliceHeader::long_term_rps
LongTermRPS long_term_rps
Definition: hevcdec.h:230
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
HEVCLayerContext::is_pcm
uint8_t * is_pcm
Definition: hevcdec.h:471
HEVC_NAL_FD_NUT
@ HEVC_NAL_FD_NUT
Definition: hevc.h:67
HEVC_NAL_BLA_W_RADL
@ HEVC_NAL_BLA_W_RADL
Definition: hevc.h:46
tdrdi.h
HEVC_NAL_TRAIL_N
@ HEVC_NAL_TRAIL_N
Definition: hevc.h:29
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3376
HEVC_SLICE_P
@ HEVC_SLICE_P
Definition: hevc.h:97
HEVCLocalContext::cc
CABACContext cc
Definition: hevcdec.h:401
TransformUnit::cu_qp_offset_cr
int8_t cu_qp_offset_cr
Definition: hevcdec.h:345
ff_dovi_ctx_replace
void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
Definition: dovi_rpu.c:59
HEVC_NAL_BLA_W_LP
@ HEVC_NAL_BLA_W_LP
Definition: hevc.h:45
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:55
ff_hevc_rem_intra_luma_pred_mode_decode
int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc)
Definition: cabac.c:715