[vlc-devel] [PATCH 21/23] nvdec: don't keep the decoder_device_nvdec_t in the picture context

Steve Lhomme robux4 at ycbcr.xyz
Thu Nov 7 10:31:36 CET 2019


---
 modules/hw/nvdec/chroma.c    | 21 +++++++++++++++++++--
 modules/hw/nvdec/nvdec.c     |  3 ---
 modules/hw/nvdec/nvdec_fmt.h |  3 ---
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/modules/hw/nvdec/chroma.c b/modules/hw/nvdec/chroma.c
index eddc91098f6..84e0f58daaf 100644
--- a/modules/hw/nvdec/chroma.c
+++ b/modules/hw/nvdec/chroma.c
@@ -32,6 +32,7 @@
 #include "nvdec_fmt.h"
 
 static int OpenCUDAToCPU( vlc_object_t * );
+static void CloseCUDAToCPU( vlc_object_t * );
 
 vlc_module_begin()
     set_shortname(N_("CUDA converter"))
@@ -39,7 +40,7 @@ vlc_module_begin()
     set_category(CAT_VIDEO)
     set_subcategory(SUBCAT_VIDEO_VFILTER)
     set_capability("video converter", 10)
-    set_callbacks(OpenCUDAToCPU, NULL)
+    set_callbacks(OpenCUDAToCPU, CloseCUDAToCPU)
 vlc_module_end()
 
 typedef struct
@@ -60,7 +61,8 @@ static picture_t * FilterCUDAToCPU( filter_t *p_filter, picture_t *src )
     }
 
     pic_context_nvdec_t *srcpic = container_of(src->context, pic_context_nvdec_t, ctx);
-    decoder_device_nvdec_t *devsys = &srcpic->nvdecDevice;
+    nvdec_filter_sys_t *p_sys = p_filter->p_sys;
+    decoder_device_nvdec_t *devsys = p_sys->device->opaque;
 
     int result;
     result = CALL_CUDA(cuCtxPushCurrent, devsys->cuCtx);
@@ -115,7 +117,22 @@ static int OpenCUDAToCPU( vlc_object_t *p_this )
            ) )
         return VLC_EGENERIC;
 
+    nvdec_filter_sys_t *p_sys = vlc_obj_malloc(VLC_OBJECT(p_filter), sizeof(*p_sys));
+    if (unlikely(p_sys==NULL))
+        return VLC_ENOMEM;
+
+    p_sys->device = vlc_video_context_HoldDevice(p_filter->vctx_in);
+    assert(p_sys->device && p_sys->device->type == VLC_DECODER_DEVICE_NVDEC);
+
     p_filter->pf_video_filter = FilterCUDAToCPU;
+    p_filter->p_sys = p_sys;
 
     return VLC_SUCCESS;
 }
+
+static void CloseCUDAToCPU( vlc_object_t *p_this )
+{
+    filter_t *p_filter = (filter_t *)p_this;
+    nvdec_filter_sys_t *p_sys = p_filter->p_sys;
+    vlc_decoder_device_Release(p_sys->device);
+}
diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index 75bc54b06b1..df957b98dfb 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -331,7 +331,6 @@ static struct picture_context_t *NVDecCtxClone(struct picture_context_t *srcctx)
     clonectx->devidePtr = srcpic->devidePtr;
     clonectx->bufferPitch = srcpic->bufferPitch;
     clonectx->bufferHeight = srcpic->bufferHeight;
-    clonectx->nvdecDevice = srcpic->nvdecDevice;
     return &clonectx->ctx;
 }
 
@@ -381,8 +380,6 @@ static int CUDAAPI HandlePictureDisplay(void *p_opaque, CUVIDPARSERDISPINFO *p_d
         picctx->devidePtr = p_sys->outputDevicePtr[pool_idx];
         picctx->bufferPitch = p_sys->outputPitch;
         picctx->bufferHeight = p_sys->decoderHeight;
-        picctx->nvdecDevice.cuCtx = p_sys->cuCtx;
-        picctx->nvdecDevice.cudaFunctions = p_sys->cudaFunctions;
 
         size_t srcY = 0;
         size_t dstY = 0;
diff --git a/modules/hw/nvdec/nvdec_fmt.h b/modules/hw/nvdec/nvdec_fmt.h
index 1668ad3696b..f1e471c7790 100644
--- a/modules/hw/nvdec/nvdec_fmt.h
+++ b/modules/hw/nvdec/nvdec_fmt.h
@@ -65,9 +65,6 @@ typedef struct
     CUdeviceptr  devidePtr;
     unsigned int bufferPitch;
     unsigned int bufferHeight;
-
-    // temporary until the filters get it from their environment/video context
-    decoder_device_nvdec_t nvdecDevice;
 } pic_context_nvdec_t;
 
 #endif /* include-guard */
-- 
2.17.1



More information about the vlc-devel mailing list