34 #define NSV_MAX_RESYNC (500*1024)
35 #define NSV_MAX_RESYNC_TRIES 300
90 uint32_t info_strings_size;
91 uint32_t table_entries;
92 uint32_t table_entries_used;
105 struct nsv_avchunk_header {
107 uint16_t vchunk_size_msb;
108 uint16_t achunk_size;
111 struct nsv_pcm_header {
126 #define T_NSVF MKTAG('N', 'S', 'V', 'f')
127 #define T_NSVS MKTAG('N', 'S', 'V', 's')
128 #define T_TOC2 MKTAG('T', 'O', 'C', '2')
129 #define T_NONE MKTAG('N', 'O', 'N', 'E')
130 #define T_SUBT MKTAG('S', 'U', 'B', 'T')
131 #define T_ASYN MKTAG('A', 'S', 'Y', 'N')
132 #define T_KEYF MKTAG('K', 'E', 'Y', 'F')
134 #define TB_NSVF MKBETAG('N', 'S', 'V', 'f')
135 #define TB_NSVS MKBETAG('N', 'S', 'V', 's')
138 #define NSV_ST_VIDEO 0
139 #define NSV_ST_AUDIO 1
140 #define NSV_ST_SUBT 2
215 #define print_tag(str, tag, size) \
216 av_dlog(NULL, "%s: tag=%c%c%c%c\n", \
219 (tag >> 16) & 0xff, \
243 av_dlog(s,
"NSV resync: [%d] = %02x\n", i, v & 0x0FF);
246 if ((v & 0x0000ffff) == 0xefbe) {
247 av_dlog(s,
"NSV resynced on BEEF after %d bytes\n", i+1);
253 av_dlog(s,
"NSV resynced on NSVf after %d bytes\n", i+1);
257 if (v ==
MKBETAG(
'N',
'S',
'V',
's')) {
258 av_dlog(s,
"NSV resynced on NSVs after %d bytes\n", i+1);
277 int table_entries_used;
279 av_dlog(s,
"%s()\n", __FUNCTION__);
290 av_dlog(s,
"NSV NSVf chunk_size %u\n", size);
291 av_dlog(s,
"NSV NSVf file_size %u\n", file_size);
294 av_dlog(s,
"NSV NSVf duration %"PRId64
" ms\n", duration);
300 av_dlog(s,
"NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
301 strings_size, table_entries, table_entries_used);
307 if (strings_size > 0) {
313 p = strings =
av_mallocz((
size_t)strings_size + 1);
316 endp = strings + strings_size;
325 if (!p || p >= endp-2)
330 p = strchr(p, quote);
334 av_dlog(s,
"NSV NSVf INFO: %s='%s'\n", token, value);
344 if (table_entries_used > 0) {
347 if((
unsigned)table_entries_used >= UINT_MAX /
sizeof(uint32_t))
353 for(i=0;i<table_entries_used;i++)
356 if(table_entries > table_entries_used &&
361 for(i=0;i<table_entries_used;i++) {
382 uint16_t vwidth, vheight;
387 av_dlog(s,
"%s()\n", __FUNCTION__);
395 av_dlog(s,
"NSV NSVs framerate code %2x\n", i);
402 framerate.
num *= 1000;
403 framerate.
den *= 1001;
406 if((i&3)==3) framerate.
num *= 24;
407 else if((i&3)==2) framerate.
num *= 25;
408 else framerate.
num *= 30;
418 av_dlog(s,
"NSV NSVs vsize %dx%d\n", vwidth, vheight);
481 av_dlog(s,
"NSV NSVs header values differ from the first one!!!\n");
499 av_dlog(s,
"%s()\n", __FUNCTION__);
544 av_dlog(s,
"%s(%d)\n", __FUNCTION__, fill_header);
567 vsize = (vsize << 4) | (auxcount >> 4);
569 av_dlog(s,
"NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize);
571 for (i = 0; i < auxcount; i++) {
575 av_dlog(s,
"NSV aux data: '%c%c%c%c', %d bytes\n",
577 ((auxtag >> 8) & 0x0ff),
578 ((auxtag >> 16) & 0x0ff),
579 ((auxtag >> 24) & 0x0ff),
582 vsize -= auxsize +
sizeof(uint16_t) +
sizeof(uint32_t);
587 if (!vsize && !asize) {
589 goto null_chunk_retry;
606 for (i = 0; i <
FFMIN(8, vsize); i++)
607 av_dlog(s,
"NSV video: [%d] = %02x\n", i, pkt->
data[i]);
610 ((
NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++;
617 if (asize && st[NSV_ST_AUDIO]->codec->codec_tag ==
MKTAG(
'P',
'C',
'M',
' ')) {
624 if (!channels || !samplerate)
627 av_dlog(s,
"NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
631 av_dlog(s,
"NSV AUDIO bit/sample != 16 (%d)!!!\n", bps);
640 av_dlog(s,
"NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
649 pkt->
dts = (((
NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset-1);
667 av_dlog(s,
"%s()\n", __FUNCTION__);
676 for (i = 0; i < 2; i++) {
678 av_dlog(s,
"%s: using cached packet[%d]\n", __FUNCTION__, i);
729 if (p->
buf[0] ==
'N' && p->
buf[1] ==
'S' &&
730 p->
buf[2] ==
'V' && (p->
buf[3] ==
'f' || p->
buf[3] ==
's'))
736 for (i = 1; i < p->
buf_size - 3; i++) {
741 int offset = i + 23 + asize + vsize + 1;
742 if (offset <= p->buf_size - 2 &&
AV_RL16(p->
buf + offset) == 0xBEEF)