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 72E0646F2A for ; Sat, 22 Jul 2023 19:27:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5D31A68C627; Sat, 22 Jul 2023 22:27:43 +0300 (EEST) Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0640A68C508 for ; Sat, 22 Jul 2023 22:27:36 +0300 (EEST) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-521dc8ae899so4011364a12.3 for ; Sat, 22 Jul 2023 12:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690054056; x=1690658856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cBEIjvZHARjJAeI20MJKMNyz+D7e8TVkN/OorZef5u8=; b=VIM8BY8J0mGcWatejp85SLsUM46K9C6ZPn4LeXIGrTMv9rWLIYMDZ12KTMsrC7sWce J73C8/+SupgpIHPkdQAfXsGorinVSdU/8xqaUhCQgk00y4zgDic4FlIMp5+ZH4xzaWsy G461AJFG68eNTxCo1VxzFumoWb486tNiP+acb7WiEixugtjBDAbrbMDexhUbD5IaDRen mKvaigjQH3XwU+vDkE4WV0SLYAYb2AUH2S32gPzleMOvH/uXF+UfQtPoz1M2x50kZySW aiiIlWpNHw3TTYpHhufLxDXkiZruLkLum5UjMhTPvGg+1b/1gT/8x3/f4As4DBHZHkSS uBlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690054056; x=1690658856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cBEIjvZHARjJAeI20MJKMNyz+D7e8TVkN/OorZef5u8=; b=WHIIhrO4CbF2EsZFes0aEu3z0dfGVYqwhYfJv1wH2JBbfEzn9MRP3A7v88sa2Ko/Ex e4AnHW3Qo2Lo2G/JD6qIMeiNc+j47NsYKFpWmkBw5EwHlctPq+XV7Nr8UOm3ENuRf9+s 5jjkWq/dVvr/fms9El6rraQs3Q8PzEn7A/4hmTPOS2cc8u6XY2efUdzYap0ipoLmaLgm XlitKfFW+zMpTGaBVR6RGch62DLye75GSYbX1e5yJJynWOVh7zsnk4SXDszwuu4TbA9K FEcFbwiL3iJ27kzD2khlabhZL/z0uH9lzbOQ7urBfHhqQDPBqFpKVMLKcvakfJYiij/7 QDzg== X-Gm-Message-State: ABy/qLZvq7QIilyb6hq4kieZS0YycN1e/I1gljvwXeLjUtj1Sj2ieygU absOiyAQR9uIoJWz3afLFr/Y5DO+1bUMww== X-Google-Smtp-Source: APBJJlGVIggS5rF/NlhfFSO/NYJrGeQRItzmqJSs4jeCGpNklyQArit3ZUrsVEoZRqG5CNiah/gVmw== X-Received: by 2002:a17:906:7394:b0:994:1806:fb96 with SMTP id f20-20020a170906739400b009941806fb96mr5547535ejl.16.1690054056155; Sat, 22 Jul 2023 12:27:36 -0700 (PDT) Received: from [192.168.1.104] (84-112-104-25.cable.dynamic.surfer.at. [84.112.104.25]) by smtp.gmail.com with ESMTPSA id d6-20020a1709067f0600b009925cbafeaasm3920987ejr.100.2023.07.22.12.27.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jul 2023 12:27:35 -0700 (PDT) From: Marvin Scholz To: FFmpeg development discussions and patches Date: Sat, 22 Jul 2023 21:27:34 +0200 X-Mailer: MailMate (1.14r5964) Message-ID: <42ECB9E4-3BED-4A8D-962C-182A265B9D18@gmail.com> In-Reply-To: References: <20230722164157.964161-1-jc@kynesim.co.uk> <20230722164157.964161-2-jc@kynesim.co.uk> MIME-Version: 1.0 Subject: Re: [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 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 22 Jul 2023, at 21:10, John Cox wrote: > On Sat, 22 Jul 2023 20:54:04 +0200, you wrote: > >> On 22 Jul 2023, at 18:41, 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..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 >> >> Nit: >> >> You can use @ref av_buffersink_set_alloc_video_frame or even >> shorter ::av_buffersink_set_alloc_video_frame to get a proper >> reference to that function that will be linked. > > Thanks - will do - Is documentation built from this? I had a quick look > to see if I could find some output to verify what I'd done but I failed > to find it. You can generate it (if you have doxygen installed) by running: make apidoc and it will end up in doc/doxy/html. > >>> + * @param w width of frame to allocate >>> + * @param height of frame to allocate >>> + * >>> + * @return >>> + * - The newly allocated frame >>> + * - NULL if error >> >> Nit: >> >> This can use retval, for example like that: >> >> @retval AVFrame* The newly allocated frame >> @retval NULL Error allocating the frame > > Will do. > > Ta > > JC > >>> + */ >>> +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". > _______________________________________________ > 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".