[vlc-devel] [PATCH] nvdec: fixed output chroma selection

Quentin Chateau quentin.chateau at gmail.com
Wed Feb 26 00:05:00 CET 2020


The vlc_video_context needs to be re-created after
each call to decoder_UpdateVideoOutput.
---
 modules/hw/nvdec/nvdec.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index e5cda56ef3..7720da0201 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -912,20 +912,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)
@@ -950,6 +936,20 @@ static int OpenDecoder(vlc_object_t *p_this)
 
     for (chroma_idx = 0; output_chromas[chroma_idx] != 0; chroma_idx++)
     {
+        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;
+        }
+
         p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma = output_chromas[chroma_idx];
         result = decoder_UpdateVideoOutput(p_dec, p_sys->vctx_out);
         if (result == VLC_SUCCESS)
@@ -958,6 +958,8 @@ static int OpenDecoder(vlc_object_t *p_this)
             break;
         }
         msg_Warn(p_dec, "Failed to use output chroma %4.4s", (char*)&p_dec->fmt_out.video.i_chroma);
+        vlc_video_context_Release(p_sys->vctx_out);
+        p_sys->vctx_out = NULL;
     }
     if (result != VLC_SUCCESS)
         goto error;
-- 
2.20.1



More information about the vlc-devel mailing list