FFmpeg
h264_ps.c
Go to the documentation of this file.
1 /*
2  * H.26L/H.264/AVC/JVT/14496-10/... parameter set decoding
3  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * H.264 / AVC / MPEG-4 part10 parameter set decoding.
25  * @author Michael Niedermayer <michaelni@gmx.at>
26  */
27 
28 #include <inttypes.h>
29 
30 #include "libavutil/imgutils.h"
31 #include "mathops.h"
32 #include "avcodec.h"
33 #include "h264data.h"
34 #include "h2645_vui.h"
35 #include "h264_ps.h"
36 #include "golomb.h"
37 
38 #define MIN_LOG2_MAX_FRAME_NUM 4
39 
40 static const uint8_t default_scaling4[2][16] = {
41  { 6, 13, 20, 28, 13, 20, 28, 32,
42  20, 28, 32, 37, 28, 32, 37, 42 },
43  { 10, 14, 20, 24, 14, 20, 24, 27,
44  20, 24, 27, 30, 24, 27, 30, 34 }
45 };
46 
47 static const uint8_t default_scaling8[2][64] = {
48  { 6, 10, 13, 16, 18, 23, 25, 27,
49  10, 11, 16, 18, 23, 25, 27, 29,
50  13, 16, 18, 23, 25, 27, 29, 31,
51  16, 18, 23, 25, 27, 29, 31, 33,
52  18, 23, 25, 27, 29, 31, 33, 36,
53  23, 25, 27, 29, 31, 33, 36, 38,
54  25, 27, 29, 31, 33, 36, 38, 40,
55  27, 29, 31, 33, 36, 38, 40, 42 },
56  { 9, 13, 15, 17, 19, 21, 22, 24,
57  13, 13, 17, 19, 21, 22, 24, 25,
58  15, 17, 19, 21, 22, 24, 25, 27,
59  17, 19, 21, 22, 24, 25, 27, 28,
60  19, 21, 22, 24, 25, 27, 28, 30,
61  21, 22, 24, 25, 27, 28, 30, 32,
62  22, 24, 25, 27, 28, 30, 32, 33,
63  24, 25, 27, 28, 30, 32, 33, 35 }
64 };
65 
66 /* maximum number of MBs in the DPB for a given level */
67 static const int level_max_dpb_mbs[][2] = {
68  { 10, 396 },
69  { 11, 900 },
70  { 12, 2376 },
71  { 13, 2376 },
72  { 20, 2376 },
73  { 21, 4752 },
74  { 22, 8100 },
75  { 30, 8100 },
76  { 31, 18000 },
77  { 32, 20480 },
78  { 40, 32768 },
79  { 41, 32768 },
80  { 42, 34816 },
81  { 50, 110400 },
82  { 51, 184320 },
83  { 52, 184320 },
84 };
85 
86 static void remove_pps(H264ParamSets *s, int id)
87 {
88  av_buffer_unref(&s->pps_list[id]);
89 }
90 
91 static void remove_sps(H264ParamSets *s, int id)
92 {
93 #if 0
94  int i;
95  if (s->sps_list[id]) {
96  /* drop all PPS that depend on this SPS */
97  for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
98  if (s->pps_list[i] && ((PPS*)s->pps_list[i]->data)->sps_id == id)
99  remove_pps(s, i);
100  }
101 #endif
102  av_buffer_unref(&s->sps_list[id]);
103 }
104 
105 static inline int decode_hrd_parameters(GetBitContext *gb, void *logctx,
106  SPS *sps)
107 {
108  int cpb_count, i;
109  cpb_count = get_ue_golomb_31(gb) + 1;
110 
111  if (cpb_count > 32U) {
112  av_log(logctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count);
113  return AVERROR_INVALIDDATA;
114  }
115 
116  sps->cpr_flag = 0x0;
117  sps->bit_rate_scale = get_bits(gb, 4);
118  get_bits(gb, 4); /* cpb_size_scale */
119  for (i = 0; i < cpb_count; i++) {
120  sps->bit_rate_value[i] = get_ue_golomb_long(gb) + 1; /* bit_rate_value_minus1 + 1 */
121  sps->cpb_size_value[i] = get_ue_golomb_long(gb) + 1; /* cpb_size_value_minus1 + 1 */
122  sps->cpr_flag |= get_bits1(gb) << i;
123  }
124  sps->initial_cpb_removal_delay_length = get_bits(gb, 5) + 1;
125  sps->cpb_removal_delay_length = get_bits(gb, 5) + 1;
126  sps->dpb_output_delay_length = get_bits(gb, 5) + 1;
127  sps->time_offset_length = get_bits(gb, 5);
128  sps->cpb_cnt = cpb_count;
129  return 0;
130 }
131 
132 static inline int decode_vui_parameters(GetBitContext *gb, void *logctx,
133  SPS *sps)
134 {
135  ff_h2645_decode_common_vui_params(gb, &sps->vui, logctx);
136 
137  if (show_bits1(gb) && get_bits_left(gb) < 10) {
138  av_log(logctx, AV_LOG_WARNING, "Truncated VUI (%d)\n", get_bits_left(gb));
139  return 0;
140  }
141 
142  sps->timing_info_present_flag = get_bits1(gb);
143  if (sps->timing_info_present_flag) {
144  unsigned num_units_in_tick = get_bits_long(gb, 32);
145  unsigned time_scale = get_bits_long(gb, 32);
146  if (!num_units_in_tick || !time_scale) {
147  av_log(logctx, AV_LOG_ERROR,
148  "time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",
149  time_scale, num_units_in_tick);
150  sps->timing_info_present_flag = 0;
151  } else {
152  sps->num_units_in_tick = num_units_in_tick;
153  sps->time_scale = time_scale;
154  }
155  sps->fixed_frame_rate_flag = get_bits1(gb);
156  }
157 
158  sps->nal_hrd_parameters_present_flag = get_bits1(gb);
159  if (sps->nal_hrd_parameters_present_flag)
160  if (decode_hrd_parameters(gb, logctx, sps) < 0)
161  return AVERROR_INVALIDDATA;
162  sps->vcl_hrd_parameters_present_flag = get_bits1(gb);
163  if (sps->vcl_hrd_parameters_present_flag)
164  if (decode_hrd_parameters(gb, logctx, sps) < 0)
165  return AVERROR_INVALIDDATA;
166  if (sps->nal_hrd_parameters_present_flag ||
167  sps->vcl_hrd_parameters_present_flag)
168  get_bits1(gb); /* low_delay_hrd_flag */
169  sps->pic_struct_present_flag = get_bits1(gb);
170  if (!get_bits_left(gb))
171  return 0;
172  sps->bitstream_restriction_flag = get_bits1(gb);
173  if (sps->bitstream_restriction_flag) {
174  get_bits1(gb); /* motion_vectors_over_pic_boundaries_flag */
175  get_ue_golomb_31(gb); /* max_bytes_per_pic_denom */
176  get_ue_golomb_31(gb); /* max_bits_per_mb_denom */
177  get_ue_golomb_31(gb); /* log2_max_mv_length_horizontal */
178  get_ue_golomb_31(gb); /* log2_max_mv_length_vertical */
179  sps->num_reorder_frames = get_ue_golomb_31(gb);
180  sps->max_dec_frame_buffering = get_ue_golomb_31(gb);
181 
182  if (get_bits_left(gb) < 0) {
183  sps->num_reorder_frames = 0;
184  sps->bitstream_restriction_flag = 0;
185  }
186 
187  if (sps->num_reorder_frames > 16U
188  /* max_dec_frame_buffering || max_dec_frame_buffering > 16 */) {
189  av_log(logctx, AV_LOG_ERROR,
190  "Clipping illegal num_reorder_frames %d\n",
191  sps->num_reorder_frames);
192  sps->num_reorder_frames = 16;
193  return AVERROR_INVALIDDATA;
194  }
195  }
196 
197  return 0;
198 }
199 
200 static int decode_scaling_list(GetBitContext *gb, uint8_t *factors, int size,
201  const uint8_t *jvt_list, const uint8_t *fallback_list,
202  uint16_t *mask, int pos)
203 {
204  int i, last = 8, next = 8;
205  const uint8_t *scan = size == 16 ? ff_zigzag_scan : ff_zigzag_direct;
206  uint16_t seq_scaling_list_present_flag = get_bits1(gb);
207  *mask |= (seq_scaling_list_present_flag << pos);
208  if (!seq_scaling_list_present_flag) /* matrix not written, we use the predicted one */
209  memcpy(factors, fallback_list, size * sizeof(uint8_t));
210  else
211  for (i = 0; i < size; i++) {
212  if (next) {
213  int v = get_se_golomb(gb);
214  if (v < -128 || v > 127) {
215  av_log(NULL, AV_LOG_ERROR, "delta scale %d is invalid\n", v);
216  return AVERROR_INVALIDDATA;
217  }
218  next = (last + v) & 0xff;
219  }
220  if (!i && !next) { /* matrix not written, we use the preset one */
221  memcpy(factors, jvt_list, size * sizeof(uint8_t));
222  break;
223  }
224  last = factors[scan[i]] = next ? next : last;
225  }
226  return 0;
227 }
228 
229 /* returns non zero if the provided SPS scaling matrix has been filled */
231  const PPS *pps, int is_sps,
232  int present_flag, uint16_t *mask,
233  uint8_t(*scaling_matrix4)[16],
234  uint8_t(*scaling_matrix8)[64])
235 {
236  int fallback_sps = !is_sps && sps->scaling_matrix_present;
237  const uint8_t *fallback[4] = {
238  fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0],
239  fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1],
240  fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0],
241  fallback_sps ? sps->scaling_matrix8[3] : default_scaling8[1]
242  };
243  int ret = 0;
244  *mask = 0x0;
245  if (present_flag) {
246  ret |= decode_scaling_list(gb, scaling_matrix4[0], 16, default_scaling4[0], fallback[0], mask, 0); // Intra, Y
247  ret |= decode_scaling_list(gb, scaling_matrix4[1], 16, default_scaling4[0], scaling_matrix4[0], mask, 1); // Intra, Cr
248  ret |= decode_scaling_list(gb, scaling_matrix4[2], 16, default_scaling4[0], scaling_matrix4[1], mask, 2); // Intra, Cb
249  ret |= decode_scaling_list(gb, scaling_matrix4[3], 16, default_scaling4[1], fallback[1], mask, 3); // Inter, Y
250  ret |= decode_scaling_list(gb, scaling_matrix4[4], 16, default_scaling4[1], scaling_matrix4[3], mask, 4); // Inter, Cr
251  ret |= decode_scaling_list(gb, scaling_matrix4[5], 16, default_scaling4[1], scaling_matrix4[4], mask, 5); // Inter, Cb
252  if (is_sps || pps->transform_8x8_mode) {
253  ret |= decode_scaling_list(gb, scaling_matrix8[0], 64, default_scaling8[0], fallback[2], mask, 6); // Intra, Y
254  ret |= decode_scaling_list(gb, scaling_matrix8[3], 64, default_scaling8[1], fallback[3], mask, 7); // Inter, Y
255  if (sps->chroma_format_idc == 3) {
256  ret |= decode_scaling_list(gb, scaling_matrix8[1], 64, default_scaling8[0], scaling_matrix8[0], mask, 8); // Intra, Cr
257  ret |= decode_scaling_list(gb, scaling_matrix8[4], 64, default_scaling8[1], scaling_matrix8[3], mask, 9); // Inter, Cr
258  ret |= decode_scaling_list(gb, scaling_matrix8[2], 64, default_scaling8[0], scaling_matrix8[1], mask, 10); // Intra, Cb
259  ret |= decode_scaling_list(gb, scaling_matrix8[5], 64, default_scaling8[1], scaling_matrix8[4], mask, 11); // Inter, Cb
260  }
261  }
262  if (!ret)
263  ret = is_sps;
264  }
265 
266  return ret;
267 }
268 
270 {
271  int i;
272 
273  for (i = 0; i < MAX_SPS_COUNT; i++)
274  av_buffer_unref(&ps->sps_list[i]);
275 
276  for (i = 0; i < MAX_PPS_COUNT; i++)
277  av_buffer_unref(&ps->pps_list[i]);
278 
279  av_buffer_unref(&ps->pps_ref);
280 
281  ps->pps = NULL;
282  ps->sps = NULL;
283 }
284 
286  H264ParamSets *ps, int ignore_truncation)
287 {
288  AVBufferRef *sps_buf;
289  int profile_idc, level_idc, constraint_set_flags = 0;
290  unsigned int sps_id;
291  int i, log2_max_frame_num_minus4;
292  SPS *sps;
293  int ret;
294 
295  sps_buf = av_buffer_allocz(sizeof(*sps));
296  if (!sps_buf)
297  return AVERROR(ENOMEM);
298  sps = (SPS*)sps_buf->data;
299 
300  sps->data_size = gb->buffer_end - gb->buffer;
301  if (sps->data_size > sizeof(sps->data)) {
302  av_log(avctx, AV_LOG_DEBUG, "Truncating likely oversized SPS\n");
303  sps->data_size = sizeof(sps->data);
304  }
305  memcpy(sps->data, gb->buffer, sps->data_size);
306 
307  // Re-add the removed stop bit (may be used by hwaccels).
308  if (!(gb->size_in_bits & 7) && sps->data_size < sizeof(sps->data))
309  sps->data[sps->data_size++] = 0x80;
310 
311  profile_idc = get_bits(gb, 8);
312  constraint_set_flags |= get_bits1(gb) << 0; // constraint_set0_flag
313  constraint_set_flags |= get_bits1(gb) << 1; // constraint_set1_flag
314  constraint_set_flags |= get_bits1(gb) << 2; // constraint_set2_flag
315  constraint_set_flags |= get_bits1(gb) << 3; // constraint_set3_flag
316  constraint_set_flags |= get_bits1(gb) << 4; // constraint_set4_flag
317  constraint_set_flags |= get_bits1(gb) << 5; // constraint_set5_flag
318  skip_bits(gb, 2); // reserved_zero_2bits
319  level_idc = get_bits(gb, 8);
320  sps_id = get_ue_golomb_31(gb);
321 
322  if (sps_id >= MAX_SPS_COUNT) {
323  av_log(avctx, AV_LOG_ERROR, "sps_id %u out of range\n", sps_id);
324  goto fail;
325  }
326 
327  sps->sps_id = sps_id;
328  sps->time_offset_length = 24;
329  sps->profile_idc = profile_idc;
330  sps->constraint_set_flags = constraint_set_flags;
331  sps->level_idc = level_idc;
332  sps->vui.video_full_range_flag = -1;
333 
334  memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
335  memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
336  sps->scaling_matrix_present = 0;
337  sps->vui.matrix_coeffs = AVCOL_SPC_UNSPECIFIED;
338 
339  if (sps->profile_idc == 100 || // High profile
340  sps->profile_idc == 110 || // High10 profile
341  sps->profile_idc == 122 || // High422 profile
342  sps->profile_idc == 244 || // High444 Predictive profile
343  sps->profile_idc == 44 || // Cavlc444 profile
344  sps->profile_idc == 83 || // Scalable Constrained High profile (SVC)
345  sps->profile_idc == 86 || // Scalable High Intra profile (SVC)
346  sps->profile_idc == 118 || // Stereo High profile (MVC)
347  sps->profile_idc == 128 || // Multiview High profile (MVC)
348  sps->profile_idc == 138 || // Multiview Depth High profile (MVCD)
349  sps->profile_idc == 144) { // old High444 profile
350  sps->chroma_format_idc = get_ue_golomb_31(gb);
351  if (sps->chroma_format_idc > 3U) {
352  avpriv_request_sample(avctx, "chroma_format_idc %u",
353  sps->chroma_format_idc);
354  goto fail;
355  } else if (sps->chroma_format_idc == 3) {
356  sps->residual_color_transform_flag = get_bits1(gb);
357  if (sps->residual_color_transform_flag) {
358  av_log(avctx, AV_LOG_ERROR, "separate color planes are not supported\n");
359  goto fail;
360  }
361  }
362  sps->bit_depth_luma = get_ue_golomb_31(gb) + 8;
363  sps->bit_depth_chroma = get_ue_golomb_31(gb) + 8;
364  if (sps->bit_depth_chroma != sps->bit_depth_luma) {
365  avpriv_request_sample(avctx,
366  "Different chroma and luma bit depth");
367  goto fail;
368  }
369  if (sps->bit_depth_luma < 8 || sps->bit_depth_luma > 14 ||
370  sps->bit_depth_chroma < 8 || sps->bit_depth_chroma > 14) {
371  av_log(avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n",
372  sps->bit_depth_luma, sps->bit_depth_chroma);
373  goto fail;
374  }
375  sps->transform_bypass = get_bits1(gb);
377  &sps->scaling_matrix_present_mask,
378  sps->scaling_matrix4, sps->scaling_matrix8);
379  if (ret < 0)
380  goto fail;
381  sps->scaling_matrix_present |= ret;
382  } else {
383  sps->chroma_format_idc = 1;
384  sps->bit_depth_luma = 8;
385  sps->bit_depth_chroma = 8;
386  }
387 
388  log2_max_frame_num_minus4 = get_ue_golomb_31(gb);
389  if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 ||
390  log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) {
391  av_log(avctx, AV_LOG_ERROR,
392  "log2_max_frame_num_minus4 out of range (0-12): %d\n",
393  log2_max_frame_num_minus4);
394  goto fail;
395  }
396  sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
397 
398  sps->poc_type = get_ue_golomb_31(gb);
399 
400  if (sps->poc_type == 0) { // FIXME #define
401  unsigned t = get_ue_golomb_31(gb);
402  if (t>12) {
403  av_log(avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t);
404  goto fail;
405  }
406  sps->log2_max_poc_lsb = t + 4;
407  } else if (sps->poc_type == 1) { // FIXME #define
408  sps->delta_pic_order_always_zero_flag = get_bits1(gb);
409  sps->offset_for_non_ref_pic = get_se_golomb_long(gb);
410  sps->offset_for_top_to_bottom_field = get_se_golomb_long(gb);
411 
412  if ( sps->offset_for_non_ref_pic == INT32_MIN
413  || sps->offset_for_top_to_bottom_field == INT32_MIN
414  ) {
415  av_log(avctx, AV_LOG_ERROR,
416  "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
417  goto fail;
418  }
419 
420  sps->poc_cycle_length = get_ue_golomb(gb);
421 
422  if ((unsigned)sps->poc_cycle_length >=
423  FF_ARRAY_ELEMS(sps->offset_for_ref_frame)) {
424  av_log(avctx, AV_LOG_ERROR,
425  "poc_cycle_length overflow %d\n", sps->poc_cycle_length);
426  goto fail;
427  }
428 
429  for (i = 0; i < sps->poc_cycle_length; i++) {
430  sps->offset_for_ref_frame[i] = get_se_golomb_long(gb);
431  if (sps->offset_for_ref_frame[i] == INT32_MIN) {
432  av_log(avctx, AV_LOG_ERROR,
433  "offset_for_ref_frame is out of range\n");
434  goto fail;
435  }
436  }
437  } else if (sps->poc_type != 2) {
438  av_log(avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type);
439  goto fail;
440  }
441 
442  sps->ref_frame_count = get_ue_golomb_31(gb);
443  if (avctx->codec_tag == MKTAG('S', 'M', 'V', '2'))
444  sps->ref_frame_count = FFMAX(2, sps->ref_frame_count);
445  if (sps->ref_frame_count > H264_MAX_DPB_FRAMES) {
446  av_log(avctx, AV_LOG_ERROR,
447  "too many reference frames %d\n", sps->ref_frame_count);
448  goto fail;
449  }
450  sps->gaps_in_frame_num_allowed_flag = get_bits1(gb);
451  sps->mb_width = get_ue_golomb(gb) + 1;
452  sps->mb_height = get_ue_golomb(gb) + 1;
453 
454  sps->frame_mbs_only_flag = get_bits1(gb);
455 
456  if (sps->mb_height >= INT_MAX / 2U) {
457  av_log(avctx, AV_LOG_ERROR, "height overflow\n");
458  goto fail;
459  }
460  sps->mb_height *= 2 - sps->frame_mbs_only_flag;
461 
462  if (!sps->frame_mbs_only_flag)
463  sps->mb_aff = get_bits1(gb);
464  else
465  sps->mb_aff = 0;
466 
467  if ((unsigned)sps->mb_width >= INT_MAX / 16 ||
468  (unsigned)sps->mb_height >= INT_MAX / 16 ||
469  av_image_check_size(16 * sps->mb_width,
470  16 * sps->mb_height, 0, avctx)) {
471  av_log(avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
472  goto fail;
473  }
474 
475  sps->direct_8x8_inference_flag = get_bits1(gb);
476 
477  sps->crop = get_bits1(gb);
478  if (sps->crop) {
479  unsigned int crop_left = get_ue_golomb(gb);
480  unsigned int crop_right = get_ue_golomb(gb);
481  unsigned int crop_top = get_ue_golomb(gb);
482  unsigned int crop_bottom = get_ue_golomb(gb);
483  int width = 16 * sps->mb_width;
484  int height = 16 * sps->mb_height;
485 
486  if (avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) {
487  av_log(avctx, AV_LOG_DEBUG, "discarding sps cropping, original "
488  "values are l:%d r:%d t:%d b:%d\n",
489  crop_left, crop_right, crop_top, crop_bottom);
490 
491  sps->crop_left =
492  sps->crop_right =
493  sps->crop_top =
494  sps->crop_bottom = 0;
495  } else {
496  int vsub = (sps->chroma_format_idc == 1) ? 1 : 0;
497  int hsub = (sps->chroma_format_idc == 1 ||
498  sps->chroma_format_idc == 2) ? 1 : 0;
499  int step_x = 1 << hsub;
500  int step_y = (2 - sps->frame_mbs_only_flag) << vsub;
501 
502  if (crop_left > (unsigned)INT_MAX / 4 / step_x ||
503  crop_right > (unsigned)INT_MAX / 4 / step_x ||
504  crop_top > (unsigned)INT_MAX / 4 / step_y ||
505  crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
506  (crop_left + crop_right ) * step_x >= width ||
507  (crop_top + crop_bottom) * step_y >= height
508  ) {
509  av_log(avctx, AV_LOG_ERROR, "crop values invalid %d %d %d %d / %d %d\n", crop_left, crop_right, crop_top, crop_bottom, width, height);
510  goto fail;
511  }
512 
513  sps->crop_left = crop_left * step_x;
514  sps->crop_right = crop_right * step_x;
515  sps->crop_top = crop_top * step_y;
516  sps->crop_bottom = crop_bottom * step_y;
517  }
518  } else {
519  sps->crop_left =
520  sps->crop_right =
521  sps->crop_top =
522  sps->crop_bottom =
523  sps->crop = 0;
524  }
525 
526  sps->vui_parameters_present_flag = get_bits1(gb);
527  if (sps->vui_parameters_present_flag) {
528  int ret = decode_vui_parameters(gb, avctx, sps);
529  if (ret < 0)
530  goto fail;
531  }
532 
533  if (get_bits_left(gb) < 0) {
534  av_log_once(avctx, ignore_truncation ? AV_LOG_WARNING : AV_LOG_ERROR, AV_LOG_DEBUG,
535  &ps->overread_warning_printed[sps->vui_parameters_present_flag],
536  "Overread %s by %d bits\n", sps->vui_parameters_present_flag ? "VUI" : "SPS", -get_bits_left(gb));
537  if (!ignore_truncation)
538  goto fail;
539  }
540 
541  /* if the maximum delay is not stored in the SPS, derive it based on the
542  * level */
543  if (!sps->bitstream_restriction_flag &&
544  (sps->ref_frame_count || avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT)) {
545  sps->num_reorder_frames = H264_MAX_DPB_FRAMES - 1;
546  for (i = 0; i < FF_ARRAY_ELEMS(level_max_dpb_mbs); i++) {
547  if (level_max_dpb_mbs[i][0] == sps->level_idc) {
548  sps->num_reorder_frames = FFMIN(level_max_dpb_mbs[i][1] / (sps->mb_width * sps->mb_height),
549  sps->num_reorder_frames);
550  break;
551  }
552  }
553  }
554 
555  if (!sps->vui.sar.den)
556  sps->vui.sar.den = 1;
557 
558  if (avctx->debug & FF_DEBUG_PICT_INFO) {
559  static const char csp[4][5] = { "Gray", "420", "422", "444" };
560  av_log(avctx, AV_LOG_DEBUG,
561  "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%u/%u/%u/%u %s %s %"PRId32"/%"PRId32" b%d reo:%d\n",
562  sps_id, sps->profile_idc, sps->level_idc,
563  sps->poc_type,
564  sps->ref_frame_count,
565  sps->mb_width, sps->mb_height,
566  sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"),
567  sps->direct_8x8_inference_flag ? "8B8" : "",
568  sps->crop_left, sps->crop_right,
569  sps->crop_top, sps->crop_bottom,
570  sps->vui_parameters_present_flag ? "VUI" : "",
571  csp[sps->chroma_format_idc],
572  sps->timing_info_present_flag ? sps->num_units_in_tick : 0,
573  sps->timing_info_present_flag ? sps->time_scale : 0,
574  sps->bit_depth_luma,
575  sps->bitstream_restriction_flag ? sps->num_reorder_frames : -1
576  );
577  }
578 
579  /* check if this is a repeat of an already parsed SPS, then keep the
580  * original one.
581  * otherwise drop all PPSes that depend on it */
582  if (ps->sps_list[sps_id] &&
583  !memcmp(ps->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) {
584  av_buffer_unref(&sps_buf);
585  } else {
586  remove_sps(ps, sps_id);
587  ps->sps_list[sps_id] = sps_buf;
588  }
589 
590  return 0;
591 
592 fail:
593  av_buffer_unref(&sps_buf);
594  return AVERROR_INVALIDDATA;
595 }
596 
597 static void init_dequant8_coeff_table(PPS *pps, const SPS *sps)
598 {
599  int i, j, q, x;
600  const int max_qp = 51 + 6 * (sps->bit_depth_luma - 8);
601 
602  for (i = 0; i < 6; i++) {
603  pps->dequant8_coeff[i] = pps->dequant8_buffer[i];
604  for (j = 0; j < i; j++)
605  if (!memcmp(pps->scaling_matrix8[j], pps->scaling_matrix8[i],
606  64 * sizeof(uint8_t))) {
607  pps->dequant8_coeff[i] = pps->dequant8_buffer[j];
608  break;
609  }
610  if (j < i)
611  continue;
612 
613  for (q = 0; q < max_qp + 1; q++) {
614  int shift = ff_h264_quant_div6[q];
615  int idx = ff_h264_quant_rem6[q];
616  for (x = 0; x < 64; x++)
617  pps->dequant8_coeff[i][q][(x >> 3) | ((x & 7) << 3)] =
618  ((uint32_t)ff_h264_dequant8_coeff_init[idx][ff_h264_dequant8_coeff_init_scan[((x >> 1) & 12) | (x & 3)]] *
619  pps->scaling_matrix8[i][x]) << shift;
620  }
621  }
622 }
623 
624 static void init_dequant4_coeff_table(PPS *pps, const SPS *sps)
625 {
626  int i, j, q, x;
627  const int max_qp = 51 + 6 * (sps->bit_depth_luma - 8);
628  for (i = 0; i < 6; i++) {
629  pps->dequant4_coeff[i] = pps->dequant4_buffer[i];
630  for (j = 0; j < i; j++)
631  if (!memcmp(pps->scaling_matrix4[j], pps->scaling_matrix4[i],
632  16 * sizeof(uint8_t))) {
633  pps->dequant4_coeff[i] = pps->dequant4_buffer[j];
634  break;
635  }
636  if (j < i)
637  continue;
638 
639  for (q = 0; q < max_qp + 1; q++) {
640  int shift = ff_h264_quant_div6[q] + 2;
641  int idx = ff_h264_quant_rem6[q];
642  for (x = 0; x < 16; x++)
643  pps->dequant4_coeff[i][q][(x >> 2) | ((x << 2) & 0xF)] =
644  ((uint32_t)ff_h264_dequant4_coeff_init[idx][(x & 1) + ((x >> 2) & 1)] *
645  pps->scaling_matrix4[i][x]) << shift;
646  }
647  }
648 }
649 
650 static void init_dequant_tables(PPS *pps, const SPS *sps)
651 {
652  int i, x;
654  memset(pps->dequant8_coeff, 0, sizeof(pps->dequant8_coeff));
655 
656  if (pps->transform_8x8_mode)
658  if (sps->transform_bypass) {
659  for (i = 0; i < 6; i++)
660  for (x = 0; x < 16; x++)
661  pps->dequant4_coeff[i][0][x] = 1 << 6;
662  if (pps->transform_8x8_mode)
663  for (i = 0; i < 6; i++)
664  for (x = 0; x < 64; x++)
665  pps->dequant8_coeff[i][0][x] = 1 << 6;
666  }
667 }
668 
669 static void build_qp_table(PPS *pps, int t, int index, const int depth)
670 {
671  int i;
672  const int max_qp = 51 + 6 * (depth - 8);
673  for (i = 0; i < max_qp + 1; i++)
674  pps->chroma_qp_table[t][i] =
675  ff_h264_chroma_qp[depth - 8][av_clip(i + index, 0, max_qp)];
676 }
677 
678 static int more_rbsp_data_in_pps(const SPS *sps, void *logctx)
679 {
680  int profile_idc = sps->profile_idc;
681 
682  if ((profile_idc == 66 || profile_idc == 77 ||
683  profile_idc == 88) && (sps->constraint_set_flags & 7)) {
684  av_log(logctx, AV_LOG_VERBOSE,
685  "Current profile doesn't provide more RBSP data in PPS, skipping\n");
686  return 0;
687  }
688 
689  return 1;
690 }
691 
692 static void pps_free(void *opaque, uint8_t *data)
693 {
694  PPS *pps = (PPS*)data;
695 
696  av_buffer_unref(&pps->sps_ref);
697 
698  av_freep(&data);
699 }
700 
702  H264ParamSets *ps, int bit_length)
703 {
704  AVBufferRef *pps_buf;
705  const SPS *sps;
706  unsigned int pps_id = get_ue_golomb(gb);
707  PPS *pps;
708  int qp_bd_offset;
709  int bits_left;
710  int ret;
711 
712  if (pps_id >= MAX_PPS_COUNT) {
713  av_log(avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id);
714  return AVERROR_INVALIDDATA;
715  }
716 
717  pps = av_mallocz(sizeof(*pps));
718  if (!pps)
719  return AVERROR(ENOMEM);
720  pps_buf = av_buffer_create((uint8_t*)pps, sizeof(*pps),
721  pps_free, NULL, 0);
722  if (!pps_buf) {
723  av_freep(&pps);
724  return AVERROR(ENOMEM);
725  }
726 
727  pps->data_size = gb->buffer_end - gb->buffer;
728  if (pps->data_size > sizeof(pps->data)) {
729  av_log(avctx, AV_LOG_DEBUG, "Truncating likely oversized PPS "
730  "(%"SIZE_SPECIFIER" > %"SIZE_SPECIFIER")\n",
731  pps->data_size, sizeof(pps->data));
732  pps->data_size = sizeof(pps->data);
733  }
734  memcpy(pps->data, gb->buffer, pps->data_size);
735 
736  // Re-add the removed stop bit (may be used by hwaccels).
737  if (!(bit_length & 7) && pps->data_size < sizeof(pps->data))
738  pps->data[pps->data_size++] = 0x80;
739 
740  pps->pps_id = pps_id;
741  pps->sps_id = get_ue_golomb_31(gb);
742  if ((unsigned)pps->sps_id >= MAX_SPS_COUNT ||
743  !ps->sps_list[pps->sps_id]) {
744  av_log(avctx, AV_LOG_ERROR, "sps_id %u out of range\n", pps->sps_id);
746  goto fail;
747  }
748  pps->sps_ref = av_buffer_ref(ps->sps_list[pps->sps_id]);
749  if (!pps->sps_ref) {
750  ret = AVERROR(ENOMEM);
751  goto fail;
752  }
753  pps->sps = (const SPS*)pps->sps_ref->data;
754  sps = pps->sps;
755 
756  if (sps->bit_depth_luma > 14) {
757  av_log(avctx, AV_LOG_ERROR,
758  "Invalid luma bit depth=%d\n",
759  sps->bit_depth_luma);
761  goto fail;
762  } else if (sps->bit_depth_luma == 11 || sps->bit_depth_luma == 13) {
764  "Unimplemented luma bit depth=%d",
765  sps->bit_depth_luma);
767  goto fail;
768  }
769 
770  pps->cabac = get_bits1(gb);
771  pps->pic_order_present = get_bits1(gb);
772  pps->slice_group_count = get_ue_golomb(gb) + 1;
773  if (pps->slice_group_count > 1) {
774  pps->mb_slice_group_map_type = get_ue_golomb(gb);
775  avpriv_report_missing_feature(avctx, "FMO");
777  goto fail;
778  }
779  pps->ref_count[0] = get_ue_golomb(gb) + 1;
780  pps->ref_count[1] = get_ue_golomb(gb) + 1;
781  if (pps->ref_count[0] - 1 > 32 - 1 || pps->ref_count[1] - 1 > 32 - 1) {
782  av_log(avctx, AV_LOG_ERROR, "reference overflow (pps)\n");
784  goto fail;
785  }
786 
787  qp_bd_offset = 6 * (sps->bit_depth_luma - 8);
788 
789  pps->weighted_pred = get_bits1(gb);
790  pps->weighted_bipred_idc = get_bits(gb, 2);
791  pps->init_qp = get_se_golomb(gb) + 26U + qp_bd_offset;
792  pps->init_qs = get_se_golomb(gb) + 26U + qp_bd_offset;
793  pps->chroma_qp_index_offset[0] = get_se_golomb(gb);
794  if (pps->chroma_qp_index_offset[0] < -12 || pps->chroma_qp_index_offset[0] > 12) {
796  goto fail;
797  }
798 
799  pps->deblocking_filter_parameters_present = get_bits1(gb);
800  pps->constrained_intra_pred = get_bits1(gb);
801  pps->redundant_pic_cnt_present = get_bits1(gb);
802 
803  pps->transform_8x8_mode = 0;
804  memcpy(pps->scaling_matrix4, sps->scaling_matrix4,
805  sizeof(pps->scaling_matrix4));
806  memcpy(pps->scaling_matrix8, sps->scaling_matrix8,
807  sizeof(pps->scaling_matrix8));
808 
809  bits_left = bit_length - get_bits_count(gb);
810  if (bits_left > 0 && more_rbsp_data_in_pps(sps, avctx)) {
811  pps->transform_8x8_mode = get_bits1(gb);
812  pps->pic_scaling_matrix_present_flag = get_bits1(gb);
814  pps->pic_scaling_matrix_present_flag,
815  &pps->pic_scaling_matrix_present_mask,
816  pps->scaling_matrix4, pps->scaling_matrix8);
817  if (ret < 0)
818  goto fail;
819  // second_chroma_qp_index_offset
820  pps->chroma_qp_index_offset[1] = get_se_golomb(gb);
821  if (pps->chroma_qp_index_offset[1] < -12 || pps->chroma_qp_index_offset[1] > 12) {
823  goto fail;
824  }
825  } else {
826  pps->chroma_qp_index_offset[1] = pps->chroma_qp_index_offset[0];
827  }
828 
829  build_qp_table(pps, 0, pps->chroma_qp_index_offset[0],
830  sps->bit_depth_luma);
831  build_qp_table(pps, 1, pps->chroma_qp_index_offset[1],
832  sps->bit_depth_luma);
833 
835 
836  if (pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1])
837  pps->chroma_qp_diff = 1;
838 
839  if (avctx->debug & FF_DEBUG_PICT_INFO) {
840  av_log(avctx, AV_LOG_DEBUG,
841  "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
842  pps_id, pps->sps_id,
843  pps->cabac ? "CABAC" : "CAVLC",
844  pps->slice_group_count,
845  pps->ref_count[0], pps->ref_count[1],
846  pps->weighted_pred ? "weighted" : "",
847  pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1],
848  pps->deblocking_filter_parameters_present ? "LPAR" : "",
849  pps->constrained_intra_pred ? "CONSTR" : "",
850  pps->redundant_pic_cnt_present ? "REDU" : "",
851  pps->transform_8x8_mode ? "8x8DCT" : "");
852  }
853 
854  remove_pps(ps, pps_id);
855  ps->pps_list[pps_id] = pps_buf;
856 
857  return 0;
858 
859 fail:
860  av_buffer_unref(&pps_buf);
861  return ret;
862 }
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
H264ParamSets::sps
const SPS * sps
Definition: h264_ps.h:153
av_clip
#define av_clip
Definition: common.h:95
show_bits1
static unsigned int show_bits1(GetBitContext *s)
Definition: get_bits.h:398
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:664
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
ff_h264_ps_uninit
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition: h264_ps.c:269
pps_free
static void pps_free(void *opaque, uint8_t *data)
Definition: h264_ps.c:692
get_se_golomb_long
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:294
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:411
ff_h264_chroma_qp
const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM+1]
Definition: h264data.c:203
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:256
GetBitContext::size_in_bits
int size_in_bits
Definition: get_bits.h:110
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
level_idc
int level_idc
Definition: h264_levels.c:25
data
const char data[16]
Definition: mxf.c:148
FF_COMPLIANCE_STRICT
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition: defs.h:59
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
init_dequant_tables
static void init_dequant_tables(PPS *pps, const SPS *sps)
Definition: h264_ps.c:650
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1383
AV_CODEC_FLAG2_IGNORE_CROP
#define AV_CODEC_FLAG2_IGNORE_CROP
Discard cropping information from SPS.
Definition: avcodec.h:363
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:74
ff_h264_decode_picture_parameter_set
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)
Decode PPS.
Definition: h264_ps.c:701
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:371
golomb.h
exp golomb vlc stuff
remove_pps
static void remove_pps(H264ParamSets *s, int id)
Definition: h264_ps.c:86
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:325
fail
#define fail()
Definition: checkasm.h:137
GetBitContext
Definition: get_bits.h:107
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
mask
static const uint16_t mask[17]
Definition: lzw.c:38
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:256
H264ParamSets::overread_warning_printed
int overread_warning_printed[2]
Definition: h264_ps.h:155
h264data.h
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
H264ParamSets::sps_list
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: h264_ps.h:147
get_se_golomb
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:239
if
if(ret)
Definition: filter_design.txt:179
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:108
NULL
#define NULL
Definition: coverity.c:32
bits_left
#define bits_left
Definition: bitstream.h:113
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
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
profile_idc
int profile_idc
Definition: h264_levels.c:53
more_rbsp_data_in_pps
static int more_rbsp_data_in_pps(const SPS *sps, void *logctx)
Definition: h264_ps.c:678
ff_h264_dequant8_coeff_init_scan
const uint8_t ff_h264_dequant8_coeff_init_scan[16]
Definition: h264data.c:161
SPS
Sequence parameter set.
Definition: h264_ps.h:45
decode_scaling_list
static int decode_scaling_list(GetBitContext *gb, uint8_t *factors, int size, const uint8_t *jvt_list, const uint8_t *fallback_list, uint16_t *mask, int pos)
Definition: h264_ps.c:200
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:378
PPS
Picture parameter set.
Definition: h264_ps.h:111
mathops.h
MAX_PPS_COUNT
#define MAX_PPS_COUNT
Definition: h264_ps.h:39
level_max_dpb_mbs
static const int level_max_dpb_mbs[][2]
Definition: h264_ps.c:67
h264_ps.h
index
int index
Definition: gxfenc.c:89
decode_hrd_parameters
static int decode_hrd_parameters(GetBitContext *gb, void *logctx, SPS *sps)
Definition: h264_ps.c:105
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:522
ff_zigzag_scan
const uint8_t ff_zigzag_scan[16+1]
Definition: mathtables.c:109
ff_h264_dequant8_coeff_init
const uint8_t ff_h264_dequant8_coeff_init[6][6]
Definition: h264data.c:165
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
shift
static int shift(int a, int b)
Definition: bonk.c:262
size
int size
Definition: twinvq_data.h:10344
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
remove_sps
static void remove_sps(H264ParamSets *s, int id)
Definition: h264_ps.c:91
init_dequant8_coeff_table
static void init_dequant8_coeff_table(PPS *pps, const SPS *sps)
Definition: h264_ps.c:597
MAX_LOG2_MAX_FRAME_NUM
#define MAX_LOG2_MAX_FRAME_NUM
Definition: h264_ps.h:40
height
#define height
ff_h264_quant_rem6
const uint8_t ff_h264_quant_rem6[QP_MAX_NUM+1]
Definition: h264data.c:174
decode_vui_parameters
static int decode_vui_parameters(GetBitContext *gb, void *logctx, SPS *sps)
Definition: h264_ps.c:132
MIN_LOG2_MAX_FRAME_NUM
#define MIN_LOG2_MAX_FRAME_NUM
Definition: h264_ps.c:38
AVBufferRef::size
size_t size
Size of data in bytes.
Definition: buffer.h:94
default_scaling4
static const uint8_t default_scaling4[2][16]
Definition: h264_ps.c:40
ff_h264_decode_seq_parameter_set
int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation)
Decode SPS.
Definition: h264_ps.c:285
H264_MAX_DPB_FRAMES
@ H264_MAX_DPB_FRAMES
Definition: h264.h:76
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
decode_scaling_matrices
static int decode_scaling_matrices(GetBitContext *gb, const SPS *sps, const PPS *pps, int is_sps, int present_flag, uint16_t *mask, uint8_t(*scaling_matrix4)[16], uint8_t(*scaling_matrix8)[64])
Definition: h264_ps.c:230
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
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:598
GetBitContext::buffer_end
const uint8_t * buffer_end
Definition: get_bits.h:108
avcodec.h
ff_zigzag_direct
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
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
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1365
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
default_scaling8
static const uint8_t default_scaling8[2][64]
Definition: h264_ps.c:47
pos
unsigned int pos
Definition: spdifenc.c:413
build_qp_table
static void build_qp_table(PPS *pps, int t, int index, const int depth)
Definition: h264_ps.c:669
U
#define U(x)
Definition: vpx_arith.h:37
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:149
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
AVCodecContext
main external API structure.
Definition: avcodec.h:435
ff_h264_dequant4_coeff_init
const uint8_t ff_h264_dequant4_coeff_init[6][3]
Definition: h264data.c:152
get_ue_golomb_31
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition: golomb.h:120
H264ParamSets::pps_list
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: h264_ps.h:148
H264ParamSets
Definition: h264_ps.h:146
MAX_SPS_COUNT
#define MAX_SPS_COUNT
Definition: h264_ps.h:38
ff_h264_quant_div6
const uint8_t ff_h264_quant_div6[QP_MAX_NUM+1]
Definition: h264data.c:182
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1382
av_log_once
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition: log.c:417
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
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
init_dequant4_coeff_table
static void init_dequant4_coeff_table(PPS *pps, const SPS *sps)
Definition: h264_ps.c:624
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:460
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
H264ParamSets::pps
const PPS * pps
Definition: h264_ps.h:152
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
H264ParamSets::pps_ref
AVBufferRef * pps_ref
Definition: h264_ps.h:150