kmssink: Do not close the DRM prime handle twice

The prime_fds for multi planes may be the same. For example, on Intel's
platform, the NV12 surface may have the same FD for the plane0 and the
plane1. Then, the DRM_IOCTL_GEM_CLOSE will close the same handle twice
and get an "Invalid argument 22" error the second time.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6914>
This commit is contained in:
He Junyan 2023-08-11 17:50:23 +08:00 committed by Nicolas Dufresne
parent e913b4870a
commit ea0dce26e0

View file

@ -427,7 +427,7 @@ gst_kms_allocator_dmabuf_import (GstAllocator * allocator, gint * prime_fds,
GstKMSAllocator *alloc; GstKMSAllocator *alloc;
GstKMSMemory *kmsmem; GstKMSMemory *kmsmem;
GstMemory *mem; GstMemory *mem;
gint i, ret; gint i, j, ret;
guint32 gem_handle[4] = { 0, }; guint32 gem_handle[4] = { 0, };
g_return_val_if_fail (n_planes <= GST_VIDEO_MAX_PLANES, FALSE); g_return_val_if_fail (n_planes <= GST_VIDEO_MAX_PLANES, FALSE);
@ -456,6 +456,14 @@ done:
if (!gem_handle[i]) if (!gem_handle[i])
continue; continue;
/* Do not close the same handle twice. */
for (j = 0; j < i; j++) {
if (gem_handle[j] == gem_handle[i])
break;
}
if (j < i)
continue;
err = drmIoctl (alloc->priv->fd, DRM_IOCTL_GEM_CLOSE, &arg); err = drmIoctl (alloc->priv->fd, DRM_IOCTL_GEM_CLOSE, &arg);
if (err) if (err)
GST_WARNING_OBJECT (allocator, GST_WARNING_OBJECT (allocator,