summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorCameron Cawley <ccawley2011@gmail.com>2018-10-13 00:06:39 +0100
committerPaul B Mahol <onemda@gmail.com>2018-10-26 13:39:25 +0200
commit22238d0b9440cf55aafda42c60f4413514d4aeb8 (patch)
treea406f18615ac7d99c232d797e229c5f3a9e7417b /libavcodec
parentfb7925ba2fa10e1ecf63eb4bada268e25627a88d (diff)
avcodec: Implement Archimedes VIDC encoder/decoder
Signed-off-by: Cameron Cawley <ccawley2011@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/Makefile2
-rw-r--r--libavcodec/allcodecs.c2
-rw-r--r--libavcodec/avcodec.h1
-rw-r--r--libavcodec/codec_desc.c7
-rw-r--r--libavcodec/pcm.c15
-rw-r--r--libavcodec/pcm_tablegen.c2
-rw-r--r--libavcodec/pcm_tablegen.h27
-rw-r--r--libavcodec/utils.c1
-rw-r--r--libavcodec/version.h4
9 files changed, 59 insertions, 2 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a97055ef3f..3e41497e34 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -794,6 +794,8 @@ OBJS-$(CONFIG_PCM_U32BE_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_U32BE_ENCODER) += pcm.o
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
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index c0b4d56d0d..1b8144a2b7 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -552,6 +552,8 @@ extern AVCodec ff_pcm_u32be_encoder;
extern AVCodec ff_pcm_u32be_decoder;
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 */
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 705a3ce4f3..7ffef768dc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -491,6 +491,7 @@ enum AVCodecID {
AV_CODEC_ID_PCM_S64BE,
AV_CODEC_ID_PCM_F16LE,
AV_CODEC_ID_PCM_F24LE,
+ AV_CODEC_ID_PCM_VIDC,
/* various ADPCM codecs */
AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 67a30542d1..1a159f7e13 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1936,6 +1936,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("PCM 24.0 floating point little-endian"),
.props = AV_CODEC_PROP_LOSSLESS,
},
+ {
+ .id = AV_CODEC_ID_PCM_VIDC,
+ .type = AVMEDIA_TYPE_AUDIO,
+ .name = "pcm_vidc",
+ .long_name = NULL_IF_CONFIG_SMALL("PCM Archimedes VIDC"),
+ .props = AV_CODEC_PROP_LOSSY,
+ },
/* various ADPCM codecs */
{
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 8c326c6829..ffcbccc77d 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -42,6 +42,9 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_PCM_MULAW:
pcm_ulaw_tableinit();
break;
+ case AV_CODEC_ID_PCM_VIDC:
+ pcm_vidc_tableinit();
+ break;
default:
break;
}
@@ -216,6 +219,12 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
*dst++ = linear_to_ulaw[(v + 32768) >> 2];
}
break;
+ case AV_CODEC_ID_PCM_VIDC:
+ for (; n > 0; n--) {
+ v = *samples++;
+ *dst++ = linear_to_vidc[(v + 32768) >> 2];
+ }
+ break;
default:
return -1;
}
@@ -249,6 +258,10 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
for (i = 0; i < 256; i++)
s->table[i] = ulaw2linear(i);
break;
+ case AV_CODEC_ID_PCM_VIDC:
+ for (i = 0; i < 256; i++)
+ s->table[i] = vidc2linear(i);
+ break;
case AV_CODEC_ID_PCM_F16LE:
case AV_CODEC_ID_PCM_F24LE:
s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
@@ -485,6 +498,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
break;
case AV_CODEC_ID_PCM_ALAW:
case AV_CODEC_ID_PCM_MULAW:
+ case AV_CODEC_ID_PCM_VIDC:
for (; n > 0; n--) {
AV_WN16A(samples, s->table[*src++]);
samples += 2;
@@ -612,3 +626,4 @@ PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned
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/pcm_tablegen.c b/libavcodec/pcm_tablegen.c
index bf8e7fb707..473a47f6d9 100644
--- a/libavcodec/pcm_tablegen.c
+++ b/libavcodec/pcm_tablegen.c
@@ -29,11 +29,13 @@ int main(void)
{
pcm_alaw_tableinit();
pcm_ulaw_tableinit();
+ pcm_vidc_tableinit();
write_fileheader();
WRITE_ARRAY("static const", uint8_t, linear_to_alaw);
WRITE_ARRAY("static const", uint8_t, linear_to_ulaw);
+ WRITE_ARRAY("static const", uint8_t, linear_to_vidc);
return 0;
}
diff --git a/libavcodec/pcm_tablegen.h b/libavcodec/pcm_tablegen.h
index 7ce147f768..d8763abc40 100644
--- a/libavcodec/pcm_tablegen.h
+++ b/libavcodec/pcm_tablegen.h
@@ -36,6 +36,12 @@
#define BIAS (0x84) /* Bias for linear code. */
+#define VIDC_SIGN_BIT (1)
+#define VIDC_QUANT_MASK (0x1E)
+#define VIDC_QUANT_SHIFT (1)
+#define VIDC_SEG_SHIFT (5)
+#define VIDC_SEG_MASK (0xE0)
+
/* alaw2linear() - Convert an A-law value to 16-bit linear PCM */
static av_cold int alaw2linear(unsigned char a_val)
{
@@ -69,14 +75,30 @@ static av_cold int ulaw2linear(unsigned char u_val)
return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
}
+static av_cold int vidc2linear(unsigned char u_val)
+{
+ int t;
+
+ /*
+ * Extract and bias the quantization bits. Then
+ * shift up by the segment number and subtract out the bias.
+ */
+ t = (((u_val & VIDC_QUANT_MASK) >> VIDC_QUANT_SHIFT) << 3) + BIAS;
+ t <<= ((unsigned)u_val & VIDC_SEG_MASK) >> VIDC_SEG_SHIFT;
+
+ return (u_val & VIDC_SIGN_BIT) ? (BIAS - t) : (t - BIAS);
+}
+
#if CONFIG_HARDCODED_TABLES
#define pcm_alaw_tableinit()
#define pcm_ulaw_tableinit()
+#define pcm_vidc_tableinit()
#include "libavcodec/pcm_tables.h"
#else
/* 16384 entries per table */
static uint8_t linear_to_alaw[16384];
static uint8_t linear_to_ulaw[16384];
+static uint8_t linear_to_vidc[16384];
static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
int (*xlaw2linear)(unsigned char),
@@ -111,6 +133,11 @@ static void pcm_ulaw_tableinit(void)
{
build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
}
+
+static void pcm_vidc_tableinit(void)
+{
+ build_xlaw_table(linear_to_vidc, vidc2linear, 0xff);
+}
#endif /* CONFIG_HARDCODED_TABLES */
#endif /* AVCODEC_PCM_TABLEGEN_H */
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 285bfdbc63..1661d48b90 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1438,6 +1438,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
case AV_CODEC_ID_DSD_MSBF_PLANAR:
case AV_CODEC_ID_PCM_ALAW:
case AV_CODEC_ID_PCM_MULAW:
+ case AV_CODEC_ID_PCM_VIDC:
case AV_CODEC_ID_PCM_S8:
case AV_CODEC_ID_PCM_S8_PLANAR:
case AV_CODEC_ID_PCM_U8:
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 9098882f47..91809641b4 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,8 +28,8 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 58
-#define LIBAVCODEC_VERSION_MINOR 33
-#define LIBAVCODEC_VERSION_MICRO 102
+#define LIBAVCODEC_VERSION_MINOR 34
+#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \