FFmpeg
ps.c
Go to the documentation of this file.
1 /*
2  * HEVC Parameter Set decoding
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) 2013 Vittorio Giovara
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 "libavutil/imgutils.h"
27 #include "libavutil/mem.h"
28 #include "golomb.h"
29 #include "h2645_vui.h"
30 #include "data.h"
31 #include "ps.h"
32 #include "refstruct.h"
33 
34 static const uint8_t default_scaling_list_intra[] = {
35  16, 16, 16, 16, 17, 18, 21, 24,
36  16, 16, 16, 16, 17, 19, 22, 25,
37  16, 16, 17, 18, 20, 22, 25, 29,
38  16, 16, 18, 21, 24, 27, 31, 36,
39  17, 17, 20, 24, 30, 35, 41, 47,
40  18, 19, 22, 27, 35, 44, 54, 65,
41  21, 22, 25, 31, 41, 54, 70, 88,
42  24, 25, 29, 36, 47, 65, 88, 115
43 };
44 
45 static const uint8_t default_scaling_list_inter[] = {
46  16, 16, 16, 16, 17, 18, 20, 24,
47  16, 16, 16, 17, 18, 20, 24, 25,
48  16, 16, 17, 18, 20, 24, 25, 28,
49  16, 17, 18, 20, 24, 25, 28, 33,
50  17, 18, 20, 24, 25, 28, 33, 41,
51  18, 20, 24, 25, 28, 33, 41, 54,
52  20, 24, 25, 28, 33, 41, 54, 71,
53  24, 25, 28, 33, 41, 54, 71, 91
54 };
55 
56 static const uint8_t hevc_sub_width_c[] = {
57  1, 2, 2, 1
58 };
59 
60 static const uint8_t hevc_sub_height_c[] = {
61  1, 2, 1, 1
62 };
63 
64 static void remove_sps(HEVCParamSets *s, int id)
65 {
66  int i;
67  if (s->sps_list[id]) {
68  if (s->sps == s->sps_list[id])
69  s->sps = NULL;
70 
71  /* drop all PPS that depend on this SPS */
72  for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
73  if (s->pps_list[i] && s->pps_list[i]->sps_id == id)
74  ff_refstruct_unref(&s->pps_list[i]);
75 
76  av_assert0(!(s->sps_list[id] && s->sps == s->sps_list[id]));
77  ff_refstruct_unref(&s->sps_list[id]);
78  }
79 }
80 
81 static void remove_vps(HEVCParamSets *s, int id)
82 {
83  int i;
84  if (s->vps_list[id]) {
85  if (s->vps == s->vps_list[id])
86  s->vps = NULL;
87 
88  for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)
89  if (s->sps_list[i] && s->sps_list[i]->vps_id == id)
90  remove_sps(s, i);
91  ff_refstruct_unref(&s->vps_list[id]);
92  }
93 }
94 
96  ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
97 {
98  int delta_poc;
99  int k0 = 0;
100  int k = 0;
101  int i;
102 
103  rps->used = 0;
104  rps->rps_predict = 0;
105 
106  if (rps != sps->st_rps && sps->nb_st_rps)
107  rps->rps_predict = get_bits1(gb);
108 
109  if (rps->rps_predict) {
110  const ShortTermRPS *rps_ridx;
111  uint8_t used[32] = { 0 };
112  int delta_rps;
113 
114  if (is_slice_header) {
115  rps->delta_idx = get_ue_golomb_long(gb) + 1;
116  if (rps->delta_idx > sps->nb_st_rps) {
117  av_log(avctx, AV_LOG_ERROR,
118  "Invalid value of delta_idx in slice header RPS: %d > %d.\n",
119  rps->delta_idx, sps->nb_st_rps);
120  return AVERROR_INVALIDDATA;
121  }
122  rps_ridx = &sps->st_rps[sps->nb_st_rps - rps->delta_idx];
123  rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs;
124  } else
125  rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];
126 
127  rps->delta_rps_sign = get_bits1(gb);
128  rps->abs_delta_rps = get_ue_golomb_long(gb) + 1;
129  if (rps->abs_delta_rps > 32768) {
130  av_log(avctx, AV_LOG_ERROR,
131  "Invalid value of abs_delta_rps: %d\n",
132  rps->abs_delta_rps);
133  return AVERROR_INVALIDDATA;
134  }
135  delta_rps = (1 - (rps->delta_rps_sign << 1)) * rps->abs_delta_rps;
136  for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {
137  used[k] = get_bits1(gb);
138 
139  rps->use_delta = 0;
140  if (!used[k])
141  rps->use_delta = get_bits1(gb);
142 
143  if (used[k] || rps->use_delta) {
144  if (i < rps_ridx->num_delta_pocs)
145  delta_poc = delta_rps + rps_ridx->delta_poc[i];
146  else
147  delta_poc = delta_rps;
148  rps->delta_poc[k] = delta_poc;
149  if (delta_poc < 0)
150  k0++;
151  k++;
152  }
153  }
154 
155  if (k >= FF_ARRAY_ELEMS(used)) {
156  av_log(avctx, AV_LOG_ERROR,
157  "Invalid num_delta_pocs: %d\n", k);
158  return AVERROR_INVALIDDATA;
159  }
160 
161  rps->num_delta_pocs = k;
162  rps->num_negative_pics = k0;
163  // sort in increasing order (smallest first)
164  if (rps->num_delta_pocs != 0) {
165  int u, tmp;
166  for (i = 1; i < rps->num_delta_pocs; i++) {
167  delta_poc = rps->delta_poc[i];
168  u = used[i];
169  for (k = i - 1; k >= 0; k--) {
170  tmp = rps->delta_poc[k];
171  if (delta_poc < tmp) {
172  rps->delta_poc[k + 1] = tmp;
173  used[k + 1] = used[k];
174  rps->delta_poc[k] = delta_poc;
175  used[k] = u;
176  }
177  }
178  }
179  }
180  if ((rps->num_negative_pics >> 1) != 0) {
181  int u;
182  k = rps->num_negative_pics - 1;
183  // flip the negative values to largest first
184  for (i = 0; i < rps->num_negative_pics >> 1; i++) {
185  delta_poc = rps->delta_poc[i];
186  u = used[i];
187  rps->delta_poc[i] = rps->delta_poc[k];
188  used[i] = used[k];
189  rps->delta_poc[k] = delta_poc;
190  used[k] = u;
191  k--;
192  }
193  }
194 
195  for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++)
196  rps->used |= (uint32_t)used[i] << i;
197  } else {
198  unsigned int nb_positive_pics;
199 
201  nb_positive_pics = get_ue_golomb_long(gb);
202 
203  if (rps->num_negative_pics >= HEVC_MAX_REFS ||
204  nb_positive_pics >= HEVC_MAX_REFS) {
205  av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n");
206  return AVERROR_INVALIDDATA;
207  }
208 
209  rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics;
210  if (rps->num_delta_pocs) {
211  int prev = 0;
212 
213  for (i = 0; i < rps->num_negative_pics; i++) {
214  delta_poc = get_ue_golomb_long(gb) + 1;
215  if (delta_poc < 1 || delta_poc > 32768) {
216  av_log(avctx, AV_LOG_ERROR,
217  "Invalid value of delta_poc: %d\n",
218  delta_poc);
219  return AVERROR_INVALIDDATA;
220  }
221  prev -= delta_poc;
222  rps->delta_poc[i] = prev;
223  rps->used |= get_bits1(gb) * (1 << i);
224  }
225  prev = 0;
226  for (i = 0; i < nb_positive_pics; i++) {
227  delta_poc = get_ue_golomb_long(gb) + 1;
228  if (delta_poc < 1 || delta_poc > 32768) {
229  av_log(avctx, AV_LOG_ERROR,
230  "Invalid value of delta_poc: %d\n",
231  delta_poc);
232  return AVERROR_INVALIDDATA;
233  }
234  prev += delta_poc;
235  rps->delta_poc[rps->num_negative_pics + i] = prev;
236  rps->used |= get_bits1(gb) * (1 << (rps->num_negative_pics + i));
237  }
238  }
239  }
240  return 0;
241 }
242 
243 
245  PTLCommon *ptl)
246 {
247  int i;
248 
249  if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 43 + 1)
250  return -1;
251 
252  ptl->profile_space = get_bits(gb, 2);
253  ptl->tier_flag = get_bits1(gb);
254  ptl->profile_idc = get_bits(gb, 5);
255  if (ptl->profile_idc == AV_PROFILE_HEVC_MAIN)
256  av_log(avctx, AV_LOG_DEBUG, "Main profile bitstream\n");
257  else if (ptl->profile_idc == AV_PROFILE_HEVC_MAIN_10)
258  av_log(avctx, AV_LOG_DEBUG, "Main 10 profile bitstream\n");
259  else if (ptl->profile_idc == AV_PROFILE_HEVC_MAIN_STILL_PICTURE)
260  av_log(avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n");
261  else if (ptl->profile_idc == AV_PROFILE_HEVC_REXT)
262  av_log(avctx, AV_LOG_DEBUG, "Range Extension profile bitstream\n");
263  else if (ptl->profile_idc == AV_PROFILE_HEVC_SCC)
264  av_log(avctx, AV_LOG_DEBUG, "Screen Content Coding Extension profile bitstream\n");
265  else
266  av_log(avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", ptl->profile_idc);
267 
268  for (i = 0; i < 32; i++) {
269  ptl->profile_compatibility_flag[i] = get_bits1(gb);
270 
271  if (ptl->profile_idc == 0 && i > 0 && ptl->profile_compatibility_flag[i])
272  ptl->profile_idc = i;
273  }
274  ptl->progressive_source_flag = get_bits1(gb);
275  ptl->interlaced_source_flag = get_bits1(gb);
276  ptl->non_packed_constraint_flag = get_bits1(gb);
277  ptl->frame_only_constraint_flag = get_bits1(gb);
278 
279 #define check_profile_idc(idc) \
280  ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc]
281 
284  check_profile_idc(10)) {
285 
286  ptl->max_12bit_constraint_flag = get_bits1(gb);
287  ptl->max_10bit_constraint_flag = get_bits1(gb);
288  ptl->max_8bit_constraint_flag = get_bits1(gb);
289  ptl->max_422chroma_constraint_flag = get_bits1(gb);
290  ptl->max_420chroma_constraint_flag = get_bits1(gb);
291  ptl->max_monochrome_constraint_flag = get_bits1(gb);
292  ptl->intra_constraint_flag = get_bits1(gb);
293  ptl->one_picture_only_constraint_flag = get_bits1(gb);
294  ptl->lower_bit_rate_constraint_flag = get_bits1(gb);
295 
297  ptl->max_14bit_constraint_flag = get_bits1(gb);
298  skip_bits_long(gb, 33); // XXX_reserved_zero_33bits[0..32]
299  } else {
300  skip_bits_long(gb, 34); // XXX_reserved_zero_34bits[0..33]
301  }
302  } else if (check_profile_idc(2)) {
303  skip_bits(gb, 7);
304  ptl->one_picture_only_constraint_flag = get_bits1(gb);
305  skip_bits_long(gb, 35); // XXX_reserved_zero_35bits[0..34]
306  } else {
307  skip_bits_long(gb, 43); // XXX_reserved_zero_43bits[0..42]
308  }
309 
312  ptl->inbld_flag = get_bits1(gb);
313  else
314  skip_bits1(gb);
315 #undef check_profile_idc
316 
317  return 0;
318 }
319 
320 static int parse_ptl(GetBitContext *gb, AVCodecContext *avctx,
321  PTL *ptl, int max_num_sub_layers)
322 {
323  int i;
324  if (decode_profile_tier_level(gb, avctx, &ptl->general_ptl) < 0 ||
325  get_bits_left(gb) < 8 + (8*2 * (max_num_sub_layers - 1 > 0))) {
326  av_log(avctx, AV_LOG_ERROR, "PTL information too short\n");
327  return -1;
328  }
329 
330  ptl->general_ptl.level_idc = get_bits(gb, 8);
331 
332  for (i = 0; i < max_num_sub_layers - 1; i++) {
335  }
336 
337  if (max_num_sub_layers - 1> 0)
338  for (i = max_num_sub_layers - 1; i < 8; i++)
339  skip_bits(gb, 2); // reserved_zero_2bits[i]
340  for (i = 0; i < max_num_sub_layers - 1; i++) {
342  decode_profile_tier_level(gb, avctx, &ptl->sub_layer_ptl[i]) < 0) {
343  av_log(avctx, AV_LOG_ERROR,
344  "PTL information for sublayer %i too short\n", i);
345  return -1;
346  }
348  if (get_bits_left(gb) < 8) {
349  av_log(avctx, AV_LOG_ERROR,
350  "Not enough data for sublayer %i level_idc\n", i);
351  return -1;
352  } else
353  ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8);
354  }
355  }
356 
357  return 0;
358 }
359 
360 static void decode_sublayer_hrd(GetBitContext *gb, unsigned int nb_cpb,
361  HEVCSublayerHdrParams *par, int subpic_params_present)
362 {
363  int i;
364 
365  for (i = 0; i < nb_cpb; i++) {
368 
369  if (subpic_params_present) {
372  }
373 
374  par->cbr_flag |= get_bits1(gb) << i;
375  }
376 }
377 
378 static int decode_hrd(GetBitContext *gb, int common_inf_present,
379  HEVCHdrParams *hdr, int max_sublayers)
380 {
381  if (common_inf_present) {
384 
388 
390  hdr->tick_divisor_minus2 = get_bits(gb, 8);
394  }
395 
396  hdr->bit_rate_scale = get_bits(gb, 4);
397  hdr->cpb_size_scale = get_bits(gb, 4);
398 
400  hdr->cpb_size_du_scale = get_bits(gb, 4);
401 
405  }
406  }
407 
408  for (int i = 0; i < max_sublayers; i++) {
409  unsigned fixed_pic_rate_general_flag = get_bits1(gb);
410  unsigned fixed_pic_rate_within_cvs_flag = 0;
411  unsigned low_delay_hrd_flag = 0;
412  hdr->flags.fixed_pic_rate_general_flag |= fixed_pic_rate_general_flag << i;
413 
414  if (!fixed_pic_rate_general_flag)
415  fixed_pic_rate_within_cvs_flag = get_bits1(gb);
416  hdr->flags.fixed_pic_rate_within_cvs_flag |= fixed_pic_rate_within_cvs_flag << i;
417 
418  if (fixed_pic_rate_within_cvs_flag || fixed_pic_rate_general_flag)
420  else
421  low_delay_hrd_flag = get_bits1(gb);
422  hdr->flags.low_delay_hrd_flag |= low_delay_hrd_flag << i;
423 
424  if (!low_delay_hrd_flag) {
425  unsigned cpb_cnt_minus1 = get_ue_golomb_long(gb);
426  if (cpb_cnt_minus1 > 31) {
427  av_log(NULL, AV_LOG_ERROR, "nb_cpb %d invalid\n",
428  cpb_cnt_minus1);
429  return AVERROR_INVALIDDATA;
430  }
431  hdr->cpb_cnt_minus1[i] = cpb_cnt_minus1;
432  }
433 
435  decode_sublayer_hrd(gb, hdr->cpb_cnt_minus1[i]+1, &hdr->nal_params[i],
437 
439  decode_sublayer_hrd(gb, hdr->cpb_cnt_minus1[i]+1, &hdr->vcl_params[i],
441  }
442 
443  return 0;
444 }
445 
446 static void hevc_vps_free(FFRefStructOpaque opaque, void *obj)
447 {
448  HEVCVPS *vps = obj;
449 
450  av_freep(&vps->hdr);
451  av_freep(&vps->data);
452 }
453 
455  HEVCParamSets *ps)
456 {
457  int i,j;
458  int vps_id = get_bits(gb, 4);
459  ptrdiff_t nal_size = gb->buffer_end - gb->buffer;
460  int ret = AVERROR_INVALIDDATA;
461  HEVCVPS *vps;
462 
463  if (ps->vps_list[vps_id]) {
464  const HEVCVPS *vps1 = ps->vps_list[vps_id];
465  if (vps1->data_size == nal_size &&
466  !memcmp(vps1->data, gb->buffer, vps1->data_size))
467  return 0;
468  }
469 
471  if (!vps)
472  return AVERROR(ENOMEM);
473 
474  av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n");
475 
476  vps->data_size = nal_size;
477  vps->data = av_memdup(gb->buffer, nal_size);
478  if (!vps->data) {
479  ret = AVERROR(ENOMEM);
480  goto err;
481  }
482  vps->vps_id = vps_id;
483 
484  if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits
485  av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
486  goto err;
487  }
488 
489  vps->vps_max_layers = get_bits(gb, 6) + 1;
490  vps->vps_max_sub_layers = get_bits(gb, 3) + 1;
491  vps->vps_temporal_id_nesting_flag = get_bits1(gb);
492 
493  if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits
494  av_log(avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n");
495  goto err;
496  }
497 
498  if (vps->vps_max_sub_layers > HEVC_MAX_SUB_LAYERS) {
499  av_log(avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n",
500  vps->vps_max_sub_layers);
501  goto err;
502  }
503 
504  if (parse_ptl(gb, avctx, &vps->ptl, vps->vps_max_sub_layers) < 0)
505  goto err;
506 
507  vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb);
508 
509  i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1;
510  for (; i < vps->vps_max_sub_layers; i++) {
511  vps->vps_max_dec_pic_buffering[i] = get_ue_golomb_long(gb) + 1;
512  vps->vps_num_reorder_pics[i] = get_ue_golomb_long(gb);
513  vps->vps_max_latency_increase[i] = get_ue_golomb_long(gb) - 1;
514 
515  if (vps->vps_max_dec_pic_buffering[i] > HEVC_MAX_DPB_SIZE || !vps->vps_max_dec_pic_buffering[i]) {
516  av_log(avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n",
517  vps->vps_max_dec_pic_buffering[i] - 1);
518  goto err;
519  }
520  if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) {
521  av_log(avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n",
522  vps->vps_num_reorder_pics[i]);
523  if (avctx->err_recognition & AV_EF_EXPLODE)
524  goto err;
525  }
526  }
527 
528  vps->vps_max_layer_id = get_bits(gb, 6);
529  vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1;
530  if (vps->vps_num_layer_sets < 1 || vps->vps_num_layer_sets > 1024 ||
531  (vps->vps_num_layer_sets - 1LL) * (vps->vps_max_layer_id + 1LL) > get_bits_left(gb)) {
532  av_log(avctx, AV_LOG_ERROR, "too many layer_id_included_flags\n");
533  goto err;
534  }
535 
536  for (i = 1; i < vps->vps_num_layer_sets; i++)
537  for (j = 0; j <= vps->vps_max_layer_id; j++)
538  skip_bits(gb, 1); // layer_id_included_flag[i][j]
539 
540  vps->vps_timing_info_present_flag = get_bits1(gb);
541  if (vps->vps_timing_info_present_flag) {
542  vps->vps_num_units_in_tick = get_bits_long(gb, 32);
543  vps->vps_time_scale = get_bits_long(gb, 32);
544  vps->vps_poc_proportional_to_timing_flag = get_bits1(gb);
545  if (vps->vps_poc_proportional_to_timing_flag)
546  vps->vps_num_ticks_poc_diff_one = get_ue_golomb_long(gb) + 1;
547  vps->vps_num_hrd_parameters = get_ue_golomb_long(gb);
548  if (vps->vps_num_hrd_parameters > (unsigned)vps->vps_num_layer_sets) {
549  av_log(avctx, AV_LOG_ERROR,
550  "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters);
551  goto err;
552  }
553 
554  if (vps->vps_num_hrd_parameters) {
555  vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
556  if (!vps->hdr)
557  goto err;
558  }
559 
560  for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
561  int common_inf_present = 1;
562 
563  get_ue_golomb_long(gb); // hrd_layer_set_idx
564  if (i)
565  common_inf_present = get_bits1(gb);
566  decode_hrd(gb, common_inf_present, &vps->hdr[i],
567  vps->vps_max_sub_layers);
568  }
569  }
570  get_bits1(gb); /* vps_extension_flag */
571 
572  if (get_bits_left(gb) < 0) {
573  av_log(avctx, AV_LOG_ERROR,
574  "Overread VPS by %d bits\n", -get_bits_left(gb));
575  if (ps->vps_list[vps_id])
576  goto err;
577  }
578 
579  remove_vps(ps, vps_id);
580  ps->vps_list[vps_id] = vps;
581 
582  return 0;
583 
584 err:
586  return ret;
587 }
588 
589 static void decode_vui(GetBitContext *gb, AVCodecContext *avctx,
590  int apply_defdispwin, HEVCSPS *sps)
591 {
592  VUI backup_vui, *vui = &sps->vui;
593  GetBitContext backup;
594  int alt = 0;
595 
596  ff_h2645_decode_common_vui_params(gb, &sps->vui.common, avctx);
597 
599  if (vui->common.video_full_range_flag && sps->pix_fmt == AV_PIX_FMT_YUV420P)
600  sps->pix_fmt = AV_PIX_FMT_YUVJ420P;
602  if (vui->common.matrix_coeffs == AVCOL_SPC_RGB) {
603  switch (sps->pix_fmt) {
604  case AV_PIX_FMT_YUV444P:
605  sps->pix_fmt = AV_PIX_FMT_GBRP;
606  break;
608  sps->pix_fmt = AV_PIX_FMT_GBRP10;
609  break;
611  sps->pix_fmt = AV_PIX_FMT_GBRP12;
612  break;
613  }
614  }
615  }
616  }
617 
619  vui->field_seq_flag = get_bits1(gb);
621 
622  // Backup context in case an alternate header is detected
623  memcpy(&backup, gb, sizeof(backup));
624  memcpy(&backup_vui, vui, sizeof(backup_vui));
625  if (get_bits_left(gb) >= 68 && show_bits(gb, 21) == 0x100000) {
627  av_log(avctx, AV_LOG_WARNING, "Invalid default display window\n");
628  } else
630 
631  if (vui->default_display_window_flag) {
632  int vert_mult = hevc_sub_height_c[sps->chroma_format_idc];
633  int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc];
634  vui->def_disp_win.left_offset = get_ue_golomb_long(gb) * horiz_mult;
635  vui->def_disp_win.right_offset = get_ue_golomb_long(gb) * horiz_mult;
636  vui->def_disp_win.top_offset = get_ue_golomb_long(gb) * vert_mult;
637  vui->def_disp_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult;
638 
639  if (apply_defdispwin &&
641  av_log(avctx, AV_LOG_DEBUG,
642  "discarding vui default display window, "
643  "original values are l:%u r:%u t:%u b:%u\n",
648 
651  vui->def_disp_win.top_offset =
652  vui->def_disp_win.bottom_offset = 0;
653  }
654  }
655 
658 
659  if (vui->vui_timing_info_present_flag) {
660  if( get_bits_left(gb) < 66 && !alt) {
661  // The alternate syntax seem to have timing info located
662  // at where def_disp_win is normally located
663  av_log(avctx, AV_LOG_WARNING,
664  "Strange VUI timing information, retrying...\n");
665  memcpy(vui, &backup_vui, sizeof(backup_vui));
666  memcpy(gb, &backup, sizeof(backup));
667  alt = 1;
668  goto timing_info;
669  }
670  vui->vui_num_units_in_tick = get_bits_long(gb, 32);
671  vui->vui_time_scale = get_bits_long(gb, 32);
672  if (alt) {
673  av_log(avctx, AV_LOG_INFO, "Retry got %"PRIu32"/%"PRIu32" fps\n",
675  }
681  decode_hrd(gb, 1, &sps->hdr, sps->max_sub_layers);
682  }
683 
685  if (vui->bitstream_restriction_flag) {
686  if (get_bits_left(gb) < 8 && !alt) {
687  av_log(avctx, AV_LOG_WARNING,
688  "Strange VUI bitstream restriction information, retrying"
689  " from timing information...\n");
690  memcpy(vui, &backup_vui, sizeof(backup_vui));
691  memcpy(gb, &backup, sizeof(backup));
692  alt = 1;
693  goto timing_info;
694  }
703  }
704 
705  if (get_bits_left(gb) < 1 && !alt) {
706  // XXX: Alternate syntax when sps_range_extension_flag != 0?
707  av_log(avctx, AV_LOG_WARNING,
708  "Overread in VUI, retrying from timing information...\n");
709  memcpy(vui, &backup_vui, sizeof(backup_vui));
710  memcpy(gb, &backup, sizeof(backup));
711  alt = 1;
712  goto timing_info;
713  }
714 }
715 
717 {
718  int matrixId;
719 
720  for (matrixId = 0; matrixId < 6; matrixId++) {
721  // 4x4 default is 16
722  memset(sl->sl[0][matrixId], 16, 16);
723  sl->sl_dc[0][matrixId] = 16; // default for 16x16
724  sl->sl_dc[1][matrixId] = 16; // default for 32x32
725  }
726  memcpy(sl->sl[1][0], default_scaling_list_intra, 64);
727  memcpy(sl->sl[1][1], default_scaling_list_intra, 64);
728  memcpy(sl->sl[1][2], default_scaling_list_intra, 64);
729  memcpy(sl->sl[1][3], default_scaling_list_inter, 64);
730  memcpy(sl->sl[1][4], default_scaling_list_inter, 64);
731  memcpy(sl->sl[1][5], default_scaling_list_inter, 64);
732  memcpy(sl->sl[2][0], default_scaling_list_intra, 64);
733  memcpy(sl->sl[2][1], default_scaling_list_intra, 64);
734  memcpy(sl->sl[2][2], default_scaling_list_intra, 64);
735  memcpy(sl->sl[2][3], default_scaling_list_inter, 64);
736  memcpy(sl->sl[2][4], default_scaling_list_inter, 64);
737  memcpy(sl->sl[2][5], default_scaling_list_inter, 64);
738  memcpy(sl->sl[3][0], default_scaling_list_intra, 64);
739  memcpy(sl->sl[3][1], default_scaling_list_intra, 64);
740  memcpy(sl->sl[3][2], default_scaling_list_intra, 64);
741  memcpy(sl->sl[3][3], default_scaling_list_inter, 64);
742  memcpy(sl->sl[3][4], default_scaling_list_inter, 64);
743  memcpy(sl->sl[3][5], default_scaling_list_inter, 64);
744 }
745 
747  ScalingList *sl, const HEVCSPS *sps)
748 {
749  uint8_t scaling_list_pred_mode_flag;
750  uint8_t scaling_list_dc_coef[2][6];
751  int size_id, matrix_id, pos;
752  int i;
753 
754  for (size_id = 0; size_id < 4; size_id++)
755  for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {
756  scaling_list_pred_mode_flag = get_bits1(gb);
757  if (!scaling_list_pred_mode_flag) {
758  unsigned int delta = get_ue_golomb_long(gb);
759  /* Only need to handle non-zero delta. Zero means default,
760  * which should already be in the arrays. */
761  if (delta) {
762  // Copy from previous array.
763  delta *= (size_id == 3) ? 3 : 1;
764  if (matrix_id < delta) {
765  av_log(avctx, AV_LOG_ERROR,
766  "Invalid delta in scaling list data: %d.\n", delta);
767  return AVERROR_INVALIDDATA;
768  }
769 
770  memcpy(sl->sl[size_id][matrix_id],
771  sl->sl[size_id][matrix_id - delta],
772  size_id > 0 ? 64 : 16);
773  if (size_id > 1)
774  sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta];
775  }
776  } else {
777  int next_coef, coef_num;
778  int32_t scaling_list_delta_coef;
779 
780  next_coef = 8;
781  coef_num = FFMIN(64, 1 << (4 + (size_id << 1)));
782  if (size_id > 1) {
783  int scaling_list_coeff_minus8 = get_se_golomb(gb);
784  if (scaling_list_coeff_minus8 < -7 ||
785  scaling_list_coeff_minus8 > 247)
786  return AVERROR_INVALIDDATA;
787  scaling_list_dc_coef[size_id - 2][matrix_id] = scaling_list_coeff_minus8 + 8;
788  next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
789  sl->sl_dc[size_id - 2][matrix_id] = next_coef;
790  }
791  for (i = 0; i < coef_num; i++) {
792  if (size_id == 0)
793  pos = 4 * ff_hevc_diag_scan4x4_y[i] +
795  else
796  pos = 8 * ff_hevc_diag_scan8x8_y[i] +
798 
799  scaling_list_delta_coef = get_se_golomb(gb);
800  next_coef = (next_coef + 256U + scaling_list_delta_coef) % 256;
801  sl->sl[size_id][matrix_id][pos] = next_coef;
802  }
803  }
804  }
805 
806  if (sps->chroma_format_idc == 3) {
807  for (i = 0; i < 64; i++) {
808  sl->sl[3][1][i] = sl->sl[2][1][i];
809  sl->sl[3][2][i] = sl->sl[2][2][i];
810  sl->sl[3][4][i] = sl->sl[2][4][i];
811  sl->sl[3][5][i] = sl->sl[2][5][i];
812  }
813  sl->sl_dc[1][1] = sl->sl_dc[0][1];
814  sl->sl_dc[1][2] = sl->sl_dc[0][2];
815  sl->sl_dc[1][4] = sl->sl_dc[0][4];
816  sl->sl_dc[1][5] = sl->sl_dc[0][5];
817  }
818 
819 
820  return 0;
821 }
822 
824 {
825  const AVPixFmtDescriptor *desc;
826  switch (sps->bit_depth) {
827  case 8:
828  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
829  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
830  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
831  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
832  break;
833  case 9:
834  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY9;
835  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9;
836  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9;
837  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9;
838  break;
839  case 10:
840  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10;
841  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
842  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
843  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
844  break;
845  case 12:
846  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12;
847  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
848  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
849  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
850  break;
851  default:
852  av_log(avctx, AV_LOG_ERROR,
853  "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, "
854  "chroma_format_idc is %d, depth is %d\n",
855  sps->chroma_format_idc, sps->bit_depth);
856  return AVERROR_INVALIDDATA;
857  }
858 
859  desc = av_pix_fmt_desc_get(sps->pix_fmt);
860  if (!desc)
861  return AVERROR(EINVAL);
862 
863  sps->hshift[0] = sps->vshift[0] = 0;
864  sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
865  sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
866 
867  sps->pixel_shift = sps->bit_depth > 8;
868 
869  return 0;
870 }
871 
873  int apply_defdispwin, const HEVCVPS * const *vps_list,
874  AVCodecContext *avctx)
875 {
876  HEVCWindow *ow;
877  int ret = 0;
878  int bit_depth_chroma, start, num_comps;
879  int i;
880 
881  // Coded parameters
882 
883  sps->vps_id = get_bits(gb, 4);
884 
885  if (vps_list) {
886  if (!vps_list[sps->vps_id]) {
887  av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
888  sps->vps_id);
889  return AVERROR_INVALIDDATA;
890  }
891  sps->vps = ff_refstruct_ref_c(vps_list[sps->vps_id]);
892  }
893 
894  sps->max_sub_layers = get_bits(gb, 3) + 1;
895  if (sps->max_sub_layers > HEVC_MAX_SUB_LAYERS) {
896  av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n",
897  sps->max_sub_layers);
898  return AVERROR_INVALIDDATA;
899  }
900 
901  sps->temporal_id_nesting = get_bits(gb, 1);
902 
903  if ((ret = parse_ptl(gb, avctx, &sps->ptl, sps->max_sub_layers)) < 0)
904  return ret;
905 
906  *sps_id = get_ue_golomb_long(gb);
907  if (*sps_id >= HEVC_MAX_SPS_COUNT) {
908  av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id);
909  return AVERROR_INVALIDDATA;
910  }
911 
912  sps->chroma_format_idc = get_ue_golomb_long(gb);
913  if (sps->chroma_format_idc > 3U) {
914  av_log(avctx, AV_LOG_ERROR, "chroma_format_idc %d is invalid\n", sps->chroma_format_idc);
915  return AVERROR_INVALIDDATA;
916  }
917 
918  if (sps->chroma_format_idc == 3)
919  sps->separate_colour_plane = get_bits1(gb);
920 
921  if (sps->separate_colour_plane)
922  sps->chroma_format_idc = 0;
923 
924  sps->width = get_ue_golomb_long(gb);
925  sps->height = get_ue_golomb_long(gb);
926  if ((ret = av_image_check_size(sps->width,
927  sps->height, 0, avctx)) < 0)
928  return ret;
929 
930  sps->conformance_window = get_bits1(gb);
931  if (sps->conformance_window) {
932  int vert_mult = hevc_sub_height_c[sps->chroma_format_idc];
933  int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc];
934  sps->pic_conf_win.left_offset = get_ue_golomb_long(gb) * horiz_mult;
935  sps->pic_conf_win.right_offset = get_ue_golomb_long(gb) * horiz_mult;
936  sps->pic_conf_win.top_offset = get_ue_golomb_long(gb) * vert_mult;
937  sps->pic_conf_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult;
938 
939  if (avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) {
940  av_log(avctx, AV_LOG_DEBUG,
941  "discarding sps conformance window, "
942  "original values are l:%u r:%u t:%u b:%u\n",
943  sps->pic_conf_win.left_offset,
944  sps->pic_conf_win.right_offset,
945  sps->pic_conf_win.top_offset,
946  sps->pic_conf_win.bottom_offset);
947 
948  sps->pic_conf_win.left_offset =
949  sps->pic_conf_win.right_offset =
950  sps->pic_conf_win.top_offset =
951  sps->pic_conf_win.bottom_offset = 0;
952  }
953  sps->output_window = sps->pic_conf_win;
954  }
955 
956  sps->bit_depth = get_ue_golomb_31(gb) + 8;
957  if (sps->bit_depth > 16) {
958  av_log(avctx, AV_LOG_ERROR, "Luma bit depth (%d) is out of range\n",
959  sps->bit_depth);
960  return AVERROR_INVALIDDATA;
961  }
962  bit_depth_chroma = get_ue_golomb_31(gb) + 8;
963  if (bit_depth_chroma > 16) {
964  av_log(avctx, AV_LOG_ERROR, "Chroma bit depth (%d) is out of range\n",
965  bit_depth_chroma);
966  return AVERROR_INVALIDDATA;
967  }
968  if (sps->chroma_format_idc && bit_depth_chroma != sps->bit_depth) {
969  av_log(avctx, AV_LOG_ERROR,
970  "Luma bit depth (%d) is different from chroma bit depth (%d), "
971  "this is unsupported.\n",
972  sps->bit_depth, bit_depth_chroma);
973  return AVERROR_INVALIDDATA;
974  }
975  sps->bit_depth_chroma = bit_depth_chroma;
976 
977  ret = map_pixel_format(avctx, sps);
978  if (ret < 0)
979  return ret;
980 
981  sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4;
982  if (sps->log2_max_poc_lsb > 16) {
983  av_log(avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n",
984  sps->log2_max_poc_lsb - 4);
985  return AVERROR_INVALIDDATA;
986  }
987 
988  sps->sublayer_ordering_info = get_bits1(gb);
989  start = sps->sublayer_ordering_info ? 0 : sps->max_sub_layers - 1;
990  for (i = start; i < sps->max_sub_layers; i++) {
991  sps->temporal_layer[i].max_dec_pic_buffering = get_ue_golomb_long(gb) + 1;
992  sps->temporal_layer[i].num_reorder_pics = get_ue_golomb_long(gb);
993  sps->temporal_layer[i].max_latency_increase = get_ue_golomb_long(gb) - 1;
994  if (sps->temporal_layer[i].max_dec_pic_buffering > (unsigned)HEVC_MAX_DPB_SIZE) {
995  av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n",
996  sps->temporal_layer[i].max_dec_pic_buffering - 1U);
997  return AVERROR_INVALIDDATA;
998  }
999  if (sps->temporal_layer[i].num_reorder_pics > sps->temporal_layer[i].max_dec_pic_buffering - 1) {
1000  av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n",
1001  sps->temporal_layer[i].num_reorder_pics);
1002  if (avctx->err_recognition & AV_EF_EXPLODE ||
1003  sps->temporal_layer[i].num_reorder_pics > HEVC_MAX_DPB_SIZE - 1) {
1004  return AVERROR_INVALIDDATA;
1005  }
1006  sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[i].num_reorder_pics + 1;
1007  }
1008  }
1009 
1010  if (!sps->sublayer_ordering_info) {
1011  for (i = 0; i < start; i++) {
1012  sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[start].max_dec_pic_buffering;
1013  sps->temporal_layer[i].num_reorder_pics = sps->temporal_layer[start].num_reorder_pics;
1014  sps->temporal_layer[i].max_latency_increase = sps->temporal_layer[start].max_latency_increase;
1015  }
1016  }
1017 
1018  sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3;
1019  sps->log2_diff_max_min_coding_block_size = get_ue_golomb_long(gb);
1020  sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2;
1021  sps->log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb);
1022  sps->log2_max_trafo_size = sps->log2_diff_max_min_transform_block_size +
1023  sps->log2_min_tb_size;
1024 
1025  if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) {
1026  av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size);
1027  return AVERROR_INVALIDDATA;
1028  }
1029 
1030  if (sps->log2_diff_max_min_coding_block_size > 30) {
1031  av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_coding_block_size", sps->log2_diff_max_min_coding_block_size);
1032  return AVERROR_INVALIDDATA;
1033  }
1034 
1035  if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) {
1036  av_log(avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size");
1037  return AVERROR_INVALIDDATA;
1038  }
1039 
1040  if (sps->log2_diff_max_min_transform_block_size > 30) {
1041  av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size",
1042  sps->log2_diff_max_min_transform_block_size);
1043  return AVERROR_INVALIDDATA;
1044  }
1045 
1046  sps->max_transform_hierarchy_depth_inter = get_ue_golomb_long(gb);
1047  sps->max_transform_hierarchy_depth_intra = get_ue_golomb_long(gb);
1048 
1049  sps->scaling_list_enabled = get_bits1(gb);
1050  if (sps->scaling_list_enabled) {
1051  set_default_scaling_list_data(&sps->scaling_list);
1052 
1053  if (get_bits1(gb)) {
1054  ret = scaling_list_data(gb, avctx, &sps->scaling_list, sps);
1055  if (ret < 0)
1056  return ret;
1057  }
1058  }
1059 
1060  sps->amp_enabled = get_bits1(gb);
1061  sps->sao_enabled = get_bits1(gb);
1062 
1063  sps->pcm_enabled = get_bits1(gb);
1064  if (sps->pcm_enabled) {
1065  sps->pcm.bit_depth = get_bits(gb, 4) + 1;
1066  sps->pcm.bit_depth_chroma = get_bits(gb, 4) + 1;
1067  sps->pcm.log2_min_pcm_cb_size = get_ue_golomb_long(gb) + 3;
1068  sps->pcm.log2_max_pcm_cb_size = sps->pcm.log2_min_pcm_cb_size +
1069  get_ue_golomb_long(gb);
1070  if (FFMAX(sps->pcm.bit_depth, sps->pcm.bit_depth_chroma) > sps->bit_depth) {
1071  av_log(avctx, AV_LOG_ERROR,
1072  "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n",
1073  sps->pcm.bit_depth, sps->pcm.bit_depth_chroma, sps->bit_depth);
1074  return AVERROR_INVALIDDATA;
1075  }
1076 
1077  sps->pcm_loop_filter_disabled = get_bits1(gb);
1078  }
1079 
1080  sps->nb_st_rps = get_ue_golomb_long(gb);
1081  if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) {
1082  av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n",
1083  sps->nb_st_rps);
1084  return AVERROR_INVALIDDATA;
1085  }
1086  for (i = 0; i < sps->nb_st_rps; i++) {
1087  if ((ret = ff_hevc_decode_short_term_rps(gb, avctx, &sps->st_rps[i],
1088  sps, 0)) < 0)
1089  return ret;
1090  }
1091 
1092  sps->long_term_ref_pics_present = get_bits1(gb);
1093  if (sps->long_term_ref_pics_present) {
1094  sps->num_long_term_ref_pics_sps = get_ue_golomb_long(gb);
1095  if (sps->num_long_term_ref_pics_sps > HEVC_MAX_LONG_TERM_REF_PICS) {
1096  av_log(avctx, AV_LOG_ERROR, "Too many long term ref pics: %d.\n",
1097  sps->num_long_term_ref_pics_sps);
1098  return AVERROR_INVALIDDATA;
1099  }
1100 
1101  sps->used_by_curr_pic_lt = 0;
1102  for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
1103  sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(gb, sps->log2_max_poc_lsb);
1104  sps->used_by_curr_pic_lt |= get_bits1(gb) * (1 << i);
1105  }
1106  }
1107 
1108  sps->temporal_mvp_enabled = get_bits1(gb);
1109  sps->strong_intra_smoothing_enabled = get_bits1(gb);
1110  sps->vui.common.sar = (AVRational){0, 1};
1111  sps->vui_present = get_bits1(gb);
1112  if (sps->vui_present)
1113  decode_vui(gb, avctx, apply_defdispwin, sps);
1114 
1115  sps->extension_present = get_bits1(gb);
1116  if (sps->extension_present) {
1117  sps->range_extension = get_bits1(gb);
1118  sps->multilayer_extension = get_bits1(gb);
1119  sps->sps_3d_extension = get_bits1(gb);
1120  sps->scc_extension = get_bits1(gb);
1121  skip_bits(gb, 4); // sps_extension_4bits
1122 
1123  if (sps->range_extension) {
1124  sps->transform_skip_rotation_enabled = get_bits1(gb);
1125  sps->transform_skip_context_enabled = get_bits1(gb);
1126  sps->implicit_rdpcm_enabled = get_bits1(gb);
1127  sps->explicit_rdpcm_enabled = get_bits1(gb);
1128 
1129  sps->extended_precision_processing = get_bits1(gb);
1130  if (sps->extended_precision_processing)
1131  av_log(avctx, AV_LOG_WARNING,
1132  "extended_precision_processing_flag not yet implemented\n");
1133 
1134  sps->intra_smoothing_disabled = get_bits1(gb);
1135  sps->high_precision_offsets_enabled = get_bits1(gb);
1136  if (sps->high_precision_offsets_enabled)
1137  av_log(avctx, AV_LOG_WARNING,
1138  "high_precision_offsets_enabled_flag not yet implemented\n");
1139 
1140  sps->persistent_rice_adaptation_enabled = get_bits1(gb);
1141 
1142  sps->cabac_bypass_alignment_enabled = get_bits1(gb);
1143  if (sps->cabac_bypass_alignment_enabled)
1144  av_log(avctx, AV_LOG_WARNING,
1145  "cabac_bypass_alignment_enabled_flag not yet implemented\n");
1146  }
1147 
1148  if (sps->multilayer_extension) {
1149  skip_bits1(gb); // inter_view_mv_vert_constraint_flag
1150  av_log(avctx, AV_LOG_WARNING,
1151  "sps_multilayer_extension_flag not yet implemented\n");
1152  }
1153 
1154  if (sps->sps_3d_extension) {
1155  for (i = 0; i <= 1; i++) {
1156  skip_bits1(gb); // iv_di_mc_enabled_flag
1157  skip_bits1(gb); // iv_mv_scal_enabled_flag
1158  if (i == 0) {
1159  get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
1160  skip_bits1(gb); // iv_res_pred_enabled_flag
1161  skip_bits1(gb); // depth_ref_enabled_flag
1162  skip_bits1(gb); // vsp_mc_enabled_flag
1163  skip_bits1(gb); // dbbp_enabled_flag
1164  } else {
1165  skip_bits1(gb); // tex_mc_enabled_flag
1166  get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
1167  skip_bits1(gb); // intra_contour_enabled_flag
1168  skip_bits1(gb); // intra_dc_only_wedge_enabled_flag
1169  skip_bits1(gb); // cqt_cu_part_pred_enabled_flag
1170  skip_bits1(gb); // inter_dc_only_enabled_flag
1171  skip_bits1(gb); // skip_intra_enabled_flag
1172  }
1173  }
1174  av_log(avctx, AV_LOG_WARNING,
1175  "sps_3d_extension_flag not yet implemented\n");
1176  }
1177 
1178  if (sps->scc_extension) {
1179  sps->curr_pic_ref_enabled = get_bits1(gb);
1180  sps->palette_mode_enabled = get_bits1(gb);
1181  if (sps->palette_mode_enabled) {
1182  sps->palette_max_size = get_ue_golomb(gb);
1183  sps->delta_palette_max_predictor_size = get_ue_golomb(gb);
1184  sps->palette_predictor_initializers_present = get_bits1(gb);
1185 
1186  if (sps->palette_predictor_initializers_present) {
1187  sps->sps_num_palette_predictor_initializers = get_ue_golomb(gb) + 1;
1188  if (sps->sps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) {
1189  av_log(avctx, AV_LOG_ERROR,
1190  "sps_num_palette_predictor_initializers out of range: %u\n",
1191  sps->sps_num_palette_predictor_initializers);
1192  return AVERROR_INVALIDDATA;
1193  }
1194  num_comps = !sps->chroma_format_idc ? 1 : 3;
1195  for (int comp = 0; comp < num_comps; comp++) {
1196  int bit_depth = !comp ? sps->bit_depth : sps->bit_depth_chroma;
1197  for (i = 0; i < sps->sps_num_palette_predictor_initializers; i++)
1198  sps->sps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth);
1199  }
1200  }
1201  }
1202  sps->motion_vector_resolution_control_idc = get_bits(gb, 2);
1203  sps->intra_boundary_filtering_disabled = get_bits1(gb);
1204  }
1205  }
1206  if (apply_defdispwin) {
1207  sps->output_window.left_offset += sps->vui.def_disp_win.left_offset;
1208  sps->output_window.right_offset += sps->vui.def_disp_win.right_offset;
1209  sps->output_window.top_offset += sps->vui.def_disp_win.top_offset;
1210  sps->output_window.bottom_offset += sps->vui.def_disp_win.bottom_offset;
1211  }
1212 
1213  ow = &sps->output_window;
1214  if (ow->left_offset >= INT_MAX - ow->right_offset ||
1215  ow->top_offset >= INT_MAX - ow->bottom_offset ||
1216  ow->left_offset + ow->right_offset >= sps->width ||
1217  ow->top_offset + ow->bottom_offset >= sps->height) {
1218  av_log(avctx, AV_LOG_WARNING, "Invalid cropping offsets: %u/%u/%u/%u\n",
1219  ow->left_offset, ow->right_offset, ow->top_offset, ow->bottom_offset);
1220  if (avctx->err_recognition & AV_EF_EXPLODE) {
1221  return AVERROR_INVALIDDATA;
1222  }
1223  av_log(avctx, AV_LOG_WARNING,
1224  "Displaying the whole video surface.\n");
1225  memset(ow, 0, sizeof(*ow));
1226  memset(&sps->pic_conf_win, 0, sizeof(sps->pic_conf_win));
1227  }
1228 
1229  // Inferred parameters
1230  sps->log2_ctb_size = sps->log2_min_cb_size +
1231  sps->log2_diff_max_min_coding_block_size;
1232  sps->log2_min_pu_size = sps->log2_min_cb_size - 1;
1233 
1234  if (sps->log2_ctb_size > HEVC_MAX_LOG2_CTB_SIZE) {
1235  av_log(avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size);
1236  return AVERROR_INVALIDDATA;
1237  }
1238  if (sps->log2_ctb_size < 4) {
1239  av_log(avctx,
1240  AV_LOG_ERROR,
1241  "log2_ctb_size %d differs from the bounds of any known profile\n",
1242  sps->log2_ctb_size);
1243  avpriv_request_sample(avctx, "log2_ctb_size %d", sps->log2_ctb_size);
1244  return AVERROR_INVALIDDATA;
1245  }
1246 
1247  sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
1248  sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
1249  sps->ctb_size = sps->ctb_width * sps->ctb_height;
1250 
1251  sps->min_cb_width = sps->width >> sps->log2_min_cb_size;
1252  sps->min_cb_height = sps->height >> sps->log2_min_cb_size;
1253  sps->min_tb_width = sps->width >> sps->log2_min_tb_size;
1254  sps->min_tb_height = sps->height >> sps->log2_min_tb_size;
1255  sps->min_pu_width = sps->width >> sps->log2_min_pu_size;
1256  sps->min_pu_height = sps->height >> sps->log2_min_pu_size;
1257  sps->tb_mask = (1 << (sps->log2_ctb_size - sps->log2_min_tb_size)) - 1;
1258 
1259  sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
1260 
1261  if (av_zero_extend(sps->width, sps->log2_min_cb_size) ||
1262  av_zero_extend(sps->height, sps->log2_min_cb_size)) {
1263  av_log(avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n");
1264  return AVERROR_INVALIDDATA;
1265  }
1266 
1267  if (sps->max_transform_hierarchy_depth_inter > sps->log2_ctb_size - sps->log2_min_tb_size) {
1268  av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n",
1269  sps->max_transform_hierarchy_depth_inter);
1270  return AVERROR_INVALIDDATA;
1271  }
1272  if (sps->max_transform_hierarchy_depth_intra > sps->log2_ctb_size - sps->log2_min_tb_size) {
1273  av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n",
1274  sps->max_transform_hierarchy_depth_intra);
1275  return AVERROR_INVALIDDATA;
1276  }
1277  if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) {
1278  av_log(avctx, AV_LOG_ERROR,
1279  "max transform block size out of range: %d\n",
1280  sps->log2_max_trafo_size);
1281  return AVERROR_INVALIDDATA;
1282  }
1283 
1284  if (get_bits_left(gb) < 0) {
1285  av_log(avctx, AV_LOG_ERROR,
1286  "Overread SPS by %d bits\n", -get_bits_left(gb));
1287  return AVERROR_INVALIDDATA;
1288  }
1289 
1290  return 0;
1291 }
1292 
1293 static void hevc_sps_free(FFRefStructOpaque opaque, void *obj)
1294 {
1295  HEVCSPS *sps = obj;
1296 
1297  ff_refstruct_unref(&sps->vps);
1298 
1299  av_freep(&sps->data);
1300 }
1301 
1302 static int compare_sps(const HEVCSPS *sps1, const HEVCSPS *sps2)
1303 {
1304  return sps1->data_size == sps2->data_size &&
1305  !memcmp(sps1->data, sps2->data, sps1->data_size);
1306 }
1307 
1309  HEVCParamSets *ps, int apply_defdispwin)
1310 {
1312  unsigned int sps_id;
1313  int ret;
1314 
1315  if (!sps)
1316  return AVERROR(ENOMEM);
1317 
1318  av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n");
1319 
1320  sps->data_size = gb->buffer_end - gb->buffer;
1321  sps->data = av_memdup(gb->buffer, sps->data_size);
1322  if (!sps->data) {
1323  ret = AVERROR(ENOMEM);
1324  goto err;
1325  }
1326 
1327  ret = ff_hevc_parse_sps(sps, gb, &sps_id,
1328  apply_defdispwin,
1329  ps->vps_list, avctx);
1330  if (ret < 0)
1331  goto err;
1332 
1333  if (avctx->debug & FF_DEBUG_BITSTREAM) {
1334  av_log(avctx, AV_LOG_DEBUG,
1335  "Parsed SPS: id %d; coded wxh: %dx%d; "
1336  "cropped wxh: %dx%d; pix_fmt: %s.\n",
1337  sps_id, sps->width, sps->height,
1338  sps->width - (sps->output_window.left_offset + sps->output_window.right_offset),
1339  sps->height - (sps->output_window.top_offset + sps->output_window.bottom_offset),
1340  av_get_pix_fmt_name(sps->pix_fmt));
1341  }
1342 
1343  /* check if this is a repeat of an already parsed SPS, then keep the
1344  * original one.
1345  * otherwise drop all PPSes that depend on it */
1346  if (ps->sps_list[sps_id] &&
1347  compare_sps(ps->sps_list[sps_id], sps)) {
1349  } else {
1350  remove_sps(ps, sps_id);
1351  ps->sps_list[sps_id] = sps;
1352  }
1353 
1354  return 0;
1355 err:
1357  return ret;
1358 }
1359 
1360 static void hevc_pps_free(FFRefStructOpaque unused, void *obj)
1361 {
1362  HEVCPPS *pps = obj;
1363 
1364  ff_refstruct_unref(&pps->sps);
1365 
1366  av_freep(&pps->column_width);
1367  av_freep(&pps->row_height);
1368  av_freep(&pps->col_bd);
1369  av_freep(&pps->row_bd);
1370  av_freep(&pps->col_idxX);
1371  av_freep(&pps->ctb_addr_rs_to_ts);
1372  av_freep(&pps->ctb_addr_ts_to_rs);
1373  av_freep(&pps->tile_pos_rs);
1374  av_freep(&pps->tile_id);
1375  av_freep(&pps->min_tb_addr_zs_tab);
1376  av_freep(&pps->data);
1377 }
1378 
1379 static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth,
1380  int idx_y, int idx_cb, int idx_cr, int inp_length)
1381 {
1382  unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r;
1383  int cm_res_bits;
1384 
1385  part_num_y = 1 << pps->cm_y_part_num_log2;
1386 
1387  split_octant_flag = inp_depth < pps->cm_octant_depth ? get_bits1(gb) : 0;
1388 
1389  if (split_octant_flag)
1390  for (int k = 0; k < 2; k++)
1391  for (int m = 0; m < 2; m++)
1392  for (int n = 0; n < 2; n++)
1393  colour_mapping_octants(gb, pps, inp_depth + 1,
1394  idx_y + part_num_y * k * inp_length / 2,
1395  idx_cb + m * inp_length / 2,
1396  idx_cr + n * inp_length / 2,
1397  inp_length / 2);
1398  else
1399  for (int i = 0; i < part_num_y; i++) {
1400  for (int j = 0; j < 4; j++) {
1401  coded_res_flag = get_bits1(gb);
1402  if (coded_res_flag)
1403  for (int c = 0; c < 3; c++) {
1404  res_coeff_q = get_ue_golomb_long(gb);
1405  cm_res_bits = FFMAX(0, 10 + pps->luma_bit_depth_cm_input -
1406  pps->luma_bit_depth_cm_output -
1407  pps->cm_res_quant_bits - pps->cm_delta_flc_bits);
1408  res_coeff_r = cm_res_bits ? get_bits(gb, cm_res_bits) : 0;
1409  if (res_coeff_q || res_coeff_r)
1410  skip_bits1(gb);
1411  }
1412  }
1413  }
1414 }
1415 
1417 {
1418  pps->num_cm_ref_layers = get_ue_golomb(gb) + 1;
1419  if (pps->num_cm_ref_layers > 62) {
1420  av_log(avctx, AV_LOG_ERROR,
1421  "num_cm_ref_layers_minus1 shall be in the range [0, 61].\n");
1422  return AVERROR_INVALIDDATA;
1423  }
1424  for (int i = 0; i < pps->num_cm_ref_layers; i++)
1425  pps->cm_ref_layer_id[i] = get_bits(gb, 6);
1426 
1427  pps->cm_octant_depth = get_bits(gb, 2);
1428  pps->cm_y_part_num_log2 = get_bits(gb, 2);
1429 
1430  pps->luma_bit_depth_cm_input = get_ue_golomb(gb) + 8;
1431  pps->chroma_bit_depth_cm_input = get_ue_golomb(gb) + 8;
1432  pps->luma_bit_depth_cm_output = get_ue_golomb(gb) + 8;
1433  pps->chroma_bit_depth_cm_output = get_ue_golomb(gb) + 8;
1434 
1435  pps->cm_res_quant_bits = get_bits(gb, 2);
1436  pps->cm_delta_flc_bits = get_bits(gb, 2) + 1;
1437 
1438  if (pps->cm_octant_depth == 1) {
1439  pps->cm_adapt_threshold_u_delta = get_se_golomb_long(gb);
1440  pps->cm_adapt_threshold_v_delta = get_se_golomb_long(gb);
1441  }
1442 
1443  colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth);
1444 
1445  return 0;
1446 }
1447 
1449  HEVCPPS *pps, const HEVCSPS *sps, const HEVCVPS *vps)
1450 {
1451  pps->poc_reset_info_present_flag = get_bits1(gb);
1452  pps->pps_infer_scaling_list_flag = get_bits1(gb);
1453  if (pps->pps_infer_scaling_list_flag)
1454  pps->pps_scaling_list_ref_layer_id = get_bits(gb, 6);
1455 
1456  pps->num_ref_loc_offsets = get_ue_golomb(gb);
1457  if (pps->num_ref_loc_offsets > vps->vps_max_layers - 1)
1458  return AVERROR_INVALIDDATA;
1459 
1460  for (int i = 0; i < pps->num_ref_loc_offsets; i++) {
1461  pps->ref_loc_offset_layer_id[i] = get_bits(gb, 6);
1462  pps->scaled_ref_layer_offset_present_flag[i] = get_bits1(gb);
1463  if (pps->scaled_ref_layer_offset_present_flag[i]) {
1464  pps->scaled_ref_layer_left_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1465  pps->scaled_ref_layer_top_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1466  pps->scaled_ref_layer_right_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1467  pps->scaled_ref_layer_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1468  }
1469 
1470  pps->ref_region_offset_present_flag[i] = get_bits1(gb);
1471  if (pps->ref_region_offset_present_flag[i]) {
1472  pps->ref_region_left_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1473  pps->ref_region_top_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1474  pps->ref_region_right_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1475  pps->ref_region_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
1476  }
1477 
1478  pps->resample_phase_set_present_flag[i] = get_bits1(gb);
1479  if (pps->resample_phase_set_present_flag[i]) {
1480  pps->phase_hor_luma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_31(gb);
1481  pps->phase_ver_luma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_31(gb);
1482  pps->phase_hor_chroma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb(gb) - 8;
1483  pps->phase_ver_chroma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb(gb) - 8;
1484  }
1485  }
1486 
1487  pps->colour_mapping_enabled_flag = get_bits1(gb);
1488  if (pps->colour_mapping_enabled_flag) {
1489  int ret = colour_mapping_table(gb, avctx, pps);
1490  if (ret < 0)
1491  return ret;
1492  }
1493 
1494  return 0;
1495 }
1496 
1498 {
1499  unsigned int num_val_delta_dlt, max_diff = 0;
1500  int min_diff_minus1 = -1;
1501  unsigned int len;
1502 
1503  num_val_delta_dlt = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1504  if (num_val_delta_dlt) {
1505  if (num_val_delta_dlt > 1)
1506  max_diff = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1507  if (num_val_delta_dlt > 2 && max_diff) {
1508  len = av_log2(max_diff) + 1;
1509  min_diff_minus1 = get_bits(gb, len);
1510  }
1511  if (max_diff > (min_diff_minus1 + 1))
1512  for (int k = 1; k < num_val_delta_dlt; k++) {
1513  len = av_log2(max_diff - (min_diff_minus1 + 1)) + 1;
1514  skip_bits(gb, len); // delta_val_diff_minus_min
1515  }
1516  }
1517 }
1518 
1520  HEVCPPS *pps, const HEVCSPS *sps)
1521 {
1522  unsigned int pps_depth_layers_minus1;
1523 
1524  if (get_bits1(gb)) { // dlts_present_flag
1525  pps_depth_layers_minus1 = get_bits(gb, 6);
1526  pps->pps_bit_depth_for_depth_layers_minus8 = get_bits(gb, 4);
1527  for (int i = 0; i <= pps_depth_layers_minus1; i++) {
1528  if (get_bits1(gb)) { // dlt_flag[i]
1529  if (!get_bits1(gb)) { // dlt_pred_flag[i]
1530  if (get_bits1(gb)) { // dlt_val_flags_present_flag[i]
1531  for (int j = 0; j <= ((1 << (pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++)
1532  skip_bits1(gb); // dlt_value_flag[i][j]
1533  } else
1534  delta_dlt(gb, pps);
1535  }
1536  }
1537  }
1538  }
1539 
1540  return 0;
1541 }
1542 
1544  HEVCPPS *pps, const HEVCSPS *sps)
1545 {
1546  if (pps->transform_skip_enabled_flag) {
1547  pps->log2_max_transform_skip_block_size = get_ue_golomb_31(gb) + 2;
1548  }
1549  pps->cross_component_prediction_enabled_flag = get_bits1(gb);
1550  pps->chroma_qp_offset_list_enabled_flag = get_bits1(gb);
1551  if (pps->chroma_qp_offset_list_enabled_flag) {
1552  pps->diff_cu_chroma_qp_offset_depth = get_ue_golomb_31(gb);
1553  pps->chroma_qp_offset_list_len_minus1 = get_ue_golomb_31(gb);
1554  if (pps->chroma_qp_offset_list_len_minus1 > 5) {
1555  av_log(avctx, AV_LOG_ERROR,
1556  "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
1557  return AVERROR_INVALIDDATA;
1558  }
1559  for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
1560  pps->cb_qp_offset_list[i] = get_se_golomb(gb);
1561  if (pps->cb_qp_offset_list[i]) {
1562  av_log(avctx, AV_LOG_WARNING,
1563  "cb_qp_offset_list not tested yet.\n");
1564  }
1565  pps->cr_qp_offset_list[i] = get_se_golomb(gb);
1566  if (pps->cr_qp_offset_list[i]) {
1567  av_log(avctx, AV_LOG_WARNING,
1568  "cb_qp_offset_list not tested yet.\n");
1569  }
1570  }
1571  }
1572  pps->log2_sao_offset_scale_luma = get_ue_golomb_31(gb);
1573  pps->log2_sao_offset_scale_chroma = get_ue_golomb_31(gb);
1574 
1575  if ( pps->log2_sao_offset_scale_luma > FFMAX(sps->bit_depth - 10, 0)
1576  || pps->log2_sao_offset_scale_chroma > FFMAX(sps->bit_depth_chroma - 10, 0)
1577  )
1578  return AVERROR_INVALIDDATA;
1579 
1580  return(0);
1581 }
1582 
1584  HEVCPPS *pps, const HEVCSPS *sps)
1585 {
1586  int num_comps, ret;
1587 
1588  pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb);
1589  if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb)) {
1590  pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb);
1591  pps->pps_act_y_qp_offset = get_se_golomb(gb) - 5;
1592  pps->pps_act_cb_qp_offset = get_se_golomb(gb) - 5;
1593  pps->pps_act_cr_qp_offset = get_se_golomb(gb) - 3;
1594 
1595 #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \
1596  pps->pps_act_ ## name ## _qp_offset >= 12)
1598 #undef CHECK_QP_OFFSET
1599  if (ret) {
1600  av_log(avctx, AV_LOG_ERROR,
1601  "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n");
1602  return AVERROR_INVALIDDATA;
1603  }
1604  }
1605 
1606  if (pps->pps_palette_predictor_initializers_present_flag = get_bits1(gb)) {
1607  pps->pps_num_palette_predictor_initializers = get_ue_golomb(gb);
1608  if (pps->pps_num_palette_predictor_initializers > 0) {
1609  if (pps->pps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) {
1610  av_log(avctx, AV_LOG_ERROR,
1611  "pps_num_palette_predictor_initializers out of range: %u\n",
1612  pps->pps_num_palette_predictor_initializers);
1613  return AVERROR_INVALIDDATA;
1614  }
1615  pps->monochrome_palette_flag = get_bits1(gb);
1616  pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8;
1617  if (pps->luma_bit_depth_entry != sps->bit_depth)
1618  return AVERROR_INVALIDDATA;
1619  if (!pps->monochrome_palette_flag) {
1620  pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8;
1621  if (pps->chroma_bit_depth_entry != sps->bit_depth_chroma)
1622  return AVERROR_INVALIDDATA;
1623  }
1624 
1625  num_comps = pps->monochrome_palette_flag ? 1 : 3;
1626  for (int comp = 0; comp < num_comps; comp++) {
1627  int bit_depth = !comp ? pps->luma_bit_depth_entry : pps->chroma_bit_depth_entry;
1628  for (int i = 0; i < pps->pps_num_palette_predictor_initializers; i++)
1629  pps->pps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth);
1630  }
1631  }
1632  }
1633 
1634  return 0;
1635 }
1636 
1637 static inline int setup_pps(AVCodecContext *avctx, GetBitContext *gb,
1638  HEVCPPS *pps, const HEVCSPS *sps)
1639 {
1640  int log2_diff;
1641  int pic_area_in_ctbs;
1642  int i, j, x, y, ctb_addr_rs, tile_id;
1643 
1644  // Inferred parameters
1645  pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd));
1646  pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd));
1647  pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX));
1648  if (!pps->col_bd || !pps->row_bd || !pps->col_idxX)
1649  return AVERROR(ENOMEM);
1650 
1651  if (pps->uniform_spacing_flag) {
1652  if (!pps->column_width) {
1653  pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
1654  pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
1655  }
1656  if (!pps->column_width || !pps->row_height)
1657  return AVERROR(ENOMEM);
1658 
1659  for (i = 0; i < pps->num_tile_columns; i++) {
1660  pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns -
1661  (i * sps->ctb_width) / pps->num_tile_columns;
1662  }
1663 
1664  for (i = 0; i < pps->num_tile_rows; i++) {
1665  pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows -
1666  (i * sps->ctb_height) / pps->num_tile_rows;
1667  }
1668  }
1669 
1670  pps->col_bd[0] = 0;
1671  for (i = 0; i < pps->num_tile_columns; i++)
1672  pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i];
1673 
1674  pps->row_bd[0] = 0;
1675  for (i = 0; i < pps->num_tile_rows; i++)
1676  pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i];
1677 
1678  for (i = 0, j = 0; i < sps->ctb_width; i++) {
1679  if (i > pps->col_bd[j])
1680  j++;
1681  pps->col_idxX[i] = j;
1682  }
1683 
1684  /**
1685  * 6.5
1686  */
1687  pic_area_in_ctbs = sps->ctb_width * sps->ctb_height;
1688 
1689  pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts));
1690  pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs));
1691  pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id));
1692  pps->min_tb_addr_zs_tab = av_malloc_array((sps->tb_mask+2) * (sps->tb_mask+2), sizeof(*pps->min_tb_addr_zs_tab));
1693  if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs ||
1694  !pps->tile_id || !pps->min_tb_addr_zs_tab) {
1695  return AVERROR(ENOMEM);
1696  }
1697 
1698  for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
1699  int tb_x = ctb_addr_rs % sps->ctb_width;
1700  int tb_y = ctb_addr_rs / sps->ctb_width;
1701  int tile_x = 0;
1702  int tile_y = 0;
1703  int val = 0;
1704 
1705  for (i = 0; i < pps->num_tile_columns; i++) {
1706  if (tb_x < pps->col_bd[i + 1]) {
1707  tile_x = i;
1708  break;
1709  }
1710  }
1711 
1712  for (i = 0; i < pps->num_tile_rows; i++) {
1713  if (tb_y < pps->row_bd[i + 1]) {
1714  tile_y = i;
1715  break;
1716  }
1717  }
1718 
1719  for (i = 0; i < tile_x; i++)
1720  val += pps->row_height[tile_y] * pps->column_width[i];
1721  for (i = 0; i < tile_y; i++)
1722  val += sps->ctb_width * pps->row_height[i];
1723 
1724  val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] +
1725  tb_x - pps->col_bd[tile_x];
1726 
1727  pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val;
1728  pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs;
1729  }
1730 
1731  for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++)
1732  for (i = 0; i < pps->num_tile_columns; i++, tile_id++)
1733  for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++)
1734  for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++)
1735  pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id;
1736 
1737  pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs));
1738  if (!pps->tile_pos_rs)
1739  return AVERROR(ENOMEM);
1740 
1741  for (j = 0; j < pps->num_tile_rows; j++)
1742  for (i = 0; i < pps->num_tile_columns; i++)
1743  pps->tile_pos_rs[j * pps->num_tile_columns + i] =
1744  pps->row_bd[j] * sps->ctb_width + pps->col_bd[i];
1745 
1746  log2_diff = sps->log2_ctb_size - sps->log2_min_tb_size;
1747  pps->min_tb_addr_zs = &pps->min_tb_addr_zs_tab[1*(sps->tb_mask+2)+1];
1748  for (y = 0; y < sps->tb_mask+2; y++) {
1749  pps->min_tb_addr_zs_tab[y*(sps->tb_mask+2)] = -1;
1750  pps->min_tb_addr_zs_tab[y] = -1;
1751  }
1752  for (y = 0; y < sps->tb_mask+1; y++) {
1753  for (x = 0; x < sps->tb_mask+1; x++) {
1754  int tb_x = x >> log2_diff;
1755  int tb_y = y >> log2_diff;
1756  int rs = sps->ctb_width * tb_y + tb_x;
1757  int val = pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2);
1758  for (i = 0; i < log2_diff; i++) {
1759  int m = 1 << i;
1760  val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
1761  }
1762  pps->min_tb_addr_zs[y * (sps->tb_mask+2) + x] = val;
1763  }
1764  }
1765 
1766  return 0;
1767 }
1768 
1770  HEVCParamSets *ps)
1771 {
1772  const HEVCSPS *sps = NULL;
1773  const HEVCVPS *vps = NULL;
1774  int i, ret = 0;
1775  ptrdiff_t nal_size = gb->buffer_end - gb->buffer;
1776  unsigned int pps_id = get_ue_golomb_long(gb);
1777  unsigned log2_parallel_merge_level_minus2;
1778  HEVCPPS *pps;
1779 
1780  av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n");
1781 
1782  if (pps_id >= HEVC_MAX_PPS_COUNT) {
1783  av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
1784  return AVERROR_INVALIDDATA;
1785  }
1786 
1787  if (ps->pps_list[pps_id]) {
1788  const HEVCPPS *pps1 = ps->pps_list[pps_id];
1789  if (pps1->data_size == nal_size &&
1790  !memcmp(pps1->data, gb->buffer, pps1->data_size))
1791  return 0;
1792  }
1793 
1794  pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free);
1795  if (!pps)
1796  return AVERROR(ENOMEM);
1797 
1798  pps->data_size = nal_size;
1799  pps->data = av_memdup(gb->buffer, nal_size);
1800  if (!pps->data) {
1802  goto err;
1803  }
1804 
1805  // Default values
1806  pps->loop_filter_across_tiles_enabled_flag = 1;
1807  pps->num_tile_columns = 1;
1808  pps->num_tile_rows = 1;
1809  pps->uniform_spacing_flag = 1;
1810  pps->disable_dbf = 0;
1811  pps->beta_offset = 0;
1812  pps->tc_offset = 0;
1813  pps->log2_max_transform_skip_block_size = 2;
1814 
1815  // Coded parameters
1816  pps->pps_id = pps_id;
1817  pps->sps_id = get_ue_golomb_long(gb);
1818  if (pps->sps_id >= HEVC_MAX_SPS_COUNT) {
1819  av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id);
1821  goto err;
1822  }
1823  if (!ps->sps_list[pps->sps_id]) {
1824  av_log(avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id);
1826  goto err;
1827  }
1828  sps = ps->sps_list[pps->sps_id];
1829  vps = ps->vps_list[sps->vps_id];
1830 
1831  pps->sps = ff_refstruct_ref_c(sps);
1832 
1833  pps->dependent_slice_segments_enabled_flag = get_bits1(gb);
1834  pps->output_flag_present_flag = get_bits1(gb);
1835  pps->num_extra_slice_header_bits = get_bits(gb, 3);
1836 
1837  pps->sign_data_hiding_flag = get_bits1(gb);
1838 
1839  pps->cabac_init_present_flag = get_bits1(gb);
1840 
1841  pps->num_ref_idx_l0_default_active = get_ue_golomb_31(gb) + 1;
1842  pps->num_ref_idx_l1_default_active = get_ue_golomb_31(gb) + 1;
1843  if (pps->num_ref_idx_l0_default_active >= HEVC_MAX_REFS ||
1844  pps->num_ref_idx_l1_default_active >= HEVC_MAX_REFS) {
1845  av_log(avctx, AV_LOG_ERROR, "Too many default refs in PPS: %d/%d.\n",
1846  pps->num_ref_idx_l0_default_active, pps->num_ref_idx_l1_default_active);
1847  goto err;
1848  }
1849 
1850  pps->pic_init_qp_minus26 = get_se_golomb(gb);
1851 
1852  pps->constrained_intra_pred_flag = get_bits1(gb);
1853  pps->transform_skip_enabled_flag = get_bits1(gb);
1854 
1855  pps->cu_qp_delta_enabled_flag = get_bits1(gb);
1856  pps->diff_cu_qp_delta_depth = 0;
1857  if (pps->cu_qp_delta_enabled_flag)
1858  pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb);
1859 
1860  if (pps->diff_cu_qp_delta_depth < 0 ||
1861  pps->diff_cu_qp_delta_depth > sps->log2_diff_max_min_coding_block_size) {
1862  av_log(avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n",
1863  pps->diff_cu_qp_delta_depth);
1865  goto err;
1866  }
1867 
1868  pps->cb_qp_offset = get_se_golomb(gb);
1869  if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) {
1870  av_log(avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n",
1871  pps->cb_qp_offset);
1873  goto err;
1874  }
1875  pps->cr_qp_offset = get_se_golomb(gb);
1876  if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) {
1877  av_log(avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n",
1878  pps->cr_qp_offset);
1880  goto err;
1881  }
1882  pps->pic_slice_level_chroma_qp_offsets_present_flag = get_bits1(gb);
1883 
1884  pps->weighted_pred_flag = get_bits1(gb);
1885  pps->weighted_bipred_flag = get_bits1(gb);
1886 
1887  pps->transquant_bypass_enable_flag = get_bits1(gb);
1888  pps->tiles_enabled_flag = get_bits1(gb);
1889  pps->entropy_coding_sync_enabled_flag = get_bits1(gb);
1890 
1891  if (pps->tiles_enabled_flag) {
1892  int num_tile_columns_minus1 = get_ue_golomb(gb);
1893  int num_tile_rows_minus1 = get_ue_golomb(gb);
1894 
1895  if (num_tile_columns_minus1 < 0 ||
1896  num_tile_columns_minus1 >= sps->ctb_width) {
1897  av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n",
1898  num_tile_columns_minus1);
1899  ret = num_tile_columns_minus1 < 0 ? num_tile_columns_minus1 : AVERROR_INVALIDDATA;
1900  goto err;
1901  }
1902  if (num_tile_rows_minus1 < 0 ||
1903  num_tile_rows_minus1 >= sps->ctb_height) {
1904  av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n",
1905  num_tile_rows_minus1);
1906  ret = num_tile_rows_minus1 < 0 ? num_tile_rows_minus1 : AVERROR_INVALIDDATA;
1907  goto err;
1908  }
1909  pps->num_tile_columns = num_tile_columns_minus1 + 1;
1910  pps->num_tile_rows = num_tile_rows_minus1 + 1;
1911 
1912  pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
1913  pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
1914  if (!pps->column_width || !pps->row_height) {
1915  ret = AVERROR(ENOMEM);
1916  goto err;
1917  }
1918 
1919  pps->uniform_spacing_flag = get_bits1(gb);
1920  if (!pps->uniform_spacing_flag) {
1921  uint64_t sum = 0;
1922  for (i = 0; i < pps->num_tile_columns - 1; i++) {
1923  pps->column_width[i] = get_ue_golomb_long(gb) + 1;
1924  sum += pps->column_width[i];
1925  }
1926  if (sum >= sps->ctb_width) {
1927  av_log(avctx, AV_LOG_ERROR, "Invalid tile widths.\n");
1929  goto err;
1930  }
1931  pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum;
1932 
1933  sum = 0;
1934  for (i = 0; i < pps->num_tile_rows - 1; i++) {
1935  pps->row_height[i] = get_ue_golomb_long(gb) + 1;
1936  sum += pps->row_height[i];
1937  }
1938  if (sum >= sps->ctb_height) {
1939  av_log(avctx, AV_LOG_ERROR, "Invalid tile heights.\n");
1941  goto err;
1942  }
1943  pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum;
1944  }
1945  pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb);
1946  }
1947 
1948  pps->seq_loop_filter_across_slices_enabled_flag = get_bits1(gb);
1949 
1950  pps->deblocking_filter_control_present_flag = get_bits1(gb);
1951  if (pps->deblocking_filter_control_present_flag) {
1952  pps->deblocking_filter_override_enabled_flag = get_bits1(gb);
1953  pps->disable_dbf = get_bits1(gb);
1954  if (!pps->disable_dbf) {
1955  int beta_offset_div2 = get_se_golomb(gb);
1956  int tc_offset_div2 = get_se_golomb(gb) ;
1957  if (beta_offset_div2 < -6 || beta_offset_div2 > 6) {
1958  av_log(avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n",
1959  beta_offset_div2);
1961  goto err;
1962  }
1963  if (tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1964  av_log(avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n",
1965  tc_offset_div2);
1967  goto err;
1968  }
1969  pps->beta_offset = 2 * beta_offset_div2;
1970  pps->tc_offset = 2 * tc_offset_div2;
1971  }
1972  }
1973 
1974  pps->scaling_list_data_present_flag = get_bits1(gb);
1975  if (pps->scaling_list_data_present_flag) {
1976  set_default_scaling_list_data(&pps->scaling_list);
1977  ret = scaling_list_data(gb, avctx, &pps->scaling_list, sps);
1978  if (ret < 0)
1979  goto err;
1980  }
1981  pps->lists_modification_present_flag = get_bits1(gb);
1982  log2_parallel_merge_level_minus2 = get_ue_golomb_long(gb);
1983  if (log2_parallel_merge_level_minus2 > sps->log2_ctb_size) {
1984  av_log(avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n",
1985  log2_parallel_merge_level_minus2);
1987  goto err;
1988  }
1989  pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2;
1990 
1991  pps->slice_header_extension_present_flag = get_bits1(gb);
1992 
1993  pps->pps_extension_present_flag = get_bits1(gb);
1994  if (pps->pps_extension_present_flag) {
1995  pps->pps_range_extensions_flag = get_bits1(gb);
1996  pps->pps_multilayer_extension_flag = get_bits1(gb);
1997  pps->pps_3d_extension_flag = get_bits1(gb);
1998  pps->pps_scc_extension_flag = get_bits1(gb);
1999  skip_bits(gb, 4); // pps_extension_4bits
2000 
2001  if (sps->ptl.general_ptl.profile_idc >= AV_PROFILE_HEVC_REXT && pps->pps_range_extensions_flag) {
2002  if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0)
2003  goto err;
2004  }
2005 
2006  if (pps->pps_multilayer_extension_flag) {
2007  if ((ret = pps_multilayer_extension(gb, avctx, pps, sps, vps)) < 0)
2008  goto err;
2009  }
2010 
2011  if (pps->pps_3d_extension_flag) {
2012  if ((ret = pps_3d_extension(gb, avctx, pps, sps)) < 0)
2013  goto err;
2014  }
2015 
2016  if (pps->pps_scc_extension_flag) {
2017  if ((ret = pps_scc_extension(gb, avctx, pps, sps)) < 0)
2018  goto err;
2019  }
2020  }
2021 
2022  ret = setup_pps(avctx, gb, pps, sps);
2023  if (ret < 0)
2024  goto err;
2025 
2026  if (get_bits_left(gb) < 0) {
2027  av_log(avctx, AV_LOG_WARNING,
2028  "Overread PPS by %d bits\n", -get_bits_left(gb));
2029  }
2030 
2032  ps->pps_list[pps_id] = pps;
2033 
2034  return 0;
2035 
2036 err:
2038  return ret;
2039 }
2040 
2042 {
2043  int i;
2044 
2045  for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++)
2046  ff_refstruct_unref(&ps->vps_list[i]);
2047  for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++)
2048  ff_refstruct_unref(&ps->sps_list[i]);
2049  for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
2050  ff_refstruct_unref(&ps->pps_list[i]);
2051 
2052  ps->sps = NULL;
2053  ps->vps = NULL;
2054 }
2055 
2056 int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type)
2057 {
2058  int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
2059  int prev_poc_lsb = pocTid0 % max_poc_lsb;
2060  int prev_poc_msb = pocTid0 - prev_poc_lsb;
2061  int poc_msb;
2062 
2063  if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
2064  poc_msb = prev_poc_msb + max_poc_lsb;
2065  else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
2066  poc_msb = prev_poc_msb - max_poc_lsb;
2067  else
2068  poc_msb = prev_poc_msb;
2069 
2070  // For BLA picture types, POCmsb is set to 0.
2071  if (nal_unit_type == HEVC_NAL_BLA_W_LP ||
2072  nal_unit_type == HEVC_NAL_BLA_W_RADL ||
2073  nal_unit_type == HEVC_NAL_BLA_N_LP)
2074  poc_msb = 0;
2075 
2076  return poc_msb + poc_lsb;
2077 }
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
decode_vui
static void decode_vui(GetBitContext *gb, AVCodecContext *avctx, int apply_defdispwin, HEVCSPS *sps)
Definition: ps.c:589
HEVCSPS::data_size
int data_size
Definition: ps.h:304
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
HEVCPPS::data_size
int data_size
Definition: ps.h:441
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
VUI::vui_time_scale
uint32_t vui_time_scale
Definition: ps.h:109
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
HEVC_MAX_SUB_LAYERS
@ HEVC_MAX_SUB_LAYERS
Definition: hevc.h:105
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:246
HEVCWindow::bottom_offset
unsigned int bottom_offset
Definition: ps.h:93
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:81
HEVCParamSets::pps_list
const HEVCPPS * pps_list[HEVC_MAX_PPS_COUNT]
RefStruct references.
Definition: ps.h:449
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
ShortTermRPS::num_negative_pics
uint8_t num_negative_pics
Definition: ps.h:78
ShortTermRPS::rps_idx_num_delta_pocs
uint8_t rps_idx_num_delta_pocs
Definition: ps.h:80
get_se_golomb_long
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:294
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2965
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1420
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
ff_refstruct_alloc_ext
static void * ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
A wrapper around ff_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:94
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:95
H2645VUI::matrix_coeffs
enum AVColorSpace matrix_coeffs
Definition: h2645_vui.h:41
HEVCSublayerHdrParams::cbr_flag
uint32_t cbr_flag
Definition: ps.h:40
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:159
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
get_ue_golomb
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:53
HEVC_NAL_BLA_N_LP
@ HEVC_NAL_BLA_N_LP
Definition: hevc.h:47
HEVCHdrParams::dpb_output_delay_du_length_minus1
uint8_t dpb_output_delay_du_length_minus1
Definition: ps.h:59
HEVCHdrFlagParams::low_delay_hrd_flag
uint8_t low_delay_hrd_flag
Definition: ps.h:47
VUI::tiles_fixed_structure_flag
int tiles_fixed_structure_flag
Definition: ps.h:115
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
VUI::vui_num_ticks_poc_diff_one_minus1
int vui_num_ticks_poc_diff_one_minus1
Definition: ps.h:111
ScalingList::sl
uint8_t sl[4][6][64]
Definition: ps.h:186
VUI::field_seq_flag
int field_seq_flag
Definition: ps.h:101
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:610
VUI::bitstream_restriction_flag
int bitstream_restriction_flag
Definition: ps.h:114
FFRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
HEVCHdrParams::elemental_duration_in_tc_minus1
uint16_t elemental_duration_in_tc_minus1[HEVC_MAX_SUB_LAYERS]
Definition: ps.h:67
HEVC_MAX_DPB_SIZE
@ HEVC_MAX_DPB_SIZE
Definition: hevc.h:117
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
HEVC_MAX_LONG_TERM_REF_PICS
@ HEVC_MAX_LONG_TERM_REF_PICS
Definition: hevc.h:124
HEVCHdrParams
Definition: ps.h:50
H2645VUI::video_full_range_flag
int video_full_range_flag
Definition: h2645_vui.h:37
ff_hevc_decode_nal_sps
int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps, int apply_defdispwin)
Definition: ps.c:1308
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:458
AV_CODEC_FLAG2_IGNORE_CROP
#define AV_CODEC_FLAG2_IGNORE_CROP
Discard cropping information from SPS.
Definition: avcodec.h:375
HEVCHdrParams::vcl_hrd_parameters_present_flag
uint8_t vcl_hrd_parameters_present_flag
Definition: ps.h:53
HEVCSublayerHdrParams::bit_rate_value_minus1
uint32_t bit_rate_value_minus1[HEVC_MAX_CPB_CNT]
Definition: ps.h:36
H2645VUI::video_signal_type_present_flag
int video_signal_type_present_flag
Definition: h2645_vui.h:35
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
golomb.h
exp golomb vlc stuff
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
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:2056
hevc_pps_free
static void hevc_pps_free(FFRefStructOpaque unused, void *obj)
Definition: ps.c:1360
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:494
HEVCWindow::left_offset
unsigned int left_offset
Definition: ps.h:90
ShortTermRPS::use_delta
unsigned use_delta
Definition: ps.h:86
GetBitContext
Definition: get_bits.h:108
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:476
H265RawProfileTierLevel::sub_layer_level_present_flag
uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:64
remove_sps
static void remove_sps(HEVCParamSets *s, int id)
Definition: ps.c:64
HEVCHdrParams::sub_pic_hrd_params_present_flag
uint8_t sub_pic_hrd_params_present_flag
Definition: ps.h:54
HEVCSublayerHdrParams::bit_rate_du_value_minus1
uint32_t bit_rate_du_value_minus1[HEVC_MAX_CPB_CNT]
Definition: ps.h:39
ff_hevc_diag_scan8x8_y
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: data.c:58
val
static double val(void *priv, double ch)
Definition: aeval.c:78
remove_vps
static void remove_vps(HEVCParamSets *s, int id)
Definition: ps.c:81
HEVC_MAX_PPS_COUNT
@ HEVC_MAX_PPS_COUNT
Definition: hevc.h:114
parse_ptl
static int parse_ptl(GetBitContext *gb, AVCodecContext *avctx, PTL *ptl, int max_num_sub_layers)
Definition: ps.c:320
HEVCSublayerHdrParams::cpb_size_du_value_minus1
uint32_t cpb_size_du_value_minus1[HEVC_MAX_CPB_CNT]
Definition: ps.h:38
scaling_list_data
static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, ScalingList *sl, const HEVCSPS *sps)
Definition: ps.c:746
HEVCParamSets::sps_list
const HEVCSPS * sps_list[HEVC_MAX_SPS_COUNT]
RefStruct references.
Definition: ps.h:448
default_scaling_list_intra
static const uint8_t default_scaling_list_intra[]
Definition: ps.c:34
HEVCSPS::data
uint8_t * data
Definition: ps.h:303
refstruct.h
VUI::restricted_ref_pic_lists_flag
int restricted_ref_pic_lists_flag
Definition: ps.h:117
HEVC_MAX_SHORT_TERM_REF_PIC_SETS
@ HEVC_MAX_SHORT_TERM_REF_PIC_SETS
Definition: hevc.h:122
HEVCPPS::row_bd
unsigned int * row_bd
RowBd.
Definition: ps.h:430
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
H265RawProfileTierLevel::sub_layer_profile_present_flag
uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:63
HEVCHdrParams::nal_hrd_parameters_present_flag
uint8_t nal_hrd_parameters_present_flag
Definition: ps.h:52
HEVCPPS::col_bd
unsigned int * col_bd
ColBd.
Definition: ps.h:429
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
HEVCHdrParams::cpb_size_scale
uint8_t cpb_size_scale
Definition: ps.h:61
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
hevc_sps_free
static void hevc_sps_free(FFRefStructOpaque opaque, void *obj)
Definition: ps.c:1293
ptl
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
hevc_vps_free
static void hevc_vps_free(FFRefStructOpaque opaque, void *obj)
Definition: ps.c:446
PTLCommon
Definition: ps.h:125
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PROFILE_HEVC_SCC
#define AV_PROFILE_HEVC_SCC
Definition: defs.h:163
HEVCHdrParams::vcl_params
HEVCSublayerHdrParams vcl_params[HEVC_MAX_SUB_LAYERS]
Definition: ps.h:70
hevc_sub_height_c
static const uint8_t hevc_sub_height_c[]
Definition: ps.c:60
compare_sps
static int compare_sps(const HEVCSPS *sps1, const HEVCSPS *sps2)
Definition: ps.c:1302
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:475
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
VUI::motion_vectors_over_pic_boundaries_flag
int motion_vectors_over_pic_boundaries_flag
Definition: ps.h:116
map_pixel_format
static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps)
Definition: ps.c:823
HEVCWindow::top_offset
unsigned int top_offset
Definition: ps.h:92
HEVCPPS::data
uint8_t * data
Definition: ps.h:440
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
ScalingList
Definition: ps.h:183
HEVCHdrParams::tick_divisor_minus2
uint8_t tick_divisor_minus2
Definition: ps.h:57
ShortTermRPS::num_delta_pocs
uint8_t num_delta_pocs
Definition: ps.h:79
get_se_golomb
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:239
ff_hevc_decode_nal_vps
int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: ps.c:454
setup_pps
static int setup_pps(AVCodecContext *avctx, GetBitContext *gb, HEVCPPS *pps, const HEVCSPS *sps)
Definition: ps.c:1637
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
ff_hevc_diag_scan4x4_y
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: data.c:32
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:109
set_default_scaling_list_data
static void set_default_scaling_list_data(ScalingList *sl)
Definition: ps.c:716
colour_mapping_table
static int colour_mapping_table(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps)
Definition: ps.c:1416
NULL
#define NULL
Definition: coverity.c:32
H2645VUI::colour_description_present_flag
int colour_description_present_flag
Definition: h2645_vui.h:38
pps_3d_extension
static int pps_3d_extension(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps, const HEVCSPS *sps)
Definition: ps.c:1519
ScalingList::sl_dc
uint8_t sl_dc[2][6]
Definition: ps.h:187
VUI::frame_field_info_present_flag
int frame_field_info_present_flag
Definition: ps.h:102
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
VUI::vui_timing_info_present_flag
int vui_timing_info_present_flag
Definition: ps.h:107
HEVCPPS::tile_id
int * tile_id
TileId.
Definition: ps.h:435
AV_PROFILE_HEVC_MAIN_STILL_PICTURE
#define AV_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: defs.h:161
ff_hevc_decode_nal_pps
int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: ps.c:1769
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
HEVCSublayerHdrParams
Definition: ps.h:35
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
HEVCHdrFlagParams::fixed_pic_rate_general_flag
uint8_t fixed_pic_rate_general_flag
Definition: ps.h:45
VUI::log2_max_mv_length_horizontal
int log2_max_mv_length_horizontal
Definition: ps.h:121
HEVCParamSets::vps
const HEVCVPS * vps
Definition: ps.h:452
PTL
Definition: ps.h:148
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
data.h
decode_sublayer_hrd
static void decode_sublayer_hrd(GetBitContext *gb, unsigned int nb_cpb, HEVCSublayerHdrParams *par, int subpic_params_present)
Definition: ps.c:360
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
VUI::max_bytes_per_pic_denom
int max_bytes_per_pic_denom
Definition: ps.h:119
pps_range_extensions
static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps, const HEVCSPS *sps)
Definition: ps.c:1543
HEVC_MAX_LOG2_CTB_SIZE
@ HEVC_MAX_LOG2_CTB_SIZE
Definition: hevc.h:128
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:160
AV_PROFILE_HEVC_REXT
#define AV_PROFILE_HEVC_REXT
Definition: defs.h:162
hevc_sub_width_c
static const uint8_t hevc_sub_width_c[]
Definition: ps.c:56
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
HEVCSublayerHdrParams::cpb_size_value_minus1
uint32_t cpb_size_value_minus1[HEVC_MAX_CPB_CNT]
Definition: ps.h:37
HEVCWindow
Definition: ps.h:89
ShortTermRPS::used
uint32_t used
Definition: ps.h:75
HEVCHdrParams::dpb_output_delay_length_minus1
uint8_t dpb_output_delay_length_minus1
Definition: ps.h:65
HEVCPPS::pps_id
unsigned int pps_id
Definition: ps.h:310
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:509
CHECK_QP_OFFSET
#define CHECK_QP_OFFSET(name)
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
VUI::common
H2645VUI common
Definition: ps.h:97
VUI::def_disp_win
HEVCWindow def_disp_win
Definition: ps.h:105
VUI::vui_poc_proportional_to_timing_flag
int vui_poc_proportional_to_timing_flag
Definition: ps.h:110
VUI
Definition: ps.h:96
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
VUI::vui_num_units_in_tick
uint32_t vui_num_units_in_tick
Definition: ps.h:108
ps.h
VUI::max_bits_per_min_cu_denom
int max_bits_per_min_cu_denom
Definition: ps.h:120
HEVC_MAX_REFS
@ HEVC_MAX_REFS
Definition: hevc.h:119
VUI::log2_max_mv_length_vertical
int log2_max_mv_length_vertical
Definition: ps.h:122
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:413
av_zero_extend
#define av_zero_extend
Definition: common.h:151
HEVCHdrParams::bit_rate_scale
uint8_t bit_rate_scale
Definition: ps.h:60
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
ff_hevc_ps_uninit
void ff_hevc_ps_uninit(HEVCParamSets *ps)
Definition: ps.c:2041
VUI::default_display_window_flag
int default_display_window_flag
Definition: ps.h:104
HEVCHdrParams::nal_params
HEVCSublayerHdrParams nal_params[HEVC_MAX_SUB_LAYERS]
Definition: ps.h:69
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
HEVCParamSets::sps
const HEVCSPS * sps
Definition: ps.h:453
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:495
VUI::neutra_chroma_indication_flag
int neutra_chroma_indication_flag
Definition: ps.h:99
delta
float delta
Definition: vorbis_enc_data.h:430
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_hevc_diag_scan4x4_x
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: data.c:25
len
int len
Definition: vorbis_enc_data.h:426
ShortTermRPS::abs_delta_rps
uint16_t abs_delta_rps
Definition: ps.h:82
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:477
GetBitContext::buffer_end
const uint8_t * buffer_end
Definition: get_bits.h:109
pps_scc_extension
static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps, const HEVCSPS *sps)
Definition: ps.c:1583
ret
ret
Definition: filter_design.txt:187
HEVCHdrFlagParams::fixed_pic_rate_within_cvs_flag
uint8_t fixed_pic_rate_within_cvs_flag
Definition: ps.h:46
HEVCVPS::data
uint8_t * data
Definition: ps.h:179
h2645_vui.h
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
ff_h2645_decode_common_vui_params
void ff_h2645_decode_common_vui_params(GetBitContext *gb, H2645VUI *vui, void *logctx)
Definition: h2645_vui.c:37
pos
unsigned int pos
Definition: spdifenc.c:414
ShortTermRPS::delta_idx
uint8_t delta_idx
Definition: ps.h:77
HEVCHdrParams::initial_cpb_removal_delay_length_minus1
uint8_t initial_cpb_removal_delay_length_minus1
Definition: ps.h:63
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
U
#define U(x)
Definition: vpx_arith.h:37
HEVC_MAX_PALETTE_PREDICTOR_SIZE
@ HEVC_MAX_PALETTE_PREDICTOR_SIZE
Definition: hevc.h:159
AVCodecContext
main external API structure.
Definition: avcodec.h:445
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
delta_dlt
static void delta_dlt(GetBitContext *gb, HEVCPPS *pps)
Definition: ps.c:1497
decode_profile_tier_level
static int decode_profile_tier_level(GetBitContext *gb, AVCodecContext *avctx, PTLCommon *ptl)
Definition: ps.c:244
decode_hrd
static int decode_hrd(GetBitContext *gb, int common_inf_present, HEVCHdrParams *hdr, int max_sublayers)
Definition: ps.c:378
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
HEVCWindow::right_offset
unsigned int right_offset
Definition: ps.h:91
ShortTermRPS
Definition: ps.h:73
VUI::vui_hrd_parameters_present_flag
int vui_hrd_parameters_present_flag
Definition: ps.h:112
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
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1396
colour_mapping_octants
static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth, int idx_y, int idx_cb, int idx_cr, int inp_length)
Definition: ps.c:1379
VUI::min_spatial_segmentation_idc
int min_spatial_segmentation_idc
Definition: ps.h:118
ff_hevc_diag_scan8x8_x
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: data.c:39
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
desc
const char * desc
Definition: libsvtav1.c:79
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
HEVCVPS
Definition: ps.h:156
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
ff_hevc_parse_sps
int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, int apply_defdispwin, const HEVCVPS *const *vps_list, AVCodecContext *avctx)
Parse the SPS from the bitstream into the provided HEVCSPS struct.
Definition: ps.c:872
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
HEVCSPS
Definition: ps.h:190
ShortTermRPS::rps_predict
unsigned rps_predict
Definition: ps.h:85
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
HEVCPPS
Definition: ps.h:309
HEVCPPS::sps_id
unsigned int sps_id
seq_parameter_set_id
Definition: ps.h:311
HEVCHdrParams::du_cpb_removal_delay_increment_length_minus1
uint8_t du_cpb_removal_delay_increment_length_minus1
Definition: ps.h:58
HEVCHdrParams::cpb_cnt_minus1
uint8_t cpb_cnt_minus1[HEVC_MAX_SUB_LAYERS]
Definition: ps.h:66
timing_info
static int FUNC() timing_info(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTimingInfo *current)
Definition: cbs_av1_syntax_template.c:158
HEVCHdrParams::au_cpb_removal_delay_length_minus1
uint8_t au_cpb_removal_delay_length_minus1
Definition: ps.h:64
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:247
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
HEVCParamSets::vps_list
const HEVCVPS * vps_list[HEVC_MAX_VPS_COUNT]
RefStruct references.
Definition: ps.h:447
int32_t
int32_t
Definition: audioconvert.c:56
HEVCHdrParams::sub_pic_cpb_params_in_pic_timing_sei_flag
uint8_t sub_pic_cpb_params_in_pic_timing_sei_flag
Definition: ps.h:55
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HEVCVPS::data_size
int data_size
Definition: ps.h:180
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ShortTermRPS::delta_poc
int32_t delta_poc[32]
Definition: ps.h:74
pps_multilayer_extension
static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps, const HEVCSPS *sps, const HEVCVPS *vps)
Definition: ps.c:1448
HEVCHdrParams::cpb_size_du_scale
uint8_t cpb_size_du_scale
Definition: ps.h:62
check_profile_idc
#define check_profile_idc(idc)
ShortTermRPS::delta_rps_sign
unsigned delta_rps_sign
Definition: ps.h:83
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460
HEVC_MAX_SPS_COUNT
@ HEVC_MAX_SPS_COUNT
Definition: hevc.h:112
FF_DEBUG_BITSTREAM
#define FF_DEBUG_BITSTREAM
Definition: avcodec.h:1399
HEVCHdrParams::flags
HEVCHdrFlagParams flags
Definition: ps.h:51
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
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
HEVC_NAL_BLA_W_RADL
@ HEVC_NAL_BLA_W_RADL
Definition: hevc.h:46
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2885
default_scaling_list_inter
static const uint8_t default_scaling_list_inter[]
Definition: ps.c:45
HEVC_NAL_BLA_W_LP
@ HEVC_NAL_BLA_W_LP
Definition: hevc.h:45
HEVCParamSets
Definition: ps.h:446