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