diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c index afbf8b4b20..dcce889570 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 f7f948fe52..40d98745ca 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.c +++ b/gst-libs/gst/vaapi/gstvaapisurface.c @@ -316,6 +316,51 @@ error_unsupported_format: #define gst_vaapi_surface_finalize gst_vaapi_surface_destroy 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 diff --git a/gst-libs/gst/vaapi/gstvaapisurface.h b/gst-libs/gst/vaapi/gstvaapisurface.h index eaed6f8e60..e9ffeb8de2 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.h +++ b/gst-libs/gst/vaapi/gstvaapisurface.h @@ -169,6 +169,10 @@ typedef enum 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);