From patchwork Thu Sep 7 07:42:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 5018 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp1613557jao; Thu, 7 Sep 2017 00:42:37 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5g3a6sXFX8pxmOvFswI3XBv3Zjv50S0PnwLYxwXy4qjHpcPLoTEldVzBaz4MnBrUBEaEZO X-Received: by 10.28.99.84 with SMTP id x81mr1549243wmb.148.1504770157072; Thu, 07 Sep 2017 00:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504770157; cv=none; d=google.com; s=arc-20160816; b=HBLEew+/Zl5jYjb1Bq17oHN5WScFEplIPbt8K4pbEf39dSyhWBPZ4ffueEHagBNyK+ eaBcYAzC13VRLPud0nEG6W+clqURRNHA4rIJWDcVp9QWJ4HOuCGNaPORPtaIRXk/46z9 a//sDzViuJS/LlmqANS/gWklid0KZCMv33GSiC5pMPq2ceEZM58weFsvvEc8g8/YHAlw 6Egw1/hHxtUKj1W7diLHV548uzw25XYbICOj+6ZDgpb1P6xt7iNIF3Bk/Jv4O8lgwzEl ZwedRiA+dMalRgW0eu67EqkFoBagFPIpbfInmDUnBW/lK+BXrZ33o1rsGbiQ3eslzdMN 1dJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=4hFyK2SjkFRXRUwhmTn8x28oG+2vTmNvIRo+815oAl8=; b=PgCSLEDOmxCoq40i0D55lHUZ95qyoNiknt+rekkhECdHJdLo438TZ7YJ/+9oJ79V0h B+BPqLCOfkRtxjJWLppkj4iJ04k2acOgGr8a44JdgfqAQi/ml93J2zfC1/uFre93ieP7 s+g+4PK4EiBaJHhA0alh3zIP/bH7TukGY7vZosp13yXk9QgT2HpEN+a3LXd9FwR78E9f oTlnct3X6XIEZZ9yPluuuG/p0dQdMfay/soFqu0xgmd6Kga8C4uF6YSjvX5OLQlTvN/O EA39/BhLMrTqLn7WWeg7fkYRYMx5tLP6mjvo55GK3dM41Dlnbg/VItxgsBD+lblUVlZ0 SRdQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q201si677873wmb.273.2017.09.07.00.42.36; Thu, 07 Sep 2017 00:42:37 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3DC846882F2; Thu, 7 Sep 2017 10:42:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CE34F6809AC for ; Thu, 7 Sep 2017 10:42:24 +0300 (EEST) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v877gSNF051215 for ; Thu, 7 Sep 2017 09:42:28 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id F0C48E00AB; Thu, 7 Sep 2017 09:42:27 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Sep 2017 09:42:19 +0200 Message-Id: <20170907074226.7273-1-george@nsup.org> X-Mailer: git-send-email 2.14.1 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Thu, 07 Sep 2017 09:42:28 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/8] lavfi: add helper functions and macros for activate. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Nicolas George --- libavfilter/avfilter.c | 20 +++++++++++++ libavfilter/filters.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 6a97456054..91939eab8a 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1650,6 +1650,26 @@ void ff_inlink_request_frame(AVFilterLink *link) ff_filter_set_ready(link->src, 100); } +void ff_inlink_set_status(AVFilterLink *link, int status) +{ + if (link->status_out) + return; + link->frame_wanted_out = 0; + link->frame_blocked_in = 0; + ff_avfilter_link_set_out_status(link, status, AV_NOPTS_VALUE); + while (ff_framequeue_queued_frames(&link->fifo)) { + AVFrame *frame = ff_framequeue_take(&link->fifo); + av_frame_free(&frame); + } + if (!link->status_in) + link->status_in = status; +} + +int ff_outlink_get_status(AVFilterLink *link) +{ + return link->status_in; +} + const AVClass *avfilter_get_class(void) { return &avfilter_class; diff --git a/libavfilter/filters.h b/libavfilter/filters.h index 1cbc18158f..b3c4a959a3 100644 --- a/libavfilter/filters.h +++ b/libavfilter/filters.h @@ -140,6 +140,12 @@ int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts */ void ff_inlink_request_frame(AVFilterLink *link); +/** + * Set the status on an input link. + * Also discard all frames in the link's FIFO. + */ +void ff_inlink_set_status(AVFilterLink *link, int status); + /** * Test if a frame is wanted on an output link. */ @@ -148,6 +154,11 @@ static inline int ff_outlink_frame_wanted(AVFilterLink *link) return link->frame_wanted_out; } +/** + * Get the status on an output link. + */ +int ff_outlink_get_status(AVFilterLink *link); + /** * Set the status field of a link from the source filter. * The pts should reflect the timestamp of the status change, @@ -160,4 +171,71 @@ static inline void ff_outlink_set_status(AVFilterLink *link, int status, int64_t ff_avfilter_link_set_in_status(link, status, pts); } +/** + * Forward the status on an output link to an input link. + * If the status is set, it will discard all queued frames and this macro + * will return immediately. + */ +#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink) do { \ + int ret = ff_outlink_get_status(outlink); \ + if (ret) { \ + ff_inlink_set_status(inlink, ret); \ + return 0; \ + } \ +} while (0) + +/** + * Forward the status on an output link to all input links. + * If the status is set, it will discard all queued frames and this macro + * will return immediately. + */ +#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter) do { \ + int ret = ff_outlink_get_status(outlink); \ + if (ret) { \ + unsigned i; \ + for (i = 0; i < filter->nb_inputs; i++) \ + ff_inlink_set_status(filter->inputs[i], ret); \ + return 0; \ + } \ +} while (0) + +/** + * Acknowledge the status on an input link and forward it to an output link. + * If the status is set, this macro will return immediately. + */ +#define FF_FILTER_FORWARD_STATUS(inlink, outlink) do { \ + int status; \ + int64_t pts; \ + if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \ + ff_outlink_set_status(outlink, status, pts); \ + return 0; \ + } \ +} while (0) + +/** + * Acknowledge the status on an input link and forward it to an output link. + * If the status is set, this macro will return immediately. + */ +#define FF_FILTER_FORWARD_STATUS_ALL(inlink, filter) do { \ + int status; \ + int64_t pts; \ + if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \ + unsigned i; \ + for (i = 0; i < filter->nb_outputs; i++) \ + ff_outlink_set_status(filter->outputs[i], status, pts); \ + return 0; \ + } \ +} while (0) + +/** + * Forward the frame_wanted_out flag from an output link to an input link. + * If the flag is set, this macro will return immediately. + */ +#define FF_FILTER_FORWARD_WANTED(outlink, inlink) do { \ + if (ff_outlink_frame_wanted(outlink)) { \ + ff_inlink_request_frame(inlink); \ + return 0; \ + } \ +} while (0) + #endif /* AVFILTER_FILTERS_H */