nvdec: Push/Pop CUDA context around library API call

This commit is contained in:
Seungha Yang 2019-08-18 22:14:37 +09:00 committed by Matthew Waters
parent f7b2b1b99d
commit 20d8f54e63

View file

@ -656,26 +656,25 @@ maybe_destroy_decoder_and_parser (GstNvDec * nvdec)
if (nvdec->decoder) { if (nvdec->decoder) {
GST_DEBUG_OBJECT (nvdec, "destroying decoder"); GST_DEBUG_OBJECT (nvdec, "destroying decoder");
ret = gst_cuda_result (CuvidDestroyDecoder (nvdec->decoder)); ret = gst_cuda_result (CuvidDestroyDecoder (nvdec->decoder));
if (ret)
nvdec->decoder = NULL; nvdec->decoder = NULL;
else
GST_ERROR_OBJECT (nvdec, "failed to destroy decoder");
}
if (!gst_cuda_context_pop (NULL)) { if (!ret)
GST_ERROR_OBJECT (nvdec, "failed to unlock CUDA context"); GST_ERROR_OBJECT (nvdec, "failed to destroy decoder");
return FALSE;
} }
if (nvdec->parser) { if (nvdec->parser) {
GST_DEBUG_OBJECT (nvdec, "destroying parser"); GST_DEBUG_OBJECT (nvdec, "destroying parser");
if (!gst_cuda_result (CuvidDestroyVideoParser (nvdec->parser))) { if (!gst_cuda_result (CuvidDestroyVideoParser (nvdec->parser))) {
GST_ERROR_OBJECT (nvdec, "failed to destroy parser"); GST_ERROR_OBJECT (nvdec, "failed to destroy parser");
return FALSE; ret = FALSE;
} }
nvdec->parser = NULL; nvdec->parser = NULL;
} }
if (!gst_cuda_context_pop (NULL)) {
GST_WARNING_OBJECT (nvdec, "failed to pop CUDA context");
}
return ret; return ret;
} }
@ -735,6 +734,7 @@ gst_nvdec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
GstNvDec *nvdec = GST_NVDEC (decoder); GstNvDec *nvdec = GST_NVDEC (decoder);
GstNvDecClass *klass = GST_NVDEC_GET_CLASS (decoder); GstNvDecClass *klass = GST_NVDEC_GET_CLASS (decoder);
CUVIDPARSERPARAMS parser_params = { 0, }; CUVIDPARSERPARAMS parser_params = { 0, };
gboolean ret = TRUE;
GST_DEBUG_OBJECT (nvdec, "set format"); GST_DEBUG_OBJECT (nvdec, "set format");
@ -759,14 +759,17 @@ gst_nvdec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
parser_params.pfnDisplayPicture = parser_params.pfnDisplayPicture =
(PFNVIDDISPLAYCALLBACK) parser_display_callback; (PFNVIDDISPLAYCALLBACK) parser_display_callback;
gst_cuda_context_push (nvdec->cuda_ctx);
GST_DEBUG_OBJECT (nvdec, "creating parser"); GST_DEBUG_OBJECT (nvdec, "creating parser");
if (!gst_cuda_result (CuvidCreateVideoParser (&nvdec->parser, if (!gst_cuda_result (CuvidCreateVideoParser (&nvdec->parser,
&parser_params))) { &parser_params))) {
GST_ERROR_OBJECT (nvdec, "failed to create parser"); 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 #ifdef HAVE_NVCODEC_GST_GL