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];
487 int *event_flags = NULL;
491 int metadata_flag = 0;
497 chapter_id =
get_s(bc);
502 if (chapter_id && !stream_id_plus1) {
507 start, start + chapter_len, NULL);
509 }
else if (stream_id_plus1) {
510 st = s->
streams[stream_id_plus1 - 1];
520 for (i = 0; i <
count; i++) {
521 get_str(bc, name,
sizeof(name));
525 get_str(bc, str_value,
sizeof(str_value));
526 }
else if (value == -2) {
527 get_str(bc, type_str,
sizeof(type_str));
529 get_str(bc, str_value,
sizeof(str_value));
530 }
else if (value == -3) {
533 }
else if (value == -4) {
536 }
else if (value < -4) {
548 if (!strcmp(type,
"UTF-8")) {
549 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
554 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
564 *event_flags |= metadata_flag;
638 int i, j, syncpoint_count;
642 int8_t *has_keyframe;
667 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
670 if (!syncpoints || !has_keyframe) {
674 for (i = 0; i < syncpoint_count; i++) {
676 if (syncpoints[i] <= 0)
679 syncpoints[i] += syncpoints[i - 1];
684 for (j = 0; j < syncpoint_count;) {
692 if (n + x >= syncpoint_count + 1) {
693 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
697 has_keyframe[n++] = flag;
698 has_keyframe[n++] = !flag;
701 if (n >= syncpoint_count + 1) {
705 has_keyframe[n++] = x & 1;
709 if (has_keyframe[0]) {
714 for (; j < n && j < syncpoint_count; j++) {
715 if (has_keyframe[j]) {
748 int initialized_stream_count;
764 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
771 initialized_stream_count++;
780 if (startcode == 0) {
813 int64_t channel_layout = 0;
819 for (i=0; i<
count; i++) {
824 get_str(bc, name,
sizeof(name));
828 get_str(bc, str_value,
sizeof(str_value));
830 }
else if (value == -2) {
832 int64_t v64, value_len;
834 get_str(bc, type_str,
sizeof(type_str));
838 if (!strcmp(name,
"Palette")) {
840 }
else if (!strcmp(name,
"Extradata")) {
842 }
else if (sscanf(name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
848 }
else if (!strcmp(name,
"ChannelLayout") && value_len == 8) {
859 }
else if (value == -3) {
861 }
else if (value == -4) {
863 }
else if (value < -4) {
866 if (!strcmp(name,
"SkipStart")) {
868 }
else if (!strcmp(name,
"SkipEnd")) {
870 }
else if (!strcmp(name,
"Channels")) {
872 }
else if (!strcmp(name,
"SampleRate")) {
874 }
else if (!strcmp(name,
"Width")) {
876 }
else if (!strcmp(name,
"Height")) {
884 if (channels || channel_layout || sample_rate || width || height) {
888 bytestream_put_le32(&dst,
895 bytestream_put_le32(&dst, channels);
897 bytestream_put_le64(&dst, channel_layout);
899 bytestream_put_le32(&dst, sample_rate);
900 if (width || height){
901 bytestream_put_le32(&dst, width);
902 bytestream_put_le32(&dst, height);
906 if (skip_start || skip_end) {
918 uint8_t *header_idx,
int frame_code)
923 int size,
flags, size_mul, pts_delta, i, reserved_count;
929 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
949 stc = &nut->
stream[*stream_id];
967 for (i = 0; i < reserved_count; i++)
997 int size, stream_id, discard;
998 int64_t pts, last_IP_pts;
1007 stc = &nut->
stream[stream_id];
1016 last_IP_pts > pts) ||
1035 pkt->
size -= sm_size;
1057 int i, frame_code = 0,
ret, skip;
1058 int64_t ts, back_ptr;
1071 if (frame_code ==
'N') {
1073 for (i = 1; i < 8; i++)
1074 tmp = (tmp << 8) +
avio_r8(bc);
1111 int64_t *pos_arg, int64_t pos_limit)
1115 int64_t pos, pts, back_ptr;
1117 stream_index, *pos_arg, pos_limit);
1131 if (stream_index == -2)
1138 int64_t pts,
int flags)
1144 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1145 int64_t pos, pos2, ts;
1163 (
void **) next_node);
1165 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1168 next_node[1]->
pos, next_node[1]->
pos,
1169 next_node[0]->
ts, next_node[1]->
ts,
1173 dummy.
pos = pos + 16;
1174 next_node[1] = &nopts_sp;
1176 (
void **) next_node);
1178 next_node[1]->
pos, next_node[1]->
pos,
1196 if (pos2 > pos || pos2 + 15 < pos)
1228 .extensions =
"nut",