From 96fdc3d322c7bf083a1411879863e1717ff2fc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Fri, 24 Jan 2020 19:32:52 +0100 Subject: [PATCH] libs: surface: Add hints to allocation flags. When creating surfaces it is possible to pass to VA hints of its usage, so the driver may do some optimizations. This commit adds the handling of encoding/decoding hints. --- gst-libs/gst/vaapi/gstvaapisurface.c | 23 ++++++++++++++++++++++- gst-libs/gst/vaapi/gstvaapisurface.h | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/vaapi/gstvaapisurface.c b/gst-libs/gst/vaapi/gstvaapisurface.c index 24da248d36..3e92e0eaf9 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.c +++ b/gst-libs/gst/vaapi/gstvaapisurface.c @@ -129,6 +129,21 @@ error_unsupported_chroma_type: return FALSE; } +static guint +get_usage_hint (guint alloc_flags) +{ + guint usage_hints = VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC; + + /* XXX(victor): So far, only media-driver uses hints for encoders + * and it doesn't test it as bitwise */ + if (alloc_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_DECODER) + usage_hints = VA_SURFACE_ATTRIB_USAGE_HINT_DECODER; + else if (alloc_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_ENCODER) + usage_hints = VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER; + + return usage_hints; +} + static gboolean gst_vaapi_surface_init_full (GstVaapiSurface * surface, const GstVideoInfo * vip, guint surface_allocation_flags) @@ -139,7 +154,7 @@ gst_vaapi_surface_init_full (GstVaapiSurface * surface, VAStatus status; guint chroma_type, va_chroma_format, i; const VAImageFormat *va_format; - VASurfaceAttrib attribs[3], *attrib; + VASurfaceAttrib attribs[4], *attrib; VASurfaceAttribExternalBuffers extbuf = { 0, }; gboolean extbuf_needed = FALSE; @@ -182,6 +197,12 @@ gst_vaapi_surface_init_full (GstVaapiSurface * surface, attrib->value.value.i = va_format->fourcc; attrib++; + attrib->flags = VA_SURFACE_ATTRIB_SETTABLE; + attrib->type = VASurfaceAttribUsageHint; + attrib->value.type = VAGenericValueTypeInteger; + attrib->value.value.i = get_usage_hint (surface_allocation_flags); + attrib++; + if (extbuf_needed) { attrib->flags = VA_SURFACE_ATTRIB_SETTABLE; attrib->type = VASurfaceAttribMemoryType; diff --git a/gst-libs/gst/vaapi/gstvaapisurface.h b/gst-libs/gst/vaapi/gstvaapisurface.h index be70ce9ff3..68f99ff2ed 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.h +++ b/gst-libs/gst/vaapi/gstvaapisurface.h @@ -165,6 +165,9 @@ typedef enum * the supplied strides information from #GstVideoInfo * @GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_OFFSETS: force allocation with * the supplied offsets information from #GstVideoInfo + * @GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_DECODER: Surface used by video + * decoder + * @GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_ENCODER: Surface used by encoder * * The set of optional allocation flags for gst_vaapi_surface_new_full(). */ @@ -173,6 +176,8 @@ typedef enum GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE = 1 << 0, GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_STRIDES = 1 << 1, GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_OFFSETS = 1 << 2, + GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_DECODER = 1 << 3, + GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_ENCODER = 1 << 4, } GstVaapiSurfaceAllocFlags; #define GST_VAAPI_SURFACE(obj) \