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