Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Paul B Mahol <onemda@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] avfilter/af_aresample: switch to activate
Date: Fri, 19 May 2023 00:19:50 +0200
Message-ID: <CAPYw7P5XrqkdRMKtz-h_iUe6R56iVK8CUPocPDwsFP+6RCkTHw@mail.gmail.com> (raw)
In-Reply-To: <20230518205405.GA1391451@pb2>

[-- Attachment #1: Type: text/plain, Size: 13 bytes --]

Fixed patch.

[-- Attachment #2: 0001-avfilter-af_aresample-switch-to-activate.patch --]
[-- Type: text/x-patch, Size: 4466 bytes --]

From 7cd57fc6ba5598fa43c068126d729180603efd02 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Wed, 17 May 2023 09:15:51 +0200
Subject: [PATCH] avfilter/af_aresample: switch to activate

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/af_aresample.c | 54 ++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index 971c861d0e..9cc50d4b38 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -32,6 +32,7 @@
 #include "libswresample/swresample.h"
 #include "avfilter.h"
 #include "audio.h"
+#include "filters.h"
 #include "internal.h"
 
 typedef struct AResampleContext {
@@ -41,6 +42,7 @@ typedef struct AResampleContext {
     struct SwrContext *swr;
     int64_t next_pts;
     int more_data;
+    int eof;
 } AResampleContext;
 
 static av_cold int preinit(AVFilterContext *ctx)
@@ -169,7 +171,8 @@ static int config_output(AVFilterLink *outlink)
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
 {
-    AResampleContext *aresample = inlink->dst->priv;
+    AVFilterContext *ctx = inlink->dst;
+    AResampleContext *aresample = ctx->priv;
     const int n_in  = insamplesref->nb_samples;
     int64_t delay;
     int n_out       = n_in * aresample->ratio + 32;
@@ -214,6 +217,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (n_out <= 0) {
         av_frame_free(&outsamplesref);
         av_frame_free(&insamplesref);
+        ff_inlink_request_frame(inlink);
         return 0;
     }
 
@@ -260,8 +264,10 @@ static int flush_frame(AVFilterLink *outlink, int final, AVFrame **outsamplesref
 static int request_frame(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
+    AVFilterLink *inlink = ctx->inputs[0];
     AResampleContext *aresample = ctx->priv;
-    int ret;
+    int ret = 0, status;
+    int64_t pts;
 
     // First try to get data from the internal buffers
     if (aresample->more_data) {
@@ -273,19 +279,52 @@ static int request_frame(AVFilterLink *outlink)
     }
     aresample->more_data = 0;
 
+    if (!aresample->eof && ff_inlink_acknowledge_status(inlink, &status, &pts))
+        aresample->eof = 1;
+
     // Second request more data from the input
-    ret = ff_request_frame(ctx->inputs[0]);
+    if (!aresample->eof)
+        FF_FILTER_FORWARD_WANTED(outlink, inlink);
 
     // Third if we hit the end flush
-    if (ret == AVERROR_EOF) {
+    if (aresample->eof) {
         AVFrame *outsamplesref;
 
-        if ((ret = flush_frame(outlink, 1, &outsamplesref)) < 0)
+        if ((ret = flush_frame(outlink, 1, &outsamplesref)) < 0) {
+            if (ret == AVERROR_EOF) {
+                ff_outlink_set_status(outlink, AVERROR_EOF, aresample->next_pts);
+                return 0;
+            }
             return ret;
+        }
 
         return ff_filter_frame(outlink, outsamplesref);
     }
-    return ret;
+
+    ff_filter_set_ready(ctx, 100);
+    return 0;
+}
+
+static int activate(AVFilterContext *ctx)
+{
+    AResampleContext *aresample = ctx->priv;
+    AVFilterLink *inlink = ctx->inputs[0];
+    AVFilterLink *outlink = ctx->outputs[0];
+
+    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+    if (!aresample->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);
+    }
+
+    return request_frame(outlink);
 }
 
 static const AVClass *resample_child_class_iterate(void **iter)
@@ -322,7 +361,6 @@ static const AVFilterPad aresample_inputs[] = {
     {
         .name         = "default",
         .type         = AVMEDIA_TYPE_AUDIO,
-        .filter_frame = filter_frame,
     },
 };
 
@@ -330,7 +368,6 @@ static const AVFilterPad aresample_outputs[] = {
     {
         .name          = "default",
         .config_props  = config_output,
-        .request_frame = request_frame,
         .type          = AVMEDIA_TYPE_AUDIO,
     },
 };
@@ -339,6 +376,7 @@ const AVFilter ff_af_aresample = {
     .name          = "aresample",
     .description   = NULL_IF_CONFIG_SMALL("Resample audio data."),
     .preinit       = preinit,
+    .activate      = activate,
     .uninit        = uninit,
     .priv_size     = sizeof(AResampleContext),
     .priv_class    = &aresample_class,
-- 
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".

  reply	other threads:[~2023-05-18 22:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18 16:27 Paul B Mahol
2023-05-18 20:54 ` Michael Niedermayer
2023-05-18 22:19   ` Paul B Mahol [this message]
2023-05-27 15:56     ` Paul B Mahol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPYw7P5XrqkdRMKtz-h_iUe6R56iVK8CUPocPDwsFP+6RCkTHw@mail.gmail.com \
    --to=onemda@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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