From 516073f9d0895eb3eb00320f4f937aa310ab18b3 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 13 Oct 2023 15:07:45 -0400 Subject: [PATCH] glupload: egl: Use n_plane values from the GstVideoInfo The number of planes is a meta we carry around in the GstVideoMeta with DMA_DRM format. In cannot be decuded correctly from knowledge of the base format. Notably, some compression modifier may introduce an extra plane to store the compression parameters. So use n_planes from GstVideoMeta and pass this explicitly when importing to EGLImage. Part-of: --- .../gst-libs/gst/gl/egl/gsteglimage.c | 10 ++++---- .../gst-libs/gst/gl/egl/gsteglimage.h | 1 + .../gst-libs/gst/gl/gstglupload.c | 24 ++++++++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c index 7b61daf831..b70fd59fe5 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c @@ -823,13 +823,14 @@ gst_egl_image_from_dmabuf_direct_target (GstGLContext * context, DRM_FORMAT_MOD_LINEAR)) return NULL; - return gst_egl_image_from_dmabuf_direct_target_with_dma_drm (context, fd, - offset, &in_info_dma, target); + return gst_egl_image_from_dmabuf_direct_target_with_dma_drm (context, + GST_VIDEO_INFO_N_PLANES (in_info), fd, offset, &in_info_dma, target); } /** * gst_egl_image_from_dmabuf_direct_target_with_dma_drm: * @context: a #GstGLContext (must be an EGL context) + * @n_planes: number of planes (obtained from a #GstVideoMeta) * @fd: Array of DMABuf file descriptors * @offset: Array of offsets, relative to the DMABuf * @in_info_dma: the #GstVideoInfoDmaDrm @@ -848,12 +849,11 @@ gst_egl_image_from_dmabuf_direct_target (GstGLContext * context, */ GstEGLImage * gst_egl_image_from_dmabuf_direct_target_with_dma_drm (GstGLContext * context, - gint * fd, const gsize * offset, const GstVideoInfoDmaDrm * in_info_dma, - GstGLTextureTarget target) + guint n_planes, gint * fd, const gsize * offset, + const GstVideoInfoDmaDrm * in_info_dma, GstGLTextureTarget target) { EGLImageKHR img; const GstVideoInfo *in_info = &in_info_dma->vinfo; - guint n_planes = GST_VIDEO_INFO_N_PLANES (in_info); guint32 fourcc; guint64 modifier; gint i; diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.h index 5d333b8eb6..b34607d40c 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.h @@ -104,6 +104,7 @@ GstEGLImage * gst_egl_image_from_dmabuf_direct_target (GstGLContext * GST_GL_API GstEGLImage * gst_egl_image_from_dmabuf_direct_target_with_dma_drm (GstGLContext * context, + guint n_planes, gint * fd, const gsize * offset, const GstVideoInfoDmaDrm * in_info_dma, diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c index 9a4695c23e..4fab920c88 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c @@ -1402,7 +1402,11 @@ _dma_buf_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps, return FALSE; } - n_planes = GST_VIDEO_INFO_N_PLANES (in_info); + if (!dmabuf->direct && in_info_drm->drm_modifier != DRM_FORMAT_MOD_LINEAR) { + GST_DEBUG_OBJECT (dmabuf->upload, + "Indirect uploads are only support for linear formats."); + return FALSE; + } /* This will eliminate most non-dmabuf out there */ if (!gst_is_dmabuf_memory (gst_buffer_peek_memory (buffer, 0))) { @@ -1410,17 +1414,13 @@ _dma_buf_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps, return FALSE; } - /* We cannot have multiple dmabuf per plane */ - if (n_mem > n_planes) { - GST_DEBUG_OBJECT (dmabuf->upload, - "number of memory (%u) != number of planes (%u)", n_mem, n_planes); - return FALSE; - } + n_planes = GST_VIDEO_INFO_N_PLANES (in_info); /* Update video info based on video meta */ if (meta) { in_info->width = meta->width; in_info->height = meta->height; + n_planes = meta->n_planes; for (i = 0; i < meta->n_planes; i++) { in_info->offset[i] = meta->offset[i]; @@ -1428,6 +1428,13 @@ _dma_buf_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps, } } + /* We cannot have multiple dmabuf per plane */ + if (n_mem > n_planes) { + GST_DEBUG_OBJECT (dmabuf->upload, + "number of memory (%u) != number of planes (%u)", n_mem, n_planes); + return FALSE; + } + if (out_caps != dmabuf->out_caps) { dmabuf->out_caps = out_caps; if (!gst_video_info_from_caps (out_info, out_caps)) @@ -1515,7 +1522,8 @@ _dma_buf_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps, /* otherwise create one and cache it */ if (dmabuf->direct) { dmabuf->eglimage[i] = gst_egl_image_from_dmabuf_direct_target_with_dma_drm - (dmabuf->upload->context, fd, offset, in_info_drm, dmabuf->target); + (dmabuf->upload->context, n_planes, fd, offset, in_info_drm, + dmabuf->target); } else { dmabuf->eglimage[i] = gst_egl_image_from_dmabuf (dmabuf->upload->context, fd[i], in_info, i, offset[i]);