IRCAM demuxer & muxer
authorPaul B Mahol <onemda@gmail.com>
Sun, 2 Dec 2012 18:13:56 +0000 (18:13 +0000)
committerPaul B Mahol <onemda@gmail.com>
Wed, 5 Dec 2012 13:01:22 +0000 (13:01 +0000)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
12 files changed:
Changelog
doc/general.texi
libavformat/Makefile
libavformat/allformats.c
libavformat/ircam.c [new file with mode: 0644]
libavformat/ircam.h [new file with mode: 0644]
libavformat/ircamdec.c [new file with mode: 0644]
libavformat/ircamenc.c [new file with mode: 0644]
libavformat/version.h
tests/fate/avformat.mak
tests/lavf-regression.sh
tests/ref/lavf/ircam [new file with mode: 0644]

index ff318e1..4fcffa4 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,7 @@ version <next>:
 - animated GIF decoder and demuxer
 - PVF demuxer
 - subtitles filter
+- IRCAM muxer/demuxer
 
 
 version 1.0:
index c28dc8d..5d7f817 100644 (file)
@@ -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
+@item IRCAM                     @tab X @tab X
 @item LATM                      @tab X @tab X
 @item LMLM4                     @tab   @tab X
     @tab Used by Linux Media Labs MPEG-4 PCI boards
index 1099099..26ddc4e 100644 (file)
@@ -163,6 +163,8 @@ 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 ircam.o pcm.o
+OBJS-$(CONFIG_IRCAM_MUXER)               += ircamenc.o ircam.o rawenc.o
 OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
 OBJS-$(CONFIG_IV8_DEMUXER)               += iv8.o
 OBJS-$(CONFIG_IVF_DEMUXER)               += ivfdec.o
index d57947f..3c59017 100644 (file)
@@ -128,6 +128,7 @@ void av_register_all(void)
     REGISTER_DEMUXER  (INGENIENT, ingenient);
     REGISTER_DEMUXER  (IPMOVIE, ipmovie);
     REGISTER_MUXER    (IPOD, ipod);
+    REGISTER_MUXDEMUX (IRCAM, ircam);
     REGISTER_MUXER    (ISMV, ismv);
     REGISTER_DEMUXER  (ISS, iss);
     REGISTER_DEMUXER  (IV8, iv8);
