[FFmpeg-cvslog] lavfi/vf_*_cuda: do not access hw contexts before checking they exist

Anton Khirnov git at videolan.org
Thu Aug 15 20:44:21 EEST 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Aug  5 12:13:52 2024 +0200| [ce24b5ba8f8d61eae518809e1188f74614db73d5] | committer: Anton Khirnov

lavfi/vf_*_cuda: do not access hw contexts before checking they exist

The checks are performed in init_processing_chain().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ce24b5ba8f8d61eae518809e1188f74614db73d5
---

 libavfilter/vf_bilateral_cuda.c  | 13 ++++++++-----
 libavfilter/vf_chromakey_cuda.c  | 13 ++++++++-----
 libavfilter/vf_colorspace_cuda.c | 14 ++++++++------
 libavfilter/vf_scale_cuda.c      | 13 ++++++++-----
 4 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/libavfilter/vf_bilateral_cuda.c b/libavfilter/vf_bilateral_cuda.c
index ba008b517a..037227af93 100644
--- a/libavfilter/vf_bilateral_cuda.c
+++ b/libavfilter/vf_bilateral_cuda.c
@@ -249,17 +249,20 @@ static av_cold int cuda_bilateral_config_props(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = outlink->src->inputs[0];
     CUDABilateralContext *s  = ctx->priv;
-    AVHWFramesContext     *frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
-    AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
+    AVHWFramesContext     *frames_ctx;
+    AVCUDADeviceContext *device_hwctx;
     int ret;
 
-    s->hwctx = device_hwctx;
-    s->cu_stream = s->hwctx->stream;
-
     ret = init_processing_chain(ctx, inlink->w, inlink->h);
     if (ret < 0)
         return ret;
 
+    frames_ctx   = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
+    device_hwctx = frames_ctx->device_ctx->hwctx;
+
+    s->hwctx = device_hwctx;
+    s->cu_stream = s->hwctx->stream;
+
     outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
 
     // the window_size makes more sense when it is odd, so add 1 if even
diff --git a/libavfilter/vf_chromakey_cuda.c b/libavfilter/vf_chromakey_cuda.c
index ac644caea7..e38521be0d 100644
--- a/libavfilter/vf_chromakey_cuda.c
+++ b/libavfilter/vf_chromakey_cuda.c
@@ -259,13 +259,10 @@ static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = outlink->src->inputs[0];
     ChromakeyCUDAContext *s = ctx->priv;
-    AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
-    AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
+    AVHWFramesContext *frames_ctx;
+    AVCUDADeviceContext *device_hwctx;
     int ret;
 
-    s->hwctx = device_hwctx;
-    s->cu_stream = s->hwctx->stream;
-
     if (s->is_yuv) {
         s->chromakey_uv[0] = s->chromakey_rgba[1];
         s->chromakey_uv[1] = s->chromakey_rgba[2];
@@ -278,6 +275,12 @@ static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
     if (ret < 0)
         return ret;
 
+    frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
+    device_hwctx = frames_ctx->device_ctx->hwctx;
+
+    s->hwctx = device_hwctx;
+    s->cu_stream = s->hwctx->stream;
+
     outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
 
     ret = cudachromakey_load_functions(ctx);
diff --git a/libavfilter/vf_colorspace_cuda.c b/libavfilter/vf_colorspace_cuda.c
index 5ad81e959c..3949cb7ed8 100644
--- a/libavfilter/vf_colorspace_cuda.c
+++ b/libavfilter/vf_colorspace_cuda.c
@@ -226,14 +226,10 @@ static av_cold int cudacolorspace_config_props(AVFilterLink* outlink)
     AVFilterContext* ctx = outlink->src;
     AVFilterLink* inlink = outlink->src->inputs[0];
     CUDAColorspaceContext* s = ctx->priv;
-    AVHWFramesContext* frames_ctx =
-        (AVHWFramesContext*)inlink->hw_frames_ctx->data;
-    AVCUDADeviceContext* device_hwctx = frames_ctx->device_ctx->hwctx;
+    AVHWFramesContext* frames_ctx;
+    AVCUDADeviceContext* device_hwctx;
     int ret;
 
-    s->hwctx = device_hwctx;
-    s->cu_stream = s->hwctx->stream;
-
     outlink->w = inlink->w;
     outlink->h = inlink->h;
 
@@ -241,6 +237,12 @@ static av_cold int cudacolorspace_config_props(AVFilterLink* outlink)
     if (ret < 0)
         return ret;
 
+    frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
+    device_hwctx = frames_ctx->device_ctx->hwctx;
+
+    s->hwctx = device_hwctx;
+    s->cu_stream = s->hwctx->stream;
+
     if (inlink->sample_aspect_ratio.num) {
         outlink->sample_aspect_ratio = av_mul_q(
             (AVRational){outlink->h * inlink->w, outlink->w * inlink->h},
diff --git a/libavfilter/vf_scale_cuda.c b/libavfilter/vf_scale_cuda.c
index 5571a52b1e..68d17072e3 100644
--- a/libavfilter/vf_scale_cuda.c
+++ b/libavfilter/vf_scale_cuda.c
@@ -349,14 +349,11 @@ static av_cold int cudascale_config_props(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = outlink->src->inputs[0];
     CUDAScaleContext *s  = ctx->priv;
-    AVHWFramesContext     *frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
-    AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
+    AVHWFramesContext     *frames_ctx;
+    AVCUDADeviceContext *device_hwctx;
     int w, h;
     int ret;
 
-    s->hwctx = device_hwctx;
-    s->cu_stream = s->hwctx->stream;
-
     if ((ret = ff_scale_eval_dimensions(s,
                                         s->w_expr, s->h_expr,
                                         inlink, outlink,
@@ -377,6 +374,12 @@ static av_cold int cudascale_config_props(AVFilterLink *outlink)
     if (ret < 0)
         return ret;
 
+    frames_ctx   = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
+    device_hwctx = frames_ctx->device_ctx->hwctx;
+
+    s->hwctx = device_hwctx;
+    s->cu_stream = s->hwctx->stream;
+
     if (inlink->sample_aspect_ratio.num) {
         outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
                                                              outlink->w*inlink->h},



More information about the ffmpeg-cvslog mailing list