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;
261 for (i = 0; i < 256;) {
282 count = tmp_mul - tmp_size;
288 while (tmp_fields-- > 8)
291 if (count == 0 || i + count > 256) {
295 if (tmp_stream >= stream_count) {
300 for (j = 0; j <
count; j++, i++) {
346 for (i = 0; i < stream_count; i++)
357 int class, stream_id;
365 stc = &nut->
stream[stream_id];
370 class = ffio_read_varlen(bc);
406 "Unknown codec tag '0x%04x' for stream number %d\n",
407 (
unsigned int) tmp, stream_id);
441 "stream header %d checksum mismatch\n", stream_id);
461 if (stream_id == i || stream_id == -1)
469 uint64_t tmp, chapter_start, chapter_len;
470 unsigned int stream_id_plus1,
count;
473 char name[256], str_value[1024], type_str[256];
482 GET_V(stream_id_plus1, tmp <= s->nb_streams);
483 chapter_id =
get_s(bc);
488 if (chapter_id && !stream_id_plus1) {
493 start, start + chapter_len, NULL);
495 }
else if (stream_id_plus1) {
496 st = s->
streams[stream_id_plus1 - 1];
501 for (i = 0; i <
count; i++) {
502 get_str(bc, name,
sizeof(name));
506 get_str(bc, str_value,
sizeof(str_value));
507 }
else if (value == -2) {
508 get_str(bc, type_str,
sizeof(type_str));
510 get_str(bc, str_value,
sizeof(str_value));
511 }
else if (value == -3) {
514 }
else if (value == -4) {
517 }
else if (value < -4) {
529 if (!strcmp(type,
"UTF-8")) {
530 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
535 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
608 int i, j, syncpoint_count;
612 int8_t *has_keyframe;
637 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
638 syncpoints = av_malloc_array(syncpoint_count,
sizeof(int64_t));
639 has_keyframe = av_malloc_array(syncpoint_count + 1,
sizeof(int8_t));
640 if (!syncpoints || !has_keyframe) {
644 for (i = 0; i < syncpoint_count; i++) {
646 if (syncpoints[i] <= 0)
649 syncpoints[i] += syncpoints[i - 1];
654 for (j = 0; j < syncpoint_count;) {
662 if (n + x >= syncpoint_count + 1) {
663 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
667 has_keyframe[n++] = flag;
668 has_keyframe[n++] = !flag;
671 if (n >= syncpoint_count + 1) {
675 has_keyframe[n++] = x & 1;
679 if (has_keyframe[0]) {
684 for (; j < n && j < syncpoint_count; j++) {
685 if (has_keyframe[j]) {
718 int initialized_stream_count;
734 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
741 initialized_stream_count++;
750 if (startcode == 0) {
778 uint8_t *header_idx,
int frame_code)
783 int size,
flags, size_mul, pts_delta, i, reserved_count;
788 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
806 GET_V(*stream_id, tmp < s->nb_streams);
808 stc = &nut->
stream[*stream_id];
826 for (i = 0; i < reserved_count; i++)
855 int size, stream_id, discard;
856 int64_t pts, last_IP_pts;
864 stc = &nut->
stream[stream_id];
873 last_IP_pts > pts) ||
898 int i, frame_code = 0,
ret, skip;
899 int64_t ts, back_ptr;
912 if (frame_code ==
'N') {
914 for (i = 1; i < 8; i++)
915 tmp = (tmp << 8) +
avio_r8(bc);
952 int64_t *pos_arg, int64_t pos_limit)
956 int64_t pos, pts, back_ptr;
958 stream_index, *pos_arg, pos_limit);
972 if (stream_index == -2)
979 int64_t pts,
int flags)
985 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
986 int64_t pos, pos2, ts;
1000 (
void **) next_node);
1002 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1005 next_node[1]->
pos, next_node[1]->
pos,
1006 next_node[0]->
ts, next_node[1]->
ts,
1010 dummy.
pos = pos + 16;
1011 next_node[1] = &nopts_sp;
1013 (
void **) next_node);
1015 next_node[1]->
pos, next_node[1]->
pos,
1033 if (pos2 > pos || pos2 + 15 < pos)
1065 .extensions =
"nut",