* [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate
@ 2023-05-18 17:48 Paul B Mahol
2023-05-27 14:03 ` Paul B Mahol
2023-05-27 15:42 ` Anton Khirnov
0 siblings, 2 replies; 5+ messages in thread
From: Paul B Mahol @ 2023-05-18 17:48 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 10 bytes --]
Attached.
[-- Attachment #2: 0021-avfilter-af_apad-switch-to-activate.patch --]
[-- Type: text/x-patch, Size: 5680 bytes --]
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
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate
2023-05-18 17:48 [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate Paul B Mahol
@ 2023-05-27 14:03 ` Paul B Mahol
2023-05-27 15:42 ` Anton Khirnov
1 sibling, 0 replies; 5+ messages in thread
From: Paul B Mahol @ 2023-05-27 14:03 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Will apply.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate
2023-05-18 17:48 [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate Paul B Mahol
2023-05-27 14:03 ` Paul B Mahol
@ 2023-05-27 15:42 ` Anton Khirnov
2023-05-27 15:46 ` Paul B Mahol
1 sibling, 1 reply; 5+ messages in thread
From: Anton Khirnov @ 2023-05-27 15:42 UTC (permalink / raw)
To: FFmpeg development discussions and patches
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate
2023-05-27 15:42 ` Anton Khirnov
@ 2023-05-27 15:46 ` Paul B Mahol
2023-05-27 15:51 ` Paul B Mahol
0 siblings, 1 reply; 5+ messages in thread
From: Paul B Mahol @ 2023-05-27 15:46 UTC (permalink / raw)
To: FFmpeg development discussions and patches
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".
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate
2023-05-27 15:46 ` Paul B Mahol
@ 2023-05-27 15:51 ` Paul B Mahol
0 siblings, 0 replies; 5+ messages in thread
From: Paul B Mahol @ 2023-05-27 15:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches
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".
>>
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-27 15:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-18 17:48 [FFmpeg-devel] [PATCH] avfilter/af_apad: switch to activate Paul B Mahol
2023-05-27 14:03 ` Paul B Mahol
2023-05-27 15:42 ` Anton Khirnov
2023-05-27 15:46 ` Paul B Mahol
2023-05-27 15:51 ` Paul B Mahol
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git