From patchwork Thu Jul 20 11:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cox X-Patchwork-Id: 42858 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:b813:b0:130:ccc6:6c4b with SMTP id fi19csp1815762pzb; Thu, 20 Jul 2023 04:40:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlEFCCY745AGi1sUujBVrhMlqyuVlrCkrFzuI30VfP7WAl0Yj/pUGS7taJxR8j2wc9SA/0JD X-Received: by 2002:a17:907:da6:b0:992:b928:adb3 with SMTP id go38-20020a1709070da600b00992b928adb3mr2440035ejc.54.1689853236578; Thu, 20 Jul 2023 04:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689853236; cv=none; d=google.com; s=arc-20160816; b=PZLZMW3RD/yYZPoCee/PeptofUmFQX15ZRgpDZzSMXQctQ1e3Ry8YSbjF75vfj9Y0f HjEKTJGt03HyV79rb6W1XYkNw65IynScjG8jMqxRTcDPELCTvOlXsNqzVcyov+ZJXkEf YN+RbJaDt2hdIuG29tWsGun0ujn3r6Ci/zz+Aq9ZgwaQTHn8gHDIaC5pYW2BhCkk9KK3 yNm12QTWx5LM88lxY0XD/hSNK6OJyykZMZrLSgL4bEDhCRzZQNoht4xVZlPitvnjoI1i xpMXecjN7s/8F/zlsqzX1e8+HubtQcdb4KSI17dg4M5BBc6ZDFwXEr58OHeIUvlnT/al Lt6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=tUslu/o1s9IVeB1o0VUjSw/71w6AN5jhKQ+6Zy0lzy8=; fh=RtkXQwrzbGVs06JUrNEEeGv1QjUQNDEuJeaoUdU5VnM=; b=H8oL+dX4aqwo/MJwr5Kc69i/lg2j8VH4ALypRQJt3JMiQ4n18XTHDr1IIORqfua7Nr JI55QN2Ny3kTbZdryZ/MeXJG6KyKz5HJbkPAlTYCILL/aAkGcWYkmVBHr2J4D7SDZ/ZA VhMBO3YZ4ytNzvaVQqvcZcx8u2U+9HgF67w+fAZ2l2A9BazTbpkEPE/6/X3wMofZi5eA OOUPXwBzjDa+Ay1kV6xRZDPA27Y/AT8xdn3mQX4USRqhKyqskRNXoi6KjSKpuRegT+mk C3+bcrgP0UY5Ty8HKk2IrOOPrP8lfDQAunf3QySHYkOtN+Kc+KUoANkzh6hqCkWYJCFd YcDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kynesim-co-uk.20221208.gappssmtp.com header.s=20221208 header.b=lf2ELZUK; 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 rp24-20020a170906d97800b0098678728b52si540995ejb.123.2023.07.20.04.40.36; Thu, 20 Jul 2023 04:40:36 -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=@kynesim-co-uk.20221208.gappssmtp.com header.s=20221208 header.b=lf2ELZUK; 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 DA73E68C403; Thu, 20 Jul 2023 14:40:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44B4968AD5A for ; Thu, 20 Jul 2023 14:40:20 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2b8392076c9so9616541fa.1 for ; Thu, 20 Jul 2023 04:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kynesim-co-uk.20221208.gappssmtp.com; s=20221208; t=1689853219; x=1690458019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cysaeSRPD7oOpPJqKe/39bnIeHJEijBKtgBl7kFYyRk=; b=lf2ELZUKCetPKYumMrdXwNEilm6rTAhs2RnRt10XSt+PAJI8LEDlXZ+ixpuvPZhXYs htR1/9YqoboqM7TFvGmMKa6POj+TKBgeMhOuTRXL2Dw38sUoqYwxEiNIotdYQUyg5xd1 ndITGVkjH0nf8b4qoQ5z1lR7ebMUYClIKvTxySwRFWEz4UNeztsE18PAwUMmux+AeN6/ GEqNjx0q4PnpiHET+jfHc7Mu6Op2aJCkLQGmnUHYfiJBPKyDej0yOLh+t3svtRKgc1zP vuI1o1uH6DPhWW8NgXnMAGGgFfUBKlbxEsj4cI9cE9Wx/wDNRcQ2I5x8Eq/nHjx9o89O Hk4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689853219; x=1690458019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cysaeSRPD7oOpPJqKe/39bnIeHJEijBKtgBl7kFYyRk=; b=QhP2YQYPh9eHFSVmEfUO40C4jTk4HCHUjatZvnImlK5cigL94tSR0SikWwVqndGpMD BgFV9YbzyP+HN+/tFYdSJEz4ijXfABq2GRT4S+7q6Afq2FpSi2ajz7H7rV4HzhlNwgWA 9MBa6daI3vkMQhoIYwfcUjowEuYwD/Sf2ZO/ZyPEnKwk0iDEH2m4DvZSvklqMC4yDPe/ UXG0cWN6NbAnYLNGQa3/hPUbhNqYhsigt84pny8d8eouLzvqDJo8LRAIpJpqek6m6AIQ Z4IN/neXdNFoWWB8ei/br70pu6r0OXkx9ZdojXbCObGGfwNndRgOZvy0pFCY6ZANTO3n R+yw== X-Gm-Message-State: ABy/qLZNRgWC+m08Ue6XPSDfjCFsgjuV86uGGi/su0L4sii12fIwXp2U G/DnQ0c8l86BjxsCVL/n11gJpHqrSfOUfMtW7Qs= X-Received: by 2002:a2e:9589:0:b0:2b6:e124:4d96 with SMTP id w9-20020a2e9589000000b002b6e1244d96mr1611231ljh.26.1689853219032; Thu, 20 Jul 2023 04:40:19 -0700 (PDT) Received: from sucnaath.outer.uphall.net (cpc1-cmbg20-2-0-cust759.5-4.cable.virginm.net. [86.21.218.248]) by smtp.gmail.com with ESMTPSA id 24-20020a05600c025800b003fbfea1afffsm964048wmj.27.2023.07.20.04.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 04:40:18 -0700 (PDT) From: John Cox To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jul 2023 11:39:55 +0000 Message-Id: <20230720113955.957942-2-jc@kynesim.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720113955.957942-1-jc@kynesim.co.uk> References: <20230720113955.957942-1-jc@kynesim.co.uk> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] avfilter/buffersink: Add video frame allocation callback 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 Cc: stefasab@gmail.com, John Cox Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1xAhK9JSeSJ6 Add a callback to enable user allocation of video frames on the final stage of a filter chain. Signed-off-by: John Cox --- libavfilter/buffersink.c | 21 +++++++++++++++++++++ libavfilter/buffersink.h | 27 +++++++++++++++++++++++++++ libavfilter/version.h | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 306c283f77..070b743186 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -62,6 +62,11 @@ typedef struct BufferSinkContext { int sample_rates_size; AVFrame *peeked_frame; + + union { + av_buffersink_alloc_video_frame * video; + } alloc_cb; + void * alloc_v; } BufferSinkContext; #define NB_ITEMS(list) (list ## _size / sizeof(*list)) @@ -154,6 +159,21 @@ int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, return get_frame_internal(ctx, frame, 0, nb_samples); } +static AVFrame * alloc_video_buffer(AVFilterLink *link, int w, int h) +{ + AVFilterContext * const ctx = link->dst; + BufferSinkContext * const bs = ctx->priv; + return bs->alloc_cb.video ? bs->alloc_cb.video(ctx, bs->alloc_v, w, h) : + ff_default_get_video_buffer(link, w, h); +} + +void av_buffersink_set_alloc_video_frame(AVFilterContext *ctx, av_buffersink_alloc_video_frame * cb, void * v) +{ + BufferSinkContext * const bs = ctx->priv; + bs->alloc_cb.video = cb; + bs->alloc_v = v; +} + static av_cold int common_init(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; @@ -381,6 +401,7 @@ static const AVFilterPad avfilter_vsink_buffer_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, + .get_buffer = {.video = alloc_video_buffer}, }, }; diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 64e08de53e..73f0ddc476 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -166,6 +166,33 @@ int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame); */ int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples); +/** + * Callback from av_buffersink_set_alloc_video_frame to allocate + * a frame + * + * @param ctx pointer to a context of the abuffersink AVFilter. + * @param v opaque pointer passed to + * av_buffersink_set_alloc_video_frame + * @param w width of frame to allocate + * @param height of frame to allocate + * + * @return + * - The newly allocated frame + * - NULL if error + */ +typedef AVFrame * av_buffersink_alloc_video_frame(AVFilterContext * ctx, void * v, int w, int h); + +/** + * Set a video frame allocation method for buffersink + * + * @param ctx pointer to a context of the abuffersink AVFilter. + * @param cb Callback to the allocation function. If set to NULL + * then the default avfilter allocation function will + * be used. + * @param v Opaque to pass to the allocation function + */ +void av_buffersink_set_alloc_video_frame(AVFilterContext *ctx, av_buffersink_alloc_video_frame * cb, void * v); + /** * @} */ diff --git a/libavfilter/version.h b/libavfilter/version.h index c001693e3c..54950497be 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFILTER_VERSION_MINOR 8 +#define LIBAVFILTER_VERSION_MINOR 9 #define LIBAVFILTER_VERSION_MICRO 102