From patchwork Thu Apr 1 11:34:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 26679 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 46E9A44BC08 for ; Thu, 1 Apr 2021 14:35:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 19D1D68A601; Thu, 1 Apr 2021 14:35:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66A0C680282 for ; Thu, 1 Apr 2021 14:35:02 +0300 (EEST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=key1; t=1617276901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YCDq/UCQVDt18nWbzv7ByazUfnYSKHEON51UAudJ7Xk=; b=D6Q72Oe7aaRaVEZjNC2x4X3D2MmbpTz+HNnrINU8spHHXftgxZrrceSkSnF51kx0meW0ig 5X5Y/rKMpBHQLkUpFbcbyJuvdpQ5LfRzFGTyKWMmXdMwhtiTw8rAoH+GWh9uWnjsdcsLWl JRwW+TnzG/Bv+Bj1NnjQm03wgqo41visiETCvsAC+i/V7Tu5IPMI82s0AezWAdC6BN0wjl EWTUVSw8NkuMiEwxPw0LZWyH7T4QufUsLhUXkUltz6tCxLM3e6bPpzTf2Gz7QlRr6wS16D xtHgKk6bCZzlN9efr7t9mh9Hyp9OoqVtXaw6N+3KrZqrNkCeJF8vXK2buMAJ8w== From: Zane van Iperen To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 21:34:47 +1000 Message-Id: <20210401113449.12680-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: git-morningstar@zanevaniperen.com Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/adpcmenc: don't share a single AVClass between multiple AVCodecs. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Temporary fix until AVClass::child_class_next is gone. Signed-off-by: Zane van Iperen --- libavcodec/adpcmenc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 78600735cf..58308dae47 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -959,14 +959,14 @@ static const AVOption options[] = { { NULL } }; -static const AVClass adpcm_encoder_class = { - .class_name = "ADPCM Encoder", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; - #define ADPCM_ENCODER(id_, name_, sample_fmts_, capabilities_, long_name_) \ +static const AVClass name_ ## _encoder_class = { \ + .class_name = #name_, \ + .item_name = av_default_item_name, \ + .option = options, \ + .version = LIBAVUTIL_VERSION_INT, \ +}; \ + \ AVCodec ff_ ## name_ ## _encoder = { \ .name = #name_, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ @@ -979,7 +979,7 @@ AVCodec ff_ ## name_ ## _encoder = { \ .sample_fmts = sample_fmts_, \ .capabilities = capabilities_, \ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, \ - .priv_class = &adpcm_encoder_class, \ + .priv_class = &name_ ## _encoder_class, \ } ADPCM_ENCODER(AV_CODEC_ID_ADPCM_ARGO, adpcm_argo, sample_fmts_p, 0, "ADPCM Argonaut Games"); From patchwork Thu Apr 1 11:34:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 26680 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 43FD344BC08 for ; Thu, 1 Apr 2021 14:35:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 333B168A6B5; Thu, 1 Apr 2021 14:35:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C902687F1A for ; Thu, 1 Apr 2021 14:35:03 +0300 (EEST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=key1; t=1617276903; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1kUBdegF7mBGoBA42pa6h/vrQJucOl5FEvLwoU5scgw=; b=FLl73OChzukq4yZn+jsO/MrguYj3hrnsliD35LWCUkY6ZM1rsNK1SFSkhrHUb5/DEmYaBo u2ySeKPptkrmrwrMx6Wmc9bUf0Y3c5kWxMwjuMMCZ/N8h8bsVFqDrhcP/ik4Nv7SZG+Utb wsbOvfZJK451eS+uSKsSrBK9XO+Yjc8rnnJO+vxHA9s/1MIK2Ljr5pks8WqtMemMx5xNE/ nlsmhkdfz3EcpQ/md+Qy88OTFNoehSpLno46HJFCaWt2y1aHgqLzFSW37V1k/cfvK1P+6G jMlZHaFZym1Qz+D5Bnxc/IM6PgR0XjLpHSvJmotGajhRyoby18dSrkRmjf2hrA== From: Zane van Iperen To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 21:34:48 +1000 Message-Id: <20210401113449.12680-2-zane@zanevaniperen.com> In-Reply-To: <20210401113449.12680-1-zane@zanevaniperen.com> References: <20210401113449.12680-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: git-morningstar@zanevaniperen.com Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/adpcm_swf: remove memory allocation during trellis encoding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The block size is hardcoded, so the buffer size is always known. Statically allocate the buffer on the stack. Signed-off-by: Zane van Iperen --- libavcodec/adpcmenc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 58308dae47..9dc77d519a 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -722,6 +722,9 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, n = frame->nb_samples - 1; + /* NB: This is safe as we don't have AV_CODEC_CAP_SMALL_LAST_FRAME. */ + av_assert0(n == 4095); + // store AdpcmCodeSize put_bits(&pb, 2, 2); // set 4-bit flash adpcm format @@ -735,8 +738,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } if (avctx->trellis > 0) { - if (!(buf = av_malloc(2 * n))) - return AVERROR(ENOMEM); + uint8_t buf[8190 /* = 2 * n */]; adpcm_compress_trellis(avctx, samples + avctx->channels, buf, &c->status[0], n, avctx->channels); if (avctx->channels == 2) @@ -748,7 +750,6 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (avctx->channels == 2) put_bits(&pb, 4, buf[n + i]); } - av_free(buf); } else { for (i = 1; i < frame->nb_samples; i++) { put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], From patchwork Thu Apr 1 11:34:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 26681 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3D07744BC08 for ; Thu, 1 Apr 2021 14:35:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2497568A6EB; Thu, 1 Apr 2021 14:35:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DFB468A682 for ; Thu, 1 Apr 2021 14:35:05 +0300 (EEST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=key1; t=1617276904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HgOQsiO5ki9EzycQcdnYdZV37hoS+8mTNoHcFiNyT7M=; b=Q4uqnsGq7YiDjQnsN9rEMbBCXL+hMjdnUeBY3JyDTVC88chest/2XfbvV2D4HiywPQ6yfP OR8EUumCDPWflZasP6/MfoZtlazHbeH4oIObkcFO+eHSqUekhdwM4UGNVmNiKahoh4sk/J PhL1fVqdMkrxggWBTXyIS+SIWYY9H9aeoKbUrfeOncA+solxylj/ACtFKnWgvgnGE7fBRq sHnof1DVW8odSyByAbCWS/dBuXiyZuLJpSPEFPyxk4vSXRHyZnUmkOO+zLWdJ6+EdjJhbE 4rKx+gBR9TQ2gn8JsQBA94xInjXd9MeC8oWg/rY1y1X4akoa2dznkGilnWP0xw== From: Zane van Iperen To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 21:34:49 +1000 Message-Id: <20210401113449.12680-3-zane@zanevaniperen.com> In-Reply-To: <20210401113449.12680-1-zane@zanevaniperen.com> References: <20210401113449.12680-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: git-morningstar@zanevaniperen.com Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/adpcm: refactor init/flush code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Most of the codecs just need everything zeroed. Those that don't are either handled inline during decode, or pull state from extradata. Move state reset/init functionality into adpcm_flush(), and invoke it from adpcm_decode_init(). Signed-off-by: Zane van Iperen --- libavcodec/adpcm.c | 71 +++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 8aab07e334..be14607eac 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -103,6 +103,8 @@ typedef struct ADPCMDecodeContext { int has_status; /**< Status flag. Reset to 0 after a flush. */ } ADPCMDecodeContext; +static void adpcm_flush(AVCodecContext *avctx); + static av_cold int adpcm_decode_init(AVCodecContext * avctx) { ADPCMDecodeContext *c = avctx->priv_data; @@ -150,38 +152,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) } switch(avctx->codec->id) { - case AV_CODEC_ID_ADPCM_CT: - c->status[0].step = c->status[1].step = 511; - break; case AV_CODEC_ID_ADPCM_IMA_WAV: if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5) return AVERROR_INVALIDDATA; break; - case AV_CODEC_ID_ADPCM_IMA_APC: - if (avctx->extradata && avctx->extradata_size >= 8) { - c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata ), 18); - c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18); - } - break; - case AV_CODEC_ID_ADPCM_IMA_APM: - if (avctx->extradata) { - if (avctx->extradata_size >= 28) { - c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 16), 18); - c->status[0].step_index = av_clip(AV_RL32(avctx->extradata + 20), 0, 88); - c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18); - c->status[1].step_index = av_clip(AV_RL32(avctx->extradata + 8), 0, 88); - } else if (avctx->extradata_size >= 16) { - c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 0), 18); - c->status[0].step_index = av_clip(AV_RL32(avctx->extradata + 4), 0, 88); - c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 8), 18); - c->status[1].step_index = av_clip(AV_RL32(avctx->extradata + 12), 0, 88); - } - } - break; - case AV_CODEC_ID_ADPCM_IMA_WS: - if (avctx->extradata && avctx->extradata_size >= 2) - c->vqa_version = AV_RL16(avctx->extradata); - break; case AV_CODEC_ID_ADPCM_ARGO: if (avctx->bits_per_coded_sample != 4 || avctx->block_align != 17 * avctx->channels) return AVERROR_INVALIDDATA; @@ -228,6 +202,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; } + adpcm_flush(avctx); return 0; } @@ -2110,29 +2085,41 @@ static void adpcm_flush(AVCodecContext *avctx) { ADPCMDecodeContext *c = avctx->priv_data; + /* Just nuke the entire state and re-init. */ + memset(c, 0, sizeof(ADPCMDecodeContext)); + switch(avctx->codec_id) { - case AV_CODEC_ID_ADPCM_AICA: - for (int channel = 0; channel < avctx->channels; channel++) - c->status[channel].step = 0; + case AV_CODEC_ID_ADPCM_CT: + c->status[0].step = c->status[1].step = 511; break; - case AV_CODEC_ID_ADPCM_ARGO: - for (int channel = 0; channel < avctx->channels; channel++) { - c->status[channel].sample1 = 0; - c->status[channel].sample2 = 0; + case AV_CODEC_ID_ADPCM_IMA_APC: + if (avctx->extradata && avctx->extradata_size >= 8) { + c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata ), 18); + c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18); } break; - case AV_CODEC_ID_ADPCM_IMA_ALP: - case AV_CODEC_ID_ADPCM_IMA_CUNNING: - case AV_CODEC_ID_ADPCM_IMA_SSI: - case AV_CODEC_ID_ADPCM_ZORK: - for (int channel = 0; channel < avctx->channels; channel++) { - c->status[channel].predictor = 0; - c->status[channel].step_index = 0; + case AV_CODEC_ID_ADPCM_IMA_APM: + if (avctx->extradata) { + if (avctx->extradata_size >= 28) { + c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 16), 18); + c->status[0].step_index = av_clip(AV_RL32(avctx->extradata + 20), 0, 88); + c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18); + c->status[1].step_index = av_clip(AV_RL32(avctx->extradata + 8), 0, 88); + } else if (avctx->extradata_size >= 16) { + c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 0), 18); + c->status[0].step_index = av_clip(AV_RL32(avctx->extradata + 4), 0, 88); + c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 8), 18); + c->status[1].step_index = av_clip(AV_RL32(avctx->extradata + 12), 0, 88); + } } break; + case AV_CODEC_ID_ADPCM_IMA_WS: + if (avctx->extradata && avctx->extradata_size >= 2) + c->vqa_version = AV_RL16(avctx->extradata); + break; default: /* Other codecs may want to handle this during decoding. */ c->has_status = 0;