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)
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);
513 }
else if (stream_id_plus1) {
514 st = s->
streams[stream_id_plus1 - 1];
524 for (i = 0; i <
count; i++) {
525 get_str(bc, name,
sizeof(name));
531 get_str(bc, str_value,
sizeof(str_value));
532 }
else if (value == -2) {
533 get_str(bc, type_str,
sizeof(type_str));
535 get_str(bc, str_value,
sizeof(str_value));
536 }
else if (value == -3) {
539 }
else if (value == -4) {
542 }
else if (value < -4) {
554 if (!strcmp(type,
"UTF-8")) {
555 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
560 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
571 *event_flags |= metadata_flag;
645 int i, j, syncpoint_count;
649 int8_t *has_keyframe;
674 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
677 if (!syncpoints || !has_keyframe) {
681 for (i = 0; i < syncpoint_count; i++) {
683 if (syncpoints[i] <= 0)
686 syncpoints[i] += syncpoints[i - 1];
691 for (j = 0; j < syncpoint_count;) {
699 if (n + x >= syncpoint_count + 1) {
700 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
704 has_keyframe[n++] = flag;
705 has_keyframe[n++] = !flag;
708 if (n >= syncpoint_count + 1) {
712 has_keyframe[n++] = x & 1;
716 if (has_keyframe[0]) {
721 for (; j < n && j < syncpoint_count; j++) {
722 if (has_keyframe[j]) {
757 int initialized_stream_count,
ret = 0;
774 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
782 initialized_stream_count++;
791 if (startcode == 0) {
819 return FFMIN(ret, 0);
828 int64_t channel_layout = 0;
834 for (i=0; i<
count; i++) {
839 get_str(bc, name,
sizeof(name));
843 get_str(bc, str_value,
sizeof(str_value));
845 }
else if (value == -2) {
847 int64_t v64, value_len;
849 get_str(bc, type_str,
sizeof(type_str));
853 if (!strcmp(name,
"Palette")) {
855 }
else if (!strcmp(name,
"Extradata")) {
857 }
else if (sscanf(name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
863 }
else if (!strcmp(name,
"ChannelLayout") && value_len == 8) {
874 }
else if (value == -3) {
876 }
else if (value == -4) {
878 }
else if (value < -4) {
881 if (!strcmp(name,
"SkipStart")) {
883 }
else if (!strcmp(name,
"SkipEnd")) {
885 }
else if (!strcmp(name,
"Channels")) {
887 }
else if (!strcmp(name,
"SampleRate")) {
889 }
else if (!strcmp(name,
"Width")) {
891 }
else if (!strcmp(name,
"Height")) {
899 if (channels || channel_layout || sample_rate || width || height) {
903 bytestream_put_le32(&dst,
910 bytestream_put_le32(&dst, channels);
912 bytestream_put_le64(&dst, channel_layout);
914 bytestream_put_le32(&dst, sample_rate);
915 if (width || height){
916 bytestream_put_le32(&dst, width);
917 bytestream_put_le32(&dst, height);
921 if (skip_start || skip_end) {
933 uint8_t *header_idx,
int frame_code)
938 int size,
flags, size_mul, pts_delta, i, reserved_count;
944 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
964 stc = &nut->
stream[*stream_id];
982 for (i = 0; i < reserved_count; i++)
1012 int size, stream_id, discard,
ret;
1013 int64_t
pts, last_IP_pts;
1021 stc = &nut->
stream[stream_id];
1030 last_IP_pts > pts) ||
1050 pkt->
size -= sm_size;
1072 int i, frame_code = 0,
ret, skip;
1073 int64_t ts, back_ptr;
1086 if (frame_code ==
'N') {
1088 for (i = 1; i < 8; i++)
1089 tmp = (tmp << 8) +
avio_r8(bc);
1126 int64_t *pos_arg, int64_t pos_limit)
1130 int64_t pos,
pts, back_ptr;
1132 stream_index, *pos_arg, pos_limit);
1146 if (stream_index == -2)
1159 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1160 int64_t pos, pos2, ts;
1178 (
void **) next_node);
1180 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1183 next_node[1]->
pos, next_node[1]->
pos,
1184 next_node[0]->
ts, next_node[1]->
ts,
1188 dummy.
pos = pos + 16;
1189 next_node[1] = &nopts_sp;
1191 (
void **) next_node);
1193 next_node[1]->
pos, next_node[1]->
pos,
1211 if (pos2 > pos || pos2 + 15 < pos)
1243 .extensions =
"nut",
if set, side / meta data is stored in the frame header.
uint64_t ffio_read_varlen(AVIOContext *bc)
discard all frames except keyframes
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t avio_size(AVIOContext *s)
Get the filesize.
int64_t last_syncpoint_pos
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.
enum AVDurationEstimationMethod duration_estimation_method
The duration field can be estimated through various ways, and this field can be used to know how the ...
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t pos
byte position in stream, -1 if unknown
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
const AVCodecTag ff_nut_audio_extra_tags[]
int event_flags
Flags for the user to detect events happening on the stream.
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
int event_flags
Flags for the user to detect events happening on the file.
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static int decode_main_header(NUTContext *nut)
const uint8_t * header[128]
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code)
if set, reserved_count is coded in the frame header
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(void *key, const void *b), void *next[2])
Opaque data information usually continuous.
static int nut_probe(AVProbeData *p)
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
const AVCodecTag ff_codec_movvideo_tags[]
unsigned int avio_rb32(AVIOContext *s)
static av_cold int end(AVCodecContext *avctx)
if set, coded_pts is in the frame header
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
If set, match_time_delta is coded in the frame header.
const AVMetadataConv ff_nut_metadata_conv[]
static double av_q2d(AVRational a)
Convert rational to double.
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
const AVCodecTag ff_nut_data_tags[]
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void ff_nut_free_sp(NUTContext *nut)
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
unsigned int avio_rl32(AVIOContext *s)
discard all bidirectional frames
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
const AVCodecTag ff_nut_audio_tags[]
static int decode_stream_header(NUTContext *nut)
const AVCodecTag ff_codec_wav_tags[]
if set, frame is keyframe
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b)
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
static int nut_read_close(AVFormatContext *s)
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.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
#define AV_TIME_BASE
Internal time base represented as integer.
const AVCodecTag ff_codec_bmp_tags[]
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int width
picture width / height.
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
GLsizei GLboolean const GLfloat * value
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
static int find_and_decode_index(NUTContext *nut)
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
if set, frame_code is invalid
static uint64_t get_fourcc(AVIOContext *bc)
static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode)
struct AVTreeNode * syncpoints
if set, data_size_msb is at frame header, otherwise data_size_msb is 0
static int nut_read_header(AVFormatContext *s)
if set, the frame header contains a checksum
static int read_header(FFV1Context *f)
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
#define AV_LOG_INFO
Standard information.
enum AVMediaType codec_type
const AVCodecTag ff_nut_subtitle_tags[]
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
AVIOContext * pb
I/O context.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
if set, coded_flags are stored in the frame header
Data found in BlockAdditional element of matroska container.
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 GET_V(dst, check)
BYTE int const BYTE int int int height
rational number numerator/denominator
Recommmends skipping the specified number of samples.
unsigned long ffio_get_checksum(AVIOContext *s)
int(* func)(AVBPrint *dst, const char *in, const char *arg)
static int skip_reserved(AVIOContext *bc, int64_t pos)
static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
Find the given startcode.
This structure contains the data a format has to probe a file.
static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
static int64_t pts
Global timestamp for the audio frames.
static int64_t find_duration(NUTContext *nut, int64_t filesize)
const Dispositions ff_nut_dispositions[]
unsigned int avio_rl16(AVIOContext *s)
uint64_t next_startcode
stores the next startcode if it has already been parsed but the stream is not seekable ...
static int decode_info_header(NUTContext *nut)
FrameCode frame_code[256]
int disposition
AV_DISPOSITION_* bit field.
const AVCodecTag ff_nut_video_tags[]
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
#define SYNCPOINT_STARTCODE
If set, header_idx is coded in the frame header.
AVInputFormat ff_nut_demuxer
int channels
number of audio channels
static int64_t get_s(AVIOContext *bc)
void * priv_data
Format private data.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
if set, stream_id is coded in the frame header
#define av_malloc_array(a, b)
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVRational r_frame_rate
Real base framerate of the stream.
const AVCodecTag *const ff_nut_codec_tags[]
This structure stores compressed data.
uint64_t avio_rl64(AVIOContext *s)
unsigned int time_base_count
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
unsigned int max_distance