30 #define CHECK_SUBSEQUENT_NSVS
36 #define NSV_MAX_RESYNC (500*1024)
37 #define NSV_MAX_RESYNC_TRIES 300
93 uint32_t info_strings_size;
94 uint32_t table_entries;
95 uint32_t table_entries_used;
108 struct nsv_avchunk_header {
110 uint16_t vchunk_size_msb;
111 uint16_t achunk_size;
114 struct nsv_pcm_header {
129 #define T_NSVF MKTAG('N', 'S', 'V', 'f')
130 #define T_NSVS MKTAG('N', 'S', 'V', 's')
131 #define T_TOC2 MKTAG('T', 'O', 'C', '2')
132 #define T_NONE MKTAG('N', 'O', 'N', 'E')
133 #define T_SUBT MKTAG('S', 'U', 'B', 'T')
134 #define T_ASYN MKTAG('A', 'S', 'Y', 'N')
135 #define T_KEYF MKTAG('K', 'E', 'Y', 'F')
137 #define TB_NSVF MKBETAG('N', 'S', 'V', 'f')
138 #define TB_NSVS MKBETAG('N', 'S', 'V', 's')
141 #define NSV_ST_VIDEO 0
142 #define NSV_ST_AUDIO 1
143 #define NSV_ST_SUBT 2
218 #define print_tag(str, tag, size) \
219 av_dlog(NULL, "%s: tag=%c%c%c%c\n", \
222 (tag >> 16) & 0xff, \
246 av_dlog(s,
"NSV resync: [%d] = %02x\n", i, v & 0x0FF);
249 if ((v & 0x0000ffff) == 0xefbe) {
250 av_dlog(s,
"NSV resynced on BEEF after %d bytes\n", i+1);
256 av_dlog(s,
"NSV resynced on NSVf after %d bytes\n", i+1);
260 if (v ==
MKBETAG(
'N',
'S',
'V',
's')) {
261 av_dlog(s,
"NSV resynced on NSVs after %d bytes\n", i+1);
280 int table_entries_used;
282 av_dlog(s,
"%s()\n", __FUNCTION__);
293 av_dlog(s,
"NSV NSVf chunk_size %u\n", size);
294 av_dlog(s,
"NSV NSVf file_size %u\n", file_size);
297 av_dlog(s,
"NSV NSVf duration %"PRId64
" ms\n", duration);
303 av_dlog(s,
"NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
304 strings_size, table_entries, table_entries_used);
310 if (strings_size > 0) {
316 p = strings =
av_mallocz((
size_t)strings_size + 1);
319 endp = strings + strings_size;
328 if (!p || p >= endp-2)
333 p = strchr(p, quote);
337 av_dlog(s,
"NSV NSVf INFO: %s='%s'\n", token, value);
347 if (table_entries_used > 0) {
350 if((
unsigned)table_entries_used >= UINT_MAX /
sizeof(uint32_t))
356 for(i=0;i<table_entries_used;i++)
359 if(table_entries > table_entries_used &&
364 for(i=0;i<table_entries_used;i++) {
372 #ifdef DEBUG_DUMP_INDEX
373 #define V(v) ((v<0x20 || v > 127)?'.':v)
375 av_dlog(s,
"NSV %d INDEX ENTRIES:\n", table_entries);
376 av_dlog(s,
"NSV [dataoffset][fileoffset]\n", table_entries);
377 for (i = 0; i < table_entries; i++) {
381 av_dlog(s,
"NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
382 "%c%c%c%c%c%c%c%c\n",
384 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
385 V(b[0]),
V(b[1]),
V(b[2]),
V(b[3]),
V(b[4]),
V(b[5]),
V(b[6]),
V(b[7]) );
404 uint16_t vwidth, vheight;
409 av_dlog(s,
"%s()\n", __FUNCTION__);
417 av_dlog(s,
"NSV NSVs framerate code %2x\n", i);
424 framerate.
num *= 1000;
425 framerate.
den *= 1001;
428 if((i&3)==3) framerate.
num *= 24;
429 else if((i&3)==2) framerate.
num *= 25;
430 else framerate.
num *= 30;
440 av_dlog(s,
"NSV NSVs vsize %dx%d\n", vwidth, vheight);
481 #ifndef DISABLE_AUDIO
503 #ifdef CHECK_SUBSEQUENT_NSVS
506 av_dlog(s,
"NSV NSVs header values differ from the first one!!!\n");
525 av_dlog(s,
"%s()\n", __FUNCTION__);
569 av_dlog(s,
"%s(%d)\n", __FUNCTION__, fill_header);
592 vsize = (vsize << 4) | (auxcount >> 4);
594 av_dlog(s,
"NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize);
596 for (i = 0; i < auxcount; i++) {
600 av_dlog(s,
"NSV aux data: '%c%c%c%c', %d bytes\n",
602 ((auxtag >> 8) & 0x0ff),
603 ((auxtag >> 16) & 0x0ff),
604 ((auxtag >> 24) & 0x0ff),
607 vsize -= auxsize +
sizeof(uint16_t) +
sizeof(uint32_t);
612 if (!vsize && !asize) {
614 goto null_chunk_retry;
630 for (i = 0; i <
FFMIN(8, vsize); i++)
631 av_dlog(s,
"NSV video: [%d] = %02x\n", i, pkt->
data[i]);
634 ((
NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++;
641 if (asize && st[NSV_ST_AUDIO]->codec->codec_tag ==
MKTAG(
'P',
'C',
'M',
' ')) {
649 av_dlog(s,
"NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
653 av_dlog(s,
"NSV AUDIO bit/sample != 16 (%d)!!!\n", bps);
665 av_dlog(s,
"NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
673 pkt->
dts = (((
NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset-1);
691 av_dlog(s,
"%s()\n", __FUNCTION__);
700 for (i = 0; i < 2; i++) {
702 av_dlog(s,
"%s: using cached packet[%d]\n", __FUNCTION__, i);
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++) {
780 int offset = i + 23 + asize + vsize + 1;
781 if (offset <= p->buf_size - 2 &&
AV_RL16(p->
buf + offset) == 0xBEEF)