[FFmpeg-devel] [PATCH] NIST SPHERE demuxer
Paul B Mahol
onemda at gmail.com
Wed Dec 19 02:38:38 CET 2012
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
doc/general.texi | 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/nistspheredec.c | 96 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 99 insertions(+)
create mode 100644 libavformat/nistspheredec.c
diff --git a/doc/general.texi b/doc/general.texi
index 921bdcd..8115f30 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -280,6 +280,7 @@ library:
@tab SMPTE 386M, D-10/IMX Mapping.
@item NC camera feed @tab @tab X
@tab NC (AVIP NC4600) camera streams
+ at item NIST SPeech HEader REsources @tab @tab X
@item NTT TwinVQ (VQF) @tab @tab X
@tab Nippon Telegraph and Telephone Corporation TwinVQ.
@item Nullsoft Streaming Video @tab @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 54e8864..dd48066 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -227,6 +227,7 @@ OBJS-$(CONFIG_MXF_DEMUXER) += mxfdec.o mxf.o
OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o audiointerleave.o
OBJS-$(CONFIG_MXG_DEMUXER) += mxg.o
OBJS-$(CONFIG_NC_DEMUXER) += ncdec.o
+OBJS-$(CONFIG_NISTSPHERE_DEMUXER) += nistspheredec.o
OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o
OBJS-$(CONFIG_NULL_MUXER) += nullenc.o
OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6456e8c..6b4c27b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -178,6 +178,7 @@ void av_register_all(void)
REGISTER_MUXER (MXF_D10, mxf_d10);
REGISTER_DEMUXER (MXG, mxg);
REGISTER_DEMUXER (NC, nc);
+ REGISTER_DEMUXER (NISTSPHERE, nistsphere);
REGISTER_DEMUXER (NSV, nsv);
REGISTER_MUXER (NULL, null);
REGISTER_MUXDEMUX (NUT, nut);
diff --git a/libavformat/nistspheredec.c b/libavformat/nistspheredec.c
new file mode 100644
index 0000000..cff240c
--- /dev/null
+++ b/libavformat/nistspheredec.c
@@ -0,0 +1,96 @@
+/*
+ * NIST Sphere demuxer
+ * Copyright (c) 2012 Paul B Mahol
+ *
+ * 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 "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "internal.h"
+#include "pcm.h"
+
+static int nist_probe(AVProbeData *p)
+{
+ if (AV_RL64(p->buf) == AV_RL64("NIST_1A\x0a"))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int nist_read_header(AVFormatContext *s)
+{
+ char buffer[32], coding[32] = "pcm", format[4] = "01";
+ int bps = 0, be = 0;
+ AVStream *st;
+
+ st = avformat_new_stream(s, NULL);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+
+ while (!url_feof(s->pb)) {
+ ff_get_line(s->pb, (char *)&buffer, sizeof(buffer));
+ if (!memcmp(buffer, "end_head", 8)) {
+ if (!strcasecmp(coding, "pcm"))
+ st->codec->codec_id = ff_get_pcm_codec_id(bps, 0, be, 0xFFFF);
+
+ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ st->codec->block_align = bps * st->codec->channels / 8;
+
+ avio_skip(s->pb, 1024 - avio_tell(s->pb));
+ return 0;
+ } else if (!memcmp(buffer, "channel_count", 13)) {
+ sscanf(buffer, "%*s %*s %u", &st->codec->channels);
+ } else if (!memcmp(buffer, "sample_byte_format", 18)) {
+ sscanf(buffer, "%*s %*s %3s", format);
+
+ if (!strcasecmp(format, "01")) {
+ be = 0;
+ } else if (!strcasecmp(format, "10")) {
+ be = 1;
+ } else if (strcasecmp(format, "1")) {
+ av_log_ask_for_sample(s, "unsupported sample byte format\n");
+ return AVERROR_INVALIDDATA;
+ }
+ } else if (!memcmp(buffer, "sample_n_bytes", 14)) {
+ sscanf(buffer, "%*s %*s %u", &bps);
+ bps <<= 3;
+ st->codec->bits_per_coded_sample = bps;
+ } else if (!memcmp(buffer, "sample_coding", 13)) {
+ sscanf(buffer, "%*s %*s %31s", coding);
+ } else if (!memcmp(buffer, "sample_count", 12)) {
+ sscanf(buffer, "%*s %*s %llu", &st->duration);
+ } else if (!memcmp(buffer, "sample_rate", 11)) {
+ sscanf(buffer, "%*s %*s %u", &st->codec->sample_rate);
+ }
+ }
+
+ return AVERROR_EOF;
+}
+
+AVInputFormat ff_nistsphere_demuxer = {
+ .name = "nistsphere",
+ .long_name = NULL_IF_CONFIG_SMALL("NIST SPeech HEader REsources"),
+ .read_probe = nist_probe,
+ .read_header = nist_read_header,
+ .read_packet = ff_pcm_read_packet,
+ .read_seek = ff_pcm_read_seek,
+ .extensions = "nist,sph",
+ .flags = AVFMT_GENERIC_INDEX,
+};
--
1.7.11.4
More information about the ffmpeg-devel
mailing list