33 #define NUT_MAX_STREAMS 256
36 int64_t *pos_arg, int64_t pos_limit);
44 while (len > maxlen) {
50 string[
FFMIN(len, maxlen - 1)] = 0;
83 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
89 v, v, file, func, line);
93 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
99 v, v, file, func, line);
103 static inline uint64_t get_4cc_trace(
AVIOContext *bc,
char *file,
109 v, v, file, func, line);
112 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
113 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
114 #define get_fourcc(bc) get_4cc_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
118 int calculate_checksum, uint64_t startcode)
147 state = (state << 8) |
avio_r8(bc);
148 if ((state >> 56) !=
'N')
173 if (startcode == code)
175 else if (startcode == 0)
187 code = (code << 8) | p->
buf[i];
194 #define GET_V(dst, check) \
196 tmp = ffio_read_varlen(bc); \
198 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
199 return AVERROR_INVALIDDATA; \
222 unsigned int stream_count;
224 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
259 for (i = 0; i < 256;) {
280 count = tmp_mul - tmp_size;
286 while (tmp_fields-- > 8)
289 if (count == 0 || i + count > 256) {
293 if (tmp_stream >= stream_count) {
298 for (j = 0; j <
count; j++, i++) {
342 for (i = 0; i < stream_count; i++)
353 int class, stream_id;
361 stc = &nut->
stream[stream_id];
366 class = ffio_read_varlen(bc);
402 "Unknown codec tag '0x%04x' for stream number %d\n",
403 (
unsigned int) tmp, stream_id);
437 "stream header %d checksum mismatch\n", stream_id);
457 if (stream_id == i || stream_id == -1)
465 uint64_t tmp, chapter_start, chapter_len;
466 unsigned int stream_id_plus1,
count;
469 char name[256], str_value[1024], type_str[256];
478 GET_V(stream_id_plus1, tmp <= s->nb_streams);
479 chapter_id =
get_s(bc);
484 if (chapter_id && !stream_id_plus1) {
489 start, start + chapter_len, NULL);
491 }
else if (stream_id_plus1) {
492 st = s->
streams[stream_id_plus1 - 1];
497 for (i = 0; i <
count; i++) {
498 get_str(bc, name,
sizeof(name));
502 get_str(bc, str_value,
sizeof(str_value));
503 }
else if (value == -2) {
504 get_str(bc, type_str,
sizeof(type_str));
506 get_str(bc, str_value,
sizeof(str_value));
507 }
else if (value == -3) {
510 }
else if (value == -4) {
513 }
else if (value < -4) {
525 if (!strcmp(type,
"UTF-8")) {
526 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
531 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
601 int i, j, syncpoint_count;
605 int8_t *has_keyframe;
630 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
631 syncpoints =
av_malloc(
sizeof(int64_t) * syncpoint_count);
632 has_keyframe =
av_malloc(
sizeof(int8_t) * (syncpoint_count + 1));
633 for (i = 0; i < syncpoint_count; i++) {
635 if (syncpoints[i] <= 0)
638 syncpoints[i] += syncpoints[i - 1];
643 for (j = 0; j < syncpoint_count;) {
651 if (n + x >= syncpoint_count + 1) {
652 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
656 has_keyframe[n++] = flag;
657 has_keyframe[n++] = !flag;
660 if (n >= syncpoint_count + 1) {
664 has_keyframe[n++] = x & 1;
668 if (has_keyframe[0]) {
673 for (; j < n && j < syncpoint_count; j++) {
674 if (has_keyframe[j]) {
707 int initialized_stream_count;
723 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
730 initialized_stream_count++;
739 if (startcode == 0) {
767 uint8_t *header_idx,
int frame_code)
772 int size,
flags, size_mul, pts_delta, i, reserved_count;
777 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
795 GET_V(*stream_id, tmp < s->nb_streams);
797 stc = &nut->
stream[*stream_id];
815 for (i = 0; i < reserved_count; i++)
844 int size, stream_id, discard;
845 int64_t pts, last_IP_pts;
853 stc = &nut->
stream[stream_id];
862 last_IP_pts > pts) ||
887 int i, frame_code = 0,
ret, skip;
888 int64_t ts, back_ptr;
901 if (frame_code ==
'N') {
903 for (i = 1; i < 8; i++)
904 tmp = (tmp << 8) +
avio_r8(bc);
941 int64_t *pos_arg, int64_t pos_limit)
945 int64_t pos, pts, back_ptr;
947 stream_index, *pos_arg, pos_limit);
961 if (stream_index == -2)
968 int64_t pts,
int flags)
974 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
975 int64_t pos, pos2, ts;
989 (
void **) next_node);
991 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
994 next_node[1]->
pos, next_node[1]->
pos,
995 next_node[0]->
ts, next_node[1]->
ts,
999 dummy.
pos = pos + 16;
1000 next_node[1] = &nopts_sp;
1002 (
void **) next_node);
1004 next_node[1]->
pos, next_node[1]->
pos,
1022 if (pos2 > pos || pos2 + 15 < pos)
1054 .extensions =
"nut",