avfilter/af_afir: reduce memory usage

pull/388/head
Paul B Mahol 2 years ago
parent 125e01d6cc
commit 64ddf04460
  1. 4
      libavfilter/af_afir.c
  2. 2
      libavfilter/af_afir.h
  3. 14
      libavfilter/afir_template.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);

@ -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;

@ -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;

Loading…
Cancel
Save