kmsbufferpool: Accept DMA_DRM caps in the config

Only linear modifier is supported due to the dumb allocator's
limitation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5174>
This commit is contained in:
Jakub Adam 2024-11-08 13:43:53 +01:00 committed by He Junyan
parent 9e81a6517b
commit 34a400cc0e

View file

@ -29,6 +29,8 @@
#include <gst/video/gstvideometa.h> #include <gst/video/gstvideometa.h>
#include <drm_fourcc.h>
#include "gstkmsbufferpool.h" #include "gstkmsbufferpool.h"
#include "gstkmsallocator.h" #include "gstkmsallocator.h"
@ -66,7 +68,7 @@ gst_kms_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
GstKMSBufferPool *vpool; GstKMSBufferPool *vpool;
GstKMSBufferPoolPrivate *priv; GstKMSBufferPoolPrivate *priv;
GstCaps *caps; GstCaps *caps;
GstVideoInfo vinfo; GstVideoInfoDmaDrm dma_drm;
GstAllocator *allocator; GstAllocator *allocator;
GstAllocationParams params; GstAllocationParams params;
@ -79,8 +81,17 @@ gst_kms_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
if (!caps) if (!caps)
goto no_caps; goto no_caps;
gst_video_info_dma_drm_init (&dma_drm);
/* now parse the caps from the config */ /* now parse the caps from the config */
if (!gst_video_info_from_caps (&vinfo, caps)) if (gst_video_is_dma_drm_caps (caps)) {
if (!gst_video_info_dma_drm_from_caps (&dma_drm, caps))
goto wrong_caps;
if (dma_drm.drm_modifier != DRM_FORMAT_MOD_LINEAR)
goto wrong_modifier;
} else if (!gst_video_info_from_caps (&dma_drm.vinfo, caps))
goto wrong_caps; goto wrong_caps;
allocator = NULL; allocator = NULL;
@ -95,7 +106,7 @@ gst_kms_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
if (!priv->allocator) if (!priv->allocator)
goto no_allocator; goto no_allocator;
priv->vinfo = vinfo; priv->vinfo = dma_drm.vinfo;
/* enable metadata based on config of the pool */ /* enable metadata based on config of the pool */
priv->add_videometa = gst_buffer_pool_config_has_option (config, priv->add_videometa = gst_buffer_pool_config_has_option (config,
@ -122,6 +133,18 @@ wrong_caps:
"failed getting geometry from caps %" GST_PTR_FORMAT, caps); "failed getting geometry from caps %" GST_PTR_FORMAT, caps);
return FALSE; return FALSE;
} }
wrong_modifier:
{
gchar *drmfmtstr = gst_video_dma_drm_fourcc_to_string (dma_drm.drm_fourcc,
dma_drm.drm_modifier);
GST_WARNING_OBJECT (pool,
"dumb allocator can't allocate nonlinear format %s", drmfmtstr);
g_clear_pointer (&drmfmtstr, g_free);
return FALSE;
}
no_allocator: no_allocator:
{ {
GST_WARNING_OBJECT (pool, "no valid allocator in pool"); GST_WARNING_OBJECT (pool, "no valid allocator in pool");