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

Steve Lhomme robux4 at ycbcr.xyz
Tue Oct 1 13:12:52 CEST 2019


---
 modules/hw/nvdec/nvdec.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index b0f46f83b60..6d7f07314ac 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,17 @@ error:
 static int OpenDecoder(vlc_object_t *p_this)
 {
     decoder_t *p_dec = (decoder_t *) p_this;
-    int result;
+
+    int result = 0;
+
     nvdec_ctx_t *p_sys = vlc_obj_calloc(VLC_OBJECT(p_dec), 1, sizeof(*p_sys));
     if (unlikely(!p_sys))
         return VLC_ENOMEM;
 
+    vlc_decoder_device *device = decoder_GetDecoderDevice( p_dec );
+    if (device == NULL)
+        return VLC_EGENERIC;
+
     p_dec->p_sys = p_sys;
 
     switch (p_dec->fmt_in.i_codec) {
@@ -667,6 +675,7 @@ static int OpenDecoder(vlc_object_t *p_this)
                                            p_dec->fmt_in.i_extra);
             if (result != VLC_SUCCESS) {
                 hxxx_helper_clean(&p_sys->hh);
+                vlc_decoder_device_Release(device);
                 return VLC_EGENERIC;
             }
             p_sys->process_block = HXXXProcessBlock;
@@ -691,6 +700,7 @@ static int OpenDecoder(vlc_object_t *p_this)
                     break;
                 }
             }
+            vlc_decoder_device_Release(device);
             return VLC_EGENERIC;
         case VLC_CODEC_MP1V:
         case VLC_CODEC_MP2V:
@@ -703,22 +713,26 @@ static int OpenDecoder(vlc_object_t *p_this)
             if (p_dec->fmt_in.i_profile != 0 && p_dec->fmt_in.i_profile != 2)
             {
                 msg_Warn(p_dec, "Unsupported VP9 profile %d", p_dec->fmt_in.i_profile);
+                vlc_decoder_device_Release(device);
                 return VLC_EGENERIC;
             }
             p_sys->i_nb_surface = 10;
             break;
         default:
+            vlc_decoder_device_Release(device);
             return VLC_EGENERIC;
     }
 
     result = cuvid_load_functions(&p_sys->cuvidFunctions, p_dec);
     if (result != VLC_SUCCESS) {
         hxxx_helper_clean(&p_sys->hh);
+        vlc_decoder_device_Release(device);
         return VLC_EGENERIC;
     }
     result = cuda_load_functions(&p_sys->cudaFunctions, p_dec);
     if (result != VLC_SUCCESS) {
         hxxx_helper_clean(&p_sys->hh);
+        vlc_decoder_device_Release(device);
         return VLC_EGENERIC;
     }
 
@@ -855,6 +869,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 +889,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 +911,12 @@ 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:
+    vlc_decoder_device_Release(device);
     CloseDecoder(p_this);
     p_dec->p_sys = NULL;
     return VLC_EGENERIC;
@@ -921,6 +939,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