diff options
author | Paul B Mahol <onemda@gmail.com> | 2022-12-25 00:42:17 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2022-12-25 20:39:54 +0100 |
commit | 64ddf04460bef57021eda60b91e0ce871174c823 (patch) | |
tree | f80b12aac9749c9876f2d71f9f5357cc3c62d3a2 | |
parent | 125e01d6cc111027c0c5f5fe6a787154c9a96006 (diff) | |
download | ffmpeg-64ddf04460bef57021eda60b91e0ce871174c823.tar.gz |
avfilter/af_afir: reduce memory usage
-rw-r--r-- | libavfilter/af_afir.c | 4 | ||||
-rw-r--r-- | libavfilter/af_afir.h | 2 | ||||
-rw-r--r-- | libavfilter/afir_template.c | 14 |
3 files changed, 8 insertions, 12 deletions
diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c index 6790cf3727..f9c18f1c23 100644 --- a/libavfilter/af_afir.c +++ b/libavfilter/af_afir.c @@ -217,7 +217,6 @@ static int init_segment(AVFilterContext *ctx, AudioFIRSegment *seg, seg->sumin = ff_get_audio_buffer(ctx->inputs[0], seg->fft_length); seg->sumout = ff_get_audio_buffer(ctx->inputs[0], seg->fft_length); - seg->blockin = ff_get_audio_buffer(ctx->inputs[0], seg->block_size * seg->nb_partitions); seg->blockout = ff_get_audio_buffer(ctx->inputs[0], seg->block_size * seg->nb_partitions); seg->tempin = ff_get_audio_buffer(ctx->inputs[0], seg->block_size); seg->tempout = ff_get_audio_buffer(ctx->inputs[0], seg->block_size); @@ -226,7 +225,7 @@ static int init_segment(AVFilterContext *ctx, AudioFIRSegment *seg, seg->input = ff_get_audio_buffer(ctx->inputs[0], seg->input_size); seg->output = ff_get_audio_buffer(ctx->inputs[0], seg->part_size); seg->loaded = ff_get_audio_buffer(ctx->inputs[0], seg->nb_partitions); - if (!seg->buffer || !seg->sumin || !seg->sumout || !seg->blockin || !seg->blockout || + if (!seg->buffer || !seg->sumin || !seg->sumout || !seg->blockout || !seg->coeff || !seg->input || !seg->output || !seg->loaded || !seg->tempin || !seg->tempout) return AVERROR(ENOMEM); @@ -261,7 +260,6 @@ static void uninit_segment(AVFilterContext *ctx, AudioFIRSegment *seg) av_frame_free(&seg->tempin); av_frame_free(&seg->tempout); - av_frame_free(&seg->blockin); av_frame_free(&seg->blockout); av_frame_free(&seg->sumin); av_frame_free(&seg->sumout); diff --git a/libavfilter/af_afir.h b/libavfilter/af_afir.h index 3bc6abfef9..21b0cf729e 100644 --- a/libavfilter/af_afir.h +++ b/libavfilter/af_afir.h @@ -37,14 +37,12 @@ typedef struct AudioFIRSegment { int input_size; int input_offset; - int *selir; int *loading; int *output_offset; int *part_index; AVFrame *sumin; AVFrame *sumout; - AVFrame *blockin; AVFrame *blockout; AVFrame *tempin; AVFrame *tempout; diff --git a/libavfilter/afir_template.c b/libavfilter/afir_template.c index ca994f4352..cce0800de9 100644 --- a/libavfilter/afir_template.c +++ b/libavfilter/afir_template.c @@ -314,7 +314,7 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse { AudioFIRContext *s = ctx->priv; const ftype *in = (const ftype *)s->in->extended_data[ch] + offset; - ftype *blockin, *blockout, *buf, *ptr = (ftype *)out->extended_data[ch] + offset; + ftype *blockout, *buf, *ptr = (ftype *)out->extended_data[ch] + offset; const int min_part_size = s->min_part_size; const int nb_samples = FFMIN(min_part_size, out->nb_samples - offset); const int nb_segments = s->nb_segments; @@ -326,6 +326,7 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse ftype *dst = (ftype *)seg->output->extended_data[ch]; ftype *sumin = (ftype *)seg->sumin->extended_data[ch]; ftype *sumout = (ftype *)seg->sumout->extended_data[ch]; + ftype *tempin = (ftype *)seg->tempin->extended_data[ch]; int *output_offset = &seg->output_offset[ch]; const int nb_partitions = seg->nb_partitions; const int input_offset = seg->input_offset; @@ -358,12 +359,11 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse } memset(sumin, 0, sizeof(*sumin) * seg->fft_length); - blockin = (ftype *)seg->blockin->extended_data[ch] + seg->part_index[ch] * seg->block_size; blockout = (ftype *)seg->blockout->extended_data[ch] + seg->part_index[ch] * seg->block_size; - memset(blockin + part_size, 0, sizeof(*blockin) * (seg->block_size - part_size)); - memcpy(blockin, src, sizeof(*src) * part_size); + memset(tempin + part_size, 0, sizeof(*tempin) * (seg->block_size - part_size)); + memcpy(tempin, src, sizeof(*src) * part_size); - seg->tx_fn(seg->tx[ch], blockout, blockin, sizeof(ftype)); + seg->tx_fn(seg->tx[ch], blockout, tempin, sizeof(ftype)); j = seg->part_index[ch]; if (seg->loading[ch] < nb_partitions) { @@ -376,8 +376,8 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse } for (int i = 0; i < nb_partitions; i++) { - const int input_partition = i; - const int coeff_partition = j; + const int input_partition = j; + const int coeff_partition = i; const int coffset = coeff_partition * seg->coeff_size; const ftype *blockout = (const ftype *)seg->blockout->extended_data[ch] + input_partition * seg->block_size; const ctype *coeff = ((const ctype *)seg->coeff->extended_data[ch]) + coffset; |