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 v = buf[i] & 0x1F;
80 if (v == 6 || v == 7 || v == 8 || v == 9) {
85 }
else if (v == 1 || v == 2 || v == 5) {
120 return i - (state & 5) - 3 * (state > 7);
137 for (list = 0; list < h->
list_count; list++) {
140 for (index = 0; ; index++) {
143 if (reordering_of_pic_nums_idc < 3)
145 else if (reordering_of_pic_nums_idc > 3) {
147 "illegal reordering_of_pic_nums_idc %d\n",
148 reordering_of_pic_nums_idc);
172 "illegal memory management control operation %d\n",
205 const uint8_t *buf_end = buf + buf_size;
207 unsigned int slice_type;
208 int state = -1, got_reset = 0;
210 int q264 = buf_size >=4 && !memcmp(
"Q264", buf, 4);
226 int src_length, dst_length, consumed, nalsize = 0;
232 nalsize = (nalsize << 8) | *buf++;
233 if (nalsize <= 0 || nalsize > buf_end - buf) {
237 src_length = nalsize;
243 src_length = buf_end -
buf;
245 switch (state & 0x1f) {
249 if ((state & 0x1f) ==
NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
256 if (src_length > 1000)
262 if (ptr == NULL || dst_length < 0)
295 "pps_id out of range\n");
300 "non-existing PPS referenced\n");
306 "non-existing SPS referenced\n");
349 field_poc[0] = field_poc[1] = INT_MAX;
422 if (field_poc[0] < field_poc[1])
424 else if (field_poc[0] > field_poc[1])
439 buf += h->
is_avc ? nalsize : consumed;
450 const uint8_t **poutbuf,
int *poutbuf_size,
505 *poutbuf_size = buf_size;
516 for (i = 0; i <= buf_size; i++) {
517 if ((state & 0xFFFFFF1F) == 0x107)
524 if ((state & 0xFFFFFF00) == 0x100 && (state & 0xFFFFFF1F) != 0x107 &&
525 (state & 0xFFFFFF1F) != 0x108 && (state & 0xFFFFFF1F) != 0x109) {
527 while (i > 4 && buf[i - 5] == 0)
533 state = (state << 8) | buf[i];
561 .parser_close =
close,