23 #include "libavutil/avstring.h"
24 #include "libavutil/avassert.h"
25 #include "libavutil/bswap.h"
26 #include "libavutil/dict.h"
27 #include "libavutil/mathematics.h"
33 #define NUT_MAX_STREAMS 256
36 int64_t *pos_arg, int64_t pos_limit);
44 while (len > maxlen) {
50 string[
FFMIN(len, maxlen - 1)] = 0;
83 static inline uint64_t get_v_trace(
AVIOContext *bc,
const char *file,
89 v, v, file, func, line);
93 static inline int64_t get_s_trace(
AVIOContext *bc,
const char *file,
99 v, v, file, func, line);
103 static inline uint64_t get_4cc_trace(
AVIOContext *bc,
char *file,
109 v, v, file, func, line);
112 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
113 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
114 #define get_fourcc(bc) get_4cc_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
118 int calculate_checksum, uint64_t startcode)
147 state = (state << 8) |
avio_r8(bc);
148 if ((state >> 56) !=
'N')
173 if (startcode == code)
175 else if (startcode == 0)
187 code = (code << 8) | p->
buf[i];
194 #define GET_V(dst, check) \
196 tmp = ffio_read_varlen(bc); \
198 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
199 return AVERROR_INVALIDDATA; \
222 unsigned int stream_count;
224 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
261 for (i = 0; i < 256;) {
282 count = tmp_mul - tmp_size;
288 while (tmp_fields-- > 8)
291 if (count == 0 || i + count > 256) {
295 if (tmp_stream >= stream_count) {
300 for (j = 0; j <
count; j++, i++) {
346 for (i = 0; i < stream_count; i++)
357 int class, stream_id;
365 stc = &nut->
stream[stream_id];
370 class = ffio_read_varlen(bc);
406 "Unknown codec tag '0x%04x' for stream number %d\n",
407 (
unsigned int) tmp, stream_id);
441 "stream header %d checksum mismatch\n", stream_id);
461 if (stream_id == i || stream_id == -1)
469 uint64_t tmp, chapter_start, chapter_len;
470 unsigned int stream_id_plus1,
count;
473 char name[256], str_value[1024], type_str[256];
482 GET_V(stream_id_plus1, tmp <= s->nb_streams);
483 chapter_id =
get_s(bc);
488 if (chapter_id && !stream_id_plus1) {
493 start, start + chapter_len, NULL);
495 }
else if (stream_id_plus1) {
496 st = s->
streams[stream_id_plus1 - 1];
501 for (i = 0; i <
count; i++) {
502 get_str(bc, name,
sizeof(name));
506 get_str(bc, str_value,
sizeof(str_value));
507 }
else if (value == -2) {
508 get_str(bc, type_str,
sizeof(type_str));
510 get_str(bc, str_value,
sizeof(str_value));
511 }
else if (value == -3) {
514 }
else if (value == -4) {
517 }
else if (value < -4) {
529 if (!strcmp(type,
"UTF-8")) {
530 if (chapter_id == 0 && !strcmp(name,
"Disposition")) {
535 if (stream_id_plus1 && !strcmp(name,
"r_frame_rate")) {
608 int i, j, syncpoint_count;
612 int8_t *has_keyframe;
637 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
640 if (!syncpoints || !has_keyframe) {
644 for (i = 0; i < syncpoint_count; i++) {
646 if (syncpoints[i] <= 0)
649 syncpoints[i] += syncpoints[i - 1];
654 for (j = 0; j < syncpoint_count;) {
662 if (n + x >= syncpoint_count + 1) {
663 av_log(s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
667 has_keyframe[n++] = flag;
668 has_keyframe[n++] = !flag;
671 if (n >= syncpoint_count + 1) {
675 has_keyframe[n++] = x & 1;
679 if (has_keyframe[0]) {
684 for (; j < n && j < syncpoint_count; j++) {
685 if (has_keyframe[j]) {
718 int initialized_stream_count;
734 for (initialized_stream_count = 0; initialized_stream_count < s->
nb_streams;) {
741 initialized_stream_count++;
750 if (startcode == 0) {
778 uint8_t *header_idx,
int frame_code)
783 int size,
flags, size_mul, pts_delta, i, reserved_count;
788 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
806 GET_V(*stream_id, tmp < s->nb_streams);
808 stc = &nut->
stream[*stream_id];
826 for (i = 0; i < reserved_count; i++)
855 int size, stream_id, discard;
856 int64_t pts, last_IP_pts;
864 stc = &nut->
stream[stream_id];
873 last_IP_pts > pts) ||
898 int i, frame_code = 0,
ret, skip;
899 int64_t ts, back_ptr;
912 if (frame_code ==
'N') {
914 for (i = 1; i < 8; i++)
915 tmp = (tmp << 8) +
avio_r8(bc);
952 int64_t *pos_arg, int64_t pos_limit)
956 int64_t pos, pts, back_ptr;
958 stream_index, *pos_arg, pos_limit);
972 if (stream_index == -2)
979 int64_t pts,
int flags)
985 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
986 int64_t pos, pos2, ts;
1000 (
void **) next_node);
1002 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1005 next_node[1]->
pos, next_node[1]->
pos,
1006 next_node[0]->
ts, next_node[1]->
ts,
1010 dummy.
pos = pos + 16;
1011 next_node[1] = &nopts_sp;
1013 (
void **) next_node);
1015 next_node[1]->
pos, next_node[1]->
pos,
1033 if (pos2 > pos || pos2 + 15 < pos)
1065 .extensions =
"nut",
uint64_t ffio_read_varlen(AVIOContext *bc)
discard all frames except keyframes
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
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 ...
int64_t pos
byte position in stream, -1 if unknown
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
AVCodecContext * codec
Codec context associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
int64_t data_offset
offset of the first packet
static int decode_main_header(NUTContext *nut)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const uint8_t * header[128]
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
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)
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(void *key, const void *b), void *next[2])
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.
static av_cold int end(AVCodecContext *avctx)
if set, coded_pts is in the frame header
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
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)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static av_cold int read_close(AVFormatContext *ctx)
const AVCodecTag ff_nut_data_tags[]
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
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.
int has_b_frames
Size of the frame reordering buffer in the decoder.
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.
void * priv_data
Format private data.
discard all bidirectional frames
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.
int64_t av_const 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.
static int nut_read_close(AVFormatContext *s)
int buf_size
Size of buf except extra allocated bytes.
unsigned int nb_streams
A list of all streams in the file.
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.
Opaque data information usually continuous.
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)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)
#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
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
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)
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)
static void * av_malloc_array(size_t nmemb, size_t size)
static int64_t find_duration(NUTContext *nut, int64_t filesize)
const Dispositions ff_nut_dispositions[]
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
#define AVERROR_INVALIDDATA
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)
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
if set, stream_id is coded in the frame header
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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.
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