[PATCH] Wideband Single-bit Data (WSD) demuxer
Signed-off-by: Peter Ross <pross@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. +@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)
Peter Ross <pross <at> xvid.org> writes:
+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 ||
Isn't p->buf[0] already checked above?
AV_RB32(p->buf + 24) < 0x80))) + return 0; + return AVPROBE_SCORE_MAX;
AVPROBE_SCORE_MAX seems too much to me.
+static int wsd_to_av_channel_layoyt
Seems to be a typo: layout
+ 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;
I would have expected AV_CH_SIDE_* in the list. Aren't Rr-middle and Lr-middle side channels?
+ av_timecode_make_smpte_tc_string(playback_time, avio_rb32(pb), 0); + av_dict_set(&s->metadata, "playback_time", playback_time, 0);
AVStream->duration or do I misunderstand? Carl Eugen
On Fri, Apr 18, 2014 at 09:01:31AM +0000, Carl Eugen Hoyos wrote:
Peter Ross <pross <at> xvid.org> writes:
Thanks for spotting these errors.
+ 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;
I would have expected AV_CH_SIDE_* in the list. Aren't Rr-middle and Lr-middle side channels?
I am unsure and don't have such WSD samples to test that hypothesis. (only capable of listening to the stereo and quad stuff anyway.) The 32-bit channel assignment value is describes the listening room as a box. When the 'flag' bit is clear, the layout is as below. Side channels may occur in the bits marked with a dot, but the specification doesn't go into any more detail. "Front" bit31 ..................................................... bit24 [------------------------------------------------------------------] [ | Lf | Lf-middle | Cf | Rf-middle | Rf | | LFE ] [------------------------------------------------------------------] [ . | | | | | | . | ] [------------------------------------------------------------------] [ . | | | | | | . | ] [------------------------------------------------------------------] [ | Lr | Lr-middle | Cr | Rr-middle | Rr | | flag ] [------------------------------------------------------------------] bit7 ...................................................... bit0 "Back" When the 'flag' bit is set, a circular room configuration can be used. Here is a dump from an 8ch file. "Front" -------------------------------------- | | | X | | X | | | | | X | | | | | | X | | | X | | | | | | X | | | | | X | | X | | | X | -------------------------------------- "Back"
+ av_timecode_make_smpte_tc_string(playback_time, avio_rb32(pb), 0); + av_dict_set(&s->metadata, "playback_time", playback_time, 0);
AVStream->duration or do I misunderstand?
True. The duration is encoded as a smpte timecode, giving 1-second precision accuracy, so I am thinking about skipping over this. -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Peter Ross <pross <at> xvid.org> writes:
I would have expected AV_CH_SIDE_* in the list. Aren't Rr-middle and Lr-middle side channels?
I am unsure and don't have such WSD samples to test that hypothesis.
Then please ignore my comment, I was just wondering / guessing... Thank you, Carl Eugen
On Fri, Apr 18, 2014 at 04:09:45PM +1000, Peter Ross wrote:
Signed-off-by: Peter Ross <pross@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. +@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;
maybe the exact value should be used as timebase with avpriv_set_pts_info [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB DNS cache poisoning attacks, popular search engine, Google internet authority dont be evil, please
On 4/18/14, Peter Ross <pross@xvid.org> wrote:
Signed-off-by: Peter Ross <pross@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
What happened to this?
On 4/27/16, Paul B Mahol <onemda@gmail.com> wrote:
On 4/18/14, Peter Ross <pross@xvid.org> wrote:
Signed-off-by: Peter Ross <pross@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
What happened to this?
I will apply this soon.
participants (4)
-
Carl Eugen Hoyos -
Michael Niedermayer -
Paul B Mahol -
Peter Ross