From patchwork Sat Dec 24 17:41:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 1916 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp383873vsb; Sat, 24 Dec 2016 09:43:56 -0800 (PST) X-Received: by 10.194.115.132 with SMTP id jo4mr18276132wjb.27.1482601436019; Sat, 24 Dec 2016 09:43:56 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e138si36304097wmf.124.2016.12.24.09.43.54; Sat, 24 Dec 2016 09:43:55 -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; 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 C86FB689CDC; Sat, 24 Dec 2016 19:42:17 +0200 (EET) 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 74BFB689BE5 for ; Sat, 24 Dec 2016 19:42:05 +0200 (EET) 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 uBOHg61t095797 for ; Sat, 24 Dec 2016 18:42:06 +0100 (CET) Received: by phare.normalesup.org (Postfix, from userid 1001) id 682C0E0087; Sat, 24 Dec 2016 18:42:06 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Dec 2016 18:41:40 +0100 Message-Id: <20161224174149.8995-9-george@nsup.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161224174149.8995-1-george@nsup.org> References: <20161224174149.8995-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Sat, 24 Dec 2016 18:42:06 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 08/17] lavfi: add helpers to consume frames from link FIFOs. 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 | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ libavfilter/internal.h | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 22a1fedd17..e2eb2980be 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1498,6 +1498,69 @@ int ff_link_acknowledge_status(AVFilterLink *link) return 1; } +int ff_link_check_available_frame(AVFilterLink *link) +{ + return ff_framequeue_queued_frames(&link->fifo) > 0; +} + +int ff_link_check_available_samples(AVFilterLink *link, unsigned min) +{ + uint64_t samples = ff_framequeue_queued_samples(&link->fifo); + av_assert1(min); + return samples >= min || (link->status_in && samples); +} + +static void consume_update(AVFilterLink *link, const AVFrame *frame) +{ + ff_link_process_commands(link, frame); + ff_link_process_timeline(link, frame); + link->frame_count_out++; +} + +int ff_link_consume_frame_sure(AVFilterLink *link, AVFrame **rframe) +{ + AVFrame *frame; + + av_assert1(ff_link_check_available_frame(link)); + frame = ff_framequeue_take(&link->fifo); + consume_update(link, frame); + *rframe = frame; + return 1; +} + +int ff_link_consume_samples_sure(AVFilterLink *link, unsigned min, unsigned max, + AVFrame **rframe) +{ + AVFrame *frame; + int ret; + + av_assert1(min); + av_assert1(ff_link_check_available_samples(link, min)); + if (link->status_in) + min = FFMIN(min, ff_framequeue_queued_samples(&link->fifo)); + ret = take_samples(link, min, link->max_samples, &frame); + if (ret < 0) + return ret; + consume_update(link, frame); + *rframe = frame; + return 1; +} + +int ff_link_consume_frame(AVFilterLink *link, AVFrame **rframe) +{ + *rframe = NULL; + return !ff_link_check_available_frame(link) ? 0 : + ff_link_consume_frame_sure(link, rframe); +} + +int ff_link_consume_samples(AVFilterLink *link, unsigned min, unsigned max, + AVFrame **rframe) +{ + *rframe = NULL; + return !ff_link_check_available_samples(link, min) ? 0 : + ff_link_consume_samples_sure(link, min, max, rframe); +} + int ff_link_make_frame_writable(AVFilterLink *link, AVFrame **rframe) { AVFrame *frame = *rframe; diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 4488821fe0..9aaf585eca 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -625,6 +625,53 @@ void ff_filter_set_ready(AVFilterContext *filter, unsigned priority); int ff_link_acknowledge_status(AVFilterLink *link); /** + * Test if a frame is available on the link. + * @return >0 if a frame is available + */ +int ff_link_check_available_frame(AVFilterLink *link); + +/** + * Test if enough samples are available on the link. + * @return >0 if enough samples are available + * @note on EOF and error, min becomes 1 + */ +int ff_link_check_available_samples(AVFilterLink *link, unsigned min); + +/** + * Take a frame from the link's FIFO and update the link's stats. + * Must only be called if a frame is available (assert1). + * @note May trigger process_command() and/or update is_disabled. + */ +int ff_link_consume_frame_sure(AVFilterLink *link, AVFrame **rframe); + +/** + * Take samples from the link's FIFO and update the link's stats. + * Must only be called if samples are available (assert1). + * @note May trigger process_command() and/or update is_disabled. + */ +int ff_link_consume_samples_sure(AVFilterLink *link, unsigned min, unsigned max, + AVFrame **rframe); + +/** + * Take a frame from the link's FIFO and update the link's stats. + * @note May trigger process_command() and/or update is_disabled. + * @return >0 if a frame is available, + * 0 and sets rframe to NULL if no frame available, + * or AVERROR code + */ +int ff_link_consume_frame(AVFilterLink *link, AVFrame **rframe); + +/** + * Take samples from the link's FIFO and update the link's stats. + * @note May trigger process_command() and/or update is_disabled. + * @return >0 if a frame is available, + * 0 and sets rframe to NULL if no frame available, + * or AVERROR code + */ +int ff_link_consume_samples(AVFilterLink *link, unsigned min, unsigned max, + AVFrame **rframe); + +/** * Make sure a frame is writable. * This is similar to av_frame_make_writable() except it uses the link's * buffer allocation callback, and therefore allows direct rendering.