From patchwork Thu Oct 4 12:01:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 10569 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:ab0:73d2:0:0:0:0:0 with SMTP id m18csp786112uaq; Thu, 4 Oct 2018 05:01:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV60jJFoI/uZvI009koUsnQZ9Liez86w6gI1OXdr9b2ANEc06f0L/7wsPvximIeWxlm2Ze6zW X-Received: by 2002:a5d:6511:: with SMTP id x17-v6mr4804085wru.150.1538654504482; Thu, 04 Oct 2018 05:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538654504; cv=none; d=google.com; s=arc-20160816; b=ZDQ3A9lJe9yszzCSx9Ob/VqLQHh7VTAb8/nJeTC0Xp5vqIhh4pNhhzc4PJFpKIwKwa ZatchHWuF/TkvOG8rVg+5pscvQN76Wb7G7LKrpy7P3zJ5XK/g18AcomAcnNd5s8E1wSU QyA7qWqF1+rsuh2BcGKBgveZL3QWkGyIe8Uv9XxM1Zx/25Bi908Px/oSgTW1LVMXzNcI z6B1CDlWNwXndTFtFsIEQ0etvIwpuD38CP8TOD3EuthSo3mHUeTKda3cVjoia2i0N/C+ W9FbXzb4xuGaQfqYtVS5QhQMJePvoe7k0cEuinp+203nyo5fzqC1tO8LYHaPeMT8G1Xt LECA== 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:dkim-signature :delivered-to; bh=ZUJquJ+Kkx2fxyYccqzsz9JvslZLQ9u8f4ncg8olqTc=; b=EuqLNpsokZOoNw2aoA2px889T51ZHOV9C6REFxTOylsLRlBoMFFIQTqElHdHwpFdFP e343g2u+2RnlEqs9/PitO4qa6FY69lZ7ie8Aot1Yci9XsxdGzq1io0EZD61/nt5DtoC8 0WkSXE6Hw3FpiHGC+ReOOf3D8QcM8HWHzCoGX52egaS+vhSgi9i/JsvDDqAVW5Hp3p1j dimItI3Byf6RzCV433WVW4yMADJuu2CspVBdOMvdx1EZRYWTXWU8S1dpFgbi0sQOaxtS aRfUvKVRThbgeloVTvJ5P0L6c/ReOyd5VAMe8um0axZGy/kXMJuM88VTcf37TeZfUkPd mW1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OZzPq1eo; 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 t2-v6si3454758wrm.351.2018.10.04.05.01.43; Thu, 04 Oct 2018 05:01:44 -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=20161025 header.b=OZzPq1eo; 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 7155868A491; Thu, 4 Oct 2018 15:01:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5581A68A0FA for ; Thu, 4 Oct 2018 15:01:14 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id c26-v6so597400edt.3 for ; Thu, 04 Oct 2018 05:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=MyDI35de7xrlE77uZ9plzyIdUpd/Nqk2f17qb91AA74=; b=OZzPq1eoFDlKF8zZmn32SogqPhKjlQ1FgTC5d3ffKnlqp4vx2pcLIhhZGdgr/zSXTA ahB6txMhykxxr2HV+veyfWI0QJ+vrBrUuo++Fk0qZMx2w3vyQiR0ZuEIMCCiqo6MJSaQ ++DICG9IVfzWnwfAVJsiWEYQF3t6hqy+MTSW3vBUUv6I7po80NUDsQ74/w73JsmXJ1mM 5NNqlexMkigPtbh800Cba0phfbT3FCWqfg0xvv9zVF0gaa/w3QyIrK+/wZzPhWq7k/e+ GDwtMJAOYo7oLb3W+Xr/SnKUa8eoG8cJXNCSpG5P8L2UJ6Zh8o4On80EpGanoxnMXKE5 O9AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=MyDI35de7xrlE77uZ9plzyIdUpd/Nqk2f17qb91AA74=; b=M5Sj9xC7EraqcswZOBqhlAwYgPgiXuMyIL+HlZs8w14WWQvCOFeMM/LA8BE8mB0Vt0 TmQBBlgIDPKetF1dMzI4CEWyoiXf/K41Nc3GjR7IBDhV08YNOmIM/AlgaiU71AxN13j+ DHwHmywr6d+tKC9QqAbVYcs9QqZx3jXoB3XaCcosjM7hffkJ3ddNwAD0enzjzEcZ5XSc 1kgluFswrIzUE4nUfCFrqE28KYdChCaF26zitq5bBbPGQNIvMb/75a7vIeFjt5ChaJe8 FT8zKIsz7D1ZJPQv+hXqLAwGs1brvNjKVUMRp/aTsnA2wot41vq8v8rFhE8nPBSEG/Tm eLFw== X-Gm-Message-State: ABuFfog3GKRCBkzOODU/lOzAgclEmDgi+7c8L6msU5z+Xnb1VEXPypyQ xcujKqM1I7BwevNNgUMMX2zIoppb X-Received: by 2002:a17:906:6b42:: with SMTP id o2-v6mr6108922ejs.186.1538654493561; Thu, 04 Oct 2018 05:01:33 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id o4-v6sm805741ejx.30.2018.10.04.05.01.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 05:01:32 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Oct 2018 14:01:19 +0200 Message-Id: <20181004120120.20953-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter: add ff_inlink_peek_samples and ff_inlink_skip samples 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: Paul B Mahol --- libavfilter/avfilter.c | 96 ++++++++++++++++++++++++++++++++++++++++++ libavfilter/filters.h | 17 ++++++++ 2 files changed, 113 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 93e866b79c..1dad873dfc 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1195,6 +1195,61 @@ static int take_samples(AVFilterLink *link, unsigned min, unsigned max, return 0; } +static int peek_samples(AVFilterLink *link, unsigned peek_samples, + AVFrame **rframe) +{ + AVFrame *frame0, *frame, *buf; + unsigned nb_samples, nb_frames, i, p; + int ret; + + /* Note: this function relies on no format changes and must only be + called with enough samples. */ + av_assert1(samples_ready(link, link->min_samples)); + frame0 = frame = ff_framequeue_peek(&link->fifo, 0); + if (!link->fifo.samples_skipped && frame->nb_samples == peek_samples) { + *rframe = frame; + return 0; + } + nb_frames = 0; + nb_samples = 0; + while (1) { + if (nb_samples + frame->nb_samples >= peek_samples) + break; + nb_samples += frame->nb_samples; + nb_frames++; + if (nb_frames == ff_framequeue_queued_frames(&link->fifo)) + break; + frame = ff_framequeue_peek(&link->fifo, nb_frames); + } + + buf = ff_get_audio_buffer(link, peek_samples); + if (!buf) + return AVERROR(ENOMEM); + ret = av_frame_copy_props(buf, frame0); + if (ret < 0) { + av_frame_free(&buf); + return ret; + } + buf->pts = frame0->pts; + + p = 0; + for (i = 0; i < nb_frames; i++) { + frame = ff_framequeue_peek(&link->fifo, i); + av_samples_copy(buf->extended_data, frame->extended_data, p, 0, + frame->nb_samples, link->channels, link->format); + p += frame->nb_samples; + } + if (p < peek_samples) { + unsigned n = peek_samples - p; + frame = ff_framequeue_peek(&link->fifo, i); + av_samples_copy(buf->extended_data, frame->extended_data, p, 0, n, + link->channels, link->format); + } + + *rframe = buf; + return 0; +} + static int ff_filter_frame_to_filter(AVFilterLink *link) { AVFrame *frame = NULL; @@ -1517,6 +1572,47 @@ int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, return 1; } +int ff_inlink_peek_samples(AVFilterLink *link, unsigned nb_samples, + AVFrame **rframe) +{ + AVFrame *frame; + int ret; + + av_assert1(nb_samples); + *rframe = NULL; + if (!ff_inlink_check_available_samples(link, nb_samples)) + return 0; + if (link->status_in) + nb_samples = FFMIN(nb_samples, ff_framequeue_queued_samples(&link->fifo)); + ret = peek_samples(link, nb_samples, &frame); + if (ret < 0) + return ret; + *rframe = frame; + return 1; +} + +void ff_inlink_skip_samples(AVFilterLink *link, unsigned skip_samples) +{ + while (skip_samples > 0) { + AVFrame *frame = ff_inlink_peek_frame(link, 0); + if (skip_samples >= frame->nb_samples) { + frame = ff_framequeue_take(&link->fifo); + skip_samples -= frame->nb_samples; + av_frame_free(&frame); + } else { + break; + } + } + + if (skip_samples) + ff_framequeue_skip_samples(&link->fifo, skip_samples, link->time_base); + + if (ff_inlink_queued_frames(link)) { + AVFrame *frame = ff_inlink_peek_frame(link, 0); + consume_update(link, frame); + } +} + AVFrame *ff_inlink_peek_frame(AVFilterLink *link, size_t idx) { return ff_framequeue_peek(&link->fifo, idx); diff --git a/libavfilter/filters.h b/libavfilter/filters.h index 1157755403..7dc0b35981 100644 --- a/libavfilter/filters.h +++ b/libavfilter/filters.h @@ -115,6 +115,23 @@ int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe); int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe); +/** + * Peek samples from the link's FIFO. + * + * @return >0 if a samples are available, + * 0 and set rframe to NULL if no samples are available, + * or AVERROR code + */ +int ff_inlink_peek_samples(AVFilterLink *link, unsigned nb_samples, + AVFrame **rframe); + +/** + * Skip samples from the link's FIFO. + * + * @note May trigger process_command() and/or update is_disabled. + */ +void ff_inlink_skip_samples(AVFilterLink *link, unsigned skip); + /** * Access a frame in the link fifo without consuming it. * The first frame is numbered 0; the designated frame must exist.