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