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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5461>
This commit is contained in:
Nicolas Dufresne 2023-10-13 15:07:45 -04:00 committed by GStreamer Marge Bot
parent 0e5f5b413c
commit 516073f9d0
3 changed files with 22 additions and 13 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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]);