vaapivideomemory: add gst_vaapi_dmabuf_can_map()
authorVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Wed, 8 Jun 2016 17:11:15 +0000 (19:11 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 23 Jun 2017 16:44:42 +0000 (18:44 +0200)
This new method checks the specified allocator can create GstMemory that can
be mapped.

https://bugzilla.gnome.org/show_bug.cgi?id=755072

gst/vaapi/gstvaapivideomemory.c
gst/vaapi/gstvaapivideomemory.h

index 6b26d02..3d00e8d 100644 (file)
@@ -1327,3 +1327,50 @@ gst_vaapi_is_dmabuf_allocator (GstAllocator * allocator)
   st = g_object_get_qdata (G_OBJECT (allocator), GST_VAAPI_VIDEO_INFO_QUARK);
   return (st != NULL);
 }
+
+/**
+ * gst_vaapi_dmabuf_can_map:
+ * @display: a #GstVaapiDisplay
+ * @allocator: a #GstAllocator
+ *
+ * It will create a dmabuf-based buffer using @allocator, and it will
+ * try to map it using gst_memory_map().
+ *
+ * Returns: %TRUE if the internal dummy buffer can be
+ * mapped. Otherwise %FALSE.
+ **/
+gboolean
+gst_vaapi_dmabuf_can_map (GstVaapiDisplay * display, GstAllocator * allocator)
+{
+  GstVaapiVideoMeta *meta;
+  GstMemory *mem;
+  GstMapInfo info;
+  gboolean ret;
+
+  g_return_val_if_fail (display != NULL, FALSE);
+
+  ret = FALSE;
+  mem = NULL;
+  meta = NULL;
+  if (!gst_vaapi_is_dmabuf_allocator (allocator))
+    return FALSE;
+  meta = gst_vaapi_video_meta_new (display);
+  if (!meta)
+    return FALSE;
+  mem = gst_vaapi_dmabuf_memory_new (allocator, meta);
+  if (!mem)
+    goto bail;
+
+  if (!gst_memory_map (mem, &info, GST_MAP_READWRITE) || info.size == 0)
+    goto bail;
+
+  gst_memory_unmap (mem, &info);
+  ret = TRUE;
+
+bail:
+  if (mem)
+    gst_memory_unref (mem);
+  if (meta)
+    gst_vaapi_video_meta_unref (meta);
+  return ret;
+}
index dcc998d..db31b69 100644 (file)
@@ -291,6 +291,10 @@ G_GNUC_INTERNAL
 gboolean
 gst_vaapi_is_dmabuf_allocator (GstAllocator * allocator);
 
+G_GNUC_INTERNAL
+gboolean
+gst_vaapi_dmabuf_can_map (GstVaapiDisplay * display, GstAllocator * allocator);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_VIDEO_MEMORY_H */