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;
81 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
87 v, v, file, func, line);
91 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
94 int64_t v =
get_s(bc);
97 v, v, file, func, line);
101 static inline uint64_t get_4cc_trace(
AVIOContext *bc,
char *file,
107 v, v, file, func, line);
110 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
111 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
112 #define get_fourcc(bc) get_4cc_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
116 int calculate_checksum, uint64_t startcode)
145 state = (state << 8) |
avio_r8(bc);
146 if ((state >> 56) !=
'N')
171 if (startcode == code)
173 else if (startcode == 0)
185 code = (code << 8) | p->
buf[i];
192 #define GET_V(dst, check) \
194 tmp = ffio_read_varlen(bc); \
196 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
220 unsigned int stream_count;
222 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
227 GET_V(tmp, tmp >= 2 && tmp <= 3);
251 for (i = 0; i < 256;) {
272 count = tmp_mul - tmp_size;
278 while (tmp_fields-- > 8)
281 if (count == 0 || i + count > 256) {
285 if (tmp_stream >= stream_count) {
290 for (j = 0; j < count; j++, i++) {
334 for (i = 0; i < stream_count; i++)
345 int class, stream_id;
353 stc = &nut->
stream[stream_id];
358 class = ffio_read_varlen(bc);
394 "Unknown codec tag '0x%04x' for stream number %d\n",
395 (
unsigned int) tmp, stream_id);
429 "stream header %d checksum mismatch\n", stream_id);
449 if (stream_id == i || stream_id == -1)
457 uint64_t tmp, chapter_start, chapter_len;
458 unsigned int stream_id_plus1, count;
461 char name[256], str_value[1024], type_str[256];
470 GET_V(stream_id_plus1, tmp <= s->nb_streams);
471 chapter_id =
get_s(bc);
476 if (chapter_id && !stream_id_plus1) {
481 start, start + chapter_len,
NULL);
483 }
else if (stream_id_plus1) {
484 st = s->
streams[stream_id_plus1 - 1];
489 for (i = 0; i < count; i++) {
490 get_str(bc, name,
sizeof(name));
494 get_str(bc, str_value,
sizeof(str_value));
495 }
else if (value == -2) {
496 get_str(bc, type_str,
sizeof(type_str));
498 get_str(bc, str_value,
sizeof(str_value));
499 }
else if (value == -3) {
502 }
else if (value == -4) {
505 }
else if (value < -4) {
517 if (!strcmp(type,
"UTF-8")) {
518 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
523 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
524 sscanf(str_value,
"%d/%d", &st->r_frame_rate.num, &st->r_frame_rate.den);
525 if (st->r_frame_rate.num >= 1000LL*st->r_frame_rate.den)
526 st->r_frame_rate.num = st->r_frame_rate.den = 0;
586 duration =
FFMAX(duration, ts);
599 int i, j, syncpoint_count;
602 int8_t *has_keyframe;
622 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
623 syncpoints =
av_malloc(
sizeof(int64_t) * syncpoint_count);
624 has_keyframe =
av_malloc(
sizeof(int8_t) * (syncpoint_count + 1));
625 for (i = 0; i < syncpoint_count; i++) {
627 if (syncpoints[i] <= 0)
630 syncpoints[i] += syncpoints[i - 1];
635 for (j = 0; j < syncpoint_count;) {
643 if (n + x >= syncpoint_count + 1) {
644 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
648 has_keyframe[n++] = flag;
649 has_keyframe[n++] = !flag;
652 if (n >= syncpoint_count + 1) {
656 has_keyframe[n++] = x & 1;
660 if (has_keyframe[0]) {
665 for (; j < n && j < syncpoint_count; j++) {
666 if (has_keyframe[j]) {
699 int initialized_stream_count;
715 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
722 initialized_stream_count++;
731 if (startcode == 0) {
759 uint8_t *header_idx,
int frame_code)
764 int size,
flags, size_mul, pts_delta, i, reserved_count;
769 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
787 GET_V(*stream_id, tmp < s->nb_streams);
789 stc = &nut->
stream[*stream_id];
807 for (i = 0; i < reserved_count; i++)
836 int size, stream_id, discard;
837 int64_t pts, last_IP_pts;
845 stc = &nut->
stream[stream_id];
854 last_IP_pts > pts) ||
879 int i, frame_code = 0, ret, skip;
880 int64_t ts, back_ptr;
893 if (frame_code ==
'N') {
895 for (i = 1; i < 8; i++)
896 tmp = (tmp << 8) +
avio_r8(bc);
933 int64_t *pos_arg, int64_t pos_limit)
937 int64_t pos, pts, back_ptr;
939 stream_index, *pos_arg, pos_limit);
953 if (stream_index == -2)
960 int64_t pts,
int flags)
966 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
967 int64_t pos, pos2, ts;
981 (
void **) next_node);
983 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
986 next_node[1]->
pos, next_node[1]->
pos,
987 next_node[0]->
ts, next_node[1]->
ts,
991 dummy.
pos = pos + 16;
992 next_node[1] = &nopts_sp;
994 (
void **) next_node);
996 next_node[1]->
pos, next_node[1]->
pos,
1014 if (pos2 > pos || pos2 + 15 < pos)
1046 .extensions =
"nut",