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;
71 }
else if (state <= 2) {
78 }
else if (state <= 5) {
79 int nalu_type = buf[i] & 0x1F;
122 return i - (state & 5) - 3 * (state > 7);
139 for (list = 0; list < h->
list_count; list++) {
142 for (index = 0; ; index++) {
145 if (reordering_of_pic_nums_idc < 3)
147 else if (reordering_of_pic_nums_idc > 3) {
149 "illegal reordering_of_pic_nums_idc %d\n",
150 reordering_of_pic_nums_idc);
157 "reference count %d overflow\n", index);
175 "illegal memory management control operation %d\n",
208 const uint8_t *buf_end = buf + buf_size;
210 unsigned int slice_type;
211 int state = -1, got_reset = 0;
213 int q264 = buf_size >=4 && !memcmp(
"Q264", buf, 4);
229 int src_length, dst_length, consumed, nalsize = 0;
235 nalsize = (nalsize << 8) | *buf++;
236 if (nalsize <= 0 || nalsize > buf_end - buf) {
240 src_length = nalsize;
246 src_length = buf_end -
buf;
248 switch (state & 0x1f) {
252 if ((state & 0x1f) ==
NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
259 if (src_length > 1000)
265 if (ptr == NULL || dst_length < 0)
298 "pps_id %u out of range\n", pps_id);
303 "non-existing PPS %u referenced\n", pps_id);
309 "non-existing SPS %u referenced\n", h->
pps.
sps_id);
352 field_poc[0] = field_poc[1] = INT_MAX;
425 if (field_poc[0] < field_poc[1])
427 else if (field_poc[0] > field_poc[1])
442 buf += h->
is_avc ? nalsize : consumed;
453 const uint8_t **poutbuf,
int *poutbuf_size,
508 *poutbuf_size = buf_size;
519 for (i = 0; i <= buf_size; i++) {
520 if ((state & 0xFFFFFF1F) == 0x107)
527 if ((state & 0xFFFFFF00) == 0x100 && (state & 0xFFFFFF1F) != 0x107 &&
528 (state & 0xFFFFFF1F) != 0x108 && (state & 0xFFFFFF1F) != 0x109) {
530 while (i > 4 && buf[i - 5] == 0)
536 state = (state << 8) | buf[i];
564 .parser_close =
close,