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
This commit is contained in:
Wangfei 2018-10-01 09:26:05 +08:00 committed by Víctor Manuel Jáquez Leal
parent bcd63f8021
commit 82872f4234
3 changed files with 55 additions and 2 deletions

View file

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

View file

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

View file

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