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