kmssink: Add DMA kind caps into sink caps

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5174>
This commit is contained in:
He Junyan 2023-08-11 18:37:18 +08:00
parent 6f78e1c3e0
commit a925630d87
2 changed files with 26 additions and 32 deletions

View file

@ -1004,10 +1004,9 @@ static gboolean
ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn, ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn,
drmModePlane * plane, drmModeRes * res) 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; int i, j;
GstVideoFormat fmt;
const gchar *format;
drmModeModeInfo *mode; drmModeModeInfo *mode;
gint count_modes; gint count_modes;
@ -1018,6 +1017,12 @@ ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn,
if (!out_caps) if (!out_caps)
return FALSE; 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) if (conn && self->modesetting_enabled)
count_modes = conn->count_modes; count_modes = conn->count_modes;
else else
@ -1025,45 +1030,29 @@ ensure_allowed_caps (GstKMSSink * self, drmModeConnector * conn,
for (i = 0; i < count_modes; i++) { for (i = 0; i < count_modes; i++) {
tmp_caps = gst_caps_new_empty (); tmp_caps = gst_caps_new_empty ();
if (!tmp_caps)
return FALSE;
mode = NULL; mode = NULL;
if (conn && self->modesetting_enabled) if (conn && self->modesetting_enabled)
mode = &conn->modes[i]; mode = &conn->modes[i];
for (j = 0; j < plane->count_formats; j++) { for (j = 0; j < plane->count_formats; j++) {
fmt = gst_video_format_from_drm (plane->formats[j]); raw_caps = create_raw_caps (self, plane->formats[j], all_formats,
if (fmt == GST_VIDEO_FORMAT_UNKNOWN) { all_modifiers, mode, res);
GST_INFO_OBJECT (self, "ignoring format %" GST_FOURCC_FORMAT, dma_caps = create_dma_drm_caps (self, plane->formats[j], all_formats,
GST_FOURCC_ARGS (plane->formats[j])); all_modifiers, mode, res);
continue;
}
format = gst_video_format_to_string (fmt); if (raw_caps)
tmp_caps = gst_caps_merge (tmp_caps, raw_caps);
if (mode) { if (dma_caps)
caps = gst_caps_new_simple ("video/x-raw", tmp_caps = gst_caps_merge (tmp_caps, dma_caps);
"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);
} }
out_caps = gst_caps_merge (out_caps, gst_caps_simplify (tmp_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)) { if (gst_caps_is_empty (out_caps)) {
GST_DEBUG_OBJECT (self, "allowed caps is empty"); GST_DEBUG_OBJECT (self, "allowed caps is empty");
gst_caps_unref (out_caps); gst_caps_unref (out_caps);

View file

@ -198,7 +198,7 @@ GstCaps *
gst_kms_sink_caps_template_fill (void) gst_kms_sink_caps_template_fill (void)
{ {
gint i; gint i;
GstCaps *caps; GstCaps *caps, *dma_caps;
GstStructure *template; GstStructure *template;
caps = gst_caps_new_empty (); 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); "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
gst_caps_append_structure (caps, template); 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] = { static const gint device_par_map[][2] = {