[FFmpeg-devel] [PATCH] hevc: If hwccel avoid creation/use of s/w only arrays
Anton Khirnov
anton at khirnov.net
Wed Jun 1 13:29:10 EEST 2022
Quoting John Cox (2022-05-27 15:51:17)
> Hwaccel doesn't use any of the block strength, pcm, slice address, etc.
> arrays which can be >100k each for 4k video. Patch to avoid initial
> allocation and zeroing at the start of every frame. On a Pi4 the memsets
> can use 10% CPU on 4k 60Hz decode, this fixes that.
>
> Signed-off-by: John Cox <jc at kynesim.co.uk>
> ---
> libavcodec/hevc_refs.c | 35 +++++++++++++++++++++--------------
> libavcodec/hevcdec.c | 42 +++++++++++++++++++++++++++++-------------
> 2 files changed, 50 insertions(+), 27 deletions(-)
>
> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> index f782ea6394..48b059ce45 100644
> --- a/libavcodec/hevcdec.c
> +++ b/libavcodec/hevcdec.c
> @@ -504,6 +504,16 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
> if (!sps)
> return 0;
>
> + // If hwaccel then we don't need all the s/w decode helper arrays
> + if (s->avctx->hwaccel) {
> + export_stream_params(s, sps);
> +
> + s->avctx->pix_fmt = pix_fmt;
> + s->ps.sps = sps;
> + s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data;
This duplication is ugly. This code should be commutative, so you can
either move it all above pic_arrays_init() and add an early return
after, or move it all to the end and jump to it with goto.
Otherwise looks reasonable.
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list