35 #define NUT_MAX_STREAMS 256
38 int64_t *pos_arg, int64_t pos_limit);
46 while (len > maxlen) {
52 string[
FFMIN(len, maxlen - 1)] = 0;
85 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
91 v, v, file, func, line);
95 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
101 v, v, file, func, line);
105 static inline uint64_t get_4cc_trace(
AVIOContext *bc,
char *file,
111 v, v, file, func, line);
114 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
115 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
116 #define get_fourcc(bc) get_4cc_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
120 int calculate_checksum, uint64_t startcode)
149 state = (state << 8) |
avio_r8(bc);
150 if ((state >> 56) !=
'N')
175 if (startcode == code)
177 else if (startcode == 0)
189 code = (code << 8) | p->
buf[i];
196 #define GET_V(dst, check) \
198 tmp = ffio_read_varlen(bc); \
200 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
201 return AVERROR_INVALIDDATA; \
224 unsigned int stream_count;
226 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
232 if (tmp < 2 && tmp > 4) {
266 for (i = 0; i < 256;) {
287 count = tmp_mul - tmp_size;
293 while (tmp_fields-- > 8)
296 if (count == 0 || i + count > 256) {
300 if (tmp_stream >= stream_count) {
305 for (j = 0; j <
count; j++, i++) {
351 for (i = 0; i < stream_count; i++)
362 int class, stream_id;
370 stc = &nut->
stream[stream_id];
375 class = ffio_read_varlen(bc);
411 "Unknown codec tag '0x%04x' for stream number %d\n",
412 (
unsigned int) tmp, stream_id);
445 "stream header %d checksum mismatch\n", stream_id);
465 if (stream_id == i || stream_id == -1)
473 uint64_t tmp, chapter_start, chapter_len;
474 unsigned int stream_id_plus1,
count;
477 char name[256], str_value[1024], type_str[256];
486 GET_V(stream_id_plus1, tmp <= s->nb_streams);
487 chapter_id =
get_s(bc);
492 if (chapter_id && !stream_id_plus1) {
497 start, start + chapter_len, NULL);
499 }
else if (stream_id_plus1) {
500 st = s->
streams[stream_id_plus1 - 1];
505 for (i = 0; i <
count; i++) {
506 get_str(bc, name,
sizeof(name));
510 get_str(bc, str_value,
sizeof(str_value));
511 }
else if (value == -2) {
512 get_str(bc, type_str,
sizeof(type_str));
514 get_str(bc, str_value,
sizeof(str_value));
515 }
else if (value == -3) {
518 }
else if (value == -4) {
521 }
else if (value < -4) {
533 if (!strcmp(type,
"UTF-8")) {
534 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
539 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
612 int i, j, syncpoint_count;
616 int8_t *has_keyframe;
641 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
642 syncpoints = av_malloc_array(syncpoint_count,
sizeof(int64_t));
643 has_keyframe = av_malloc_array(syncpoint_count + 1,
sizeof(int8_t));
644 if (!syncpoints || !has_keyframe) {
648 for (i = 0; i < syncpoint_count; i++) {
650 if (syncpoints[i] <= 0)
653 syncpoints[i] += syncpoints[i - 1];
658 for (j = 0; j < syncpoint_count;) {
666 if (n + x >= syncpoint_count + 1) {
667 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
671 has_keyframe[n++] = flag;
672 has_keyframe[n++] = !flag;
675 if (n >= syncpoint_count + 1) {
679 has_keyframe[n++] = x & 1;
683 if (has_keyframe[0]) {
688 for (; j < n && j < syncpoint_count; j++) {
689 if (has_keyframe[j]) {
722 int initialized_stream_count;
738 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
745 initialized_stream_count++;
754 if (startcode == 0) {
787 int64_t channel_layout = 0;
793 for (i=0; i<
count; i++) {
798 get_str(bc, name,
sizeof(name));
802 get_str(bc, str_value,
sizeof(str_value));
804 }
else if (value == -2) {
806 int64_t v64, value_len;
808 get_str(bc, type_str,
sizeof(type_str));
812 if (!strcmp(name,
"Palette")) {
814 }
else if (!strcmp(name,
"Extradata")) {
816 }
else if (sscanf(name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
822 }
else if (!strcmp(name,
"ChannelLayout") && value_len == 8) {
833 }
else if (value == -3) {
835 }
else if (value == -4) {
837 }
else if (value < -4) {
840 if (!strcmp(name,
"SkipStart")) {
842 }
else if (!strcmp(name,
"SkipEnd")) {
844 }
else if (!strcmp(name,
"Channels")) {
846 }
else if (!strcmp(name,
"SampleRate")) {
848 }
else if (!strcmp(name,
"Width")) {
850 }
else if (!strcmp(name,
"Height")) {
858 if (channels || channel_layout || sample_rate || width || height) {
862 bytestream_put_le32(&dst,
869 bytestream_put_le32(&dst, channels);
871 bytestream_put_le64(&dst, channel_layout);
873 bytestream_put_le32(&dst, sample_rate);
874 if (width || height){
875 bytestream_put_le32(&dst, width);
876 bytestream_put_le32(&dst, height);
880 if (skip_start || skip_end) {
892 uint8_t *header_idx,
int frame_code)
897 int size,
flags, size_mul, pts_delta, i, reserved_count;
902 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
920 GET_V(*stream_id, tmp < s->nb_streams);
922 stc = &nut->
stream[*stream_id];
940 for (i = 0; i < reserved_count; i++)
969 int size, stream_id, discard;
970 int64_t pts, last_IP_pts;
979 stc = &nut->
stream[stream_id];
988 last_IP_pts > pts) ||
1007 pkt->
size -= sm_size;
1029 int i, frame_code = 0,
ret, skip;
1030 int64_t ts, back_ptr;
1043 if (frame_code ==
'N') {
1045 for (i = 1; i < 8; i++)
1046 tmp = (tmp << 8) +
avio_r8(bc);
1083 int64_t *pos_arg, int64_t pos_limit)
1087 int64_t pos, pts, back_ptr;
1089 stream_index, *pos_arg, pos_limit);
1103 if (stream_index == -2)
1110 int64_t pts,
int flags)
1116 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1117 int64_t pos, pos2, ts;
1131 (
void **) next_node);
1133 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1136 next_node[1]->
pos, next_node[1]->
pos,
1137 next_node[0]->
ts, next_node[1]->
ts,
1141 dummy.
pos = pos + 16;
1142 next_node[1] = &nopts_sp;
1144 (
void **) next_node);
1146 next_node[1]->
pos, next_node[1]->
pos,
1164 if (pos2 > pos || pos2 + 15 < pos)
1196 .extensions =
"nut",