diff options
author | Zane van Iperen <zane@zanevaniperen.com> | 2020-05-27 00:17:59 +1000 |
---|---|---|
committer | Zane van Iperen <zane@zanevaniperen.com> | 2020-07-21 11:36:14 +1000 |
commit | 80dda809811ea68cc7d7e4064b51fc433c54384e (patch) | |
tree | fb2e96dd98c5b348736ea2f836142e30d7f93be9 /libavcodec | |
parent | 8598fc4010dc49ffdb360a844c4f60dc7d8cef15 (diff) | |
download | ffmpeg-80dda809811ea68cc7d7e4064b51fc433c54384e.tar.gz |
avcodec: add adpcm_ima_apm encoder
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/Makefile | 1 | ||||
-rw-r--r-- | libavcodec/adpcmenc.c | 34 | ||||
-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, 3 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 18353da549..c48138d0ad 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -854,6 +854,7 @@ OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_APM_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_IMA_APM_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_CUNNING_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o adpcm_data.o diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 1e94ef4047..4985abb163 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -74,7 +74,9 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (avctx->trellis && avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI) { + if (avctx->trellis && + (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI || + avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_APM)) { /* * The current trellis implementation doesn't work for extended * runs of samples without periodic resets. Disallow it. @@ -145,6 +147,14 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->frame_size = BLKSIZE * 2 / avctx->channels; avctx->block_align = BLKSIZE; break; + case AV_CODEC_ID_ADPCM_IMA_APM: + avctx->frame_size = BLKSIZE * 2 / avctx->channels; + avctx->block_align = BLKSIZE; + + if (!(avctx->extradata = av_mallocz(28 + AV_INPUT_BUFFER_PADDING_SIZE))) + return AVERROR(ENOMEM); + avctx->extradata_size = 28; + break; default: return AVERROR(EINVAL); } @@ -486,7 +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) + else if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI || + avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM) pkt_size = (frame->nb_samples * avctx->channels) / 2; else pkt_size = avctx->block_align; @@ -711,6 +722,24 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, *dst++ = nibble; } break; + case AV_CODEC_ID_ADPCM_IMA_APM: + { + PutBitContext pb; + init_put_bits(&pb, dst, pkt_size); + + av_assert0(avctx->trellis == 0); + + for (n = frame->nb_samples / 2; n > 0; n--) { + for (ch = 0; ch < avctx->channels; ch++) { + put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++)); + put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, samples[st])); + } + samples += avctx->channels; + } + + flush_put_bits(&pb); + break; + } default: return AVERROR(EINVAL); } @@ -743,6 +772,7 @@ AVCodec ff_ ## name_ ## _encoder = { \ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \ } +ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_APM, adpcm_ima_apm, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Ubisoft APM"); 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"); diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index a5048290f7..7a941b257e 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -608,6 +608,7 @@ extern AVCodec ff_adpcm_ima_amv_decoder; extern AVCodec ff_adpcm_ima_alp_decoder; extern AVCodec ff_adpcm_ima_apc_decoder; extern AVCodec ff_adpcm_ima_apm_decoder; +extern AVCodec ff_adpcm_ima_apm_encoder; extern AVCodec ff_adpcm_ima_cunning_decoder; extern AVCodec ff_adpcm_ima_dat4_decoder; extern AVCodec ff_adpcm_ima_dk3_decoder; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 2ece34f921..a379d62802 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1481,6 +1481,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id) case AV_CODEC_ID_8SVX_FIB: case AV_CODEC_ID_ADPCM_CT: case AV_CODEC_ID_ADPCM_IMA_APC: + case AV_CODEC_ID_ADPCM_IMA_APM: case AV_CODEC_ID_ADPCM_IMA_EA_SEAD: case AV_CODEC_ID_ADPCM_IMA_OKI: case AV_CODEC_ID_ADPCM_IMA_WS: diff --git a/libavcodec/version.h b/libavcodec/version.h index ad0bfd619d..d5dca8cbda 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 96 +#define LIBAVCODEC_VERSION_MINOR 97 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |