History

avcodec: add adpcm_ima_apm encoder

Zane van Iperen committed 6 years ago

Commit 80dda801 parent 8598fc47 files · +38 −4Browse files

Unified · Split

7 files
  1. Changelog +1 −0
  2. doc/general.texi +1 −1
  3. libavcodec/Makefile +1 −0
  4. libavcodec/adpcmenc.c +32 −2
  5. libavcodec/allcodecs.c +1 −0
  6. libavcodec/utils.c +1 −0
  7. libavcodec/version.h +1 −1
Changelog+1−0
@@ -7,6 +7,7 @@ version <next>: · 6 unmodified lines
77 - PGX decoder
88 - chromanr video filter
99 - VDPAU accelerated HEVC 10/12bit decoding
10+- ADPCM IMA Ubisoft APM encoder
1011
1112
1213 version 4.3:
doc/general.texi+1−1
@@ -1113,7 +1113,7 @@ following image formats are supported: · 1112 unmodified lines
11131113 @item ADPCM IMA High Voltage Software ALP @tab @tab X
11141114 @item ADPCM IMA QuickTime @tab X @tab X
11151115 @item ADPCM IMA Simon & Schuster Interactive @tab X @tab X
1116−@item ADPCM IMA Ubisoft APM @tab @tab X
1116+@item ADPCM IMA Ubisoft APM @tab X @tab X
11171117 @item ADPCM IMA Loki SDL MJPEG @tab @tab X
11181118 @item ADPCM IMA WAV @tab X @tab X
11191119 @item ADPCM IMA Westwood @tab @tab X
libavcodec/Makefile+1−0
@@ -854,6 +854,7 @@ OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o adpcm_data.o · 853 unmodified lines
854854 OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER) += adpcm.o adpcm_data.o
855855 OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER) += adpcm.o adpcm_data.o
856856 OBJS-$(CONFIG_ADPCM_IMA_APM_DECODER) += adpcm.o adpcm_data.o
857+OBJS-$(CONFIG_ADPCM_IMA_APM_ENCODER) += adpcmenc.o adpcm_data.o
857858 OBJS-$(CONFIG_ADPCM_IMA_CUNNING_DECODER) += adpcm.o adpcm_data.o
858859 OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER) += adpcm.o adpcm_data.o
859860 OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o adpcm_data.o
libavcodec/adpcmenc.c+32−2
@@ -74,7 +74,9 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 73 unmodified lines
7474 return AVERROR(EINVAL);
7575 }
7676
77− if (avctx->trellis && avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI) {
77+ if (avctx->trellis &&
78+ (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI ||
79+ avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_APM)) {
7880 /*
7981 * The current trellis implementation doesn't work for extended
8082 * runs of samples without periodic resets. Disallow it.
@@ -145,6 +147,14 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 64 unmodified lines
145147 avctx->frame_size = BLKSIZE * 2 / avctx->channels;
146148 avctx->block_align = BLKSIZE;
147149 break;
150+ case AV_CODEC_ID_ADPCM_IMA_APM:
151+ avctx->frame_size = BLKSIZE * 2 / avctx->channels;
152+ avctx->block_align = BLKSIZE;
153+
154+ if (!(avctx->extradata = av_mallocz(28 + AV_INPUT_BUFFER_PADDING_SIZE)))
155+ return AVERROR(ENOMEM);
156+ avctx->extradata_size = 28;
157+ break;
148158 default:
149159 return AVERROR(EINVAL);
150160 }
@@ -486,7 +496,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 335 unmodified lines
486496
487497 if (avctx->codec_id == AV_CODEC_ID_ADPCM_SWF)
488498 pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8;
489− else if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI)
499+ else if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI ||
500+ avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM)
490501 pkt_size = (frame->nb_samples * avctx->channels) / 2;
491502 else
492503 pkt_size = avctx->block_align;
@@ -711,6 +722,24 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 218 unmodified lines
711722 *dst++ = nibble;
712723 }
713724 break;
725+ case AV_CODEC_ID_ADPCM_IMA_APM:
726+ {
727+ PutBitContext pb;
728+ init_put_bits(&pb, dst, pkt_size);
729+
730+ av_assert0(avctx->trellis == 0);
731+
732+ for (n = frame->nb_samples / 2; n > 0; n--) {
733+ for (ch = 0; ch < avctx->channels; ch++) {
734+ put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++));
735+ put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, samples[st]));
736+ }
737+ samples += avctx->channels;
738+ }
739+
740+ flush_put_bits(&pb);
741+ break;
742+ }
714743 default:
715744 return AVERROR(EINVAL);
716745 }
@@ -743,6 +772,7 @@ AVCodec ff_ ## name_ ## _encoder = { \ · 26 unmodified lines
743772 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
744773 }
745774
775+ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_APM, adpcm_ima_apm, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Ubisoft APM");
746776 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, 0, "ADPCM IMA QuickTime");
747777 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive");
748778 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0, "ADPCM IMA WAV");
libavcodec/allcodecs.c+1−0
@@ -608,6 +608,7 @@ extern AVCodec ff_adpcm_ima_amv_decoder; · 607 unmodified lines
608608 extern AVCodec ff_adpcm_ima_alp_decoder;
609609 extern AVCodec ff_adpcm_ima_apc_decoder;
610610 extern AVCodec ff_adpcm_ima_apm_decoder;
611+extern AVCodec ff_adpcm_ima_apm_encoder;
611612 extern AVCodec ff_adpcm_ima_cunning_decoder;
612613 extern AVCodec ff_adpcm_ima_dat4_decoder;
613614 extern AVCodec ff_adpcm_ima_dk3_decoder;
libavcodec/utils.c+1−0
@@ -1481,6 +1481,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id) · 1480 unmodified lines
14811481 case AV_CODEC_ID_8SVX_FIB:
14821482 case AV_CODEC_ID_ADPCM_CT:
14831483 case AV_CODEC_ID_ADPCM_IMA_APC:
1484+ case AV_CODEC_ID_ADPCM_IMA_APM:
14841485 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
14851486 case AV_CODEC_ID_ADPCM_IMA_OKI:
14861487 case AV_CODEC_ID_ADPCM_IMA_WS:
libavcodec/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVCODEC_VERSION_MAJOR 58
31−#define LIBAVCODEC_VERSION_MINOR 96
31+#define LIBAVCODEC_VERSION_MINOR 97
3232 #define LIBAVCODEC_VERSION_MICRO 100
3333
3434 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t