From patchwork Thu Aug 31 18:04:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4924 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp1843684jao; Thu, 31 Aug 2017 11:04:38 -0700 (PDT) X-Google-Smtp-Source: ADKCNb6f76j/rgZH6m6Ec2RTAkwSqdz3+aCnEVPq5RUfATCuPaKQOsXVhe2Y1Y4K065gLOIj2joz X-Received: by 10.28.63.138 with SMTP id m132mr1908wma.76.1504202678217; Thu, 31 Aug 2017 11:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504202678; cv=none; d=google.com; s=arc-20160816; b=IvHH5WuKb/PG2fMbDKe5YQHhvx6oFJzBy4017X4bOrQXGkgCcUDZbeA/Dm4pg4v1r4 pcm+3EDbxPODGi2j20mfcI06w8FEAKhdxoYRKMttlpnfWIxk0A1CaESn6AtgzAD+kphj WPlPV306ZJAgdEW9mOmbXjOkX/OAaJKVT0chOXZSC+KFSdvWeFYDfT+7vYOYjSAtBZcs IQPQkPdU5Lm8FrCghfvqMkla155pgFcvqBi7DH/GsetpQmiH51O/AKyZ4L/R89u9XSz8 g17K6FHHkpmbUJj6cJ2/Y0WFiioQBfTcLTUuWUlwcSsObnwzFlUeSSPFJsSRqXkKdlY2 wZDA== 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=fkPNpKYMmhuzetFscjC6Qh0muSClcyDzvLzSOfBQWlc=; b=f1vA3gxIHnO4se8ZN9UlTLKdacEOQDoWAPG+9qtpILlykuFdU6MpXTAk81FaYEEXzz ajVOOMa7XHlsWqKiBpF9J5LkhSSWDoR5jFKcXwjStB5l8zr0fzyXY0v/q4492K1Sx7IM Ymledyuo6F5udrej92c+L2GqVSVdoQXO1rE22ehs5ZaHYje4o+lDVqA5XkMo5SFie7G+ VE1HQlRVE17uRrip7aFV2SFg/GTJDNvdsruUIFKTN/DiSak+Nbdv25f3j+h4iXexcivB fc/BJucdJvZP2W4zABfDFXBYPojspemLeBahklm5vdiRUstFyAGqF1K1VlOSUkug0gWF rMZw== 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 u11si246256wru.226.2017.08.31.11.04.37; Thu, 31 Aug 2017 11:04:38 -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 8F29B689FAD; Thu, 31 Aug 2017 21:04:34 +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 24588680112 for ; Thu, 31 Aug 2017 21:04:28 +0300 (EEST) Received: from phare.normalesup.org (archicubes.ens.fr [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v7VI4Skf069622 for ; Thu, 31 Aug 2017 20:04:28 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 97096E92D9; Thu, 31 Aug 2017 20:04:28 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Aug 2017 20:04:22 +0200 Message-Id: <20170831180427.32102-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, 31 Aug 2017 20:04:28 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/6] 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(+) This series is still work-in-progress, but I do not know when I will have time to give it again. The patches work by themselves. 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 */