[vlc-devel] [PATCH 26/32] nvdec: create a video context for the decoder

Steve Lhomme robux4 at ycbcr.xyz
Thu Sep 26 16:00:17 CEST 2019


---
 modules/hw/nvdec/nvdec.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index b0f46f83b60..68319e11fcb 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -100,6 +100,8 @@ typedef struct nvdec_ctx {
     CUdeviceptr                 outputDevicePtr[MAX_POOL_SIZE];
     unsigned int                outputPitch;
     picture_pool_t              *out_pool;
+
+    vlc_video_context           *vctx_out;
 } nvdec_ctx_t;
 
 #define CALL_CUDA_DEC(func, ...) CudaCheckErr(VLC_OBJECT(p_dec),  p_sys->cudaFunctions, p_sys->cudaFunctions->func(__VA_ARGS__), #func)
@@ -288,7 +290,7 @@ clean_pics:
 
     CALL_CUDA_DEC(cuCtxPopCurrent, NULL);
 
-    ret = decoder_UpdateVideoFormat(p_dec);
+    ret = decoder_UpdateVideoOutput(p_dec, p_sys->vctx_out);
     return (ret == VLC_SUCCESS);
 error:
     p_sys->b_nvparser_success = false;
@@ -649,11 +651,18 @@ error:
 static int OpenDecoder(vlc_object_t *p_this)
 {
     decoder_t *p_dec = (decoder_t *) p_this;
+
+    vlc_decoder_device *device = NULL;
     int result;
+
     nvdec_ctx_t *p_sys = vlc_obj_calloc(VLC_OBJECT(p_dec), 1, sizeof(*p_sys));
     if (unlikely(!p_sys))
         return VLC_ENOMEM;
 
+    result = decoder_HoldDecoderDevice( p_dec, &device );
+    if (result != 0)
+        return result;
+
     p_dec->p_sys = p_sys;
 
     switch (p_dec->fmt_in.i_codec) {
@@ -855,6 +864,8 @@ static int OpenDecoder(vlc_object_t *p_this)
         goto error;
     }
 
+    p_sys->vctx_out = vlc_video_context_Create( device, 0,  NULL );
+
     vlc_fourcc_t output_chromas[3];
     size_t chroma_idx = 0;
     if (cudaChroma == cudaVideoChromaFormat_420)
@@ -873,7 +884,7 @@ static int OpenDecoder(vlc_object_t *p_this)
     for (chroma_idx = 0; output_chromas[chroma_idx] != 0; chroma_idx++)
     {
         p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma = output_chromas[chroma_idx];
-        result = decoder_UpdateVideoFormat(p_dec);
+        result = decoder_UpdateVideoOutput(p_dec, p_sys->vctx_out);
         if (result == VLC_SUCCESS)
         {
             msg_Dbg(p_dec, "using chroma %4.4s", (char*)&p_dec->fmt_out.video.i_chroma);
@@ -895,10 +906,13 @@ static int OpenDecoder(vlc_object_t *p_this)
     p_dec->pf_decode = DecodeBlock;
 
     p_sys->b_nvparser_success = true;
+    vlc_decoder_device_Release(device);
 
     return VLC_SUCCESS;
 
 error:
+    if (device)
+        vlc_decoder_device_Release(device);
     CloseDecoder(p_this);
     p_dec->p_sys = NULL;
     return VLC_EGENERIC;
@@ -921,6 +935,8 @@ static void CloseDecoder(vlc_object_t *p_this)
         CALL_CUVID(cuvidDestroyVideoParser, p_sys->cuparser);
     if (p_sys->cuCtx)
         CALL_CUDA_DEC(cuCtxDestroy, p_sys->cuCtx);
+    if (p_sys->vctx_out)
+        vlc_video_context_Release(p_sys->vctx_out);
     cuda_free_functions(&p_sys->cudaFunctions);
     cuvid_free_functions(&p_sys->cuvidFunctions);
     if (p_sys->b_is_hxxx)
-- 
2.17.1



More information about the vlc-devel mailing list