From patchwork Sat Jul 22 16:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cox X-Patchwork-Id: 42904 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be1d:b0:130:ccc6:6c4b with SMTP id ge29csp952230pzb; Sat, 22 Jul 2023 09:42:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEF5C1zSWLt4O1FhILCPsKojnvDsoHCiolsIRjd5v2mTNpofsktT3nwTNUiX52OAm4cnhw X-Received: by 2002:a17:906:300d:b0:973:d06d:545f with SMTP id 13-20020a170906300d00b00973d06d545fmr4808548ejz.24.1690044160156; Sat, 22 Jul 2023 09:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690044160; cv=none; d=google.com; s=arc-20160816; b=QuNVaNlcHKvmmtc3j4y7f2gXlGeuZNDBgFOVNFOKalQPzTgoqBcbY03xBmzLOl7AnH e+CqDriDsVUBa1jQTHCAM3RLuadkHYXkXrxTOxM/eN5cuvtrjoZ5QWXz3XVqfGWFxr4V pMQc6ORzrMwXhr+Y17wzGmAsiauj2lFmV8SyEMjxtBPqNvOkBs7kytqap9IxNoTg/A8E tcaAjgkOhh6oV20/+vewTrKrwyWpA7vvl3UKmAAMSLugSAIdZvWj69isbU51Wrk1NCPd ZdqoKxDMlAhjbtIziw6miygdvAhZI4hVIZ59LkEfF8xDVSYJUcos0eWpZy2CLBU8+HiJ JvuQ== 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=ELqlL9xhPnZnRgRbQNIS15/ppn/vv9Ep+Kc2pgwRKCE=; b=fWPxbNegBwtXbcROzJ0PUs+zsN7QCwNt09gC24VX/kv23yu4ol57gxixVDoSh7wMch jlngH7Aqj+K8j1HpSbdGfSij+vEbhbO5iahfs3MAidoOggI7GG7yTt1Ac1fFdsQBrcne juRdgBgxSahkFN6xZ+2PaiMD3u8fK/YwYD4hbpzIQUxeOXPsxKGfZ45+AZn2eTqcCL3p 1lhuSsMpknVIt6aZc4VugAFjTeYFyqOJ9wbu2WAwGVTgNmJxfzpsqypL9QAWE6eMMsvC qwcpXO3epBvSctHfSwGT4Pk2PFuPIExAyzCCcgcmLV3/C//ZH+02FztG1Ub600Uz5Btc BI1A== 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=VmCVVpWr; 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 bs10-20020a170906d1ca00b0097650856f55si3971684ejb.695.2023.07.22.09.42.39; Sat, 22 Jul 2023 09:42:40 -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=VmCVVpWr; 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 73AE768C418; Sat, 22 Jul 2023 19:42:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DF6F68C59C for ; Sat, 22 Jul 2023 19:42:25 +0300 (EEST) Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-3fc04692e20so26863515e9.0 for ; Sat, 22 Jul 2023 09:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kynesim-co-uk.20221208.gappssmtp.com; s=20221208; t=1690044144; x=1690648944; 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=VmCVVpWrZHJsnwkFpypvBAFJzXT96e591f7aGd5EhUb43q0RQ7ox+zCjOFmezQULsF 8uW4XMUBZ4GYTl3Nbjz5OlqgDreIt9Ayxg8b3VUpKDURxrPcBlgd8HyR2ye6UmTueVMG DMCYebQ3NwvoGakd0G781eaZoy9YhPJS+MsH2SnMkxCG9cQOy0ewR4BooWOPpgiSJ5mv pyJaEZywsNtxIkOBw1BnXSAZeCphYYRSgicg0x6CiEnLZrA7OoRJfBmW7tGFoyUPui/t 5gPYeGxfM2WRHExSYqnIyOBin+DtZCuog8AU9081G2qNCDi+G5XKjkTrc3A0Tjc5+c9U 0zNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690044144; x=1690648944; 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=FMKYr/OEGdev5kEn607Q/1a18zvPf7y9pLxpiLe/4LomH9LbRnnUS/nNkeZO0X33jD OhhqOsgLVUcLOzjDEwYuH3kKkovDi8LIRaKkMFLW+UPOlbowNHgDPzvn4E4i0/eqRz2D peqmc09oHkPp2QI+wOqvzzMzffkL+eDBhlXrUIP44NruIr27et/Xm5YTISpEuhfG5EzK 13PLGiFGhXuTMozn1Qh2cqliQKeTV6HZhzrYkjbZxx27zexvJ17wgLe6cug6xrpuHnZN hLUD0cTojasb+LU0WMVoWvDHHi2sWTbQMx4gKBuwz2++A+wIm+mM3YTRxsYIoIJ20R5+ lraA== X-Gm-Message-State: ABy/qLYrEEHtkhvZsm1xOcDuxdfcSG+m5d/kufTi0uncSq0TTl2vk47u SbPbTBAH9D4EzAqDACtVco7a8a5K5nlV0JIurPw= X-Received: by 2002:a5d:4a8a:0:b0:315:adee:1297 with SMTP id o10-20020a5d4a8a000000b00315adee1297mr4610484wrq.10.1690044144361; Sat, 22 Jul 2023 09:42:24 -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 cr18-20020a05600004f200b003141a3c4353sm7298555wrb.30.2023.07.22.09.42.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 09:42:24 -0700 (PDT) From: John Cox To: ffmpeg-devel@ffmpeg.org Date: Sat, 22 Jul 2023 16:41:57 +0000 Message-Id: <20230722164157.964161-2-jc@kynesim.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230722164157.964161-1-jc@kynesim.co.uk> References: <20230722164157.964161-1-jc@kynesim.co.uk> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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, george@nsup.org, John Cox Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BCI4HAXv3ycA 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