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

Steve Lhomme robux4 at ycbcr.xyz
Fri Sep 20 16:28:52 CEST 2019


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

diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index b0f46f83b60..d61d7515c84 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -288,7 +288,7 @@ clean_pics:
 
     CALL_CUDA_DEC(cuCtxPopCurrent, NULL);
 
-    ret = decoder_UpdateVideoFormat(p_dec);
+    ret = decoder_UpdateVideoOutput(p_dec);
     return (ret == VLC_SUCCESS);
 error:
     p_sys->b_nvparser_success = false;
@@ -649,11 +649,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 +862,8 @@ static int OpenDecoder(vlc_object_t *p_this)
         goto error;
     }
 
+    p_dec->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 +882,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);
         if (result == VLC_SUCCESS)
         {
             msg_Dbg(p_dec, "using chroma %4.4s", (char*)&p_dec->fmt_out.video.i_chroma);
@@ -895,10 +904,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 +933,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_dec->vctx_out)
+        vlc_video_context_Release(p_dec->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