From a925630d876441af0b0956b14693e3e14a846116 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 11 Aug 2023 18:37:18 +0800 Subject: [PATCH] kmssink: Add DMA kind caps into sink caps Part-of: --- .../gst-plugins-bad/sys/kms/gstkmssink.c | 49 +++++++------------ .../gst-plugins-bad/sys/kms/gstkmsutils.c | 9 +++- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/kms/gstkmssink.c b/subprojects/gst-plugins-bad/sys/kms/gstkmssink.c index c937664094..439c8521bd 100644 --- a/subprojects/gst-plugins-bad/sys/kms/gstkmssink.c +++ b/subprojects/gst-plugins-bad/sys/kms/gstkmssink.c @@ -1004,10 +1004,9 @@ static gboolean ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn, drmModePlane * plane, drmModeRes * res) { - GstCaps *out_caps, *tmp_caps, *caps; + GstCaps *out_caps, *tmp_caps, *raw_caps, *dma_caps; + GArray *all_formats = NULL, *all_modifiers = NULL; int i, j; - GstVideoFormat fmt; - const gchar *format; drmModeModeInfo *mode; gint count_modes; @@ -1018,6 +1017,12 @@ ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn, if (!out_caps) return FALSE; + if (!self->has_prime_import || !get_all_formats_and_modifiers (self, plane, + &all_formats, &all_modifiers)) { + GST_INFO_OBJECT (self, "Not support prime import or fail to query " + "the fourcc and modifier list, no DMA mode support."); + } + if (conn && self->modesetting_enabled) count_modes = conn->count_modes; else @@ -1025,45 +1030,29 @@ ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn, for (i = 0; i < count_modes; i++) { tmp_caps = gst_caps_new_empty (); - if (!tmp_caps) - return FALSE; mode = NULL; if (conn && self->modesetting_enabled) mode = &conn->modes[i]; for (j = 0; j < plane->count_formats; j++) { - fmt = gst_video_format_from_drm (plane->formats[j]); - if (fmt == GST_VIDEO_FORMAT_UNKNOWN) { - GST_INFO_OBJECT (self, "ignoring format %" GST_FOURCC_FORMAT, - GST_FOURCC_ARGS (plane->formats[j])); - continue; - } + raw_caps = create_raw_caps (self, plane->formats[j], all_formats, + all_modifiers, mode, res); + dma_caps = create_dma_drm_caps (self, plane->formats[j], all_formats, + all_modifiers, mode, res); - format = gst_video_format_to_string (fmt); - - if (mode) { - caps = gst_caps_new_simple ("video/x-raw", - "format", G_TYPE_STRING, format, - "width", G_TYPE_INT, mode->hdisplay, - "height", G_TYPE_INT, mode->vdisplay, - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); - } else { - caps = gst_caps_new_simple ("video/x-raw", - "format", G_TYPE_STRING, format, - "width", GST_TYPE_INT_RANGE, res->min_width, res->max_width, - "height", GST_TYPE_INT_RANGE, res->min_height, res->max_height, - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); - } - if (!caps) - continue; - - tmp_caps = gst_caps_merge (tmp_caps, caps); + if (raw_caps) + tmp_caps = gst_caps_merge (tmp_caps, raw_caps); + if (dma_caps) + tmp_caps = gst_caps_merge (tmp_caps, dma_caps); } out_caps = gst_caps_merge (out_caps, gst_caps_simplify (tmp_caps)); } + g_clear_pointer (&all_formats, g_array_unref); + g_clear_pointer (&all_modifiers, g_array_unref); + if (gst_caps_is_empty (out_caps)) { GST_DEBUG_OBJECT (self, "allowed caps is empty"); gst_caps_unref (out_caps); diff --git a/subprojects/gst-plugins-bad/sys/kms/gstkmsutils.c b/subprojects/gst-plugins-bad/sys/kms/gstkmsutils.c index cc719fcd64..6e0b4dd8b3 100644 --- a/subprojects/gst-plugins-bad/sys/kms/gstkmsutils.c +++ b/subprojects/gst-plugins-bad/sys/kms/gstkmsutils.c @@ -198,7 +198,7 @@ GstCaps * gst_kms_sink_caps_template_fill (void) { gint i; - GstCaps *caps; + GstCaps *caps, *dma_caps; GstStructure *template; caps = gst_caps_new_empty (); @@ -210,7 +210,12 @@ gst_kms_sink_caps_template_fill (void) "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); gst_caps_append_structure (caps, template); } - return gst_caps_simplify (caps); + + caps = gst_caps_simplify (caps); + + dma_caps = gst_caps_from_string (GST_VIDEO_DMA_DRM_CAPS_MAKE); + + return gst_caps_merge (caps, dma_caps); } static const gint device_par_map[][2] = {