Signed-off-by: Paul B Mahol
---
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/genh.c | 176 +++
3 files changed, 178 insertions(+)
create mode 100644 libavformat/genh.c
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2971912..a66bd17 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -177,6 +177,7 @@ OBJS-$(CONFIG_G722_MUXER)+= rawenc.o
OBJS-$(CONFIG_G723_1_DEMUXER)+= g723_1.o
OBJS-$(CONFIG_G723_1_MUXER) += rawenc.o
OBJS-$(CONFIG_G729_DEMUXER) += g729dec.o
+OBJS-$(CONFIG_GENH_DEMUXER) += genh.o
OBJS-$(CONFIG_H261_DEMUXER) += h261dec.o rawdec.o
OBJS-$(CONFIG_H261_MUXER)+= rawenc.o
OBJS-$(CONFIG_H263_DEMUXER) += h263dec.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 0ccde9d..dbd7719 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -138,6 +138,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX(G722, g722);
REGISTER_MUXDEMUX(G723_1, g723_1);
REGISTER_DEMUXER (G729, g729);
+REGISTER_DEMUXER (GENH, genh);
REGISTER_MUXDEMUX(GIF, gif);
REGISTER_DEMUXER (GSM, gsm);
REGISTER_MUXDEMUX(GXF, gxf);
diff --git a/libavformat/genh.c b/libavformat/genh.c
new file mode 100644
index 000..ce054b5
--- /dev/null
+++ b/libavformat/genh.c
@@ -0,0 +1,176 @@
+/*
+ * GENH demuxer
+ * Copyright (c) 2015 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"
+
+typedef struct GENHDemuxContext {
+unsigned dsp_int_type;
+unsigned interleave_size;
+} GENHDemuxContext;
+
+static int genh_probe(AVProbeData *p)
+{
+if (AV_RL32(p->buf) != MKTAG('G','E','N','H'))
+return 0;
+
+return AVPROBE_SCORE_MAX / 3 * 2;
+}
+
+static int genh_read_header(AVFormatContext *s)
+{
+unsigned start_offset, header_size, codec, coef_type, coef[2];
+GENHDemuxContext *c = s->priv_data;
+unsigned coef_splitted[2];
+int align, ch;
+AVStream *st;
+
+avio_skip(s->pb, 4);
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+
+st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+st->codec->channels= avio_rl32(s->pb);
+if (st->codec->channels <= 0)
+return AVERROR_INVALIDDATA;
+if (st->codec->channels == 1)
+st->codec->channel_layout = AV_CH_LAYOUT_MONO;
+else if (st->codec->channels == 2)
+st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
+align =
+c->interleave_size = avio_rl32(s->pb);
+if (align < 0 || align > INT_MAX / st->codec->channels)
+return AVERROR_INVALIDDATA;
+st->codec->block_align = align * st->codec->channels;
+st->codec->sample_rate = avio_rl32(s->pb);
+avio_skip(s->pb, 4);
+st->duration = avio_rl32(s->pb);
+
+codec = avio_rl32(s->pb);
+switch (codec) {
+case 1:
+case 11: st->codec->bits_per_coded_sample = 4;
+ st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WAV;break;
+case 3: st->codec->codec_id = st->codec->block_align > 0 ?
+ AV_CODEC_ID_PCM_S16BE_PLANAR :
+ AV_CODEC_ID_PCM_S16BE;break;
+case 4: st->codec->codec_id = st->codec->block_align > 0 ?
+ AV_CODEC_ID_PCM_S16LE_PLANAR :
+ AV_CODEC_ID_PCM_S16LE;break;
+case 5: st->codec->codec_id = st->codec->block_align > 0 ?
+ AV_CODEC_ID_PCM_S8_PLANAR :
+ AV_CODEC_ID_PCM_S8; break;
+case 12: st->codec->codec_id = AV_CODEC_ID_ADPCM_THP;break;
+case 13: st->codec->codec_id = AV_CODEC_ID_PCM_U8; break;
+default:
+ avpriv_request_sample(s, "codec %d", codec);
+ return AVERROR_PATCHWELCOME;
+}
+
+start_offset = avio_rl32(s->pb);
+header_size = avio_rl32(s->pb);
+
+if (header_size > sta