diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c index 4017c7bb1d..bf7a915e91 100644 --- a/gst-libs/gst/vaapi/gstvaapicontext.c +++ b/gst-libs/gst/vaapi/gstvaapicontext.c @@ -50,6 +50,18 @@ /* Number of scratch surfaces beyond those used as reference */ #define SCRATCH_SURFACES_COUNT (4) +static gboolean +ensure_formats (GstVaapiContext * context) +{ + if (G_LIKELY (context->formats)) + return TRUE; + + context->formats = + gst_vaapi_get_surface_formats (GST_VAAPI_OBJECT_DISPLAY (context), + context->va_config); + return (context->formats != NULL); +} + static void unref_surface_cb (GstVaapiSurface * surface) { @@ -106,6 +118,11 @@ context_destroy (GstVaapiContext * context) GST_WARNING ("failed to destroy config 0x%08x", context->va_config); context->va_config = VA_INVALID_ID; } + + if (context->formats) { + g_array_unref (context->formats); + context->formats = NULL; + } } static gboolean @@ -325,6 +342,8 @@ gst_vaapi_context_init (GstVaapiContext * context, context->va_config = VA_INVALID_ID; context->reset_on_resize = TRUE; gst_vaapi_context_overlay_init (context); + + context->formats = NULL; } static void @@ -520,3 +539,25 @@ gst_vaapi_context_reset_on_resize (GstVaapiContext * context, context->reset_on_resize = reset_on_resize; } + +/** + * gst_vaapi_context_get_surface_formats: + * @context: a #GstVaapiContext + * + * Determines the set of supported formats by the surfaces associated + * to @context. The caller owns an extra reference of the resulting + * array of #GstVideoFormat elements, so it shall be released with + * g_array_unref after usage. + * + * Return value: (transfer full): the set of target formats supported + * by the surfaces in @context. + */ +GArray * +gst_vaapi_context_get_surface_formats (GstVaapiContext * context) +{ + g_return_val_if_fail (context, NULL); + + if (!ensure_formats (context)) + return NULL; + return g_array_ref (context->formats); +} diff --git a/gst-libs/gst/vaapi/gstvaapicontext.h b/gst-libs/gst/vaapi/gstvaapicontext.h index 19afc0626a..030419e131 100644 --- a/gst-libs/gst/vaapi/gstvaapicontext.h +++ b/gst-libs/gst/vaapi/gstvaapicontext.h @@ -109,6 +109,7 @@ struct _GstVaapiContext GPtrArray *overlays[2]; guint overlay_id; gboolean reset_on_resize; + GArray *formats; }; /** @@ -149,6 +150,10 @@ void gst_vaapi_context_reset_on_resize (GstVaapiContext * context, gboolean reset_on_resize); +G_GNUC_INTERNAL +GArray * +gst_vaapi_context_get_surface_formats (GstVaapiContext * context); + G_END_DECLS #endif /* GST_VAAPI_CONTEXT_H */