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