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