va: allocator: dma: Fail when mapping the non-linear buffer.
authorHe Junyan <junyan.he@intel.com>
Tue, 29 Jun 2021 15:21:24 +0000 (23:21 +0800)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 2 Jul 2021 08:15:49 +0000 (08:15 +0000)
The current way of DMA buffer mapping is simply forwarding the job
to parent's map function, which is a mmap(). That can not handle the
non-linear buffers, such as tiling, compressed, etc. The incorrect
mapping of such buffers causes broken images, which are recognized
as bugs. We should directly block this kind of mapping to avoid the
misunderstanding.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2353>

sys/va/gstvaallocator.c

index 78d8931..b2f5094 100644 (file)
@@ -505,21 +505,19 @@ gst_va_dmabuf_mem_map (GstMemory * gmem, gsize maxsize, GstMapFlags flags)
 {
   GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (gmem->allocator);
   VASurfaceID surface = gst_va_memory_get_surface (gmem);
+  guint64 *drm_mod;
 
-  _sync_surface (self->display, surface);
-
-  /* @TODO: if mapping with flag GST_MAP_VASURFACE return the
-   * VA_SURFACE_ID.
-   * if mapping and drm_modifers are not lineal, use vaDeriveImage */
-#ifndef GST_DISABLE_GST_DEBUG
-  {
-    guint64 *drm_mod;
+  drm_mod = gst_mini_object_get_qdata (GST_MINI_OBJECT (gmem),
+      gst_va_drm_mod_quark ());
 
-    drm_mod = gst_mini_object_get_qdata (GST_MINI_OBJECT (gmem),
-        gst_va_drm_mod_quark ());
-    GST_TRACE_OBJECT (self, "DRM modifiers: %#lx", *drm_mod);
+  /* 0 is DRM_FORMAT_MOD_LINEAR, we do not include its header now. */
+  if (*drm_mod != 0) {
+    GST_ERROR_OBJECT (self, "Failed to map the dmabuf because the modifier "
+        "is: %#lx, which is not linear.", *drm_mod);
+    return NULL;
   }
-#endif
+
+  _sync_surface (self->display, surface);
 
   return self->parent_map (gmem, maxsize, flags);
 }