diff --git a/libavformat/ircam.c b/libavformat/ircam.c
new file mode 100644 (file)
index 0000000..561cbb1
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * IRCAM common code
+ * 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"
+
+const AVCodecTag ff_codec_ircam_le_tags[] = {
+    { CODEC_ID_PCM_ALAW,  0x10001 },
+    { CODEC_ID_PCM_F32LE, 0x00004 },
+    { CODEC_ID_PCM_F64LE, 0x00008 },
+    { CODEC_ID_PCM_MULAW, 0x20001 },
+    { CODEC_ID_PCM_S16LE, 0x00002 },
+    { CODEC_ID_PCM_S24LE, 0x00003 },
+    { CODEC_ID_PCM_S32LE, 0x40004 },
+    { CODEC_ID_PCM_S8,    0x00001 },
+    { CODEC_ID_NONE,      0       },
+};
+
+const AVCodecTag ff_codec_ircam_be_tags[] = {
+    { CODEC_ID_PCM_ALAW,  0x10001 },
+    { CODEC_ID_PCM_F32BE, 0x00004 },
+    { CODEC_ID_PCM_F64BE, 0x00008 },
+    { CODEC_ID_PCM_MULAW, 0x20001 },
+    { CODEC_ID_PCM_S16BE, 0x00002 },
+    { CODEC_ID_PCM_S24BE, 0x00003 },
+    { CODEC_ID_PCM_S32BE, 0x40004 },
+    { CODEC_ID_PCM_S8,    0x00001 },
+    { CODEC_ID_NONE,      0       },
+};
diff --git a/libavformat/ircam.h b/libavformat/ircam.h
new file mode 100644 (file)
index 0000000..f7f9c84
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * IRCAM common code
+ * 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
+ */
+
+#ifndef AVFORMAT_IRCAM_H
+#define AVFORMAT_IRCAM_H
+
+#include "internal.h"
+
+extern const AVCodecTag ff_codec_ircam_be_tags[];
+extern const AVCodecTag ff_codec_ircam_le_tags[];
+
+#endif /* AVFORMAT_IRCAM_H */
diff --git a/libavformat/ircamdec.c b/libavformat/ircamdec.c
new file mode 100644 (file)
index 0000000..f9533ec
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * 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 "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "internal.h"
+#include "pcm.h"
+#include "ircam.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) &&
+        AV_RN32(p->buf + 4) && AV_RN32(p->buf + 8))
+        return AVPROBE_SCORE_MAX / 4 * 3;
+    return 0;
+}
+
+static const struct endianess {
+    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, tag;
+    const AVCodecTag *tags;
+    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;
+            break;
+        }
+    }
+
+    if (le == 1) {
+        sample_rate = av_int2float(avio_rl32(s->pb));
+        channels    = avio_rl32(s->pb);
+        tag         = avio_rl32(s->pb);
+        tags        = ff_codec_ircam_le_tags;
+    } else if (le == 0) {
+        sample_rate = av_int2float(avio_rb32(s->pb));
+        channels    = avio_rb32(s->pb);
+        tag         = avio_rb32(s->pb);
+        tags        = ff_codec_ircam_be_tags;
+    } else {
+        return AVERROR_INVALIDDATA;
+    }
+
+    if (!channels || !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;
+
+    st->codec->codec_id = ff_codec_get_id(tags, tag);
+    if (st->codec->codec_id == AV_CODEC_ID_NONE) {
+        av_log(s, AV_LOG_ERROR, "unknown tag %X\n", tag);
+        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;
+}
+
+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    = ff_pcm_read_packet,
+    .read_seek      = ff_pcm_read_seek,
+    .extensions     = "sf,ircam",
+    .flags          = AVFMT_GENERIC_INDEX,
+};
diff --git a/libavformat/ircamenc.c b/libavformat/ircamenc.c
new file mode 100644 (file)
index 0000000..d33a062
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * IRCAM muxer
+ * 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 "rawenc.h"
+#include "ircam.h"
+
+static int ircam_write_header(AVFormatContext *s)
+{
+    AVCodecContext *codec = s->streams[0]->codec;
+    uint32_t tag;
+
+    if (s->nb_streams != 1) {
+        av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+        return AVERROR(EINVAL);
+    }
+
+    tag = ff_codec_get_tag(ff_codec_ircam_le_tags, codec->codec_id);
+    if (!tag) {
+        av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+        return AVERROR(EINVAL);
+    }
+
+    avio_wl32(s->pb, 0x0001A364);
+    avio_wl32(s->pb, av_float2int(codec->sample_rate));
+    avio_wl32(s->pb, codec->channels);
+    avio_wl32(s->pb, tag);
+    avio_skip(s->pb, 1008);
+    return 0;
+}
+
+AVOutputFormat ff_ircam_muxer = {
+    .name           = "ircam",
+    .extensions     = "sf,ircam",
+    .long_name      = NULL_IF_CONFIG_SMALL("Berkeley/IRCAM/CARL Sound Format"),
+    .audio_codec    = AV_CODEC_ID_PCM_S16LE,
+    .video_codec    = AV_CODEC_ID_NONE,
+    .write_header   = ircam_write_header,
+    .write_packet   = ff_raw_write_packet,
+    .codec_tag      = (const AVCodecTag *const []){ ff_codec_ircam_le_tags, 0 },
+};
index 73c1f31..f5ed810 100644 (file)
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 44
+#define LIBAVFORMAT_VERSION_MINOR 45
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
index 4c99707..3528e55 100644 (file)
@@ -13,6 +13,7 @@ FATE_LAVF-$(call ENCDEC,  RAWVIDEO,              FILMSTRIP)          += flm
 FATE_LAVF-$(call ENCDEC,  FLV,                   FLV)                += flv_fmt
 FATE_LAVF-$(call ENCDEC,  GIF,                   IMAGE2)             += gif
 FATE_LAVF-$(call ENCDEC2, MPEG2VIDEO, PCM_S16LE, GXF)                += gxf
+FATE_LAVF-$(call ENCDEC,  PCM_S16LE,             IRCAM)              += ircam
 FATE_LAVF-$(call ENCDEC,  MJPEG,                 IMAGE2)             += jpg
 FATE_LAVF-$(call ENCDEC2, MPEG4,      MP2,       MATROSKA)           += mkv
 FATE_LAVF-$(call ENCDEC,  ADPCM_YAMAHA,          MMF)                += mmf
index 473c235..4afc29a 100755 (executable)
@@ -330,6 +330,10 @@ if [ -n "$do_ast" ] ; then
 do_audio_only ast "-ac 2" "-loopstart 1 -loopend 10"
 fi
 
+if [ -n "$do_ircam" ] ; then
+do_audio_only ircam
+fi
+
 # pix_fmt conversions
 
 if [ -n "$do_pixfmt" ] ; then
diff --git a/tests/ref/lavf/ircam b/tests/ref/lavf/ircam
new file mode 100644 (file)
index 0000000..17c0b69
--- /dev/null
@@ -0,0 +1,3 @@
+26f9c402de811b0434b09aa1a2e5eee3 *./tests/data/lavf/lavf.ircam
+91136 ./tests/data/lavf/lavf.ircam
+./tests/data/lavf/lavf.ircam CRC=0xf1ae5536