gtk4: Try importing dmabufs withouth DMA_DRM caps

If an upstream elements uses dmabufs - and supports the videometa -
but negotiated sysmem caps, try to use the dmabuf texture builder
for direct GPU buffer imports.

This is notably the case if a udmabuf allocator is used, but also
if elements support dmabufs but do not yet support the DMA_DRM API.
An example for the later is Snapshot on phones. On one hand its
current implementation around camerabin makes using DMA_DRM caps hard
without breaking capturing with software encoders, while on the other
hand importing buffers with GL/VK not only avoids a buffer upload/copy,
but also `DMA_BUF_IOCTL_SYNC` calls, which are potentially expensive
on aarch64. Finally importing dmabufs potentially allows offloading to
display planes.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2490>
This commit is contained in:
Robert Mader 2025-07-19 16:41:14 +02:00
parent b2ae5dfa54
commit 5d976540b3

View file

@ -713,8 +713,20 @@ impl Frame {
.peek_memory(0)
.is_memory_type::<gst_allocators::DmaBufMemory>()
{
let drm_info;
let drm_info_ref = match info.dma_drm() {
Some(drm) => Some(drm),
None => match gst_video::VideoInfoDmaDrm::from_video_info(info, 0) {
Ok(i) => {
drm_info = Some(i);
drm_info.as_ref()
}
Err(_) => None,
},
};
if let Some((vmeta, info)) =
Option::zip(buffer.meta::<gst_video::VideoMeta>(), info.dma_drm())
Option::zip(buffer.meta::<gst_video::VideoMeta>(), drm_info_ref)
{
let mut fds = [-1i32; 4];
let mut offsets = [0; 4];