[FFmpeg-devel] [PATCH 1/3] avcodec: add SGA PCM decoder

Paul B Mahol onemda at gmail.com
Fri Feb 26 13:29:17 EET 2021


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavcodec/Makefile     | 1 +
 libavcodec/allcodecs.c  | 1 +
 libavcodec/codec_desc.c | 7 +++++++
 libavcodec/codec_id.h   | 1 +
 libavcodec/pcm.c        | 9 +++++++++
 libavcodec/utils.c      | 1 +
 6 files changed, 20 insertions(+)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index eb90841dfe..fe7026c1db 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -830,6 +830,7 @@ OBJS-$(CONFIG_PCM_S64BE_DECODER)          += pcm.o
 OBJS-$(CONFIG_PCM_S64BE_ENCODER)          += pcm.o
 OBJS-$(CONFIG_PCM_S64LE_DECODER)          += pcm.o
 OBJS-$(CONFIG_PCM_S64LE_ENCODER)          += pcm.o
+OBJS-$(CONFIG_PCM_SGA_DECODER)            += pcm.o
 OBJS-$(CONFIG_PCM_U8_DECODER)             += pcm.o
 OBJS-$(CONFIG_PCM_U8_ENCODER)             += pcm.o
 OBJS-$(CONFIG_PCM_U16BE_DECODER)          += pcm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 354d146379..990998b64b 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -568,6 +568,7 @@ extern AVCodec ff_pcm_s64be_encoder;
 extern AVCodec ff_pcm_s64be_decoder;
 extern AVCodec ff_pcm_s64le_encoder;
 extern AVCodec ff_pcm_s64le_decoder;
+extern AVCodec ff_pcm_sga_decoder;
 extern AVCodec ff_pcm_u8_encoder;
 extern AVCodec ff_pcm_u8_decoder;
 extern AVCodec ff_pcm_u16be_encoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 8e695b11d2..f64ba488f2 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2096,6 +2096,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("PCM Archimedes VIDC"),
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_PCM_SGA,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "pcm_sga",
+        .long_name = NULL_IF_CONFIG_SMALL("PCM SGA"),
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
+    },
 
     /* various ADPCM codecs */
     {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 56a69cf1c2..7dd316afd2 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -346,6 +346,7 @@ enum AVCodecID {
     AV_CODEC_ID_PCM_F16LE,
     AV_CODEC_ID_PCM_F24LE,
     AV_CODEC_ID_PCM_VIDC,
+    AV_CODEC_ID_PCM_SGA,
 
     /* various ADPCM codecs */
     AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 7f0af8564f..19d04e9181 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -419,6 +419,14 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
         for (; n > 0; n--)
             *samples++ = *src++ + 128;
         break;
+    case AV_CODEC_ID_PCM_SGA:
+        for (; n > 0; n--) {
+            int sign = *src >> 7;
+            int magn = *src & 0x7f;
+            *samples++ = sign ? 128 - magn : 128 + magn;
+            src++;
+        }
+        break;
     case AV_CODEC_ID_PCM_S8_PLANAR:
         n /= avctx->channels;
         for (c = 0; c < avctx->channels; c++) {
@@ -622,3 +630,4 @@ PCM_CODEC  (PCM_U32LE,        AV_SAMPLE_FMT_S32, pcm_u32le,        "PCM unsigned
 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");
+PCM_DECODER(PCM_SGA,          AV_SAMPLE_FMT_U8,  pcm_sga,          "PCM SGA");
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4d1909b581..db6cd0cde8 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1547,6 +1547,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
     case AV_CODEC_ID_PCM_VIDC:
     case AV_CODEC_ID_PCM_S8:
     case AV_CODEC_ID_PCM_S8_PLANAR:
+    case AV_CODEC_ID_PCM_SGA:
     case AV_CODEC_ID_PCM_U8:
     case AV_CODEC_ID_SDX2_DPCM:
     case AV_CODEC_ID_DERF_DPCM:
-- 
2.17.1



More information about the ffmpeg-devel mailing list