[vlc-devel] [PATCH 1/2] nvdec: get the decoder device earlier

Steve Lhomme robux4 at ycbcr.xyz
Mon Mar 16 15:54:36 CET 2020


If the decoder device doesn't match we shouldn't be using this decoder anyway.
---
 modules/hw/nvdec/nvdec.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index 162330788fb..d5246bf4bd6 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -758,17 +758,33 @@ static int OpenDecoder(vlc_object_t *p_this)
             return VLC_EGENERIC;
     }
 
+    vlc_decoder_device *dec_device = decoder_GetDecoderDevice( p_dec );
+    if (dec_device == NULL)
+        return VLC_ENOOBJ;
+    if (dec_device->type != VLC_DECODER_DEVICE_NVDEC)
+    {
+        vlc_decoder_device_Release(dec_device);
+        return VLC_ENOOBJ;
+    }
+    p_sys->vctx_out = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_NVDEC, 0, NULL );
+    vlc_decoder_device_Release(dec_device);
+    if (unlikely(p_sys->vctx_out == NULL))
+    {
+        msg_Err(p_dec, "failed to create a video context");
+        return VLC_ENOOBJ;
+    }
+
     result = cuvid_load_functions(&p_sys->cuvidFunctions, p_dec);
     if (result != VLC_SUCCESS) {
         if (p_sys->b_is_hxxx)
             hxxx_helper_clean(&p_sys->hh);
-        return VLC_EGENERIC;
+        goto error;
     }
     result = cuda_load_functions(&p_sys->cudaFunctions, p_dec);
     if (result != VLC_SUCCESS) {
         if (p_sys->b_is_hxxx)
             hxxx_helper_clean(&p_sys->hh);
-        return VLC_EGENERIC;
+        goto error;
     }
 
     result = CALL_CUDA_DEC(cuInit, 0);
@@ -918,20 +934,6 @@ static int OpenDecoder(vlc_object_t *p_this)
         goto error;
     }
 
-    vlc_decoder_device *dec_device = decoder_GetDecoderDevice( p_dec );
-    if (dec_device == NULL)
-        goto error;
-    if (dec_device->type == VLC_DECODER_DEVICE_NVDEC)
-    {
-        p_sys->vctx_out = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_NVDEC, 0, NULL );
-    }
-    vlc_decoder_device_Release(dec_device);
-    if (unlikely(p_sys->vctx_out == NULL))
-    {
-        msg_Err(p_dec, "failed to create a video context");
-        goto error;
-    }
-
     vlc_fourcc_t output_chromas[3];
     size_t chroma_idx = 0;
     if (cudaChroma == cudaVideoChromaFormat_420)
-- 
2.17.1



More information about the vlc-devel mailing list