--- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/falcom_xa.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 libavformat/falcom_xa.c
diff --git a/libavformat/Makefile b/libavformat/Makefile index 6bdfbe6789..06b6b5da57 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -158,6 +158,7 @@ OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o OBJS-$(CONFIG_EAC3_DEMUXER) += ac3dec.o rawdec.o OBJS-$(CONFIG_EAC3_MUXER) += rawenc.o OBJS-$(CONFIG_EPAF_DEMUXER) += epafdec.o pcm.o +OBJS-$(CONFIG_FALCOM_XA_DEMUXER) += falcom_xa.o OBJS-$(CONFIG_FFM_DEMUXER) += ffmdec.o OBJS-$(CONFIG_FFM_MUXER) += ffmenc.o OBJS-$(CONFIG_FFMETADATA_DEMUXER) += ffmetadec.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 09e62c3cfc..0c23ea9df0 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -117,6 +117,7 @@ static void register_all(void) REGISTER_MUXDEMUX(EAC3, eac3); REGISTER_DEMUXER (EPAF, epaf); REGISTER_MUXER (F4V, f4v); + REGISTER_DEMUXER (FALCOM_XA, falcom_xa); REGISTER_MUXDEMUX(FFM, ffm); REGISTER_MUXDEMUX(FFMETADATA, ffmetadata); REGISTER_MUXER (FIFO, fifo); diff --git a/libavformat/falcom_xa.c b/libavformat/falcom_xa.c new file mode 100644 index 0000000000..4c5f32a1b6 --- /dev/null +++ b/libavformat/falcom_xa.c @@ -0,0 +1,98 @@ +/* + * Falcom Xanadu demuxer + * Copyright (c) 2016 James Darnley + * + * 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" + +typedef struct FalcomXADemuxContext { + const AVClass *class; + unsigned frame_size; +} FalcomXADemuxContext; + +static av_cold +int falcom_xa_read_header(AVFormatContext *s) +{ + int sample_rate, bit_depth, channels; + AVStream *st; + AVIOContext *pb = s->pb; + + avio_seek(pb, 22, SEEK_SET); + channels = avio_rl16(pb); + if (channels != 2) + return AVERROR_INVALIDDATA; + + sample_rate = avio_rl32(pb); + if (sample_rate != 44100) + return AVERROR_INVALIDDATA; + + avio_seek(pb, 34, SEEK_SET); + bit_depth = avio_rl16(pb); + if (bit_depth != 16) + return AVERROR_INVALIDDATA; + + avio_seek(pb, 44, SEEK_SET); + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_MS; + st->codecpar->sample_rate = sample_rate; + st->codecpar->channels = channels; + st->codecpar->block_align = 2048; + + return 0; +} + +static +int falcom_xa_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + FalcomXADemuxContext *ctx = s->priv_data; + + if (ctx->frame_size == 0) { + unsigned tell = avio_tell(s->pb); + unsigned size = avio_rl32(s->pb); + av_log(ctx, AV_LOG_DEBUG, "read size %u (0x%x) at offset %u (0x%x)\n", + size, size, tell, tell); + if (size % 2048) + return AVERROR_INVALIDDATA; + ctx->frame_size = size; + avio_skip(s->pb, 4); // unknown bytes + } + + ctx->frame_size -= 2048; + return av_get_packet(s->pb, pkt, 2048); +} + +static const AVClass falcom_xa_demux_class = { + .class_name = "Falcom Xanadu demuxer", + .item_name = av_default_item_name, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_falcom_xa_demuxer = { + .name = "falcom_xa", + .long_name = NULL_IF_CONFIG_SMALL("Falcom Xanadu demuxer"), + .priv_data_size = sizeof(FalcomXADemuxContext), + .read_header = falcom_xa_read_header, + .read_packet = falcom_xa_read_packet, + .priv_class = &falcom_xa_demux_class, +}; -- 2.12.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel