summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2020-01-22 17:41:28 +0100
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2020-07-27 19:32:00 +0200
commit634fefab5df3caf98586cb4314ecd2deb0a59eba (patch)
tree1c0346b759bc80beabada3617d3b2a15276b6343 /gst
parentf04dd7f33100ead30d98e5c76d42ee24290fa771 (diff)
vaapidecode: build allowed srcpad caps from va context
Instead of generating allowed srcpad caps with generic information, now it takes the size an formats limits from the decoder's context. This is possible since srcpad caps are generated after the internal decoder is created. The patch replaces gst_vaapi_decoder_get_surface_formats() with gst_vaapi_decoder_get_suface_attributes(). From these attributes, formats are only used for VASurface memory caps feature. For system memory caps feature, the old gst_vaapi_plugin_get_allowed_srcpad_caps() is still used, since i965 jpeg decoder cannot deliver mappable format for gstreamer. And for the other caps features (dmabuf and texture upload) the same static list are used. This patch also adds DMABuf caps feature only if the context supports that memory type. Nonetheless, we keep the pre-defined formats since they are the subset of common derive formats formats supported either by amd/gallium and both intel drivers, since, when exporting the fd through vaAcquireBufferHandle()/ vaReleaseBufferHandle(), the formats of the derivable image cannot be retriebable from the driver. Later we'll use the attribute formats for the DMABuf feature too, when the code be ported to vaExportSurfaceHandle(). Finally, the allowed srcpad caps are removed if the internal decoder is destroyed, since context attribues will change. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/366>
Diffstat (limited to 'gst')
-rw-r--r--gst/vaapi/gstvaapidecode.c105
1 files changed, 82 insertions, 23 deletions
diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c
index c1be7ba4..5e348ea9 100644
--- a/gst/vaapi/gstvaapidecode.c
+++ b/gst/vaapi/gstvaapidecode.c
@@ -197,10 +197,33 @@ gst_vaapidecode_update_sink_caps (GstVaapiDecode * decode, GstCaps * caps)
return TRUE;
}
+static inline void
+caps_set_width_and_height_range (GstCaps * caps, gint min_width,
+ gint min_height, gint max_width, gint max_height)
+{
+ guint size, i;
+ GstStructure *structure;
+
+ /* Set the width/height info to caps */
+ size = gst_caps_get_size (caps);
+ for (i = 0; i < size; i++) {
+ structure = gst_caps_get_structure (caps, i);
+ if (!structure)
+ continue;
+ gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width,
+ max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height,
+ "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
+ }
+}
+
static gboolean
gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
{
- GstCaps *out_caps, *raw_caps;
+ GstCaps *out_caps, *raw_caps, *va_caps, *dma_caps, *gltexup_caps, *base_caps;
+ GArray *formats;
+ gint min_width, min_height, max_width, max_height;
+ guint mem_types;
+ gboolean ret = FALSE;
if (decode->allowed_srcpad_caps)
return TRUE;
@@ -208,40 +231,74 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode)
if (!GST_VAAPI_PLUGIN_BASE_DISPLAY (decode))
return FALSE;
- /* Create VA caps */
- out_caps = gst_caps_from_string (GST_VAAPI_MAKE_SURFACE_CAPS);
- if (!out_caps) {
- GST_WARNING_OBJECT (decode, "failed to create VA/GL source caps");
+ if (!decode->decoder)
return FALSE;
- }
-#if (USE_GLX || USE_EGL)
- if (!GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAN_DMABUF (decode) &&
- gst_vaapi_display_has_opengl (GST_VAAPI_PLUGIN_BASE_DISPLAY (decode))) {
- out_caps = gst_caps_make_writable (out_caps);
- gst_caps_append (out_caps,
- gst_caps_from_string (GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS));
- }
-#endif
- out_caps = gst_caps_make_writable (out_caps);
- gst_caps_append (out_caps, gst_caps_from_string (GST_VAAPI_MAKE_DMABUF_CAPS));
+
+ out_caps = base_caps = raw_caps = va_caps = dma_caps = gltexup_caps = NULL;
+
+ formats = gst_vaapi_decoder_get_surface_attributes (decode->decoder,
+ &min_width, &min_height, &max_width, &max_height, &mem_types);
+ if (!formats)
+ return FALSE;
+
+ base_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
+ if (!base_caps)
+ goto bail;
+ caps_set_width_and_height_range (base_caps, min_width, min_height, max_width,
+ max_height);
raw_caps = gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps
(GST_VAAPI_PLUGIN_BASE (decode),
GST_VIDEO_INFO_FORMAT (&decode->decoded_info));
- if (!raw_caps) {
- gst_caps_unref (out_caps);
- GST_WARNING_OBJECT (decode, "failed to create raw sink caps");
- return FALSE;
+ if (!raw_caps)
+ goto bail;
+ raw_caps = gst_caps_copy (raw_caps);
+ caps_set_width_and_height_range (raw_caps, min_width, min_height,
+ max_width, max_height);
+
+ va_caps = gst_caps_copy (base_caps);
+ gst_caps_set_features_simple (va_caps,
+ gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE));
+
+ if (GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAN_DMABUF (decode)
+ && gst_vaapi_mem_type_supports (mem_types,
+ GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF)) {
+ dma_caps = gst_caps_from_string (GST_VAAPI_MAKE_DMABUF_CAPS);
+ caps_set_width_and_height_range (dma_caps, min_width, min_height, max_width,
+ max_height);
+ }
+#if (USE_GLX || USE_EGL)
+ if (!GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAN_DMABUF (decode)
+ && gst_vaapi_display_has_opengl (GST_VAAPI_PLUGIN_BASE_DISPLAY (decode))) {
+ gltexup_caps = gst_caps_from_string (GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS);
+ if (gltexup_caps) {
+ caps_set_width_and_height_range (base_caps, min_width, min_height,
+ max_width, max_height);
+ }
}
+#endif
+
+ out_caps = va_caps;
+ if (dma_caps)
+ gst_caps_append (out_caps, dma_caps);
+ if (gltexup_caps)
+ gst_caps_append (out_caps, gltexup_caps);
+ if (raw_caps)
+ gst_caps_append (out_caps, raw_caps);
- out_caps = gst_caps_make_writable (out_caps);
- gst_caps_append (out_caps, gst_caps_copy (raw_caps));
decode->allowed_srcpad_caps = out_caps;
GST_INFO_OBJECT (decode, "allowed srcpad caps: %" GST_PTR_FORMAT,
decode->allowed_srcpad_caps);
- return TRUE;
+ ret = TRUE;
+
+bail:
+ if (formats)
+ g_array_unref (formats);
+ if (base_caps)
+ gst_caps_unref (base_caps);
+ return ret;
}
static GstCaps *
@@ -963,6 +1020,8 @@ gst_vaapidecode_destroy (GstVaapiDecode * decode)
gst_vaapidecode_purge (decode);
gst_vaapi_decoder_replace (&decode->decoder, NULL);
+ /* srcpad caps are decoder's context dependant */
+ gst_caps_replace (&decode->allowed_srcpad_caps, NULL);
}
static gboolean