36 #define NUT_MAX_STREAMS 256
39 int64_t *pos_arg, int64_t pos_limit);
47 while (
len > maxlen) {
90 int calculate_checksum, uint64_t startcode)
119 if ((
state >> 56) !=
'N')
144 if (startcode ==
code)
146 else if (startcode == 0)
165 #define GET_V(dst, check) \
167 tmp = ffio_read_varlen(bc); \
169 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
170 ret = AVERROR_INVALIDDATA; \
196 uint64_t
tmp, end, length;
197 unsigned int stream_count;
198 int i, j, count, ret;
199 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
242 for (
i = 0;
i < 256;) {
263 count = tmp_mul - (unsigned)tmp_size;
269 while (tmp_fields-- > 8) {
278 if (count <= 0 || count > 256 - (
i <=
'N') -
i) {
283 if (tmp_stream >= stream_count) {
285 tmp_stream, stream_count);
290 for (j = 0; j < count; j++,
i++) {
314 if (rem < nut->header_len[
i]) {
316 "invalid elision header %d : %d > %d\n",
349 for (
i = 0;
i < stream_count;
i++)
367 int class, stream_id, ret;
375 stc = &nut->
stream[stream_id];
376 st =
s->streams[stream_id];
380 class = ffio_read_varlen(bc);
418 "Unknown codec tag '0x%04x' for stream number %d\n",
419 (
unsigned int)
tmp, stream_id);
455 "stream header %d checksum mismatch\n", stream_id);
482 if (stream_id ==
i || stream_id == -1)
490 uint64_t
tmp, chapter_start, chapter_len;
491 unsigned int stream_id_plus1, count;
493 int64_t chapter_id,
value, end;
494 char name[256], str_value[1024], type_str[256];
496 int *event_flags =
NULL;
500 int metadata_flag = 0;
506 chapter_id =
get_s(bc);
511 if (chapter_id && !stream_id_plus1) {
516 start, start + chapter_len,
NULL);
522 }
else if (stream_id_plus1) {
523 st =
s->streams[stream_id_plus1 - 1];
528 metadata = &
s->metadata;
529 event_flags = &
s->event_flags;
533 for (
i = 0;
i < count;
i++) {
544 ret =
get_str(bc, str_value,
sizeof(str_value));
545 }
else if (
value == -2) {
546 ret =
get_str(bc, type_str,
sizeof(type_str));
552 ret =
get_str(bc, str_value,
sizeof(str_value));
553 }
else if (
value == -3) {
556 }
else if (
value == -4) {
559 }
else if (
value < -4) {
571 if (stream_id_plus1 >
s->nb_streams) {
573 "invalid stream id %d for info packet\n",
578 if (!strcmp(
type,
"UTF-8")) {
579 if (chapter_id == 0 && !strcmp(
name,
"Disposition")) {
584 if (stream_id_plus1 && !strcmp(
name,
"r_frame_rate")) {
595 *event_flags |= metadata_flag;
606 return FFMIN(ret, 0);
670 int i, j, syncpoint_count;
672 int64_t *syncpoints =
NULL;
674 int8_t *has_keyframe =
NULL;
699 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
702 if (!syncpoints || !has_keyframe) {
706 for (
i = 0;
i < syncpoint_count;
i++) {
708 if (syncpoints[
i] <= 0)
711 syncpoints[
i] += syncpoints[
i - 1];
714 for (
i = 0;
i <
s->nb_streams;
i++) {
716 for (j = 0; j < syncpoint_count;) {
724 if (n + x >= syncpoint_count + 1) {
725 av_log(
s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
729 has_keyframe[n++] =
flag;
730 has_keyframe[n++] = !
flag;
737 if (n >= syncpoint_count + 1) {
741 has_keyframe[n++] = x & 1;
745 if (has_keyframe[0]) {
750 for (; j < n && j < syncpoint_count; j++) {
751 if (has_keyframe[j]) {
798 int initialized_stream_count;
814 for (initialized_stream_count = 0; initialized_stream_count <
s->nb_streams;) {
821 initialized_stream_count++;
830 if (startcode == 0) {
843 s->internal->data_offset =
pos - 8;
868 int64_t channel_layout = 0;
874 for (
i=0;
i<count;
i++) {
887 ret =
get_str(bc, str_value,
sizeof(str_value));
893 }
else if (
value == -2) {
895 int64_t v64, value_len;
897 ret =
get_str(bc, type_str,
sizeof(type_str));
903 if (value_len < 0 || value_len >= maxpos -
avio_tell(bc))
905 if (!strcmp(
name,
"Palette")) {
907 }
else if (!strcmp(
name,
"Extradata")) {
909 }
else if (sscanf(
name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
915 }
else if (!strcmp(
name,
"ChannelLayout") && value_len == 8) {
926 }
else if (
value == -3) {
928 }
else if (
value == -4) {
930 }
else if (
value < -4) {
933 if (!strcmp(
name,
"SkipStart")) {
935 }
else if (!strcmp(
name,
"SkipEnd")) {
937 }
else if (!strcmp(
name,
"Channels")) {
939 }
else if (!strcmp(
name,
"SampleRate")) {
941 }
else if (!strcmp(
name,
"Width")) {
943 }
else if (!strcmp(
name,
"Height")) {
955 bytestream_put_le32(&dst,
962 bytestream_put_le32(&dst,
channels);
964 bytestream_put_le64(&dst, channel_layout);
968 bytestream_put_le32(&dst,
width);
969 bytestream_put_le32(&dst,
height);
973 if (skip_start || skip_end) {
988 uint8_t *header_idx,
int frame_code)
993 int size,
flags, size_mul, pts_delta,
i, reserved_count, ret;
999 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
1019 stc = &nut->
stream[*stream_id];
1037 for (
i = 0;
i < reserved_count;
i++) {
1074 int size, stream_id, discard, ret;
1075 int64_t
pts, last_IP_pts;
1083 stc = &nut->
stream[stream_id];
1088 discard =
s->streams[stream_id]->discard;
1089 last_IP_pts =
s->streams[stream_id]->last_IP_pts;
1092 last_IP_pts >
pts) ||
1102 if (nut->
header[header_idx])
1142 int i, frame_code = 0, ret, skip;
1143 int64_t ts, back_ptr;
1156 if (frame_code ==
'N') {
1158 for (
i = 1;
i < 8;
i++)
1197 int64_t *pos_arg, int64_t pos_limit)
1201 int64_t
pos,
pts, back_ptr;
1203 stream_index, *pos_arg, pos_limit);
1217 if (stream_index == -2)
1227 AVStream *st =
s->streams[stream_index];
1230 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1231 int64_t
pos, pos2, ts;
1249 (
void **) next_node);
1251 next_node[0]->
pos, next_node[1]->
pos, next_node[0]->ts,
1254 next_node[1]->pos, next_node[1]->pos,
1255 next_node[0]->ts, next_node[1]->ts,
1262 next_node[1] = &nopts_sp;
1264 (
void **) next_node);
1266 next_node[1]->pos, next_node[1]->pos,
1267 next_node[0]->back_ptr, next_node[1]->back_ptr,
1278 pos2 =
sp->back_ptr - 15;
1285 if (pos2 >
pos || pos2 + 15 <
pos)
1287 for (
i = 0;
i <
s->nb_streams;
i++)
1305 .extensions =
"nut",
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
uint64_t avio_rb64(AVIOContext *s)
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
unsigned int avio_rl16(AVIOContext *s)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
unsigned int avio_rl32(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
uint64_t avio_rl64(AVIOContext *s)
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
unsigned long ffio_get_checksum(AVIOContext *s)
uint64_t ffio_read_varlen(AVIOContext *bc)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
#define flags(name, subs,...)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int read_header(FFV1Context *f)
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_BIDIR
discard all bidirectional frames
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
const AVCodecTag ff_codec_movvideo_tags[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
const AVCodecTag ff_nut_audio_tags[]
const AVCodecTag ff_nut_video_tags[]
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
int ff_nut_sp_pos_cmp(const void *a, const void *b)
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
int ff_nut_sp_pts_cmp(const void *a, const void *b)
const AVCodecTag ff_nut_data_tags[]
const AVCodecTag *const ff_nut_codec_tags[]
void ff_nut_free_sp(NUTContext *nut)
const AVCodecTag ff_nut_audio_extra_tags[]
const Dispositions ff_nut_dispositions[]
const AVCodecTag ff_nut_subtitle_tags[]
const AVMetadataConv ff_nut_metadata_conv[]
#define SYNCPOINT_STARTCODE
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
static uint64_t get_fourcc(AVIOContext *bc)
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
static int decode_main_header(NUTContext *nut)
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
static int decode_info_header(NUTContext *nut)
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
AVInputFormat ff_nut_demuxer
static int64_t find_duration(NUTContext *nut, int64_t filesize)
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode)
static int nut_probe(const AVProbeData *p)
static int skip_reserved(AVIOContext *bc, int64_t pos)
static int find_and_decode_index(NUTContext *nut)
static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
static int64_t get_s(AVIOContext *bc)
static int nut_read_close(AVFormatContext *s)
static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
#define GET_V(dst, check)
static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
Find the given startcode.
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code)
static int decode_stream_header(NUTContext *nut)
static int nut_read_header(AVFormatContext *s)
const AVCodecTag ff_codec_bmp_tags[]
const AVCodecTag ff_codec_wav_tags[]
internal header for RIFF based (de)muxers do NOT include this in end user applications
int extradata_size
Size of the extradata content in bytes.
enum AVMediaType codec_type
General type of the encoded data.
int video_delay
Video only.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
Audio only.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVStream ** streams
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int eof_reached
true if was unable to read due to error or eof
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t pos
byte position in stream, -1 if unknown
This structure contains the data a format has to probe a file.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVRational r_frame_rate
Real base framerate of the stream.
int disposition
AV_DISPOSITION_* bit field.
const uint8_t * header[128]
struct AVTreeNode * syncpoints
FrameCode frame_code[256]
unsigned int max_distance
int64_t last_syncpoint_pos
unsigned int time_base_count
#define av_malloc_array(a, b)
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])