diff mbox series

[FFmpeg-devel,08/25] avfilter/af_headphone: Only attempt once to init coeffs

Message ID 20200908211856.16290-8-andreas.rheinhardt@gmail.com
State Accepted
Commit 5e68727fa7265a1f2eb0faf63e0b87869cc41199
Headers show
Series [FFmpeg-devel,01/25] avfilter/af_headphone: Don't use uninitialized buffer in log message | expand


Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 8, 2020, 9:18 p.m. UTC
The headphone filter does most of its initialization after its init
function, because it can perform certain tasks only after all but its
first input streams have reached eof. When this happens, it allocates
certain buffers and errors out if an allocation fails.

Yet the filter didn't check whether some of these buffers already exist
(which may happen if an earlier attempt has been interrupted in the
middle (due to an allocation error)) in which case the old buffers leak.

This commit makes sure that initializing the buffers is only attempted
once; if not successfull at the first attempt, future calls to the
filter will error out. Trying to support resuming initialization doesn't
seem worthwhile.

Notice that some allocations were freed before a new allocation was
performed; yet this effort was incomplete. Said code has been removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
While I am sure about the aim of this patch, I am not sure if simply
returning EOF is enough or if I have to use one of those FF_FILTER
status macros to return that this filter is finished.

 libavfilter/af_headphone.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
diff mbox series


diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index c71f43c5c8..4a68d35e66 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -425,12 +425,8 @@  static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
             goto fail;
-        av_fft_end(s->fft[0]);
-        av_fft_end(s->fft[1]);
         s->fft[0] = av_fft_init(av_log2(s->n_fft), 0);
         s->fft[1] = av_fft_init(av_log2(s->n_fft), 0);
-        av_fft_end(s->ifft[0]);
-        av_fft_end(s->ifft[1]);
         s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1);
         s->ifft[1] = av_fft_init(av_log2(s->n_fft), 1);
@@ -657,13 +653,12 @@  static int activate(AVFilterContext *ctx)
         if (!eof)
             return 0;
         s->eof_hrirs = 1;
-    }
-    if (!s->have_hrirs && s->eof_hrirs) {
         ret = convert_coeffs(ctx, inlink);
         if (ret < 0)
             return ret;
-    }
+    } else if (!s->have_hrirs)
+        return AVERROR_EOF;
     if ((ret = ff_inlink_consume_samples(ctx->inputs[0], s->size, s->size, &in)) > 0) {
         ret = headphone_frame(s, in, outlink);