/*
* 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 "libavutil/mathematics.h"
#include "avformat.h"
#include "riff.h"
+#include "libavutil/dict.h"
-//#define DEBUG
//#define DEBUG_DUMP_INDEX // XXX dumbdriving-271.nsv breaks with it commented!!
-//#define DEBUG_SEEK
#define CHECK_SUBSEQUENT_NSVS
//#define DISABLE_AUDIO
{
NSVContext *nsv = s->priv_data;
AVIOContext *pb = s->pb;
- unsigned int file_size, size;
+ unsigned int av_unused file_size;
+ unsigned int size;
int64_t duration;
int strings_size;
int table_entries;
break;
*p++ = '\0';
av_dlog(s, "NSV NSVf INFO: %s='%s'\n", token, value);
- av_metadata_set2(&s->metadata, token, value, 0);
+ av_dict_set(&s->metadata, token, value, 0);
}
av_free(strings);
}
nsv->vheight = vwidth;
if (vtag != T_NONE) {
int i;
- st = av_new_stream(s, NSV_ST_VIDEO);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
+ st->id = NSV_ST_VIDEO;
nst = av_mallocz(sizeof(NSVStream));
if (!nst)
goto fail;
}
if (atag != T_NONE) {
#ifndef DISABLE_AUDIO
- st = av_new_stream(s, NSV_ST_AUDIO);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
+ st->id = NSV_ST_AUDIO;
nst = av_mallocz(sizeof(NSVStream));
if (!nst)
goto fail;
err = nsv_read_chunk(s, 1);
av_dlog(s, "parsed header\n");
- return 0;
+ return err;
}
static int nsv_read_chunk(AVFormatContext *s, int fill_header)
uint32_t vsize;
uint16_t asize;
uint16_t auxsize;
- uint32_t auxtag;
+ uint32_t av_unused auxtag;
av_dlog(s, "%s(%d)\n", __FUNCTION__, fill_header);
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 = {
- "nsv",
- NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"),
- sizeof(NSVContext),
- nsv_probe,
- nsv_read_header,
- nsv_read_packet,
- nsv_read_close,
- nsv_read_seek,
+ .name = "nsv",
+ .long_name = NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"),
+ .priv_data_size = sizeof(NSVContext),
+ .read_probe = nsv_probe,
+ .read_header = nsv_read_header,
+ .read_packet = nsv_read_packet,
+ .read_close = nsv_read_close,
+ .read_seek = nsv_read_seek,
};