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.
This commit is contained in:
Víctor Manuel Jáquez Leal 2020-01-24 19:32:52 +01:00
parent 8c08ef31a5
commit 96fdc3d322
2 changed files with 27 additions and 1 deletions

View file

@ -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;

View file

@ -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) \