35 #define NUT_MAX_STREAMS 256
43 while (len > maxlen) {
49 string[
FFMIN(len, maxlen - 1)] = 0;
80 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
81 const char *func,
int line)
86 v, v, file, func, line);
90 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
91 const char *func,
int line)
93 int64_t v =
get_s(bc);
96 v, v, file, func, line);
100 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
101 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
105 int calculate_checksum, uint64_t startcode)
134 state = (state << 8) |
avio_r8(bc);
135 if ((state >> 56) !=
'N')
160 if (startcode == code)
162 else if (startcode == 0)
174 code = (code << 8) | p->
buf[i];
181 #define GET_V(dst, check) \
183 tmp = ffio_read_varlen(bc); \
185 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
186 return AVERROR_INVALIDDATA; \
209 unsigned int stream_count;
211 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
246 for (i = 0; i < 256;) {
267 count = tmp_mul - tmp_size;
273 while (tmp_fields-- > 8)
276 if (count == 0 || i + count > 256) {
280 if (tmp_stream >= stream_count) {
285 for (j = 0; j < count; j++, i++) {
329 for (i = 0; i < stream_count; i++)
340 int class, stream_id;
348 stc = &nut->
stream[stream_id];
389 "Unknown codec tag '0x%04x' for stream number %d\n",
390 (
unsigned int) tmp, stream_id);
424 "stream header %d checksum mismatch\n", stream_id);
444 if (stream_id == i || stream_id == -1)
452 uint64_t tmp, chapter_start, chapter_len;
453 unsigned int stream_id_plus1, count;
456 char name[256], str_value[1024], type_str[256];
465 GET_V(stream_id_plus1, tmp <= s->nb_streams);
466 chapter_id =
get_s(bc);
471 if (chapter_id && !stream_id_plus1) {
476 start, start + chapter_len,
NULL);
478 }
else if (stream_id_plus1) {
479 st = s->
streams[stream_id_plus1 - 1];
484 for (i = 0; i < count; i++) {
485 get_str(bc, name,
sizeof(name));
489 get_str(bc, str_value,
sizeof(str_value));
490 }
else if (value == -2) {
491 get_str(bc, type_str,
sizeof(type_str));
493 get_str(bc, str_value,
sizeof(str_value));
494 }
else if (value == -3) {
497 }
else if (value == -4) {
500 }
else if (value < -4) {
512 if (!strcmp(type,
"UTF-8")) {
513 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
569 int i, j, syncpoint_count;
572 int8_t *has_keyframe;
586 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
587 syncpoints =
av_malloc(
sizeof(int64_t) * syncpoint_count);
588 has_keyframe =
av_malloc(
sizeof(int8_t) * (syncpoint_count + 1));
589 for (i = 0; i < syncpoint_count; i++) {
591 if (syncpoints[i] <= 0)
594 syncpoints[i] += syncpoints[i - 1];
598 int64_t last_pts = -1;
599 for (j = 0; j < syncpoint_count;) {
607 if (n + x >= syncpoint_count + 1) {
612 has_keyframe[n++] = flag;
613 has_keyframe[n++] = !flag;
616 if (n >= syncpoint_count + 1) {
620 has_keyframe[n++] = x & 1;
624 if (has_keyframe[0]) {
628 assert(n <= syncpoint_count + 1);
629 for (; j < n && j < syncpoint_count; j++) {
630 if (has_keyframe[j]) {
663 int initialized_stream_count;
679 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
686 initialized_stream_count++;
695 if (startcode == 0) {
723 uint8_t *header_idx,
int frame_code)
728 int size,
flags, size_mul, pts_delta, i, reserved_count;
733 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
751 GET_V(*stream_id, tmp < s->nb_streams);
753 stc = &nut->
stream[*stream_id];
771 for (i = 0; i < reserved_count; i++)
800 int size, stream_id, discard;
801 int64_t pts, last_IP_pts;
809 stc = &nut->
stream[stream_id];
818 last_IP_pts > pts) ||
842 int i, frame_code = 0, ret, skip;
843 int64_t ts, back_ptr;
856 if (frame_code ==
'N') {
858 for (i = 1; i < 8; i++)
859 tmp = (tmp << 8) +
avio_r8(bc);
896 int64_t *pos_arg, int64_t pos_limit)
900 int64_t pos, pts, back_ptr;
902 stream_index, *pos_arg, pos_limit);
917 if (stream_index == -1)
919 else if (stream_index == -2)
926 int64_t pts,
int flags)
932 Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
933 int64_t pos, pos2, ts;
945 (
void **) next_node);
947 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
950 next_node[1]->
pos, next_node[1]->
pos,
951 next_node[0]->
ts, next_node[1]->
ts,
955 dummy.
pos = pos + 16;
956 next_node[1] = &nopts_sp;
958 (
void **) next_node);
960 next_node[1]->
pos, next_node[1]->
pos,
978 if (pos2 > pos || pos2 + 15 < pos)
1009 .extensions =
"nut",