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