[FFmpeg-devel] [PATCH] Wideband Single-bit Data (WSD) demuxer

Peter Ross pross at xvid.org
Fri Apr 18 08:09:45 CEST 2014


Signed-off-by: Peter Ross <pross at xvid.org>
---
samples: www.acoust.rise.waseda.ac.jp/1bitcons/data.html

 Changelog                |   1 +
 doc/general.texi         |   1 +
 libavformat/Makefile     |   1 +
 libavformat/allformats.c |   1 +
 libavformat/wsddec.c     | 171 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 175 insertions(+)
 create mode 100644 libavformat/wsddec.c

diff --git a/Changelog b/Changelog
index 6b46df3..09f015b 100644
--- a/Changelog
+++ b/Changelog
@@ -18,6 +18,7 @@ version <next>:
 - alternative rendition support for HTTP Live Streaming
 - AVFoundation input device
 - Direct Stream Digital (DSD) decoder
+- Wideband Single-bit Data (WSD) demuxer
 
 
 version 2.2:
diff --git a/doc/general.texi b/doc/general.texi
index 8bf0379..2c9c1b5 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -470,6 +470,7 @@ library:
     @tab Multimedia format used in Westwood Studios games.
 @item Westwood Studios VQA      @tab   @tab X
     @tab Multimedia format used in Westwood Studios games.
+ at item Wideband Single-bit Data (WSD)  @tab  @tab X
 @item XMV                       @tab   @tab X
     @tab Microsoft video container used in Xbox games.
 @item xWMA                      @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 38b7f9a..ca6820e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -418,6 +418,7 @@ OBJS-$(CONFIG_WEBM_MUXER)                += matroskaenc.o matroska.o \
 OBJS-$(CONFIG_WEBVTT_DEMUXER)            += webvttdec.o subtitles.o
 OBJS-$(CONFIG_WEBVTT_MUXER)              += webvttenc.o
 OBJS-$(CONFIG_WSAUD_DEMUXER)             += westwood_aud.o
+OBJS-$(CONFIG_WSD_DEMUXER)               += wsddec.o
 OBJS-$(CONFIG_WSVQA_DEMUXER)             += westwood_vqa.o
 OBJS-$(CONFIG_WTV_DEMUXER)               += wtvdec.o wtv_common.o asfdec.o asf.o asfcrypt.o \
                                             avlanguage.o mpegts.o isom.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index f6d78ae..780019d 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -305,6 +305,7 @@ void av_register_all(void)
     REGISTER_MUXER   (WEBM,             webm);
     REGISTER_MUXDEMUX(WEBVTT,           webvtt);
     REGISTER_DEMUXER (WSAUD,            wsaud);
+    REGISTER_DEMUXER (WSD,              wsd);
     REGISTER_DEMUXER (WSVQA,            wsvqa);
     REGISTER_MUXDEMUX(WTV,              wtv);
     REGISTER_MUXDEMUX(WV,               wv);
