[FFmpeg-cvslog] lavc: add little-endian ADPCM_THP decoder
Rodger Combs
git at videolan.org
Sat Jun 20 16:49:36 CEST 2015
ffmpeg | branch: master | Rodger Combs <rodger.combs at gmail.com> | Sat Jun 20 05:01:14 2015 -0500| [7e7256c3a4962613408b5549b8f643fcfdeea829] | committer: Michael Niedermayer
lavc: add little-endian ADPCM_THP decoder
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7e7256c3a4962613408b5549b8f643fcfdeea829
---
Changelog | 1 +
libavcodec/adpcm.c | 25 +++++++++++++++++++------
libavcodec/allcodecs.c | 1 +
libavcodec/avcodec.h | 1 +
libavcodec/codec_desc.c | 7 +++++++
libavcodec/utils.c | 1 +
libavcodec/version.h | 2 +-
7 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/Changelog b/Changelog
index c93889a..cfe3e93 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
version <next>:
- colorkey video filter
- BFSTM demuxer
+- little-endian ADPCM_THP decoder
version 2.7:
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 22b5468..9e230c7 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -105,6 +105,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
case AV_CODEC_ID_ADPCM_EA_R3:
case AV_CODEC_ID_ADPCM_EA_XAS:
case AV_CODEC_ID_ADPCM_THP:
+ case AV_CODEC_ID_ADPCM_THP_LE:
max_channels = 6;
break;
}
@@ -145,6 +146,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
case AV_CODEC_ID_ADPCM_EA_R3:
case AV_CODEC_ID_ADPCM_EA_XAS:
case AV_CODEC_ID_ADPCM_THP:
+ case AV_CODEC_ID_ADPCM_THP_LE:
case AV_CODEC_ID_ADPCM_AFC:
case AV_CODEC_ID_ADPCM_DTK:
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
@@ -636,13 +638,16 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
break;
}
case AV_CODEC_ID_ADPCM_THP:
+ case AV_CODEC_ID_ADPCM_THP_LE:
if (avctx->extradata) {
- nb_samples = buf_size / (8 * ch) * 14;
+ nb_samples = buf_size * 14 / (8 * ch);
break;
}
has_coded_samples = 1;
bytestream2_skip(gb, 4); // channel size
- *coded_samples = bytestream2_get_be32(gb);
+ *coded_samples = (avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE) ?
+ bytestream2_get_le32(gb) :
+ bytestream2_get_be32(gb);
*coded_samples -= *coded_samples % 14;
nb_samples = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
break;
@@ -1415,10 +1420,17 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
break;
}
case AV_CODEC_ID_ADPCM_THP:
+ case AV_CODEC_ID_ADPCM_THP_LE:
{
int table[6][16];
int ch;
+#define THP_GET16(g) \
+ sign_extend( \
+ avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
+ bytestream2_get_le16u(&(g)) : \
+ bytestream2_get_be16u(&(g)), 16)
+
if (avctx->extradata) {
GetByteContext tb;
if (avctx->extradata_size < 32 * avctx->channels) {
@@ -1429,16 +1441,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
for (i = 0; i < avctx->channels; i++)
for (n = 0; n < 16; n++)
- table[i][n] = sign_extend(bytestream2_get_be16u(&tb), 16);
+ table[i][n] = THP_GET16(tb);
} else {
for (i = 0; i < avctx->channels; i++)
for (n = 0; n < 16; n++)
- table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
+ table[i][n] = THP_GET16(gb);
/* Initialize the previous sample. */
for (i = 0; i < avctx->channels; i++) {
- c->status[i].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16);
- c->status[i].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16);
+ c->status[i].sample1 = THP_GET16(gb);
+ c->status[i].sample2 = THP_GET16(gb);
}
}
@@ -1593,6 +1605,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2,
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash");
+ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo Gamecube THP (little-endian)");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo Gamecube THP");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index ce97746..25462a6 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -486,6 +486,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(ADPCM_SBPRO_4, adpcm_sbpro_4);
REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf);
REGISTER_DECODER(ADPCM_THP, adpcm_thp);
+ REGISTER_DECODER(ADPCM_THP_LE, adpcm_thp_le);
REGISTER_DECODER(ADPCM_VIMA, adpcm_vima);
REGISTER_DECODER(ADPCM_XA, adpcm_xa);
REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 6fdeb4f..77cddf8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -401,6 +401,7 @@ enum AVCodecID {
AV_CODEC_ID_ADPCM_DTK = MKBETAG('D','T','K',' '),
AV_CODEC_ID_ADPCM_IMA_RAD = MKBETAG('R','A','D',' '),
AV_CODEC_ID_ADPCM_G726LE = MKBETAG('6','2','7','G'),
+ AV_CODEC_ID_ADPCM_THP_LE = MKBETAG('T','H','P','L'),
/* AMR */
AV_CODEC_ID_AMR_NB = 0x12000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index f32843a..81baf1e 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1824,6 +1824,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.props = AV_CODEC_PROP_LOSSY,
},
{
+ .id = AV_CODEC_ID_ADPCM_THP_LE,
+ .type = AVMEDIA_TYPE_AUDIO,
+ .name = "adpcm_thp_le",
+ .long_name = NULL_IF_CONFIG_SMALL("ADPCM Nintendo Gamecube THP (Little-Endian)"),
+ .props = AV_CODEC_PROP_LOSSY,
+ },
+ {
.id = AV_CODEC_ID_ADPCM_IMA_AMV,
.type = AVMEDIA_TYPE_AUDIO,
.name = "adpcm_ima_amv",
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a444a5e..78e14a2 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3431,6 +3431,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
case AV_CODEC_ID_ADPCM_IMA_AMV:
return (frame_bytes - 8) * 2 / ch;
case AV_CODEC_ID_ADPCM_THP:
+ case AV_CODEC_ID_ADPCM_THP_LE:
if (avctx->extradata)
return frame_bytes * 14 / (8 * ch);
break;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 74a1b30..7490dd9 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 56
-#define LIBAVCODEC_VERSION_MINOR 41
+#define LIBAVCODEC_VERSION_MINOR 42
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
More information about the ffmpeg-cvslog
mailing list