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)
85 av_log(
NULL, AV_LOG_DEBUG,
"get_v %5"PRId64
" / %"PRIX64
" in %s %s:%d\n",
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);
95 av_log(
NULL, AV_LOG_DEBUG,
"get_s %5"PRId64
" / %"PRIX64
" in %s %s:%d\n",
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); \
209 unsigned int stream_count;
211 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
216 GET_V(tmp, tmp >= 2 && tmp <= 3);
240 for (i = 0; i < 256;) {
261 count = tmp_mul - tmp_size;
267 while (tmp_fields-- > 8)
270 if (count == 0 || i + count > 256) {
274 if (tmp_stream >= stream_count) {
279 for (j = 0; j < count; j++, i++) {
323 for (i = 0; i < stream_count; i++)
334 int class, stream_id;
342 stc = &nut->
stream[stream_id];
383 "Unknown codec tag '0x%04x' for stream number %d\n",
384 (
unsigned int) tmp, stream_id);
418 "stream header %d checksum mismatch\n", stream_id);
438 if (stream_id == i || stream_id == -1)
446 uint64_t tmp, chapter_start, chapter_len;
447 unsigned int stream_id_plus1, count;
450 char name[256], str_value[1024], type_str[256];
459 GET_V(stream_id_plus1, tmp <= s->nb_streams);
460 chapter_id =
get_s(bc);
465 if (chapter_id && !stream_id_plus1) {
470 start, start + chapter_len,
NULL);
472 }
else if (stream_id_plus1) {
473 st = s->
streams[stream_id_plus1 - 1];
478 for (i = 0; i < count; i++) {
479 get_str(bc, name,
sizeof(name));
483 get_str(bc, str_value,
sizeof(str_value));
484 }
else if (value == -2) {
485 get_str(bc, type_str,
sizeof(type_str));
487 get_str(bc, str_value,
sizeof(str_value));
488 }
else if (value == -3) {
491 }
else if (value == -4) {
494 }
else if (value < -4) {
506 if (!strcmp(type,
"UTF-8")) {
507 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
563 int i, j, syncpoint_count;
566 int8_t *has_keyframe;
580 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
581 syncpoints =
av_malloc(
sizeof(int64_t) * syncpoint_count);
582 has_keyframe =
av_malloc(
sizeof(int8_t) * (syncpoint_count + 1));
583 for (i = 0; i < syncpoint_count; i++) {
585 if (syncpoints[i] <= 0)
588 syncpoints[i] += syncpoints[i - 1];
592 int64_t last_pts = -1;
593 for (j = 0; j < syncpoint_count;) {
601 if (n + x >= syncpoint_count + 1) {
606 has_keyframe[n++] = flag;
607 has_keyframe[n++] = !flag;
610 if (n >= syncpoint_count + 1) {
614 has_keyframe[n++] = x & 1;
618 if (has_keyframe[0]) {
622 assert(n <= syncpoint_count + 1);
623 for (; j < n && j < syncpoint_count; j++) {
624 if (has_keyframe[j]) {
657 int initialized_stream_count;
673 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
680 initialized_stream_count++;
689 if (startcode == 0) {
717 uint8_t *header_idx,
int frame_code)
722 int size,
flags, size_mul, pts_delta, i, reserved_count;
727 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
745 GET_V(*stream_id, tmp < s->nb_streams);
747 stc = &nut->
stream[*stream_id];
765 for (i = 0; i < reserved_count; i++)
794 int size, stream_id, discard;
795 int64_t pts, last_IP_pts;
803 stc = &nut->
stream[stream_id];
812 last_IP_pts > pts) ||
836 int i, frame_code = 0, ret, skip;
837 int64_t ts, back_ptr;
850 if (frame_code ==
'N') {
852 for (i = 1; i < 8; i++)
853 tmp = (tmp << 8) +
avio_r8(bc);
890 int64_t *pos_arg, int64_t pos_limit)
894 int64_t pos, pts, back_ptr;
896 stream_index, *pos_arg, pos_limit);
911 if (stream_index == -1)
913 else if (stream_index == -2)
920 int64_t pts,
int flags)
926 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
927 int64_t pos, pos2, ts;
939 (
void **) next_node);
941 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
944 next_node[1]->
pos, next_node[1]->
pos,
945 next_node[0]->
ts, next_node[1]->
ts,
949 dummy.
pos = pos + 16;
950 next_node[1] = &nopts_sp;
952 (
void **) next_node);
954 next_node[1]->
pos, next_node[1]->
pos,
972 if (pos2 > pos || pos2 + 15 < pos)
1003 .extensions =
"nut",