29 #define CHECK_SUBSEQUENT_NSVS
35 #define NSV_MAX_RESYNC (500*1024)
36 #define NSV_MAX_RESYNC_TRIES 300
96 uint32_t info_strings_size;
97 uint32_t table_entries;
98 uint32_t table_entries_used;
111 struct nsv_avchunk_header {
113 uint16_t vchunk_size_msb;
114 uint16_t achunk_size;
117 struct nsv_pcm_header {
120 uint16_t sample_rate;
132 #define T_NSVF MKTAG('N', 'S', 'V', 'f')
133 #define T_NSVS MKTAG('N', 'S', 'V', 's')
134 #define T_TOC2 MKTAG('T', 'O', 'C', '2')
135 #define T_NONE MKTAG('N', 'O', 'N', 'E')
136 #define T_SUBT MKTAG('S', 'U', 'B', 'T')
137 #define T_ASYN MKTAG('A', 'S', 'Y', 'N')
138 #define T_KEYF MKTAG('K', 'E', 'Y', 'F')
140 #define TB_NSVF MKBETAG('N', 'S', 'V', 'f')
141 #define TB_NSVS MKBETAG('N', 'S', 'V', 's')
144 #define NSV_ST_VIDEO 0
145 #define NSV_ST_AUDIO 1
146 #define NSV_ST_SUBT 2
219 #define print_tag(str, tag, size) \
220 av_dlog(NULL, "%s: tag=%c%c%c%c\n", \
223 (tag >> 16) & 0xff, \
247 av_dlog(s,
"NSV resync: [%d] = %02x\n", i, v & 0x0FF);
250 if ((v & 0x0000ffff) == 0xefbe) {
251 av_dlog(s,
"NSV resynced on BEEF after %d bytes\n", i+1);
257 av_dlog(s,
"NSV resynced on NSVf after %d bytes\n", i+1);
261 if (v ==
MKBETAG(
'N',
'S',
'V',
's')) {
262 av_dlog(s,
"NSV resynced on NSVs after %d bytes\n", i+1);
281 int table_entries_used;
283 av_dlog(s,
"%s()\n", __FUNCTION__);
294 av_dlog(s,
"NSV NSVf chunk_size %u\n", size);
295 av_dlog(s,
"NSV NSVf file_size %u\n", file_size);
298 av_dlog(s,
"NSV NSVf duration %"PRId64
" ms\n", duration);
304 av_dlog(s,
"NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
305 strings_size, table_entries, table_entries_used);
311 if (strings_size > 0) {
317 p = strings =
av_mallocz((
size_t)strings_size + 1);
320 endp = strings + strings_size;
329 if (!p || p >= endp-2)
334 p = strchr(p, quote);
338 av_dlog(s,
"NSV NSVf INFO: %s='%s'\n", token, value);
348 if (table_entries_used > 0) {
351 if((
unsigned)table_entries_used >= UINT_MAX /
sizeof(uint32_t))
357 for(i=0;i<table_entries_used;i++)
360 if(table_entries > table_entries_used &&
365 for(i=0;i<table_entries_used;i++) {
373 #ifdef DEBUG_DUMP_INDEX
374 #define V(v) ((v<0x20 || v > 127)?'.':v)
376 av_dlog(s,
"NSV %d INDEX ENTRIES:\n", table_entries);
377 av_dlog(s,
"NSV [dataoffset][fileoffset]\n", table_entries);
378 for (i = 0; i < table_entries; i++) {
382 av_dlog(s,
"NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
383 "%c%c%c%c%c%c%c%c\n",
385 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
386 V(b[0]),
V(b[1]),
V(b[2]),
V(b[3]),
V(b[4]),
V(b[5]),
V(b[6]),
V(b[7]) );
405 uint16_t vwidth, vheight;
410 av_dlog(s,
"%s()\n", __FUNCTION__);
418 av_dlog(s,
"NSV NSVs framerate code %2x\n", i);
425 framerate.
num *= 1000;
426 framerate.
den *= 1001;
429 if((i&3)==3) framerate.
num *= 24;
430 else if((i&3)==2) framerate.
num *= 25;
431 else framerate.
num *= 30;
441 av_dlog(s,
"NSV NSVs vsize %dx%d\n", vwidth, vheight);
482 #ifndef DISABLE_AUDIO
504 #ifdef CHECK_SUBSEQUENT_NSVS
507 av_dlog(s,
"NSV NSVs header values differ from the first one!!!\n");
526 av_dlog(s,
"%s()\n", __FUNCTION__);
570 av_dlog(s,
"%s(%d)\n", __FUNCTION__, fill_header);
593 vsize = (vsize << 4) | (auxcount >> 4);
595 av_dlog(s,
"NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize);
597 for (i = 0; i < auxcount; i++) {
601 av_dlog(s,
"NSV aux data: '%c%c%c%c', %d bytes\n",
603 ((auxtag >> 8) & 0x0ff),
604 ((auxtag >> 16) & 0x0ff),
605 ((auxtag >> 24) & 0x0ff),
608 vsize -= auxsize +
sizeof(uint16_t) +
sizeof(uint32_t);
613 if (!vsize && !asize) {
615 goto null_chunk_retry;
631 for (i = 0; i <
FFMIN(8, vsize); i++)
632 av_dlog(s,
"NSV video: [%d] = %02x\n", i, pkt->
data[i]);
635 ((
NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++;
642 if (asize && st[NSV_ST_AUDIO]->codec->codec_tag ==
MKTAG(
'P',
'C',
'M',
' ')) {
650 av_dlog(s,
"NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
654 av_dlog(s,
"NSV AUDIO bit/sample != 16 (%d)!!!\n", bps);
663 av_dlog(s,
"NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
671 pkt->
dts = (((
NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset-1);
689 av_dlog(s,
"%s()\n", __FUNCTION__);
698 for (i = 0; i < 2; i++) {
700 av_dlog(s,
"%s: using cached packet[%d]\n", __FUNCTION__, i);
763 int vsize, asize, auxcount;
768 if (p->
buf[0] ==
'N' && p->
buf[1] ==
'S' &&
769 p->
buf[2] ==
'V' && (p->
buf[3] ==
'f' || p->
buf[3] ==
's'))
775 for (i = 1; i < p->
buf_size - 3; i++) {
776 if (p->
buf[i+0] ==
'N' && p->
buf[i+1] ==
'S' &&
777 p->
buf[i+2] ==
'V' && p->
buf[i+3] ==
's') {
780 auxcount = p->
buf[i+19];
781 vsize = p->
buf[i+20] | p->
buf[i+21] << 8;
782 asize = p->
buf[i+22] | p->
buf[i+23] << 8;
783 vsize = (vsize << 4) | (auxcount >> 4);
784 if ((asize + vsize + i + 23) < p->
buf_size - 2) {
785 if (p->
buf[i+23+asize+vsize+1] == 0xEF &&
786 p->
buf[i+23+asize+vsize+2] == 0xBE)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void av_free_packet(AVPacket *pkt)
Free a packet.
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 const AVCodecTag nsv_codec_video_tags[]
static int nsv_parse_NSVf_header(AVFormatContext *s)
uint32_t * nsvs_file_offset
uint32_t * nsvs_timestamps
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
int index
stream index in AVFormatContext
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.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", 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)
static const AVCodecTag nsv_codec_audio_tags[]
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define NSV_MAX_RESYNC_TRIES
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
static av_cold int read_close(AVFormatContext *ctx)
#define MKTAG(a, b, c, d)
static int nsv_resync(AVFormatContext *s)
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static int nsv_read_close(AVFormatContext *s)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int nsv_read_packet(AVFormatContext *s, AVPacket *pkt)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
static int nsv_read_chunk(AVFormatContext *s, int fill_header)
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
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.
AVInputFormat ff_nsv_demuxer
struct AVRational AVRational
rational number numerator/denominator
static int nsv_parse_NSVs_header(AVFormatContext *s)
char filename[1024]
input or output filename
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int width
picture width / height.
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static int nsv_probe(AVProbeData *p)
static int read_header(FFV1Context *f)
enum AVMediaType codec_type
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').
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 MKBETAG(a, b, c, d)
rational number numerator/denominator
This structure contains the data a format has to probe a file.
static int nsv_read_header(AVFormatContext *s)
int64_t duration
Decoding: duration of the stream, in stream time base.
unsigned int avio_rl16(AVIOContext *s)
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
#define AVPROBE_SCORE_MAX
struct NSVStream NSVStream
int eof_reached
true if eof reached
int channels
number of audio channels
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define print_tag(str, tag, size)
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...