FFmpeg
h2645_parse.c
Go to the documentation of this file.
1 /*
2  * H.264/HEVC common parsing code
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <string.h>
22 
23 #include "config.h"
24 
25 #include "libavutil/intmath.h"
26 #include "libavutil/intreadwrite.h"
27 #include "libavutil/mem.h"
28 
29 #include "bytestream.h"
30 #include "hevc.h"
31 #include "h264.h"
32 #include "h2645_parse.h"
33 
34 int ff_h2645_extract_rbsp(const uint8_t *src, int length,
35  H2645RBSP *rbsp, H2645NAL *nal, int small_padding)
36 {
37  int i, si, di;
38  uint8_t *dst;
39 
40  nal->skipped_bytes = 0;
41 #define STARTCODE_TEST \
42  if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
43  if (src[i + 2] != 3 && src[i + 2] != 0) { \
44  /* startcode, so we must be past the end */ \
45  length = i; \
46  } \
47  break; \
48  }
49 #if HAVE_FAST_UNALIGNED
50 #define FIND_FIRST_ZERO \
51  if (i > 0 && !src[i]) \
52  i--; \
53  while (src[i]) \
54  i++
55 #if HAVE_FAST_64BIT
56  for (i = 0; i + 1 < length; i += 9) {
57  if (!((~AV_RN64(src + i) &
58  (AV_RN64(src + i) - 0x0100010001000101ULL)) &
59  0x8000800080008080ULL))
60  continue;
61  FIND_FIRST_ZERO;
63  i -= 7;
64  }
65 #else
66  for (i = 0; i + 1 < length; i += 5) {
67  if (!((~AV_RN32(src + i) &
68  (AV_RN32(src + i) - 0x01000101U)) &
69  0x80008080U))
70  continue;
71  FIND_FIRST_ZERO;
73  i -= 3;
74  }
75 #endif /* HAVE_FAST_64BIT */
76 #else
77  for (i = 0; i + 1 < length; i += 2) {
78  if (src[i])
79  continue;
80  if (i > 0 && src[i - 1] == 0)
81  i--;
83  }
84 #endif /* HAVE_FAST_UNALIGNED */
85 
86  if (i >= length - 1 && small_padding) { // no escaped 0
87  nal->data =
88  nal->raw_data = src;
89  nal->size =
90  nal->raw_size = length;
91  return length;
92  } else if (i > length)
93  i = length;
94 
95  dst = &rbsp->rbsp_buffer[rbsp->rbsp_buffer_size];
96 
97  memcpy(dst, src, i);
98  si = di = i;
99  while (si + 2 < length) {
100  // remove escapes (very rare 1:2^22)
101  if (src[si + 2] > 3) {
102  dst[di++] = src[si++];
103  dst[di++] = src[si++];
104  } else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) {
105  if (src[si + 2] == 3) { // escape
106  dst[di++] = 0;
107  dst[di++] = 0;
108  si += 3;
109 
110  if (nal->skipped_bytes_pos) {
111  nal->skipped_bytes++;
112  if (nal->skipped_bytes_pos_size < nal->skipped_bytes) {
113  nal->skipped_bytes_pos_size *= 2;
117  sizeof(*nal->skipped_bytes_pos));
118  if (!nal->skipped_bytes_pos) {
119  nal->skipped_bytes_pos_size = 0;
120  return AVERROR(ENOMEM);
121  }
122  }
123  if (nal->skipped_bytes_pos)
124  nal->skipped_bytes_pos[nal->skipped_bytes-1] = di - 1;
125  }
126  continue;
127  } else // next start code
128  goto nsc;
129  }
130 
131  dst[di++] = src[si++];
132  }
133  while (si < length)
134  dst[di++] = src[si++];
135 
136 nsc:
137  memset(dst + di, 0, AV_INPUT_BUFFER_PADDING_SIZE);
138 
139  nal->data = dst;
140  nal->size = di;
141  nal->raw_data = src;
142  nal->raw_size = si;
143  rbsp->rbsp_buffer_size += si;
144 
145  return si;
146 }
147 
148 static const char *const hevc_nal_type_name[64] = {
149  "TRAIL_N", // HEVC_NAL_TRAIL_N
150  "TRAIL_R", // HEVC_NAL_TRAIL_R
151  "TSA_N", // HEVC_NAL_TSA_N
152  "TSA_R", // HEVC_NAL_TSA_R
153  "STSA_N", // HEVC_NAL_STSA_N
154  "STSA_R", // HEVC_NAL_STSA_R
155  "RADL_N", // HEVC_NAL_RADL_N
156  "RADL_R", // HEVC_NAL_RADL_R
157  "RASL_N", // HEVC_NAL_RASL_N
158  "RASL_R", // HEVC_NAL_RASL_R
159  "RSV_VCL_N10", // HEVC_NAL_VCL_N10
160  "RSV_VCL_R11", // HEVC_NAL_VCL_R11
161  "RSV_VCL_N12", // HEVC_NAL_VCL_N12
162  "RSV_VLC_R13", // HEVC_NAL_VCL_R13
163  "RSV_VCL_N14", // HEVC_NAL_VCL_N14
164  "RSV_VCL_R15", // HEVC_NAL_VCL_R15
165  "BLA_W_LP", // HEVC_NAL_BLA_W_LP
166  "BLA_W_RADL", // HEVC_NAL_BLA_W_RADL
167  "BLA_N_LP", // HEVC_NAL_BLA_N_LP
168  "IDR_W_RADL", // HEVC_NAL_IDR_W_RADL
169  "IDR_N_LP", // HEVC_NAL_IDR_N_LP
170  "CRA_NUT", // HEVC_NAL_CRA_NUT
171  "RSV_IRAP_VCL22", // HEVC_NAL_RSV_IRAP_VCL22
172  "RSV_IRAP_VCL23", // HEVC_NAL_RSV_IRAP_VCL23
173  "RSV_VCL24", // HEVC_NAL_RSV_VCL24
174  "RSV_VCL25", // HEVC_NAL_RSV_VCL25
175  "RSV_VCL26", // HEVC_NAL_RSV_VCL26
176  "RSV_VCL27", // HEVC_NAL_RSV_VCL27
177  "RSV_VCL28", // HEVC_NAL_RSV_VCL28
178  "RSV_VCL29", // HEVC_NAL_RSV_VCL29
179  "RSV_VCL30", // HEVC_NAL_RSV_VCL30
180  "RSV_VCL31", // HEVC_NAL_RSV_VCL31
181  "VPS", // HEVC_NAL_VPS
182  "SPS", // HEVC_NAL_SPS
183  "PPS", // HEVC_NAL_PPS
184  "AUD", // HEVC_NAL_AUD
185  "EOS_NUT", // HEVC_NAL_EOS_NUT
186  "EOB_NUT", // HEVC_NAL_EOB_NUT
187  "FD_NUT", // HEVC_NAL_FD_NUT
188  "SEI_PREFIX", // HEVC_NAL_SEI_PREFIX
189  "SEI_SUFFIX", // HEVC_NAL_SEI_SUFFIX
190  "RSV_NVCL41", // HEVC_NAL_RSV_NVCL41
191  "RSV_NVCL42", // HEVC_NAL_RSV_NVCL42
192  "RSV_NVCL43", // HEVC_NAL_RSV_NVCL43
193  "RSV_NVCL44", // HEVC_NAL_RSV_NVCL44
194  "RSV_NVCL45", // HEVC_NAL_RSV_NVCL45
195  "RSV_NVCL46", // HEVC_NAL_RSV_NVCL46
196  "RSV_NVCL47", // HEVC_NAL_RSV_NVCL47
197  "UNSPEC48", // HEVC_NAL_UNSPEC48
198  "UNSPEC49", // HEVC_NAL_UNSPEC49
199  "UNSPEC50", // HEVC_NAL_UNSPEC50
200  "UNSPEC51", // HEVC_NAL_UNSPEC51
201  "UNSPEC52", // HEVC_NAL_UNSPEC52
202  "UNSPEC53", // HEVC_NAL_UNSPEC53
203  "UNSPEC54", // HEVC_NAL_UNSPEC54
204  "UNSPEC55", // HEVC_NAL_UNSPEC55
205  "UNSPEC56", // HEVC_NAL_UNSPEC56
206  "UNSPEC57", // HEVC_NAL_UNSPEC57
207  "UNSPEC58", // HEVC_NAL_UNSPEC58
208  "UNSPEC59", // HEVC_NAL_UNSPEC59
209  "UNSPEC60", // HEVC_NAL_UNSPEC60
210  "UNSPEC61", // HEVC_NAL_UNSPEC61
211  "UNSPEC62", // HEVC_NAL_UNSPEC62
212  "UNSPEC63", // HEVC_NAL_UNSPEC63
213 };
214 
215 static const char *hevc_nal_unit_name(int nal_type)
216 {
217  av_assert0(nal_type >= 0 && nal_type < 64);
218  return hevc_nal_type_name[nal_type];
219 }
220 
221 static const char *const h264_nal_type_name[32] = {
222  "Unspecified 0", //H264_NAL_UNSPECIFIED
223  "Coded slice of a non-IDR picture", // H264_NAL_SLICE
224  "Coded slice data partition A", // H264_NAL_DPA
225  "Coded slice data partition B", // H264_NAL_DPB
226  "Coded slice data partition C", // H264_NAL_DPC
227  "IDR", // H264_NAL_IDR_SLICE
228  "SEI", // H264_NAL_SEI
229  "SPS", // H264_NAL_SPS
230  "PPS", // H264_NAL_PPS
231  "AUD", // H264_NAL_AUD
232  "End of sequence", // H264_NAL_END_SEQUENCE
233  "End of stream", // H264_NAL_END_STREAM
234  "Filler data", // H264_NAL_FILLER_DATA
235  "SPS extension", // H264_NAL_SPS_EXT
236  "Prefix", // H264_NAL_PREFIX
237  "Subset SPS", // H264_NAL_SUB_SPS
238  "Depth parameter set", // H264_NAL_DPS
239  "Reserved 17", // H264_NAL_RESERVED17
240  "Reserved 18", // H264_NAL_RESERVED18
241  "Auxiliary coded picture without partitioning", // H264_NAL_AUXILIARY_SLICE
242  "Slice extension", // H264_NAL_EXTEN_SLICE
243  "Slice extension for a depth view or a 3D-AVC texture view", // H264_NAL_DEPTH_EXTEN_SLICE
244  "Reserved 22", // H264_NAL_RESERVED22
245  "Reserved 23", // H264_NAL_RESERVED23
246  "Unspecified 24", // H264_NAL_UNSPECIFIED24
247  "Unspecified 25", // H264_NAL_UNSPECIFIED25
248  "Unspecified 26", // H264_NAL_UNSPECIFIED26
249  "Unspecified 27", // H264_NAL_UNSPECIFIED27
250  "Unspecified 28", // H264_NAL_UNSPECIFIED28
251  "Unspecified 29", // H264_NAL_UNSPECIFIED29
252  "Unspecified 30", // H264_NAL_UNSPECIFIED30
253  "Unspecified 31", // H264_NAL_UNSPECIFIED31
254 };
255 
256 static const char *h264_nal_unit_name(int nal_type)
257 {
258  av_assert0(nal_type >= 0 && nal_type < 32);
259  return h264_nal_type_name[nal_type];
260 }
261 
262 static int get_bit_length(H2645NAL *nal, int skip_trailing_zeros)
263 {
264  int size = nal->size;
265  int v;
266 
267  while (skip_trailing_zeros && size > 0 && nal->data[size - 1] == 0)
268  size--;
269 
270  if (!size)
271  return 0;
272 
273  v = nal->data[size - 1];
274 
275  if (size > INT_MAX / 8)
276  return AVERROR(ERANGE);
277  size *= 8;
278 
279  /* remove the stop bit and following trailing zeros,
280  * or nothing for damaged bitstreams */
281  if (v)
282  size -= ff_ctz(v) + 1;
283 
284  return size;
285 }
286 
287 /**
288  * @return AVERROR_INVALIDDATA if the packet is not a valid NAL unit,
289  * 0 otherwise
290  */
291 static int hevc_parse_nal_header(H2645NAL *nal, void *logctx)
292 {
293  GetBitContext *gb = &nal->gb;
294 
295  if (get_bits1(gb) != 0)
296  return AVERROR_INVALIDDATA;
297 
298  nal->type = get_bits(gb, 6);
299 
300  nal->nuh_layer_id = get_bits(gb, 6);
301  nal->temporal_id = get_bits(gb, 3) - 1;
302  if (nal->temporal_id < 0)
303  return AVERROR_INVALIDDATA;
304 
305  av_log(logctx, AV_LOG_DEBUG,
306  "nal_unit_type: %d(%s), nuh_layer_id: %d, temporal_id: %d\n",
307  nal->type, hevc_nal_unit_name(nal->type), nal->nuh_layer_id, nal->temporal_id);
308 
309  return 0;
310 }
311 
312 static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
313 {
314  GetBitContext *gb = &nal->gb;
315 
316  if (get_bits1(gb) != 0)
317  return AVERROR_INVALIDDATA;
318 
319  nal->ref_idc = get_bits(gb, 2);
320  nal->type = get_bits(gb, 5);
321 
322  av_log(logctx, AV_LOG_DEBUG,
323  "nal_unit_type: %d(%s), nal_ref_idc: %d\n",
324  nal->type, h264_nal_unit_name(nal->type), nal->ref_idc);
325 
326  return 0;
327 }
328 
329 static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc)
330 {
331  int i = 0;
332 
333  if (buf + 3 >= next_avc)
334  return next_avc - buf;
335 
336  while (buf + i + 3 < next_avc) {
337  if (buf[i] == 0 && buf[i + 1] == 0 && buf[i + 2] == 1)
338  break;
339  i++;
340  }
341  return i + 3;
342 }
343 
344 static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref)
345 {
346  int min_size = size;
347 
348  if (size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
349  goto fail;
351 
352  if (rbsp->rbsp_buffer_alloc_size >= size &&
354  av_assert0(rbsp->rbsp_buffer);
355  memset(rbsp->rbsp_buffer + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
356  return;
357  }
358 
359  size = FFMIN(size + size / 16 + 32, INT_MAX);
360 
361  if (rbsp->rbsp_buffer_ref)
363  else
364  av_free(rbsp->rbsp_buffer);
365 
366  rbsp->rbsp_buffer = av_mallocz(size);
367  if (!rbsp->rbsp_buffer)
368  goto fail;
370 
371  if (use_ref) {
373  NULL, NULL, 0);
374  if (!rbsp->rbsp_buffer_ref)
375  goto fail;
376  }
377 
378  return;
379 
380 fail:
381  rbsp->rbsp_buffer_alloc_size = 0;
382  if (rbsp->rbsp_buffer_ref) {
384  rbsp->rbsp_buffer = NULL;
385  } else
386  av_freep(&rbsp->rbsp_buffer);
387 
388  return;
389 }
390 
391 int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
392  void *logctx, int is_nalff, int nal_length_size,
393  enum AVCodecID codec_id, int small_padding, int use_ref)
394 {
395  GetByteContext bc;
396  int consumed, ret = 0;
397  int next_avc = is_nalff ? 0 : length;
398  int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE;
399 
400  bytestream2_init(&bc, buf, length);
401  alloc_rbsp_buffer(&pkt->rbsp, length + padding, use_ref);
402 
403  if (!pkt->rbsp.rbsp_buffer)
404  return AVERROR(ENOMEM);
405 
406  pkt->rbsp.rbsp_buffer_size = 0;
407  pkt->nb_nals = 0;
408  while (bytestream2_get_bytes_left(&bc) >= 4) {
409  H2645NAL *nal;
410  int extract_length = 0;
411  int skip_trailing_zeros = 1;
412 
413  if (bytestream2_tell(&bc) == next_avc) {
414  int i = 0;
415  extract_length = get_nalsize(nal_length_size,
416  bc.buffer, bytestream2_get_bytes_left(&bc), &i, logctx);
417  if (extract_length < 0)
418  return extract_length;
419 
420  bytestream2_skip(&bc, nal_length_size);
421 
422  next_avc = bytestream2_tell(&bc) + extract_length;
423  } else {
424  int buf_index;
425 
426  if (bytestream2_tell(&bc) > next_avc)
427  av_log(logctx, AV_LOG_WARNING, "Exceeded next NALFF position, re-syncing.\n");
428 
429  /* search start code */
430  buf_index = find_next_start_code(bc.buffer, buf + next_avc);
431 
432  bytestream2_skip(&bc, buf_index);
433 
434  if (!bytestream2_get_bytes_left(&bc)) {
435  if (pkt->nb_nals > 0) {
436  // No more start codes: we discarded some irrelevant
437  // bytes at the end of the packet.
438  return 0;
439  } else {
440  av_log(logctx, AV_LOG_ERROR, "No start code is found.\n");
441  return AVERROR_INVALIDDATA;
442  }
443  }
444 
445  extract_length = FFMIN(bytestream2_get_bytes_left(&bc), next_avc - bytestream2_tell(&bc));
446 
447  if (bytestream2_tell(&bc) >= next_avc) {
448  /* skip to the start of the next NAL */
449  bytestream2_skip(&bc, next_avc - bytestream2_tell(&bc));
450  continue;
451  }
452  }
453 
454  if (pkt->nals_allocated < pkt->nb_nals + 1) {
455  int new_size = pkt->nals_allocated + 1;
456  void *tmp;
457 
458  if (new_size >= INT_MAX / sizeof(*pkt->nals))
459  return AVERROR(ENOMEM);
460 
461  tmp = av_fast_realloc(pkt->nals, &pkt->nal_buffer_size, new_size * sizeof(*pkt->nals));
462  if (!tmp)
463  return AVERROR(ENOMEM);
464 
465  pkt->nals = tmp;
466  memset(pkt->nals + pkt->nals_allocated, 0, sizeof(*pkt->nals));
467 
468  nal = &pkt->nals[pkt->nb_nals];
469  nal->skipped_bytes_pos_size = FFMIN(1024, extract_length/3+1); // initial buffer size
471  if (!nal->skipped_bytes_pos)
472  return AVERROR(ENOMEM);
473 
474  pkt->nals_allocated = new_size;
475  }
476  nal = &pkt->nals[pkt->nb_nals];
477 
478  consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, &pkt->rbsp, nal, small_padding);
479  if (consumed < 0)
480  return consumed;
481 
482  if (is_nalff && (extract_length != consumed) && extract_length)
483  av_log(logctx, AV_LOG_DEBUG,
484  "NALFF: Consumed only %d bytes instead of %d\n",
485  consumed, extract_length);
486 
487  bytestream2_skip(&bc, consumed);
488 
489  /* see commit 3566042a0 */
490  if (bytestream2_get_bytes_left(&bc) >= 4 &&
491  bytestream2_peek_be32(&bc) == 0x000001E0)
492  skip_trailing_zeros = 0;
493 
494  nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
495 
496  if (nal->size <= 0 || nal->size_bits <= 0)
497  continue;
498 
499  ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
500  if (ret < 0)
501  return ret;
502 
503  /* Reset type in case it contains a stale value from a previously parsed NAL */
504  nal->type = 0;
505 
506  if (codec_id == AV_CODEC_ID_HEVC)
507  ret = hevc_parse_nal_header(nal, logctx);
508  else
509  ret = h264_parse_nal_header(nal, logctx);
510  if (ret < 0) {
511  av_log(logctx, AV_LOG_WARNING, "Invalid NAL unit %d, skipping.\n",
512  nal->type);
513  continue;
514  }
515 
516  pkt->nb_nals++;
517  }
518 
519  return 0;
520 }
521 
523 {
524  int i;
525  for (i = 0; i < pkt->nals_allocated; i++) {
526  av_freep(&pkt->nals[i].skipped_bytes_pos);
527  }
528  av_freep(&pkt->nals);
529  pkt->nals_allocated = pkt->nal_buffer_size = 0;
530  if (pkt->rbsp.rbsp_buffer_ref) {
531  av_buffer_unref(&pkt->rbsp.rbsp_buffer_ref);
532  pkt->rbsp.rbsp_buffer = NULL;
533  } else
534  av_freep(&pkt->rbsp.rbsp_buffer);
535  pkt->rbsp.rbsp_buffer_alloc_size = pkt->rbsp.rbsp_buffer_size = 0;
536 }
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
h2645_parse.h
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_ctz
#define ff_ctz
Definition: intmath.h:106
STARTCODE_TEST
#define STARTCODE_TEST
GetByteContext
Definition: bytestream.h:33
H2645NAL::ref_idc
int ref_idc
H.264 only, nal_ref_idc.
Definition: h2645_parse.h:57
H2645NAL::nuh_layer_id
int nuh_layer_id
Definition: h2645_parse.h:67
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:368
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
h264_parse_nal_header
static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
Definition: h2645_parse.c:312
ff_h2645_packet_uninit
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:522
find_next_start_code
static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc)
Definition: h2645_parse.c:329
H2645NAL::skipped_bytes_pos_size
int skipped_bytes_pos_size
Definition: h2645_parse.h:70
H2645NAL::temporal_id
int temporal_id
HEVC only, nuh_temporal_id_plus_1 - 1.
Definition: h2645_parse.h:62
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:660
hevc_parse_nal_header
static int hevc_parse_nal_header(H2645NAL *nal, void *logctx)
Definition: h2645_parse.c:291
H2645NAL::size_bits
int size_bits
Size, in bits, of just the data, excluding the stop bit and any trailing padding.
Definition: h2645_parse.h:42
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:380
hevc_nal_unit_name
static const char * hevc_nal_unit_name(int nal_type)
Definition: h2645_parse.c:215
get_bit_length
static int get_bit_length(H2645NAL *nal, int skip_trailing_zeros)
Definition: h2645_parse.c:262
fail
#define fail()
Definition: checkasm.h:127
GetBitContext
Definition: get_bits.h:62
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
H2645NAL::size
int size
Definition: h2645_parse.h:36
h264_nal_type_name
static const char *const h264_nal_type_name[32]
Definition: h2645_parse.c:221
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:504
intreadwrite.h
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
H2645NAL::data
const uint8_t * data
Definition: h2645_parse.h:35
H2645NAL::skipped_bytes_pos
int * skipped_bytes_pos
Definition: h2645_parse.h:71
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
H2645NAL::type
int type
NAL unit type.
Definition: h2645_parse.h:52
H2645NAL::raw_size
int raw_size
Definition: h2645_parse.h:44
NULL
#define NULL
Definition: coverity.c:32
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
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:499
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:364
src
#define src
Definition: vp8dsp.c:255
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
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
H2645NAL::skipped_bytes
int skipped_bytes
Definition: h2645_parse.h:69
H2645RBSP::rbsp_buffer
uint8_t * rbsp_buffer
Definition: h2645_parse.h:75
hevc_nal_type_name
static const char *const hevc_nal_type_name[64]
Definition: h2645_parse.c:148
size
int size
Definition: twinvq_data.h:10344
H2645NAL::gb
GetBitContext gb
Definition: h2645_parse.h:47
H2645NAL
Definition: h2645_parse.h:34
H2645RBSP::rbsp_buffer_size
int rbsp_buffer_size
Definition: h2645_parse.h:78
ff_h2645_packet_split
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int is_nalff, int nal_length_size, enum AVCodecID codec_id, int small_padding, int use_ref)
Split an input packet into NAL units.
Definition: h2645_parse.c:391
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:232
h264_nal_unit_name
static const char * h264_nal_unit_name(int nal_type)
Definition: h2645_parse.c:256
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
ff_h2645_extract_rbsp
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp, H2645NAL *nal, int small_padding)
Extract the raw (unescaped) bitstream.
Definition: h2645_parse.c:34
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:224
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:263
H2645RBSP::rbsp_buffer_ref
AVBufferRef * rbsp_buffer_ref
Definition: h2645_parse.h:76
hevc.h
H2645RBSP::rbsp_buffer_alloc_size
int rbsp_buffer_alloc_size
Definition: h2645_parse.h:77
av_buffer_is_writable
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:147
ret
ret
Definition: filter_design.txt:187
H2645NAL::raw_data
const uint8_t * raw_data
Definition: h2645_parse.h:45
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
MAX_MBPAIR_SIZE
#define MAX_MBPAIR_SIZE
Definition: h2645_parse.h:32
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
bytestream.h
h264.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
get_nalsize
static int get_nalsize(int nal_length_size, const uint8_t *buf, int buf_size, int *buf_index, void *logctx)
Definition: h2645_parse.h:119
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
H2645Packet
Definition: h2645_parse.h:82
H2645RBSP
Definition: h2645_parse.h:74
alloc_rbsp_buffer
static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref)
Definition: h2645_parse.c:344
intmath.h