35 #define NUT_MAX_STREAMS 256 43 while (len > maxlen) {
49 string[
FFMIN(len, maxlen - 1)] = 0;
80 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
86 v, v, file,
func, line);
90 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
93 int64_t v =
get_s(bc);
96 v, v, file,
func, line);
100 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) 101 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) 105 int calculate_checksum, uint64_t startcode)
134 state = (state << 8) |
avio_r8(bc);
135 if ((state >> 56) !=
'N')
160 if (startcode == code)
162 else if (startcode == 0)
174 code = (code << 8) | p->
buf[i];
181 #define GET_V(dst, check) \ 183 tmp = ffio_read_varlen(bc); \ 185 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \ 186 return AVERROR_INVALIDDATA; \ 209 unsigned int stream_count;
211 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
251 for (i = 0; i < 256;) {
272 count = tmp_mul - tmp_size;
278 while (tmp_fields-- > 8)
281 if (count == 0 || i + count > 256) {
285 if (tmp_stream >= stream_count) {
287 tmp_stream, stream_count);
291 for (j = 0; j < count; j++, i++) {
315 if (rem < nut->header_len[i]) {
317 "invalid elision header %d : %d > %d\n",
344 for (i = 0; i < stream_count; i++)
355 int class, stream_id;
363 stc = &nut->
stream[stream_id];
368 class = ffio_read_varlen(bc);
404 "Unknown codec tag '0x%04x' for stream number %d\n",
405 (
unsigned int) tmp, stream_id);
440 "stream header %d checksum mismatch\n", stream_id);
460 if (stream_id == i || stream_id == -1)
468 uint64_t
tmp, chapter_start, chapter_len;
469 unsigned int stream_id_plus1, count;
472 char name[256], str_value[1024], type_str[256];
474 int *event_flags =
NULL;
478 int metadata_flag = 0;
483 GET_V(stream_id_plus1, tmp <= s->nb_streams);
484 chapter_id =
get_s(bc);
489 if (chapter_id && !stream_id_plus1) {
494 start, start + chapter_len,
NULL);
500 }
else if (stream_id_plus1) {
501 st = s->
streams[stream_id_plus1 - 1];
511 for (i = 0; i < count; i++) {
512 get_str(bc, name,
sizeof(name));
516 get_str(bc, str_value,
sizeof(str_value));
517 }
else if (value == -2) {
518 get_str(bc, type_str,
sizeof(type_str));
520 get_str(bc, str_value,
sizeof(str_value));
521 }
else if (value == -3) {
524 }
else if (value == -4) {
527 }
else if (value < -4) {
536 "invalid stream id %d for info packet\n",
541 if (!strcmp(type,
"UTF-8")) {
542 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
549 *event_flags |= metadata_flag;
609 int i, j, syncpoint_count;
612 int8_t *has_keyframe;
626 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
627 syncpoints =
av_malloc(
sizeof(int64_t) * syncpoint_count);
628 has_keyframe =
av_malloc(
sizeof(int8_t) * (syncpoint_count + 1));
629 if (!syncpoints || !has_keyframe) {
633 for (i = 0; i < syncpoint_count; i++) {
635 if (syncpoints[i] <= 0)
638 syncpoints[i] += syncpoints[i - 1];
642 int64_t last_pts = -1;
643 for (j = 0; j < syncpoint_count;) {
651 if (n + x >= syncpoint_count + 1) {
656 has_keyframe[n++] =
flag;
657 has_keyframe[n++] = !
flag;
660 if (n >= syncpoint_count + 1) {
664 has_keyframe[n++] = x & 1;
668 if (has_keyframe[0]) {
672 assert(n <= syncpoint_count + 1);
673 for (; j < n && j < syncpoint_count; j++) {
674 if (has_keyframe[j]) {
721 int initialized_stream_count;
737 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
744 initialized_stream_count++;
753 if (startcode == 0) {
786 uint8_t *header_idx,
int frame_code)
791 int size,
flags, size_mul, pts_delta, i, reserved_count;
797 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
815 GET_V(*stream_id, tmp < s->nb_streams);
817 stc = &nut->
stream[*stream_id];
835 for (i = 0; i < reserved_count; i++)
865 int size, stream_id, discard, ret;
866 int64_t
pts, last_IP_pts;
874 stc = &nut->
stream[stream_id];
883 last_IP_pts > pts) ||
893 if (nut->
header[header_idx])
910 int i, frame_code = 0, ret, skip;
911 int64_t ts, back_ptr;
924 if (frame_code ==
'N') {
926 for (i = 1; i < 8; i++)
927 tmp = (tmp << 8) +
avio_r8(bc);
964 int64_t *pos_arg, int64_t pos_limit)
968 int64_t pos,
pts, back_ptr;
970 stream_index, *pos_arg, pos_limit);
985 if (stream_index == -1)
987 else if (stream_index == -2)
1000 Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1001 int64_t pos, pos2, ts;
1017 (
void **) next_node);
1019 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1022 next_node[1]->pos, next_node[1]->pos,
1023 next_node[0]->ts, next_node[1]->ts,
1027 dummy.
pos = pos + 16;
1028 next_node[1] = &nopts_sp;
1030 (
void **) next_node);
1032 next_node[1]->pos, next_node[1]->pos,
1033 next_node[0]->back_ptr, next_node[1]->back_ptr,
1050 if (pos2 > pos || pos2 + 15 < pos)
1067 .extensions =
"nut",
#define NUT_STABLE_VERSION
uint64_t ffio_read_varlen(AVIOContext *bc)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t pos
byte position in stream, -1 if unknown
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)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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)
static int decode_main_header(NUTContext *nut)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
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)
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
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.
unsigned int avio_rb32(AVIOContext *s)
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.
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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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
#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.
enum AVMediaType codec_type
General type of the encoded data.
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[]
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b)
int flags
A combination of AV_PKT_FLAG values.
int extradata_size
Size of the extradata content in bytes.
int avio_r8(AVIOContext *s)
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)
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
static int find_and_decode_index(NUTContext *nut)
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static uint64_t get_fourcc(AVIOContext *bc)
static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode)
struct AVTreeNode * syncpoints
static int nut_read_header(AVFormatContext *s)
static int read_header(FFV1Context *f)
if(ac->has_optimized_func)
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
#define AV_LOG_INFO
Standard information.
const AVCodecTag ff_nut_subtitle_tags[]
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
AVIOContext * pb
I/O context.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
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)
rational number numerator/denominator
unsigned long ffio_get_checksum(AVIOContext *s)
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)
static int64_t pts
Global timestamp for the audio frames.
int sample_rate
Audio only.
const Dispositions ff_nut_dispositions[]
unsigned int avio_rl16(AVIOContext *s)
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 AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define SYNCPOINT_STARTCODE
int eof_reached
true if eof reached
AVInputFormat ff_nut_demuxer
static int64_t get_s(AVIOContext *bc)
void * priv_data
Format private data.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVCodecParameters * codecpar
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
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.
const AVCodecTag *const ff_nut_codec_tags[]
This structure stores compressed data.
unsigned int time_base_count
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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