From 71264ede6f3eb82c8dd3cb6ac566afefa502fd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 18 Feb 2016 19:32:58 +0100 Subject: [PATCH] libs: context: ensure context formats This patch ensures to get the formats, as filter does, available in the decoder / encoder context. The context fills up the array as soon it is created, otherwise the pipeline could get stalled (perhaps this is a bug in my HSW backend). https://bugzilla.gnome.org/show_bug.cgi?id=752958 --- gst-libs/gst/vaapi/gstvaapicontext.c | 41 ++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapicontext.h | 5 ++++ 2 files changed, 46 insertions(+) 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 */