[FFmpeg-devel] [PATCH] libavcodec/nvdec: Do not exceed 32 surfaces when initializing hw_frames_ctx

Timo Rothenpieler timo at rothenpieler.org
Tue Aug 10 15:04:28 EEST 2021


On 10.08.2021 04:37, Ameer J wrote:
> From: ameerj <52414509+ameerj at users.noreply.github.com>
> 
> nvdec is likely to fail when the initial pool size exceeds 32. This change ensures we don't exceed the limit when initializing a new hw_frames_ctx
> 
> Signed-off-by: ameerj <52414509+ameerj at users.noreply.github.com>
> ---
>   libavcodec/nvdec.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
> index 251be039a8..bef33dbae9 100644
> --- a/libavcodec/nvdec.c
> +++ b/libavcodec/nvdec.c
> @@ -303,8 +303,10 @@ static int nvdec_init_hwframes(AVCodecContext *avctx, AVBufferRef **out_frames_r
>       frames_ctx = (AVHWFramesContext*)(*out_frames_ref)->data;
>   
>       if (dummy) {
> -        // Copied from ff_decode_get_hw_frames_ctx for compatibility
> -        frames_ctx->initial_pool_size += 3;
> +        // The function above guarantees 1 work surface, We must guarantee 4 work surfaces.
> +        // (the absolute minimum), so add the missing count without exceeding the maximum
> +        // recommended for nvdec.
> +        frames_ctx->initial_pool_size = min(frames_ctx->initial_pool_size + 3, 32);

Where does this min() function come from?

>           frames_ctx->free = nvdec_free_dummy;
>           frames_ctx->pool = av_buffer_pool_init(0, nvdec_alloc_dummy);
> 

So far, the 32 surface limit has only ever been enforced as a soft 
limit, and a warning printed when exceeded. Since it being a limit is 
not strictly documented and it might be risen in the future.

Also, if the pool is limited in size, something is likely to fail due to 
that further down the chain.
So I'm not sure if this is a better solution.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4494 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210810/7d277bce/attachment.bin>


More information about the ffmpeg-devel mailing list