diff options
author | Zane van Iperen <zane@zanevaniperen.com> | 2020-05-16 11:53:36 +0000 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2020-05-27 22:13:39 +0200 |
commit | b1189c1571321626b2777bd04f81b3e237f8210b (patch) | |
tree | 6788a111c395289627ff517a5c5c9dd3e424524a /libavcodec | |
parent | 908199802af608ae4ea79b3ee854b28b64018a06 (diff) | |
download | ffmpeg-b1189c1571321626b2777bd04f81b3e237f8210b.tar.gz |
avcodec: add adpcm_ima_ssi encoder
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/Makefile | 1 | ||||
-rw-r--r-- | libavcodec/adpcmenc.c | 32 | ||||
-rw-r--r-- | libavcodec/allcodecs.c | 1 | ||||
-rw-r--r-- | libavcodec/utils.c | 1 | ||||
-rw-r--r-- | libavcodec/version.h | 2 |
5 files changed, 36 insertions, 1 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 6d816308c7..d0917a656f 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -865,6 +865,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 a514c2ffa7..6a5f50568c 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) { + /* + * The current trellis implementation doesn't work for extended + * runs of samples without periodic resets. Disallow it. + */ + av_log(avctx, AV_LOG_ERROR, "trellis not supported\n"); + return AVERROR_PATCHWELCOME; + } + 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 * 2 / avctx->channels; + avctx->block_align = BLKSIZE; + break; default: ret = AVERROR(EINVAL); goto error; @@ -483,6 +496,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (avctx->codec_id == AV_CODEC_ID_ADPCM_SWF) pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8; + else if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI) + pkt_size = (frame->nb_samples * avctx->channels) / 2; else pkt_size = avctx->block_align; if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0) @@ -567,6 +582,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; @@ -721,6 +752,7 @@ AVCodec ff_ ## name_ ## _encoder = { \ } ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, 0, "ADPCM IMA QuickTime"); +ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0, "ADPCM IMA WAV"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_MS, adpcm_ms, sample_fmts, 0, "ADPCM Microsoft"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_SWF, adpcm_swf, sample_fmts, 0, "ADPCM Shockwave Flash"); diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index eb5044f80e..5899eee5ee 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -619,6 +619,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 3899a13b99..a9c69e30dd 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1475,6 +1475,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 2d2cc69ab6..91002dc0b9 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 88 +#define LIBAVCODEC_VERSION_MINOR 89 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |