diff mbox series

[FFmpeg-devel] avfilter/af_apad: switch to activate

Message ID CAPYw7P4Pg0EkQaoqS8bTV2=oHcFbEBH8Y=i5E2q32wLSKKZdvg@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] avfilter/af_apad: switch to activate | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Paul B Mahol May 18, 2023, 5:48 p.m. UTC
Attached.

Comments

Paul B Mahol May 27, 2023, 2:03 p.m. UTC | #1
Will apply.
Anton Khirnov May 27, 2023, 3:42 p.m. UTC | #2
Quoting Paul B Mahol (2023-05-18 19:48:47)
> Attached.
> 
> From c06d3d9f6020fdda19641637cafa6f86c77b4b73 Mon Sep 17 00:00:00 2001
> From: Paul B Mahol <onemda@gmail.com>
> Date: Wed, 17 May 2023 09:14:56 +0200
> Subject: [PATCH 21/27] avfilter/af_apad: switch to activate
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavfilter/af_apad.c | 105 ++++++++++++++++++++++++++++--------------
>  1 file changed, 71 insertions(+), 34 deletions(-)

The commit message for such commits should mention why is this better,
because it is not obvious. For one thing, the new code is significantly
longer.
Paul B Mahol May 27, 2023, 3:46 p.m. UTC | #3
On Sat, May 27, 2023 at 5:43 PM Anton Khirnov <anton@khirnov.net> wrote:

> Quoting Paul B Mahol (2023-05-18 19:48:47)
> > Attached.
> >
> > From c06d3d9f6020fdda19641637cafa6f86c77b4b73 Mon Sep 17 00:00:00 2001
> > From: Paul B Mahol <onemda@gmail.com>
> > Date: Wed, 17 May 2023 09:14:56 +0200
> > Subject: [PATCH 21/27] avfilter/af_apad: switch to activate
> >
> > Signed-off-by: Paul B Mahol <onemda@gmail.com>
> > ---
> >  libavfilter/af_apad.c | 105 ++++++++++++++++++++++++++++--------------
> >  1 file changed, 71 insertions(+), 34 deletions(-)
>
> The commit message for such commits should mention why is this better,
> because it is not obvious. For one thing, the new code is significantly
> longer.
>




>
> --
> Anton Khirnov
> _______________________________________________
> 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".
>
Paul B Mahol May 27, 2023, 3:51 p.m. UTC | #4
On Sat, May 27, 2023 at 5:46 PM Paul B Mahol <onemda@gmail.com> wrote:

>
>
> On Sat, May 27, 2023 at 5:43 PM Anton Khirnov <anton@khirnov.net> wrote:
>
>> Quoting Paul B Mahol (2023-05-18 19:48:47)
>> > Attached.
>> >
>> > From c06d3d9f6020fdda19641637cafa6f86c77b4b73 Mon Sep 17 00:00:00 2001
>> > From: Paul B Mahol <onemda@gmail.com>
>> > Date: Wed, 17 May 2023 09:14:56 +0200
>> > Subject: [PATCH 21/27] avfilter/af_apad: switch to activate
>> >
>> > Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> > ---
>> >  libavfilter/af_apad.c | 105 ++++++++++++++++++++++++++++--------------
>> >  1 file changed, 71 insertions(+), 34 deletions(-)
>>
>> The commit message for such commits should mention why is this better,
>> because it is not obvious. For one thing, the new code is significantly
>> longer.
>>
>

Than I will count your net change in lines too, and will reject such
patches from 0.
~30 lines is irrelevant. This fixes EOF reporting which when combined with
other filters in filter graph can reduce usage of both processing and
memory resources significantly.

I'm astonished of your lack of general knowledge in this domain.



>
>
>>
>> --
>> Anton Khirnov
>> _______________________________________________
>> 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".
>>
>
diff mbox series

Patch

From c06d3d9f6020fdda19641637cafa6f86c77b4b73 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Wed, 17 May 2023 09:14:56 +0200
Subject: [PATCH 21/27] avfilter/af_apad: switch to activate

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/af_apad.c | 105 ++++++++++++++++++++++++++++--------------
 1 file changed, 71 insertions(+), 34 deletions(-)

diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c
index df17c9a531..45693a2bd5 100644
--- a/libavfilter/af_apad.c
+++ b/libavfilter/af_apad.c
@@ -32,12 +32,14 @@ 
 #include "libavutil/avassert.h"
 #include "avfilter.h"
 #include "audio.h"
+#include "filters.h"
 #include "internal.h"
 
 typedef struct APadContext {
     const AVClass *class;
     int64_t next_pts;
 
+    int eof;
     int packet_size;
     int64_t pad_len, pad_len_left;
     int64_t whole_len, whole_len_left;
@@ -87,50 +89,86 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     return ff_filter_frame(ctx->outputs[0], frame);
 }
 
-static int request_frame(AVFilterLink *outlink)
+static int push_frame(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     APadContext *s = ctx->priv;
-    int ret;
+    AVFrame *outsamplesref;
+    int n_out;
 
-    ret = ff_request_frame(ctx->inputs[0]);
+    if (ctx->is_disabled)
+        return 0;
+    n_out = s->packet_size;
 
-    if (ret == AVERROR_EOF && !ctx->is_disabled) {
-        int n_out = s->packet_size;
-        AVFrame *outsamplesref;
+    if (s->whole_len >= 0 && s->pad_len < 0) {
+        s->pad_len = s->pad_len_left = s->whole_len_left;
+    }
+    if (s->pad_len >=0 || s->whole_len >= 0) {
+        n_out = FFMIN(n_out, s->pad_len_left);
+        s->pad_len_left -= n_out;
+        av_log(ctx, AV_LOG_DEBUG,
+               "padding n_out:%d pad_len_left:%"PRId64"\n", n_out, s->pad_len_left);
+    }
 
-        if (s->whole_len >= 0 && s->pad_len < 0) {
-            s->pad_len = s->pad_len_left = s->whole_len_left;
-        }
-        if (s->pad_len >=0 || s->whole_len >= 0) {
-            n_out = FFMIN(n_out, s->pad_len_left);
-            s->pad_len_left -= n_out;
-            av_log(ctx, AV_LOG_DEBUG,
-                   "padding n_out:%d pad_len_left:%"PRId64"\n", n_out, s->pad_len_left);
-        }
+    if (!n_out)
+        return AVERROR_EOF;
+
+    outsamplesref = ff_get_audio_buffer(outlink, n_out);
+    if (!outsamplesref)
+        return AVERROR(ENOMEM);
+
+    av_assert0(outsamplesref->sample_rate == outlink->sample_rate);
+    av_assert0(outsamplesref->nb_samples  == n_out);
+
+    av_samples_set_silence(outsamplesref->extended_data, 0,
+                           n_out,
+                           outsamplesref->ch_layout.nb_channels,
+                           outsamplesref->format);
+
+    outsamplesref->pts = s->next_pts;
+    if (s->next_pts != AV_NOPTS_VALUE)
+        s->next_pts += av_rescale_q(n_out, (AVRational){1, outlink->sample_rate}, outlink->time_base);
+
+    return ff_filter_frame(outlink, outsamplesref);
+}
 
-        if (!n_out)
-            return AVERROR_EOF;
+static int activate(AVFilterContext *ctx)
+{
+    AVFilterLink *inlink = ctx->inputs[0];
+    AVFilterLink *outlink = ctx->outputs[0];
+    APadContext *s = ctx->priv;
+    int64_t pts;
+    int status;
 
-        outsamplesref = ff_get_audio_buffer(outlink, n_out);
-        if (!outsamplesref)
-            return AVERROR(ENOMEM);
+    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
 
-        av_assert0(outsamplesref->sample_rate == outlink->sample_rate);
-        av_assert0(outsamplesref->nb_samples  == n_out);
+    if (!s->eof && ff_inlink_queued_frames(inlink)) {
+        AVFrame *frame = NULL;
+        int ret;
+
+        ret = ff_inlink_consume_frame(inlink, &frame);
+        if (ret < 0)
+            return ret;
+        if (ret > 0)
+            return filter_frame(inlink, frame);
+    }
 
-        av_samples_set_silence(outsamplesref->extended_data, 0,
-                               n_out,
-                               outsamplesref->ch_layout.nb_channels,
-                               outsamplesref->format);
+    if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts))
+        s->eof = status == AVERROR_EOF;
 
-        outsamplesref->pts = s->next_pts;
-        if (s->next_pts != AV_NOPTS_VALUE)
-            s->next_pts += av_rescale_q(n_out, (AVRational){1, outlink->sample_rate}, outlink->time_base);
+    if (s->eof) {
+        int ret = push_frame(outlink);
 
-        return ff_filter_frame(outlink, outsamplesref);
+        if (ret == AVERROR_EOF) {
+            ff_outlink_set_status(outlink, AVERROR_EOF, s->next_pts);
+            return 0;
+        }
+        return ret;
     }
-    return ret;
+
+    FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+    return FFERROR_NOT_READY;
 }
 
 static int config_output(AVFilterLink *outlink)
@@ -153,16 +191,14 @@  static const AVFilterPad apad_inputs[] = {
     {
         .name         = "default",
         .type         = AVMEDIA_TYPE_AUDIO,
-        .filter_frame = filter_frame,
     },
 };
 
 static const AVFilterPad apad_outputs[] = {
     {
         .name          = "default",
-        .request_frame = request_frame,
-        .config_props  = config_output,
         .type          = AVMEDIA_TYPE_AUDIO,
+        .config_props  = config_output,
     },
 };
 
@@ -170,6 +206,7 @@  const AVFilter ff_af_apad = {
     .name          = "apad",
     .description   = NULL_IF_CONFIG_SMALL("Pad audio with silence."),
     .init          = init,
+    .activate      = activate,
     .priv_size     = sizeof(APadContext),
     FILTER_INPUTS(apad_inputs),
     FILTER_OUTPUTS(apad_outputs),
-- 
2.39.1