[FFmpeg-cvslog] avcodec: fix pcm zork decoder
Paul B Mahol
git at videolan.org
Sun Feb 16 13:55:51 EET 2020
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Feb 14 20:37:42 2020 +0100| [dfb0b9370d3621ab1f603e7bb8e142b1f6996562] | committer: Paul B Mahol
avcodec: fix pcm zork decoder
Fixes #1939
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dfb0b9370d3621ab1f603e7bb8e142b1f6996562
---
libavcodec/Makefile | 2 +-
libavcodec/adpcm.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
libavcodec/allcodecs.c | 2 +-
libavcodec/avcodec.h | 1 +
libavcodec/codec_desc.c | 14 ++++++------
libavcodec/pcm.c | 9 --------
libavcodec/utils.c | 1 -
libavcodec/version.h | 2 +-
libavformat/riff.c | 2 +-
libavformat/riffdec.c | 2 +-
10 files changed, 73 insertions(+), 22 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b49328aed7..46da42570f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -810,7 +810,6 @@ OBJS-$(CONFIG_PCM_U32LE_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_U32LE_ENCODER) += pcm.o
OBJS-$(CONFIG_PCM_VIDC_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_VIDC_ENCODER) += pcm.o
-OBJS-$(CONFIG_PCM_ZORK_DECODER) += pcm.o
OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o adx.o
@@ -865,6 +864,7 @@ OBJS-$(CONFIG_ADPCM_VIMA_DECODER) += vima.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_ZORK_DECODER) += adpcm.o adpcm_data.o
# hardware accelerators
OBJS-$(CONFIG_D3D11VA) += dxva2.o
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 0cd28431d7..f5d20ddd81 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -83,6 +83,10 @@ static const int8_t swf_index_tables[4][16] = {
/*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
};
+static const int8_t zork_index_table[8] = {
+ -1, -1, -1, 1, 4, 7, 10, 12,
+};
+
/* end of tables */
typedef struct ADPCMDecodeContext {
@@ -154,6 +158,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
if (avctx->bits_per_coded_sample != 4)
return AVERROR_INVALIDDATA;
break;
+ case AV_CODEC_ID_ADPCM_ZORK:
+ if (avctx->bits_per_coded_sample != 8)
+ return AVERROR_INVALIDDATA;
+ break;
default:
break;
}
@@ -416,6 +424,41 @@ static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t ni
return c->predictor;
}
+static inline int16_t adpcm_zork_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
+{
+ int16_t index = c->step_index;
+ uint32_t lookup_sample = ff_adpcm_step_table[index];
+ int32_t sample = 0;
+
+ if (nibble & 0x40)
+ sample += lookup_sample;
+ if (nibble & 0x20)
+ sample += lookup_sample >> 1;
+ if (nibble & 0x10)
+ sample += lookup_sample >> 2;
+ if (nibble & 0x08)
+ sample += lookup_sample >> 3;
+ if (nibble & 0x04)
+ sample += lookup_sample >> 4;
+ if (nibble & 0x02)
+ sample += lookup_sample >> 5;
+ if (nibble & 0x01)
+ sample += lookup_sample >> 6;
+ if (nibble & 0x80)
+ sample = -sample;
+
+ sample += c->predictor;
+ sample = av_clip_int16(sample);
+
+ index += zork_index_table[(nibble >> 4) & 7];
+ index = av_clip(index, 0, 88);
+
+ c->predictor = sample;
+ c->step_index = index;
+
+ return sample;
+}
+
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)
@@ -780,6 +823,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
case AV_CODEC_ID_ADPCM_PSX:
nb_samples = buf_size / (16 * ch) * 28;
break;
+ case AV_CODEC_ID_ADPCM_ZORK:
+ nb_samples = buf_size / ch;
+ break;
}
/* validate coded sample count */
@@ -1842,6 +1888,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
}
break;
+ case AV_CODEC_ID_ADPCM_ZORK:
+ if (!c->has_status) {
+ for (channel = 0; channel < avctx->channels; channel++) {
+ c->status[channel].predictor = 0;
+ c->status[channel].step_index = 0;
+ }
+ c->has_status = 1;
+ }
+ for (n = 0; n < nb_samples * avctx->channels; n++) {
+ int v = bytestream2_get_byteu(&gb);
+ *samples++ = adpcm_zork_expand_nibble(&c->status[n % avctx->channels], v);
+ }
+ break;
default:
av_assert0(0); // unsupported codec_id should not happen
}
@@ -1930,3 +1989,4 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le,
ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo 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");
+ADPCM_DECODER(AV_CODEC_ID_ADPCM_ZORK, sample_fmts_s16, adpcm_zork, "ADPCM Zork");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index aff0b88d2d..103f34fd32 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -566,7 +566,6 @@ extern AVCodec ff_pcm_u32le_encoder;
extern AVCodec ff_pcm_u32le_decoder;
extern AVCodec ff_pcm_vidc_encoder;
extern AVCodec ff_pcm_vidc_decoder;
-extern AVCodec ff_pcm_zork_decoder;
/* DPCM codecs */
extern AVCodec ff_gremlin_dpcm_decoder;
@@ -630,6 +629,7 @@ extern AVCodec ff_adpcm_vima_decoder;
extern AVCodec ff_adpcm_xa_decoder;
extern AVCodec ff_adpcm_yamaha_encoder;
extern AVCodec ff_adpcm_yamaha_decoder;
+extern AVCodec ff_adpcm_zork_decoder;
/* subtitles */
extern AVCodec ff_ssa_encoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 8cbcd3b1d0..368341ba93 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -548,6 +548,7 @@ enum AVCodecID {
AV_CODEC_ID_ADPCM_AGM,
AV_CODEC_ID_ADPCM_ARGO,
AV_CODEC_ID_ADPCM_IMA_SSI,
+ AV_CODEC_ID_ADPCM_ZORK,
/* AMR */
AV_CODEC_ID_AMR_NB = 0x12000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 960c4889f8..609c7501fd 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1875,13 +1875,6 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("PCM D-Cinema audio signed 24-bit"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
},
- {
- .id = AV_CODEC_ID_PCM_ZORK,
- .type = AVMEDIA_TYPE_AUDIO,
- .name = "pcm_zork",
- .long_name = NULL_IF_CONFIG_SMALL("PCM Zork"),
- .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
- },
{
.id = AV_CODEC_ID_PCM_S16LE_PLANAR,
.type = AVMEDIA_TYPE_AUDIO,
@@ -2318,6 +2311,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Simon & Schuster Interactive"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
},
+ {
+ .id = AV_CODEC_ID_ADPCM_ZORK,
+ .type = AVMEDIA_TYPE_AUDIO,
+ .name = "adpcm_zork",
+ .long_name = NULL_IF_CONFIG_SMALL("ADPCM Zork"),
+ .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+ },
/* AMR */
{
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 0c4b452b0e..6346510de0 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -491,14 +491,6 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
bytestream_get_buffer(&src, samples, n * sample_size);
}
break;
- case AV_CODEC_ID_PCM_ZORK:
- for (; n > 0; n--) {
- int v = *src++;
- if (v < 128)
- v = 128 - v;
- *samples++ = v;
- }
- break;
case AV_CODEC_ID_PCM_ALAW:
case AV_CODEC_ID_PCM_MULAW:
case AV_CODEC_ID_PCM_VIDC:
@@ -626,7 +618,6 @@ PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned
PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian");
PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian");
PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian");
-PCM_DECODER(PCM_ZORK, AV_SAMPLE_FMT_U8, pcm_zork, "PCM Zork");
PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be, "PCM signed 64-bit big-endian");
PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le, "PCM signed 64-bit little-endian");
PCM_CODEC (PCM_VIDC, AV_SAMPLE_FMT_S16, pcm_vidc, "PCM Archimedes VIDC");
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c685b9c9d7..dba2022478 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1474,7 +1474,6 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
case AV_CODEC_ID_PCM_S8:
case AV_CODEC_ID_PCM_S8_PLANAR:
case AV_CODEC_ID_PCM_U8:
- case AV_CODEC_ID_PCM_ZORK:
case AV_CODEC_ID_SDX2_DPCM:
return 8;
case AV_CODEC_ID_PCM_S16BE:
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 692c4a0e49..5c8147f681 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 58
-#define LIBAVCODEC_VERSION_MINOR 69
+#define LIBAVCODEC_VERSION_MINOR 70
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavformat/riff.c b/libavformat/riff.c
index c73f6e9db0..b15d5e9753 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -516,7 +516,7 @@ const AVCodecTag ff_codec_wav_tags[] = {
{ AV_CODEC_ID_ADPCM_IMA_OKI, 0x0010 },
{ AV_CODEC_ID_ADPCM_IMA_WAV, 0x0011 },
/* must come after adpcm_ima_wav in this list */
- { AV_CODEC_ID_PCM_ZORK, 0x0011 },
+ { AV_CODEC_ID_ADPCM_ZORK, 0x0011 },
{ AV_CODEC_ID_ADPCM_IMA_OKI, 0x0017 },
{ AV_CODEC_ID_ADPCM_YAMAHA, 0x0020 },
{ AV_CODEC_ID_TRUESPEECH, 0x0022 },
diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 070c42eee3..533bb5a15d 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -202,7 +202,7 @@ enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps)
id = ff_get_pcm_codec_id(bps, 1, 0, 0);
if (id == AV_CODEC_ID_ADPCM_IMA_WAV && bps == 8)
- id = AV_CODEC_ID_PCM_ZORK;
+ id = AV_CODEC_ID_ADPCM_ZORK;
return id;
}
More information about the ffmpeg-cvslog
mailing list