From be3a3da829e4156850ec327e3453a5146c746953 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 29 Aug 2019 20:20:14 +0900 Subject: [PATCH] nvdec: Fallback to system memory if OpenGL context could not support PBO memory If the environment could not support OpenGL PBO memory, nvdec will do negotiation with system memory as fallback. --- sys/nvcodec/gstnvdec.c | 56 ++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/sys/nvcodec/gstnvdec.c b/sys/nvcodec/gstnvdec.c index 4ff73245f7..7e9b5bd5f5 100644 --- a/sys/nvcodec/gstnvdec.c +++ b/sys/nvcodec/gstnvdec.c @@ -158,6 +158,9 @@ static gboolean gst_nvdec_flush (GstVideoDecoder * decoder); static GstFlowReturn gst_nvdec_drain (GstVideoDecoder * decoder); static GstFlowReturn gst_nvdec_finish (GstVideoDecoder * decoder); static gboolean gst_nvdec_negotiate (GstVideoDecoder * decoder); +#ifdef HAVE_NVCODEC_GST_GL +static gboolean gst_nvdec_ensure_gl_context (GstNvDec * nvdec); +#endif #define gst_nvdec_parent_class parent_class G_DEFINE_ABSTRACT_TYPE (GstNvDec, gst_nvdec, GST_TYPE_VIDEO_DECODER); @@ -473,6 +476,13 @@ gst_nvdec_negotiate (GstVideoDecoder * decoder) gst_clear_caps (&caps); } + if (nvdec->mem_type == GST_NVDEC_MEM_TYPE_GL && + !gst_nvdec_ensure_gl_context (nvdec)) { + GST_WARNING_OBJECT (nvdec, + "OpenGL context cannot support PBO memory, fallback to system memory"); + nvdec->mem_type = GST_NVDEC_MEM_TYPE_SYSTEM; + } + if (nvdec->mem_type == GST_NVDEC_MEM_TYPE_GL) { gst_caps_set_features (state->caps, 0, gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_GL_MEMORY, NULL)); @@ -1157,24 +1167,16 @@ gst_nvdec_finish (GstVideoDecoder * decoder) return gst_nvdec_drain (decoder); } +#ifdef HAVE_NVCODEC_GST_GL static gboolean -gst_nvdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) +gst_nvdec_ensure_gl_context (GstNvDec * nvdec) { -#ifdef HAVE_NVCODEC_GST_GL - GstNvDec *nvdec = GST_NVDEC (decoder); - GstCaps *outcaps; - GstBufferPool *pool = NULL; - guint n, size, min, max; - GstVideoInfo vinfo = { 0, }; - GstStructure *config; - - GST_DEBUG_OBJECT (nvdec, "decide allocation"); - - if (nvdec->mem_type == GST_NVDEC_MEM_TYPE_SYSTEM) - return GST_VIDEO_DECODER_CLASS (gst_nvdec_parent_class)->decide_allocation - (decoder, query); + if (!nvdec->gl_display) { + GST_DEBUG_OBJECT (nvdec, "No available OpenGL display"); + return FALSE; + } - if (!gst_gl_query_local_gl_context (GST_ELEMENT (decoder), GST_PAD_SRC, + if (!gst_gl_query_local_gl_context (GST_ELEMENT (nvdec), GST_PAD_SRC, &nvdec->gl_context)) { GST_INFO_OBJECT (nvdec, "failed to query local OpenGL context"); if (nvdec->gl_context) @@ -1200,10 +1202,32 @@ gst_nvdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) if (!gst_gl_context_check_gl_version (nvdec->gl_context, SUPPORTED_GL_APIS, 3, 0)) { - GST_ERROR_OBJECT (nvdec, "OpenGL context could not support PBO download"); + GST_WARNING_OBJECT (nvdec, "OpenGL context could not support PBO download"); return FALSE; } + return TRUE; +} + +#endif + +static gboolean +gst_nvdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) +{ +#ifdef HAVE_NVCODEC_GST_GL + GstNvDec *nvdec = GST_NVDEC (decoder); + GstCaps *outcaps; + GstBufferPool *pool = NULL; + guint n, size, min, max; + GstVideoInfo vinfo = { 0, }; + GstStructure *config; + + GST_DEBUG_OBJECT (nvdec, "decide allocation"); + + if (nvdec->mem_type == GST_NVDEC_MEM_TYPE_SYSTEM) + return GST_VIDEO_DECODER_CLASS (gst_nvdec_parent_class)->decide_allocation + (decoder, query); + gst_query_parse_allocation (query, &outcaps, NULL); n = gst_query_get_n_allocation_pools (query); if (n > 0) -- 2.34.1