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