From patchwork Thu May 18 16:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 41716 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp642725pzb; Thu, 18 May 2023 09:28:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zNKc91xBK0fQWK3HndsL6+Cj9le/jaga1gh+FtEaUbAYuZf9vcw+Cp+W+ydPj3np58+PK X-Received: by 2002:aa7:c309:0:b0:50b:ca1b:adeb with SMTP id l9-20020aa7c309000000b0050bca1badebmr5436953edq.0.1684427305392; Thu, 18 May 2023 09:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684427305; cv=none; d=google.com; s=arc-20160816; b=SygFyY3hpzpjsWKIl4h/6xkUTSh+BOizNq3CurcwMZeyBSqzwqWKLwGxBDlTpnk/1y 87elvL0L0c00iaiCErD2ZEnBP5PqoGwYqbX0VUNJUXkMkj6IaEbjt9Zwn1nJz6LDQ1KQ kW2i4itNMJyRS1LNaqKJb7oIAOZMQ2Yrla2XekVJ9+TFXGSWYs65zbCF8xZSZDSKIX3Q CmLMyMSUiPYIqdix/rcTJzcP9ntOBuH6dFUsg/zKOba+UcWGiBTPlA1VRazCM9CrSN0u Fd+SB2AEqF/kQmsht+a/tDRp89FmFJiaX3qyBd6LKLPuuGDdxYWRyKnlliLx4Syi0wpd TIGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=NCL9wR3EDwU/ywlv+4l8PhvIBg+ctllnyuBZoFtRxK8=; b=dsL4Nwq7KjAjlyJdeTCp5Tq2CGpkficJOB7zCgYv1JUQCCJmM483EJJ4FYZsEDc6V6 pPYp0TWNMuIFPnri0hTquBnsWYr+p7j8Pdx4v5EfhjXP3xGwNCupv4CqGoMe5QAo3d4z gq5TXDo4gQnYK13sr99eyHIXVePOYbCDua4x7ZqcrQM2N3/zvtABUJh3dX6nFxHAT5rY 1WelbRPV4PsW7XhxzSGEDKdIBgOVfQwWry15xxVwyg5HMTheE7Sg2+zPvlz1iVrjfq8V MyUckgjOHXxfhM8KvUXFHwwf7/NtDg2Qdcgikf6sSzrZ3TVVBldrbWhAD05+Bj34SnbJ BOJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=mVEQOdoW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e2-20020a056402088200b0050bc41b5200si1176405edy.15.2023.05.18.09.28.01; Thu, 18 May 2023 09:28:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=mVEQOdoW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E256168C104; Thu, 18 May 2023 19:27:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vs1-f49.google.com (mail-vs1-f49.google.com [209.85.217.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 01DD068BFAC for ; Thu, 18 May 2023 19:27:50 +0300 (EEST) Received: by mail-vs1-f49.google.com with SMTP id ada2fe7eead31-434839b4544so693546137.1 for ; Thu, 18 May 2023 09:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684427269; x=1687019269; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=bsFaTg0b7uIaHrGZXy5GbQRbMJch4dSyqERIp49dkaY=; b=mVEQOdoWQPRXY1fG9DAFTCCbDwetaJ2zyE05cY4ehrQicdQPLLSyKIympLXrFGIahG 3FvwbQL3lM3sgxdSnT9RvVhyNSdsPlQ2iWVxNBNy53edFiW2lQk38x3533bVjXHPqQ1r A3PCs9DOIE+fFnIAoCWExMBGdKhcPh7AjRKCHLSwA96XcH5JshwwFw5RgBwPQspQWXrO kEMY82Ah2qmFC9NzgbDVk6+MUaiA1HdM36OUaEUCOh8AFznAFKMjDMVTW9xttYGWYuik DKRBOhkcpWKKLbtBCeBBZj3nUXgf8JNORu6QAyN2MbiCHttSI75MpOvD+cRujGbcPQBn 8tJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684427269; x=1687019269; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bsFaTg0b7uIaHrGZXy5GbQRbMJch4dSyqERIp49dkaY=; b=YkhiOw0JRo8Z0QKVeZfa4PB2lWtKv3PnH/4N9oMZ5lj5EwByBqaBnybJAyj5Tyz3MO xBAzEfJV0NYFfXwLrBg5df1b4P29EchQUPJS3k//U36+5meWKtioG5W+wN+M7zzyIxQb pJTD/QESkzCDciS8mJ8wQQMqr3qqoYkXWGfGLLsKgrAjD3W4Fb4UxjGf9XcETmv0KBK9 eirO7R3d88CkbjnNIxTIr35x/QAXx6EQuN1QG9Kw5ZYfzRl+Y5ItZTs1GygXxP9gj8LD G59j3TehlBXv+h92XVOcZZAqNykEev5EPHhMvh4dMExVsTy0Z5dmgYYRUQcfr3KhKuds qqtA== X-Gm-Message-State: AC+VfDwLQ8kst4bZp3B7kJg2GPQpvkn0v5WUmtPPHEicH03zhkWBuGCF Qmn/RdgAhOYog0TrOB7rfmkuJ38LmqNApzGMKVdpIFCT X-Received: by 2002:a67:efd6:0:b0:436:7417:9ce0 with SMTP id s22-20020a67efd6000000b0043674179ce0mr326509vsp.2.1684427269374; Thu, 18 May 2023 09:27:49 -0700 (PDT) MIME-Version: 1.0 From: Paul B Mahol Date: Thu, 18 May 2023 18:27:00 +0200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] avfilter/af_aresample: switch to activate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: c5pz0/3NvWKG With proper EOF reporting support. Attached. From ed6be8443c29ce2246eec572b7342cee00e61925 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 17 May 2023 09:15:51 +0200 Subject: [PATCH 22/27] avfilter/af_aresample: switch to activate Signed-off-by: Paul B Mahol --- 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..a9fc74b7a3 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_filter_set_ready(ctx, 100); 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