Go to the documentation of this file.
37 #define NUT_MAX_STREAMS 256
40 int64_t *pos_arg, int64_t pos_limit);
48 while (
len > maxlen) {
91 int calculate_checksum, uint64_t startcode)
120 if ((
state >> 56) !=
'N')
145 if (startcode ==
code)
147 else if (startcode == 0)
166 #define GET_V(dst, check) \
168 tmp = ffio_read_varlen(bc); \
170 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
171 ret = AVERROR_INVALIDDATA; \
197 uint64_t
tmp, end, length;
198 unsigned int stream_count;
199 int i, j, count,
ret;
200 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
203 if (length == (uint64_t)-1)
245 for (
i = 0;
i < 256;) {
248 if (tmp_fields < 0) {
271 count = tmp_mul - (unsigned)tmp_size;
277 while (tmp_fields-- > 8) {
286 if (count <= 0 || count > 256 - (
i <=
'N') -
i) {
291 if (tmp_stream >= stream_count) {
293 tmp_stream, stream_count);
297 if (tmp_size < 0 || tmp_size > INT_MAX - count) {
303 for (j = 0; j < count; j++,
i++) {
327 if (rem < nut->header_len[
i]) {
329 "invalid elision header %d : %d > %d\n",
362 for (
i = 0;
i < stream_count;
i++) {
384 int class, stream_id,
ret;
392 stc = &nut->
stream[stream_id];
393 st =
s->streams[stream_id];
397 class = ffio_read_varlen(bc);
435 "Unknown codec tag '0x%04x' for stream number %d\n",
436 (
unsigned int)
tmp, stream_id);
472 "stream header %d checksum mismatch\n", stream_id);
499 if (stream_id ==
i || stream_id == -1)
507 uint64_t
tmp, chapter_start, chapter_len;
508 unsigned int stream_id_plus1, count;
510 int64_t chapter_id,
value, end;
511 char name[256], str_value[1024], type_str[256];
513 int *event_flags =
NULL;
517 int metadata_flag = 0;
523 chapter_id =
get_s(bc);
528 if (chapter_id && !stream_id_plus1) {
533 start, start + chapter_len,
NULL);
539 }
else if (stream_id_plus1) {
540 st =
s->streams[stream_id_plus1 - 1];
545 metadata = &
s->metadata;
546 event_flags = &
s->event_flags;
550 for (
i = 0;
i < count;
i++) {
561 ret =
get_str(bc, str_value,
sizeof(str_value));
562 }
else if (
value == -2) {
563 ret =
get_str(bc, type_str,
sizeof(type_str));
569 ret =
get_str(bc, str_value,
sizeof(str_value));
570 }
else if (
value == -3) {
573 }
else if (
value == -4) {
576 }
else if (
value < -4) {
588 if (stream_id_plus1 >
s->nb_streams) {
590 "invalid stream id %d for info packet\n",
595 if (!strcmp(
type,
"UTF-8")) {
596 if (chapter_id == 0 && !strcmp(
name,
"Disposition")) {
601 if (stream_id_plus1 && !strcmp(
name,
"r_frame_rate")) {
612 *event_flags |= metadata_flag;
687 int i, j, syncpoint_count;
689 int64_t *syncpoints =
NULL;
691 int8_t *has_keyframe =
NULL;
716 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
719 if (!syncpoints || !has_keyframe) {
723 for (
i = 0;
i < syncpoint_count;
i++) {
725 if (syncpoints[
i] <= 0)
728 syncpoints[
i] += syncpoints[
i - 1];
731 for (
i = 0;
i <
s->nb_streams;
i++) {
733 for (j = 0; j < syncpoint_count;) {
741 if (n + x >= syncpoint_count + 1) {
742 av_log(
s,
AV_LOG_ERROR,
"index overflow A %d + %"PRIu64
" >= %d\n", n, x, syncpoint_count + 1);
746 has_keyframe[n++] =
flag;
747 has_keyframe[n++] = !
flag;
754 if (n >= syncpoint_count + 1) {
758 has_keyframe[n++] = x & 1;
762 if (has_keyframe[0]) {
767 for (; j < n && j < syncpoint_count; j++) {
768 if (has_keyframe[j]) {
815 int initialized_stream_count,
ret;
835 for (initialized_stream_count = 0; initialized_stream_count <
s->nb_streams;) {
842 initialized_stream_count++;
851 if (startcode == 0) {
884 int64_t channel_layout = 0;
890 for (
i=0;
i<count;
i++) {
891 uint8_t
name[256], str_value[256], type_str[256];
903 ret =
get_str(bc, str_value,
sizeof(str_value));
909 }
else if (
value == -2) {
911 int64_t v64, value_len;
913 ret =
get_str(bc, type_str,
sizeof(type_str));
919 if (value_len < 0 || value_len >= maxpos -
avio_tell(bc))
921 if (!strcmp(
name,
"Palette")) {
923 }
else if (!strcmp(
name,
"Extradata")) {
925 }
else if (sscanf(
name,
"CodecSpecificSide%"SCNd64
"", &v64) == 1) {
931 }
else if (!strcmp(
name,
"ChannelLayout") && value_len == 8) {
942 }
else if (
value == -3) {
944 }
else if (
value == -4) {
946 }
else if (
value < -4) {
949 if (!strcmp(
name,
"SkipStart")) {
951 }
else if (!strcmp(
name,
"SkipEnd")) {
953 }
else if (!strcmp(
name,
"Channels")) {
955 }
else if (!strcmp(
name,
"SampleRate")) {
957 }
else if (!strcmp(
name,
"Width")) {
959 }
else if (!strcmp(
name,
"Height")) {
971 bytestream_put_le32(&dst,
973 AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT*(!!
channels) +
974 AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT*(!!channel_layout) +
980 bytestream_put_le32(&dst,
channels);
982 bytestream_put_le64(&dst, channel_layout);
986 bytestream_put_le32(&dst,
width);
987 bytestream_put_le32(&dst,
height);
991 if (skip_start || skip_end) {
1006 uint8_t *header_idx,
int frame_code)
1011 int size,
flags, size_mul, pts_delta,
i, reserved_count,
ret;
1017 "Last frame must have been damaged %"PRId64
" > %"PRId64
" + %d\n",
1037 stc = &nut->
stream[*stream_id];
1055 for (
i = 0;
i < reserved_count;
i++) {
1092 int size, stream_id, discard,
ret;
1093 int64_t
pts, last_IP_pts;
1101 stc = &nut->
stream[stream_id];
1106 discard =
s->streams[stream_id]->discard;
1110 last_IP_pts >
pts) ||
1120 if (nut->
header[header_idx])
1160 int64_t ts, back_ptr;
1173 if (frame_code ==
'N') {
1175 for (
i = 1;
i < 8;
i++)
1214 int64_t *pos_arg, int64_t pos_limit)
1218 int64_t
pos,
pts, back_ptr;
1220 stream_index, *pos_arg, pos_limit);
1234 if (stream_index == -2)
1244 AVStream *st =
s->streams[stream_index];
1248 Syncpoint *
sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1249 int64_t
pos, pos2, ts;
1267 (
void **) next_node);
1269 next_node[0]->
pos, next_node[1]->
pos, next_node[0]->ts,
1272 next_node[1]->pos, next_node[1]->pos,
1273 next_node[0]->ts, next_node[1]->ts,
1280 next_node[1] = &nopts_sp;
1282 (
void **) next_node);
1284 next_node[1]->pos, next_node[1]->pos,
1285 next_node[0]->back_ptr, next_node[1]->back_ptr,
1296 pos2 =
sp->back_ptr - 15;
1303 if (pos2 >
pos || pos2 + 15 <
pos)
1305 for (
i = 0;
i <
s->nb_streams;
i++)
1324 .extensions =
"nut",
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
Perform a binary search using read_timestamp().
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static int nut_read_close(AVFormatContext *s)
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
const AVCodecTag ff_nut_audio_extra_tags[]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
enum AVMediaType codec_type
General type of the encoded data.
unsigned int time_base_count
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
unsigned int max_distance
#define AVERROR_EOF
End of file.
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
const AVCodecTag ff_nut_data_tags[]
#define SYNCPOINT_STARTCODE
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
AVStream ** streams
A list of all streams in the file.
const Dispositions ff_nut_dispositions[]
int64_t last_syncpoint_pos
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
#define AV_LOG_VERBOSE
Detailed information.
const AVCodecTag ff_codec_wav_tags[]
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
int buf_size
Size of buf except extra allocated bytes.
static int nut_probe(const AVProbeData *p)
static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
int nb_channels
Number of channels in this layout.
int64_t avio_size(AVIOContext *s)
Get the filesize.
static uint64_t get_fourcc(AVIOContext *bc)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
unsigned long ffio_get_checksum(AVIOContext *s)
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
int ff_nut_sp_pos_cmp(const void *a, const void *b)
void ff_nut_free_sp(NUTContext *nut)
static int64_t get_s(AVIOContext *bc)
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
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.
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static int skip_reserved(AVIOContext *bc, int64_t pos)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
const uint8_t * header[128]
unsigned int avio_rl16(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
const AVMetadataConv ff_nut_metadata_conv[]
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
Find the given startcode.
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t data_offset
offset of the first packet
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
@ AVDISCARD_BIDIR
discard all bidirectional frames
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define GET_V(dst, check)
@ AVDISCARD_ALL
discard all
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int ff_nut_sp_pts_cmp(const void *a, const void *b)
Rational number (pair of numerator and denominator).
uint64_t avio_rb64(AVIOContext *s)
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)
const AVCodecTag ff_nut_video_tags[]
const AVCodecTag ff_codec_movvideo_tags[]
AVChannelLayout ch_layout
Audio only.
int sample_rate
Audio only.
int extradata_size
Size of the extradata content in bytes.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static int decode_main_header(NUTContext *nut)
unsigned int avio_rl32(AVIOContext *s)
@ AVDISCARD_NONKEY
discard all frames except keyframes
const AVInputFormat ff_nut_demuxer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
#define FF_API_OLD_CHANNEL_LAYOUT
const AVCodecTag ff_nut_audio_tags[]
#define AV_NOPTS_VALUE
Undefined timestamp value.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int avio_r8(AVIOContext *s)
int flags
A combination of AV_PKT_FLAG values.
uint64_t ffio_read_varlen(AVIOContext *bc)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
#define AV_LOG_INFO
Standard information.
static int64_t filesize(AVIOContext *pb)
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
struct AVTreeNode * syncpoints
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
static int find_and_decode_index(NUTContext *nut)
#define AV_TIME_BASE
Internal time base represented as integer.
#define av_malloc_array(a, b)
static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
void * av_calloc(size_t nmemb, size_t size)
FrameCode frame_code[256]
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code)
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
const AVCodecTag ff_codec_bmp_tags[]
const AVCodecTag *const ff_nut_codec_tags[]
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
@ 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...
static int nut_read_header(AVFormatContext *s)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
AVRational r_frame_rate
Real base framerate of the stream.
int eof_reached
true if was unable to read due to error or eof
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static int read_probe(const AVProbeData *p)
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
const AVCodecTag ff_nut_subtitle_tags[]
int video_delay
Video only.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
static int decode_stream_header(NUTContext *nut)
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
uint64_t avio_rl64(AVIOContext *s)
#define flags(name, subs,...)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int64_t find_duration(NUTContext *nut, int64_t filesize)
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static int decode_info_header(NUTContext *nut)
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.