aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2011-11-21 02:34:18 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2011-11-26 16:25:07 -0500
commita17c3c7d15a841ce330e142966b9420fb64cf299 (patch)
treebbdda72e7c7b23c92023677196231f7a11442df4 /libavformat
parent27360ccc5edcaa1a37dec39127e87c461ce668b6 (diff)
downloadffmpeg-a17c3c7d15a841ce330e142966b9420fb64cf299.tar.gz
avformat: add CRI ADX format demuxer
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile1
-rw-r--r--libavformat/adxdec.c110
-rw-r--r--libavformat/allformats.c1
-rw-r--r--libavformat/version.h2
4 files changed, 113 insertions, 1 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2b7588f1ad..3419148b56 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -21,6 +21,7 @@ OBJS-$(CONFIG_A64_MUXER) += a64.o
OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o rawdec.o
OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o
OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
+OBJS-$(CONFIG_ADX_DEMUXER) += adxdec.o
OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o
OBJS-$(CONFIG_AEA_DEMUXER) += aea.o pcm.o
OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o
diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c
new file mode 100644
index 0000000000..76b3728b1e
--- /dev/null
+++ b/libavformat/adxdec.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2011 Justin Ruggles
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * CRI ADX demuxer
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavcodec/adx.h"
+#include "avformat.h"
+
+#define BLOCK_SIZE 18
+#define BLOCK_SAMPLES 32
+
+typedef struct ADXDemuxerContext {
+ int header_size;
+} ADXDemuxerContext;
+
+static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ADXDemuxerContext *c = s->priv_data;
+ AVCodecContext *avctx = s->streams[0]->codec;
+ int ret, size;
+
+ size = BLOCK_SIZE * avctx->channels;
+
+ pkt->pos = avio_tell(s->pb);
+ pkt->stream_index = 0;
+
+ ret = av_get_packet(s->pb, pkt, size);
+ if (ret != size) {
+ av_free_packet(pkt);
+ return ret < 0 ? ret : AVERROR(EIO);
+ }
+ if (AV_RB16(pkt->data) & 0x8000) {
+ av_free_packet(pkt);
+ return AVERROR_EOF;
+ }
+ pkt->size = size;
+ pkt->duration = 1;
+ pkt->pts = (pkt->pos - c->header_size) / size;
+
+ return 0;
+}
+
+static int adx_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ ADXDemuxerContext *c = s->priv_data;
+ AVCodecContext *avctx;
+ int ret;
+
+ AVStream *st = avformat_new_stream(s, NULL);
+ if (!st)
+ return AVERROR(ENOMEM);
+ avctx = s->streams[0]->codec;
+
+ if (avio_rb16(s->pb) != 0x8000)
+ return AVERROR_INVALIDDATA;
+ c->header_size = avio_rb16(s->pb) + 4;
+ avio_seek(s->pb, -4, SEEK_CUR);
+
+ avctx->extradata = av_mallocz(c->header_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!avctx->extradata)
+ return AVERROR(ENOMEM);
+ if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) {
+ av_freep(&avctx->extradata);
+ return AVERROR(EIO);
+ }
+ avctx->extradata_size = c->header_size;
+
+ ret = ff_adx_decode_header(avctx, avctx->extradata, avctx->extradata_size,
+ &c->header_size, NULL);
+ if (ret)
+ return ret;
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = s->iformat->value;
+
+ av_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate);
+
+ return 0;
+}
+
+AVInputFormat ff_adx_demuxer = {
+ .name = "adx",
+ .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"),
+ .priv_data_size = sizeof(ADXDemuxerContext),
+ .read_header = adx_read_header,
+ .read_packet = adx_read_packet,
+ .extensions = "adx",
+ .value = CODEC_ID_ADPCM_ADX,
+};
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index bee2f5f11f..573b714d33 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -52,6 +52,7 @@ void av_register_all(void)
REGISTER_DEMUXER (AAC, aac);
REGISTER_MUXDEMUX (AC3, ac3);
REGISTER_MUXER (ADTS, adts);
+ REGISTER_DEMUXER (ADX, adx);
REGISTER_DEMUXER (AEA, aea);
REGISTER_MUXDEMUX (AIFF, aiff);
REGISTER_MUXDEMUX (AMR, amr);
diff --git a/libavformat/version.h b/libavformat/version.h
index d56bdb7c87..37c3d5bc88 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -24,7 +24,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 15
+#define LIBAVFORMAT_VERSION_MINOR 16
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \