Hi, patches attached.
From abc698513cbbbbbbf96b464ff5e9995d9e1e4f12 Mon Sep 17 00:00:00 2001 From: Paul B Mahol <one...@gmail.com> Date: Sun, 15 May 2016 20:35:14 +0200 Subject: [PATCH 1/2] avformat: add MTAF demuxer
Signed-off-by: Paul B Mahol <one...@gmail.com> --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/mtaf.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 libavformat/mtaf.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 742aff5..6684ead 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -301,6 +301,7 @@ OBJS-$(CONFIG_MPL2_DEMUXER) += mpl2dec.o subtitles.o OBJS-$(CONFIG_MSF_DEMUXER) += msf.o OBJS-$(CONFIG_MPSUB_DEMUXER) += mpsubdec.o subtitles.o OBJS-$(CONFIG_MSNWC_TCP_DEMUXER) += msnwc_tcp.o +OBJS-$(CONFIG_MTAF_DEMUXER) += mtaf.o OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o OBJS-$(CONFIG_MUSX_DEMUXER) += musx.o OBJS-$(CONFIG_MV_DEMUXER) += mvdec.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index e6ee8d6..0a38793 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -209,6 +209,7 @@ void av_register_all(void) REGISTER_DEMUXER (MPSUB, mpsub); REGISTER_DEMUXER (MSF, msf); REGISTER_DEMUXER (MSNWC_TCP, msnwc_tcp); + REGISTER_DEMUXER (MTAF, mtaf); REGISTER_DEMUXER (MTV, mtv); REGISTER_DEMUXER (MUSX, musx); REGISTER_DEMUXER (MV, mv); diff --git a/libavformat/mtaf.c b/libavformat/mtaf.c new file mode 100644 index 0000000..b25c2aa --- /dev/null +++ b/libavformat/mtaf.c @@ -0,0 +1,81 @@ +/* + * MTAF demuxer + * Copyright (c) 2016 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 "libavutil/intreadwrite.h" +#include "avformat.h" +#include "internal.h" + +static int mtaf_probe(AVProbeData *p) +{ + if (p->buf_size < 0x44) + return 0; + + if (AV_RL32(p->buf) != MKTAG('M','T','A','F') || + AV_RL32(p->buf + 0x40) != MKTAG('H','E','A','D')) + return 0; + + return AVPROBE_SCORE_MAX; +} + +static int mtaf_read_header(AVFormatContext *s) +{ + int stream_count; + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + avio_skip(s->pb, 0x5c); + st->duration = avio_rl32(s->pb); + avio_skip(s->pb, 1); + stream_count = avio_r8(s->pb); + if (!stream_count) + return AVERROR_INVALIDDATA; + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_MTAF; + st->codecpar->channels = 2 * stream_count; + st->codecpar->sample_rate = 48000; + st->codecpar->block_align = 0x110 * st->codecpar->channels / 2; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); + + avio_seek(s->pb, 0x800, SEEK_SET); + + return 0; +} + +static int mtaf_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVCodecParameters *par = s->streams[0]->codecpar; + + return av_get_packet(s->pb, pkt, par->block_align); +} + +AVInputFormat ff_mtaf_demuxer = { + .name = "mtaf", + .long_name = NULL_IF_CONFIG_SMALL("Konami PS2 MTAF"), + .read_probe = mtaf_probe, + .read_header = mtaf_read_header, + .read_packet = mtaf_read_packet, + .extensions = "mtaf", +}; -- 2.5.0
From a3c0ddfde6a75a6d0724f52c8c9779e5123abebb Mon Sep 17 00:00:00 2001 From: Paul B Mahol <one...@gmail.com> Date: Sun, 15 May 2016 20:45:04 +0200 Subject: [PATCH 2/2] avcodec: add adpcm MTAF decoder Signed-off-by: Paul B Mahol <one...@gmail.com> --- libavcodec/Makefile | 1 + libavcodec/adpcm.c | 41 ++++++++++++++++++++++++++++++ libavcodec/adpcm_data.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/adpcm_data.h | 1 + libavcodec/allcodecs.c | 1 + libavcodec/avcodec.h | 1 + libavcodec/codec_desc.c | 7 ++++++ libavcodec/utils.c | 2 ++ 8 files changed, 121 insertions(+) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3f0ffd1..3a9dd95 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -707,6 +707,7 @@ OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_MTAF_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_PSX_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o adpcm_data.o diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 0b6b92e..e624b85 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -107,6 +107,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) case AV_CODEC_ID_ADPCM_EA_XAS: max_channels = 6; break; + case AV_CODEC_ID_ADPCM_MTAF: + min_channels = 2; + max_channels = 8; + break; case AV_CODEC_ID_ADPCM_PSX: max_channels = 8; break; @@ -159,6 +163,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) case AV_CODEC_ID_ADPCM_AFC: case AV_CODEC_ID_ADPCM_DTK: case AV_CODEC_ID_ADPCM_PSX: + case AV_CODEC_ID_ADPCM_MTAF: avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break; case AV_CODEC_ID_ADPCM_IMA_WS: @@ -342,6 +347,15 @@ static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t return c->predictor; } +static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble) +{ + c->predictor += ff_adpcm_mtaf_stepsize[c->step][nibble]; + c->predictor = av_clip_int16(c->predictor); + c->step += ff_adpcm_index_table[nibble]; + c->step = av_clip(c->step, 0, 31); + return c->predictor; +} + static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1, const uint8_t *in, ADPCMChannelStatus *left, ADPCMChannelStatus *right, int channels, int sample_offset) @@ -617,6 +631,11 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, buf_size = FFMIN(buf_size, avctx->block_align); nb_samples = (buf_size - 6 * ch) * 2 / ch; break; + case AV_CODEC_ID_ADPCM_MTAF: + if (avctx->block_align > 0) + buf_size = FFMIN(buf_size, avctx->block_align); + nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch; + break; case AV_CODEC_ID_ADPCM_SBPRO_2: case AV_CODEC_ID_ADPCM_SBPRO_3: case AV_CODEC_ID_ADPCM_SBPRO_4: @@ -887,6 +906,27 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } break; } + case AV_CODEC_ID_ADPCM_MTAF: + for (channel = 0; channel < avctx->channels; channel+=2) { + bytestream2_skipu(&gb, 4); + c->status[channel ].step = bytestream2_get_le16u(&gb); + c->status[channel + 1].step = bytestream2_get_le16u(&gb); + c->status[channel ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); + bytestream2_skipu(&gb, 2); + c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); + bytestream2_skipu(&gb, 2); + for (n = 0; n < nb_samples; n+=2) { + int v = bytestream2_get_byteu(&gb); + samples_p[channel][n ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F); + samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4 ); + } + for (n = 0; n < nb_samples; n+=2) { + int v = bytestream2_get_byteu(&gb); + samples_p[channel + 1][n ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F); + samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4 ); + } + } + break; case AV_CODEC_ID_ADPCM_IMA_DK4: for (channel = 0; channel < avctx->channels; channel++) { cs = &c->status[channel]; @@ -1706,6 +1746,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_s16, adpcm_ms, "ADPCM Microsoft"); +ADPCM_DECODER(AV_CODEC_ID_ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit"); diff --git a/libavcodec/adpcm_data.c b/libavcodec/adpcm_data.c index 9c38360..655bfc4 100644 --- a/libavcodec/adpcm_data.c +++ b/libavcodec/adpcm_data.c @@ -110,3 +110,70 @@ const int16_t ff_adpcm_afc_coeffs[2][16] = { { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, 64512, 64512, 63488 }, { 0, 0, 2048, 1024, 63488, 64000, 64512, 62976, 63288, 63236, 62464, 63488, 64512, 1024, 0, 0 } }; + +const int16_t ff_adpcm_mtaf_stepsize[32][16] = { + { 1, 5, 9, 13, 16, 20, 24, 28, + -1, -5, -9, -13, -16, -20, -24, -28, }, + { 2, 6, 11, 15, 20, 24, 29, 33, + -2, -6, -11, -15, -20, -24, -29, -33, }, + { 2, 7, 13, 18, 23, 28, 34, 39, + -2, -7, -13, -18, -23, -28, -34, -39, }, + { 3, 9, 15, 21, 28, 34, 40, 46, + -3, -9, -15, -21, -28, -34, -40, -46, }, + { 3, 11, 18, 26, 33, 41, 48, 56, + -3, -11, -18, -26, -33, -41, -48, -56, }, + { 4, 13, 22, 31, 40, 49, 58, 67, + -4, -13, -22, -31, -40, -49, -58, -67, }, + { 5, 16, 26, 37, 48, 59, 69, 80, + -5, -16, -26, -37, -48, -59, -69, -80, }, + { 6, 19, 31, 44, 57, 70, 82, 95, + -6, -19, -31, -44, -57, -70, -82, -95, }, + { 7, 22, 38, 53, 68, 83, 99, 114, + -7, -22, -38, -53, -68, -83, -99, -114, }, + { 9, 27, 45, 63, 81, 99, 117, 135, + -9, -27, -45, -63, -81, -99, -117, -135, }, + { 10, 32, 53, 75, 96, 118, 139, 161, + -10, -32, -53, -75, -96, -118, -139, -161, }, + { 12, 38, 64, 90, 115, 141, 167, 193, + -12, -38, -64, -90, -115, -141, -167, -193, }, + { 15, 45, 76, 106, 137, 167, 198, 228, + -15, -45, -76, -106, -137, -167, -198, -228, }, + { 18, 54, 91, 127, 164, 200, 237, 273, + -18, -54, -91, -127, -164, -200, -237, -273, }, + { 21, 65, 108, 152, 195, 239, 282, 326, + -21, -65, -108, -152, -195, -239, -282, -326, }, + { 25, 77, 129, 181, 232, 284, 336, 388, + -25, -77, -129, -181, -232, -284, -336, -388, }, + { 30, 92, 153, 215, 276, 338, 399, 461, + -30, -92, -153, -215, -276, -338, -399, -461, }, + { 36, 109, 183, 256, 329, 402, 476, 549, + -36, -109, -183, -256, -329, -402, -476, -549, }, + { 43, 130, 218, 305, 392, 479, 567, 654, + -43, -130, -218, -305, -392, -479, -567, -654, }, + { 52, 156, 260, 364, 468, 572, 676, 780, + -52, -156, -260, -364, -468, -572, -676, -780, }, + { 62, 186, 310, 434, 558, 682, 806, 930, + -62, -186, -310, -434, -558, -682, -806, -930, }, + { 73, 221, 368, 516, 663, 811, 958, 1106, + -73, -221, -368, -516, -663, -811, -958, -1106, }, + { 87, 263, 439, 615, 790, 966, 1142, 1318, + -87, -263, -439, -615, -790, -966, -1142, -1318, }, + { 104, 314, 523, 733, 942, 1152, 1361, 1571, + -104, -314, -523, -733, -942, -1152, -1361, -1571, }, + { 124, 374, 623, 873, 1122, 1372, 1621, 1871, + -124, -374, -623, -873, -1122, -1372, -1621, -1871, }, + { 148, 445, 743, 1040, 1337, 1634, 1932, 2229, + -148, -445, -743, -1040, -1337, -1634, -1932, -2229, }, + { 177, 531, 885, 1239, 1593, 1947, 2301, 2655, + -177, -531, -885, -1239, -1593, -1947, -2301, -2655, }, + { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161, + -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, }, + { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766, + -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, }, + { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486, + -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, }, + { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343, + -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, }, + { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365, + -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, }, +}; diff --git a/libavcodec/adpcm_data.h b/libavcodec/adpcm_data.h index b179d65..3ae2784 100644 --- a/libavcodec/adpcm_data.h +++ b/libavcodec/adpcm_data.h @@ -41,5 +41,6 @@ extern const int8_t ff_adpcm_AdaptCoeff2[]; extern const int16_t ff_adpcm_yamaha_indexscale[]; extern const int8_t ff_adpcm_yamaha_difflookup[]; extern const int16_t ff_adpcm_afc_coeffs[2][16]; +extern const int16_t ff_adpcm_mtaf_stepsize[32][16]; #endif /* AVCODEC_ADPCM_DATA_H */ diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 44ebafd..6d0a7e7 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -524,6 +524,7 @@ void avcodec_register_all(void) REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); REGISTER_DECODER(ADPCM_IMA_WS, adpcm_ima_ws); REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); + REGISTER_DECODER(ADPCM_MTAF, adpcm_mtaf); REGISTER_DECODER(ADPCM_PSX, adpcm_psx); REGISTER_DECODER(ADPCM_SBPRO_2, adpcm_sbpro_2); REGISTER_DECODER(ADPCM_SBPRO_3, adpcm_sbpro_3); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 9ec9adf..00d0ef8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -489,6 +489,7 @@ enum AVCodecID { AV_CODEC_ID_ADPCM_PSX, AV_CODEC_ID_ADPCM_AICA, AV_CODEC_ID_ADPCM_IMA_DAT4, + AV_CODEC_ID_ADPCM_MTAF, /* AMR */ AV_CODEC_ID_AMR_NB = 0x12000, diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 23d5911..c7acd01 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -2690,6 +2690,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("DST (Direct Stream Transfer)"), .props = AV_CODEC_PROP_LOSSLESS, }, + { + .id = AV_CODEC_ID_ADPCM_MTAF, + .type = AVMEDIA_TYPE_AUDIO, + .name = "adpcm_mtaf", + .long_name = NULL_IF_CONFIG_SMALL("ADPCM MTAF"), + .props = AV_CODEC_PROP_LOSSY, + }, /* subtitle codecs */ { diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e5a832b..c2be7d6 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3600,6 +3600,8 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, return blocks * ((ba - 4 * ch) * 2 / ch); case AV_CODEC_ID_ADPCM_MS: return blocks * (2 + (ba - 7 * ch) * 2 / ch); + case AV_CODEC_ID_ADPCM_MTAF: + return blocks * (ba - 16) / 2; } } -- 2.5.0
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel