FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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.h"
29 
31  16, 16, 16, 16, 17, 18, 21, 24,
32  16, 16, 16, 16, 17, 19, 22, 25,
33  16, 16, 17, 18, 20, 22, 25, 29,
34  16, 16, 18, 21, 24, 27, 31, 36,
35  17, 17, 20, 24, 30, 35, 41, 47,
36  18, 19, 22, 27, 35, 44, 54, 65,
37  21, 22, 25, 31, 41, 54, 70, 88,
38  24, 25, 29, 36, 47, 65, 88, 115
39 };
40 
42  16, 16, 16, 16, 17, 18, 20, 24,
43  16, 16, 16, 17, 18, 20, 24, 25,
44  16, 16, 17, 18, 20, 24, 25, 28,
45  16, 17, 18, 20, 24, 25, 28, 33,
46  17, 18, 20, 24, 25, 28, 33, 41,
47  18, 20, 24, 25, 28, 33, 41, 54,
48  20, 24, 25, 28, 33, 41, 54, 71,
49  24, 25, 28, 33, 41, 54, 71, 91
50 };
51 
52 static const AVRational vui_sar[] = {
53  { 0, 1 },
54  { 1, 1 },
55  { 12, 11 },
56  { 10, 11 },
57  { 16, 11 },
58  { 40, 33 },
59  { 24, 11 },
60  { 20, 11 },
61  { 32, 11 },
62  { 80, 33 },
63  { 18, 11 },
64  { 15, 11 },
65  { 64, 33 },
66  { 160, 99 },
67  { 4, 3 },
68  { 3, 2 },
69  { 2, 1 },
70 };
71 
72 static void remove_pps(HEVCContext *s, int id)
73 {
74  if (s->pps_list[id] && s->pps == (const HEVCPPS*)s->pps_list[id]->data)
75  s->pps = NULL;
76  av_buffer_unref(&s->pps_list[id]);
77 }
78 
79 static void remove_sps(HEVCContext *s, int id)
80 {
81  int i;
82  if (s->sps_list[id]) {
83  if (s->sps == (const HEVCSPS*)s->sps_list[id]->data)
84  s->sps = NULL;
85 
86  /* drop all PPS that depend on this SPS */
87  for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
88  if (s->pps_list[i] && ((HEVCPPS*)s->pps_list[i]->data)->sps_id == id)
89  remove_pps(s, i);
90 
91  av_assert0(!(s->sps_list[id] && s->sps == (HEVCSPS*)s->sps_list[id]->data));
92  }
93  av_buffer_unref(&s->sps_list[id]);
94 }
95 
96 static void remove_vps(HEVCContext *s, int id)
97 {
98  int i;
99  if (s->vps_list[id]) {
100  if (s->vps == (const HEVCVPS*)s->vps_list[id]->data)
101  s->vps = NULL;
102 
103  for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)
104  if (s->sps_list[i] && ((HEVCSPS*)s->sps_list[i]->data)->vps_id == id)
105  remove_sps(s, i);
106  }
107  av_buffer_unref(&s->vps_list[id]);
108 }
109 
111  const HEVCSPS *sps, int is_slice_header)
112 {
113  HEVCLocalContext *lc = s->HEVClc;
114  uint8_t rps_predict = 0;
115  int delta_poc;
116  int k0 = 0;
117  int k1 = 0;
118  int k = 0;
119  int i;
120 
121  GetBitContext *gb = &lc->gb;
122 
123  if (rps != sps->st_rps && sps->nb_st_rps)
124  rps_predict = get_bits1(gb);
125 
126  if (rps_predict) {
127  const ShortTermRPS *rps_ridx;
128  int delta_rps;
129  unsigned abs_delta_rps;
130  uint8_t use_delta_flag = 0;
131  uint8_t delta_rps_sign;
132 
133  if (is_slice_header) {
134  unsigned int delta_idx = get_ue_golomb_long(gb) + 1;
135  if (delta_idx > sps->nb_st_rps) {
137  "Invalid value of delta_idx in slice header RPS: %d > %d.\n",
138  delta_idx, sps->nb_st_rps);
139  return AVERROR_INVALIDDATA;
140  }
141  rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx];
142  } else
143  rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];
144 
145  delta_rps_sign = get_bits1(gb);
146  abs_delta_rps = get_ue_golomb_long(gb) + 1;
147  if (abs_delta_rps < 1 || abs_delta_rps > 32768) {
149  "Invalid value of abs_delta_rps: %d\n",
150  abs_delta_rps);
151  return AVERROR_INVALIDDATA;
152  }
153  delta_rps = (1 - (delta_rps_sign << 1)) * abs_delta_rps;
154  for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {
155  int used = rps->used[k] = get_bits1(gb);
156 
157  if (!used)
158  use_delta_flag = get_bits1(gb);
159 
160  if (used || use_delta_flag) {
161  if (i < rps_ridx->num_delta_pocs)
162  delta_poc = delta_rps + rps_ridx->delta_poc[i];
163  else
164  delta_poc = delta_rps;
165  rps->delta_poc[k] = delta_poc;
166  if (delta_poc < 0)
167  k0++;
168  else
169  k1++;
170  k++;
171  }
172  }
173 
174  rps->num_delta_pocs = k;
175  rps->num_negative_pics = k0;
176  // sort in increasing order (smallest first)
177  if (rps->num_delta_pocs != 0) {
178  int used, tmp;
179  for (i = 1; i < rps->num_delta_pocs; i++) {
180  delta_poc = rps->delta_poc[i];
181  used = rps->used[i];
182  for (k = i - 1; k >= 0; k--) {
183  tmp = rps->delta_poc[k];
184  if (delta_poc < tmp) {
185  rps->delta_poc[k + 1] = tmp;
186  rps->used[k + 1] = rps->used[k];
187  rps->delta_poc[k] = delta_poc;
188  rps->used[k] = used;
189  }
190  }
191  }
192  }
193  if ((rps->num_negative_pics >> 1) != 0) {
194  int used;
195  k = rps->num_negative_pics - 1;
196  // flip the negative values to largest first
197  for (i = 0; i < rps->num_negative_pics >> 1; i++) {
198  delta_poc = rps->delta_poc[i];
199  used = rps->used[i];
200  rps->delta_poc[i] = rps->delta_poc[k];
201  rps->used[i] = rps->used[k];
202  rps->delta_poc[k] = delta_poc;
203  rps->used[k] = used;
204  k--;
205  }
206  }
207  } else {
208  unsigned int prev, nb_positive_pics;
210  nb_positive_pics = get_ue_golomb_long(gb);
211 
212  if (rps->num_negative_pics >= MAX_REFS ||
213  nb_positive_pics >= MAX_REFS) {
214  av_log(s->avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n");
215  return AVERROR_INVALIDDATA;
216  }
217 
218  rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics;
219  if (rps->num_delta_pocs) {
220  prev = 0;
221  for (i = 0; i < rps->num_negative_pics; i++) {
222  delta_poc = get_ue_golomb_long(gb) + 1;
223  prev -= delta_poc;
224  rps->delta_poc[i] = prev;
225  rps->used[i] = get_bits1(gb);
226  }
227  prev = 0;
228  for (i = 0; i < nb_positive_pics; i++) {
229  delta_poc = get_ue_golomb_long(gb) + 1;
230  prev += delta_poc;
231  rps->delta_poc[rps->num_negative_pics + i] = prev;
232  rps->used[rps->num_negative_pics + i] = get_bits1(gb);
233  }
234  }
235  }
236  return 0;
237 }
238 
239 
241 {
242  int i;
243  HEVCLocalContext *lc = s->HEVClc;
244  GetBitContext *gb = &lc->gb;
245 
246  if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 16 + 16 + 12)
247  return -1;
248 
249  ptl->profile_space = get_bits(gb, 2);
250  ptl->tier_flag = get_bits1(gb);
251  ptl->profile_idc = get_bits(gb, 5);
252  if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN)
253  av_log(s->avctx, AV_LOG_DEBUG, "Main profile bitstream\n");
254  else if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN_10)
255  av_log(s->avctx, AV_LOG_DEBUG, "Main 10 profile bitstream\n");
257  av_log(s->avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n");
258  else if (ptl->profile_idc == FF_PROFILE_HEVC_REXT)
259  av_log(s->avctx, AV_LOG_DEBUG, "Range Extension profile bitstream\n");
260  else
261  av_log(s->avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", ptl->profile_idc);
262 
263  for (i = 0; i < 32; i++)
269 
270  skip_bits(gb, 16); // XXX_reserved_zero_44bits[0..15]
271  skip_bits(gb, 16); // XXX_reserved_zero_44bits[16..31]
272  skip_bits(gb, 12); // XXX_reserved_zero_44bits[32..43]
273 
274  return 0;
275 }
276 
277 static int parse_ptl(HEVCContext *s, PTL *ptl, int max_num_sub_layers)
278 {
279  int i;
280  HEVCLocalContext *lc = s->HEVClc;
281  GetBitContext *gb = &lc->gb;
282  if (decode_profile_tier_level(s, &ptl->general_ptl) < 0 ||
283  get_bits_left(gb) < 8 + 8*2) {
284  av_log(s->avctx, AV_LOG_ERROR, "PTL information too short\n");
285  return -1;
286  }
287 
288  ptl->general_ptl.level_idc = get_bits(gb, 8);
289 
290  for (i = 0; i < max_num_sub_layers - 1; i++) {
293  }
294 
295  if (max_num_sub_layers - 1> 0)
296  for (i = max_num_sub_layers - 1; i < 8; i++)
297  skip_bits(gb, 2); // reserved_zero_2bits[i]
298  for (i = 0; i < max_num_sub_layers - 1; i++) {
299  if (ptl->sub_layer_profile_present_flag[i] &&
300  decode_profile_tier_level(s, &ptl->sub_layer_ptl[i]) < 0) {
302  "PTL information for sublayer %i too short\n", i);
303  return -1;
304  }
305  if (ptl->sub_layer_level_present_flag[i]) {
306  if (get_bits_left(gb) < 8) {
308  "Not enough data for sublayer %i level_idc\n", i);
309  return -1;
310  } else
311  ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8);
312  }
313  }
314 
315  return 0;
316 }
317 
318 static void decode_sublayer_hrd(HEVCContext *s, unsigned int nb_cpb,
319  int subpic_params_present)
320 {
321  GetBitContext *gb = &s->HEVClc->gb;
322  int i;
323 
324  for (i = 0; i < nb_cpb; i++) {
325  get_ue_golomb_long(gb); // bit_rate_value_minus1
326  get_ue_golomb_long(gb); // cpb_size_value_minus1
327 
328  if (subpic_params_present) {
329  get_ue_golomb_long(gb); // cpb_size_du_value_minus1
330  get_ue_golomb_long(gb); // bit_rate_du_value_minus1
331  }
332  skip_bits1(gb); // cbr_flag
333  }
334 }
335 
336 static int decode_hrd(HEVCContext *s, int common_inf_present,
337  int max_sublayers)
338 {
339  GetBitContext *gb = &s->HEVClc->gb;
340  int nal_params_present = 0, vcl_params_present = 0;
341  int subpic_params_present = 0;
342  int i;
343 
344  if (common_inf_present) {
345  nal_params_present = get_bits1(gb);
346  vcl_params_present = get_bits1(gb);
347 
348  if (nal_params_present || vcl_params_present) {
349  subpic_params_present = get_bits1(gb);
350 
351  if (subpic_params_present) {
352  skip_bits(gb, 8); // tick_divisor_minus2
353  skip_bits(gb, 5); // du_cpb_removal_delay_increment_length_minus1
354  skip_bits(gb, 1); // sub_pic_cpb_params_in_pic_timing_sei_flag
355  skip_bits(gb, 5); // dpb_output_delay_du_length_minus1
356  }
357 
358  skip_bits(gb, 4); // bit_rate_scale
359  skip_bits(gb, 4); // cpb_size_scale
360 
361  if (subpic_params_present)
362  skip_bits(gb, 4); // cpb_size_du_scale
363 
364  skip_bits(gb, 5); // initial_cpb_removal_delay_length_minus1
365  skip_bits(gb, 5); // au_cpb_removal_delay_length_minus1
366  skip_bits(gb, 5); // dpb_output_delay_length_minus1
367  }
368  }
369 
370  for (i = 0; i < max_sublayers; i++) {
371  int low_delay = 0;
372  unsigned int nb_cpb = 1;
373  int fixed_rate = get_bits1(gb);
374 
375  if (!fixed_rate)
376  fixed_rate = get_bits1(gb);
377 
378  if (fixed_rate)
379  get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1
380  else
381  low_delay = get_bits1(gb);
382 
383  if (!low_delay) {
384  nb_cpb = get_ue_golomb_long(gb) + 1;
385  if (nb_cpb < 1 || nb_cpb > 32) {
386  av_log(s->avctx, AV_LOG_ERROR, "nb_cpb %d invalid\n", nb_cpb);
387  return AVERROR_INVALIDDATA;
388  }
389  }
390 
391  if (nal_params_present)
392  decode_sublayer_hrd(s, nb_cpb, subpic_params_present);
393  if (vcl_params_present)
394  decode_sublayer_hrd(s, nb_cpb, subpic_params_present);
395  }
396  return 0;
397 }
398 
400 {
401  int i,j;
402  GetBitContext *gb = &s->HEVClc->gb;
403  int vps_id = 0;
404  HEVCVPS *vps;
405  AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps));
406 
407  if (!vps_buf)
408  return AVERROR(ENOMEM);
409  vps = (HEVCVPS*)vps_buf->data;
410 
411  av_log(s->avctx, AV_LOG_DEBUG, "Decoding VPS\n");
412 
413  vps_id = get_bits(gb, 4);
414  if (vps_id >= MAX_VPS_COUNT) {
415  av_log(s->avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id);
416  goto err;
417  }
418 
419  if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits
420  av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
421  goto err;
422  }
423 
424  vps->vps_max_layers = get_bits(gb, 6) + 1;
425  vps->vps_max_sub_layers = get_bits(gb, 3) + 1;
427 
428  if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits
429  av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n");
430  goto err;
431  }
432 
433  if (vps->vps_max_sub_layers > MAX_SUB_LAYERS) {
434  av_log(s->avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n",
435  vps->vps_max_sub_layers);
436  goto err;
437  }
438 
439  if (parse_ptl(s, &vps->ptl, vps->vps_max_sub_layers) < 0)
440  goto err;
441 
443 
445  for (; i < vps->vps_max_sub_layers; i++) {
449 
451  av_log(s->avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n",
452  vps->vps_max_dec_pic_buffering[i] - 1);
453  goto err;
454  }
455  if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) {
456  av_log(s->avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n",
457  vps->vps_num_reorder_pics[i]);
459  goto err;
460  }
461  }
462 
463  vps->vps_max_layer_id = get_bits(gb, 6);
464  vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1;
465  if (vps->vps_num_layer_sets < 1 || vps->vps_num_layer_sets > 1024 ||
466  (vps->vps_num_layer_sets - 1LL) * (vps->vps_max_layer_id + 1LL) > get_bits_left(gb)) {
467  av_log(s->avctx, AV_LOG_ERROR, "too many layer_id_included_flags\n");
468  goto err;
469  }
470 
471  for (i = 1; i < vps->vps_num_layer_sets; i++)
472  for (j = 0; j <= vps->vps_max_layer_id; j++)
473  skip_bits(gb, 1); // layer_id_included_flag[i][j]
474 
476  if (vps->vps_timing_info_present_flag) {
477  vps->vps_num_units_in_tick = get_bits_long(gb, 32);
478  vps->vps_time_scale = get_bits_long(gb, 32);
483  if (vps->vps_num_hrd_parameters > (unsigned)vps->vps_num_layer_sets) {
485  "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters);
486  goto err;
487  }
488  for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
489  int common_inf_present = 1;
490 
491  get_ue_golomb_long(gb); // hrd_layer_set_idx
492  if (i)
493  common_inf_present = get_bits1(gb);
494  decode_hrd(s, common_inf_present, vps->vps_max_sub_layers);
495  }
496  }
497  get_bits1(gb); /* vps_extension_flag */
498 
499  if (get_bits_left(gb) < 0) {
501  "Overread VPS by %d bits\n", -get_bits_left(gb));
502  goto err;
503  }
504 
505  if (s->vps_list[vps_id] &&
506  !memcmp(s->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) {
507  av_buffer_unref(&vps_buf);
508  } else {
509  remove_vps(s, vps_id);
510  s->vps_list[vps_id] = vps_buf;
511  }
512 
513  return 0;
514 
515 err:
516  av_buffer_unref(&vps_buf);
517  return AVERROR_INVALIDDATA;
518 }
519 
520 static void decode_vui(HEVCContext *s, HEVCSPS *sps)
521 {
522  VUI *vui = &sps->vui;
523  GetBitContext *gb = &s->HEVClc->gb;
524  GetBitContext backup;
525  int sar_present, alt = 0;
526 
527  av_log(s->avctx, AV_LOG_DEBUG, "Decoding VUI\n");
528 
529  sar_present = get_bits1(gb);
530  if (sar_present) {
531  uint8_t sar_idx = get_bits(gb, 8);
532  if (sar_idx < FF_ARRAY_ELEMS(vui_sar))
533  vui->sar = vui_sar[sar_idx];
534  else if (sar_idx == 255) {
535  vui->sar.num = get_bits(gb, 16);
536  vui->sar.den = get_bits(gb, 16);
537  } else
539  "Unknown SAR index: %u.\n", sar_idx);
540  }
541 
545 
548  vui->video_format = get_bits(gb, 3);
549  vui->video_full_range_flag = get_bits1(gb);
554  vui->colour_primaries = get_bits(gb, 8);
555  vui->transfer_characteristic = get_bits(gb, 8);
556  vui->matrix_coeffs = get_bits(gb, 8);
557 
558  // Set invalid values to "unspecified"
559  if (vui->colour_primaries >= AVCOL_PRI_NB)
563  if (vui->matrix_coeffs >= AVCOL_SPC_NB)
565  }
566  }
567 
569  if (vui->chroma_loc_info_present_flag) {
572  }
573 
575  vui->field_seq_flag = get_bits1(gb);
577 
578  if (get_bits_left(gb) >= 68 && show_bits_long(gb, 21) == 0x100000) {
580  av_log(s->avctx, AV_LOG_WARNING, "Invalid default display window\n");
581  } else
583  // Backup context in case an alternate header is detected
584  memcpy(&backup, gb, sizeof(backup));
585 
586  if (vui->default_display_window_flag) {
587  //TODO: * 2 is only valid for 420
592 
593  if (s->apply_defdispwin &&
596  "discarding vui default display window, "
597  "original values are l:%u r:%u t:%u b:%u\n",
602 
605  vui->def_disp_win.top_offset =
606  vui->def_disp_win.bottom_offset = 0;
607  }
608  }
609 
611 
612  if (vui->vui_timing_info_present_flag) {
613  if( get_bits_left(gb) < 66) {
614  // The alternate syntax seem to have timing info located
615  // at where def_disp_win is normally located
617  "Strange VUI timing information, retrying...\n");
619  memset(&vui->def_disp_win, 0, sizeof(vui->def_disp_win));
620  memcpy(gb, &backup, sizeof(backup));
621  alt = 1;
622  }
623  vui->vui_num_units_in_tick = get_bits_long(gb, 32);
624  vui->vui_time_scale = get_bits_long(gb, 32);
625  if (alt) {
626  av_log(s->avctx, AV_LOG_INFO, "Retry got %i/%i fps\n",
628  }
634  decode_hrd(s, 1, sps->max_sub_layers);
635  }
636 
638  if (vui->bitstream_restriction_flag) {
647  }
648 }
649 
651 {
652  int matrixId;
653 
654  for (matrixId = 0; matrixId < 6; matrixId++) {
655  // 4x4 default is 16
656  memset(sl->sl[0][matrixId], 16, 16);
657  sl->sl_dc[0][matrixId] = 16; // default for 16x16
658  sl->sl_dc[1][matrixId] = 16; // default for 32x32
659  }
660  memcpy(sl->sl[1][0], default_scaling_list_intra, 64);
661  memcpy(sl->sl[1][1], default_scaling_list_intra, 64);
662  memcpy(sl->sl[1][2], default_scaling_list_intra, 64);
663  memcpy(sl->sl[1][3], default_scaling_list_inter, 64);
664  memcpy(sl->sl[1][4], default_scaling_list_inter, 64);
665  memcpy(sl->sl[1][5], default_scaling_list_inter, 64);
666  memcpy(sl->sl[2][0], default_scaling_list_intra, 64);
667  memcpy(sl->sl[2][1], default_scaling_list_intra, 64);
668  memcpy(sl->sl[2][2], default_scaling_list_intra, 64);
669  memcpy(sl->sl[2][3], default_scaling_list_inter, 64);
670  memcpy(sl->sl[2][4], default_scaling_list_inter, 64);
671  memcpy(sl->sl[2][5], default_scaling_list_inter, 64);
672  memcpy(sl->sl[3][0], default_scaling_list_intra, 64);
673  memcpy(sl->sl[3][1], default_scaling_list_intra, 64);
674  memcpy(sl->sl[3][2], default_scaling_list_intra, 64);
675  memcpy(sl->sl[3][3], default_scaling_list_inter, 64);
676  memcpy(sl->sl[3][4], default_scaling_list_inter, 64);
677  memcpy(sl->sl[3][5], default_scaling_list_inter, 64);
678 }
679 
681 {
682  GetBitContext *gb = &s->HEVClc->gb;
683  uint8_t scaling_list_pred_mode_flag;
684  int32_t scaling_list_dc_coef[2][6];
685  int size_id, matrix_id, pos;
686  int i;
687 
688  for (size_id = 0; size_id < 4; size_id++)
689  for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {
690  scaling_list_pred_mode_flag = get_bits1(gb);
691  if (!scaling_list_pred_mode_flag) {
692  unsigned int delta = get_ue_golomb_long(gb);
693  /* Only need to handle non-zero delta. Zero means default,
694  * which should already be in the arrays. */
695  if (delta) {
696  // Copy from previous array.
697  if (matrix_id < delta) {
699  "Invalid delta in scaling list data: %d.\n", delta);
700  return AVERROR_INVALIDDATA;
701  }
702 
703  memcpy(sl->sl[size_id][matrix_id],
704  sl->sl[size_id][matrix_id - delta],
705  size_id > 0 ? 64 : 16);
706  if (size_id > 1)
707  sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta];
708  }
709  } else {
710  int next_coef, coef_num;
711  int32_t scaling_list_delta_coef;
712 
713  next_coef = 8;
714  coef_num = FFMIN(64, 1 << (4 + (size_id << 1)));
715  if (size_id > 1) {
716  scaling_list_dc_coef[size_id - 2][matrix_id] = get_se_golomb(gb) + 8;
717  next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
718  sl->sl_dc[size_id - 2][matrix_id] = next_coef;
719  }
720  for (i = 0; i < coef_num; i++) {
721  if (size_id == 0)
722  pos = 4 * ff_hevc_diag_scan4x4_y[i] +
724  else
725  pos = 8 * ff_hevc_diag_scan8x8_y[i] +
727 
728  scaling_list_delta_coef = get_se_golomb(gb);
729  next_coef = (next_coef + scaling_list_delta_coef + 256) % 256;
730  sl->sl[size_id][matrix_id][pos] = next_coef;
731  }
732  }
733  }
734 
735  if (sps->chroma_format_idc == 3) {
736  for (i = 0; i < 64; i++) {
737  sl->sl[3][1][i] = sl->sl[2][1][i];
738  sl->sl[3][2][i] = sl->sl[2][2][i];
739  sl->sl[3][4][i] = sl->sl[2][4][i];
740  sl->sl[3][5][i] = sl->sl[2][5][i];
741  }
742  sl->sl_dc[1][1] = sl->sl_dc[0][1];
743  sl->sl_dc[1][2] = sl->sl_dc[0][2];
744  sl->sl_dc[1][4] = sl->sl_dc[0][4];
745  sl->sl_dc[1][5] = sl->sl_dc[0][5];
746  }
747 
748 
749  return 0;
750 }
751 
753 {
754  const AVPixFmtDescriptor *desc;
755  GetBitContext *gb = &s->HEVClc->gb;
756  int ret = 0;
757  unsigned int sps_id = 0;
758  int log2_diff_max_min_transform_block_size;
759  int bit_depth_chroma, start, vui_present, sublayer_ordering_info;
760  int i;
761 
762  HEVCSPS *sps;
763  AVBufferRef *sps_buf = av_buffer_allocz(sizeof(*sps));
764 
765  if (!sps_buf)
766  return AVERROR(ENOMEM);
767  sps = (HEVCSPS*)sps_buf->data;
768 
769  av_log(s->avctx, AV_LOG_DEBUG, "Decoding SPS\n");
770 
771  // Coded parameters
772 
773  sps->vps_id = get_bits(gb, 4);
774  if (sps->vps_id >= MAX_VPS_COUNT) {
775  av_log(s->avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
776  ret = AVERROR_INVALIDDATA;
777  goto err;
778  }
779 
780  if (!s->vps_list[sps->vps_id]) {
781  av_log(s->avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
782  sps->vps_id);
783  ret = AVERROR_INVALIDDATA;
784  goto err;
785  }
786 
787  sps->max_sub_layers = get_bits(gb, 3) + 1;
788  if (sps->max_sub_layers > MAX_SUB_LAYERS) {
789  av_log(s->avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n",
790  sps->max_sub_layers);
791  ret = AVERROR_INVALIDDATA;
792  goto err;
793  }
794 
795  skip_bits1(gb); // temporal_id_nesting_flag
796 
797  if (parse_ptl(s, &sps->ptl, sps->max_sub_layers) < 0)
798  goto err;
799 
800  sps_id = get_ue_golomb_long(gb);
801  if (sps_id >= MAX_SPS_COUNT) {
802  av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", sps_id);
803  ret = AVERROR_INVALIDDATA;
804  goto err;
805  }
806 
808 
809  if (sps->chroma_format_idc == 3)
811 
813  sps->chroma_format_idc = 0;
814 
815  sps->width = get_ue_golomb_long(gb);
816  sps->height = get_ue_golomb_long(gb);
817  if ((ret = av_image_check_size(sps->width,
818  sps->height, 0, s->avctx)) < 0)
819  goto err;
820 
821  if (get_bits1(gb)) { // pic_conformance_flag
822  //TODO: * 2 is only valid for 420
827 
830  "discarding sps conformance window, "
831  "original values are l:%u r:%u t:%u b:%u\n",
836 
839  sps->pic_conf_win.top_offset =
840  sps->pic_conf_win.bottom_offset = 0;
841  }
842  sps->output_window = sps->pic_conf_win;
843  }
844 
845  sps->bit_depth = get_ue_golomb_long(gb) + 8;
846  bit_depth_chroma = get_ue_golomb_long(gb) + 8;
847  if (sps->chroma_format_idc && bit_depth_chroma != sps->bit_depth) {
849  "Luma bit depth (%d) is different from chroma bit depth (%d), "
850  "this is unsupported.\n",
851  sps->bit_depth, bit_depth_chroma);
852  ret = AVERROR_INVALIDDATA;
853  goto err;
854  }
855 
856  switch (sps->bit_depth) {
857  case 8:
858  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
859  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
860  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
861  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
862  break;
863  case 9:
864  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
865  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9;
866  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9;
867  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9;
868  break;
869  case 10:
870  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
871  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
872  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
873  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
874  break;
875  case 12:
876  if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
877  if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
878  if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
879  if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
880  break;
881  default:
883  "4:2:0, 4:2:2, 4:4:4 supports are currently specified for 8, 10 and 12 bits.\n");
884  ret = AVERROR_PATCHWELCOME;
885  goto err;
886  }
887 
888  desc = av_pix_fmt_desc_get(sps->pix_fmt);
889  if (!desc) {
890  ret = AVERROR(EINVAL);
891  goto err;
892  }
893 
894  sps->hshift[0] = sps->vshift[0] = 0;
895  sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
896  sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
897 
898  sps->pixel_shift = sps->bit_depth > 8;
899 
900  sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4;
901  if (sps->log2_max_poc_lsb > 16) {
902  av_log(s->avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n",
903  sps->log2_max_poc_lsb - 4);
904  ret = AVERROR_INVALIDDATA;
905  goto err;
906  }
907 
908  sublayer_ordering_info = get_bits1(gb);
909  start = sublayer_ordering_info ? 0 : sps->max_sub_layers - 1;
910  for (i = start; i < sps->max_sub_layers; i++) {
915  av_log(s->avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n",
917  ret = AVERROR_INVALIDDATA;
918  goto err;
919  }
921  av_log(s->avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n",
923  if (s->avctx->err_recognition & AV_EF_EXPLODE ||
925  ret = AVERROR_INVALIDDATA;
926  goto err;
927  }
929  }
930  }
931 
932  if (!sublayer_ordering_info) {
933  for (i = 0; i < start; i++) {
937  }
938  }
939 
940  sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3;
942  sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2;
943  log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb);
944  sps->log2_max_trafo_size = log2_diff_max_min_transform_block_size +
945  sps->log2_min_tb_size;
946 
947  if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) {
948  av_log(s->avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size);
949  ret = AVERROR_INVALIDDATA;
950  goto err;
951  }
952 
953  if (sps->log2_diff_max_min_coding_block_size > 30) {
954  av_log(s->avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_coding_block_size", sps->log2_diff_max_min_coding_block_size);
955  ret = AVERROR_INVALIDDATA;
956  goto err;
957  }
958 
959  if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) {
960  av_log(s->avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size");
961  ret = AVERROR_INVALIDDATA;
962  goto err;
963  }
964 
965  if (log2_diff_max_min_transform_block_size < 0 || log2_diff_max_min_transform_block_size > 30) {
966  av_log(s->avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size", log2_diff_max_min_transform_block_size);
967  ret = AVERROR_INVALIDDATA;
968  goto err;
969  }
970 
973 
975  if (sps->scaling_list_enable_flag) {
977 
978  if (get_bits1(gb)) {
979  ret = scaling_list_data(s, &sps->scaling_list, sps);
980  if (ret < 0)
981  goto err;
982  }
983  }
984 
985  sps->amp_enabled_flag = get_bits1(gb);
986  sps->sao_enabled = get_bits1(gb);
987 
988  sps->pcm_enabled_flag = get_bits1(gb);
989  if (sps->pcm_enabled_flag) {
990  sps->pcm.bit_depth = get_bits(gb, 4) + 1;
991  sps->pcm.bit_depth_chroma = get_bits(gb, 4) + 1;
994  get_ue_golomb_long(gb);
995  if (sps->pcm.bit_depth > sps->bit_depth) {
997  "PCM bit depth (%d) is greater than normal bit depth (%d)\n",
998  sps->pcm.bit_depth, sps->bit_depth);
999  ret = AVERROR_INVALIDDATA;
1000  goto err;
1001  }
1002 
1004  }
1005 
1006  sps->nb_st_rps = get_ue_golomb_long(gb);
1007  if (sps->nb_st_rps > MAX_SHORT_TERM_RPS_COUNT) {
1008  av_log(s->avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n",
1009  sps->nb_st_rps);
1010  ret = AVERROR_INVALIDDATA;
1011  goto err;
1012  }
1013  for (i = 0; i < sps->nb_st_rps; i++) {
1014  if ((ret = ff_hevc_decode_short_term_rps(s, &sps->st_rps[i],
1015  sps, 0)) < 0)
1016  goto err;
1017  }
1018 
1022  if (sps->num_long_term_ref_pics_sps > 31U) {
1023  av_log(s->avctx, AV_LOG_ERROR, "num_long_term_ref_pics_sps %d is out of range.\n",
1025  goto err;
1026  }
1027  for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
1028  sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(gb, sps->log2_max_poc_lsb);
1030  }
1031  }
1032 
1035  sps->vui.sar = (AVRational){0, 1};
1036  vui_present = get_bits1(gb);
1037  if (vui_present)
1038  decode_vui(s, sps);
1039 
1040  if (get_bits1(gb)) { // sps_extension_flag
1041  int sps_extension_flag[1];
1042  for (i = 0; i < 1; i++)
1043  sps_extension_flag[i] = get_bits1(gb);
1044  skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
1045  if (sps_extension_flag[0]) {
1046  int extended_precision_processing_flag;
1047  int high_precision_offsets_enabled_flag;
1048  int cabac_bypass_alignment_enabled_flag;
1049 
1053 
1055 
1056  extended_precision_processing_flag = get_bits1(gb);
1057  if (extended_precision_processing_flag)
1059  "extended_precision_processing_flag not yet implemented\n");
1060 
1062  high_precision_offsets_enabled_flag = get_bits1(gb);
1063  if (high_precision_offsets_enabled_flag)
1065  "high_precision_offsets_enabled_flag not yet implemented\n");
1066 
1068 
1069  cabac_bypass_alignment_enabled_flag = get_bits1(gb);
1070  if (cabac_bypass_alignment_enabled_flag)
1072  "cabac_bypass_alignment_enabled_flag not yet implemented\n");
1073  }
1074  }
1075  if (s->apply_defdispwin) {
1080  }
1081  if (sps->output_window.left_offset & (0x1F >> (sps->pixel_shift)) &&
1082  !(s->avctx->flags & CODEC_FLAG_UNALIGNED)) {
1083  sps->output_window.left_offset &= ~(0x1F >> (sps->pixel_shift));
1084  av_log(s->avctx, AV_LOG_WARNING, "Reducing left output window to %d "
1085  "chroma samples to preserve alignment.\n",
1086  sps->output_window.left_offset);
1087  }
1088  sps->output_width = sps->width -
1090  sps->output_height = sps->height -
1092  if (sps->width <= sps->output_window.left_offset + (int64_t)sps->output_window.right_offset ||
1093  sps->height <= sps->output_window.top_offset + (int64_t)sps->output_window.bottom_offset) {
1094  av_log(s->avctx, AV_LOG_WARNING, "Invalid visible frame dimensions: %dx%d.\n",
1095  sps->output_width, sps->output_height);
1096  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
1097  ret = AVERROR_INVALIDDATA;
1098  goto err;
1099  }
1101  "Displaying the whole video surface.\n");
1102  memset(&sps->pic_conf_win, 0, sizeof(sps->pic_conf_win));
1103  memset(&sps->output_window, 0, sizeof(sps->output_window));
1104  sps->output_width = sps->width;
1105  sps->output_height = sps->height;
1106  }
1107 
1108  // Inferred parameters
1109  sps->log2_ctb_size = sps->log2_min_cb_size +
1111  sps->log2_min_pu_size = sps->log2_min_cb_size - 1;
1112 
1113  if (sps->log2_ctb_size > MAX_LOG2_CTB_SIZE) {
1114  av_log(s->avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size);
1115  goto err;
1116  }
1117  if (sps->log2_ctb_size < 4) {
1118  av_log(s->avctx,
1119  AV_LOG_ERROR,
1120  "log2_ctb_size %d differs from the bounds of any known profile\n",
1121  sps->log2_ctb_size);
1122  avpriv_request_sample(s->avctx, "log2_ctb_size %d", sps->log2_ctb_size);
1123  goto err;
1124  }
1125 
1126  sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
1127  sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
1128  sps->ctb_size = sps->ctb_width * sps->ctb_height;
1129 
1130  sps->min_cb_width = sps->width >> sps->log2_min_cb_size;
1131  sps->min_cb_height = sps->height >> sps->log2_min_cb_size;
1132  sps->min_tb_width = sps->width >> sps->log2_min_tb_size;
1133  sps->min_tb_height = sps->height >> sps->log2_min_tb_size;
1134  sps->min_pu_width = sps->width >> sps->log2_min_pu_size;
1135  sps->min_pu_height = sps->height >> sps->log2_min_pu_size;
1136  sps->tb_mask = (1 << (sps->log2_ctb_size - sps->log2_min_tb_size)) - 1;
1137 
1138  sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
1139 
1140  if (av_mod_uintp2(sps->width, sps->log2_min_cb_size) ||
1141  av_mod_uintp2(sps->height, sps->log2_min_cb_size)) {
1142  av_log(s->avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n");
1143  goto err;
1144  }
1145 
1147  av_log(s->avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n",
1149  goto err;
1150  }
1152  av_log(s->avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n",
1154  goto err;
1155  }
1156  if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) {
1158  "max transform block size out of range: %d\n",
1159  sps->log2_max_trafo_size);
1160  goto err;
1161  }
1162 
1163  if (get_bits_left(gb) < 0) {
1165  "Overread SPS by %d bits\n", -get_bits_left(gb));
1166  goto err;
1167  }
1168 
1169  if (s->avctx->debug & FF_DEBUG_BITSTREAM) {
1171  "Parsed SPS: id %d; coded wxh: %dx%d; "
1172  "cropped wxh: %dx%d; pix_fmt: %s.\n",
1173  sps_id, sps->width, sps->height,
1174  sps->output_width, sps->output_height,
1176  }
1177 
1178  /* check if this is a repeat of an already parsed SPS, then keep the
1179  * original one.
1180  * otherwise drop all PPSes that depend on it */
1181  if (s->sps_list[sps_id] &&
1182  !memcmp(s->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) {
1183  av_buffer_unref(&sps_buf);
1184  } else {
1185  remove_sps(s, sps_id);
1186  s->sps_list[sps_id] = sps_buf;
1187  }
1188 
1189  return 0;
1190 
1191 err:
1192  av_buffer_unref(&sps_buf);
1193  return ret;
1194 }
1195 
1196 static void hevc_pps_free(void *opaque, uint8_t *data)
1197 {
1198  HEVCPPS *pps = (HEVCPPS*)data;
1199 
1200  av_freep(&pps->column_width);
1201  av_freep(&pps->row_height);
1202  av_freep(&pps->col_bd);
1203  av_freep(&pps->row_bd);
1204  av_freep(&pps->col_idxX);
1205  av_freep(&pps->ctb_addr_rs_to_ts);
1206  av_freep(&pps->ctb_addr_ts_to_rs);
1207  av_freep(&pps->tile_pos_rs);
1208  av_freep(&pps->tile_id);
1210 
1211  av_freep(&pps);
1212 }
1213 
1215  GetBitContext *gb = &s->HEVClc->gb;
1216  int i;
1217 
1218  if (pps->transform_skip_enabled_flag) {
1220  }
1228  "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
1229  return AVERROR_INVALIDDATA;
1230  }
1231  for (i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
1232  pps->cb_qp_offset_list[i] = get_se_golomb_long(gb);
1233  if (pps->cb_qp_offset_list[i]) {
1235  "cb_qp_offset_list not tested yet.\n");
1236  }
1237  pps->cr_qp_offset_list[i] = get_se_golomb_long(gb);
1238  if (pps->cr_qp_offset_list[i]) {
1240  "cb_qp_offset_list not tested yet.\n");
1241  }
1242  }
1243  }
1246 
1247  return(0);
1248 }
1249 
1251 {
1252  GetBitContext *gb = &s->HEVClc->gb;
1253  HEVCSPS *sps = NULL;
1254  int pic_area_in_ctbs;
1255  int log2_diff_ctb_min_tb_size;
1256  int i, j, x, y, ctb_addr_rs, tile_id;
1257  int ret = 0;
1258  unsigned int pps_id = 0;
1259 
1260  AVBufferRef *pps_buf;
1261  HEVCPPS *pps = av_mallocz(sizeof(*pps));
1262 
1263  if (!pps)
1264  return AVERROR(ENOMEM);
1265 
1266  pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps),
1267  hevc_pps_free, NULL, 0);
1268  if (!pps_buf) {
1269  av_freep(&pps);
1270  return AVERROR(ENOMEM);
1271  }
1272 
1273  av_log(s->avctx, AV_LOG_DEBUG, "Decoding PPS\n");
1274 
1275  // Default values
1277  pps->num_tile_columns = 1;
1278  pps->num_tile_rows = 1;
1279  pps->uniform_spacing_flag = 1;
1280  pps->disable_dbf = 0;
1281  pps->beta_offset = 0;
1282  pps->tc_offset = 0;
1284 
1285  // Coded parameters
1286  pps_id = get_ue_golomb_long(gb);
1287  if (pps_id >= MAX_PPS_COUNT) {
1288  av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
1289  ret = AVERROR_INVALIDDATA;
1290  goto err;
1291  }
1292  pps->sps_id = get_ue_golomb_long(gb);
1293  if (pps->sps_id >= MAX_SPS_COUNT) {
1294  av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id);
1295  ret = AVERROR_INVALIDDATA;
1296  goto err;
1297  }
1298  if (!s->sps_list[pps->sps_id]) {
1299  av_log(s->avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id);
1300  ret = AVERROR_INVALIDDATA;
1301  goto err;
1302  }
1303  sps = (HEVCSPS *)s->sps_list[pps->sps_id]->data;
1304 
1307  pps->num_extra_slice_header_bits = get_bits(gb, 3);
1308 
1309  pps->sign_data_hiding_flag = get_bits1(gb);
1310 
1312 
1315 
1317 
1320 
1322  pps->diff_cu_qp_delta_depth = 0;
1323  if (pps->cu_qp_delta_enabled_flag)
1325 
1326  if (pps->diff_cu_qp_delta_depth < 0 ||
1328  av_log(s->avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n",
1329  pps->diff_cu_qp_delta_depth);
1330  ret = AVERROR_INVALIDDATA;
1331  goto err;
1332  }
1333 
1334  pps->cb_qp_offset = get_se_golomb(gb);
1335  if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) {
1336  av_log(s->avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n",
1337  pps->cb_qp_offset);
1338  ret = AVERROR_INVALIDDATA;
1339  goto err;
1340  }
1341  pps->cr_qp_offset = get_se_golomb(gb);
1342  if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) {
1343  av_log(s->avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n",
1344  pps->cr_qp_offset);
1345  ret = AVERROR_INVALIDDATA;
1346  goto err;
1347  }
1349 
1350  pps->weighted_pred_flag = get_bits1(gb);
1351  pps->weighted_bipred_flag = get_bits1(gb);
1352 
1354  pps->tiles_enabled_flag = get_bits1(gb);
1356 
1357  if (pps->tiles_enabled_flag) {
1358  pps->num_tile_columns = get_ue_golomb_long(gb) + 1;
1359  pps->num_tile_rows = get_ue_golomb_long(gb) + 1;
1360  if (pps->num_tile_columns <= 0 ||
1361  pps->num_tile_columns >= sps->width) {
1362  av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n",
1363  pps->num_tile_columns - 1);
1364  ret = AVERROR_INVALIDDATA;
1365  goto err;
1366  }
1367  if (pps->num_tile_rows <= 0 ||
1368  pps->num_tile_rows >= sps->height) {
1369  av_log(s->avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n",
1370  pps->num_tile_rows - 1);
1371  ret = AVERROR_INVALIDDATA;
1372  goto err;
1373  }
1374 
1375  pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
1376  pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
1377  if (!pps->column_width || !pps->row_height) {
1378  ret = AVERROR(ENOMEM);
1379  goto err;
1380  }
1381 
1382  pps->uniform_spacing_flag = get_bits1(gb);
1383  if (!pps->uniform_spacing_flag) {
1384  uint64_t sum = 0;
1385  for (i = 0; i < pps->num_tile_columns - 1; i++) {
1386  pps->column_width[i] = get_ue_golomb_long(gb) + 1;
1387  sum += pps->column_width[i];
1388  }
1389  if (sum >= sps->ctb_width) {
1390  av_log(s->avctx, AV_LOG_ERROR, "Invalid tile widths.\n");
1391  ret = AVERROR_INVALIDDATA;
1392  goto err;
1393  }
1394  pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum;
1395 
1396  sum = 0;
1397  for (i = 0; i < pps->num_tile_rows - 1; i++) {
1398  pps->row_height[i] = get_ue_golomb_long(gb) + 1;
1399  sum += pps->row_height[i];
1400  }
1401  if (sum >= sps->ctb_height) {
1402  av_log(s->avctx, AV_LOG_ERROR, "Invalid tile heights.\n");
1403  ret = AVERROR_INVALIDDATA;
1404  goto err;
1405  }
1406  pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum;
1407  }
1409  }
1410 
1412 
1416  pps->disable_dbf = get_bits1(gb);
1417  if (!pps->disable_dbf) {
1418  pps->beta_offset = get_se_golomb(gb) * 2;
1419  pps->tc_offset = get_se_golomb(gb) * 2;
1420  if (pps->beta_offset/2 < -6 || pps->beta_offset/2 > 6) {
1421  av_log(s->avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n",
1422  pps->beta_offset/2);
1423  ret = AVERROR_INVALIDDATA;
1424  goto err;
1425  }
1426  if (pps->tc_offset/2 < -6 || pps->tc_offset/2 > 6) {
1427  av_log(s->avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n",
1428  pps->tc_offset/2);
1429  ret = AVERROR_INVALIDDATA;
1430  goto err;
1431  }
1432  }
1433  }
1434 
1436  if (pps->scaling_list_data_present_flag) {
1438  ret = scaling_list_data(s, &pps->scaling_list, sps);
1439  if (ret < 0)
1440  goto err;
1441  }
1444  if (pps->log2_parallel_merge_level > sps->log2_ctb_size) {
1445  av_log(s->avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n",
1446  pps->log2_parallel_merge_level - 2);
1447  ret = AVERROR_INVALIDDATA;
1448  goto err;
1449  }
1450 
1452 
1453  if (get_bits1(gb)) { // pps_extension_present_flag
1454  int pps_range_extensions_flag = get_bits1(gb);
1455  /* int pps_extension_7bits = */ get_bits(gb, 7);
1456  if (sps->ptl.general_ptl.profile_idc == FF_PROFILE_HEVC_REXT && pps_range_extensions_flag) {
1457  if ((ret = pps_range_extensions(s, pps, sps)) < 0)
1458  goto err;
1459  }
1460  }
1461 
1462  // Inferred parameters
1463  pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd));
1464  pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd));
1465  pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX));
1466  if (!pps->col_bd || !pps->row_bd || !pps->col_idxX) {
1467  ret = AVERROR(ENOMEM);
1468  goto err;
1469  }
1470 
1471  if (pps->uniform_spacing_flag) {
1472  if (!pps->column_width) {
1473  pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
1474  pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
1475  }
1476  if (!pps->column_width || !pps->row_height) {
1477  ret = AVERROR(ENOMEM);
1478  goto err;
1479  }
1480 
1481  for (i = 0; i < pps->num_tile_columns; i++) {
1482  pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns -
1483  (i * sps->ctb_width) / pps->num_tile_columns;
1484  }
1485 
1486  for (i = 0; i < pps->num_tile_rows; i++) {
1487  pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows -
1488  (i * sps->ctb_height) / pps->num_tile_rows;
1489  }
1490  }
1491 
1492  pps->col_bd[0] = 0;
1493  for (i = 0; i < pps->num_tile_columns; i++)
1494  pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i];
1495 
1496  pps->row_bd[0] = 0;
1497  for (i = 0; i < pps->num_tile_rows; i++)
1498  pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i];
1499 
1500  for (i = 0, j = 0; i < sps->ctb_width; i++) {
1501  if (i > pps->col_bd[j])
1502  j++;
1503  pps->col_idxX[i] = j;
1504  }
1505 
1506  /**
1507  * 6.5
1508  */
1509  pic_area_in_ctbs = sps->ctb_width * sps->ctb_height;
1510 
1511  pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts));
1512  pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs));
1513  pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id));
1514  pps->min_tb_addr_zs_tab = av_malloc_array((sps->tb_mask+2) * (sps->tb_mask+2), sizeof(*pps->min_tb_addr_zs_tab));
1515  if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs ||
1516  !pps->tile_id || !pps->min_tb_addr_zs_tab) {
1517  ret = AVERROR(ENOMEM);
1518  goto err;
1519  }
1520 
1521  for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
1522  int tb_x = ctb_addr_rs % sps->ctb_width;
1523  int tb_y = ctb_addr_rs / sps->ctb_width;
1524  int tile_x = 0;
1525  int tile_y = 0;
1526  int val = 0;
1527 
1528  for (i = 0; i < pps->num_tile_columns; i++) {
1529  if (tb_x < pps->col_bd[i + 1]) {
1530  tile_x = i;
1531  break;
1532  }
1533  }
1534 
1535  for (i = 0; i < pps->num_tile_rows; i++) {
1536  if (tb_y < pps->row_bd[i + 1]) {
1537  tile_y = i;
1538  break;
1539  }
1540  }
1541 
1542  for (i = 0; i < tile_x; i++)
1543  val += pps->row_height[tile_y] * pps->column_width[i];
1544  for (i = 0; i < tile_y; i++)
1545  val += sps->ctb_width * pps->row_height[i];
1546 
1547  val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] +
1548  tb_x - pps->col_bd[tile_x];
1549 
1550  pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val;
1551  pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs;
1552  }
1553 
1554  for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++)
1555  for (i = 0; i < pps->num_tile_columns; i++, tile_id++)
1556  for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++)
1557  for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++)
1558  pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id;
1559 
1560  pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs));
1561  if (!pps->tile_pos_rs) {
1562  ret = AVERROR(ENOMEM);
1563  goto err;
1564  }
1565 
1566  for (j = 0; j < pps->num_tile_rows; j++)
1567  for (i = 0; i < pps->num_tile_columns; i++)
1568  pps->tile_pos_rs[j * pps->num_tile_columns + i] = pps->row_bd[j] * sps->ctb_width + pps->col_bd[i];
1569 
1570  log2_diff_ctb_min_tb_size = sps->log2_ctb_size - sps->log2_min_tb_size;
1571  pps->min_tb_addr_zs = &pps->min_tb_addr_zs_tab[1*(sps->tb_mask+2)+1];
1572  for (y = 0; y < sps->tb_mask+2; y++) {
1573  pps->min_tb_addr_zs_tab[y*(sps->tb_mask+2)] = -1;
1574  pps->min_tb_addr_zs_tab[y] = -1;
1575  }
1576  for (y = 0; y < sps->tb_mask+1; y++) {
1577  for (x = 0; x < sps->tb_mask+1; x++) {
1578  int tb_x = x >> log2_diff_ctb_min_tb_size;
1579  int tb_y = y >> log2_diff_ctb_min_tb_size;
1580  int ctb_addr_rs = sps->ctb_width * tb_y + tb_x;
1581  int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
1582  (log2_diff_ctb_min_tb_size * 2);
1583  for (i = 0; i < log2_diff_ctb_min_tb_size; i++) {
1584  int m = 1 << i;
1585  val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
1586  }
1587  pps->min_tb_addr_zs[y * (sps->tb_mask+2) + x] = val;
1588  }
1589  }
1590 
1591  if (get_bits_left(gb) < 0) {
1593  "Overread PPS by %d bits\n", -get_bits_left(gb));
1594  goto err;
1595  }
1596 
1597  remove_pps(s, pps_id);
1598  s->pps_list[pps_id] = pps_buf;
1599 
1600  return 0;
1601 
1602 err:
1603  av_buffer_unref(&pps_buf);
1604  return ret;
1605 }
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:383
#define NULL
Definition: coverity.c:32
unsigned int log2_min_cb_size
Definition: hevc.h:449
const char const char void * val
Definition: avisynth_c.h:634
uint8_t log2_sao_offset_scale_luma
Definition: hevc.h:542
const char * s
Definition: avisynth_c.h:631
int min_spatial_segmentation_idc
Definition: hevc.h:343
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:124
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
static int parse_ptl(HEVCContext *s, PTL *ptl, int max_num_sub_layers)
Definition: hevc_ps.c:277
int ctb_height
Definition: hevc.h:470
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define CODEC_FLAG_UNALIGNED
Allow decoders to produce frames with data planes that are not aligned to CPU requirements (e...
Definition: avcodec.h:711
uint8_t diff_cu_chroma_qp_offset_depth
Definition: hevc.h:538
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:183
enum AVCodecID id
Definition: mxfenc.c:99
int vui_num_ticks_poc_diff_one_minus1
Definition: hevc.h:336
int max_dec_pic_buffering
Definition: hevc.h:417
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
int transform_skip_rotation_enabled_flag
Definition: hevc.h:459
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define CODEC_FLAG2_IGNORE_CROP
Discard cropping information from SPS.
Definition: avcodec.h:769
int8_t cb_qp_offset_list[5]
Definition: hevc.h:540
int ff_hevc_decode_nal_sps(HEVCContext *s)
Definition: hevc_ps.c:752
unsigned int * row_height
RowHeight.
Definition: hevc.h:547
#define FF_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: avcodec.h:2912
int vps_num_ticks_poc_diff_one
vps_num_ticks_poc_diff_one_minus1 + 1
Definition: hevc.h:386
#define MAX_REFS
Definition: hevc.h:40
int pic_init_qp_minus26
Definition: hevc.h:495
#define MAX_PPS_COUNT
Definition: h264.h:50
VUI vui
Definition: hevc.h:422
#define MAX_DPB_SIZE
Definition: hevc.h:39
int vshift[3]
Definition: hevc.h:481
int num
numerator
Definition: rational.h:44
#define MAX_LOG2_CTB_SIZE
Definition: hevc.h:59
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: hevc_cabac.c:430
uint32_t vui_time_scale
Definition: hevc.h:334
static int decode_hrd(HEVCContext *s, int common_inf_present, int max_sublayers)
Definition: hevc_ps.c:336
uint8_t weighted_bipred_flag
Definition: hevc.h:507
unsigned int left_offset
Definition: hevc.h:301
Definition: hevc.h:362
uint8_t seq_loop_filter_across_slices_enabled_flag
Definition: hevc.h:520
uint8_t cabac_init_present_flag
Definition: hevc.h:491
int chroma_loc_info_present_flag
Definition: hevc.h:321
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:368
int max_latency_increase
Definition: hevc.h:419
#define FF_ARRAY_ELEMS(a)
int min_cb_height
Definition: hevc.h:473
int * ctb_addr_ts_to_rs
CtbAddrTSToRS.
Definition: hevc.h:553
int explicit_rdpcm_enabled_flag
Definition: hevc.h:462
int num_ref_idx_l0_default_active
num_ref_idx_l0_default_active_minus1 + 1
Definition: hevc.h:493
static const AVRational vui_sar[]
Definition: hevc_ps.c:52
ShortTermRPS st_rps[MAX_SHORT_TERM_RPS_COUNT]
Definition: hevc.h:429
int chroma_sample_loc_type_top_field
Definition: hevc.h:322
int width
Definition: hevc.h:467
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
int qp_bd_offset
Definition: hevc.h:483
int pixel_shift
Definition: hevc.h:409
uint8_t entropy_coding_sync_enabled_flag
Definition: hevc.h:513
HEVCWindow output_window
Definition: hevc.h:404
int output_width
Definition: hevc.h:403
int log2_parallel_merge_level
log2_parallel_merge_level_minus2 + 2
Definition: hevc.h:532
uint8_t log2_sao_offset_scale_chroma
Definition: hevc.h:543
int restricted_ref_pic_lists_flag
Definition: hevc.h:342
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int chroma_format_idc
Definition: hevc.h:399
uint8_t disable_dbf
Definition: hevc.h:524
unsigned int log2_max_trafo_size
Definition: hevc.h:452
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t profile_compatibility_flag[32]
Definition: hevc.h:354
Definition: hevc.h:307
unsigned int num_negative_pics
Definition: hevc.h:277
uint8_t
uint8_t sub_layer_profile_present_flag[MAX_SUB_LAYERS]
Definition: hevc.h:366
static const uint8_t default_scaling_list_inter[]
Definition: hevc_ps.c:41
unsigned int vps_num_reorder_pics[MAX_SUB_LAYERS]
Definition: hevc.h:378
float delta
HEVCWindow pic_conf_win
Definition: hevc.h:406
uint8_t log2_max_transform_skip_block_size
Definition: hevc.h:535
int overscan_info_present_flag
Definition: hevc.h:310
uint8_t vps_timing_info_present_flag
Definition: hevc.h:382
uint8_t matrix_coeffs
Definition: hevc.h:319
int min_tb_width
Definition: hevc.h:474
int apply_defdispwin
Definition: hevc.h:905
int num_ref_idx_l1_default_active
num_ref_idx_l1_default_active_minus1 + 1
Definition: hevc.h:494
unsigned int log2_min_pcm_cb_size
Definition: hevc.h:442
AVCodecContext * avctx
Definition: hevc.h:792
int min_cb_width
Definition: hevc.h:472
int vps_max_sub_layers
vps_max_temporal_layers_minus1 + 1
Definition: hevc.h:373
int frame_field_info_present_flag
Definition: hevc.h:327
uint8_t tier_flag
Definition: hevc.h:352
uint8_t scaling_list_data_present_flag
Definition: hevc.h:528
uint8_t bit_depth_chroma
Definition: hevc.h:441
static int decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl)
Definition: hevc_ps.c:240
static int pps_range_extensions(HEVCContext *s, HEVCPPS *pps, HEVCSPS *sps)
Definition: hevc_ps.c:1214
int ff_hevc_decode_nal_vps(HEVCContext *s)
Definition: hevc_ps.c:399
uint8_t loop_filter_disable_flag
Definition: hevc.h:444
int ff_hevc_decode_nal_pps(HEVCContext *s)
Definition: hevc_ps.c:1250
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:369
int bitstream_restriction_flag
Definition: hevc.h:339
uint8_t transquant_bypass_enable_flag
Definition: hevc.h:509
#define av_log(a,...)
unsigned m
Definition: audioconvert.c:187
int8_t cr_qp_offset_list[5]
Definition: hevc.h:541
int vps_max_layer_id
Definition: hevc.h:380
#define U(x)
Definition: vp56_arith.h:37
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:588
const HEVCSPS * sps
Definition: hevc.h:816
static void remove_sps(HEVCContext *s, int id)
Definition: hevc_ps.c:79
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t frame_only_constraint_flag
Definition: hevc.h:359
unsigned int log2_max_poc_lsb
Definition: hevc.h:412
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
int vps_max_layers
Definition: hevc.h:372
int min_pu_height
Definition: hevc.h:477
AVBufferRef * vps_list[MAX_VPS_COUNT]
Definition: hevc.h:818
int persistent_rice_adaptation_enabled_flag
coded frame dimension in various units
Definition: hevc.h:464
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:2623
#define AVERROR(e)
Definition: error.h:43
int vui_timing_info_present_flag
Definition: hevc.h:332
uint8_t amp_enabled_flag
Definition: hevc.h:431
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
#define MAX_SHORT_TERM_RPS_COUNT
Definition: hevc.h:52
Not part of ABI.
Definition: pixfmt.h:471
unsigned int log2_ctb_size
Definition: hevc.h:453
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1335
int vui_poc_proportional_to_timing_flag
Definition: hevc.h:335
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:367
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
uint8_t vps_temporal_id_nesting_flag
Definition: hevc.h:371
uint8_t colour_primaries
Definition: hevc.h:317
uint8_t used[32]
Definition: hevc.h:280
int motion_vectors_over_pic_boundaries_flag
Definition: hevc.h:341
uint8_t tiles_enabled_flag
Definition: hevc.h:512
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
uint32_t vps_num_units_in_tick
Definition: hevc.h:383
const HEVCPPS * pps
Definition: hevc.h:817
int * col_idxX
Definition: hevc.h:550
int vps_num_layer_sets
vps_num_layer_sets_minus1 + 1
Definition: hevc.h:381
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:362
uint8_t lists_modification_present_flag
Definition: hevc.h:531
int * min_tb_addr_zs_tab
MinTbAddrZS.
Definition: hevc.h:557
uint8_t profile_idc
Definition: hevc.h:353
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:241
static int scaling_list_data(HEVCContext *s, ScalingList *sl, HEVCSPS *sps)
Definition: hevc_ps.c:680
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2612
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:348
int max_transform_hierarchy_depth_inter
Definition: hevc.h:456
#define FFMIN(a, b)
Definition: common.h:66
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:75
uint8_t vps_poc_proportional_to_timing_flag
Definition: hevc.h:385
int num_tile_columns
num_tile_columns_minus1 + 1
Definition: hevc.h:515
ret
Definition: avfilter.c:974
int output_height
Definition: hevc.h:403
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:2911
unsigned int top_offset
Definition: hevc.h:303
int hshift[3]
Definition: hevc.h:480
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: hevc.h:819
int32_t
int max_bits_per_min_cu_denom
Definition: hevc.h:345
uint8_t cu_qp_delta_enabled_flag
Definition: hevc.h:500
uint8_t used_by_curr_pic_lt_sps_flag[32]
Definition: hevc.h:436
#define MAX_SPS_COUNT
Definition: h264.h:49
int ctb_width
Definition: hevc.h:469
uint8_t sl_dc[2][6]
Definition: hevc.h:394
int32_t delta_poc[32]
Definition: hevc.h:279
uint8_t sign_data_hiding_flag
Definition: hevc.h:489
int height
Definition: hevc.h:468
uint8_t output_flag_present_flag
Definition: hevc.h:508
int log2_max_mv_length_vertical
Definition: hevc.h:347
PTLCommon general_ptl
Definition: hevc.h:363
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:363
int max_bytes_per_pic_denom
Definition: hevc.h:344
int overscan_appropriate_flag
Definition: hevc.h:311
static void set_default_scaling_list_data(ScalingList *sl)
Definition: hevc_ps.c:650
int implicit_rdpcm_enabled_flag
Definition: hevc.h:461
unsigned vps_id
Definition: hevc.h:398
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: hevc.h:820
uint8_t constrained_intra_pred_flag
Definition: hevc.h:497
int tb_mask
Definition: hevc.h:478
uint8_t sl[4][6][64]
Definition: hevc.h:393
PTL ptl
Definition: hevc.h:375
uint8_t pic_slice_level_chroma_qp_offsets_present_flag
Definition: hevc.h:505
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:85
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
uint32_t vps_time_scale
Definition: hevc.h:384
int colour_description_present_flag
Definition: hevc.h:316
uint8_t sub_layer_level_present_flag[MAX_SUB_LAYERS]
Definition: hevc.h:367
Definition: hevc.h:397
enum AVPixelFormat pix_fmt
Definition: hevc.h:410
Definition: hevc.h:370
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:215
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
Definition: hevc.h:486
uint8_t transform_skip_enabled_flag
Definition: hevc.h:498
uint8_t uniform_spacing_flag
Definition: hevc.h:517
int ctb_size
Definition: hevc.h:471
int * ctb_addr_rs_to_ts
CtbAddrRSToTS.
Definition: hevc.h:552
PTL ptl
Definition: hevc.h:423
int max_sub_layers
Definition: hevc.h:415
static void remove_pps(HEVCContext *s, int id)
Definition: hevc_ps.c:72
unsigned int log2_min_pu_size
Definition: hevc.h:454
unsigned int sps_id
seq_parameter_set_id
Definition: hevc.h:487
int debug
debug
Definition: avcodec.h:2565
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
#define MAX_VPS_COUNT
Definition: hevc.h:49
ScalingList scaling_list
Definition: hevc.h:529
struct HEVCSPS::@51 pcm
int log2_max_mv_length_horizontal
Definition: hevc.h:346
uint8_t sao_enabled
Definition: hevc.h:432
int num_extra_slice_header_bits
Definition: hevc.h:533
uint8_t * data
The data buffer.
Definition: buffer.h:89
uint8_t loop_filter_across_tiles_enabled_flag
Definition: hevc.h:518
uint8_t num_long_term_ref_pics_sps
Definition: hevc.h:437
const HEVCVPS * vps
Definition: hevc.h:815
uint8_t cross_component_prediction_enabled_flag
Definition: hevc.h:536
uint32_t vui_num_units_in_tick
Definition: hevc.h:333
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:82
uint8_t deblocking_filter_control_present_flag
Definition: hevc.h:522
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
int transform_skip_context_enabled_flag
Definition: hevc.h:460
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:329
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:364
uint8_t sps_temporal_mvp_enabled_flag
Definition: hevc.h:446
unsigned int nb_st_rps
Definition: hevc.h:428
int chroma_sample_loc_type_bottom_field
Definition: hevc.h:323
int num_tile_rows
num_tile_rows_minus1 + 1
Definition: hevc.h:516
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:297
uint8_t chroma_qp_offset_list_enabled_flag
Definition: hevc.h:537
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: hevc_cabac.c:470
rational number numerator/denominator
Definition: rational.h:43
int vps_num_hrd_parameters
Definition: hevc.h:387
#define MAX_SUB_LAYERS
7.4.2.1
Definition: hevc.h:48
Not part of ABI.
Definition: pixfmt.h:494
GetBitContext gb
Definition: hevc.h:754
static void hevc_pps_free(void *opaque, uint8_t *data)
Definition: hevc_ps.c:1196
#define FF_PROFILE_HEVC_REXT
Definition: avcodec.h:2913
unsigned int log2_min_tb_size
Definition: hevc.h:451
uint16_t lt_ref_pic_poc_lsb_sps[32]
Definition: hevc.h:435
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:361
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:337
uint8_t scaling_list_enable_flag
Definition: hevc.h:425
int * tile_id
TileId.
Definition: hevc.h:554
static const uint8_t default_scaling_list_intra[]
Definition: hevc_ps.c:30
int tc_offset
tc_offset_div2 * 2
Definition: hevc.h:526
uint8_t transfer_characteristic
Definition: hevc.h:318
int default_display_window_flag
Definition: hevc.h:329
HEVCLocalContext * HEVClc
Definition: hevc.h:797
int size
Size of data in bytes.
Definition: buffer.h:93
HEVCWindow def_disp_win
Definition: hevc.h:330
int cr_qp_offset
Definition: hevc.h:504
ScalingList scaling_list
Definition: hevc.h:426
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:365
unsigned int log2_diff_max_min_coding_block_size
Definition: hevc.h:450
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:371
unsigned int log2_max_pcm_cb_size
Definition: hevc.h:443
uint8_t level_idc
Definition: hevc.h:355
int neutra_chroma_indication_flag
Definition: hevc.h:324
int * tile_pos_rs
TilePosRS.
Definition: hevc.h:555
static void decode_vui(HEVCContext *s, HEVCSPS *sps)
Definition: hevc_ps.c:520
A reference to a data buffer.
Definition: buffer.h:81
int max_transform_hierarchy_depth_intra
Definition: hevc.h:457
uint8_t profile_space
Definition: hevc.h:351
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
unsigned int * row_bd
RowBd.
Definition: hevc.h:549
int video_format
Definition: hevc.h:314
uint8_t weighted_pred_flag
Definition: hevc.h:506
unsigned int * col_bd
ColBd.
Definition: hevc.h:548
unsigned int * column_width
ColumnWidth.
Definition: hevc.h:546
uint8_t slice_header_extension_present_flag
Definition: hevc.h:534
static void remove_vps(HEVCContext *s, int id)
Definition: hevc_ps.c:96
int den
denominator
Definition: rational.h:45
int video_full_range_flag
Definition: hevc.h:315
PTLCommon sub_layer_ptl[MAX_SUB_LAYERS]
Definition: hevc.h:364
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:2910
AVRational sar
Definition: hevc.h:308
uint8_t chroma_qp_offset_list_len_minus1
Definition: hevc.h:539
int num_delta_pocs
Definition: hevc.h:278
uint8_t sps_strong_intra_smoothing_enable_flag
Definition: hevc.h:447
#define FF_DEBUG_BITSTREAM
Definition: avcodec.h:2568
int min_pu_width
Definition: hevc.h:476
int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
Definition: hevc_ps.c:110
unsigned int vps_max_dec_pic_buffering[MAX_SUB_LAYERS]
Definition: hevc.h:377
uint8_t long_term_ref_pics_present_flag
Definition: hevc.h:434
unsigned int vps_max_latency_increase[MAX_SUB_LAYERS]
Definition: hevc.h:379
int flags2
CODEC_FLAG2_*.
Definition: avcodec.h:1342
static void decode_sublayer_hrd(HEVCContext *s, unsigned int nb_cpb, int subpic_params_present)
Definition: hevc_ps.c:318
int vui_hrd_parameters_present_flag
Definition: hevc.h:337
unsigned int right_offset
Definition: hevc.h:302
int diff_cu_qp_delta_depth
Definition: hevc.h:501
#define av_freep(p)
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: hevc_cabac.c:451
void INT64 start
Definition: avisynth_c.h:553
int num_reorder_pics
Definition: hevc.h:418
struct HEVCSPS::@50 temporal_layer[MAX_SUB_LAYERS]
uint8_t progressive_source_flag
Definition: hevc.h:356
int cb_qp_offset
Definition: hevc.h:503
#define av_malloc_array(a, b)
int video_signal_type_present_flag
Definition: hevc.h:313
uint8_t deblocking_filter_override_enabled_flag
Definition: hevc.h:523
int bit_depth
Definition: hevc.h:408
int beta_offset
beta_offset_div2 * 2
Definition: hevc.h:525
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:2011
int min_tb_height
Definition: hevc.h:475
int * min_tb_addr_zs
MinTbAddrZS.
Definition: hevc.h:556
uint8_t non_packed_constraint_flag
Definition: hevc.h:358
int intra_smoothing_disabled_flag
Definition: hevc.h:463
exp golomb vlc stuff
int pcm_enabled_flag
Definition: hevc.h:413
int tiles_fixed_structure_flag
Definition: hevc.h:340
uint8_t interlaced_source_flag
Definition: hevc.h:357
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:250
int field_seq_flag
Definition: hevc.h:326
Not part of ABI.
Definition: pixfmt.h:512
for(j=16;j >0;--j)
uint8_t separate_colour_plane_flag
output (i.e. cropped) values
Definition: hevc.h:400
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: hevc_cabac.c:437
unsigned int bottom_offset
Definition: hevc.h:304
int vps_sub_layer_ordering_info_present_flag
Definition: hevc.h:376
uint8_t dependent_slice_segments_enabled_flag
Definition: hevc.h:511