FFmpeg
hevc_ps.c
Go to the documentation of this file.
1 /*
2  * HEVC Parameter Set decoding
3  *
4  * Copyright (C) 2012 - 2103 Guillaume Martres
5  * Copyright (C) 2012 - 2103 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 "hevc_data.h"
29 #include "hevc_ps.h"
30 
32  16, 16, 16, 16, 17, 18, 21, 24,
33  16, 16, 16, 16, 17, 19, 22, 25,
34  16, 16, 17, 18, 20, 22, 25, 29,
35  16, 16, 18, 21, 24, 27, 31, 36,
36  17, 17, 20, 24, 30, 35, 41, 47,
37  18, 19, 22, 27, 35, 44, 54, 65,
38  21, 22, 25, 31, 41, 54, 70, 88,
39  24, 25, 29, 36, 47, 65, 88, 115
40 };
41 
43  16, 16, 16, 16, 17, 18, 20, 24,
44  16, 16, 16, 17, 18, 20, 24, 25,
45  16, 16, 17, 18, 20, 24, 25, 28,
46  16, 17, 18, 20, 24, 25, 28, 33,
47  17, 18, 20, 24, 25, 28, 33, 41,
48  18, 20, 24, 25, 28, 33, 41, 54,
49  20, 24, 25, 28, 33, 41, 54, 71,
50  24, 25, 28, 33, 41, 54, 71, 91
51 };
52 
53 static const AVRational vui_sar[] = {
54  { 0, 1 },
55  { 1, 1 },
56  { 12, 11 },
57  { 10, 11 },
58  { 16, 11 },
59  { 40, 33 },
60  { 24, 11 },
61  { 20, 11 },
62  { 32, 11 },
63  { 80, 33 },
64  { 18, 11 },
65  { 15, 11 },
66  { 64, 33 },
67  { 160, 99 },
68  { 4, 3 },
69  { 3, 2 },
70  { 2, 1 },
71 };
72 
73 static const uint8_t hevc_sub_width_c[] = {
74  1, 2, 2, 1
75 };
76 
77 static const uint8_t hevc_sub_height_c[] = {
78  1, 2, 1, 1
79 };
80 
81 static void remove_pps(HEVCParamSets *s, int id)
82 {
83  if (s->pps_list[id] && s->pps == (const HEVCPPS*)s->pps_list[id]->data)
84  s->pps = NULL;
85  av_buffer_unref(&s->pps_list[id]);
86 }
87 
88 static void remove_sps(HEVCParamSets *s, int id)
89 {
90  int i;
91  if (s->sps_list[id]) {
92  if (s->sps == (const HEVCSPS*)s->sps_list[id]->data)
93  s->sps = NULL;
94 
95  /* drop all PPS that depend on this SPS */
96  for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
97  if (s->pps_list[i] && ((HEVCPPS*)s->pps_list[i]->data)->sps_id == id)
98  remove_pps(s, i);
99 
100  av_assert0(!(s->sps_list[id] && s->sps == (HEVCSPS*)s->sps_list[id]->data));
101  }
102  av_buffer_unref(&s->sps_list[id]);
103 }
104 
105 static void remove_vps(HEVCParamSets *s, int id)
106 {
107  int i;
108  if (s->vps_list[id]) {
109  if (s->vps == (const HEVCVPS*)s->vps_list[id]->data)
110  s->vps = NULL;
111 
112  for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)
113  if (s->sps_list[i] && ((HEVCSPS*)s->sps_list[i]->data)->vps_id == id)
114  remove_sps(s, i);
115  }
116  av_buffer_unref(&s->vps_list[id]);
117 }
118 
120  ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
121 {
122  uint8_t rps_predict = 0;
123  int delta_poc;
124  int k0 = 0;
125  int k1 = 0;
126  int k = 0;
127  int i;
128 
129  if (rps != sps->st_rps && sps->nb_st_rps)
130  rps_predict = get_bits1(gb);
131 
132  if (rps_predict) {
133  const ShortTermRPS *rps_ridx;
134  int delta_rps;
135  unsigned abs_delta_rps;
136  uint8_t use_delta_flag = 0;
137  uint8_t delta_rps_sign;
138 
139  if (is_slice_header) {
140  unsigned int delta_idx = get_ue_golomb_long(gb) + 1;
141  if (delta_idx > sps->nb_st_rps) {
142  av_log(avctx, AV_LOG_ERROR,
143  "Invalid value of delta_idx in slice header RPS: %d > %d.\n",
144  delta_idx, sps->nb_st_rps);
145  return AVERROR_INVALIDDATA;
146  }
147  rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx];
148  rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs;
149  } else
150  rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];
151 
152  delta_rps_sign = get_bits1(gb);
153  abs_delta_rps = get_ue_golomb_long(gb) + 1;
154  if (abs_delta_rps < 1 || abs_delta_rps > 32768) {
155  av_log(avctx, AV_LOG_ERROR,
156  "Invalid value of abs_delta_rps: %d\n",
157  abs_delta_rps);
158  return AVERROR_INVALIDDATA;
159  }
160  delta_rps = (1 - (delta_rps_sign << 1)) * abs_delta_rps;
161  for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {
162  int used = rps->used[k] = get_bits1(gb);
163 
164  if (!used)
165  use_delta_flag = get_bits1(gb);
166 
167  if (used || use_delta_flag) {
168  if (i < rps_ridx->num_delta_pocs)
169  delta_poc = delta_rps + rps_ridx->delta_poc[i];
170  else
171  delta_poc = delta_rps;
172  rps->delta_poc[k] = delta_poc;
173  if (delta_poc < 0)
174  k0++;
175  else
176  k1++;
177  k++;
178  }
179  }
180 
181  if (k >= FF_ARRAY_ELEMS(rps->used)) {
182  av_log(avctx, AV_LOG_ERROR,
183  "Invalid num_delta_pocs: %d\n", k);
184  return AVERROR_INVALIDDATA;
185  }
186 
187  rps->num_delta_pocs = k;
188  rps->num_negative_pics = k0;
189  // sort in increasing order (smallest first)
190  if (rps->num_delta_pocs != 0) {
191  int used, tmp;
192  for (i = 1; i < rps->num_delta_pocs; i++) {
193  delta_poc = rps->delta_poc[i];
194  used = rps->used[i];
195  for (k = i - 1; k >= 0; k--) {
196  tmp = rps->delta_poc[k];
197  if (delta_poc < tmp) {
198  rps->delta_poc[k + 1] = tmp;
199  rps->used[k + 1] = rps->used[k];
200  rps->delta_poc[k] = delta_poc;
201  rps->used[k] = used;
202  }
203  }
204  }
205  }
206  if ((rps->num_negative_pics >> 1) != 0) {
207  int used;
208  k = rps->num_negative_pics - 1;
209  // flip the negative values to largest first
210  for (i = 0; i < rps->num_negative_pics >> 1; i++) {
211  delta_poc = rps->delta_poc[i];
212  used = rps->used[i];
213  rps->delta_poc[i] = rps->delta_poc[k];
214  rps->used[i] = rps->used[k];
215  rps->delta_poc[k] = delta_poc;
216  rps->used[k] = used;
217  k--;
218  }
219  }
220  } else {
221  unsigned int prev, nb_positive_pics;
223  nb_positive_pics = get_ue_golomb_long(gb);
224 
225  if (rps->num_negative_pics >= HEVC_MAX_REFS ||
226  nb_positive_pics >= HEVC_MAX_REFS) {
227  av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n");
228  return AVERROR_INVALIDDATA;
229  }
230 
231  rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics;
232  if (rps->num_delta_pocs) {
233  prev = 0;
234  for (i = 0; i < rps->num_negative_pics; i++) {
235  delta_poc = get_ue_golomb_long(gb) + 1;
236  if (delta_poc < 1 || delta_poc > 32768) {
237  av_log(avctx, AV_LOG_ERROR,
238  "Invalid value of delta_poc: %d\n",
239  delta_poc);
240  return AVERROR_INVALIDDATA;
241  }
242  prev -= delta_poc;
243  rps->delta_poc[i] = prev;
244  rps->used[i] = get_bits1(gb);
245  }
246  prev = 0;
247  for (i = 0; i < nb_positive_pics; i++) {
248  delta_poc = get_ue_golomb_long(gb) + 1;
249  if (delta_poc < 1 || delta_poc > 32768) {
250  av_log(avctx, AV_LOG_ERROR,
251  "Invalid value of delta_poc: %d\n",
252  delta_poc);
253  return AVERROR_INVALIDDATA;
254  }
255  prev += delta_poc;
256  rps->delta_poc[rps->num_negative_pics + i] = prev;
257  rps->used[rps->num_negative_pics + i] = get_bits1(gb);
258  }
259  }
260  }
261  return 0;
262 }
263 
264 
266  PTLCommon *ptl)
267 {
268  int i;
269 
270  if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 43 + 1)
271  return -1;
272 
273  ptl->profile_space = get_bits(gb, 2);
274  ptl->tier_flag = get_bits1(gb);
275  ptl->profile_idc = get_bits(gb, 5);
276  if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN)
277  av_log(avctx, AV_LOG_DEBUG, "Main profile bitstream\n");
278  else if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN_10)
279  av_log(avctx, AV_LOG_DEBUG, "Main 10 profile bitstream\n");
281  av_log(avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n");
282  else if (ptl->profile_idc == FF_PROFILE_HEVC_REXT)
283  av_log(avctx, AV_LOG_DEBUG, "Range Extension profile bitstream\n");
284  else
285  av_log(avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", ptl->profile_idc);
286 
287  for (i = 0; i < 32; i++) {
289 
290  if (ptl->profile_idc == 0 && i > 0 && ptl->profile_compatibility_flag[i])
291  ptl->profile_idc = i;
292  }
297 
298 #define check_profile_idc(idc) \
299  ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc]
300 
303  check_profile_idc(10)) {
304 
311  ptl->intra_constraint_flag = get_bits1(gb);
314 
317  skip_bits_long(gb, 33); // XXX_reserved_zero_33bits[0..32]
318  } else {
319  skip_bits_long(gb, 34); // XXX_reserved_zero_34bits[0..33]
320  }
321  } else if (check_profile_idc(2)) {
322  skip_bits(gb, 7);
324  skip_bits_long(gb, 35); // XXX_reserved_zero_35bits[0..34]
325  } else {
326  skip_bits_long(gb, 43); // XXX_reserved_zero_43bits[0..42]
327  }
328 
331  ptl->inbld_flag = get_bits1(gb);
332  else
333  skip_bits1(gb);
334 #undef check_profile_idc
335 
336  return 0;
337 }
338 
339 static int parse_ptl(GetBitContext *gb, AVCodecContext *avctx,
340  PTL *ptl, int max_num_sub_layers)
341 {
342  int i;
343  if (decode_profile_tier_level(gb, avctx, &ptl->general_ptl) < 0 ||
344  get_bits_left(gb) < 8 + (8*2 * (max_num_sub_layers - 1 > 0))) {
345  av_log(avctx, AV_LOG_ERROR, "PTL information too short\n");
346  return -1;
347  }
348 
349  ptl->general_ptl.level_idc = get_bits(gb, 8);
350 
351  for (i = 0; i < max_num_sub_layers - 1; i++) {
354  }
355 
356  if (max_num_sub_layers - 1> 0)
357  for (i = max_num_sub_layers - 1; i < 8; i++)
358  skip_bits(gb, 2); // reserved_zero_2bits[i]
359  for (i = 0; i < max_num_sub_layers - 1; i++) {
360  if (ptl->sub_layer_profile_present_flag[i] &&
361  decode_profile_tier_level(gb, avctx, &ptl->sub_layer_ptl[i]) < 0) {
362  av_log(avctx, AV_LOG_ERROR,
363  "PTL information for sublayer %i too short\n", i);
364  return -1;
365  }
366  if (ptl->sub_layer_level_present_flag[i]) {
367  if (get_bits_left(gb) < 8) {
368  av_log(avctx, AV_LOG_ERROR,
369  "Not enough data for sublayer %i level_idc\n", i);
370  return -1;
371  } else
372  ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8);
373  }
374  }
375 
376  return 0;
377 }
378 
379 static void decode_sublayer_hrd(GetBitContext *gb, unsigned int nb_cpb,
380  int subpic_params_present)
381 {
382  int i;
383 
384  for (i = 0; i < nb_cpb; i++) {
385  get_ue_golomb_long(gb); // bit_rate_value_minus1
386  get_ue_golomb_long(gb); // cpb_size_value_minus1
387 
388  if (subpic_params_present) {
389  get_ue_golomb_long(gb); // cpb_size_du_value_minus1
390  get_ue_golomb_long(gb); // bit_rate_du_value_minus1
391  }
392  skip_bits1(gb); // cbr_flag
393  }
394 }
395 
396 static int decode_hrd(GetBitContext *gb, int common_inf_present,
397  int max_sublayers)
398 {
399  int nal_params_present = 0, vcl_params_present = 0;
400  int subpic_params_present = 0;
401  int i;
402 
403  if (common_inf_present) {
404  nal_params_present = get_bits1(gb);
405  vcl_params_present = get_bits1(gb);
406 
407  if (nal_params_present || vcl_params_present) {
408  subpic_params_present = get_bits1(gb);
409 
410  if (subpic_params_present) {
411  skip_bits(gb, 8); // tick_divisor_minus2
412  skip_bits(gb, 5); // du_cpb_removal_delay_increment_length_minus1
413  skip_bits(gb, 1); // sub_pic_cpb_params_in_pic_timing_sei_flag
414  skip_bits(gb, 5); // dpb_output_delay_du_length_minus1
415  }
416 
417  skip_bits(gb, 4); // bit_rate_scale
418  skip_bits(gb, 4); // cpb_size_scale
419 
420  if (subpic_params_present)
421  skip_bits(gb, 4); // cpb_size_du_scale
422 
423  skip_bits(gb, 5); // initial_cpb_removal_delay_length_minus1
424  skip_bits(gb, 5); // au_cpb_removal_delay_length_minus1
425  skip_bits(gb, 5); // dpb_output_delay_length_minus1
426  }
427  }
428 
429  for (i = 0; i < max_sublayers; i++) {
430  int low_delay = 0;
431  unsigned int nb_cpb = 1;
432  int fixed_rate = get_bits1(gb);
433 
434  if (!fixed_rate)
435  fixed_rate = get_bits1(gb);
436 
437  if (fixed_rate)
438  get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1
439  else
440  low_delay = get_bits1(gb);
441 
442  if (!low_delay) {
443  nb_cpb = get_ue_golomb_long(gb) + 1;
444  if (nb_cpb < 1 || nb_cpb > 32) {
445  av_log(NULL, AV_LOG_ERROR, "nb_cpb %d invalid\n", nb_cpb);
446  return AVERROR_INVALIDDATA;
447  }
448  }
449 
450  if (nal_params_present)
451  decode_sublayer_hrd(gb, nb_cpb, subpic_params_present);
452  if (vcl_params_present)
453  decode_sublayer_hrd(gb, nb_cpb, subpic_params_present);
454  }
455  return 0;
456 }
457 
459  HEVCParamSets *ps)
460 {
461  int i,j;
462  int vps_id = 0;
463  ptrdiff_t nal_size;
464  HEVCVPS *vps;
465  AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps));
466 
467  if (!vps_buf)
468  return AVERROR(ENOMEM);
469  vps = (HEVCVPS*)vps_buf->data;
470 
471  av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n");
472 
473  nal_size = gb->buffer_end - gb->buffer;
474  if (nal_size > sizeof(vps->data)) {
475  av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized VPS "
476  "(%"PTRDIFF_SPECIFIER" > %"SIZE_SPECIFIER")\n",
477  nal_size, sizeof(vps->data));
478  vps->data_size = sizeof(vps->data);
479  } else {
480  vps->data_size = nal_size;
481  }
482  memcpy(vps->data, gb->buffer, vps->data_size);
483 
484  vps_id = get_bits(gb, 4);
485 
486  if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits
487  av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
488  goto err;
489  }
490 
491  vps->vps_max_layers = get_bits(gb, 6) + 1;
492  vps->vps_max_sub_layers = get_bits(gb, 3) + 1;
494 
495  if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits
496  av_log(avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n");
497  goto err;
498  }
499 
501  av_log(avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n",
502  vps->vps_max_sub_layers);
503  goto err;
504  }
505 
506  if (parse_ptl(gb, avctx, &vps->ptl, vps->vps_max_sub_layers) < 0)
507  goto err;
508 
510 
512  for (; i < vps->vps_max_sub_layers; i++) {
516 
518  av_log(avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n",
519  vps->vps_max_dec_pic_buffering[i] - 1);
520  goto err;
521  }
522  if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) {
523  av_log(avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n",
524  vps->vps_num_reorder_pics[i]);
525  if (avctx->err_recognition & AV_EF_EXPLODE)
526  goto err;
527  }
528  }
529 
530  vps->vps_max_layer_id = get_bits(gb, 6);
531  vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1;
532  if (vps->vps_num_layer_sets < 1 || vps->vps_num_layer_sets > 1024 ||
533  (vps->vps_num_layer_sets - 1LL) * (vps->vps_max_layer_id + 1LL) > get_bits_left(gb)) {
534  av_log(avctx, AV_LOG_ERROR, "too many layer_id_included_flags\n");
535  goto err;
536  }
537 
538  for (i = 1; i < vps->vps_num_layer_sets; i++)
539  for (j = 0; j <= vps->vps_max_layer_id; j++)
540  skip_bits(gb, 1); // layer_id_included_flag[i][j]
541 
543  if (vps->vps_timing_info_present_flag) {
544  vps->vps_num_units_in_tick = get_bits_long(gb, 32);
545  vps->vps_time_scale = get_bits_long(gb, 32);
550  if (vps->vps_num_hrd_parameters > (unsigned)vps->vps_num_layer_sets) {
551  av_log(avctx, AV_LOG_ERROR,
552  "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters);
553  goto err;
554  }
555  for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
556  int common_inf_present = 1;
557 
558  get_ue_golomb_long(gb); // hrd_layer_set_idx
559  if (i)
560  common_inf_present = get_bits1(gb);
561  decode_hrd(gb, common_inf_present, vps->vps_max_sub_layers);
562  }
563  }
564  get_bits1(gb); /* vps_extension_flag */
565 
566  if (get_bits_left(gb) < 0) {
567  av_log(avctx, AV_LOG_ERROR,
568  "Overread VPS by %d bits\n", -get_bits_left(gb));
569  if (ps->vps_list[vps_id])
570  goto err;
571  }
572 
573  if (ps->vps_list[vps_id] &&
574  !memcmp(ps->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) {
575  av_buffer_unref(&vps_buf);
576  } else {
577  remove_vps(ps, vps_id);
578  ps->vps_list[vps_id] = vps_buf;
579  }
580 
581  return 0;
582 
583 err:
584  av_buffer_unref(&vps_buf);
585  return AVERROR_INVALIDDATA;
586 }
587 
588 static void decode_vui(GetBitContext *gb, AVCodecContext *avctx,
589  int apply_defdispwin, HEVCSPS *sps)
590 {
591  VUI backup_vui, *vui = &sps->vui;
592  GetBitContext backup;
593  int sar_present, alt = 0;
594 
595  av_log(avctx, AV_LOG_DEBUG, "Decoding VUI\n");
596 
597  sar_present = get_bits1(gb);
598  if (sar_present) {
599  uint8_t sar_idx = get_bits(gb, 8);
600  if (sar_idx < FF_ARRAY_ELEMS(vui_sar))
601  vui->sar = vui_sar[sar_idx];
602  else if (sar_idx == 255) {
603  vui->sar.num = get_bits(gb, 16);
604  vui->sar.den = get_bits(gb, 16);
605  } else
606  av_log(avctx, AV_LOG_WARNING,
607  "Unknown SAR index: %u.\n", sar_idx);
608  }
609 
613 
616  vui->video_format = get_bits(gb, 3);
617  vui->video_full_range_flag = get_bits1(gb);
622  vui->colour_primaries = get_bits(gb, 8);
623  vui->transfer_characteristic = get_bits(gb, 8);
624  vui->matrix_coeffs = get_bits(gb, 8);
625 
626  // Set invalid values to "unspecified"
633  if (vui->matrix_coeffs == AVCOL_SPC_RGB) {
634  switch (sps->pix_fmt) {
635  case AV_PIX_FMT_YUV444P:
636  sps->pix_fmt = AV_PIX_FMT_GBRP;
637  break;
639  sps->pix_fmt = AV_PIX_FMT_GBRP10;
640  break;
642  sps->pix_fmt = AV_PIX_FMT_GBRP12;
643  break;
644  }
645  }
646  }
647  }
648 
650  if (vui->chroma_loc_info_present_flag) {
653  }
654 
656  vui->field_seq_flag = get_bits1(gb);
658 
659  // Backup context in case an alternate header is detected
660  memcpy(&backup, gb, sizeof(backup));
661  memcpy(&backup_vui, vui, sizeof(backup_vui));
662  if (get_bits_left(gb) >= 68 && show_bits_long(gb, 21) == 0x100000) {
664  av_log(avctx, AV_LOG_WARNING, "Invalid default display window\n");
665  } else
667 
668  if (vui->default_display_window_flag) {
669  int vert_mult = hevc_sub_height_c[sps->chroma_format_idc];
670  int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc];
671  vui->def_disp_win.left_offset = get_ue_golomb_long(gb) * horiz_mult;
672  vui->def_disp_win.right_offset = get_ue_golomb_long(gb) * horiz_mult;
673  vui->def_disp_win.top_offset = get_ue_golomb_long(gb) * vert_mult;
674  vui->def_disp_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult;
675 
676  if (apply_defdispwin &&
678  av_log(avctx, AV_LOG_DEBUG,
679  "discarding vui default display window, "
680  "original values are l:%u r:%u t:%u b:%u\n",
685 
688  vui->def_disp_win.top_offset =
689  vui->def_disp_win.bottom_offset = 0;
690  }
691  }
692 
695 
696  if (vui->vui_timing_info_present_flag) {
697  if( get_bits_left(gb) < 66 && !alt) {
698  // The alternate syntax seem to have timing info located
699  // at where def_disp_win is normally located
700  av_log(avctx, AV_LOG_WARNING,
701  "Strange VUI timing information, retrying...\n");
702  memcpy(vui, &backup_vui, sizeof(backup_vui));
703  memcpy(gb, &backup, sizeof(backup));
704  alt = 1;
705  goto timing_info;
706  }
707  vui->vui_num_units_in_tick = get_bits_long(gb, 32);
708  vui->vui_time_scale = get_bits_long(gb, 32);
709  if (alt) {
710  av_log(avctx, AV_LOG_INFO, "Retry got %"PRIu32"/%"PRIu32" fps\n",
712  }
718  decode_hrd(gb, 1, sps->max_sub_layers);
719  }
720 
722  if (vui->bitstream_restriction_flag) {
723  if (get_bits_left(gb) < 8 && !alt) {
724  av_log(avctx, AV_LOG_WARNING,
725  "Strange VUI bitstream restriction information, retrying"
726  " from timing information...\n");
727  memcpy(vui, &backup_vui, sizeof(backup_vui));
728  memcpy(gb, &backup, sizeof(backup));
729  alt = 1;
730  goto timing_info;
731  }
740  }
741 
742  if (get_bits_left(gb) < 1 && !alt) {
743  // XXX: Alternate syntax when sps_range_extension_flag != 0?
744  av_log(avctx, AV_LOG_WARNING,
745  "Overread in VUI, retrying from timing information...\n");
746  memcpy(vui, &backup_vui, sizeof(backup_vui));
747  memcpy(gb, &backup, sizeof(backup));
748  alt = 1;
749  goto timing_info;
750  }
751 }
752 
754 {
755  int matrixId;
756 
757  for (matrixId = 0; matrixId < 6; matrixId++) {
758  // 4x4 default is 16
759  memset(sl->sl[0][matrixId], 16, 16);
760  sl->sl_dc[0][matrixId] = 16; // default for 16x16
761  sl->sl_dc[1][matrixId] = 16; // default for 32x32
762  }
763  memcpy(sl->sl[1][0], default_scaling_list_intra, 64);
764  memcpy(sl->sl[1][1], default_scaling_list_intra, 64);
765  memcpy(sl->sl[1][2], default_scaling_list_intra, 64);
766  memcpy(sl->sl[1][3], default_scaling_list_inter, 64);
767  memcpy(sl->sl[1][4], default_scaling_list_inter, 64);
768  memcpy(sl->sl[1][5], default_scaling_list_inter, 64);
769  memcpy(sl->sl[2][0], default_scaling_list_intra, 64);
770  memcpy(sl->sl[2][1], default_scaling_list_intra, 64);
771  memcpy(sl->sl[2][2], default_scaling_list_intra, 64);
772  memcpy(sl->sl[2][3], default_scaling_list_inter, 64);
773  memcpy(sl->sl[2][4], default_scaling_list_inter, 64);
774  memcpy(sl->sl[2][5], default_scaling_list_inter, 64);
775  memcpy(sl->sl[3][0], default_scaling_list_intra, 64);
776  memcpy(sl->sl[3][1], default_scaling_list_intra, 64);
777  memcpy(sl->sl[3][2], default_scaling_list_intra, 64);
778  memcpy(sl->sl[3][3], default_scaling_list_inter, 64);
779  memcpy(sl->sl[3][4], default_scaling_list_inter, 64);
780  memcpy(sl->sl[3][5], default_scaling_list_inter, 64);
781 }
782 
784 {
785  uint8_t scaling_list_pred_mode_flag;
786  int32_t scaling_list_dc_coef[2][6];
787  int size_id, matrix_id, pos;
788  int i;
789 
790  for (size_id = 0; size_id < 4; size_id++)
791  for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {
792  scaling_list_pred_mode_flag = get_bits1(gb);
793  if (!scaling_list_pred_mode_flag) {
794  unsigned int delta = get_ue_golomb_long(gb);
795  /* Only need to handle non-zero delta. Zero means default,
796  * which should already be in the arrays. */
797  if (delta) {
798  // Copy from previous array.
799  delta *= (size_id == 3) ? 3 : 1;
800  if (matrix_id < delta) {
801  av_log(avctx, AV_LOG_ERROR,
802  "Invalid delta in scaling list data: %d.\n", delta);
803  return AVERROR_INVALIDDATA;
804  }
805 
806  memcpy(sl->sl[size_id][matrix_id],
807  sl->sl[size_id][matrix_id - delta],
808  size_id > 0 ? 64 : 16);
809  if (size_id > 1)
810  sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta];
811  }
812  } else {
813  int next_coef, coef_num;
814  int32_t scaling_list_delta_coef;
815 
816  next_coef = 8;
817  coef_num = FFMIN(64, 1 << (4 + (size_id << 1)));
818  if (size_id > 1) {
819  scaling_list_dc_coef[size_id - 2][matrix_id] = get_se_golomb(gb) + 8;
820  next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
821  sl->sl_dc[size_id - 2][matrix_id] = next_coef;
822  }
823  for (i = 0; i < coef_num; i++) {
824  if (size_id == 0)
825  pos = 4 * ff_hevc_diag_scan4x4_y[i] +
827  else
828  pos = 8 * ff_hevc_diag_scan8x8_y[i] +
830 
831  scaling_list_delta_coef = get_se_golomb(gb);
832  next_coef = (next_coef + 256U + scaling_list_delta_coef) % 256;
833  sl->sl[size_id][matrix_id][pos] = next_coef;
834  }
835  }
836  }
837 
838  if (sps->chroma_format_idc == 3) {
839  for (i = 0; i < 64; i++) {
840  sl->sl[3][1][i] = sl->sl[2][1][i];
841  sl->sl[3][2][i] = sl->sl[2][2][i];
842  sl->sl[3][4][i] = sl->sl[2][4][i];
843  sl->sl[3][5][i] = sl->sl[2][5][i];
844  }
845  sl->sl_dc[1][1] = sl->sl_dc[0][1];
846  sl->sl_dc[1][2] = sl->sl_dc[0][2];
847  sl->sl_dc[1][4] = sl->sl_dc[0][4];
848  sl->sl_dc[1][5] = sl->sl_dc[0][5];
849  }
850 
851 
852  return 0;
853 }
854 
856 {
857  const AVPixFmtDescriptor *desc;
858  switch (sps->bit_depth) {
859  case 8:
860  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
861  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
862  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
863  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
864  break;
865  case 9:
866  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY9;
867  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9;
868  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9;
869  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9;
870  break;
871  case 10:
872  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10;
873  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
874  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
875  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
876  break;
877  case 12:
878  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12;
879  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
880  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
881  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
882  break;
883  default:
884  av_log(avctx, AV_LOG_ERROR,
885  "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, "
886  "chroma_format_idc is %d, depth is %d\n",
887  sps->chroma_format_idc, sps->bit_depth);
888  return AVERROR_INVALIDDATA;
889  }
890 
891  desc = av_pix_fmt_desc_get(sps->pix_fmt);
892  if (!desc)
893  return AVERROR(EINVAL);
894 
895  sps->hshift[0] = sps->vshift[0] = 0;
896  sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
897  sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
898 
899  sps->pixel_shift = sps->bit_depth > 8;
900 
901  return 0;
902 }
903 
904 int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
905  int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx)
906 {
907  HEVCWindow *ow;
908  int ret = 0;
909  int log2_diff_max_min_transform_block_size;
910  int bit_depth_chroma, start, vui_present, sublayer_ordering_info;
911  int i;
912 
913  // Coded parameters
914 
915  sps->vps_id = get_bits(gb, 4);
916 
917  if (vps_list && !vps_list[sps->vps_id]) {
918  av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
919  sps->vps_id);
920  return AVERROR_INVALIDDATA;
921  }
922 
923  sps->max_sub_layers = get_bits(gb, 3) + 1;
924  if (sps->max_sub_layers > HEVC_MAX_SUB_LAYERS) {
925  av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n",
926  sps->max_sub_layers);
927  return AVERROR_INVALIDDATA;
928  }
929 
930  sps->temporal_id_nesting_flag = get_bits(gb, 1);
931 
932  if ((ret = parse_ptl(gb, avctx, &sps->ptl, sps->max_sub_layers)) < 0)
933  return ret;
934 
935  *sps_id = get_ue_golomb_long(gb);
936  if (*sps_id >= HEVC_MAX_SPS_COUNT) {
937  av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id);
938  return AVERROR_INVALIDDATA;
939  }
940 
942  if (sps->chroma_format_idc > 3U) {
943  av_log(avctx, AV_LOG_ERROR, "chroma_format_idc %d is invalid\n", sps->chroma_format_idc);
944  return AVERROR_INVALIDDATA;
945  }
946 
947  if (sps->chroma_format_idc == 3)
949 
951  sps->chroma_format_idc = 0;
952 
953  sps->width = get_ue_golomb_long(gb);
954  sps->height = get_ue_golomb_long(gb);
955  if ((ret = av_image_check_size(sps->width,
956  sps->height, 0, avctx)) < 0)
957  return ret;
958 
959  if (get_bits1(gb)) { // pic_conformance_flag
960  int vert_mult = hevc_sub_height_c[sps->chroma_format_idc];
961  int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc];
962  sps->pic_conf_win.left_offset = get_ue_golomb_long(gb) * horiz_mult;
963  sps->pic_conf_win.right_offset = get_ue_golomb_long(gb) * horiz_mult;
964  sps->pic_conf_win.top_offset = get_ue_golomb_long(gb) * vert_mult;
965  sps->pic_conf_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult;
966 
967  if (avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) {
968  av_log(avctx, AV_LOG_DEBUG,
969  "discarding sps conformance window, "
970  "original values are l:%u r:%u t:%u b:%u\n",
975 
978  sps->pic_conf_win.top_offset =
979  sps->pic_conf_win.bottom_offset = 0;
980  }
981  sps->output_window = sps->pic_conf_win;
982  }
983 
984  sps->bit_depth = get_ue_golomb_long(gb) + 8;
985  bit_depth_chroma = get_ue_golomb_long(gb) + 8;
986  if (sps->chroma_format_idc && bit_depth_chroma != sps->bit_depth) {
987  av_log(avctx, AV_LOG_ERROR,
988  "Luma bit depth (%d) is different from chroma bit depth (%d), "
989  "this is unsupported.\n",
990  sps->bit_depth, bit_depth_chroma);
991  return AVERROR_INVALIDDATA;
992  }
993  sps->bit_depth_chroma = bit_depth_chroma;
994 
995  ret = map_pixel_format(avctx, sps);
996  if (ret < 0)
997  return ret;
998 
999  sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4;
1000  if (sps->log2_max_poc_lsb > 16) {
1001  av_log(avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n",
1002  sps->log2_max_poc_lsb - 4);
1003  return AVERROR_INVALIDDATA;
1004  }
1005 
1006  sublayer_ordering_info = get_bits1(gb);
1007  start = sublayer_ordering_info ? 0 : sps->max_sub_layers - 1;
1008  for (i = start; i < sps->max_sub_layers; i++) {
1012  if (sps->temporal_layer[i].max_dec_pic_buffering > (unsigned)HEVC_MAX_DPB_SIZE) {
1013  av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n",
1015  return AVERROR_INVALIDDATA;
1016  }
1018  av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n",
1020  if (avctx->err_recognition & AV_EF_EXPLODE ||
1021  sps->temporal_layer[i].num_reorder_pics > HEVC_MAX_DPB_SIZE - 1) {
1022  return AVERROR_INVALIDDATA;
1023  }
1025  }
1026  }
1027 
1028  if (!sublayer_ordering_info) {
1029  for (i = 0; i < start; i++) {
1033  }
1034  }
1035 
1036  sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3;
1038  sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2;
1039  log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb);
1040  sps->log2_max_trafo_size = log2_diff_max_min_transform_block_size +
1041  sps->log2_min_tb_size;
1042 
1043  if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) {
1044  av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size);
1045  return AVERROR_INVALIDDATA;
1046  }
1047 
1048  if (sps->log2_diff_max_min_coding_block_size > 30) {
1049  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);
1050  return AVERROR_INVALIDDATA;
1051  }
1052 
1053  if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) {
1054  av_log(avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size");
1055  return AVERROR_INVALIDDATA;
1056  }
1057 
1058  if (log2_diff_max_min_transform_block_size < 0 || log2_diff_max_min_transform_block_size > 30) {
1059  av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size", log2_diff_max_min_transform_block_size);
1060  return AVERROR_INVALIDDATA;
1061  }
1062 
1065 
1067  if (sps->scaling_list_enable_flag) {
1069 
1070  if (get_bits1(gb)) {
1071  ret = scaling_list_data(gb, avctx, &sps->scaling_list, sps);
1072  if (ret < 0)
1073  return ret;
1074  }
1075  }
1076 
1077  sps->amp_enabled_flag = get_bits1(gb);
1078  sps->sao_enabled = get_bits1(gb);
1079 
1080  sps->pcm_enabled_flag = get_bits1(gb);
1081  if (sps->pcm_enabled_flag) {
1082  sps->pcm.bit_depth = get_bits(gb, 4) + 1;
1083  sps->pcm.bit_depth_chroma = get_bits(gb, 4) + 1;
1086  get_ue_golomb_long(gb);
1087  if (FFMAX(sps->pcm.bit_depth, sps->pcm.bit_depth_chroma) > sps->bit_depth) {
1088  av_log(avctx, AV_LOG_ERROR,
1089  "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n",
1090  sps->pcm.bit_depth, sps->pcm.bit_depth_chroma, sps->bit_depth);
1091  return AVERROR_INVALIDDATA;
1092  }
1093 
1095  }
1096 
1097  sps->nb_st_rps = get_ue_golomb_long(gb);
1099  av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n",
1100  sps->nb_st_rps);
1101  return AVERROR_INVALIDDATA;
1102  }
1103  for (i = 0; i < sps->nb_st_rps; i++) {
1104  if ((ret = ff_hevc_decode_short_term_rps(gb, avctx, &sps->st_rps[i],
1105  sps, 0)) < 0)
1106  return ret;
1107  }
1108 
1113  av_log(avctx, AV_LOG_ERROR, "Too many long term ref pics: %d.\n",
1115  return AVERROR_INVALIDDATA;
1116  }
1117  for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
1120  }
1121  }
1122 
1125  sps->vui.sar = (AVRational){0, 1};
1126  vui_present = get_bits1(gb);
1127  if (vui_present)
1128  decode_vui(gb, avctx, apply_defdispwin, sps);
1129 
1130  if (get_bits1(gb)) { // sps_extension_flag
1132  skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
1133  if (sps->sps_range_extension_flag) {
1137 
1139 
1142  av_log(avctx, AV_LOG_WARNING,
1143  "extended_precision_processing_flag not yet implemented\n");
1144 
1148  av_log(avctx, AV_LOG_WARNING,
1149  "high_precision_offsets_enabled_flag not yet implemented\n");
1150 
1152 
1155  av_log(avctx, AV_LOG_WARNING,
1156  "cabac_bypass_alignment_enabled_flag not yet implemented\n");
1157  }
1158  }
1159  if (apply_defdispwin) {
1164  }
1165 
1166  ow = &sps->output_window;
1167  if (ow->left_offset >= INT_MAX - ow->right_offset ||
1168  ow->top_offset >= INT_MAX - ow->bottom_offset ||
1169  ow->left_offset + ow->right_offset >= sps->width ||
1170  ow->top_offset + ow->bottom_offset >= sps->height) {
1171  av_log(avctx, AV_LOG_WARNING, "Invalid cropping offsets: %u/%u/%u/%u\n",
1172  ow->left_offset, ow->right_offset, ow->top_offset, ow->bottom_offset);
1173  if (avctx->err_recognition & AV_EF_EXPLODE) {
1174  return AVERROR_INVALIDDATA;
1175  }
1176  av_log(avctx, AV_LOG_WARNING,
1177  "Displaying the whole video surface.\n");
1178  memset(ow, 0, sizeof(*ow));
1179  memset(&sps->pic_conf_win, 0, sizeof(sps->pic_conf_win));
1180  }
1181 
1182  // Inferred parameters
1183  sps->log2_ctb_size = sps->log2_min_cb_size +
1185  sps->log2_min_pu_size = sps->log2_min_cb_size - 1;
1186 
1188  av_log(avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size);
1189  return AVERROR_INVALIDDATA;
1190  }
1191  if (sps->log2_ctb_size < 4) {
1192  av_log(avctx,
1193  AV_LOG_ERROR,
1194  "log2_ctb_size %d differs from the bounds of any known profile\n",
1195  sps->log2_ctb_size);
1196  avpriv_request_sample(avctx, "log2_ctb_size %d", sps->log2_ctb_size);
1197  return AVERROR_INVALIDDATA;
1198  }
1199 
1200  sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
1201  sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
1202  sps->ctb_size = sps->ctb_width * sps->ctb_height;
1203 
1204  sps->min_cb_width = sps->width >> sps->log2_min_cb_size;
1205  sps->min_cb_height = sps->height >> sps->log2_min_cb_size;
1206  sps->min_tb_width = sps->width >> sps->log2_min_tb_size;
1207  sps->min_tb_height = sps->height >> sps->log2_min_tb_size;
1208  sps->min_pu_width = sps->width >> sps->log2_min_pu_size;
1209  sps->min_pu_height = sps->height >> sps->log2_min_pu_size;
1210  sps->tb_mask = (1 << (sps->log2_ctb_size - sps->log2_min_tb_size)) - 1;
1211 
1212  sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
1213 
1214  if (av_mod_uintp2(sps->width, sps->log2_min_cb_size) ||
1215  av_mod_uintp2(sps->height, sps->log2_min_cb_size)) {
1216  av_log(avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n");
1217  return AVERROR_INVALIDDATA;
1218  }
1219 
1221  av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n",
1223  return AVERROR_INVALIDDATA;
1224  }
1226  av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n",
1228  return AVERROR_INVALIDDATA;
1229  }
1230  if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) {
1231  av_log(avctx, AV_LOG_ERROR,
1232  "max transform block size out of range: %d\n",
1233  sps->log2_max_trafo_size);
1234  return AVERROR_INVALIDDATA;
1235  }
1236 
1237  if (get_bits_left(gb) < 0) {
1238  av_log(avctx, AV_LOG_ERROR,
1239  "Overread SPS by %d bits\n", -get_bits_left(gb));
1240  return AVERROR_INVALIDDATA;
1241  }
1242 
1243  return 0;
1244 }
1245 
1247  HEVCParamSets *ps, int apply_defdispwin)
1248 {
1249  HEVCSPS *sps;
1250  AVBufferRef *sps_buf = av_buffer_allocz(sizeof(*sps));
1251  unsigned int sps_id;
1252  int ret;
1253  ptrdiff_t nal_size;
1254 
1255  if (!sps_buf)
1256  return AVERROR(ENOMEM);
1257  sps = (HEVCSPS*)sps_buf->data;
1258 
1259  av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n");
1260 
1261  nal_size = gb->buffer_end - gb->buffer;
1262  if (nal_size > sizeof(sps->data)) {
1263  av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized SPS "
1264  "(%"PTRDIFF_SPECIFIER" > %"SIZE_SPECIFIER")\n",
1265  nal_size, sizeof(sps->data));
1266  sps->data_size = sizeof(sps->data);
1267  } else {
1268  sps->data_size = nal_size;
1269  }
1270  memcpy(sps->data, gb->buffer, sps->data_size);
1271 
1272  ret = ff_hevc_parse_sps(sps, gb, &sps_id,
1273  apply_defdispwin,
1274  ps->vps_list, avctx);
1275  if (ret < 0) {
1276  av_buffer_unref(&sps_buf);
1277  return ret;
1278  }
1279 
1280  if (avctx->debug & FF_DEBUG_BITSTREAM) {
1281  av_log(avctx, AV_LOG_DEBUG,
1282  "Parsed SPS: id %d; coded wxh: %dx%d; "
1283  "cropped wxh: %dx%d; pix_fmt: %s.\n",
1284  sps_id, sps->width, sps->height,
1288  }
1289 
1290  /* check if this is a repeat of an already parsed SPS, then keep the
1291  * original one.
1292  * otherwise drop all PPSes that depend on it */
1293  if (ps->sps_list[sps_id] &&
1294  !memcmp(ps->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) {
1295  av_buffer_unref(&sps_buf);
1296  } else {
1297  remove_sps(ps, sps_id);
1298  ps->sps_list[sps_id] = sps_buf;
1299  }
1300 
1301  return 0;
1302 }
1303 
1304 static void hevc_pps_free(void *opaque, uint8_t *data)
1305 {
1306  HEVCPPS *pps = (HEVCPPS*)data;
1307 
1308  av_freep(&pps->column_width);
1309  av_freep(&pps->row_height);
1310  av_freep(&pps->col_bd);
1311  av_freep(&pps->row_bd);
1312  av_freep(&pps->col_idxX);
1313  av_freep(&pps->ctb_addr_rs_to_ts);
1314  av_freep(&pps->ctb_addr_ts_to_rs);
1315  av_freep(&pps->tile_pos_rs);
1316  av_freep(&pps->tile_id);
1318 
1319  av_freep(&pps);
1320 }
1321 
1323  HEVCPPS *pps, HEVCSPS *sps) {
1324  int i;
1325 
1326  if (pps->transform_skip_enabled_flag) {
1328  }
1334  if (pps->chroma_qp_offset_list_len_minus1 > 5) {
1335  av_log(avctx, AV_LOG_ERROR,
1336  "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
1337  return AVERROR_INVALIDDATA;
1338  }
1339  for (i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
1341  if (pps->cb_qp_offset_list[i]) {
1342  av_log(avctx, AV_LOG_WARNING,
1343  "cb_qp_offset_list not tested yet.\n");
1344  }
1346  if (pps->cr_qp_offset_list[i]) {
1347  av_log(avctx, AV_LOG_WARNING,
1348  "cb_qp_offset_list not tested yet.\n");
1349  }
1350  }
1351  }
1354 
1355  if ( pps->log2_sao_offset_scale_luma > FFMAX(sps->bit_depth - 10, 0)
1356  || pps->log2_sao_offset_scale_chroma > FFMAX(sps->bit_depth_chroma - 10, 0)
1357  )
1358  return AVERROR_INVALIDDATA;
1359 
1360  return(0);
1361 }
1362 
1363 static inline int setup_pps(AVCodecContext *avctx, GetBitContext *gb,
1364  HEVCPPS *pps, HEVCSPS *sps)
1365 {
1366  int log2_diff;
1367  int pic_area_in_ctbs;
1368  int i, j, x, y, ctb_addr_rs, tile_id;
1369 
1370  // Inferred parameters
1371  pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd));
1372  pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd));
1373  pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX));
1374  if (!pps->col_bd || !pps->row_bd || !pps->col_idxX)
1375  return AVERROR(ENOMEM);
1376 
1377  if (pps->uniform_spacing_flag) {
1378  if (!pps->column_width) {
1379  pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
1380  pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
1381  }
1382  if (!pps->column_width || !pps->row_height)
1383  return AVERROR(ENOMEM);
1384 
1385  for (i = 0; i < pps->num_tile_columns; i++) {
1386  pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns -
1387  (i * sps->ctb_width) / pps->num_tile_columns;
1388  }
1389 
1390  for (i = 0; i < pps->num_tile_rows; i++) {
1391  pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows -
1392  (i * sps->ctb_height) / pps->num_tile_rows;
1393  }
1394  }
1395 
1396  pps->col_bd[0] = 0;
1397  for (i = 0; i < pps->num_tile_columns; i++)
1398  pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i];
1399 
1400  pps->row_bd[0] = 0;
1401  for (i = 0; i < pps->num_tile_rows; i++)
1402  pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i];
1403 
1404  for (i = 0, j = 0; i < sps->ctb_width; i++) {
1405  if (i > pps->col_bd[j])
1406  j++;
1407  pps->col_idxX[i] = j;
1408  }
1409 
1410  /**
1411  * 6.5
1412  */
1413  pic_area_in_ctbs = sps->ctb_width * sps->ctb_height;
1414 
1415  pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts));
1416  pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs));
1417  pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id));
1418  pps->min_tb_addr_zs_tab = av_malloc_array((sps->tb_mask+2) * (sps->tb_mask+2), sizeof(*pps->min_tb_addr_zs_tab));
1419  if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs ||
1420  !pps->tile_id || !pps->min_tb_addr_zs_tab) {
1421  return AVERROR(ENOMEM);
1422  }
1423 
1424  for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
1425  int tb_x = ctb_addr_rs % sps->ctb_width;
1426  int tb_y = ctb_addr_rs / sps->ctb_width;
1427  int tile_x = 0;
1428  int tile_y = 0;
1429  int val = 0;
1430 
1431  for (i = 0; i < pps->num_tile_columns; i++) {
1432  if (tb_x < pps->col_bd[i + 1]) {
1433  tile_x = i;
1434  break;
1435  }
1436  }
1437 
1438  for (i = 0; i < pps->num_tile_rows; i++) {
1439  if (tb_y < pps->row_bd[i + 1]) {
1440  tile_y = i;
1441  break;
1442  }
1443  }
1444 
1445  for (i = 0; i < tile_x; i++)
1446  val += pps->row_height[tile_y] * pps->column_width[i];
1447  for (i = 0; i < tile_y; i++)
1448  val += sps->ctb_width * pps->row_height[i];
1449 
1450  val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] +
1451  tb_x - pps->col_bd[tile_x];
1452 
1453  pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val;
1454  pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs;
1455  }
1456 
1457  for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++)
1458  for (i = 0; i < pps->num_tile_columns; i++, tile_id++)
1459  for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++)
1460  for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++)
1461  pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id;
1462 
1463  pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs));
1464  if (!pps->tile_pos_rs)
1465  return AVERROR(ENOMEM);
1466 
1467  for (j = 0; j < pps->num_tile_rows; j++)
1468  for (i = 0; i < pps->num_tile_columns; i++)
1469  pps->tile_pos_rs[j * pps->num_tile_columns + i] =
1470  pps->row_bd[j] * sps->ctb_width + pps->col_bd[i];
1471 
1472  log2_diff = sps->log2_ctb_size - sps->log2_min_tb_size;
1473  pps->min_tb_addr_zs = &pps->min_tb_addr_zs_tab[1*(sps->tb_mask+2)+1];
1474  for (y = 0; y < sps->tb_mask+2; y++) {
1475  pps->min_tb_addr_zs_tab[y*(sps->tb_mask+2)] = -1;
1476  pps->min_tb_addr_zs_tab[y] = -1;
1477  }
1478  for (y = 0; y < sps->tb_mask+1; y++) {
1479  for (x = 0; x < sps->tb_mask+1; x++) {
1480  int tb_x = x >> log2_diff;
1481  int tb_y = y >> log2_diff;
1482  int rs = sps->ctb_width * tb_y + tb_x;
1483  int val = pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2);
1484  for (i = 0; i < log2_diff; i++) {
1485  int m = 1 << i;
1486  val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
1487  }
1488  pps->min_tb_addr_zs[y * (sps->tb_mask+2) + x] = val;
1489  }
1490  }
1491 
1492  return 0;
1493 }
1494 
1496  HEVCParamSets *ps)
1497 {
1498  HEVCSPS *sps = NULL;
1499  int i, ret = 0;
1500  unsigned int pps_id = 0;
1501  ptrdiff_t nal_size;
1502  unsigned log2_parallel_merge_level_minus2;
1503 
1504  AVBufferRef *pps_buf;
1505  HEVCPPS *pps = av_mallocz(sizeof(*pps));
1506 
1507  if (!pps)
1508  return AVERROR(ENOMEM);
1509 
1510  pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps),
1511  hevc_pps_free, NULL, 0);
1512  if (!pps_buf) {
1513  av_freep(&pps);
1514  return AVERROR(ENOMEM);
1515  }
1516 
1517  av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n");
1518 
1519  nal_size = gb->buffer_end - gb->buffer;
1520  if (nal_size > sizeof(pps->data)) {
1521  av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized PPS "
1522  "(%"PTRDIFF_SPECIFIER" > %"SIZE_SPECIFIER")\n",
1523  nal_size, sizeof(pps->data));
1524  pps->data_size = sizeof(pps->data);
1525  } else {
1526  pps->data_size = nal_size;
1527  }
1528  memcpy(pps->data, gb->buffer, pps->data_size);
1529 
1530  // Default values
1532  pps->num_tile_columns = 1;
1533  pps->num_tile_rows = 1;
1534  pps->uniform_spacing_flag = 1;
1535  pps->disable_dbf = 0;
1536  pps->beta_offset = 0;
1537  pps->tc_offset = 0;
1539 
1540  // Coded parameters
1541  pps_id = get_ue_golomb_long(gb);
1542  if (pps_id >= HEVC_MAX_PPS_COUNT) {
1543  av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
1544  ret = AVERROR_INVALIDDATA;
1545  goto err;
1546  }
1547  pps->sps_id = get_ue_golomb_long(gb);
1548  if (pps->sps_id >= HEVC_MAX_SPS_COUNT) {
1549  av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id);
1550  ret = AVERROR_INVALIDDATA;
1551  goto err;
1552  }
1553  if (!ps->sps_list[pps->sps_id]) {
1554  av_log(avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id);
1555  ret = AVERROR_INVALIDDATA;
1556  goto err;
1557  }
1558  sps = (HEVCSPS *)ps->sps_list[pps->sps_id]->data;
1559 
1562  pps->num_extra_slice_header_bits = get_bits(gb, 3);
1563 
1564  pps->sign_data_hiding_flag = get_bits1(gb);
1565 
1567 
1570 
1572 
1575 
1577  pps->diff_cu_qp_delta_depth = 0;
1578  if (pps->cu_qp_delta_enabled_flag)
1580 
1581  if (pps->diff_cu_qp_delta_depth < 0 ||
1583  av_log(avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n",
1584  pps->diff_cu_qp_delta_depth);
1585  ret = AVERROR_INVALIDDATA;
1586  goto err;
1587  }
1588 
1589  pps->cb_qp_offset = get_se_golomb(gb);
1590  if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) {
1591  av_log(avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n",
1592  pps->cb_qp_offset);
1593  ret = AVERROR_INVALIDDATA;
1594  goto err;
1595  }
1596  pps->cr_qp_offset = get_se_golomb(gb);
1597  if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) {
1598  av_log(avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n",
1599  pps->cr_qp_offset);
1600  ret = AVERROR_INVALIDDATA;
1601  goto err;
1602  }
1604 
1605  pps->weighted_pred_flag = get_bits1(gb);
1606  pps->weighted_bipred_flag = get_bits1(gb);
1607 
1609  pps->tiles_enabled_flag = get_bits1(gb);
1611 
1612  if (pps->tiles_enabled_flag) {
1613  int num_tile_columns_minus1 = get_ue_golomb(gb);
1614  int num_tile_rows_minus1 = get_ue_golomb(gb);
1615 
1616  if (num_tile_columns_minus1 < 0 ||
1617  num_tile_columns_minus1 >= sps->ctb_width) {
1618  av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n",
1619  num_tile_columns_minus1);
1620  ret = num_tile_columns_minus1 < 0 ? num_tile_columns_minus1 : AVERROR_INVALIDDATA;
1621  goto err;
1622  }
1623  if (num_tile_rows_minus1 < 0 ||
1624  num_tile_rows_minus1 >= sps->ctb_height) {
1625  av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n",
1626  num_tile_rows_minus1);
1627  ret = num_tile_rows_minus1 < 0 ? num_tile_rows_minus1 : AVERROR_INVALIDDATA;
1628  goto err;
1629  }
1630  pps->num_tile_columns = num_tile_columns_minus1 + 1;
1631  pps->num_tile_rows = num_tile_rows_minus1 + 1;
1632 
1633  pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
1634  pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
1635  if (!pps->column_width || !pps->row_height) {
1636  ret = AVERROR(ENOMEM);
1637  goto err;
1638  }
1639 
1640  pps->uniform_spacing_flag = get_bits1(gb);
1641  if (!pps->uniform_spacing_flag) {
1642  uint64_t sum = 0;
1643  for (i = 0; i < pps->num_tile_columns - 1; i++) {
1644  pps->column_width[i] = get_ue_golomb_long(gb) + 1;
1645  sum += pps->column_width[i];
1646  }
1647  if (sum >= sps->ctb_width) {
1648  av_log(avctx, AV_LOG_ERROR, "Invalid tile widths.\n");
1649  ret = AVERROR_INVALIDDATA;
1650  goto err;
1651  }
1652  pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum;
1653 
1654  sum = 0;
1655  for (i = 0; i < pps->num_tile_rows - 1; i++) {
1656  pps->row_height[i] = get_ue_golomb_long(gb) + 1;
1657  sum += pps->row_height[i];
1658  }
1659  if (sum >= sps->ctb_height) {
1660  av_log(avctx, AV_LOG_ERROR, "Invalid tile heights.\n");
1661  ret = AVERROR_INVALIDDATA;
1662  goto err;
1663  }
1664  pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum;
1665  }
1667  }
1668 
1670 
1674  pps->disable_dbf = get_bits1(gb);
1675  if (!pps->disable_dbf) {
1676  int beta_offset_div2 = get_se_golomb(gb);
1677  int tc_offset_div2 = get_se_golomb(gb) ;
1678  if (beta_offset_div2 < -6 || beta_offset_div2 > 6) {
1679  av_log(avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n",
1680  beta_offset_div2);
1681  ret = AVERROR_INVALIDDATA;
1682  goto err;
1683  }
1684  if (tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1685  av_log(avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n",
1686  tc_offset_div2);
1687  ret = AVERROR_INVALIDDATA;
1688  goto err;
1689  }
1690  pps->beta_offset = 2 * beta_offset_div2;
1691  pps->tc_offset = 2 * tc_offset_div2;
1692  }
1693  }
1694 
1696  if (pps->scaling_list_data_present_flag) {
1698  ret = scaling_list_data(gb, avctx, &pps->scaling_list, sps);
1699  if (ret < 0)
1700  goto err;
1701  }
1703  log2_parallel_merge_level_minus2 = get_ue_golomb_long(gb);
1704  if (log2_parallel_merge_level_minus2 > sps->log2_ctb_size) {
1705  av_log(avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n",
1706  log2_parallel_merge_level_minus2);
1707  ret = AVERROR_INVALIDDATA;
1708  goto err;
1709  }
1710  pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2;
1711 
1713 
1714  if (get_bits1(gb)) { // pps_extension_present_flag
1716  skip_bits(gb, 7); // pps_extension_7bits
1718  if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0)
1719  goto err;
1720  }
1721  }
1722 
1723  ret = setup_pps(avctx, gb, pps, sps);
1724  if (ret < 0)
1725  goto err;
1726 
1727  if (get_bits_left(gb) < 0) {
1728  av_log(avctx, AV_LOG_ERROR,
1729  "Overread PPS by %d bits\n", -get_bits_left(gb));
1730  goto err;
1731  }
1732 
1733  remove_pps(ps, pps_id);
1734  ps->pps_list[pps_id] = pps_buf;
1735 
1736  return 0;
1737 
1738 err:
1739  av_buffer_unref(&pps_buf);
1740  return ret;
1741 }
1742 
1744 {
1745  int i;
1746 
1747  for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++)
1748  av_buffer_unref(&ps->vps_list[i]);
1749  for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++)
1750  av_buffer_unref(&ps->sps_list[i]);
1751  for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
1752  av_buffer_unref(&ps->pps_list[i]);
1753 
1754  ps->sps = NULL;
1755  ps->pps = NULL;
1756  ps->vps = NULL;
1757 }
1758 
1759 int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type)
1760 {
1761  int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
1762  int prev_poc_lsb = pocTid0 % max_poc_lsb;
1763  int prev_poc_msb = pocTid0 - prev_poc_lsb;
1764  int poc_msb;
1765 
1766  if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
1767  poc_msb = prev_poc_msb + max_poc_lsb;
1768  else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
1769  poc_msb = prev_poc_msb - max_poc_lsb;
1770  else
1771  poc_msb = prev_poc_msb;
1772 
1773  // For BLA picture types, POCmsb is set to 0.
1774  if (nal_unit_type == HEVC_NAL_BLA_W_LP ||
1775  nal_unit_type == HEVC_NAL_BLA_W_RADL ||
1776  nal_unit_type == HEVC_NAL_BLA_N_LP)
1777  poc_msb = 0;
1778 
1779  return poc_msb + poc_lsb;
1780 }
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:602
PTLCommon sub_layer_ptl[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:117
const HEVCPPS * pps
Definition: hevc_ps.h:335
#define NULL
Definition: coverity.c:32
unsigned int log2_min_cb_size
Definition: hevc_ps.h:205
int extended_precision_processing_flag
Definition: hevc_ps.h:220
uint8_t log2_sao_offset_scale_luma
Definition: hevc_ps.h:306
int min_spatial_segmentation_idc
Definition: hevc_ps.h:85
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
int ctb_height
Definition: hevc_ps.h:230
uint8_t max_12bit_constraint_flag
Definition: hevc_ps.h:101
AVBufferRef * vps_list[HEVC_MAX_VPS_COUNT]
Definition: hevc_ps.h:328
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
uint8_t diff_cu_chroma_qp_offset_depth
Definition: hevc_ps.h:302
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:241
int vui_num_ticks_poc_diff_one_minus1
Definition: hevc_ps.h:78
int max_dec_pic_buffering
Definition: hevc_ps.h:172
const char * desc
Definition: libsvtav1.c:79
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
int transform_skip_rotation_enabled_flag
Definition: hevc_ps.h:216
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
unsigned int * row_height
RowHeight.
Definition: hevc_ps.h:311
int vps_num_ticks_poc_diff_one
vps_num_ticks_poc_diff_one_minus1 + 1
Definition: hevc_ps.h:139
uint8_t max_monochrome_constraint_flag
Definition: hevc_ps.h:106
#define avpriv_request_sample(...)
int pic_init_qp_minus26
Definition: hevc_ps.h:258
unsigned int vps_max_latency_increase[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:132
VUI vui
Definition: hevc_ps.h:178
int vshift[3]
Definition: hevc_ps.h:241
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
static const uint8_t hevc_sub_width_c[]
Definition: hevc_ps.c:73
int num
Numerator.
Definition: rational.h:59
#define FF_DEBUG_BITSTREAM
Definition: avcodec.h:1614
uint32_t vui_time_scale
Definition: hevc_ps.h:76
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
uint8_t weighted_bipred_flag
Definition: hevc_ps.h:270
const uint8_t * buffer
Definition: get_bits.h:62
int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
Definition: hevc_ps.c:119
unsigned int left_offset
Definition: hevc_ps.h:43
Definition: hevc_ps.h:115
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
unsigned int vps_max_dec_pic_buffering[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:130
uint8_t seq_loop_filter_across_slices_enabled_flag
Definition: hevc_ps.h:283
uint8_t cabac_init_present_flag
Definition: hevc_ps.h:254
int chroma_loc_info_present_flag
Definition: hevc_ps.h:63
static void decode_sublayer_hrd(GetBitContext *gb, unsigned int nb_cpb, int subpic_params_present)
Definition: hevc_ps.c:379
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
int max_latency_increase
Definition: hevc_ps.h:174
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS]
Definition: hevc_ps.h:192
ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_REF_PIC_SETS]
Definition: hevc_ps.h:185
int min_cb_height
Definition: hevc_ps.h:233
int * ctb_addr_ts_to_rs
CtbAddrTSToRS.
Definition: hevc_ps.h:317
int explicit_rdpcm_enabled_flag
Definition: hevc_ps.h:219
int num_ref_idx_l0_default_active
num_ref_idx_l0_default_active_minus1 + 1
Definition: hevc_ps.h:256
static const AVRational vui_sar[]
Definition: hevc_ps.c:53
uint8_t max_420chroma_constraint_flag
Definition: hevc_ps.h:105
int8_t cr_qp_offset_list[6]
Definition: hevc_ps.h:305
uint8_t one_picture_only_constraint_flag
Definition: hevc_ps.h:108
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:513
int chroma_sample_loc_type_top_field
Definition: hevc_ps.h:64
int width
Definition: hevc_ps.h:227
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2966
int qp_bd_offset
Definition: hevc_ps.h:243
int pixel_shift
Definition: hevc_ps.h:164
uint8_t entropy_coding_sync_enabled_flag
Definition: hevc_ps.h:276
HEVCWindow output_window
Definition: hevc_ps.h:158
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
int log2_parallel_merge_level
log2_parallel_merge_level_minus2 + 2
Definition: hevc_ps.h:295
uint8_t log2_sao_offset_scale_chroma
Definition: hevc_ps.h:307
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
int restricted_ref_pic_lists_flag
Definition: hevc_ps.h:84
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static void remove_vps(HEVCParamSets *s, int id)
Definition: hevc_ps.c:105
int chroma_format_idc
Definition: hevc_ps.h:155
uint8_t disable_dbf
Definition: hevc_ps.h:287
unsigned int log2_max_trafo_size
Definition: hevc_ps.h:208
AVBufferRef * sps_list[HEVC_MAX_SPS_COUNT]
Definition: hevc_ps.h:329
uint8_t profile_compatibility_flag[32]
Definition: hevc_ps.h:96
Definition: hevc_ps.h:49
static int decode_hrd(GetBitContext *gb, int common_inf_present, int max_sublayers)
Definition: hevc_ps.c:396
unsigned int num_negative_pics
Definition: hevc_ps.h:35
uint8_t
static void remove_pps(HEVCParamSets *s, int id)
Definition: hevc_ps.c:81
static const uint8_t default_scaling_list_inter[]
Definition: hevc_ps.c:42
float delta
HEVCWindow pic_conf_win
Definition: hevc_ps.h:160
uint8_t log2_max_transform_skip_block_size
Definition: hevc_ps.h:298
int overscan_info_present_flag
Definition: hevc_ps.h:52
uint8_t vps_timing_info_present_flag
Definition: hevc_ps.h:135
uint8_t matrix_coeffs
Definition: hevc_ps.h:61
int min_tb_width
Definition: hevc_ps.h:234
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:1947
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: hevc_data.c:39
int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx)
Parse the SPS from the bitstream into the provided HEVCSPS struct.
Definition: hevc_ps.c:904
const HEVCVPS * vps
Definition: hevc_ps.h:333
int num_ref_idx_l1_default_active
num_ref_idx_l1_default_active_minus1 + 1
Definition: hevc_ps.h:257
unsigned int log2_min_pcm_cb_size
Definition: hevc_ps.h:198
int min_cb_width
Definition: hevc_ps.h:232
int vps_max_sub_layers
vps_max_temporal_layers_minus1 + 1
Definition: hevc_ps.h:126
int frame_field_info_present_flag
Definition: hevc_ps.h:69
uint8_t tier_flag
Definition: hevc_ps.h:94
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
uint8_t scaling_list_data_present_flag
Definition: hevc_ps.h:291
int high_precision_offsets_enabled_flag
Definition: hevc_ps.h:222
AVBufferRef * pps_list[HEVC_MAX_PPS_COUNT]
Definition: hevc_ps.h:330
uint8_t loop_filter_disable_flag
Definition: hevc_ps.h:200
static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps)
Definition: hevc_ps.c:855
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:1948
int8_t cb_qp_offset_list[6]
Definition: hevc_ps.h:304
int bitstream_restriction_flag
Definition: hevc_ps.h:81
uint8_t transquant_bypass_enable_flag
Definition: hevc_ps.h:272
#define av_log(a,...)
uint8_t intra_constraint_flag
Definition: hevc_ps.h:107
int bit_depth_chroma
Definition: hevc_ps.h:163
int vps_max_layer_id
Definition: hevc_ps.h:133
#define U(x)
Definition: vp56_arith.h:37
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
uint8_t frame_only_constraint_flag
Definition: hevc_ps.h:100
#define AV_CODEC_FLAG2_IGNORE_CROP
Discard cropping information from SPS.
Definition: avcodec.h:371
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:55
unsigned int log2_max_poc_lsb
Definition: hevc_ps.h:167
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
int vps_max_layers
Definition: hevc_ps.h:125
int min_pu_height
Definition: hevc_ps.h:237
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:1759
#define PTRDIFF_SPECIFIER
Definition: internal.h:228
int persistent_rice_adaptation_enabled_flag
Definition: hevc_ps.h:223
uint8_t temporal_id_nesting_flag
Definition: hevc_ps.h:176
int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: hevc_ps.c:458
int data_size
Definition: hevc_ps.h:324
int vui_timing_info_present_flag
Definition: hevc_ps.h:74
uint8_t amp_enabled_flag
Definition: hevc_ps.h:187
unsigned int pos
Definition: spdifenc.c:410
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
unsigned int log2_ctb_size
Definition: hevc_ps.h:209
#define check_profile_idc(idc)
int vui_poc_proportional_to_timing_flag
Definition: hevc_ps.h:77
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:29
uint8_t lower_bit_rate_constraint_flag
Definition: hevc_ps.h:109
uint8_t vps_temporal_id_nesting_flag
Definition: hevc_ps.h:124
uint8_t pps_range_extensions_flag
Definition: hevc_ps.h:299
#define FFMAX(a, b)
Definition: common.h:94
uint8_t colour_primaries
Definition: hevc_ps.h:59
uint8_t used[32]
Definition: hevc_ps.h:39
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2918
int motion_vectors_over_pic_boundaries_flag
Definition: hevc_ps.h:83
uint8_t tiles_enabled_flag
Definition: hevc_ps.h:275
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
uint32_t vps_num_units_in_tick
Definition: hevc_ps.h:136
int * col_idxX
Definition: hevc_ps.h:314
uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:120
struct HEVCSPS::@76 pcm
const HEVCSPS * sps
Definition: hevc_ps.h:334
int vps_num_layer_sets
vps_num_layer_sets_minus1 + 1
Definition: hevc_ps.h:134
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
uint8_t lists_modification_present_flag
Definition: hevc_ps.h:294
int * min_tb_addr_zs_tab
MinTbAddrZS.
Definition: hevc_ps.h:321
uint8_t profile_idc
Definition: hevc_ps.h:95
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:317
static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps, HEVCSPS *sps)
Definition: hevc_ps.c:1322
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1655
int max_transform_hierarchy_depth_inter
Definition: hevc_ps.h:212
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
uint8_t vps_poc_proportional_to_timing_flag
Definition: hevc_ps.h:138
struct HEVCSPS::@75 temporal_layer[HEVC_MAX_SUB_LAYERS]
unsigned int top_offset
Definition: hevc_ps.h:45
int hshift[3]
Definition: hevc_ps.h:240
unsigned int vps_num_reorder_pics[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:131
#define FF_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: avcodec.h:1949
int32_t
int max_bits_per_min_cu_denom
Definition: hevc_ps.h:87
uint8_t cu_qp_delta_enabled_flag
Definition: hevc_ps.h:263
#define s(width, name)
Definition: cbs_vp9.c:257
int ctb_width
Definition: hevc_ps.h:229
uint8_t sl_dc[2][6]
Definition: hevc_ps.h:150
int32_t delta_poc[32]
Definition: hevc_ps.h:38
uint8_t sign_data_hiding_flag
Definition: hevc_ps.h:252
int height
Definition: hevc_ps.h:228
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1666
uint8_t output_flag_present_flag
Definition: hevc_ps.h:271
int log2_max_mv_length_vertical
Definition: hevc_ps.h:89
int data_size
Definition: hevc_ps.h:143
PTLCommon general_ptl
Definition: hevc_ps.h:116
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: hevc_data.c:32
uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:119
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
int max_bytes_per_pic_denom
Definition: hevc_ps.h:86
int overscan_appropriate_flag
Definition: hevc_ps.h:53
static void set_default_scaling_list_data(ScalingList *sl)
Definition: hevc_ps.c:753
int implicit_rdpcm_enabled_flag
Definition: hevc_ps.h:218
unsigned vps_id
Definition: hevc_ps.h:154
#define FF_ARRAY_ELEMS(a)
uint8_t constrained_intra_pred_flag
Definition: hevc_ps.h:260
int tb_mask
Definition: hevc_ps.h:238
uint8_t sl[4][6][64]
Definition: hevc_ps.h:149
PTL ptl
Definition: hevc_ps.h:128
uint8_t pic_slice_level_chroma_qp_offsets_present_flag
Definition: hevc_ps.h:268
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:106
uint32_t vps_time_scale
Definition: hevc_ps.h:137
int colour_description_present_flag
Definition: hevc_ps.h:58
void ff_hevc_ps_uninit(HEVCParamSets *ps)
Definition: hevc_ps.c:1743
enum AVPixelFormat pix_fmt
Definition: hevc_ps.h:165
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:296
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
uint8_t transform_skip_enabled_flag
Definition: hevc_ps.h:261
uint16_t num_tile_columns
num_tile_columns_minus1 + 1
Definition: hevc_ps.h:278
uint8_t uniform_spacing_flag
Definition: hevc_ps.h:280
int ctb_size
Definition: hevc_ps.h:231
static void decode_vui(GetBitContext *gb, AVCodecContext *avctx, int apply_defdispwin, HEVCSPS *sps)
Definition: hevc_ps.c:588
int * ctb_addr_rs_to_ts
CtbAddrRSToTS.
Definition: hevc_ps.h:316
PTL ptl
Definition: hevc_ps.h:179
int max_sub_layers
Definition: hevc_ps.h:170
unsigned int log2_min_pu_size
Definition: hevc_ps.h:210
unsigned int sps_id
seq_parameter_set_id
Definition: hevc_ps.h:250
int debug
debug
Definition: avcodec.h:1611
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
ScalingList scaling_list
Definition: hevc_ps.h:292
main external API structure.
Definition: avcodec.h:526
static int parse_ptl(GetBitContext *gb, AVCodecContext *avctx, PTL *ptl, int max_num_sub_layers)
Definition: hevc_ps.c:339
int log2_max_mv_length_horizontal
Definition: hevc_ps.h:88
uint8_t sao_enabled
Definition: hevc_ps.h:188
int num_extra_slice_header_bits
Definition: hevc_ps.h:296
uint8_t * data
The data buffer.
Definition: buffer.h:89
uint8_t loop_filter_across_tiles_enabled_flag
Definition: hevc_ps.h:281
uint8_t max_10bit_constraint_flag
Definition: hevc_ps.h:102
uint8_t num_long_term_ref_pics_sps
Definition: hevc_ps.h:193
uint8_t cross_component_prediction_enabled_flag
Definition: hevc_ps.h:300
uint32_t vui_num_units_in_tick
Definition: hevc_ps.h:75
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
uint8_t deblocking_filter_control_present_flag
Definition: hevc_ps.h:285
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
int transform_skip_context_enabled_flag
Definition: hevc_ps.h:217
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:538
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
uint8_t sps_temporal_mvp_enabled_flag
Definition: hevc_ps.h:202
unsigned int nb_st_rps
Definition: hevc_ps.h:184
int chroma_sample_loc_type_bottom_field
Definition: hevc_ps.h:65
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
uint8_t chroma_qp_offset_list_enabled_flag
Definition: hevc_ps.h:301
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int vps_num_hrd_parameters
Definition: hevc_ps.h:140
static void hevc_pps_free(void *opaque, uint8_t *data)
Definition: hevc_ps.c:1304
unsigned int log2_min_tb_size
Definition: hevc_ps.h:207
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: hevc_ps.c:1495
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
static const uint8_t hevc_sub_height_c[]
Definition: hevc_ps.c:77
int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps, int apply_defdispwin)
Definition: hevc_ps.c:1246
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:546
uint8_t scaling_list_enable_flag
Definition: hevc_ps.h:181
int * tile_id
TileId.
Definition: hevc_ps.h:318
static const uint8_t default_scaling_list_intra[]
Definition: hevc_ps.c:31
int tc_offset
tc_offset_div2 * 2
Definition: hevc_ps.h:289
uint8_t transfer_characteristic
Definition: hevc_ps.h:60
int default_display_window_flag
Definition: hevc_ps.h:71
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
int size
Size of data in bytes.
Definition: buffer.h:93
HEVCWindow def_disp_win
Definition: hevc_ps.h:72
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
int cr_qp_offset
Definition: hevc_ps.h:267
ScalingList scaling_list
Definition: hevc_ps.h:182
#define SIZE_SPECIFIER
Definition: internal.h:229
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
unsigned int log2_diff_max_min_coding_block_size
Definition: hevc_ps.h:206
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, ScalingList *sl, HEVCSPS *sps)
Definition: hevc_ps.c:783
unsigned int log2_max_pcm_cb_size
Definition: hevc_ps.h:199
static int setup_pps(AVCodecContext *avctx, GetBitContext *gb, HEVCPPS *pps, HEVCSPS *sps)
Definition: hevc_ps.c:1363
uint8_t level_idc
Definition: hevc_ps.h:112
int neutra_chroma_indication_flag
Definition: hevc_ps.h:66
int * tile_pos_rs
TilePosRS.
Definition: hevc_ps.h:319
static int FUNC() timing_info(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTimingInfo *current)
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: hevc_data.c:25
int data_size
Definition: hevc_ps.h:246
A reference to a data buffer.
Definition: buffer.h:81
int max_transform_hierarchy_depth_intra
Definition: hevc_ps.h:213
uint8_t profile_space
Definition: hevc_ps.h:93
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
unsigned int * row_bd
RowBd.
Definition: hevc_ps.h:313
uint16_t lt_ref_pic_poc_lsb_sps[HEVC_MAX_LONG_TERM_REF_PICS]
Definition: hevc_ps.h:191
int video_format
Definition: hevc_ps.h:56
uint8_t weighted_pred_flag
Definition: hevc_ps.h:269
uint8_t data[4096]
Definition: hevc_ps.h:142
uint16_t num_tile_rows
num_tile_rows_minus1 + 1
Definition: hevc_ps.h:279
unsigned int * col_bd
ColBd.
Definition: hevc_ps.h:312
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:2942
const uint8_t * buffer_end
Definition: get_bits.h:62
unsigned int * column_width
ColumnWidth.
Definition: hevc_ps.h:310
uint8_t slice_header_extension_present_flag
Definition: hevc_ps.h:297
static int decode_profile_tier_level(GetBitContext *gb, AVCodecContext *avctx, PTLCommon *ptl)
Definition: hevc_ps.c:265
int den
Denominator.
Definition: rational.h:60
int video_full_range_flag
Definition: hevc_ps.h:57
int cabac_bypass_alignment_enabled_flag
coded frame dimension in various units
Definition: hevc_ps.h:224
AVRational sar
Definition: hevc_ps.h:50
uint8_t chroma_qp_offset_list_len_minus1
Definition: hevc_ps.h:303
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: hevc_data.c:58
int num_delta_pocs
Definition: hevc_ps.h:36
#define FF_PROFILE_HEVC_REXT
Definition: avcodec.h:1950
uint8_t sps_strong_intra_smoothing_enable_flag
Definition: hevc_ps.h:203
int rps_idx_num_delta_pocs
Definition: hevc_ps.h:37
uint8_t data[4096]
Definition: hevc_ps.h:245
int min_pu_width
Definition: hevc_ps.h:236
uint8_t max_422chroma_constraint_flag
Definition: hevc_ps.h:104
int sps_range_extension_flag
Definition: hevc_ps.h:215
uint8_t max_8bit_constraint_flag
Definition: hevc_ps.h:103
uint8_t long_term_ref_pics_present_flag
Definition: hevc_ps.h:190
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:613
uint8_t max_14bit_constraint_flag
Definition: hevc_ps.h:110
int vui_hrd_parameters_present_flag
Definition: hevc_ps.h:79
unsigned int right_offset
Definition: hevc_ps.h:44
int diff_cu_qp_delta_depth
Definition: hevc_ps.h:264
#define av_freep(p)
int num_reorder_pics
Definition: hevc_ps.h:173
static void remove_sps(HEVCParamSets *s, int id)
Definition: hevc_ps.c:88
uint8_t progressive_source_flag
Definition: hevc_ps.h:97
int cb_qp_offset
Definition: hevc_ps.h:266
#define av_malloc_array(a, b)
int video_signal_type_present_flag
Definition: hevc_ps.h:55
uint8_t deblocking_filter_override_enabled_flag
Definition: hevc_ps.h:286
int bit_depth
Definition: hevc_ps.h:162
int beta_offset
beta_offset_div2 * 2
Definition: hevc_ps.h:288
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:2489
int min_tb_height
Definition: hevc_ps.h:235
int * min_tb_addr_zs
MinTbAddrZS.
Definition: hevc_ps.h:320
uint8_t inbld_flag
Definition: hevc_ps.h:111
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
uint8_t non_packed_constraint_flag
Definition: hevc_ps.h:99
int intra_smoothing_disabled_flag
Definition: hevc_ps.h:221
exp golomb vlc stuff
int pcm_enabled_flag
Definition: hevc_ps.h:168
enum AVCodecID id
int tiles_fixed_structure_flag
Definition: hevc_ps.h:82
static double val(void *priv, double ch)
Definition: aeval.c:76
uint8_t interlaced_source_flag
Definition: hevc_ps.h:98
int field_seq_flag
Definition: hevc_ps.h:68
for(j=16;j >0;--j)
uint8_t separate_colour_plane_flag
Definition: hevc_ps.h:156
int i
Definition: input.c:407
unsigned int bottom_offset
Definition: hevc_ps.h:46
int vps_sub_layer_ordering_info_present_flag
Definition: hevc_ps.h:129
uint8_t data[4096]
Definition: hevc_ps.h:323
uint8_t dependent_slice_segments_enabled_flag
Definition: hevc_ps.h:274
static uint8_t tmp[11]
Definition: aes_ctr.c:26