From 20d8f54e63152d3dcceebd37a0644e39f5d48f87 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sun, 18 Aug 2019 22:14:37 +0900 Subject: [PATCH] nvdec: Push/Pop CUDA context around library API call --- sys/nvcodec/gstnvdec.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sys/nvcodec/gstnvdec.c b/sys/nvcodec/gstnvdec.c index a1c54b3f3a..0b28e46c9f 100644 --- a/sys/nvcodec/gstnvdec.c +++ b/sys/nvcodec/gstnvdec.c @@ -656,26 +656,25 @@ maybe_destroy_decoder_and_parser (GstNvDec * nvdec) if (nvdec->decoder) { GST_DEBUG_OBJECT (nvdec, "destroying decoder"); ret = gst_cuda_result (CuvidDestroyDecoder (nvdec->decoder)); - if (ret) - nvdec->decoder = NULL; - else - GST_ERROR_OBJECT (nvdec, "failed to destroy decoder"); - } + nvdec->decoder = NULL; - if (!gst_cuda_context_pop (NULL)) { - GST_ERROR_OBJECT (nvdec, "failed to unlock CUDA context"); - return FALSE; + if (!ret) + GST_ERROR_OBJECT (nvdec, "failed to destroy decoder"); } if (nvdec->parser) { GST_DEBUG_OBJECT (nvdec, "destroying parser"); if (!gst_cuda_result (CuvidDestroyVideoParser (nvdec->parser))) { GST_ERROR_OBJECT (nvdec, "failed to destroy parser"); - return FALSE; + ret = FALSE; } nvdec->parser = NULL; } + if (!gst_cuda_context_pop (NULL)) { + GST_WARNING_OBJECT (nvdec, "failed to pop CUDA context"); + } + return ret; } @@ -735,6 +734,7 @@ gst_nvdec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state) GstNvDec *nvdec = GST_NVDEC (decoder); GstNvDecClass *klass = GST_NVDEC_GET_CLASS (decoder); CUVIDPARSERPARAMS parser_params = { 0, }; + gboolean ret = TRUE; GST_DEBUG_OBJECT (nvdec, "set format"); @@ -759,14 +759,17 @@ gst_nvdec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state) parser_params.pfnDisplayPicture = (PFNVIDDISPLAYCALLBACK) parser_display_callback; + gst_cuda_context_push (nvdec->cuda_ctx); GST_DEBUG_OBJECT (nvdec, "creating parser"); if (!gst_cuda_result (CuvidCreateVideoParser (&nvdec->parser, &parser_params))) { GST_ERROR_OBJECT (nvdec, "failed to create parser"); - return FALSE; + ret = FALSE; } - return TRUE; + gst_cuda_context_pop (NULL); + + return ret; } #ifdef HAVE_NVCODEC_GST_GL