[FFmpeg-cvslog] AFC demuxer

Paul B Mahol git at videolan.org
Tue Nov 27 11:23:15 CET 2012


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Nov 26 12:49:46 2012 +0000| [51d6879939bf4777227d77db59c659c66d3d967d] | committer: Paul B Mahol

AFC demuxer

Signed-off-by: Paul B Mahol <onemda at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=51d6879939bf4777227d77db59c659c66d3d967d
---

 doc/general.texi         |    2 ++
 libavcodec/adpcm.c       |   19 +++++++++--
 libavformat/Makefile     |    1 +
 libavformat/afc.c        |   81 ++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/allformats.c |    1 +
 libavformat/version.h    |    2 +-
 6 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/doc/general.texi b/doc/general.texi
index 366b315..0e10d30 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 AFC                       @tab   @tab X
+    @tab Audio format used on the Nintendo Gamecube.
 @item ASF                       @tab X @tab X
 @item AST                       @tab   @tab X
     @tab Audio format used on the Nintendo Wii.
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index df8aba9..c182e6f 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -1268,13 +1268,26 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         break;
     case AV_CODEC_ID_ADPCM_AFC:
+    {
+        int samples_per_block;
+        int blocks;
+
+        if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
+            samples_per_block = avctx->extradata[0] / 16;
+            blocks = nb_samples / avctx->extradata[0];
+        } else {
+            samples_per_block = nb_samples / 16;
+            blocks = 1;
+        }
+
+        for (m = 0; m < blocks; m++) {
         for (channel = 0; channel < avctx->channels; channel++) {
             int prev1 = c->status[channel].sample1;
             int prev2 = c->status[channel].sample2;
 
-            samples = samples_p[channel];
+            samples = samples_p[channel] + m * 16;
             /* Read in every sample for this channel.  */
-            for (i = 0; i < nb_samples / 16; i++) {
+            for (i = 0; i < samples_per_block; i++) {
                 int byte = bytestream2_get_byteu(&gb);
                 int scale = 1 << (byte >> 4);
                 int index = byte & 0xf;
@@ -1303,8 +1316,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             c->status[channel].sample1 = prev1;
             c->status[channel].sample2 = prev2;
         }
+        }
         bytestream2_seek(&gb, 0, SEEK_END);
         break;
+    }
     case AV_CODEC_ID_ADPCM_THP:
     {
         int table[6][16];
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 136ada8..463ce32 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -37,6 +37,7 @@ OBJS-$(CONFIG_ADX_DEMUXER)               += adxdec.o
 OBJS-$(CONFIG_ADX_MUXER)                 += rawenc.o
 OBJS-$(CONFIG_ADTS_MUXER)                += adtsenc.o
 OBJS-$(CONFIG_AEA_DEMUXER)               += aea.o pcm.o
+OBJS-$(CONFIG_AFC_DEMUXER)               += afc.o
 OBJS-$(CONFIG_AIFF_DEMUXER)              += aiffdec.o pcm.o isom.o \
                                             mov_chan.o
 OBJS-$(CONFIG_AIFF_MUXER)                += aiffenc.o isom.o
diff --git a/libavformat/afc.c b/libavformat/afc.c
new file mode 100644
index 0000000..183a8e0
--- /dev/null
+++ b/libavformat/afc.c
@@ -0,0 +1,81 @@
+/*
+ * AFC demuxer
+ * Copyright (c) 2012 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/channel_layout.h"
+#include "avformat.h"
+#include "internal.h"
+
+typedef struct AFCDemuxContext {
+    int64_t    data_end;
+} AFCDemuxContext;
+
+static int afc_read_header(AVFormatContext *s)
+{
+    AFCDemuxContext *c = s->priv_data;
+    AVStream *st;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id   = AV_CODEC_ID_ADPCM_AFC;
+    st->codec->channels   = 2;
+    st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
+    st->codec->extradata_size = 1;
+
+    st->codec->extradata = av_mallocz(1 + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!st->codec->extradata)
+        return AVERROR(ENOMEM);
+    st->codec->extradata[0] = 8 * st->codec->channels;
+
+    c->data_end = avio_rb32(s->pb) + 32LL;
+    st->duration = avio_rb32(s->pb);
+    st->codec->sample_rate = avio_rb16(s->pb);
+    avio_skip(s->pb, 22);
+    avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+    return 0;
+}
+
+static int afc_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    AFCDemuxContext *c = s->priv_data;
+    int64_t size;
+    int ret;
+
+    size = FFMIN(c->data_end - avio_tell(s->pb), 18 * 128);
+    if (size <= 0)
+        return AVERROR_EOF;
+
+    ret = av_get_packet(s->pb, pkt, size);
+    pkt->stream_index = 0;
+    return ret;
+}
+
+AVInputFormat ff_afc_demuxer = {
+    .name           = "afc",
+    .long_name      = NULL_IF_CONFIG_SMALL("AFC"),
+    .priv_data_size = sizeof(AFCDemuxContext),
+    .read_header    = afc_read_header,
+    .read_packet    = afc_read_packet,
+    .extensions     = "afc",
+    .flags          = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
+};
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index eaeb51a..6c721c4 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -57,6 +57,7 @@ void av_register_all(void)
     REGISTER_MUXER    (ADTS, adts);
     REGISTER_MUXDEMUX (ADX, adx);
     REGISTER_DEMUXER  (AEA, aea);
+    REGISTER_DEMUXER  (AFC, afc);
     REGISTER_MUXDEMUX (AIFF, aiff);
     REGISTER_MUXDEMUX (AMR, amr);
     REGISTER_DEMUXER  (ANM, anm);
diff --git a/libavformat/version.h b/libavformat/version.h
index 02ebb8c..10391b3 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 37
+#define LIBAVFORMAT_VERSION_MINOR 38
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list