]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_overlay_cuda.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / vf_overlay_cuda.c
index 2f0f860e504cc74bd0d1f39cfff31170dd45597b..b91ac9a713e339538b346a2953a4f8d8efe3d4aa 100644 (file)
@@ -63,6 +63,7 @@ typedef struct OverlayCUDAContext {
     enum AVPixelFormat in_format_overlay;
     enum AVPixelFormat in_format_main;
 
+    AVBufferRef *hw_device_ctx;
     AVCUDADeviceContext *hwctx;
 
     CUcontext cu_ctx;
@@ -157,9 +158,12 @@ static int overlay_cuda_blend(FFFrameSync *fs)
     if (ret < 0)
         return ret;
 
-    if (!input_main || !input_overlay)
+    if (!input_main)
         return AVERROR_BUG;
 
+    if (!input_overlay)
+        return ff_filter_frame(outlink, input_main);
+
     ret = av_frame_make_writable(input_main);
     if (ret < 0) {
         av_frame_free(&input_main);
@@ -253,6 +257,9 @@ static av_cold void overlay_cuda_uninit(AVFilterContext *avctx)
         CHECK_CU(cu->cuModuleUnload(ctx->cu_module));
         CHECK_CU(cu->cuCtxPopCurrent(&dummy));
     }
+
+    av_buffer_unref(&ctx->hw_device_ctx);
+    ctx->hwctx = NULL;
 }
 
 /**
@@ -338,13 +345,19 @@ static int overlay_cuda_config_output(AVFilterLink *outlink)
 
     // initialize
 
-    ctx->hwctx = frames_ctx->device_ctx->hwctx;
+    ctx->hw_device_ctx = av_buffer_ref(frames_ctx->device_ref);
+    if (!ctx->hw_device_ctx)
+        return AVERROR(ENOMEM);
+    ctx->hwctx = ((AVHWDeviceContext*)ctx->hw_device_ctx->data)->hwctx;
+
     cuda_ctx = ctx->hwctx->cuda_ctx;
     ctx->fs.time_base = inlink->time_base;
 
     ctx->cu_stream = ctx->hwctx->stream;
 
     outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
+    if (!outlink->hw_frames_ctx)
+        return AVERROR(ENOMEM);
 
     // load functions
 
@@ -422,7 +435,7 @@ static const AVFilterPad overlay_cuda_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vf_overlay_cuda = {
+const AVFilter ff_vf_overlay_cuda = {
     .name            = "overlay_cuda",
     .description     = NULL_IF_CONFIG_SMALL("Overlay one video on top of another using CUDA"),
     .priv_size       = sizeof(OverlayCUDAContext),