diff --git a/libavformat/wsddec.c b/libavformat/wsddec.c
new file mode 100644
index 0000000..7b127d9
--- /dev/null
+++ b/libavformat/wsddec.c
@@ -0,0 +1,171 @@
+/*
+ * Wideband Single-bit Data (WSD) demuxer
+ * Copyright (c) 2014 Peter Ross
+ *
+ * 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 "libavutil/timecode.h"
+#include "avformat.h"
+#include "internal.h"
+#include "rawdec.h"
+
+static int wsd_probe(AVProbeData *p)
+{
+    if (p->buf_size < 45 || memcmp(p->buf, "1bit", 4) ||
+        !AV_RB32(p->buf + 36) || !p->buf[44] ||
+        (p->buf[0] >= 0x10 && (AV_RB32(p->buf + 20) < 0x80 || AV_RB32(p->buf + 24) < 0x80)))
+       return 0;
+    return AVPROBE_SCORE_MAX;
+}
+
+static int empty_string(const char *buf, unsigned size)
+{
+    while (size--) {
+       if (*buf++ != ' ')
+           return 0;
+    }
+    return 1;
+}
+
+static int wsd_to_av_channel_layoyt(AVFormatContext *s, int bit)
+{
+    switch (bit) {
+    case 2: return AV_CH_BACK_RIGHT;
+    case 3:
+        avpriv_request_sample(s, "Rr-middle");
+        break;
+    case 4: return AV_CH_BACK_CENTER;
+    case 5:
+        avpriv_request_sample(s, "Lr-middle");
+        break;
+    case 6: return AV_CH_BACK_LEFT;
+    case 24: return AV_CH_LOW_FREQUENCY;
+    case 26: return AV_CH_FRONT_RIGHT;
+    case 27: return AV_CH_FRONT_RIGHT_OF_CENTER;
+    case 28: return AV_CH_FRONT_CENTER;
+    case 29: return AV_CH_FRONT_LEFT_OF_CENTER;
+    case 30: return AV_CH_FRONT_LEFT;
+    default:
+        av_log(s, AV_LOG_WARNING, "reserved channel assignment\n");
+        break;
+    }
+    return 0;
+}
+
+static int get_metadata(AVFormatContext *s, const char *const tag, const unsigned size)
+{
+    uint8_t *buf;
+    if (!(size + 1))
+        return AVERROR(ENOMEM);
+
+    buf = av_malloc(size + 1);
+    if (!buf)
+        return AVERROR(ENOMEM);
+
+    if (avio_read(s->pb, buf, size) != size) {
+        av_free(buf);
+        return AVERROR(EIO);
+    }
+
+    if (empty_string(buf, size)) {
+        av_free(buf);
+        return 0;
+    }
+
+    buf[size] = 0;
+    av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL);
+    return 0;
+}
+
+static int wsd_read_header(AVFormatContext *s)
+{
+    AVIOContext *pb = s->pb;
+    AVStream *st;
+    int version;
+    uint32_t text_offset, data_offset, channel_assign;
+    char playback_time[AV_TIMECODE_STR_SIZE];
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+    avio_skip(pb, 8);
+    version = avio_r8(pb);
+    av_log(s, AV_LOG_DEBUG, "version: %i.%i\n", version >> 4, version & 0xF);
+    avio_skip(pb, 11);
+
+    if (version < 0x10) {
+        text_offset = 0x80;
+        data_offset = 0x800;
+        avio_skip(pb, 8);
+    } else {
+        text_offset = avio_rb32(pb);
+        data_offset = avio_rb32(pb);
+    }
+
+    avio_skip(pb, 4);
+    av_timecode_make_smpte_tc_string(playback_time, avio_rb32(pb), 0);
+    av_dict_set(&s->metadata, "playback_time", playback_time, 0);
+
+    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id    = s->iformat->raw_codec_id;
+    st->codec->sample_rate = avio_rb32(pb) / 8;
+    avio_skip(pb, 4);
+    st->codec->channels    = avio_r8(pb) & 0xF;
+    if (!st->codec->channels)
+        return AVERROR_INVALIDDATA;
+
+    avio_skip(pb, 3);
+    channel_assign         = avio_rb32(pb);
+    if (!(channel_assign & 1)) {
+        int i;
+        for (i = 1; i < 32; i++)
+            if (channel_assign & (1 << i))
+                st->codec->channel_layout |= wsd_to_av_channel_layoyt(s, i);
+    }
+
+    avio_skip(pb, 16);
+    if (avio_rb32(pb))
+       avpriv_request_sample(s, "emphasis");
+
+    if (avio_seek(pb, text_offset, SEEK_SET) >= 0) {
+        get_metadata(s, "title",       128);
+        get_metadata(s, "composer",    128);
+        get_metadata(s, "song_writer", 128);
+        get_metadata(s, "artist",      128);
+        get_metadata(s, "album",       128);
+        get_metadata(s, "genre",        32);
+        get_metadata(s, "date",         32);
+        get_metadata(s, "location",     32);
+        get_metadata(s, "comment",     512);
+        get_metadata(s, "user",        512);
+    }
+
+    return avio_seek(pb, data_offset, SEEK_SET);
+}
+
+AVInputFormat ff_wsd_demuxer = {
+    .name         = "wsd",
+    .long_name    = NULL_IF_CONFIG_SMALL("Wideband Single-bit Data (WSD)"),
+    .read_probe   = wsd_probe,
+    .read_header  = wsd_read_header,
+    .read_packet  = ff_raw_read_partial_packet,
+    .flags        = AVFMT_GENERIC_INDEX | AVFMT_NO_BYTE_SEEK,
+    .raw_codec_id = AV_CODEC_ID_DSD_MSBF,
+};
-- 
1.8.3.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140418/7e8e8b34/attachment.asc>


More information about the ffmpeg-devel mailing list