Re: [FFmpeg-devel] [PATCH 2/2] avcodec/nvdec: make explicit copy of frames unless user requested otherwise

2022-12-06 Thread Philip Langdale
On Mon,  5 Dec 2022 23:25:59 +0100
Timo Rothenpieler  wrote:

> ---
>  libavcodec/nvdec.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
> index fbaedf0b6b..76ee395734 100644
> --- a/libavcodec/nvdec.c
> +++ b/libavcodec/nvdec.c
> @@ -51,6 +51,8 @@ typedef struct NVDECDecoder {
>  
>  CudaFunctions *cudl;
>  CuvidFunctions *cvdl;
> +
> +int minimize_copies;
>  } NVDECDecoder;
>  
>  typedef struct NVDECFramePool {
> @@ -344,6 +346,8 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
>  int cuvid_codec_type, cuvid_chroma_format, chroma_444;
>  int ret = 0;
>  
> +int minimize_copies = !!(avctx->hwaccel_flags &
> AV_HWACCEL_FLAG_MINIMIZE_COPIES); +
>  sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
>  if (!sw_desc)
>  return AVERROR_BUG;
> @@ -402,7 +406,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
>  params.CodecType   = cuvid_codec_type;
>  params.ChromaFormat= cuvid_chroma_format;
>  params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
> -params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
> +params.ulNumOutputSurfaces = minimize_copies ?
> frames_ctx->initial_pool_size : 1; 
>  ret = nvdec_decoder_create(>decoder_ref,
> frames_ctx->device_ref, , avctx); if (ret < 0) {
> @@ -417,6 +421,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
>  }
>  
>  decoder = (NVDECDecoder*)ctx->decoder_ref->data;
> +decoder->minimize_copies = minimize_copies;
>  decoder->real_hw_frames_ref = real_hw_frames_ref;
>  real_hw_frames_ref = NULL;
>  
> @@ -554,7 +559,11 @@ copy_fail:
>  
>  finish:
>  CHECK_CU(decoder->cudl->cuCtxPopCurrent());
> -return ret;
> +
> +if (ret < 0 || decoder->minimize_copies)
> +return ret;
> +
> +return av_frame_make_writable(frame);
>  }
>  
>  int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)

LGTM.


--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] avcodec/nvdec: make explicit copy of frames unless user requested otherwise

2022-12-05 Thread Timo Rothenpieler
---
 libavcodec/nvdec.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index fbaedf0b6b..76ee395734 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -51,6 +51,8 @@ typedef struct NVDECDecoder {
 
 CudaFunctions *cudl;
 CuvidFunctions *cvdl;
+
+int minimize_copies;
 } NVDECDecoder;
 
 typedef struct NVDECFramePool {
@@ -344,6 +346,8 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
 int cuvid_codec_type, cuvid_chroma_format, chroma_444;
 int ret = 0;
 
+int minimize_copies = !!(avctx->hwaccel_flags & 
AV_HWACCEL_FLAG_MINIMIZE_COPIES);
+
 sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
 if (!sw_desc)
 return AVERROR_BUG;
@@ -402,7 +406,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
 params.CodecType   = cuvid_codec_type;
 params.ChromaFormat= cuvid_chroma_format;
 params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
-params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
+params.ulNumOutputSurfaces = minimize_copies ? 
frames_ctx->initial_pool_size : 1;
 
 ret = nvdec_decoder_create(>decoder_ref, frames_ctx->device_ref, 
, avctx);
 if (ret < 0) {
@@ -417,6 +421,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
 }
 
 decoder = (NVDECDecoder*)ctx->decoder_ref->data;
+decoder->minimize_copies = minimize_copies;
 decoder->real_hw_frames_ref = real_hw_frames_ref;
 real_hw_frames_ref = NULL;
 
@@ -554,7 +559,11 @@ copy_fail:
 
 finish:
 CHECK_CU(decoder->cudl->cuCtxPopCurrent());
-return ret;
+
+if (ret < 0 || decoder->minimize_copies)
+return ret;
+
+return av_frame_make_writable(frame);
 }
 
 int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".