Signed-off-by: Paul B Mahol <one...@gmail.com> --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/genh.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 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 0000000..b9b9c46 --- /dev/null +++ b/libavformat/genh.c @@ -0,0 +1,113 @@ +/* + * 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" + +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; + int align; + 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 == 2) + st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + align = 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 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 > start_offset) + return AVERROR_INVALIDDATA; + + if (header_size == 0) + start_offset = 0x800; + + avio_skip(s->pb, start_offset - avio_tell(s->pb)); + + avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + return 0; +} + +static int genh_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVCodecContext *codec = s->streams[0]->codec; + int ret; + + ret = av_get_packet(s->pb, pkt, codec->block_align ? codec->block_align : 1024 * codec->channels); + pkt->stream_index = 0; + return ret; +} + +AVInputFormat ff_genh_demuxer = { + .name = "genh", + .long_name = NULL_IF_CONFIG_SMALL("GENeric Header"), + .read_probe = genh_probe, + .read_header = genh_read_header, + .read_packet = genh_read_packet, + .extensions = "genh", +}; -- 1.9.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel