Message ID | a398f5f4-bb3e-44bb-be9b-e37e1bced2e0@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v2] avcodec/cuviddec: update parser ulMaxNumDecodeSurfaces | expand |
Context | Check | Description |
---|---|---|
andriy/configure_x86 | warning | Failed to apply patch |
yinshiyou/configure_loongarch64 | warning | Failed to apply patch |
On 11.08.2023 19:50, Random Joe wrote: > Fixes video output stutter caused by different number of buffers in > decoder vs parser introduced in 402d98c. > > Signed-off-by: Random Joe <ff.random.joe@gmail.com> > --- > libavcodec/cuviddec.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c > index 814bc53f70..1b62832eca 100644 > --- a/libavcodec/cuviddec.c > +++ b/libavcodec/cuviddec.c > @@ -360,7 +360,14 @@ static int CUDAAPI cuvid_handle_video_sequence(void > *opaque, CUVIDEOFORMAT* form > } > } > > - return 1; > + // make CUVIDDECODECREATEINFO::ulNumDecodeSurfaces = > CUVIDPARSERPARAMS::ulMaxNumDecodeSurfaces > + // returning a value > 1 , will notify the driver to set the > parser ulMaxNumDecodeSurfaces > + // to this return value . > + > + if(ctx->cuparseinfo.ulMaxNumDecodeSurfaces != > cuinfo.ulNumDecodeSurfaces) > + return cuinfo.ulNumDecodeSurfaces; > + else > + return 1; Any reason to not just always return nb_surfaces here? I don't really understand why this would cause stuttering though. It might waste a bit of memory to always set the maximum number to the allowed maximum, but why would it hurt performance? > } > > static int CUDAAPI cuvid_handle_picture_decode(void *opaque, > CUVIDPICPARAMS* picparams) > @@ -1022,7 +1029,9 @@ static av_cold int > cuvid_decode_init(AVCodecContext *avctx) > goto error; > } > > - ctx->cuparseinfo.ulMaxNumDecodeSurfaces = ctx->nb_surfaces; > + // set ulMaxNumDecodeSurfaces to a dummy value of 1 as recommended > in NVDEC Programming Guide > + // set the optimal value in pfnSequenceCallback where > CUVIDEOFORMAT::min_num_decode_surfaces is reported > + ctx->cuparseinfo.ulMaxNumDecodeSurfaces = 1; > ctx->cuparseinfo.ulMaxDisplayDelay = (avctx->flags & > AV_CODEC_FLAG_LOW_DELAY) ? 0 : CUVID_MAX_DISPLAY_DELAY; > ctx->cuparseinfo.pUserData = avctx; > ctx->cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence;
Only update ulMaxNumDecodeSurfaces if necessary. As for the stutter , I can't tell for sure , maybe it's a race condition somewhere in the driver. 402d98c decoupled cuvid parser and decoder number of decode buffers , with parser buffers set to be always CUVID_DEFAULT_NUM_SURFACES (5). In NVDEC Programming Guide they recommend setting an equal number of buffers for parser and decoder. Here are my test outputs and logs , edited memory pointers for better files comparison : https://drive.google.com/drive/folders/1f0ehcNxQV-0sMvm2g66J97kHxAGeRKUT On Sat, Aug 12, 2023 at 12:15 AM Timo Rothenpieler <timo@rothenpieler.org> wrote: > > On 11.08.2023 19:50, Random Joe wrote: > Any reason to not just always return nb_surfaces here? > I don't really understand why this would cause stuttering though. It > might waste a bit of memory to always set the maximum number to the > allowed maximum, but why would it hurt performance? >
diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c index 814bc53f70..1b62832eca 100644 --- a/libavcodec/cuviddec.c +++ b/libavcodec/cuviddec.c @@ -360,7 +360,14 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form } } - return 1; + // make CUVIDDECODECREATEINFO::ulNumDecodeSurfaces = CUVIDPARSERPARAMS::ulMaxNumDecodeSurfaces + // returning a value > 1 , will notify the driver to set the parser ulMaxNumDecodeSurfaces + // to this return value . + + if(ctx->cuparseinfo.ulMaxNumDecodeSurfaces != cuinfo.ulNumDecodeSurfaces) + return cuinfo.ulNumDecodeSurfaces; + else + return 1; } static int CUDAAPI cuvid_handle_picture_decode(void *opaque, CUVIDPICPARAMS* picparams) @@ -1022,7 +1029,9 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) goto error; } - ctx->cuparseinfo.ulMaxNumDecodeSurfaces = ctx->nb_surfaces; + // set ulMaxNumDecodeSurfaces to a dummy value of 1 as recommended in NVDEC Programming Guide + // set the optimal value in pfnSequenceCallback where CUVIDEOFORMAT::min_num_decode_surfaces is reported + ctx->cuparseinfo.ulMaxNumDecodeSurfaces = 1; ctx->cuparseinfo.ulMaxDisplayDelay = (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : CUVID_MAX_DISPLAY_DELAY; ctx->cuparseinfo.pUserData = avctx; ctx->cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence;
Fixes video output stutter caused by different number of buffers in decoder vs parser introduced in 402d98c. Signed-off-by: Random Joe <ff.random.joe@gmail.com> --- libavcodec/cuviddec.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)