From patchwork Tue Feb 22 16:46:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 34450 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp18334nkx; Tue, 22 Feb 2022 08:45:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBGVHGCEHHDzsrE+etz6C9BOepiopBJDwIUwCjiMeRNBjM4xoB1MaqziYuwYzYVmW5WEWJ X-Received: by 2002:a17:906:b1d0:b0:6cf:7f39:50e0 with SMTP id bv16-20020a170906b1d000b006cf7f3950e0mr21030747ejb.760.1645548320704; Tue, 22 Feb 2022 08:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645548320; cv=none; d=google.com; s=arc-20160816; b=nM3wnJBOPpJl3RRaIsYICep8Gq0+3U2q+r3+QJefzBU9B2uRNzQ1RRxOYzJBdoCYOH 59utrHZB7kjg3FAtTKqCZEC8n5xTFe2mpeOVhwCKkl8NBMJu+za5FfEFLUwl/S6r552e gSGctAQheO5jAi00aSDMp9cn/pf31NnXP42ZpDFC/emel22dGeUHtRjlEAo4BTkQiuhw 1B6jvb+wYhMrZutO9KQ5IJdF0DMHzLIGt0bn4KegB+AnjzClOs2E9bAPhDBQZW/dSQFV g3uqU9j/xghFBMEUZMrOKoeMzkU7gbESiRJvQQix+xQVl1O2UYR8vgeyEht9eR05GqpV apaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=+106AQC0SqRyEfj6um8cz41tFpnxY6vZ7s/6l1gxvuc=; b=PUWuZD+0NG3PUhqyfmL5aa5AMFCO69iMeieGnZmZLywlDgzpcXZU/PrxugDPdNUojA xOW/G6opa4VuyCcyKBxMRpaw6tFHlH+AA7Sx7DQF33LTonLXMajjMcxkaxoP8W4LEXqH g6Xj8kb4E41E+1XuSphMY6DVRw8qojaFLZWMdXQ1yr+iyXpANTgvFIWuRkG8YZ8ncCCo f0M0+alfrut1P0h+za0DM2d+joq/HOvj2w4ivE7xaP7M2MuFSKD+40AiWVMVOo04Guuv v6TBdCnIjHeoV1J6crVOSBY6kuazu7B7u46C78gEyC1UO0Uti+Rq3sd319bx+9wkCn59 p6kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=JeFWLFUE; 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 i19si11670929edc.96.2022.02.22.08.45.00; Tue, 22 Feb 2022 08:45:20 -0800 (PST) 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=20210112 header.b=JeFWLFUE; 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 313D068B0A7; Tue, 22 Feb 2022 18:44:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C1005687992 for ; Tue, 22 Feb 2022 18:44:50 +0200 (EET) Received: by mail-ej1-f45.google.com with SMTP id a8so44840729ejc.8 for ; Tue, 22 Feb 2022 08:44:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=eJExGto+955eBS4cdXWMz+yXVoK9DJbNuC9l2oVOkW4=; b=JeFWLFUEu8X/7tWhnyhHsaeinyvVYc2dCJac186LhRHDbmtImWb0akiYIHAZ82HiKr BNykzSfsNK7O+cHaOBJ0OMGsdO0+o/X8mTWNWAPS6heMq5axCybpOVsvl6h3MK/XPUdQ ZvzPzPCuxZT3w2910+2mET+s928bRMLNWbcLkMMO/xlBpCTHj8G8cXTtU8xEnRx0MgZx Rs+Lc6CK/NFdOm/P9k5LX0QnGVNWNLJs7d57ijsX2qFyDr3qpE94DIHKfPOnTJuQbi2g o/gfYbeXxHFZlHim8lmVbKsRUxWlNKr3ZhbIwwUNU7RY2Z6kAdwA+Zja8+NK1Qrw4iE1 aQlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=eJExGto+955eBS4cdXWMz+yXVoK9DJbNuC9l2oVOkW4=; b=NgVUEDwJiYTpzyjJfvTxuJmKw0T02iEcR6mfDIFcJf2Y+5FBEOnZefXd4ctYVfOFWP L2noXp7fkfB0raQH054145Oh3MY/ZDCow4xnn8DKB1CcG0+pro7Cy5YTFRRzkjc1oftg HILrW/4pGvK4lwFydNO+rEaBzWwCsXz9XyL2gjcH2LRSyE6GpnFrb1p1WhsBKis48Sl6 Fp4lWK1H+49jNdi6/H+HO9MSzGzRNmAK99IIh9fh1W6A/ERXgbpZ0xN3OH4/NdBKDQa5 VB6INJ62VJsu2vPERumfsLz+6RStXJa7V44k/hPMm/sc0cFA4JDfezYQA7zLRpH1xkHE 6anQ== X-Gm-Message-State: AOAM5304pe+YjaYoaMWyd+njbKK70x/1/IlLG9RA+oZE7tG6DCtVruWX 1PWOgv9sJebLQ9P1+eq/LEZfes8ie14= X-Received: by 2002:a17:906:26d8:b0:6d2:515:9bdb with SMTP id u24-20020a17090626d800b006d205159bdbmr4793107ejc.261.1645548289875; Tue, 22 Feb 2022 08:44:49 -0800 (PST) Received: from localhost.localdomain ([212.15.177.16]) by smtp.gmail.com with ESMTPSA id g11sm6635938ejs.14.2022.02.22.08.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 08:44:49 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 22 Feb 2022 17:46:14 +0100 Message-Id: <20220222164616.511012-1-onemda@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/af_loudnorm: 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: dEb8FrN+jV2F Signed-off-by: Paul B Mahol --- libavfilter/af_loudnorm.c | 62 ++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c index dbe7fba986..5b4b6e8548 100644 --- a/libavfilter/af_loudnorm.c +++ b/libavfilter/af_loudnorm.c @@ -22,6 +22,7 @@ #include "libavutil/opt.h" #include "avfilter.h" +#include "filters.h" #include "internal.h" #include "audio.h" #include "ebur128.h" @@ -502,9 +503,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ff_ebur128_add_frames_double(s->r128_out, dst, subframe_length); s->pts += - out->nb_samples = - inlink->min_samples = - inlink->max_samples = subframe_length; + out->nb_samples = subframe_length; s->frame_type = INNER_FRAME; break; @@ -636,15 +635,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(outlink, out); } -static int request_frame(AVFilterLink *outlink) +static int flush_frame(AVFilterLink *outlink) { - int ret; AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; LoudNormContext *s = ctx->priv; + int ret = 0; - ret = ff_request_frame(inlink); - if (ret == AVERROR_EOF && s->frame_type == INNER_FRAME) { + if (s->frame_type == INNER_FRAME) { double *src; double *buf; int nb_samples, n, c, offset; @@ -681,6 +679,48 @@ static int request_frame(AVFilterLink *outlink) return ret; } +static int activate(AVFilterContext *ctx) +{ + AVFilterLink *inlink = ctx->inputs[0]; + AVFilterLink *outlink = ctx->outputs[0]; + LoudNormContext *s = ctx->priv; + AVFrame *in = NULL; + int ret = 0, status; + int64_t pts; + + FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); + + if (s->frame_type != LINEAR_MODE) { + int nb_samples; + + if (s->frame_type == FIRST_FRAME) { + nb_samples = frame_size(inlink->sample_rate, 3000); + } else { + nb_samples = frame_size(inlink->sample_rate, 100); + } + + ret = ff_inlink_consume_samples(inlink, nb_samples, nb_samples, &in); + } else { + ret = ff_inlink_consume_frame(inlink, &in); + } + + if (ret < 0) + return ret; + if (ret > 0) + ret = filter_frame(inlink, in); + if (ret < 0) + return ret; + + if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { + ff_outlink_set_status(outlink, status, pts); + return flush_frame(outlink); + } + + FF_FILTER_FORWARD_WANTED(outlink, inlink); + + return FFERROR_NOT_READY; +} + static int query_formats(AVFilterContext *ctx) { LoudNormContext *s = ctx->priv; @@ -749,11 +789,6 @@ static int config_input(AVFilterLink *inlink) init_gaussian_filter(s); - if (s->frame_type != LINEAR_MODE) { - inlink->min_samples = - inlink->max_samples = frame_size(inlink->sample_rate, 3000); - } - s->pts = AV_NOPTS_VALUE; s->buf_index = s->prev_buf_index = @@ -894,14 +929,12 @@ static const AVFilterPad avfilter_af_loudnorm_inputs[] = { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = config_input, - .filter_frame = filter_frame, }, }; static const AVFilterPad avfilter_af_loudnorm_outputs[] = { { .name = "default", - .request_frame = request_frame, .type = AVMEDIA_TYPE_AUDIO, }, }; @@ -912,6 +945,7 @@ const AVFilter ff_af_loudnorm = { .priv_size = sizeof(LoudNormContext), .priv_class = &loudnorm_class, .init = init, + .activate = activate, .uninit = uninit, FILTER_INPUTS(avfilter_af_loudnorm_inputs), FILTER_OUTPUTS(avfilter_af_loudnorm_outputs),