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 E102B46F1A for ; Sat, 22 Jul 2023 17:04:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4CB6868C638; Sat, 22 Jul 2023 20:04:22 +0300 (EEST) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8418368C614 for ; Sat, 22 Jul 2023 20:04:16 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-314319c0d3eso2554624f8f.0 for ; Sat, 22 Jul 2023 10:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kynesim-co-uk.20221208.gappssmtp.com; s=20221208; t=1690045456; x=1690650256; 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=eyl1coqdee/+EJ/8VIaMU7GyvNZd8C4h+GyLndXWeCQ=; b=eBxYXQcdcc9NdFg497dWmAV+m+3FxUqPq6CEVQEnWqy6t6GKPOpjDo+asJ/eD6djQD FevNGXLDhI0tePeMcAFwF0fYPAxJvTmS66wNNb0Z+TvFb5NkqwDNj7nMWqeTKdxBjaDp r+5I/9BVVogSOZawBcO1GH9xrA6taikl9klG8o6lR6cgJZZURV2XQltfWFvzZtiXSXh5 70qGXlt22L3v7yydx000hWf8tJb9ScDD9zUWO6vmGXVac51IdLQ1RYLznyBPIGsF+73g 28kJhiIv2G3uiNYT++L+cHmCYROB3v/Se1X0hskGyfRO8pcpuBYJM4BTgYGkv2VQtCYB U0mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690045456; x=1690650256; 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=eyl1coqdee/+EJ/8VIaMU7GyvNZd8C4h+GyLndXWeCQ=; b=N5yR+EbHioeqFHVf3fGiPXVe5z/pBsimvj8bDCuVETgMVtEdk1h13SpPlzrbJp7shm BJVJbfcvueSD0sqS2SyfM9S2QmpDQpcRhmSh+YnJtVYZ7Tp6zYJsPJsG67i+1GGRmeKV 7lTncrdXLaQL6Za78YnyBI5EbdmUMthnwLl51QZ1JFRLE8yoKKo/4QjXjudwEvGHJ3Uo AcJSEdJNPG2qwvPltVUE6Z9zC84X2YoYgBx32aChgKAWW7qwZdjP4IJ4p02lNDOgCj4b QYtNiPD462n2hReYrGdhxU70DKqdQ1jxBIrwjcBwi6ulVoYK16nK8KsiRlP4BBPKqIPd Wl3Q== X-Gm-Message-State: ABy/qLZZruBE+70l/e1kGG/Qjhm1iySN4Gop+1jUfXweR6ClKhWT/WBx Ha5cDZ4gmAXYLpYe6zwZ2gWFk+qHx4dOaVO4XcI= X-Google-Smtp-Source: APBJJlEF5p4myItdkWRD2itDlvwU2rD79B1xRDFjGxlWEx1QKL34XRR10X4y+MCkfeCXtn5T402DDw== X-Received: by 2002:adf:dd4d:0:b0:314:350a:6912 with SMTP id u13-20020adfdd4d000000b00314350a6912mr4270478wrm.36.1690045455816; Sat, 22 Jul 2023 10:04:15 -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 y13-20020a05600c364d00b003fbb25da65bsm5726449wmq.30.2023.07.22.10.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 10:04:15 -0700 (PDT) From: John Cox To: ffmpeg-devel@ffmpeg.org Date: Sat, 22 Jul 2023 17:03:57 +0000 Message-Id: <20230722170357.964313-2-jc@kynesim.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230722170357.964313-1-jc@kynesim.co.uk> References: <20230722170357.964313-1-jc@kynesim.co.uk> MIME-Version: 1.0 Subject: [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 Cc: stefasab@gmail.com, John Cox 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: 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); +} + +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 -- 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".