* [FFmpeg-devel] [PATCH 1/7] avutil/frame: Always return error upon error
@ 2025-06-03 18:08 Andreas Rheinhardt
2025-06-05 16:49 ` Andreas Rheinhardt
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-06-03 18:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 29 bytes --]
Patches attached.
- Andreas
[-- Attachment #2: 0001-avutil-frame-Always-return-error-upon-error.patch --]
[-- Type: text/x-patch, Size: 1273 bytes --]
From 94466f8cd58e9a457cf7249d5907d99c80ba5d57 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 16:44:08 +0200
Subject: [PATCH 1/7] avutil/frame: Always return error upon error
(I don't know whether this can be triggered for a file with
nonnegative channel count, given that src's extended data can't
have been allocated in this case.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/frame.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index dcfc835626..569059c45c 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -456,14 +456,11 @@ int av_frame_replace(AVFrame *dst, const AVFrame *src)
if (src->extended_data != src->data) {
int ch = dst->ch_layout.nb_channels;
- if (!ch) {
+ if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
ret = AVERROR(EINVAL);
goto fail;
}
- if (ch > SIZE_MAX / sizeof(*dst->extended_data))
- goto fail;
-
dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
if (!dst->extended_data) {
ret = AVERROR(ENOMEM);
--
2.45.2
[-- Attachment #3: 0002-avutil-frame-Use-av_memdup-for-duplicating-extended-.patch --]
[-- Type: text/x-patch, Size: 1536 bytes --]
From 74f866d9eee4092fcb46aea10efdf90e7f1cec9a Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 16:52:49 +0200
Subject: [PATCH 2/7] avutil/frame: Use av_memdup() for duplicating extended
data array
Just do it like av_frame_replace().
Also "fixes" the swapped order or arguments to av_malloc_array()
(the first is supposed to be the number of elements, the second
the size of an element) and therefore part of ticket #11620.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/frame.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 569059c45c..13141f143e 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -348,17 +348,16 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
if (src->extended_data != src->data) {
int ch = dst->ch_layout.nb_channels;
- if (!ch) {
+ if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
ret = AVERROR(EINVAL);
goto fail;
}
- dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
+ dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
if (!dst->extended_data) {
ret = AVERROR(ENOMEM);
goto fail;
}
- memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
} else
dst->extended_data = dst->data;
--
2.45.2
[-- Attachment #4: 0003-avcodec-psymodel-Use-av_memdup-where-appropriate.patch --]
[-- Type: text/x-patch, Size: 1866 bytes --]
From dfee7c0ea337e8bafadf2c5d55c7c80d9ddee175 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 17:19:48 +0200
Subject: [PATCH 3/7] avcodec/psymodel: Use av_memdup() where appropriate
Also "fixes" the inverted order of arguments in the av_malloc_array()
calls and therefore part of ticket #11620.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/psymodel.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index 890b13e1c8..1720e9b09b 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -37,8 +37,8 @@ av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
ctx->avctx = avctx;
ctx->ch = av_calloc(avctx->ch_layout.nb_channels, 2 * sizeof(ctx->ch[0]));
ctx->group = av_calloc(num_groups, sizeof(ctx->group[0]));
- ctx->bands = av_malloc_array (sizeof(ctx->bands[0]), num_lens);
- ctx->num_bands = av_malloc_array (sizeof(ctx->num_bands[0]), num_lens);
+ ctx->bands = av_memdup(bands, num_lens * sizeof(ctx->bands[0]));
+ ctx->num_bands = av_memdup(num_bands, num_lens * sizeof(ctx->num_bands[0]));
ctx->cutoff = avctx->cutoff;
if (!ctx->ch || !ctx->group || !ctx->bands || !ctx->num_bands) {
@@ -46,9 +46,6 @@ av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
return AVERROR(ENOMEM);
}
- memcpy(ctx->bands, bands, sizeof(ctx->bands[0]) * num_lens);
- memcpy(ctx->num_bands, num_bands, sizeof(ctx->num_bands[0]) * num_lens);
-
/* assign channels to groups (with virtual channels for coupling) */
for (i = 0; i < num_groups; i++) {
/* NOTE: Add 1 to handle the AAC chan_config without modification.
--
2.45.2
[-- Attachment #5: 0004-avcodec-iirfilter-Remove-iirfilter-psy-preprocessing.patch --]
[-- Type: text/x-patch, Size: 38358 bytes --]
From ff3dd93ded2280aed8a6210a305929a71d3973fc Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 17:56:00 +0200
Subject: [PATCH 4/7] avcodec/iirfilter: Remove iirfilter, psy-preprocessing
The iirfilter is only used in its test tool since
01ecb7172b684f1c4b3e748f95c5a9a494ca36ec which
stopped using it in AAC, its only user.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 3 +-
doc/mips.txt | 1 -
libavcodec/Makefile | 2 -
libavcodec/aacenc.c | 5 -
libavcodec/aacenc.h | 1 -
libavcodec/iirfilter.c | 326 -------------------------------
libavcodec/iirfilter.h | 116 -----------
libavcodec/mips/Makefile | 1 -
libavcodec/mips/iirfilter_mips.c | 209 --------------------
libavcodec/psymodel.c | 73 -------
libavcodec/tests/.gitignore | 1 -
libavcodec/tests/iirfilter.c | 69 -------
tests/fate/libavcodec.mak | 4 -
13 files changed, 1 insertion(+), 810 deletions(-)
delete mode 100644 libavcodec/iirfilter.c
delete mode 100644 libavcodec/iirfilter.h
delete mode 100644 libavcodec/mips/iirfilter_mips.c
delete mode 100644 libavcodec/tests/iirfilter.c
diff --git a/configure b/configure
index f61128bce6..262e80123e 100755
--- a/configure
+++ b/configure
@@ -2606,7 +2606,6 @@ CONFIG_EXTRA="
iamfdec
iamfenc
idctdsp
- iirfilter
inflate_wrapper
intrax8
iso_media
@@ -2917,7 +2916,7 @@ wmv2dsp_select="qpeldsp"
# decoders / encoders
aac_decoder_select="adts_header mpeg4audio sinewin"
aac_fixed_decoder_select="adts_header mpeg4audio"
-aac_encoder_select="audio_frame_queue iirfilter lpc sinewin"
+aac_encoder_select="audio_frame_queue lpc sinewin"
aac_latm_decoder_select="aac_decoder aac_latm_parser"
ac3_decoder_select="ac3_parser ac3dsp bswapdsp fmtconvert"
ac3_fixed_decoder_select="ac3_parser ac3dsp bswapdsp"
diff --git a/doc/mips.txt b/doc/mips.txt
index a42546f0cd..f7529bd8e7 100644
--- a/doc/mips.txt
+++ b/doc/mips.txt
@@ -60,6 +60,5 @@ Files that have MIPS copyright notice in them:
compute_antialias_float.h
lsp_mips.h
fmtconvert_mips.c
- iirfilter_mips.c
mpegaudiodsp_mips_fixed.c
mpegaudiodsp_mips_float.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb3fb7f7f7..15c69e6290 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -121,7 +121,6 @@ OBJS-$(CONFIG_HUFFMAN) += huffman.o
OBJS-$(CONFIG_HUFFYUVDSP) += huffyuvdsp.o
OBJS-$(CONFIG_HUFFYUVENCDSP) += huffyuvencdsp.o
OBJS-$(CONFIG_IDCTDSP) += idctdsp.o simple_idct.o jrevdct.o
-OBJS-$(CONFIG_IIRFILTER) += iirfilter.o
OBJS-$(CONFIG_INFLATE_WRAPPER) += zlib_wrapper.o
OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o msmpeg4_vc1_data.o
OBJS-$(CONFIG_IVIDSP) += ivi_dsp.o
@@ -1337,7 +1336,6 @@ TESTPROGS-$(CONFIG_AV1_VAAPI_ENCODER) += av1_levels
TESTPROGS-$(CONFIG_CABAC) += cabac
TESTPROGS-$(CONFIG_GOLOMB) += golomb
TESTPROGS-$(CONFIG_IDCTDSP) += dct
-TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
TESTPROGS-$(CONFIG_MJPEG_ENCODER) += mjpegenc_huffman
TESTPROGS-$(HAVE_MMX) += motion
TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index afb4478bfe..b8df8dc530 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -845,8 +845,6 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
copy_input_samples(s, frame);
- if (s->psypp)
- ff_psy_preprocess(s->psypp, s->planar_samples, s->channels);
if (!avctx->frame_num)
return 0;
@@ -1141,8 +1139,6 @@ static av_cold int aac_encode_end(AVCodecContext *avctx)
av_tx_uninit(&s->mdct128);
ff_psy_end(&s->psy);
ff_lpc_end(&s->lpc);
- if (s->psypp)
- ff_psy_preprocess_end(s->psypp);
av_freep(&s->buffer.samples);
av_freep(&s->cpe);
av_freep(&s->fdsp);
@@ -1294,7 +1290,6 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
if ((ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths,
s->chan_map[0], grouping)) < 0)
return ret;
- s->psypp = ff_psy_preprocess_init(avctx);
ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON);
s->random_state = 0x1f2e3d4c;
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index 241d75025a..51a216e6d0 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -199,7 +199,6 @@ typedef struct AACEncContext {
ChannelElement *cpe; ///< channel elements
FFPsyContext psy;
- struct FFPsyPreprocessContext* psypp;
const AACCoefficientsEncoder *coder;
int cur_channel; ///< current channel for coder context
int random_state;
diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
deleted file mode 100644
index cefe35ab6e..0000000000
--- a/libavcodec/iirfilter.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * IIR filter
- * Copyright (c) 2008 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * different IIR filters implementation
- */
-
-#include <math.h>
-
-#include "config.h"
-
-#include "libavutil/attributes.h"
-#include "libavutil/common.h"
-#include "libavutil/log.h"
-#include "libavutil/mem.h"
-
-#include "iirfilter.h"
-
-/**
- * IIR filter global parameters
- */
-typedef struct FFIIRFilterCoeffs {
- int order;
- float gain;
- int *cx;
- float *cy;
-} FFIIRFilterCoeffs;
-
-/**
- * IIR filter state
- */
-typedef struct FFIIRFilterState {
- float x[1];
-} FFIIRFilterState;
-
-/// maximum supported filter order
-#define MAXORDER 30
-
-static av_cold int butterworth_init_coeffs(void *avc,
- struct FFIIRFilterCoeffs *c,
- enum IIRFilterMode filt_mode,
- int order, float cutoff_ratio,
- float stopband)
-{
- int i, j;
- double wa;
- double p[MAXORDER + 1][2];
-
- if (filt_mode != FF_FILTER_MODE_LOWPASS) {
- av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
- "low-pass filter mode\n");
- return -1;
- }
- if (order & 1) {
- av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
- "even filter orders\n");
- return -1;
- }
-
- wa = 2 * tan(M_PI * 0.5 * cutoff_ratio);
-
- c->cx[0] = 1;
- for (i = 1; i < (order >> 1) + 1; i++)
- c->cx[i] = c->cx[i - 1] * (order - i + 1LL) / i;
-
- p[0][0] = 1.0;
- p[0][1] = 0.0;
- for (i = 1; i <= order; i++)
- p[i][0] = p[i][1] = 0.0;
- for (i = 0; i < order; i++) {
- double zp[2];
- double th = (i + (order >> 1) + 0.5) * M_PI / order;
- double a_re, a_im, c_re, c_im;
- zp[0] = cos(th) * wa;
- zp[1] = sin(th) * wa;
- a_re = zp[0] + 2.0;
- c_re = zp[0] - 2.0;
- a_im =
- c_im = zp[1];
- zp[0] = (a_re * c_re + a_im * c_im) / (c_re * c_re + c_im * c_im);
- zp[1] = (a_im * c_re - a_re * c_im) / (c_re * c_re + c_im * c_im);
-
- for (j = order; j >= 1; j--) {
- a_re = p[j][0];
- a_im = p[j][1];
- p[j][0] = a_re * zp[0] - a_im * zp[1] + p[j - 1][0];
- p[j][1] = a_re * zp[1] + a_im * zp[0] + p[j - 1][1];
- }
- a_re = p[0][0] * zp[0] - p[0][1] * zp[1];
- p[0][1] = p[0][0] * zp[1] + p[0][1] * zp[0];
- p[0][0] = a_re;
- }
- c->gain = p[order][0];
- for (i = 0; i < order; i++) {
- c->gain += p[i][0];
- c->cy[i] = (-p[i][0] * p[order][0] + -p[i][1] * p[order][1]) /
- (p[order][0] * p[order][0] + p[order][1] * p[order][1]);
- }
- c->gain /= 1 << order;
-
- return 0;
-}
-
-static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
- enum IIRFilterMode filt_mode, int order,
- float cutoff_ratio, float stopband)
-{
- double cos_w0, sin_w0;
- double a0, x0, x1;
-
- if (filt_mode != FF_FILTER_MODE_HIGHPASS &&
- filt_mode != FF_FILTER_MODE_LOWPASS) {
- av_log(avc, AV_LOG_ERROR, "Biquad filter currently only supports "
- "high-pass and low-pass filter modes\n");
- return -1;
- }
- if (order != 2) {
- av_log(avc, AV_LOG_ERROR, "Biquad filter must have order of 2\n");
- return -1;
- }
-
- cos_w0 = cos(M_PI * cutoff_ratio);
- sin_w0 = sin(M_PI * cutoff_ratio);
-
- a0 = 1.0 + (sin_w0 / 2.0);
-
- if (filt_mode == FF_FILTER_MODE_HIGHPASS) {
- c->gain = ((1.0 + cos_w0) / 2.0) / a0;
- x0 = ((1.0 + cos_w0) / 2.0) / a0;
- x1 = (-(1.0 + cos_w0)) / a0;
- } else { // FF_FILTER_MODE_LOWPASS
- c->gain = ((1.0 - cos_w0) / 2.0) / a0;
- x0 = ((1.0 - cos_w0) / 2.0) / a0;
- x1 = (1.0 - cos_w0) / a0;
- }
- c->cy[0] = (-1.0 + (sin_w0 / 2.0)) / a0;
- c->cy[1] = (2.0 * cos_w0) / a0;
-
- // divide by gain to make the x coeffs integers.
- // during filtering, the delay state will include the gain multiplication
- c->cx[0] = lrintf(x0 / c->gain);
- c->cx[1] = lrintf(x1 / c->gain);
-
- return 0;
-}
-
-av_cold struct FFIIRFilterCoeffs *ff_iir_filter_init_coeffs(void *avc,
- enum IIRFilterType filt_type,
- enum IIRFilterMode filt_mode,
- int order, float cutoff_ratio,
- float stopband, float ripple)
-{
- FFIIRFilterCoeffs *c;
- int ret = 0;
-
- if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0)
- return NULL;
-
- if (!(c = av_mallocz(sizeof(*c))) ||
- !(c->cx = av_malloc (sizeof(c->cx[0]) * ((order >> 1) + 1))) ||
- !(c->cy = av_malloc (sizeof(c->cy[0]) * order)))
- goto free;
- c->order = order;
-
- switch (filt_type) {
- case FF_FILTER_TYPE_BUTTERWORTH:
- ret = butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
- stopband);
- break;
- case FF_FILTER_TYPE_BIQUAD:
- ret = biquad_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
- stopband);
- break;
- default:
- av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n");
- goto free;
- }
-
- if (!ret)
- return c;
-free:
- ff_iir_filter_free_coeffsp(&c);
- return NULL;
-}
-
-av_cold struct FFIIRFilterState *ff_iir_filter_init_state(int order)
-{
- FFIIRFilterState *s = av_mallocz(sizeof(FFIIRFilterState) + sizeof(s->x[0]) * (order - 1));
- return s;
-}
-
-#define CONV_S16(dest, source) dest = av_clip_int16(lrintf(source));
-
-#define CONV_FLT(dest, source) dest = source;
-
-#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt) \
- in = *src0 * c->gain + \
- c->cy[0] * s->x[i0] + \
- c->cy[1] * s->x[i1] + \
- c->cy[2] * s->x[i2] + \
- c->cy[3] * s->x[i3]; \
- res = (s->x[i0] + in) * 1 + \
- (s->x[i1] + s->x[i3]) * 4 + \
- s->x[i2] * 6; \
- CONV_ ## fmt(*dst0, res) \
- s->x[i0] = in; \
- src0 += sstep; \
- dst0 += dstep;
-
-#define FILTER_BW_O4(type, fmt) { \
- int i; \
- const type *src0 = src; \
- type *dst0 = dst; \
- for (i = 0; i < size; i += 4) { \
- float in, res; \
- FILTER_BW_O4_1(0, 1, 2, 3, fmt); \
- FILTER_BW_O4_1(1, 2, 3, 0, fmt); \
- FILTER_BW_O4_1(2, 3, 0, 1, fmt); \
- FILTER_BW_O4_1(3, 0, 1, 2, fmt); \
- } \
-}
-
-#define FILTER_DIRECT_FORM_II(type, fmt) { \
- int i; \
- const type *src0 = src; \
- type *dst0 = dst; \
- for (i = 0; i < size; i++) { \
- int j; \
- float in, res; \
- in = *src0 * c->gain; \
- for (j = 0; j < c->order; j++) \
- in += c->cy[j] * s->x[j]; \
- res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1]; \
- for (j = 1; j < c->order >> 1; j++) \
- res += (s->x[j] + s->x[c->order - j]) * c->cx[j]; \
- for (j = 0; j < c->order - 1; j++) \
- s->x[j] = s->x[j + 1]; \
- CONV_ ## fmt(*dst0, res) \
- s->x[c->order - 1] = in; \
- src0 += sstep; \
- dst0 += dstep; \
- } \
-}
-
-#define FILTER_O2(type, fmt) { \
- int i; \
- const type *src0 = src; \
- type *dst0 = dst; \
- for (i = 0; i < size; i++) { \
- float in = *src0 * c->gain + \
- s->x[0] * c->cy[0] + \
- s->x[1] * c->cy[1]; \
- CONV_ ## fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1]) \
- s->x[0] = s->x[1]; \
- s->x[1] = in; \
- src0 += sstep; \
- dst0 += dstep; \
- } \
-}
-
-/**
- * Perform IIR filtering on floating-point input samples.
- *
- * @param coeffs pointer to filter coefficients
- * @param state pointer to filter state
- * @param size input length
- * @param src source samples
- * @param sstep source stride
- * @param dst filtered samples (destination may be the same as input)
- * @param dstep destination stride
- */
-static void iir_filter_flt(const struct FFIIRFilterCoeffs *c,
- struct FFIIRFilterState *s, int size,
- const float *src, ptrdiff_t sstep,
- float *dst, ptrdiff_t dstep)
-{
- if (c->order == 2) {
- FILTER_O2(float, FLT)
- } else if (c->order == 4) {
- FILTER_BW_O4(float, FLT)
- } else {
- FILTER_DIRECT_FORM_II(float, FLT)
- }
-}
-
-av_cold void ff_iir_filter_free_statep(struct FFIIRFilterState **state)
-{
- av_freep(state);
-}
-
-av_cold void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffsp)
-{
- struct FFIIRFilterCoeffs *coeffs = *coeffsp;
- if (coeffs) {
- av_freep(&coeffs->cx);
- av_freep(&coeffs->cy);
- }
- av_freep(coeffsp);
-}
-
-void ff_iir_filter_init(FFIIRFilterContext *f) {
- f->filter_flt = iir_filter_flt;
-
-#if HAVE_MIPSFPU
- ff_iir_filter_init_mips(f);
-#endif
-}
diff --git a/libavcodec/iirfilter.h b/libavcodec/iirfilter.h
deleted file mode 100644
index 8ab8ae68c6..0000000000
--- a/libavcodec/iirfilter.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * IIR filter
- * Copyright (c) 2008 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * IIR filter interface
- */
-
-#ifndef AVCODEC_IIRFILTER_H
-#define AVCODEC_IIRFILTER_H
-
-#include <stddef.h>
-
-struct FFIIRFilterCoeffs;
-struct FFIIRFilterState;
-
-enum IIRFilterType{
- FF_FILTER_TYPE_BESSEL,
- FF_FILTER_TYPE_BIQUAD,
- FF_FILTER_TYPE_BUTTERWORTH,
- FF_FILTER_TYPE_CHEBYSHEV,
- FF_FILTER_TYPE_ELLIPTIC,
-};
-
-enum IIRFilterMode{
- FF_FILTER_MODE_LOWPASS,
- FF_FILTER_MODE_HIGHPASS,
- FF_FILTER_MODE_BANDPASS,
- FF_FILTER_MODE_BANDSTOP,
-};
-
-typedef struct FFIIRFilterContext {
- /**
- * Perform IIR filtering on floating-point input samples.
- *
- * @param coeffs pointer to filter coefficients
- * @param state pointer to filter state
- * @param size input length
- * @param src source samples
- * @param sstep source stride
- * @param dst filtered samples (destination may be the same as input)
- * @param dstep destination stride
- */
- void (*filter_flt)(const struct FFIIRFilterCoeffs *coeffs,
- struct FFIIRFilterState *state, int size,
- const float *src, ptrdiff_t sstep, float *dst, ptrdiff_t dstep);
-} FFIIRFilterContext;
-
-/**
- * Initialize FFIIRFilterContext
- */
-void ff_iir_filter_init(FFIIRFilterContext *f);
-void ff_iir_filter_init_mips(FFIIRFilterContext *f);
-
-/**
- * Initialize filter coefficients.
- *
- * @param avc a pointer to an arbitrary struct of which the first
- * field is a pointer to an AVClass struct
- * @param filt_type filter type (e.g. Butterworth)
- * @param filt_mode filter mode (e.g. lowpass)
- * @param order filter order
- * @param cutoff_ratio cutoff to input frequency ratio
- * @param stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes)
- * @param ripple ripple factor (used only in Chebyshev filters)
- *
- * @return pointer to filter coefficients structure or NULL if filter cannot be created
- */
-struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
- enum IIRFilterType filt_type,
- enum IIRFilterMode filt_mode,
- int order, float cutoff_ratio,
- float stopband, float ripple);
-
-/**
- * Create new filter state.
- *
- * @param order filter order
- *
- * @return pointer to new filter state or NULL if state creation fails
- */
-struct FFIIRFilterState* ff_iir_filter_init_state(int order);
-
-/**
- * Free filter coefficients.
- *
- * @param coeffs pointer allocated with ff_iir_filter_init_coeffs()
- */
-void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffs);
-
-/**
- * Free and zero filter state.
- *
- * @param state pointer to pointer allocated with ff_iir_filter_init_state()
- */
-void ff_iir_filter_free_statep(struct FFIIRFilterState **state);
-
-#endif /* AVCODEC_IIRFILTER_H */
diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile
index fc1bc6b03f..569d1db4a3 100644
--- a/libavcodec/mips/Makefile
+++ b/libavcodec/mips/Makefile
@@ -14,7 +14,6 @@ MIPSFPU-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_float.o
MIPSDSP-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_fixed.o
MIPSFPU-OBJS-$(CONFIG_FMTCONVERT) += mips/fmtconvert_mips.o
OBJS-$(CONFIG_AC3DSP) += mips/ac3dsp_mips.o
-MIPSFPU-OBJS-$(CONFIG_AAC_ENCODER) += mips/iirfilter_mips.o
OBJS-$(CONFIG_HEVC_DECODER) += mips/hevcdsp_init_mips.o \
mips/hevcpred_init_mips.o
OBJS-$(CONFIG_VP9_DECODER) += mips/vp9dsp_init_mips.o
diff --git a/libavcodec/mips/iirfilter_mips.c b/libavcodec/mips/iirfilter_mips.c
deleted file mode 100644
index 3a1352a7e4..0000000000
--- a/libavcodec/mips/iirfilter_mips.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (c) 2012
- * MIPS Technologies, Inc., California.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Author: Bojan Zivkovic (bojan@mips.com)
- *
- * IIR filter optimized for MIPS floating-point architecture
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
- /**
- * @file
- * Reference: libavcodec/iirfilter.c
- */
-
-#include "config.h"
-#include "libavcodec/iirfilter.h"
-
-#if HAVE_INLINE_ASM
-#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
-typedef struct FFIIRFilterCoeffs {
- int order;
- float gain;
- int *cx;
- float *cy;
-} FFIIRFilterCoeffs;
-
-typedef struct FFIIRFilterState {
- float x[1];
-} FFIIRFilterState;
-
-static void iir_filter_flt_mips(const struct FFIIRFilterCoeffs *c,
- struct FFIIRFilterState *s, int size,
- const float *src, ptrdiff_t sstep, float *dst, ptrdiff_t dstep)
-{
- if (c->order == 2) {
- int i;
- const float *src0 = src;
- float *dst0 = dst;
- for (i = 0; i < size; i++) {
- float in = *src0 * c->gain + s->x[0] * c->cy[0] + s->x[1] * c->cy[1];
- *dst0 = s->x[0] + in + s->x[1] * c->cx[1];
- s->x[0] = s->x[1];
- s->x[1] = in;
- src0 += sstep;
- dst0 += dstep;
- }
- } else if (c->order == 4) {
- int i;
- const float *src0 = src;
- float *dst0 = dst;
- float four = 4.0;
- float six = 6.0;
- for (i = 0; i < size; i += 4) {
- float in1, in2, in3, in4;
- float res1, res2, res3, res4;
- float *x = s->x;
- float *cy = c->cy;
- float gain = c->gain;
- float src0_0 = src0[0 ];
- float src0_1 = src0[sstep ];
- float src0_2 = src0[2*sstep];
- float src0_3 = src0[3*sstep];
-
- __asm__ volatile (
- "lwc1 $f0, 0(%[cy]) \n\t"
- "lwc1 $f4, 0(%[x]) \n\t"
- "lwc1 $f5, 4(%[x]) \n\t"
- "lwc1 $f6, 8(%[x]) \n\t"
- "lwc1 $f7, 12(%[x]) \n\t"
- "mul.s %[in1], %[src0_0], %[gain] \n\t"
- "mul.s %[in2], %[src0_1], %[gain] \n\t"
- "mul.s %[in3], %[src0_2], %[gain] \n\t"
- "mul.s %[in4], %[src0_3], %[gain] \n\t"
- "lwc1 $f1, 4(%[cy]) \n\t"
- "madd.s %[in1], %[in1], $f0, $f4 \n\t"
- "madd.s %[in2], %[in2], $f0, $f5 \n\t"
- "madd.s %[in3], %[in3], $f0, $f6 \n\t"
- "madd.s %[in4], %[in4], $f0, $f7 \n\t"
- "lwc1 $f2, 8(%[cy]) \n\t"
- "madd.s %[in1], %[in1], $f1, $f5 \n\t"
- "madd.s %[in2], %[in2], $f1, $f6 \n\t"
- "madd.s %[in3], %[in3], $f1, $f7 \n\t"
- "lwc1 $f3, 12(%[cy]) \n\t"
- "add.s $f8, $f5, $f7 \n\t"
- "madd.s %[in1], %[in1], $f2, $f6 \n\t"
- "madd.s %[in2], %[in2], $f2, $f7 \n\t"
- "mul.s $f9, $f6, %[six] \n\t"
- "mul.s $f10, $f7, %[six] \n\t"
- "madd.s %[in1], %[in1], $f3, $f7 \n\t"
- "madd.s %[in2], %[in2], $f3, %[in1] \n\t"
- "madd.s %[in3], %[in3], $f2, %[in1] \n\t"
- "madd.s %[in4], %[in4], $f1, %[in1] \n\t"
- "add.s %[res1], $f4, %[in1] \n\t"
- "swc1 %[in1], 0(%[x]) \n\t"
- "add.s $f0, $f6, %[in1] \n\t"
- "madd.s %[in3], %[in3], $f3, %[in2] \n\t"
- "madd.s %[in4], %[in4], $f2, %[in2] \n\t"
- "add.s %[res2], $f5, %[in2] \n\t"
- "madd.s %[res1], %[res1], $f8, %[four] \n\t"
- "add.s $f8, $f7, %[in2] \n\t"
- "swc1 %[in2], 4(%[x]) \n\t"
- "madd.s %[in4], %[in4], $f3, %[in3] \n\t"
- "add.s %[res3], $f6, %[in3] \n\t"
- "add.s %[res1], %[res1], $f9 \n\t"
- "madd.s %[res2], %[res2], $f0, %[four] \n\t"
- "swc1 %[in3], 8(%[x]) \n\t"
- "add.s %[res4], $f7, %[in4] \n\t"
- "madd.s %[res3], %[res3], $f8, %[four] \n\t"
- "swc1 %[in4], 12(%[x]) \n\t"
- "add.s %[res2], %[res2], $f10 \n\t"
- "add.s $f8, %[in1], %[in3] \n\t"
- "madd.s %[res3], %[res3], %[in1], %[six] \n\t"
- "madd.s %[res4], %[res4], $f8, %[four] \n\t"
- "madd.s %[res4], %[res4], %[in2], %[six] \n\t"
-
- : [in1]"=&f"(in1), [in2]"=&f"(in2),
- [in3]"=&f"(in3), [in4]"=&f"(in4),
- [res1]"=&f"(res1), [res2]"=&f"(res2),
- [res3]"=&f"(res3), [res4]"=&f"(res4)
- : [src0_0]"f"(src0_0), [src0_1]"f"(src0_1),
- [src0_2]"f"(src0_2), [src0_3]"f"(src0_3),
- [gain]"f"(gain), [x]"r"(x), [cy]"r"(cy),
- [four]"f"(four), [six]"f"(six)
- : "$f0", "$f1", "$f2", "$f3",
- "$f4", "$f5", "$f6", "$f7",
- "$f8", "$f9", "$f10",
- "memory"
- );
-
- dst0[0 ] = res1;
- dst0[sstep ] = res2;
- dst0[2*sstep] = res3;
- dst0[3*sstep] = res4;
-
- src0 += 4*sstep;
- dst0 += 4*dstep;
- }
- } else {
- int i;
- const float *src0 = src;
- float *dst0 = dst;
- for (i = 0; i < size; i++) {
- int j;
- float in, res;
- in = *src0 * c->gain;
- for(j = 0; j < c->order; j++)
- in += c->cy[j] * s->x[j];
- res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1];
- for(j = 1; j < c->order >> 1; j++)
- res += (s->x[j] + s->x[c->order - j]) * c->cx[j];
- for(j = 0; j < c->order - 1; j++)
- s->x[j] = s->x[j + 1];
- *dst0 = res;
- s->x[c->order - 1] = in;
- src0 += sstep;
- dst0 += dstep;
- }
- }
-}
-#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
-#endif /* HAVE_INLINE_ASM */
-
-void ff_iir_filter_init_mips(FFIIRFilterContext *f) {
-#if HAVE_INLINE_ASM
-#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
- f->filter_flt = iir_filter_flt_mips;
-#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
-#endif /* HAVE_INLINE_ASM */
-}
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index 1720e9b09b..87f7b216cd 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -19,11 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <string.h>
-
#include "avcodec.h"
#include "psymodel.h"
-#include "iirfilter.h"
#include "libavutil/mem.h"
extern const FFPsyModel ff_aac_psy_model;
@@ -86,73 +83,3 @@ av_cold void ff_psy_end(FFPsyContext *ctx)
av_freep(&ctx->group);
av_freep(&ctx->ch);
}
-
-typedef struct FFPsyPreprocessContext{
- AVCodecContext *avctx;
- float stereo_att;
- struct FFIIRFilterCoeffs *fcoeffs;
- struct FFIIRFilterState **fstate;
- struct FFIIRFilterContext fiir;
-}FFPsyPreprocessContext;
-
-#define FILT_ORDER 4
-
-av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *avctx)
-{
- FFPsyPreprocessContext *ctx;
- int i;
- float cutoff_coeff = 0;
- ctx = av_mallocz(sizeof(FFPsyPreprocessContext));
- if (!ctx)
- return NULL;
- ctx->avctx = avctx;
-
- /* AAC has its own LP method */
- if (avctx->codec_id != AV_CODEC_ID_AAC) {
- if (avctx->cutoff > 0)
- cutoff_coeff = 2.0 * avctx->cutoff / avctx->sample_rate;
-
- if (cutoff_coeff && cutoff_coeff < 0.98)
- ctx->fcoeffs = ff_iir_filter_init_coeffs(avctx, FF_FILTER_TYPE_BUTTERWORTH,
- FF_FILTER_MODE_LOWPASS, FILT_ORDER,
- cutoff_coeff, 0.0, 0.0);
- if (ctx->fcoeffs) {
- ctx->fstate = av_calloc(avctx->ch_layout.nb_channels, sizeof(ctx->fstate[0]));
- if (!ctx->fstate) {
- av_free(ctx->fcoeffs);
- av_free(ctx);
- return NULL;
- }
- for (i = 0; i < avctx->ch_layout.nb_channels; i++)
- ctx->fstate[i] = ff_iir_filter_init_state(FILT_ORDER);
- }
- }
-
- ff_iir_filter_init(&ctx->fiir);
-
- return ctx;
-}
-
-void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
-{
- int ch;
- int frame_size = ctx->avctx->frame_size;
- FFIIRFilterContext *iir = &ctx->fiir;
-
- if (ctx->fstate) {
- for (ch = 0; ch < channels; ch++)
- iir->filter_flt(ctx->fcoeffs, ctx->fstate[ch], frame_size,
- &audio[ch][frame_size], 1, &audio[ch][frame_size], 1);
- }
-}
-
-av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
-{
- int i;
- ff_iir_filter_free_coeffsp(&ctx->fcoeffs);
- if (ctx->fstate)
- for (i = 0; i < ctx->avctx->ch_layout.nb_channels; i++)
- ff_iir_filter_free_statep(&ctx->fstate[i]);
- av_freep(&ctx->fstate);
- av_free(ctx);
-}
diff --git a/libavcodec/tests/.gitignore b/libavcodec/tests/.gitignore
index 2c5bbec7f9..29020a5945 100644
--- a/libavcodec/tests/.gitignore
+++ b/libavcodec/tests/.gitignore
@@ -12,7 +12,6 @@
/h264_levels
/h265_levels
/htmlsubtitles
-/iirfilter
/jpeg2000dwt
/mathops
/mjpegenc_huffman
diff --git a/libavcodec/tests/iirfilter.c b/libavcodec/tests/iirfilter.c
deleted file mode 100644
index e03e842b85..0000000000
--- a/libavcodec/tests/iirfilter.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <math.h>
-#include <stdint.h>
-#include <stdio.h>
-
-#include "libavutil/libm.h"
-
-#include "libavcodec/iirfilter.h"
-#include "libavcodec/iirfilter.c"
-
-#define FILT_ORDER 4
-#define SIZE 1024
-
-static void iir_filter_int16(const struct FFIIRFilterCoeffs *c,
- struct FFIIRFilterState *s, int size,
- const int16_t *src, ptrdiff_t sstep,
- int16_t *dst, ptrdiff_t dstep)
-{
- if (c->order == 2) {
- FILTER_O2(int16_t, S16)
- } else if (c->order == 4) {
- FILTER_BW_O4(int16_t, S16)
- } else {
- FILTER_DIRECT_FORM_II(int16_t, S16)
- }
-}
-
-int main(void)
-{
- struct FFIIRFilterCoeffs *fcoeffs = NULL;
- struct FFIIRFilterState *fstate = NULL;
- float cutoff_coeff = 0.4;
- int16_t x[SIZE], y[SIZE];
- int i;
-
- fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH,
- FF_FILTER_MODE_LOWPASS, FILT_ORDER,
- cutoff_coeff, 0.0, 0.0);
- fstate = ff_iir_filter_init_state(FILT_ORDER);
-
- for (i = 0; i < SIZE; i++)
- x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE));
-
- iir_filter_int16(fcoeffs, fstate, SIZE, x, 1, y, 1);
-
- for (i = 0; i < SIZE; i++)
- printf("%6d %6d\n", x[i], y[i]);
-
- ff_iir_filter_free_coeffsp(&fcoeffs);
- ff_iir_filter_free_statep(&fstate);
- return 0;
-}
diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
index b69ad53f7c..2fc5c7f8b4 100644
--- a/tests/fate/libavcodec.mak
+++ b/tests/fate/libavcodec.mak
@@ -76,10 +76,6 @@ fate-h265-levels: libavcodec/tests/h265_levels$(EXESUF)
fate-h265-levels: CMD = run libavcodec/tests/h265_levels$(EXESUF)
fate-h265-levels: REF = /dev/null
-FATE_LIBAVCODEC-$(CONFIG_IIRFILTER) += fate-iirfilter
-fate-iirfilter: libavcodec/tests/iirfilter$(EXESUF)
-fate-iirfilter: CMD = run libavcodec/tests/iirfilter$(EXESUF)
-
FATE_LIBAVCODEC-$(CONFIG_MPEGVIDEO) += fate-mpeg12framerate
fate-mpeg12framerate: libavcodec/tests/mpeg12framerate$(EXESUF)
fate-mpeg12framerate: CMD = run libavcodec/tests/mpeg12framerate$(EXESUF)
--
2.45.2
[-- Attachment #6: 0005-avcodec-aacpsy-Remove-always-true-checks.patch --]
[-- Type: text/x-patch, Size: 1440 bytes --]
From edf6cc08480fa8be116009b45530add2573225dc Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 18:17:51 +0200
Subject: [PATCH 5/7] avcodec/aacpsy: Remove always-true checks
Possible since 03cf10164578aed33f4d0cb5b69d63669c01a538.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacpsy.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 019be09fa3..ac7ae5b28d 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -593,7 +593,6 @@ static float calc_reduced_thr_3gpp(AacPsyBand *band, float min_snr,
return thr;
}
-#ifndef calc_thr_3gpp
static void calc_thr_3gpp(const FFPsyWindowInfo *wi, const int num_bands, AacPsyChannel *pch,
const uint8_t *band_sizes, const float *coefs, const int cutoff)
{
@@ -622,9 +621,7 @@ static void calc_thr_3gpp(const FFPsyWindowInfo *wi, const int num_bands, AacPsy
}
}
}
-#endif /* calc_thr_3gpp */
-#ifndef psy_hp_filter
static void psy_hp_filter(const float *firbuf, float *hpfsmpl, const float *psy_fir_coeffs)
{
int i, j;
@@ -641,7 +638,6 @@ static void psy_hp_filter(const float *firbuf, float *hpfsmpl, const float *psy_
hpfsmpl[i] = (sum1 + sum2) * 32768.0f;
}
}
-#endif /* psy_hp_filter */
/**
* Calculate band thresholds as suggested in 3GPP TS26.403
--
2.45.2
[-- Attachment #7: 0006-avcodec-huffman-Combine-allocations.patch --]
[-- Type: text/x-patch, Size: 2240 bytes --]
From ae342c5f78003b80b3c94d3f5f9fdaba6b735f69 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 19:52:18 +0200
Subject: [PATCH 6/7] avcodec/huffman: Combine allocations
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/huffman.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/libavcodec/huffman.c b/libavcodec/huffman.c
index 0de3097a82..0c2d0c27e1 100644
--- a/libavcodec/huffman.c
+++ b/libavcodec/huffman.c
@@ -39,7 +39,10 @@
#define HNODE -1
typedef struct HeapElem {
- uint64_t val;
+ union {
+ uint64_t val;
+ uint16_t dummy; // exists solely to ensure alignof(HeapElem) >= alignof(uint16_t)
+ };
int name;
} HeapElem;
@@ -59,19 +62,23 @@ static void heap_sift(HeapElem *h, int root, int size)
int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int stats_size, int skip0)
{
- HeapElem *h = av_malloc_array(sizeof(*h), stats_size);
- int *up = av_malloc_array(sizeof(*up) * 2, stats_size);
- uint8_t *len = av_malloc_array(sizeof(*len) * 2, stats_size);
- uint16_t *map= av_malloc_array(sizeof(*map), stats_size);
+ int *up;
+ uint16_t *map;
+ uint8_t *len;
+ HeapElem *h = av_malloc_array(stats_size,
+ sizeof(*h) + 2 * sizeof(up) + 2 * sizeof(len) + sizeof(map));
+ if (!h)
+ return AVERROR(ENOMEM);
+ up = (int*)(h + stats_size);
+ // map is suitably aligned because up uses an even number of elements
+ // and alignof(uint16_t) is either 1 or 2.
+ map = (uint16_t*)(up + 2 * stats_size);
+ len = (uint8_t*)(map + stats_size);
+
int offset, i, next;
int size = 0;
int ret = 0;
- if (!h || !up || !len || !map) {
- ret = AVERROR(ENOMEM);
- goto end;
- }
-
for (i = 0; i<stats_size; i++) {
dst[i] = 255;
if (stats[i] || !skip0)
@@ -107,11 +114,7 @@ int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int stats_size, i
}
if (i==size) break;
}
-end:
av_free(h);
- av_free(up);
- av_free(len);
- av_free(map);
return ret;
}
--
2.45.2
[-- Attachment #8: 0007-avutil-frame-Fix-av_realloc_array-argument-order.patch --]
[-- Type: text/x-patch, Size: 1188 bytes --]
From 111eab871915ed0f8446ac67a9c03e8511ab7dbb Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 3 Jun 2025 19:57:38 +0200
Subject: [PATCH 7/7] avutil/frame: Fix av_realloc_array() argument order
This is not a real bug, but mostly cosmetic. Fixes ticket #11620.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/frame.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 13141f143e..8f3fda2371 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -421,8 +421,8 @@ int av_frame_replace(AVFrame *dst, const AVFrame *src)
for (int i = nb_extended_buf; i < dst->nb_extended_buf; i++)
av_buffer_unref(&dst->extended_buf[i]);
- tmp = av_realloc_array(dst->extended_buf, sizeof(*dst->extended_buf),
- src->nb_extended_buf);
+ tmp = av_realloc_array(dst->extended_buf, src->nb_extended_buf,
+ sizeof(*dst->extended_buf));
if (!tmp) {
ret = AVERROR(ENOMEM);
goto fail;
--
2.45.2
[-- Attachment #9: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/7] avutil/frame: Always return error upon error
2025-06-03 18:08 [FFmpeg-devel] [PATCH 1/7] avutil/frame: Always return error upon error Andreas Rheinhardt
@ 2025-06-05 16:49 ` Andreas Rheinhardt
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-06-05 16:49 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> Patches attached.
>
> - Andreas
>
Will apply this patchset tomorrow unless there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-05 16:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-03 18:08 [FFmpeg-devel] [PATCH 1/7] avutil/frame: Always return error upon error Andreas Rheinhardt
2025-06-05 16:49 ` Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git