From 9ee58825cc142601043cf3ba8635339453d8625c Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Tue, 23 Jan 2024 15:34:15 +0100 Subject: [PATCH] vaallocator: Allow non-linear modifiers for dummy mem_maps A client may map dmabufs without the intention to either read or write to the memory. One example is clients wanting to use the `gst_video_frame_map()` helper function. Thus, in order to make buffers from `GstVaDmabufAllocator` conveniently usable, ignore the modifier check if the client specified neither `GST_MAP_READ` nor `GST_MAP_WRITE`. Also skip the `va_sync_surface()` call in that case, as it's likely only needed for CPU reads/writes. Part-of: --- .../gst-libs/gst/va/gstvaallocator.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c b/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c index 55d1c6c3b2..d8fcc93f0e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c @@ -391,15 +391,17 @@ 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); - if (self->info.drm_modifier != DRM_FORMAT_MOD_LINEAR) { - GST_ERROR_OBJECT (self, "Failed to map the dmabuf because the modifier " - "is: %#" G_GINT64_MODIFIER "x, which is not linear.", - self->info.drm_modifier); - return NULL; - } + if (flags & GST_MAP_READWRITE) { + if (self->info.drm_modifier != DRM_FORMAT_MOD_LINEAR) { + GST_ERROR_OBJECT (self, "Failed to map the dmabuf because the modifier " + "is: %#" G_GINT64_MODIFIER "x, which is not linear.", + self->info.drm_modifier); + return NULL; + } - if (!va_sync_surface (self->display, surface)) - return NULL; + if (!va_sync_surface (self->display, surface)) + return NULL; + } return self->parent_map (gmem, maxsize, flags); }