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 9BC79465CA for ; Sat, 22 Jul 2023 15:13:01 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D5F5A68C51E; Sat, 22 Jul 2023 18:12:58 +0300 (EEST) Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9442568C068 for ; Sat, 22 Jul 2023 18:12:52 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 36MFCpJR019737 ; Sat, 22 Jul 2023 17:12:51 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 20D4FEB5B7; Sat, 22 Jul 2023 17:12:51 +0200 (CEST) Date: Sat, 22 Jul 2023 17:12:51 +0200 From: Nicolas George To: FFmpeg development discussions and patches Message-ID: References: <20230720113955.957942-1-jc@kynesim.co.uk> <20230720113955.957942-2-jc@kynesim.co.uk> MIME-Version: 1.0 In-Reply-To: <20230720113955.957942-2-jc@kynesim.co.uk> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Sat, 22 Jul 2023 17:12:51 +0200 (CEST) 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, John Cox Content-Type: multipart/mixed; boundary="===============6570998679181209191==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============6570998679181209191== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="m1oVCAm71bkL/YIT" Content-Disposition: inline --m1oVCAm71bkL/YIT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable John Cox (12023-07-20): > Add a callback to enable user allocation of video frames on the final > stage of a filter chain. >=20 > Signed-off-by: John Cox > --- > libavfilter/buffersink.c | 21 +++++++++++++++++++++ > libavfilter/buffersink.h | 27 +++++++++++++++++++++++++++ > libavfilter/version.h | 2 +- > 3 files changed, 49 insertions(+), 1 deletion(-) Hi. Thanks for the patch. >=20 > 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; > =20 > AVFrame *peeked_frame; > + > + union { > + av_buffersink_alloc_video_frame * video; > + } alloc_cb; > + void * alloc_v; Here and everywhere: our coding style puts a space before the * but not after. > } BufferSinkContext; > =20 > #define NB_ITEMS(list) (list ## _size / sizeof(*list)) > @@ -154,6 +159,21 @@ int attribute_align_arg av_buffersink_get_samples(AV= FilterContext *ctx, > return get_frame_internal(ctx, frame, 0, nb_samples); > } > =20 > +static AVFrame * alloc_video_buffer(AVFilterLink *link, int w, int h) > +{ > + AVFilterContext * const ctx =3D link->dst; > + BufferSinkContext * const bs =3D ctx->priv; Nit: it is called buf in the rest of this file. > + return bs->alloc_cb.video ? bs->alloc_cb.video(ctx, bs->alloc_v, w, = h) : > + ff_default_get_video_buffer(link, w, h); Nit: align ff_ with bs->. > +} > + > +void av_buffersink_set_alloc_video_frame(AVFilterContext *ctx, av_buffer= sink_alloc_video_frame * cb, void * v) > +{ > + BufferSinkContext * const bs =3D ctx->priv; > + bs->alloc_cb.video =3D cb; > + bs->alloc_v =3D v; > +} > + > static av_cold int common_init(AVFilterContext *ctx) > { > BufferSinkContext *buf =3D ctx->priv; > @@ -381,6 +401,7 @@ static const AVFilterPad avfilter_vsink_buffer_inputs= [] =3D { > { > .name =3D "default", > .type =3D AVMEDIA_TYPE_VIDEO, > + .get_buffer =3D {.video =3D alloc_video_buffer}, > }, > }; > =20 > 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, AV= Frame *frame); > */ > int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int = nb_samples); > =20 > +/** > + * Callback from av_buffersink_set_alloc_video_frame to allocate=20 > + * a frame=20 > + * =20 > + * @param ctx pointer to a context of the abuffersink AVFilter. > + * @param v opaque pointer passed to=20 > + * av_buffersink_set_alloc_video_frame > + * @param w width of frame to allocate=20 > + * @param height of frame to allocate=20 > + * =20 > + * @return=20 > + * - The newly allocated frame > + * - NULL if error > + */ > +typedef AVFrame * av_buffersink_alloc_video_frame(AVFilterContext * ctx,= void * v, int w, int h); In the rest of the API, function typedefs are always pointer-to-function typedefs. Also, I find this typedef looks too much like actually a function, maybe use CamelCase. > + > +/** > + * 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=20 > + * 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_buffer= sink_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 @@ > =20 > #include "version_major.h" > =20 > -#define LIBAVFILTER_VERSION_MINOR 8 > +#define LIBAVFILTER_VERSION_MINOR 9 > #define LIBAVFILTER_VERSION_MICRO 102 A test program would be nice too. I assume you have something to test your code: would it be a lot of work to make it public? Regards, --=20 Nicolas George --m1oVCAm71bkL/YIT Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE6ooRQGBoNzw0KnwPcZVLI8pNxgwFAmS78fEACgkQcZVLI8pN xgyL8RAAr48J2GQjm6ITeQqGIdFGRw6kA67M/jPnTSVJJVpMOtl7FWi0dlfuvdyZ xDww8bPDD9ABlea0YnY5abnpqIso5iypBedHE82+kCHKJWII7+q8Eh1yVvpRy98w T4sQuFLYAISko3oDtSdYHZ8BrSdD4z3iOIz2hfRfsbzgVQKrR/qDaqaja6dcOphK i1ijrA4ESjLcMxMnCVi8ia7zwOee3jA9z3nUInDg/ZMUJykQp9rP9MRlM7ZviErb d4lwIohrZ3AkgJZvzG/lNccxVfVHsGa5Azw1HFCy97ARTPhc3Odyf3sfTeyFlE13 O66KE2cEEKdef4WkBjlJo8nkO6dOrfmbPhv9e9Jg1SG6+4K3BQmA6TqpuPTloNhw qIn7S5VEcwpf928AHW+oyb+QF9cxaMMhPc17B33nmALL7VbvPY+V+UmUJ25x0P33 9Qy3SCZqkvcl5rVTkBlEU8cBunaAklXME8zlekHrZhPoiYfgiZClvdTaFxK/ecsg zh2t5Iw85rs6QKd41ok9ASg12VLIP9zCuzF928PIBmMufXnLKj492TRhDT2vz24G Zf+enInzJds0uDAfGd3zQ3UZjgPAs8Is9QpPGJx/8EjKL+7uoId064bkXY1gLGft cNx3+RZ2jwWC6cs89uiM8eMeIdL+zNcWO8QhtdY7neOsSffC9fs= =yqij -----END PGP SIGNATURE----- --m1oVCAm71bkL/YIT-- --===============6570998679181209191== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============6570998679181209191==--