From 82872f42344506c4f5e31c0a485a68a5f40f98cf Mon Sep 17 00:00:00 2001 From: Wangfei Date: Mon, 1 Oct 2018 09:26:05 +0800 Subject: [PATCH] libs: context: query surface format before context to create surface. Before using context to create surface, the supported surface format should be checked first. https://bugzilla.gnome.org/show_bug.cgi?id=797222 --- gst-libs/gst/vaapi/gstvaapicontext.c | 8 +++++-- gst-libs/gst/vaapi/gstvaapisurface.c | 45 ++++++++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapisurface.h | 4 ++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c index afbf8b4..dcce889 100644 --- a/gst-libs/gst/vaapi/gstvaapicontext.c +++ b/gst-libs/gst/vaapi/gstvaapicontext.c @@ -133,9 +133,13 @@ context_ensure_surfaces (GstVaapiContext * context) GstVaapiSurface *surface; guint i; + if (!ensure_formats (context)) + return FALSE; + for (i = context->surfaces->len; i < num_surfaces; i++) { - surface = gst_vaapi_surface_new (GST_VAAPI_OBJECT_DISPLAY (context), - cip->chroma_type, cip->width, cip->height); + surface = + gst_vaapi_surface_new_from_formats (GST_VAAPI_OBJECT_DISPLAY (context), + cip->chroma_type, cip->width, cip->height, context->formats); if (!surface) return FALSE; gst_vaapi_surface_set_parent_context (surface, context); diff --git a/gst-libs/gst/vaapi/gstvaapisurface.c b/gst-libs/gst/vaapi/gstvaapisurface.c index f7f948f..40d9874 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.c +++ b/gst-libs/gst/vaapi/gstvaapisurface.c @@ -317,6 +317,51 @@ error_unsupported_format: GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiSurface, gst_vaapi_surface); /** + * gst_vaapi_surface_new_from_formats: + * @display: a #GstVaapiDisplay + * @chroma_type: the surface chroma format + * @width: the requested surface width + * @height: the requested surface height + * @formats: the limited format list + * + * Creates a new #GstVaapiSurface with a @chroma_type valid for any + * format in @formats; If there aren't any, the returned surface is + * created forcing the passed @chroma_type. + * + * Return value: the newly allocated #GstVaapiSurface object + */ +GstVaapiSurface * +gst_vaapi_surface_new_from_formats (GstVaapiDisplay * display, + GstVaapiChromaType chroma_type, guint width, guint height, GArray * formats) +{ + GstVaapiSurface *surface; + guint i; + + for (i = 0; i < formats->len; i++) { + GstVideoFormat format = g_array_index (formats, GstVideoFormat, i); + if (format == gst_vaapi_video_format_from_chroma (chroma_type)) + return gst_vaapi_surface_new (display, chroma_type, width, height); + } + + /* Fallback: if there's no format valid for the chroma type let's + * just use the passed chroma */ + surface = gst_vaapi_object_new (gst_vaapi_surface_class (), display); + if (!surface) + return NULL; + if (!gst_vaapi_surface_create (surface, chroma_type, width, height)) + goto error; + + return surface; + + /* ERRORS */ +error: + { + gst_vaapi_object_unref (surface); + return NULL; + } +} + +/** * gst_vaapi_surface_new: * @display: a #GstVaapiDisplay * @chroma_type: the surface chroma format diff --git a/gst-libs/gst/vaapi/gstvaapisurface.h b/gst-libs/gst/vaapi/gstvaapisurface.h index eaed6f8..e9ffeb8 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.h +++ b/gst-libs/gst/vaapi/gstvaapisurface.h @@ -170,6 +170,10 @@ typedef struct _GstVaapiSurface GstVaapiSurface; typedef struct _GstVaapiSurfaceProxy GstVaapiSurfaceProxy; GstVaapiSurface * +gst_vaapi_surface_new_from_formats (GstVaapiDisplay * display, + GstVaapiChromaType chroma_type, guint width, guint height, GArray * formts); + +GstVaapiSurface * gst_vaapi_surface_new (GstVaapiDisplay * display, GstVaapiChromaType chroma_type, guint width, guint height); -- 2.7.4