[FFmpeg-devel] [PATCH 1/2] avcodec: add adpcm_ima_ssi encoder

Zane van Iperen zane at zanevaniperen.com
Fri Apr 10 06:10:40 EEST 2020


Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
---
 Changelog              |  1 +
 doc/general.texi       |  2 +-
 libavcodec/Makefile    |  1 +
 libavcodec/adpcmenc.c  | 30 ++++++++++++++++++++++++++++++
 libavcodec/allcodecs.c |  1 +
 libavcodec/utils.c     |  1 +
 libavcodec/version.h   |  4 ++--
 7 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index e6db88af07..b4fff44329 100644
--- a/Changelog
+++ b/Changelog
@@ -56,6 +56,7 @@ version <next>:
 - CRI HCA demuxer
 - overlay_cuda filter
 - switch from AvxSynth to AviSynth+ on Linux
+- Simon & Schuster Interactive ADPCM encoder
 
 
 version 4.2:
diff --git a/doc/general.texi b/doc/general.texi
index 4adcc9e742..a7b0cc1718 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1107,7 +1107,7 @@ following image formats are supported:
 @item ADPCM IMA Funcom       @tab     @tab  X
 @item ADPCM IMA High Voltage Software ALP   @tab     @tab  X
 @item ADPCM IMA QuickTime    @tab  X  @tab  X
- at item ADPCM IMA Simon & Schuster Interactive   @tab  @tab  X
+ at item ADPCM IMA Simon & Schuster Interactive   @tab  X  @tab  X
 @item ADPCM IMA Ubisoft APM  @tab     @tab X
 @item ADPCM IMA Loki SDL MJPEG  @tab     @tab  X
 @item ADPCM IMA WAV          @tab  X  @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c1c9a44f2b..0c46396ae0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -851,6 +851,7 @@ OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER)       += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER)       += adpcmenc.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_RAD_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_SSI_DECODER)      += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_SSI_ENCODER)      += adpcmenc.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER)   += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER)      += adpcmenc.o adpcm_data.o
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 668939c778..1d6ea798a9 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -77,6 +77,15 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
+    if (avctx->trellis && avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI) {
+        /*
+         * Trellis sort-of works, but has some DC offset problems.
+         * Disable it until I can figure out why.
+         */
+        av_log(avctx, AV_LOG_ERROR, "trellis not supported\n");
+        return AVERROR(EINVAL);
+    }
+
     if (avctx->trellis) {
         int frontier  = 1 << avctx->trellis;
         int max_paths =  frontier * FREEZE_INTERVAL;
@@ -139,6 +148,10 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         }
         avctx->frame_size = 512 * (avctx->sample_rate / 11025);
         break;
+    case AV_CODEC_ID_ADPCM_IMA_SSI:
+        avctx->frame_size = BLKSIZE;
+        avctx->block_align = BLKSIZE;
+        break;
     default:
         ret = AVERROR(EINVAL);
         goto error;
@@ -568,6 +581,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         flush_put_bits(&pb);
         break;
     }
+    case AV_CODEC_ID_ADPCM_IMA_SSI:
+    {
+        PutBitContext pb;
+        init_put_bits(&pb, dst, pkt_size);
+
+        av_assert0(avctx->trellis == 0);
+
+        for (i = 0; i < frame->nb_samples; i++) {
+            for (ch = 0; ch < avctx->channels; ch++) {
+                put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++));
+            }
+        }
+
+        flush_put_bits(&pb);
+        break;
+    }
     case AV_CODEC_ID_ADPCM_SWF:
     {
         PutBitContext pb;
@@ -720,6 +749,7 @@ AVCodec ff_ ## name_ ## _encoder = {                        \
 }
 
 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT,  adpcm_ima_qt,  sample_fmts_p, "ADPCM IMA QuickTime");
+ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts,   "ADPCM IMA Simon & Schuster Interactive");
 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, "ADPCM IMA WAV");
 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_MS,      adpcm_ms,      sample_fmts,   "ADPCM Microsoft");
 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_SWF,     adpcm_swf,     sample_fmts,   "ADPCM Shockwave Flash");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b3184af954..8dd02f2f8a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -616,6 +616,7 @@ extern AVCodec ff_adpcm_ima_qt_encoder;
 extern AVCodec ff_adpcm_ima_qt_decoder;
 extern AVCodec ff_adpcm_ima_rad_decoder;
 extern AVCodec ff_adpcm_ima_ssi_decoder;
+extern AVCodec ff_adpcm_ima_ssi_encoder;
 extern AVCodec ff_adpcm_ima_smjpeg_decoder;
 extern AVCodec ff_adpcm_ima_wav_encoder;
 extern AVCodec ff_adpcm_ima_wav_decoder;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4ab8cff4f5..b297eb3552 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1463,6 +1463,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
     case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
     case AV_CODEC_ID_ADPCM_IMA_OKI:
     case AV_CODEC_ID_ADPCM_IMA_WS:
+    case AV_CODEC_ID_ADPCM_IMA_SSI:
     case AV_CODEC_ID_ADPCM_G722:
     case AV_CODEC_ID_ADPCM_YAMAHA:
     case AV_CODEC_ID_ADPCM_AICA:
diff --git a/libavcodec/version.h b/libavcodec/version.h
index f4d1d4de21..e62d1a7925 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  77
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR  78
+#define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
2.17.1




More information about the ffmpeg-devel mailing list