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