36 #define NUT_MAX_STREAMS 256
39 int64_t *pos_arg, int64_t pos_limit);
47 while (len > maxlen) {
53 string[
FFMIN(len, maxlen - 1)] = 0;
86 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
92 v, v, file, func, line);
96 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
102 v, v, file, func, line);
106 static inline uint64_t get_4cc_trace(
AVIOContext *bc,
char *file,
112 v, v, file, func, line);
115 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
116 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
117 #define get_fourcc(bc) get_4cc_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
121 int calculate_checksum, uint64_t startcode)
150 state = (state << 8) |
avio_r8(bc);
151 if ((state >> 56) !=
'N')
176 if (startcode == code)
178 else if (startcode == 0)
188 for (i = 0; i < p->
buf_size-8; i++) {
197 #define GET_V(dst, check) \
199 tmp = ffio_read_varlen(bc); \
201 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
202 return AVERROR_INVALIDDATA; \
225 unsigned int stream_count;
227 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
267 for (i = 0; i < 256;) {
288 count = tmp_mul - tmp_size;
294 while (tmp_fields-- > 8)
297 if (count == 0 || i + count > 256) {
301 if (tmp_stream >= stream_count) {
306 for (j = 0; j <
count; j++, i++) {
357 for (i = 0; i < stream_count; i++)
368 int class, stream_id;
376 stc = &nut->
stream[stream_id];
381 class = ffio_read_varlen(bc);
419 "Unknown codec tag '0x%04x' for stream number %d\n",
420 (
unsigned int) tmp, stream_id);
453 "stream header %d checksum mismatch\n", stream_id);
473 if (stream_id == i || stream_id == -1)
481 uint64_t tmp, chapter_start, chapter_len;
482 unsigned int stream_id_plus1,
count;
485 char name[256], str_value[1024], type_str[256];
495 chapter_id =
get_s(bc);
500 if (chapter_id && !stream_id_plus1) {
505 start, start + chapter_len, NULL);
507 }
else if (stream_id_plus1) {
508 st = s->
streams[stream_id_plus1 - 1];
513 for (i = 0; i <
count; i++) {
514 get_str(bc, name,
sizeof(name));
518 get_str(bc, str_value,
sizeof(str_value));
519 }
else if (value == -2) {
520 get_str(bc, type_str,
sizeof(type_str));
522 get_str(bc, str_value,
sizeof(str_value));
523 }
else if (value == -3) {
526 }
else if (value == -4) {
529 }
else if (value < -4) {
541 if (!strcmp(type,
"UTF-8")) {
542 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
547 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
628 int i, j, syncpoint_count;
632 int8_t *has_keyframe;
657 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
660 if (!syncpoints || !has_keyframe) {
664 for (i = 0; i < syncpoint_count; i++) {
666 if (syncpoints[i] <= 0)
669 syncpoints[i] += syncpoints[i - 1];
674 for (j = 0; j < syncpoint_count;) {
682 if (n + x >= syncpoint_count + 1) {
683 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
687 has_keyframe[n++] = flag;
688 has_keyframe[n++] = !flag;
691 if (n >= syncpoint_count + 1) {
695 has_keyframe[n++] = x & 1;
699 if (has_keyframe[0]) {
704 for (; j < n && j < syncpoint_count; j++) {
705 if (has_keyframe[j]) {
738 int initialized_stream_count;
754 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
761 initialized_stream_count++;
770 if (startcode == 0) {
803 int64_t channel_layout = 0;
809 for (i=0; i<
count; i++) {
814 get_str(bc, name,
sizeof(name));
818 get_str(bc, str_value,
sizeof(str_value));
820 }
else if (value == -2) {
822 int64_t v64, value_len;
824 get_str(bc, type_str,
sizeof(type_str));
828 if (!strcmp(name,
"Palette")) {
830 }
else if (!strcmp(name,
"Extradata")) {
832 }
else if (sscanf(name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
838 }
else if (!strcmp(name,
"ChannelLayout") && value_len == 8) {
849 }
else if (value == -3) {
851 }
else if (value == -4) {
853 }
else if (value < -4) {
856 if (!strcmp(name,
"SkipStart")) {
858 }
else if (!strcmp(name,
"SkipEnd")) {
860 }
else if (!strcmp(name,
"Channels")) {
862 }
else if (!strcmp(name,
"SampleRate")) {
864 }
else if (!strcmp(name,
"Width")) {
866 }
else if (!strcmp(name,
"Height")) {
874 if (channels || channel_layout || sample_rate || width || height) {
878 bytestream_put_le32(&dst,
885 bytestream_put_le32(&dst, channels);
887 bytestream_put_le64(&dst, channel_layout);
889 bytestream_put_le32(&dst, sample_rate);
890 if (width || height){
891 bytestream_put_le32(&dst, width);
892 bytestream_put_le32(&dst, height);
896 if (skip_start || skip_end) {
908 uint8_t *header_idx,
int frame_code)
913 int size,
flags, size_mul, pts_delta, i, reserved_count;
919 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
939 stc = &nut->
stream[*stream_id];
957 for (i = 0; i < reserved_count; i++)
987 int size, stream_id, discard;
988 int64_t pts, last_IP_pts;
997 stc = &nut->
stream[stream_id];
1006 last_IP_pts > pts) ||
1025 pkt->
size -= sm_size;
1047 int i, frame_code = 0,
ret, skip;
1048 int64_t ts, back_ptr;
1061 if (frame_code ==
'N') {
1063 for (i = 1; i < 8; i++)
1064 tmp = (tmp << 8) +
avio_r8(bc);
1101 int64_t *pos_arg, int64_t pos_limit)
1105 int64_t pos, pts, back_ptr;
1107 stream_index, *pos_arg, pos_limit);
1121 if (stream_index == -2)
1128 int64_t pts,
int flags)
1134 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1135 int64_t pos, pos2, ts;
1153 (
void **) next_node);
1155 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1158 next_node[1]->
pos, next_node[1]->
pos,
1159 next_node[0]->
ts, next_node[1]->
ts,
1163 dummy.
pos = pos + 16;
1164 next_node[1] = &nopts_sp;
1166 (
void **) next_node);
1168 next_node[1]->
pos, next_node[1]->
pos,
1186 if (pos2 > pos || pos2 + 15 < pos)
1218 .extensions =
"nut",