[FFmpeg-devel] [PATCH 2/2] ADP demuxer

James Almer jamrial at gmail.com
Sat Apr 20 05:03:21 CEST 2013


Signed-off-by: James Almer <jamrial at gmail.com>
---
 Changelog                |  1 +
 doc/general.texi         |  2 ++
 libavformat/Makefile     |  1 +
 libavformat/adp.c        | 86 ++++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/allformats.c |  1 +
 libavformat/version.h    |  2 +-
 6 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/adp.c

diff --git a/Changelog b/Changelog
index 967792c..dfa1819 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@ version <next>:
   become the default at the next libavformat major bump.
 - decent native animated GIF encoding
 - ADPCM DTK decoder
+- ADP demuxer
 
 
 version 1.2:
diff --git a/doc/general.texi b/doc/general.texi
index 215abe6..6bb3603 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -147,6 +147,8 @@ library:
     @tab Multimedia format used in game Heart Of Darkness.
 @item Apple HTTP Live Streaming @tab   @tab X
 @item Artworx Data Format       @tab   @tab X
+ at item ADP                       @tab   @tab X
+    @tab Audio format used on the Nintendo Gamecube.
 @item AFC                       @tab   @tab X
     @tab Audio format used on the Nintendo Gamecube.
 @item ASF                       @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 470e7f3..26c0944 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -55,6 +55,7 @@ OBJS-$(CONFIG_AC3_DEMUXER)               += ac3dec.o rawdec.o
 OBJS-$(CONFIG_AC3_MUXER)                 += rawenc.o
 OBJS-$(CONFIG_ACT_DEMUXER)               += act.o
 OBJS-$(CONFIG_ADF_DEMUXER)               += bintext.o sauce.o
+OBJS-$(CONFIG_ADP_DEMUXER)               += adp.o
 OBJS-$(CONFIG_ADX_DEMUXER)               += adxdec.o
 OBJS-$(CONFIG_ADX_MUXER)                 += rawenc.o
 OBJS-$(CONFIG_ADTS_MUXER)                += adtsenc.o
diff --git a/libavformat/adp.c b/libavformat/adp.c
new file mode 100644
index 0000000..398f2b6
--- /dev/null
+++ b/libavformat/adp.c
@@ -0,0 +1,86 @@
+/*
+ * ADP demuxer
+ * Copyright (c) 2013 James Almer
+ *
+ * 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/channel_layout.h"
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "internal.h"
+
+typedef struct ADPDemuxContext {
+    int64_t    filesize;
+} ADPDemuxContext;
+
+static int adp_probe(AVProbeData *p)
+{
+    if (p->buf[0] == p->buf[2] && p->buf[1] == p->buf[3])
+        return AVPROBE_SCORE_MAX / 3;
+    return 0;
+}
+
+static int adp_read_header(AVFormatContext *s)
+{
+    ADPDemuxContext *adp = s->priv_data;
+    AVStream *st;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+    adp->filesize = avio_size(s->pb);
+    st->codec->codec_type     = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id       = AV_CODEC_ID_ADPCM_DTK;
+    st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
+    st->codec->channels       = 2;
+    st->codec->sample_rate    = 48000;
+    st->start_time            = 0;
+    st->duration              = adp->filesize / 32 * 28;
+
+    avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+    return 0;
+}
+
+static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    ADPDemuxContext *adp = s->priv_data;
+    int ret, size = FFMIN(adp->filesize, 32 * 1024);
+
+    if (url_feof(s->pb) || size <= 0)
+        return AVERROR_EOF;
+
+    ret = av_get_packet(s->pb, pkt, size);
+    pkt->stream_index = 0;
+
+    if (ret != size)
+        ret = AVERROR(EIO);
+
+    return ret;
+}
+
+AVInputFormat ff_adp_demuxer = {
+    .name           = "adp",
+    .long_name      = NULL_IF_CONFIG_SMALL("ADP"),
+    .priv_data_size = sizeof(ADPDemuxContext),
+    .read_probe     = adp_probe,
+    .read_header    = adp_read_header,
+    .read_packet    = adp_read_packet,
+    .extensions     = "adp,dtk",
+};
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 80c53f6..cbe0414 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -65,6 +65,7 @@ void av_register_all(void)
     REGISTER_MUXDEMUX(AC3,              ac3);
     REGISTER_DEMUXER (ACT,              act);
     REGISTER_DEMUXER (ADF,              adf);
+    REGISTER_DEMUXER (ADP,              adp);
     REGISTER_MUXER   (ADTS,             adts);
     REGISTER_MUXDEMUX(ADX,              adx);
     REGISTER_DEMUXER (AEA,              aea);
diff --git a/libavformat/version.h b/libavformat/version.h
index 8fd08cf..3e186a9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 55
-#define LIBAVFORMAT_VERSION_MINOR  3
+#define LIBAVFORMAT_VERSION_MINOR  4
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
1.8.1.msysgit.1




More information about the ffmpeg-devel mailing list