[FFmpeg-devel] [PATCH] IRCAM demuxer

Paul B Mahol onemda at gmail.com
Mon Dec 3 14:07:54 CET 2012


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 doc/general.texi         |   1 +
 libavformat/Makefile     |   1 +
 libavformat/allformats.c |   1 +
 libavformat/ircamdec.c   | 141 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+)
 create mode 100644 libavformat/ircamdec.c

diff --git a/doc/general.texi b/doc/general.texi
index 5698106..f6c3d4d 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -235,6 +235,7 @@ library:
     @tab A format generated by IndigoVision 8000 video server.
 @item IVF (On2)                 @tab X @tab X
     @tab A format used by libvpx
+ at item IRCAM                     @tab   @tab X
 @item LATM                      @tab X @tab X
 @item LMLM4                     @tab   @tab X
     @tab Used by Linux Media Labs MPEG-4 PCI boards
diff --git a/libavformat/Makefile b/libavformat/Makefile
index daa406f..1289097 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -143,6 +143,7 @@ OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER)        += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE2PIPE_MUXER)          += img2enc.o img2.o
 OBJS-$(CONFIG_INGENIENT_DEMUXER)         += ingenientdec.o rawdec.o
 OBJS-$(CONFIG_IPMOVIE_DEMUXER)           += ipmovie.o
+OBJS-$(CONFIG_IRCAM_DEMUXER)             += ircamdec.o pcm.o
 OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
 OBJS-$(CONFIG_IV8_DEMUXER)               += iv8.o
 OBJS-$(CONFIG_IVF_DEMUXER)               += ivfdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 2987b8a..a282899 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -128,6 +128,7 @@ void av_register_all(void)
     REGISTER_DEMUXER  (INGENIENT, ingenient);
     REGISTER_DEMUXER  (IPMOVIE, ipmovie);
     REGISTER_MUXER    (IPOD, ipod);
+    REGISTER_DEMUXER  (IRCAM, ircam);
     REGISTER_MUXER    (ISMV, ismv);
     REGISTER_DEMUXER  (ISS, iss);
     REGISTER_DEMUXER  (IV8, iv8);
diff --git a/libavformat/ircamdec.c b/libavformat/ircamdec.c
new file mode 100644
index 0000000..1e0488e
--- /dev/null
+++ b/libavformat/ircamdec.c
@@ -0,0 +1,141 @@
+/*
+ * IRCAM 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 "avformat.h"
+#include "internal.h"
+#include "pcm.h"
+
+static int ircam_probe(AVProbeData *p)
+{
+    if ((p->buf[0] == 0x64 && p->buf[1] == 0xA3 && p->buf[3] == 0x00 &&
+         p->buf[2] >=    1 && p->buf[2] <= 4) ||
+        (p->buf[3] == 0x64 && p->buf[2] == 0xA3 && p->buf[0] == 0x00 &&
+         p->buf[1] >=    1 && p->buf[1] <= 3))
+        return AVPROBE_SCORE_MAX;
+    return 0;
+}
+
+static const struct endianes {
+    uint32_t magic;
+    int      is_le;
+} table[] = {
+  { 0x64A30100, 0 },
+  { 0x64A30200, 1 },
+  { 0x64A30300, 0 },
+  { 0x64A30400, 1 },
+  { 0x0001A364, 1 },
+  { 0x0002A364, 0 },
+  { 0x0003A364, 1 },
+};
+
+static int ircam_read_header(AVFormatContext *s)
+{
+    uint32_t magic, sample_rate, channels, encoding;
+    int le = -1, i;
+    AVStream *st;
+
+    magic = avio_rl32(s->pb);
+    for (i = 0; i < 7; i++) {
+        if (magic == table[i].magic)
+            le = table[i].is_le;
+    }
+
+    if (!!le) {
+        sample_rate = av_int2float(avio_rl32(s->pb));
+        channels    = avio_rl32(s->pb);
+        encoding    = avio_rl32(s->pb);
+    } else if (!le) {
+        sample_rate = av_int2float(avio_rb32(s->pb));
+        channels    = avio_rb32(s->pb);
+        encoding    = avio_rb32(s->pb);
+    } else {
+        return AVERROR_INVALIDDATA;
+    }
+
+    if (!channels || !encoding || !sample_rate)
+        return AVERROR_INVALIDDATA;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
+    st->codec->channels    = channels;
+    st->codec->sample_rate = sample_rate;
+
+    switch (encoding) {
+    case 0x00001:
+        st->codec->codec_id = AV_CODEC_ID_PCM_S8;
+        break;
+    case 0x00002:
+        st->codec->codec_id = le ? AV_CODEC_ID_PCM_S16LE : AV_CODEC_ID_PCM_S16BE;
+        break;
+    case 0x00003:
+        st->codec->codec_id = le ? AV_CODEC_ID_PCM_S24LE : AV_CODEC_ID_PCM_S24BE;
+        break;
+    case 0x40004:
+        st->codec->codec_id = le ? AV_CODEC_ID_PCM_S32LE : AV_CODEC_ID_PCM_S32BE;
+        break;
+    case 0x00004:
+        st->codec->codec_id = le ? AV_CODEC_ID_PCM_F32LE : AV_CODEC_ID_PCM_F32BE;
+        break;
+    case 0x00008:
+        st->codec->codec_id = le ? AV_CODEC_ID_PCM_F64LE : AV_CODEC_ID_PCM_F64BE;
+        break;
+    case 0x10001:
+        st->codec->codec_id = AV_CODEC_ID_PCM_ALAW;
+        break;
+    case 0x20001:
+        st->codec->codec_id = AV_CODEC_ID_PCM_MULAW;
+        break;
+    default:
+        return AVERROR_INVALIDDATA;
+    }
+
+    st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
+    st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8;
+    avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+    avio_skip(s->pb, 1008);
+
+    return 0;
+}
+
+static int ircam_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    int ret;
+
+    ret = av_get_packet(s->pb, pkt, 1024 * s->streams[0]->codec->block_align);
+    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+    pkt->stream_index = 0;
+
+    return ret;
+}
+
+AVInputFormat ff_ircam_demuxer = {
+    .name           = "ircam",
+    .long_name      = NULL_IF_CONFIG_SMALL("Berkeley/IRCAM/CARL Sound Format"),
+    .read_probe     = ircam_probe,
+    .read_header    = ircam_read_header,
+    .read_packet    = ircam_read_packet,
+    .read_seek      = ff_pcm_read_seek,
+    .extensions     = "sf,ircam",
+    .flags          = AVFMT_GENERIC_INDEX,
+};
-- 
1.7.11.4



More information about the ffmpeg-devel mailing list