wayland: Remove custom format mapping

As of Gst >= 1.24 we can just use GstVideoInfoDmaDrm APIs. Note
that SHM formats match DRM ones with only two exceptions.

No functional changes intended (for backporting) apart from
supporting a few more formats - those present in video-info-dma.c
but missing in the removed mapping.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8983>
This commit is contained in:
Robert Mader 2025-05-14 20:07:52 +02:00 committed by GStreamer Marge Bot
parent 571f32eec0
commit 47308092dd

View File

@ -29,17 +29,6 @@
#include <drm_fourcc.h>
/* This can be removed once we can bump the required wl_client_dep,
* which again is blocked by a CI image update, see
* https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5275
*/
#ifndef WL_SHM_FORMAT_P010
#define WL_SHM_FORMAT_P010 DRM_FORMAT_P010
#endif
#ifndef WL_SHM_FORMAT_NV15
#define WL_SHM_FORMAT_NV15 DRM_FORMAT_NV15
#endif
#define GST_CAT_DEFAULT gst_wl_videoformat_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
@ -56,94 +45,59 @@ gst_wl_videoformat_init_once (void)
}
}
typedef struct
{
enum wl_shm_format wl_shm_format;
guint32 dma_format;
GstVideoFormat gst_format;
} wl_VideoFormat;
static const wl_VideoFormat wl_formats[] = {
{WL_SHM_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888, GST_VIDEO_FORMAT_BGRx},
{WL_SHM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888, GST_VIDEO_FORMAT_BGRA},
{WL_SHM_FORMAT_XBGR8888, DRM_FORMAT_XBGR8888, GST_VIDEO_FORMAT_RGBx},
{WL_SHM_FORMAT_RGBX8888, DRM_FORMAT_RGBX8888, GST_VIDEO_FORMAT_xBGR},
{WL_SHM_FORMAT_BGRX8888, DRM_FORMAT_BGRX8888, GST_VIDEO_FORMAT_xRGB},
{WL_SHM_FORMAT_ABGR8888, DRM_FORMAT_ABGR8888, GST_VIDEO_FORMAT_RGBA},
{WL_SHM_FORMAT_RGBA8888, DRM_FORMAT_RGBA8888, GST_VIDEO_FORMAT_ABGR},
{WL_SHM_FORMAT_BGRA8888, DRM_FORMAT_BGRA8888, GST_VIDEO_FORMAT_ARGB},
{WL_SHM_FORMAT_RGB888, DRM_FORMAT_RGB888, GST_VIDEO_FORMAT_BGR},
{WL_SHM_FORMAT_BGR888, DRM_FORMAT_BGR888, GST_VIDEO_FORMAT_RGB},
{WL_SHM_FORMAT_RGB565, DRM_FORMAT_RGB565, GST_VIDEO_FORMAT_RGB16},
{WL_SHM_FORMAT_BGR565, DRM_FORMAT_BGR565, GST_VIDEO_FORMAT_BGR16},
{WL_SHM_FORMAT_YUYV, DRM_FORMAT_YUYV, GST_VIDEO_FORMAT_YUY2},
{WL_SHM_FORMAT_YVYU, DRM_FORMAT_YVYU, GST_VIDEO_FORMAT_YVYU},
{WL_SHM_FORMAT_UYVY, DRM_FORMAT_UYVY, GST_VIDEO_FORMAT_UYVY},
{WL_SHM_FORMAT_AYUV, DRM_FORMAT_AYUV, GST_VIDEO_FORMAT_AYUV},
{WL_SHM_FORMAT_NV12, DRM_FORMAT_NV12, GST_VIDEO_FORMAT_NV12},
{WL_SHM_FORMAT_NV21, DRM_FORMAT_NV21, GST_VIDEO_FORMAT_NV21},
{WL_SHM_FORMAT_NV16, DRM_FORMAT_NV16, GST_VIDEO_FORMAT_NV16},
{WL_SHM_FORMAT_NV61, DRM_FORMAT_NV61, GST_VIDEO_FORMAT_NV61},
{WL_SHM_FORMAT_P010, DRM_FORMAT_P010, GST_VIDEO_FORMAT_P010_10LE},
{WL_SHM_FORMAT_NV15, DRM_FORMAT_NV15, GST_VIDEO_FORMAT_NV12_10LE40},
{WL_SHM_FORMAT_YUV410, DRM_FORMAT_YUV410, GST_VIDEO_FORMAT_YUV9},
{WL_SHM_FORMAT_YVU410, DRM_FORMAT_YVU410, GST_VIDEO_FORMAT_YVU9},
{WL_SHM_FORMAT_YUV411, DRM_FORMAT_YUV411, GST_VIDEO_FORMAT_Y41B},
{WL_SHM_FORMAT_YUV420, DRM_FORMAT_YUV420, GST_VIDEO_FORMAT_I420},
{WL_SHM_FORMAT_YVU420, DRM_FORMAT_YVU420, GST_VIDEO_FORMAT_YV12},
{WL_SHM_FORMAT_YUV422, DRM_FORMAT_YUV422, GST_VIDEO_FORMAT_Y42B},
{WL_SHM_FORMAT_YUV444, DRM_FORMAT_YUV444, GST_VIDEO_FORMAT_v308},
};
enum wl_shm_format
gst_video_format_to_wl_shm_format (GstVideoFormat format)
{
guint i;
guint32 drm_format;
guint64 modifier;
for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
if (wl_formats[i].gst_format == format)
return wl_formats[i].wl_shm_format;
drm_format = gst_video_dma_drm_format_from_gst_format (format, &modifier);
GST_WARNING ("wayland shm video format not found");
return -1;
if (drm_format == DRM_FORMAT_INVALID || modifier != DRM_FORMAT_MOD_LINEAR) {
GST_WARNING ("wayland shm video format not found");
return -1;
}
if (drm_format == DRM_FORMAT_XRGB8888)
drm_format = WL_SHM_FORMAT_XRGB8888;
else if (drm_format == DRM_FORMAT_ARGB8888)
drm_format = WL_SHM_FORMAT_ARGB8888;
return drm_format;
}
guint32
gst_video_format_to_wl_dmabuf_format (GstVideoFormat format)
{
guint i;
guint32 drm_format;
guint64 modifier;
for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
if (wl_formats[i].gst_format == format)
return wl_formats[i].dma_format;
drm_format = gst_video_dma_drm_format_from_gst_format (format, &modifier);
GST_WARNING ("wayland dmabuf video format not found");
return 0;
if (drm_format == DRM_FORMAT_INVALID || modifier != DRM_FORMAT_MOD_LINEAR) {
GST_WARNING ("wayland dmabuf video format not found");
return DRM_FORMAT_INVALID;
}
return drm_format;
}
GstVideoFormat
gst_wl_shm_format_to_video_format (enum wl_shm_format wl_format)
{
guint i;
if (wl_format == WL_SHM_FORMAT_XRGB8888)
wl_format = DRM_FORMAT_XRGB8888;
else if (wl_format == WL_SHM_FORMAT_ARGB8888)
wl_format = DRM_FORMAT_ARGB8888;
for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
if (wl_formats[i].wl_shm_format == wl_format)
return wl_formats[i].gst_format;
return GST_VIDEO_FORMAT_UNKNOWN;
return gst_wl_dmabuf_format_to_video_format (wl_format);
}
GstVideoFormat
gst_wl_dmabuf_format_to_video_format (guint wl_format)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
if (wl_formats[i].dma_format == wl_format)
return wl_formats[i].gst_format;
return GST_VIDEO_FORMAT_UNKNOWN;
return gst_video_dma_drm_format_to_gst_format (wl_format,
DRM_FORMAT_MOD_LINEAR);
}
const gchar *