[FFmpeg-devel] [PATCH] Wave64 demuxer
Daniel Verkamp
daniel
Fri Aug 7 19:10:31 CEST 2009
Hi,
Attached is a patch for a Sony Wave64 (w64) demuxer; first patch is
necessary so that the WAV seeking code can be used in w64 as well.
Thanks,
-- Daniel Verkamp
-------------- next part --------------
>From 349e159f6e94e81b684268b662451243d18c4293 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Fri, 7 Aug 2009 12:29:43 -0400
Subject: [PATCH 1/2] Rename and export wav_read_seek as ff_wav_read_seek
---
libavformat/wav.c | 5 +++--
libavformat/wav.h | 29 +++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
create mode 100644 libavformat/wav.h
diff --git a/libavformat/wav.c b/libavformat/wav.c
index 051cd84..7f8fbba 100644
--- a/libavformat/wav.c
+++ b/libavformat/wav.c
@@ -21,6 +21,7 @@
#include "avformat.h"
#include "raw.h"
#include "riff.h"
+#include "wav.h"
typedef struct {
int64_t data;
@@ -234,7 +235,7 @@ static int wav_read_packet(AVFormatContext *s,
return ret;
}
-static int wav_read_seek(AVFormatContext *s,
+int ff_wav_read_seek(AVFormatContext *s,
int stream_index, int64_t timestamp, int flags)
{
AVStream *st;
@@ -262,7 +263,7 @@ AVInputFormat wav_demuxer = {
wav_read_header,
wav_read_packet,
NULL,
- wav_read_seek,
+ ff_wav_read_seek,
.flags= AVFMT_GENERIC_INDEX,
.codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0},
};
diff --git a/libavformat/wav.h b/libavformat/wav.h
new file mode 100644
index 0000000..212ed30
--- /dev/null
+++ b/libavformat/wav.h
@@ -0,0 +1,29 @@
+/*
+ * WAV muxer and demuxer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_WAV_H
+#define AVFORMAT_WAV_H
+
+#include "avformat.h"
+
+int ff_wav_read_seek(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags);
+
+#endif /* AVFORMAT_WAV_H */
--
1.6.4
-------------- next part --------------
>From 338d917a83717398f6d4645ac0ad5815eded9f63 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Fri, 7 Aug 2009 13:06:31 -0400
Subject: [PATCH 2/2] Sony Wave64 demuxer
---
Changelog | 1 +
doc/general.texi | 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/w64.c | 35 ++++++++++
libavformat/w64.h | 33 ++++++++++
libavformat/w64dec.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 228 insertions(+), 0 deletions(-)
create mode 100644 libavformat/w64.c
create mode 100644 libavformat/w64.h
create mode 100644 libavformat/w64dec.c
diff --git a/Changelog b/Changelog
index 03599fd..1725e75 100644
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,7 @@ version <next>:
- RTP depacketization of ASF and RTSP from WMS servers
- RTMP support in libavformat
- noX handling for OPT_BOOL X options
+- Wave64 demuxer
diff --git a/doc/general.texi b/doc/general.texi
index 6326df9..b83158e 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -210,6 +210,7 @@ library:
@item Sony OpenMG (OMA) @tab @tab X
@tab Audio format used in Sony Sonic Stage and Sony Vegas.
@item Sony PlayStation STR @tab @tab X
+ at item Sony Wave64 (W64) @tab @tab X
@item SoX native format @tab X @tab X
@item SUN AU format @tab X @tab X
@item THP @tab @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 7838efe..c563b45 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -216,6 +216,7 @@ OBJS-$(CONFIG_VMD_DEMUXER) += sierravmd.o
OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o
OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o
OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o
+OBJS-$(CONFIG_W64_DEMUXER) += w64dec.o w64.o wav.o riff.o raw.o
OBJS-$(CONFIG_WAV_DEMUXER) += wav.o riff.o raw.o
OBJS-$(CONFIG_WAV_MUXER) += wav.o riff.o
OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 569ef50..0990598 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -193,6 +193,7 @@ void av_register_all(void)
REGISTER_DEMUXER (VMD, vmd);
REGISTER_MUXDEMUX (VOC, voc);
REGISTER_DEMUXER (VQF, vqf);
+ REGISTER_DEMUXER (W64, w64);
REGISTER_MUXDEMUX (WAV, wav);
REGISTER_DEMUXER (WC3, wc3);
REGISTER_DEMUXER (WSAUD, wsaud);
diff --git a/libavformat/w64.c b/libavformat/w64.c
new file mode 100644
index 0000000..77c837a
--- /dev/null
+++ b/libavformat/w64.c
@@ -0,0 +1,35 @@
+/*
+ * Sony Wave64 constants
+ * Copyright (c) 2009 Daniel Verkamp
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "w64.h"
+
+const uint8_t ff_w64_guid_riff[16] = { 'r', 'i', 'f', 'f',
+ 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
+
+const uint8_t ff_w64_guid_wave[16] = { 'w', 'a', 'v', 'e',
+ 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
+
+const uint8_t ff_w64_guid_fmt [16] = { 'f', 'm', 't', ' ',
+ 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
+
+const uint8_t ff_w64_guid_data[16] = { 'd', 'a', 't', 'a',
+ 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
diff --git a/libavformat/w64.h b/libavformat/w64.h
new file mode 100644
index 0000000..592d090
--- /dev/null
+++ b/libavformat/w64.h
@@ -0,0 +1,33 @@
+/*
+ * Sony Wave64 constants
+ * Copyright (c) 2009 Daniel Verkamp
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LIBAVFORMAT_W64_H
+#define LIBAVFORMAT_W64_H
+
+#include "avformat.h"
+#include "w64.h"
+
+extern const uint8_t ff_w64_guid_riff[16];
+extern const uint8_t ff_w64_guid_wave[16];
+extern const uint8_t ff_w64_guid_fmt [16];
+extern const uint8_t ff_w64_guid_data[16];
+
+#endif /* LIBAVFORMAT_W64_H */
diff --git a/libavformat/w64dec.c b/libavformat/w64dec.c
new file mode 100644
index 0000000..ce55428
--- /dev/null
+++ b/libavformat/w64dec.c
@@ -0,0 +1,156 @@
+/*
+ * Sony Wave64 demuxer
+ * Copyright (c) 2009 Daniel Verkamp
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * Sony Wave64 demuxer
+ * @file libavformat/w64dec.c
+ * @author Daniel Verkamp
+ * @sa http://wiki.multimedia.cx/index.php?title=Sony_Wave64
+ */
+
+#include "avformat.h"
+#include "raw.h"
+#include "riff.h"
+#include "wav.h"
+#include "w64.h"
+
+typedef struct {
+ int64_t data_end;
+} W64Context;
+
+static int w64_probe(AVProbeData *p)
+{
+ if (p->buf_size <= 40)
+ return 0;
+ if (!memcmp(p->buf, ff_w64_guid_riff, 16) &&
+ !memcmp(p->buf + 24, ff_w64_guid_wave, 16)) {
+ return AVPROBE_SCORE_MAX;
+ } else
+ return 0;
+}
+
+/* return the size of the found chunk */
+static int64_t find_guid(ByteIOContext *pb, const uint8_t guid1[16])
+{
+ uint8_t guid[16];
+ int64_t size;
+
+ while (!url_feof(pb)) {
+ get_buffer(pb, guid, 16);
+ size = get_le64(pb);
+ if (!memcmp(guid, guid1, 16))
+ return size;
+ url_fskip(pb, (size + 7) & ~INT64_C(7));
+ }
+ return -1;
+}
+
+static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ int64_t size;
+ ByteIOContext *pb = s->pb;
+ W64Context *w64 = s->priv_data;
+ AVStream *st;
+ uint8_t guid[16];
+
+ get_buffer(pb, guid, 16);
+ if (memcmp(guid, ff_w64_guid_riff, 16))
+ return -1;
+
+ if (get_le64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */
+ return -1;
+
+ get_buffer(pb, guid, 16);
+ if (memcmp(guid, ff_w64_guid_wave, 16))
+ return -1;
+
+ size = find_guid(pb, ff_w64_guid_fmt);
+ if (size < 0) {
+ av_log(s, AV_LOG_ERROR, "could not find fmt guid\n");
+ return -1;
+ }
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ /* subtract chunk header size - normal wav file doesn't count it */
+ ff_get_wav_header(pb, st->codec, size - 24);
+ url_fskip(pb, ((size + 7) & ~INT64_C(7)) - size);
+
+ st->need_parsing = AVSTREAM_PARSE_FULL;
+
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ size = find_guid(pb, ff_w64_guid_data);
+ if (size < 0) {
+ av_log(s, AV_LOG_ERROR, "could not find data guid\n");
+ return -1;
+ }
+ w64->data_end = url_ftell(pb) + size - 24;
+
+ return 0;
+}
+
+#define MAX_SIZE 4096
+
+static int w64_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int size;
+ int64_t left;
+ W64Context *w64 = s->priv_data;
+ AVStream *st = s->streams[0];
+
+ if (url_feof(s->pb))
+ return AVERROR_EOF;
+
+ left = w64->data_end - url_ftell(s->pb);
+ if (left <= 0)
+ return AVERROR_EOF;
+
+ size = MAX_SIZE;
+ if (st->codec->block_align > 1) {
+ if (size < st->codec->block_align)
+ size = st->codec->block_align;
+ size = (size / st->codec->block_align) * st->codec->block_align;
+ }
+
+ size = av_get_packet(s->pb, pkt, FFMIN(size, left));
+ if (size <= 0)
+ return AVERROR(EIO);
+ pkt->stream_index = 0;
+ pkt->size = size;
+
+ return size;
+}
+
+AVInputFormat w64_demuxer = {
+ "w64",
+ NULL_IF_CONFIG_SMALL("Sony Wave64 format"),
+ sizeof(W64Context),
+ w64_probe,
+ w64_read_header,
+ w64_read_packet,
+ NULL,
+ ff_wav_read_seek,
+ .flags = AVFMT_GENERIC_INDEX,
+ .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
+};
--
1.6.4
More information about the ffmpeg-devel
mailing list