From: John Cox <jc@kynesim.co.uk> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH v3 1/1] avfilter/buffersink: Add video frame allocation callback Date: Sun, 23 Jul 2023 20:03:44 +0100 Message-ID: <v2uqbihb3e824b3njdgadncbp3b549j1ue@4ax.com> (raw) In-Reply-To: <48dc91a8-5da0-d074-386d-4a095651afaa@gmail.com> 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 <jc@kynesim.co.uk> >> --- >> 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".
next prev parent reply other threads:[~2023-07-23 19:03 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-22 17:03 [FFmpeg-devel] [PATCH v3 0/1] avfilter/buffersink: Add user video frame allocation John Cox 2023-07-22 17:03 ` [FFmpeg-devel] [PATCH v3 1/1] avfilter/buffersink: Add video frame allocation callback John Cox 2023-07-22 19:14 ` Andreas Rheinhardt 2023-07-23 8:23 ` John Cox 2023-07-23 8:32 ` Andreas Rheinhardt 2023-07-23 17:21 ` James Almer 2023-07-23 19:03 ` John Cox [this message] 2023-07-23 19:06 ` Nicolas George 2023-07-23 19:16 ` James Almer 2023-07-23 19:26 ` Nicolas George 2023-07-23 19:40 ` Paul B Mahol 2023-07-23 19:36 ` Nicolas George 2023-07-23 19:45 ` Paul B Mahol 2023-07-24 8:21 ` Nicolas George 2023-07-24 9:07 ` Paul B Mahol 2023-07-24 18:24 ` James Almer 2023-07-23 19:52 ` Paul B Mahol 2023-07-23 20:04 ` James Almer 2023-07-24 18:04 ` Kieran Kunhya 2023-07-25 11:41 ` John Cox
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=v2uqbihb3e824b3njdgadncbp3b549j1ue@4ax.com \ --to=jc@kynesim.co.uk \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git