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 9EFED46F15 for ; Sat, 22 Jul 2023 16:08:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5FDBA68C5A8; Sat, 22 Jul 2023 19:08:27 +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 4C8A668C1CC for ; Sat, 22 Jul 2023 19:08:21 +0300 (EEST) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-3fbc59de009so23819145e9.3 for ; Sat, 22 Jul 2023 09:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kynesim-co-uk.20221208.gappssmtp.com; s=20221208; t=1690042100; x=1690646900; 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=URwgDkKP4HRJFHAz8a04HESlcDj8CmUQQvgzHsoolGA=; b=X1TBQp0yI8wXVL3Tn5NH7kgIsir+QtdRYWgy7yImLq4VQEmLgqUckZxjoDQ9maBPQ2 OQ4E1s3lttRn30eD9nRh7E/E0wJR/kR6/iO7wX4GO5TTGc2R0PtYuRqF8InK2rNV6R6o dNxG6r0AAsW222/YXoRIKxKMtrRkjQJp0TR1VgYm1QsyPZSYnvjqp1+P+tQkVBg4WIUa ZoyYvNKB0e1xbVd3mSyWNcAM7TtUmQM4HvmxDbSlwzSXbnzdI8w2Mr8UTcgUKtxFPNXN /mH10o406sTEhDY4PCgOwEXjBKuho6IiqMlpdTP9Ywf1x2iuwTw7HbLJsUIYKGjBCodo sBig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690042100; x=1690646900; 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=URwgDkKP4HRJFHAz8a04HESlcDj8CmUQQvgzHsoolGA=; b=CGZTw0qmFWOAulKCMvh0cYRWEmBo20Qu8UKviRGpnsDU6bTmLyyZ4T6Z5SALA+/oh+ JDl0fWWJ0n+muBp3MU8VC0/TOuZ90UM1K/jslpcXc/1cKqNPsqe9rCCr5bYnaDuxKjOP C/BKQ3SoW7kggJlo3D3GK7ESp3XEsZJHgF5CO587b3rANjDoypO4jFWKVMaivcVDuxSW y6F0amHktlDq3JR2+itOiS2qljtpsxUUl4tYvE6bYU2tHQ0lxNKIJqxTBAL3AbBFG8OA phPN0qu06CKWyvY8uy16Vt0ZM/Mse3QFLPTJ2FUmn1zF/7IDJkZYDXPfGBB2esCkiNrm p6HA== X-Gm-Message-State: ABy/qLa++WtP+f0kO1X/Yg49VdrrD0wN66qRHgzOJ59zRysH072u0HXy JsMNgnkeXF2cmM2uAy5xQPjE2w== X-Google-Smtp-Source: APBJJlEZEyjuze42imItWr+Q6iFxT84Rk49SGrYAcjLwlIM4lZLgzo0Ei57QKgpao2KwI4vgV5fEMw== X-Received: by 2002:a1c:e908:0:b0:3f8:f1db:d206 with SMTP id q8-20020a1ce908000000b003f8f1dbd206mr3578701wmc.25.1690042100593; Sat, 22 Jul 2023 09:08:20 -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 s19-20020a1cf213000000b003fbaade072dsm5631763wmc.23.2023.07.22.09.08.20 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sat, 22 Jul 2023 09:08:20 -0700 (PDT) From: John Cox To: Paul B Mahol Date: Sat, 22 Jul 2023 17:08:19 +0100 Message-ID: References: <20230720113955.957942-1-jc@kynesim.co.uk> <20230720113955.957942-2-jc@kynesim.co.uk> In-Reply-To: User-Agent: ForteAgent/8.00.32.1272 MIME-Version: 1.0 Subject: Re: [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, Nicolas George , 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: On Sat, 22 Jul 2023 17:28:31 +0200, you wrote: >On Thu, Jul 20, 2023 at 1:40?PM John Cox wrote: > >> Add a callback to enable user allocation of video frames on the final >> stage of a filter chain. >> >> >What about an audio? I have a use case for video and none for audio, but I can add audio if you want. >This works only for sinks mostly, what about filters inside graph? Buffer allocation can already be set by the next filter in the chain which is the callback I am tapping into. If you want to change that then I guess the right answer would be to move get_buffer.video & audio out of AVFilterPad and into somewhere publicly writeable, but I really don't see the need. It seems sensible to me that buffer allocation internal to graphs is negotiated between those filter elements and is opaque to the user and it is only at the point where a buffer is delivered to the user that the user needs to be able to intervene. Regards JC >> 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 >> >> >> -- >> 2.39.2 >> >> _______________________________________________ >> 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".