From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id F369246F50 for ; Sun, 23 Jul 2023 17:21:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A1F0768C6D1; Sun, 23 Jul 2023 20:21:13 +0300 (EEST) Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07EE968C1C3 for ; Sun, 23 Jul 2023 20:21:07 +0300 (EEST) Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6b9defb36a2so3100516a34.2 for ; Sun, 23 Jul 2023 10:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690132865; x=1690737665; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=55dFyAOfL8ZTPriVHud+jdDu0k7j1Ryup4aNHoGJdD8=; b=nmbOOCHA1aTxolOZ89EUNLDgCyE80BsCrB1grSEZabF91VX7ildY2t8FiCOCfwupv+ FbQsX2szDu55SSVgEfPGf5cC/MekDB9Hqs0GmUqCXbm61lrrKdbGft6NuUddmDrJH03r fTxK1rp2mAlTtsDy/I5tV+ROjnkXf0RvjkCOIh0N5g8ZuTLrNEzELqvNiY/cZ/WEQeW6 TV6g+mg/0xMY4XYA9o137VMEsyzENdQTo4O4cEYUXGvYF6FwI6/7PKCO2a6BJFA+8VjA Pbf/W+qV4foRXu4U/ShUcAHzd1JS28vLGnTO/482bXatDUJfxrsi30+Nk800/gdmx2n6 M6Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690132865; x=1690737665; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=55dFyAOfL8ZTPriVHud+jdDu0k7j1Ryup4aNHoGJdD8=; b=jVtPYBS4r6yN2jUXgacSNvOTSWsB1mmcbCLUQ235gjRAwPBFY6Y2ki/2h/MPJS9Zvx W+SiXAJ59YNCZr1/juPUn1GhyT1tFLyV+1cCEe66O7zBT24vIiLi/LRhMnT5IKIIn30O mWyHU/yEGa3OGxs/iyOTLwNh2ydwpwfmMXBEKTUxJlrwJtWtQfxIDZ49LeZ/VAlhTnJO 5LXz8R2yV+8Com3LZ5fteeLOUX5/Jt0KfMahyzTu95GBXnYBoC1TWXTtShP4/ASlw7gl tYU1KrbpGOZievGVJzTYXvqOfDQ9SUparKVzv2Tvahw8c+NI54jMAaKiBbWJyX0f4v5F 68QQ== X-Gm-Message-State: ABy/qLZFhuOnBE4lxupc66StIQ/nODlbtapgNlTn8t9sC2RaqwnBWT7W pXaaIH2TKBBQEd2of3fgBblg8zEOkuM= X-Google-Smtp-Source: APBJJlGeVBXh057vdfmeVEd5MGfma/c5UwM++74EDq/mTQZOvfP0ihIBNaU1Mzkl1BJWxt2lsseYPA== X-Received: by 2002:a05:6808:2c7:b0:3a3:f8f4:defd with SMTP id a7-20020a05680802c700b003a3f8f4defdmr7014236oid.19.1690132864614; Sun, 23 Jul 2023 10:21:04 -0700 (PDT) Received: from [192.168.0.16] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id n19-20020a4ad633000000b00566250a04f6sm3292262oon.18.2023.07.23.10.21.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Jul 2023 10:21:04 -0700 (PDT) Message-ID: <48dc91a8-5da0-d074-386d-4a095651afaa@gmail.com> Date: Sun, 23 Jul 2023 14:21:17 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20230722170357.964313-1-jc@kynesim.co.uk> <20230722170357.964313-2-jc@kynesim.co.uk> From: James Almer In-Reply-To: <20230722170357.964313-2-jc@kynesim.co.uk> Subject: Re: [FFmpeg-devel] [PATCH v3 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 7/22/2023 2:03 PM, John Cox wrote: > 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..e99d444530 100644 > --- a/libavfilter/buffersink.c > +++ b/libavfilter/buffersink.c > @@ -62,6 +62,11 @@ typedef struct BufferSinkContext { > int sample_rates_size; > > AVFrame *peeked_frame; > + > + union { > + AVBuffersinkAllocVideoFrameFunc 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 buf = ctx->priv; > + return buf->alloc_cb.video ? buf->alloc_cb.video(ctx, buf->alloc_v, w, h) : > + ff_default_get_video_buffer(link, w, h); Does the AVBuffersinkAllocVideoFrameFunc function have access to the AVFilterLink ff_default_get_video_buffer() gets? I assume it'd be needed to get values like pixel format. If so, it should be documented how, but maybe it's easier to just pass link here instead of the AVFilterContext, and let the caller access link->dst if needed. Also, looking at ff_default_get_video_buffer(), a hardware enabled filter may populate hw_frames_ctx, and that's a field only available in the AVFilterLink and that should not be accessed from outside lavfi, which includes a caller defined function used for this callback. > +} > + > +void av_buffersink_set_alloc_video_frame(AVFilterContext *ctx, AVBuffersinkAllocVideoFrameFunc cb, void *v) > +{ > + BufferSinkContext *const buf = ctx->priv; > + buf->alloc_cb.video = cb; > + buf->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..2419d1bd80 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 *(*AVBuffersinkAllocVideoFrameFunc)(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, AVBuffersinkAllocVideoFrameFunc 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 > > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".