avfilter/af_surround: drain input at EOF
authorPaul B Mahol <onemda@gmail.com>
Fri, 16 Mar 2018 11:30:17 +0000 (12:30 +0100)
committerPaul B Mahol <onemda@gmail.com>
Fri, 16 Mar 2018 11:31:56 +0000 (12:31 +0100)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
libavfilter/af_surround.c

index 460e18c..f29afec 100644 (file)
@@ -1390,6 +1390,27 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     return 0;
 }
 
+static int request_frame(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    AudioSurroundContext *s = ctx->priv;
+    int ret = 0;
+
+    ret = ff_request_frame(ctx->inputs[0]);
+
+    if (ret == AVERROR_EOF && av_audio_fifo_size(s->fifo) > 0 && av_audio_fifo_size(s->fifo) < s->buf_size) {
+        AVFrame *in;
+
+        in = ff_get_audio_buffer(outlink, s->buf_size - av_audio_fifo_size(s->fifo));
+        if (!in)
+            return AVERROR(ENOMEM);
+        ret = filter_frame(ctx->inputs[0], in);
+        av_audio_fifo_drain(s->fifo, s->buf_size);
+    }
+
+    return ret;
+}
+
 static av_cold void uninit(AVFilterContext *ctx)
 {
     AudioSurroundContext *s = ctx->priv;
@@ -1445,9 +1466,10 @@ static const AVFilterPad inputs[] = {
 
 static const AVFilterPad outputs[] = {
     {
-        .name         = "default",
-        .type         = AVMEDIA_TYPE_AUDIO,
-        .config_props = config_output,
+        .name          = "default",
+        .type          = AVMEDIA_TYPE_AUDIO,
+        .request_frame = request_frame,
+        .config_props  = config_output,
     },
     { NULL }
 };