28 #define UNCHECKED_BITSTREAM_READER 1
43 int next_avc= h->
is_avc ? 0 : buf_size;
53 for (i = 0; i < buf_size; i++) {
58 nalsize = (nalsize << 8) | buf[i++];
59 if (nalsize <= 0 || nalsize > buf_size - i) {
63 next_avc = i + nalsize;
68 #if HAVE_FAST_UNALIGNED
74 while (i < next_avc &&
75 !((~*(
const uint64_t *)(buf + i) &
76 (*(
const uint64_t *)(buf + i) - 0x0101010101010101ULL)) &
77 0x8080808080808080ULL))
80 while (i < next_avc &&
81 !((~*(
const uint32_t *)(buf + i) &
82 (*(
const uint32_t *)(buf + i) - 0x01010101U)) &
87 for (; i < next_avc; i++)
92 }
else if (state <= 2) {
99 }
else if (state <= 5) {
100 int v = buf[i] & 0x1F;
101 if (v == 6 || v == 7 || v == 8 || v == 9) {
106 }
else if (v == 1 || v == 2 || v == 5) {
141 return i - (state & 5) - 3 * (state > 7);
157 const uint8_t *buf_end = buf + buf_size;
159 unsigned int slice_type;
162 int q264 = buf_size >=4 && !memcmp(
"Q264", buf, 4);
180 int src_length, dst_length, consumed, nalsize = 0;
186 nalsize = (nalsize << 8) | *buf++;
187 if (nalsize <= 0 || nalsize > buf_end - buf) {
191 src_length = nalsize;
197 src_length = buf_end -
buf;
199 switch (state & 0x1f) {
208 if (ptr == NULL || dst_length < 0)
241 "pps_id out of range\n");
246 "non-existing PPS referenced\n");
252 "non-existing SPS referenced\n");
338 if (field_poc[0] < field_poc[1])
340 else if (field_poc[0] > field_poc[1])
355 buf += h->
is_avc ? nalsize : consumed;
366 const uint8_t **poutbuf,
int *poutbuf_size,
421 *poutbuf_size = buf_size;
432 for (i = 0; i <= buf_size; i++) {
433 if ((state & 0xFFFFFF1F) == 0x107)
440 if ((state & 0xFFFFFF00) == 0x100 && (state & 0xFFFFFF1F) != 0x107 &&
441 (state & 0xFFFFFF1F) != 0x108 && (state & 0xFFFFFF1F) != 0x109) {
443 while (i > 4 && buf[i - 5] == 0)
449 state = (state << 8) | buf[i];
476 .parser_close =
close,