nvdec: Fallback to system memory if OpenGL context could not support PBO memory
authorSeungha Yang <seungha.yang@navercorp.com>
Thu, 29 Aug 2019 11:20:14 +0000 (20:20 +0900)
committerSeungha Yang <seungha.yang@navercorp.com>
Thu, 29 Aug 2019 16:36:46 +0000 (01:36 +0900)
If the environment could not support OpenGL PBO memory, nvdec will do negotiation
with system memory as fallback.

sys/nvcodec/gstnvdec.c

index 4ff73245f7cd25ede01d6666be1fd6036a485493..7e9b5bd5f561c955e2ddb878273ecdb9947147bd 100644 (file)
@@ -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)