Commit 51d68799 authored by Paul B Mahol's avatar Paul B Mahol

AFC demuxer

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 10c8f913
......@@ -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
@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.
......
......@@ -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];
......
......@@ -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
......
/*
* 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,
};
......@@ -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);
......
......@@ -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, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment