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 A658F46F68 for ; Sun, 23 Jul 2023 19:03:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE6FB68C709; Sun, 23 Jul 2023 22:03:52 +0300 (EEST) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 20B4E68C67F for ; Sun, 23 Jul 2023 22:03:46 +0300 (EEST) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-3fbc59de0e2so28182595e9.3 for ; Sun, 23 Jul 2023 12:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kynesim-co-uk.20221208.gappssmtp.com; s=20221208; t=1690139025; x=1690743825; h=content-transfer-encoding:mime-version:user-agent:in-reply-to :references:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=rGWgVBYemjooqY9hx47KftIvrajP+InSWWobcYdhCN4=; b=ImWF0kCVdr5yA0uzoeG5ByQBfUyCDvir1gKEkZ+fuSOBKGejYV4wUWaEuKfdBcZPL0 fI06fmlZn9Xm+bNKZe5S2ncc/HghjJi2pJubfViOV4ak2ECxTWaI8bocq1psPmcMybcZ MKdJZxRpX5VWA6CZMoJvYrdw4Dm8xPrz02O6++GYbNOYu0taxI4GSNRo8TeWVyF7PNZ2 hxIJC7ZTUkmzic+gsg0vIFGuk4XitdNowMv4DSW5JkGhrg5IlDPkSt7TU8hrxmPBXBox EQwIslmnijmj98CH4zZc+cPPBE4tUXpExb6OVmS9+xs2c9sjKxnRXPA2FcoV4OmaoRGv TA7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690139025; x=1690743825; h=content-transfer-encoding:mime-version:user-agent:in-reply-to :references:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rGWgVBYemjooqY9hx47KftIvrajP+InSWWobcYdhCN4=; b=UowgqZtHxKCUFBcKZ1p07xemktQ/uWZTSS3C4RoKBhhsUROhWv6jTyTIoDFvJyDF3t A5WxGf5qwKg7OWkQP2FGKNmnhyMP5tLCpJlboAN+/Bl10wdwuIJ7quQJSAWhK0P01wWa sk8lAzlLqlpOTtuCVAZQBE9LFkRx5IDSC4OOGYV2XeGCvPDhuC94npYj39VCuyJYVNUP 4v0t9qeTGb/dEnuuKJsMlqvTtCH1SPKpD6diG0S9RZfYmWpabPbqyQ/wU/l3Bse3d9Ru lhf6hYZ+CybLd+NXyTkk99/OO7nZ6bksO62cMVBYgSvpRrv/vUrZItyFLjUAWGD1mBCp H/bg== X-Gm-Message-State: ABy/qLaP1q14ZUhXDfj/zuvG2SIVYT9n3DcgWenuDlcipB3uakpIP6fo rurYjhVwBVtACqmHhjMRCKLS/9ZCdM+7R0O3+KM= X-Google-Smtp-Source: APBJJlGM4qBuxcA1B3GQ6Bi0ZBnQAFCNMwvAWT7wkszI91SfM9wqwpjbk32LW2XkVppmVQB5pqsoiQ== X-Received: by 2002:a05:600c:2802:b0:3fb:c462:1833 with SMTP id m2-20020a05600c280200b003fbc4621833mr5863004wmb.30.1690139025240; Sun, 23 Jul 2023 12:03:45 -0700 (PDT) Received: from CTHALPA.outer.uphall.net (cpc1-cmbg20-2-0-cust759.5-4.cable.virginm.net. [86.21.218.248]) by smtp.gmail.com with ESMTPSA id g8-20020a7bc4c8000000b003fa8158135esm11124519wmk.11.2023.07.23.12.03.44 for (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 23 Jul 2023 12:03:44 -0700 (PDT) From: John Cox To: FFmpeg development discussions and patches Cc: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Jul 2023 20:03:44 +0100 Message-ID: References: <20230722170357.964313-1-jc@kynesim.co.uk> <20230722170357.964313-2-jc@kynesim.co.uk> <48dc91a8-5da0-d074-386d-4a095651afaa@gmail.com> In-Reply-To: <48dc91a8-5da0-d074-386d-4a095651afaa@gmail.com> User-Agent: ForteAgent/8.00.32.1272 MIME-Version: 1.0 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Hi >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. Unless I'm misreading stuff you can get at AVFilterLink from from AVFilterContext so I think AVFilterContext is good. If you are suggesting that the documentation of AVFilterContext & Link could be improved I feel that is outside the scope of this patch. >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. I'm afraid I don't quite understand what you are suggesting here. What would you have me do differently? Regards JC >> +} >> + >> +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". _______________________________________________ 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".