34 #define NUT_MAX_STREAMS 256
47 string[
FFMIN(len, maxlen-1)]= 0;
58 if (v&1)
return -(v>>1);
71 static inline uint64_t get_v_trace(
AVIOContext *bc,
char *file,
char *func,
int line){
78 static inline int64_t get_s_trace(
AVIOContext *bc,
char *file,
char *func,
int line){
84 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
85 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
115 state= (state<<8) |
avio_r8(bc);
116 if((state>>56) !=
'N')
140 if(startcode == code)
142 else if(startcode == 0)
153 code = (code << 8) | p->
buf[i];
160 #define GET_V(dst, check) \
161 tmp= ffio_read_varlen(bc);\
163 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp);\
184 unsigned int stream_count;
185 int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res, tmp_head_idx;
190 GET_V(tmp , tmp >=2 && tmp <= 3)
217 if(tmp_fields>0) tmp_pts =
get_s(bc);
225 else count = tmp_mul - tmp_size;
226 if(tmp_fields>6)
get_s(bc);
229 while(tmp_fields-- > 8)
232 if(count == 0 || i+count > 256){
236 if(tmp_stream >= stream_count){
241 for(j=0; j<count; j++,i++){
281 for(i=0; i<stream_count; i++){
292 int class, stream_id;
300 stc= &nut->
stream[stream_id];
306 class = ffio_read_varlen(bc);
334 (
unsigned int)tmp, stream_id);
382 if (stream_id == i || stream_id == -1)
389 uint64_t tmp, chapter_start, chapter_len;
390 unsigned int stream_id_plus1, count;
393 char name[256], str_value[1024], type_str[256];
402 GET_V(stream_id_plus1, tmp <= s->nb_streams)
403 chapter_id =
get_s(bc);
408 if(chapter_id && !stream_id_plus1){
412 start, start + chapter_len,
NULL);
414 }
else if(stream_id_plus1) {
415 st= s->
streams[stream_id_plus1 - 1];
420 for(i=0; i<count; i++){
421 get_str(bc, name,
sizeof(name));
425 get_str(bc, str_value,
sizeof(str_value));
426 }
else if(value == -2){
427 get_str(bc, type_str,
sizeof(type_str));
429 get_str(bc, str_value,
sizeof(str_value));
430 }
else if(value == -3){
433 }
else if(value == -4){
436 }
else if(value < -4){
448 if(!strcmp(type,
"UTF-8")){
449 if(chapter_id==0 && !strcmp(name,
"Disposition")) {
498 int i, j, syncpoint_count;
501 int8_t *has_keyframe;
515 GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0)
516 syncpoints=
av_malloc(
sizeof(int64_t)*syncpoint_count);
517 has_keyframe=
av_malloc(
sizeof(int8_t)*(syncpoint_count+1));
518 for(i=0; i<syncpoint_count; i++){
520 if(syncpoints[i] <= 0)
523 syncpoints[i] += syncpoints[i-1];
527 int64_t last_pts= -1;
528 for(j=0; j<syncpoint_count;){
536 if(n+x >= syncpoint_count + 1){
541 has_keyframe[n++]= flag;
542 has_keyframe[n++]= !flag;
545 if(n>=syncpoint_count + 1){
549 has_keyframe[n++]= x&1;
557 assert(n<=syncpoint_count+1);
558 for(; j<n && j<syncpoint_count; j++){
596 int initialized_stream_count;
612 for(initialized_stream_count=0; initialized_stream_count < s->
nb_streams;){
619 initialized_stream_count++;
659 int size,
flags, size_mul, pts_delta, i, reserved_count;
680 GET_V(*stream_id, tmp < s->nb_streams)
682 stc= &nut->
stream[*stream_id];
701 for(i=0; i<reserved_count; i++)
728 int size, stream_id, discard;
729 int64_t pts, last_IP_pts;
737 stc= &nut->
stream[stream_id];
769 int i, frame_code=0, ret, skip;
770 int64_t ts, back_ptr;
783 if(frame_code ==
'N'){
825 int64_t pos, pts, back_ptr;
826 av_log(s,
AV_LOG_DEBUG,
"read_timestamp(X,%d,%"PRId64
",%"PRId64
")\n", stream_index, *pos_arg, pos_limit);
841 if (stream_index == -1)
return pts;
842 else if(stream_index == -2)
return back_ptr;
852 Syncpoint *
sp, *next_node[2]= {&nopts_sp, &nopts_sp};
853 int64_t pos, pos2, ts;
865 (
void **) next_node);
866 av_log(s,
AV_LOG_DEBUG,
"%"PRIu64
"-%"PRIu64
" %"PRId64
"-%"PRId64
"\n", next_node[0]->pos, next_node[1]->pos,
867 next_node[0]->ts , next_node[1]->ts);
873 next_node[1]= &nopts_sp;
875 (
void **) next_node);
893 if(pos2 > pos || pos2 + 15 < pos){
916 #if CONFIG_NUT_DEMUXER
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
uint64_t ffio_read_varlen(AVIOContext *bc)
#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.
int64_t pos
byte position in stream, -1 if unknown
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)
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.
discard all bidirectional frames
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t data_offset
offset of the first packet
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)
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])
Opaque data information usually continuous.
static int nut_probe(AVProbeData *p)
unsigned int avio_rb32(AVIOContext *s)
if set, coded_pts is in the frame header
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
If set, match_time_delta is coded in the frame header.
const AVMetadataConv ff_nut_metadata_conv[]
static int read_header(FFV1Context *f)
static double av_q2d(AVRational a)
Convert rational to double.
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
static av_cold int read_close(AVFormatContext *ctx)
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
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.
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.
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
static int decode_stream_header(NUTContext *nut)
static AVDictionary * metadata
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
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
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.
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)
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)
static int find_and_decode_index(NUTContext *nut)
enum CodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the CodecID for the given codec tag tag.
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)
static int read_probe(AVProbeData *p)
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
if set, the frame header contains a checksum
void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
enum AVMediaType codec_type
const AVCodecTag ff_nut_subtitle_tags[]
int sample_rate
samples per second
static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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
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)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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 Dispositions ff_nut_dispositions[]
unsigned int avio_rl16(AVIOContext *s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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[]
#define SYNCPOINT_STARTCODE
int eof_reached
true if eof reached
If set, header_idx is coded in the frame header.
int channels
number of audio channels
static int64_t get_s(AVIOContext *bc)
void * priv_data
Format private data.
if set, stream_id is coded in the frame header
discard all frames except keyframes
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.
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