36 #define NUT_MAX_STREAMS 256
39 int64_t *pos_arg, int64_t pos_limit);
47 while (len > maxlen) {
55 string[
FFMIN(len, maxlen - 1)] = 0;
90 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
96 v, v, file, func, line);
100 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
106 v, v, file, func, line);
110 static inline uint64_t get_4cc_trace(
AVIOContext *bc,
char *file,
116 v, v, file, func, line);
119 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
120 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
121 #define get_fourcc(bc) get_4cc_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
125 int calculate_checksum, uint64_t startcode)
154 state = (state << 8) |
avio_r8(bc);
155 if ((state >> 56) !=
'N')
180 if (startcode == code)
182 else if (startcode == 0)
192 for (i = 0; i < p->
buf_size-8; i++) {
201 #define GET_V(dst, check) \
203 tmp = ffio_read_varlen(bc); \
205 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
206 return AVERROR_INVALIDDATA; \
232 unsigned int stream_count;
234 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
274 for (i = 0; i < 256;) {
295 count = tmp_mul - tmp_size;
301 while (tmp_fields-- > 8) {
313 if (tmp_stream >= stream_count) {
318 for (j = 0; j <
count; j++, i++) {
369 for (i = 0; i < stream_count; i++)
380 int class, stream_id;
388 stc = &nut->
stream[stream_id];
431 "Unknown codec tag '0x%04x' for stream number %d\n",
432 (
unsigned int) tmp, stream_id);
465 "stream header %d checksum mismatch\n", stream_id);
485 if (stream_id == i || stream_id == -1)
493 uint64_t tmp, chapter_start, chapter_len;
494 unsigned int stream_id_plus1,
count;
495 int chapter_id, i,
ret;
497 char name[256], str_value[1024], type_str[256];
499 int *event_flags =
NULL;
503 int metadata_flag = 0;
509 chapter_id =
get_s(bc);
514 if (chapter_id && !stream_id_plus1) {
519 start, start + chapter_len,
NULL);
525 }
else if (stream_id_plus1) {
526 st = s->
streams[stream_id_plus1 - 1];
536 for (i = 0; i <
count; i++) {
537 ret =
get_str(bc, name,
sizeof(name));
547 get_str(bc, str_value,
sizeof(str_value));
548 }
else if (value == -2) {
549 get_str(bc, type_str,
sizeof(type_str));
551 get_str(bc, str_value,
sizeof(str_value));
552 }
else if (value == -3) {
555 }
else if (value == -4) {
558 }
else if (value < -4) {
570 if (!strcmp(type,
"UTF-8")) {
571 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
576 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
587 *event_flags |= metadata_flag;
661 int i, j, syncpoint_count;
665 int8_t *has_keyframe;
690 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
693 if (!syncpoints || !has_keyframe) {
697 for (i = 0; i < syncpoint_count; i++) {
699 if (syncpoints[i] <= 0)
702 syncpoints[i] += syncpoints[i - 1];
707 for (j = 0; j < syncpoint_count;) {
715 if (n + x >= syncpoint_count + 1) {
716 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
720 has_keyframe[n++] = flag;
721 has_keyframe[n++] = !flag;
728 if (n >= syncpoint_count + 1) {
732 has_keyframe[n++] = x & 1;
736 if (has_keyframe[0]) {
741 for (; j < n && j < syncpoint_count; j++) {
742 if (has_keyframe[j]) {
777 int initialized_stream_count,
ret = 0;
794 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
802 initialized_stream_count++;
811 if (startcode == 0) {
839 return FFMIN(ret, 0);
848 int64_t channel_layout = 0;
854 for (i=0; i<
count; i++) {
859 ret =
get_str(bc, name,
sizeof(name));
867 get_str(bc, str_value,
sizeof(str_value));
869 }
else if (value == -2) {
871 int64_t v64, value_len;
873 get_str(bc, type_str,
sizeof(type_str));
875 if (value_len < 0 || value_len >= maxpos -
avio_tell(bc))
877 if (!strcmp(name,
"Palette")) {
879 }
else if (!strcmp(name,
"Extradata")) {
881 }
else if (sscanf(name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
887 }
else if (!strcmp(name,
"ChannelLayout") && value_len == 8) {
898 }
else if (value == -3) {
900 }
else if (value == -4) {
902 }
else if (value < -4) {
905 if (!strcmp(name,
"SkipStart")) {
907 }
else if (!strcmp(name,
"SkipEnd")) {
909 }
else if (!strcmp(name,
"Channels")) {
911 }
else if (!strcmp(name,
"SampleRate")) {
913 }
else if (!strcmp(name,
"Width")) {
915 }
else if (!strcmp(name,
"Height")) {
923 if (channels || channel_layout || sample_rate || width || height) {
927 bytestream_put_le32(&dst,
934 bytestream_put_le32(&dst, channels);
936 bytestream_put_le64(&dst, channel_layout);
938 bytestream_put_le32(&dst, sample_rate);
939 if (width || height){
940 bytestream_put_le32(&dst, width);
941 bytestream_put_le32(&dst, height);
945 if (skip_start || skip_end) {
960 uint8_t *header_idx,
int frame_code)
965 int size,
flags, size_mul, pts_delta, i, reserved_count;
971 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
991 stc = &nut->
stream[*stream_id];
1009 for (i = 0; i < reserved_count; i++) {
1044 int size, stream_id, discard,
ret;
1045 int64_t
pts, last_IP_pts;
1053 stc = &nut->
stream[stream_id];
1062 last_IP_pts > pts) ||
1072 if (nut->
header[header_idx])
1083 pkt->
size -= sm_size;
1105 int i, frame_code = 0,
ret, skip;
1106 int64_t ts, back_ptr;
1119 if (frame_code ==
'N') {
1121 for (i = 1; i < 8; i++)
1122 tmp = (tmp << 8) +
avio_r8(bc);
1160 int64_t *pos_arg, int64_t pos_limit)
1164 int64_t pos,
pts, back_ptr;
1166 stream_index, *pos_arg, pos_limit);
1180 if (stream_index == -2)
1193 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1194 int64_t pos, pos2, ts;
1212 (
void **) next_node);
1214 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1217 next_node[1]->
pos, next_node[1]->
pos,
1218 next_node[0]->
ts, next_node[1]->
ts,
1222 dummy.
pos = pos + 16;
1223 next_node[1] = &nopts_sp;
1225 (
void **) next_node);
1227 next_node[1]->
pos, next_node[1]->
pos,
1246 if (pos2 > pos || pos2 + 15 < pos)
1280 .extensions =
"nut",