/*
* NSV demuxer
- * Copyright (c) 2004 The FFmpeg Project
+ * Copyright (c) 2004 The Libav Project
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
uint32_t v = 0;
int i;
- av_dlog(s, "%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, url_ftell(pb), nsv->state);
+ av_dlog(s, "%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, avio_tell(pb), nsv->state);
//nsv->state = NSV_UNSYNC;
for (i = 0; i < NSV_MAX_RESYNC; i++) {
- if (url_feof(pb)) {
+ if (pb->eof_reached) {
av_dlog(s, "NSV EOF\n");
nsv->state = NSV_UNSYNC;
return -1;
}
v <<= 8;
- v |= get_byte(pb);
+ v |= avio_r8(pb);
if (i < 8) {
av_dlog(s, "NSV resync: [%d] = %02x\n", i, v & 0x0FF);
}
nsv->state = NSV_UNSYNC; /* in case we fail */
- size = get_le32(pb);
+ size = avio_rl32(pb);
if (size < 28)
return -1;
nsv->NSVf_end = size;
- //s->file_size = (uint32_t)get_le32(pb);
- file_size = (uint32_t)get_le32(pb);
+ //s->file_size = (uint32_t)avio_rl32(pb);
+ file_size = (uint32_t)avio_rl32(pb);
av_dlog(s, "NSV NSVf chunk_size %u\n", size);
av_dlog(s, "NSV NSVf file_size %u\n", file_size);
- nsv->duration = duration = get_le32(pb); /* in ms */
+ nsv->duration = duration = avio_rl32(pb); /* in ms */
av_dlog(s, "NSV NSVf duration %"PRId64" ms\n", duration);
// XXX: store it in AVStreams
- strings_size = get_le32(pb);
- table_entries = get_le32(pb);
- table_entries_used = get_le32(pb);
+ strings_size = avio_rl32(pb);
+ table_entries = avio_rl32(pb);
+ table_entries_used = avio_rl32(pb);
av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
strings_size, table_entries, table_entries_used);
- if (url_feof(pb))
+ if (pb->eof_reached)
return -1;
- av_dlog(s, "NSV got header; filepos %"PRId64"\n", url_ftell(pb));
+ av_dlog(s, "NSV got header; filepos %"PRId64"\n", avio_tell(pb));
if (strings_size > 0) {
char *strings; /* last byte will be '\0' to play safe with str*() */
p = strings = av_mallocz(strings_size + 1);
endp = strings + strings_size;
- get_buffer(pb, strings, strings_size);
+ avio_read(pb, strings, strings_size);
while (p < endp) {
while (*p == ' ')
p++; /* strip out spaces */
}
av_free(strings);
}
- if (url_feof(pb))
+ if (pb->eof_reached)
return -1;
- av_dlog(s, "NSV got infos; filepos %"PRId64"\n", url_ftell(pb));
+ av_dlog(s, "NSV got infos; filepos %"PRId64"\n", avio_tell(pb));
if (table_entries_used > 0) {
int i;
nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t));
for(i=0;i<table_entries_used;i++)
- nsv->nsvs_file_offset[i] = get_le32(pb) + size;
+ nsv->nsvs_file_offset[i] = avio_rl32(pb) + size;
if(table_entries > table_entries_used &&
- get_le32(pb) == MKTAG('T','O','C','2')) {
+ avio_rl32(pb) == MKTAG('T','O','C','2')) {
nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t));
for(i=0;i<table_entries_used;i++) {
- nsv->nsvs_timestamps[i] = get_le32(pb);
+ nsv->nsvs_timestamps[i] = avio_rl32(pb);
}
}
}
- av_dlog(s, "NSV got index; filepos %"PRId64"\n", url_ftell(pb));
+ av_dlog(s, "NSV got index; filepos %"PRId64"\n", avio_tell(pb));
#ifdef DEBUG_DUMP_INDEX
#define V(v) ((v<0x20 || v > 127)?'.':v)
av_dlog(s, "NSV [dataoffset][fileoffset]\n", table_entries);
for (i = 0; i < table_entries; i++) {
unsigned char b[8];
- url_fseek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET);
- get_buffer(pb, b, 8);
+ avio_seek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET);
+ avio_read(pb, b, 8);
av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
"%c%c%c%c%c%c%c%c\n",
nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i],
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) );
}
- //url_fseek(pb, size, SEEK_SET); /* go back to end of header */
+ //avio_seek(pb, size, SEEK_SET); /* go back to end of header */
#undef V
#endif
- url_fseek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */
+ avio_seek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */
- if (url_feof(pb))
+ if (pb->eof_reached)
return -1;
nsv->state = NSV_HAS_READ_NSVF;
return 0;
NSVStream *nst;
av_dlog(s, "%s()\n", __FUNCTION__);
- vtag = get_le32(pb);
- atag = get_le32(pb);
- vwidth = get_le16(pb);
- vheight = get_le16(pb);
- i = get_byte(pb);
+ vtag = avio_rl32(pb);
+ atag = avio_rl32(pb);
+ vwidth = avio_rl16(pb);
+ vheight = avio_rl16(pb);
+ i = avio_r8(pb);
av_dlog(s, "NSV NSVs framerate code %2x\n", i);
if(i&0x80) { /* odd way of giving native framerates from docs */
else
framerate= (AVRational){i, 1};
- nsv->avsync = get_le16(pb);
+ nsv->avsync = avio_rl16(pb);
nsv->framerate = framerate;
print_tag("NSV NSVs vtag", vtag, 0);
return 0; //-1; /* hey! eat what you've in your plate first! */
null_chunk_retry:
- if (url_feof(pb))
+ if (pb->eof_reached)
return -1;
for (i = 0; i < NSV_MAX_RESYNC_TRIES && nsv->state < NSV_FOUND_NSVS && !err; i++)
if (nsv->state != NSV_HAS_READ_NSVS && nsv->state != NSV_FOUND_BEEF)
return -1;
- auxcount = get_byte(pb);
- vsize = get_le16(pb);
- asize = get_le16(pb);
+ auxcount = avio_r8(pb);
+ vsize = avio_rl16(pb);
+ asize = avio_rl16(pb);
vsize = (vsize << 4) | (auxcount >> 4);
auxcount &= 0x0f;
av_dlog(s, "NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize);
/* skip aux stuff */
for (i = 0; i < auxcount; i++) {
- auxsize = get_le16(pb);
- auxtag = get_le32(pb);
+ auxsize = avio_rl16(pb);
+ auxtag = avio_rl32(pb);
av_dlog(s, "NSV aux data: '%c%c%c%c', %d bytes\n",
(auxtag & 0x0ff),
((auxtag >> 8) & 0x0ff),
((auxtag >> 16) & 0x0ff),
((auxtag >> 24) & 0x0ff),
auxsize);
- url_fskip(pb, auxsize);
+ avio_skip(pb, auxsize);
vsize -= auxsize + sizeof(uint16_t) + sizeof(uint32_t); /* that's becoming braindead */
}
- if (url_feof(pb))
+ if (pb->eof_reached)
return -1;
if (!vsize && !asize) {
nsv->state = NSV_UNSYNC;
uint8_t bps;
uint8_t channels;
uint16_t samplerate;
- bps = get_byte(pb);
- channels = get_byte(pb);
- samplerate = get_le16(pb);
+ bps = avio_r8(pb);
+ channels = avio_r8(pb);
+ samplerate = avio_rl16(pb);
asize-=4;
av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
if (fill_header) {
if(index < 0)
return -1;
- url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET);
+ avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET);
nst->frame_offset = st->index_entries[index].timestamp;
nsv->state = NSV_UNSYNC;
return 0;
static int nsv_probe(AVProbeData *p)
{
int i;
+ int score;
+ int vsize, asize, auxcount;
+ score = 0;
av_dlog(NULL, "nsv_probe(), buf_size %d\n", p->buf_size);
/* check file header */
/* streamed files might not have any header */
/* sometimes even the first header is at 9KB or something :^) */
for (i = 1; i < p->buf_size - 3; i++) {
if (p->buf[i+0] == 'N' && p->buf[i+1] == 'S' &&
- p->buf[i+2] == 'V' && p->buf[i+3] == 's')
- return AVPROBE_SCORE_MAX-20;
+ p->buf[i+2] == 'V' && p->buf[i+3] == 's') {
+ score = AVPROBE_SCORE_MAX/5;
+ /* Get the chunk size and check if at the end we are getting 0xBEEF */
+ auxcount = p->buf[i+19];
+ vsize = p->buf[i+20] | p->buf[i+21] << 8;
+ asize = p->buf[i+22] | p->buf[i+23] << 8;
+ vsize = (vsize << 4) | (auxcount >> 4);
+ if ((asize + vsize + i + 23) < p->buf_size - 2) {
+ if (p->buf[i+23+asize+vsize+1] == 0xEF &&
+ p->buf[i+23+asize+vsize+2] == 0xBE)
+ return AVPROBE_SCORE_MAX-20;
+ }
+ }
}
/* so we'll have more luck on extension... */
if (av_match_ext(p->filename, "nsv"))
return AVPROBE_SCORE_MAX/2;
/* FIXME: add mime-type check */
- return 0;
+ return score;
}
AVInputFormat ff_nsv_demuxer = {