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); \
222 unsigned int stream_count;
224 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
229 GET_V(tmp, tmp >= 2 && tmp <= 3);
253 for (i = 0; i < 256;) {
274 count = tmp_mul - tmp_size;
280 while (tmp_fields-- > 8)
283 if (count == 0 || i + count > 256) {
287 if (tmp_stream >= stream_count) {
292 for (j = 0; j < count; j++, i++) {
336 for (i = 0; i < stream_count; i++)
347 int class, stream_id;
355 stc = &nut->
stream[stream_id];
360 class = ffio_read_varlen(bc);
396 "Unknown codec tag '0x%04x' for stream number %d\n",
397 (
unsigned int) tmp, stream_id);
431 "stream header %d checksum mismatch\n", stream_id);
451 if (stream_id == i || stream_id == -1)
459 uint64_t tmp, chapter_start, chapter_len;
460 unsigned int stream_id_plus1, count;
463 char name[256], str_value[1024], type_str[256];
472 GET_V(stream_id_plus1, tmp <= s->nb_streams);
473 chapter_id =
get_s(bc);
478 if (chapter_id && !stream_id_plus1) {
483 start, start + chapter_len,
NULL);
485 }
else if (stream_id_plus1) {
486 st = s->
streams[stream_id_plus1 - 1];
491 for (i = 0; i < count; i++) {
492 get_str(bc, name,
sizeof(name));
496 get_str(bc, str_value,
sizeof(str_value));
497 }
else if (value == -2) {
498 get_str(bc, type_str,
sizeof(type_str));
500 get_str(bc, str_value,
sizeof(str_value));
501 }
else if (value == -3) {
504 }
else if (value == -4) {
507 }
else if (value < -4) {
519 if (!strcmp(type,
"UTF-8")) {
520 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
525 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
526 sscanf(str_value,
"%d/%d", &st->r_frame_rate.num, &st->r_frame_rate.den);
527 if (st->r_frame_rate.num >= 1000LL*st->r_frame_rate.den)
528 st->r_frame_rate.num = st->r_frame_rate.den = 0;
588 duration =
FFMAX(duration, ts);
601 int i, j, syncpoint_count;
604 int8_t *has_keyframe;
624 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
625 syncpoints =
av_malloc(
sizeof(int64_t) * syncpoint_count);
626 has_keyframe =
av_malloc(
sizeof(int8_t) * (syncpoint_count + 1));
627 for (i = 0; i < syncpoint_count; i++) {
629 if (syncpoints[i] <= 0)
632 syncpoints[i] += syncpoints[i - 1];
637 for (j = 0; j < syncpoint_count;) {
645 if (n + x >= syncpoint_count + 1) {
646 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
650 has_keyframe[n++] = flag;
651 has_keyframe[n++] = !flag;
654 if (n >= syncpoint_count + 1) {
658 has_keyframe[n++] = x & 1;
662 if (has_keyframe[0]) {
667 for (; j < n && j < syncpoint_count; j++) {
668 if (has_keyframe[j]) {
701 int initialized_stream_count;
717 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
724 initialized_stream_count++;
733 if (startcode == 0) {
761 uint8_t *header_idx,
int frame_code)
766 int size,
flags, size_mul, pts_delta, i, reserved_count;
771 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
789 GET_V(*stream_id, tmp < s->nb_streams);
791 stc = &nut->
stream[*stream_id];
809 for (i = 0; i < reserved_count; i++)
838 int size, stream_id, discard;
839 int64_t pts, last_IP_pts;
847 stc = &nut->
stream[stream_id];
856 last_IP_pts > pts) ||
881 int i, frame_code = 0, ret, skip;
882 int64_t ts, back_ptr;
895 if (frame_code ==
'N') {
897 for (i = 1; i < 8; i++)
898 tmp = (tmp << 8) +
avio_r8(bc);
935 int64_t *pos_arg, int64_t pos_limit)
939 int64_t pos, pts, back_ptr;
941 stream_index, *pos_arg, pos_limit);
955 if (stream_index == -2)
962 int64_t pts,
int flags)
968 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
969 int64_t pos, pos2, ts;
983 (
void **) next_node);
985 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
988 next_node[1]->
pos, next_node[1]->
pos,
989 next_node[0]->
ts, next_node[1]->
ts,
993 dummy.
pos = pos + 16;
994 next_node[1] = &nopts_sp;
996 (
void **) next_node);
998 next_node[1]->
pos, next_node[1]->
pos,
1016 if (pos2 > pos || pos2 + 15 < pos)
1048 .extensions =
"nut",